Using multiple regression to predict unknown values
With a fitted regression model, we can apply the model to predict unknown values. For regression models, we can express the precision of prediction with a prediction interval and a confidence interval. In the following recipe, we will introduce how to predict unknown values under these two measurements.
Getting ready
You need to have completed the previous recipe by computing the linear model of the income, prestige, and women variables from the Prestige dataset.
How to do it...
Perform the following steps to predict values with multiple regression:
- Fit a linear model with the
income,prestige, andwomenvariables:
> model = lm(income ~ prestige + women, Prestige)
- Assign values to be predicted into
newdata:
> newdat = data.frame(prestige = c(75,80), women=c(14,13))
- Compute the prediction result using the confidence interval with
levelset as0.95:
> predict(model, newdata = newdat)
Output:
1...