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.val
the predicted values.
xnew
values of predictor at which predictions should be evaluated.
var.pe
estimated variance of prediction error.
sig.squ
estimated variance of error term.
smpl.err
estimated sampling error.
mod
the model estimated (for internal purposes)
Examples
## Estimate logarithmic modelfert.est <- ols(barley ~ phos + nit, data = log(data.fertilizer))## Set new x datamy.mat = cbind(x1 = log(c(6,3,9)), x2 = log(c(5,3,10)))## Returns fitted valuesols.predict(fert.est)## Returns predicted values at new x-valuesols.predict(fert.est, xnew = my.mat)## Returns re-transformed predicted values and est. var. of pred. errorols.predict(fert.est, xnew = my.mat, antilog =TRUE, details =TRUE)