ols.predict function

Predictions in a Linear Model

Predictions in a Linear Model

Calculates the predicted values of a linear model based on specified values of the exogenous variables. Optionally the estimated variance of the prediction error is returned.

ols.predict(mod, data = list(), xnew, antilog = FALSE, details = FALSE)

Arguments

  • mod: model object generated by ols() or lm().
  • data: name of data frame to be specified if mod is a formula.
  • xnew: (T x K) matrix of new values of the exogenous variables, for which a prediction should be made, where K is the number of exogenous variables in the model T is the number of predictions to be made. If xnew is not specified, the fitted values are returned.
  • antilog: logical value which indicates whether to re-transform the predicted value of a log transformed dependent variable back into original units.
  • details: logical value, if specified as TRUE, a list is returned, which additionally includes the estimated variance of the prediction error (var.pe), estimated variance of the error term (sig.squ), and the estimated sampling error (smpl.err).

Returns

A list object including:

pred.valthe predicted values.
xnewvalues of predictor at which predictions should be evaluated.
var.peestimated variance of prediction error.
sig.squestimated variance of error term.
smpl.errestimated sampling error.
modthe model estimated (for internal purposes)

Examples

## Estimate logarithmic model fert.est <- ols(barley ~ phos + nit, data = log(data.fertilizer)) ## Set new x data my.mat = cbind(x1 = log(c(6,3,9)), x2 = log(c(5,3,10))) ## Returns fitted values ols.predict(fert.est) ## Returns predicted values at new x-values ols.predict(fert.est, xnew = my.mat) ## Returns re-transformed predicted values and est. var. of pred. error ols.predict(fert.est, xnew = my.mat, antilog = TRUE, details = TRUE)
  • Maintainer: Soenke Hoffmann
  • License: GPL (>= 3)
  • Last published: 2024-12-20