Weights.Rd
Calculate, extract or set normalized model likelihoods (‘Akaike weights’).
Weights(x)
Weights(x) <- value
a numeric vector of any information criterion (such as
, , , ) values, or objects returned by functions like
AIC
. There are also methods for extracting ‘Akaike weights’ from
"model.selection"
or "averaging"
objects.
numeric, the new weights for the "averaging"
object or
NULL
to reset the weights based on the original used.
The assigned value
need not sum to one, but if they are all zero, the
result will be invalid (NaN
).
‘Akaike weights’, _iXw_i, of a model i can be interpreted as the probability that the model is the best (approximating) model given the data and the set of all models considered. The weights are calculated as:
_i = (_i/2)_r=1^R(_r/2) X w_i = exp(Delta_i / 2) / (sum(exp(Delta_r / 2))
where i is the difference of the i-th model relative to the smallest value in the set of R models.
The replacement version of Weights
can assign new weights to an
"averaging"
object, affecting coefficient values and the order of
component models. Upon assignment, the weights are normalised to sum to one.
For the extractor, a numeric vector of normalized likelihoods.
Assigning new weights changes the model order accordingly, so reassigning
weights to the same object must take this new order into account, otherwise
the averaged coefficients will be calculated incorrectly. To avoid this, either
re-set the model weights by assigning NULL
, or sort the new weights
using the (decreasing) order of the previously assigned weights.
sw, weighted.mean
armWeights, bootWeights, BGWeights, cos2Weights, jackknifeWeights and stackingWeights can be used to produce various kinds of model weights.
Not to be confused with weights, which extracts fitting weights from model objects.
fm1 <- glm(Prop ~ dose, data = Beetle, family = binomial)
fm2 <- update(fm1, . ~ . + I(dose^2))
fm3 <- update(fm1, . ~ log(dose))
fm4 <- update(fm3, . ~ . + I(log(dose)^2))
round(Weights(AICc(fm1, fm2, fm3, fm4)), 3)
#> model weights
#> [1] 0.312 0.329 0.044 0.314
am <- model.avg(fm1, fm2, fm3, fm4, rank = AICc)
coef(am)
#> (Intercept) dose I(dose^2) log(dose) I(log(dose)^2)
#> 149.56958558 -0.20303260 0.00726326 -219.93533091 32.74938293
# Assign equal weights to all models:
Weights(am) <- rep(1, 4) # assigned weights are rescaled to sum to 1
Weights(am)
#> unknown model weights
#> [1] 0.25 0.25 0.25 0.25
coef(am)
#> (Intercept) dose I(dose^2) log(dose) I(log(dose)^2)
#> 105.86553402 -0.19150628 0.00726326 -119.12081828 32.74938293
# Assign dummy weights:
wts <- c(2,1,4,3)
Weights(am) <- wts
coef(am)
#> (Intercept) dose I(dose^2) log(dose) I(log(dose)^2)
#> 27.13729609 -0.04582424 0.00726326 -52.21611191 32.74938293
# Component models are now sorted according to the new weights.
# The same weights assigned again produce incorrect results!
Weights(am) <- wts
coef(am) # wrong!
#> (Intercept) dose I(dose^2) log(dose) I(log(dose)^2)
#> 141.62459048 -0.33718833 0.00726326 -186.02552464 32.74938293
#
Weights(am) <- NULL # reset to original model weights
Weights(am) <- wts
coef(am) # correct
#> (Intercept) dose I(dose^2) log(dose) I(log(dose)^2)
#> 27.13729609 -0.04582424 0.00726326 -52.21611191 32.74938293