# Example from Burnham and Anderson (2002), page 100:
data(Cement)
fm1 <- lm(y ~ ., data = Cement)
dd <- dredge(fm1)
subset(dd, delta < 4)
# Visualize the model selection table:
if(require(graphics))
plot(dd)
# Model average models with delta AICc < 4
model.avg(get.models(dd, subset = delta < 4))
#or as a 95\% confidence set:
confset.95p <- get.models(dd, cumsum(weight) <= .95)
model.avg(confset.95p) # get averaged coefficients
#'Best' model
summary(confset.95p[[1]])
# Examples of using 'subset':
# exclude models containing both X1 and X2
dredge(fm1, subset = !(X1 & X2))
# keep only models containing X3
dredge(fm1, subset = ~ X3) # subset as a formula
dredge(fm1, subset = expression(X3)) # subset as expression object
# the same, but more effective:
dredge(fm1, fixed = "X3")
#Reduce the number of generated models, by including only those with
# up to 2 terms (and intercept)
dredge(fm1, m.max = 2)
# Add R^2 and F-statistics, use the 'extra' argument
dredge(fm1, m.max = 1, extra = c("R^2", F = function(x) summary(x)$fstatistic[[1]]))
# with summary statistics:
dredge(fm1, m.max = 1, extra = list(
"R^2", "*" = function(x) {
s <- summary(x)
c(Rsq = s$r.squared, adjRsq = s$adj.r.squared, F = s$fstatistic[[1]])
})
)
# with other information criterions:
# there is no BIC in R < 2.13.0, so need to add it:
if(!exists("BIC", mode="function"))
BIC <- function(object, ...) AIC(object, k = log(length(resid(object))))
dredge(fm1, m.max = 1, extra = alist(AIC, BIC, ICOMP, Cp))
Run the code above in your browser using DataLab