Discrete predictors
So far, we have seen only the simple case of both the response and the predictor variables being continuous. Now, let's generalize the model a bit, and enter a discrete predictor into the model. Take the usair
data and add x5
(precipitation: average number of wet days per year) as a predictor with three categories (low, middle, and high levels of precipitation), using 30 and 45 as the cut-points. The research question is how these precipitation groups are associated with the SO2 concentration. The association is not necessary linear, as the following plot shows:
> plot(y ~ x5, data = usair, cex.lab = 1.5) > abline(lm(y ~ x5, data = usair), col = 'red', lwd = 2.5, lty = 1) > abline(lm(y ~ x5, data = usair[usair$x5<=45,]), + col ...
Get Mastering Data Analysis with R now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.