predict.lm {base} | R Documentation |
Predicted values based on linear model object
## S3 method for class 'lm'
predict(object, newdata, se.fit = FALSE, scale = NULL, df = Inf,
interval = c("none", "confidence", "prediction"),
level = 0.95, type = c("response", "terms"),
terms = NULL, ...)
object |
Object of class inheriting from |
newdata |
Data frame in which to predict |
se.fit |
A switch indicating if standard errors are required. |
scale |
Scale parameter for std.err. calculation |
df |
Degrees of freedom for scale |
interval |
Type of interval calculation |
level |
Tolerance/confidence level |
type |
Type of prediction (response or model term) |
terms |
If |
... |
further arguments passed to or from other methods. |
predict.lm
produces predicted values, obtained by evaluating
the regression function in the frame newdata
(which defaults to
model.frame(object)
. If the logical se.fit
is
TRUE
, standard errors of the predictions are calculated. If
the numeric argument scale
is set (with optional df
), it
is used as the residual standard deviation in the computation of the
standard errors, otherwise this is extracted from the model fit.
Setting intervals
specifies computation of confidence or
prediction (tolerance) intervals at the specified level
.
predict.lm
produces a vector of predictions or a matrix of
predictions and bounds with column names fit
, lwr
, and
upr
if interval
is set. If se.fit
is
TRUE
, a list with the following components is returned:
fit |
vector or matrix as above |
se.fit |
standard error of predictions |
residual.scale |
residual standard deviations |
df |
degrees of freedom for residual |
Offsets specified by offset
in the fit by lm
will not be included in predictions, whereas those specified by an
offset term in the formula will be.
The model fitting function lm
, predict
,
SafePrediction
## Predictions
x <- rnorm(15)
y <- x + rnorm(15)
predict(lm(y ~ x))
new <- data.frame(x = seq(-3, 3, 0.5))
predict(lm(y ~ x), new, se.fit = TRUE)
pred.w.plim <- predict(lm(y ~ x), new, interval="prediction")
pred.w.clim <- predict(lm(y ~ x), new, interval="confidence")
matplot(new$x,cbind(pred.w.clim, pred.w.plim[,-1]),
lty=c(1,2,2,3,3), type="l", ylab="predicted y")