Predict is a generic function with, at present, a single method for "lm" objects, Predict.lm, which is a modification of the standard predict.lm method in the stats package, but with an additional vcov. argument for a user-specified covariance matrix for intreval estimation.

Predict(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, na.action = na.pass,
  pred.var = res.var/weights, weights = 1, vcov., ...)

Arguments

object

a model object for which predictions are desired.

newdata, se.fit, scale, df, interval, level, type, terms, na.action, pred.var, weights

see predict.lm.

vcov.

optional, either a function to compute the coefficient covariance matrix of object (e.g., hccm) or a coefficient covariance matrix (as returned, e.g., by hccm). To use a bootstrap to estimate the covariance matrix, set vcov. = vcov(Boot(object)).

...

arguments to pass down to Predict or predict methods.

Details

If there is no appropriate method for Predict, then a predict method is invoked. If there is a specific predict method for the primary class of object but only an inherited Predict method, then the predict method is invoked. Thus an object of class c("glm", "lm") will invoke method predict.glm rather than Predict.lm, but an object of class c("aov", "lm") will invoke Predict.lm rather than predict.lm.

Value

See predict and predict.lm.

References

Fox, J. and Weisberg, S. (2019) An R Companion to Applied Regression, Third Edition, Sage.

Author

John Fox jfox@mcmaster.ca

See also

Examples

mod <- lm(interlocks ~ log(assets), data=Ornstein)
newd <- data.frame(assets=exp(4:12))
(p1 <- predict(mod, newd, interval="prediction"))
#>          fit        lwr      upr
#> 1 -11.546844 -35.632612 12.53892
#> 2  -4.213580 -28.167353 19.74019
#> 3   3.119684 -20.746798 26.98617
#> 4  10.452948 -13.371440 34.27734
#> 5  17.786212  -6.041518 41.61394
#> 6  25.119476   1.242988 48.99596
#> 7  32.452740   8.482354 56.42313
#> 8  39.786004  15.677109 63.89490
#> 9  47.119268  22.828014 71.41052
p2 <- Predict(mod, newd, interval="prediction", vcov.=vcov)
all.equal(p1, p2) # the same
#> [1] TRUE

(predict(mod, newd, se=TRUE))
#> $fit
#>          1          2          3          4          5          6          7 
#> -11.546844  -4.213580   3.119684  10.452948  17.786212  25.119476  32.452740 
#>          8          9 
#>  39.786004  47.119268 
#> 
#> $se.fit
#>         1         2         3         4         5         6         7         8 
#> 1.9662292 1.4938511 1.0750019 0.7988559 0.8241457 1.1308251 1.5610312 2.0379832 
#>         9 
#> 2.5354361 
#> 
#> $df
#> [1] 246
#> 
#> $residual.scale
#> [1] 12.06931
#> 
(p3 <- Predict(mod, newd, se=TRUE, vcov.=hccm)) # larger SEs
#> $fit
#>          1          2          3          4          5          6          7 
#> -11.546844  -4.213580   3.119684  10.452948  17.786212  25.119476  32.452740 
#>          8          9 
#>  39.786004  47.119268 
#> 
#> $se.fit
#>         1         2         3         4         5         6         7         8 
#> 2.8225421 1.9026552 1.0414745 0.6003835 1.2031087 2.0846342 3.0091773 3.9466208 
#>         9 
#> 4.8895503 
#> 
#> $df
#> [1] 246
#> 
#> $residual.scale
#> [1] 12.06931
#> 
p4 <- Predict(mod, newd, se=TRUE, vcov.=hccm(mod, type="hc3"))
all.equal(p3, p4) # the same
#> [1] TRUE