Linear regression with continuous predictors
Let's start with an actual and illuminating example of confounding. Consider that we would like to predict the amount of air pollution based on the size of the city (measured in population size as thousand of habitants). Air pollution is measured by the sulfur dioxide (SO2) concentration in the air, in milligrams per cubic meter. We will use the US air pollution data set (Hand and others 1994) from the gamlss.data
package:
> library(gamlss.data) > data(usair)
Model interpretation
Let's draw our very first linear regression model by building a formula. The lm
function from the stats
package is used to fit linear models, which is an important tool for regression modeling:
> model.0 <- lm(y ~ x3, data = usair) > summary(model.0) Residuals: Min 1Q Median 3Q Max -32.545 -14.456 -4.019 11.019 72.549 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 17.868316 4.713844...