Learn R Programming

MuMIn (version 1.5.0)

predict.averaging: Predict Method for the Averaged Model

Description

Model-averaged predictions with optional standard errors.

Usage

## S3 method for class 'averaging':
predict(object, newdata = NULL, se.fit = FALSE,
	interval = NULL, type = c("link", "response"), full = FALSE, ...)

Arguments

object
An object returned by model.avg
newdata
An optional data frame in which to look for variables with which to predict. If omitted, the fitted values are used.
se.fit
logical, indicates if standard errors should be returned. This has any effect only if the predict methods for each of the component models support it.
interval
Currently not used
type
Predictions on response scale are only possible if all component models use the same family. See predict.glm.
full
If TRUE, the full model averaged coefficients are used (only if se.fit = FALSE and the component objects are a result of lm).
...
Arguments to be passed to respective predict method (e.g. level for lme model).

Value

  • If se.fit = FALSE, a vector of predictions. If se = TRUE, a list with components: fit containing the predictions, and se.fit with the estimated standard errors.

encoding

utf-8

Details

For an ordinary linear model, the predicted values can be averaged either using the subset-averaged coefficients (if argument full = FALSE, the default), or the full averaged coefficients. In other cases the prediction is obtained by calling predict on each component model and weighted averaging the results, which corresponds to assuming that missing coefficients are averaged only over are averaged over a subset of models wherein a variable appears. See Note in model.avg.

Predictions on the response scale from generalized models are calculated by averaging predictions of each model on the link scale, followed by inverse transformation.

See Also

model.avg See par.avg for details of model-averaged parameter calculation.

Examples

Run this code
require(graphics)

# Example from Burnham and Anderson (2002), page 100:
data(Cement)
fm1 <- lm(y ~ ., data = Cement)

ms1 <- dredge(fm1)
confset.95p <- get.models(ms1, subset=cumsum(weight) <= .95)
avgm <- model.avg(confset.95p)

nseq <- function(x, len=length(x)) seq(min(x, na.rm=TRUE),
    max(x, na.rm=TRUE), length=len)

# New predictors: X1 along the range of original data, other
# variables held constant at their means
newdata <- as.data.frame(lapply(lapply(Cement[1:5], mean), rep, 25))
newdata$X1 <- nseq(Cement$X1, nrow(newdata))

# Predictions from each of the models in a set:
pred <- sapply(confset.95p, predict, newdata=newdata)


pred <- cbind(pred,
    averaged.subset = predict(avgm, newdata),
    averaged.full = predict(avgm, newdata, full = TRUE))

matplot(x=newdata$X1, y=pred, type="l", lwd=c(rep(1,ncol(pred)-2), 2, 2),
    xlab="X1", ylab="y", col=c(3:7, 1,2), lty=c(1:5,1,1))

legend("topleft",
    legend=c(lapply(confset.95p, formula),
        paste(c("subset", "full"), "averaged")),
    col=c(3:7, 1,2), lty=c(1:5,1,1), lwd=c(rep(1,ncol(pred)-2), 2, 2), cex = .75)

Run the code above in your browser using DataLab