model.avg(object, ..., beta = FALSE, rank = NULL, rank.args = NULL,
revised.var = TRUE)
model.selection
. See AICc
, e.g. BIC
or QAIC
, may be omitted
if object
is a model list returned by get.models
or a list
of arguments for the rank
function. If one is an expression, an x
within it is substituted
with a current model.par.avg
.averaging
is a list with components:data.frame
with log-likelihood, IC, Delta(IC) and
Akaike weights for the component models.summary
.data.frame
containing
averaged coefficients, unconditional standard error, adjusted SE (if
dfs are available) and z-values (coefficient and SE) and
significance (assuming a normal error distribution).formula
contains only the averaged
coefficients.TRUE
, the standard errors were calculated with the
revised formula (See par.avg
).model.avg
has been tested to work with the fitted objects from the following
modelling functions:
lm
, glm
;
gam
, gamm
(gamm4
(lme
, gls
(lmer
(rlm
, glm.nb
, polr
(multinom
(sarlm
, spautolm
(glmmML
(coxph
, survreg
(unmarkedFit
(model.avg
may be used with a list of models, but also directly with a
model.selection
object returned by dredge
. In the latter case,
the models from the model selection table are evaluated (with a call to
get.models
) prior to averaging.
A warning is given if the subset
argument is not provided, and the
default delta <= 4<="" code=""> will be used.
rank
is found by a call to match.fun
and typically is
specified as a function or a symbol (e.g. a back-quoted name) or a character
string specifying a function to be searched for from the environment of the
call to lapply. rank
must be a function able to accept model as a
first argument and must always return a scalar.
Several standard methods for fitted model objects exist for class
averaging
, including
summary
, predict
,
coef
, confint
, formula
,
residuals
, vcov
.
The coef
method a accepts argument full
, if set to TRUE
the
full model-averaged coefficients are returned, rather than subset-averaged
ones.
logLik
returns a list of logLik
objects
for the component models.
par.avg
for more details of model averaged parameter
calculation.dredge
, get.models
AICc
has examples of averaging models fitted by REML.
modavg
in package coef.glmulti
in package
# Example from Burnham and Anderson (2002), page 100:
data(Cement)
fm1 <- lm(y ~ ., data = Cement)
(ms1 <- dredge(fm1))
#models with delta.aicc < 4
summary(model.avg(get.models(ms1, subset = delta < 4))) # get averaged coefficients
#or as a 95\% confidence set:
confset.95p <- get.models(ms1, cumsum(weight) <= .95)
avgmod.95p <- model.avg(confset.95p) # get averaged coefficients
confint(avgmod.95p)
# The same result
model.avg(ms1, cumsum(weight) <= .95)
# using BIC (Schwarz's Bayesian criterion) to rank the models
BIC <- function(x) AIC(x, k=log(length(residuals(x))))
model.avg(confset.95p, rank=BIC)
# the same result, using AIC directly, with argument k
# 'x' in a quoted 'rank' argument is substituted with a model object
# (in this case it does not make much sense as the number of observations is
# common to all models)
model.avg(confset.95p, rank=AIC, rank.args=alist(k=log(length(residuals(x)))))
Run the code above in your browser using DataLab