Returns predictions for new data from a fitted ols model, with
optional standard errors and exact closed-form confidence or
prediction intervals.
Arguments
- object
An object of class
"ols".- newdata
A numeric matrix or data frame of new predictors.
NULL(default) returnsobject$fitted.values.- type
Prediction scale. Only
"response"is supported (the linear predictor coincides with the response for a gaussian fit).- se.fit
If
TRUE, the returned vector carries an"se.fit"attribute holding the per-row standard error of the fitted mean. For bagged fits the standard error is the per-row bag standard deviation. DefaultFALSE.- interval
Type of interval to return.
"none"(default): point predictions only."confidence": a matrix with columnsc("fit", "lwr", "upr")for the mean response."prediction": a matrix with columnsc("fit", "lwr", "upr")for a new observation (adds the residual variance, or the variance-model variance when the fit was built withvarmod = "const"or"lm").
- level
Confidence/prediction level. Default
0.95.- robust
Heteroscedasticity-consistent covariance used for the standard errors / intervals.
"none"(default): the classicalsigma2 (X'WX)^-1."HC0","HC1","HC2","HC3": a sandwich estimator.
- ...
Currently unused.
Value
A numeric vector of predictions, or a matrix with columns
c("fit", "lwr", "upr") when interval != "none". With
se.fit = TRUE the result carries an "se.fit" attribute.
Examples
fit <- ols(mpg ~ wt + hp, data = mtcars)
predict(fit, mtcars[1:5, ], interval = "confidence")
#> fit lwr upr
#> Mazda RX4 23.57233 22.45623 24.68843
#> Mazda RX4 Wag 22.58348 21.51622 23.65074
#> Datsun 710 25.27582 23.97441 26.57723
#> Hornet 4 Drive 21.26502 20.10932 22.42072
#> Hornet Sportabout 18.32727 17.30889 19.34564