Learn R Programming

MuMIn (version 1.13.4)

subset.model.selection: Subsetting model selection table

Description

Return subsets of a model selection table returned by dredge or model.sel.

Usage

## S3 method for class 'model.selection':
subset(x, subset, select, recalc.weights = TRUE,
	recalc.delta = FALSE, ...)
## S3 method for class 'model.selection':
[(x, i, j, recalc.weights = TRUE, recalc.delta = FALSE, ...)

Arguments

x
a model.selection object to be subsetted.
subset,select
logical expressions indicating columns and rows to keep. See subset.
i,j
indices specifying elements to extract.
recalc.weights
logical value specyfying whether Akaike weights should be normalized across the new set of models to sum to one.
recalc.delta
logical value specyfying whether latex{$\Delta_{IC}$}{Δ{Delta}_IC} should be calculated for the new set of models (not done by default).
...
further arguments passed to [.data.frame.

Value

  • A model.selection object containing only the selected models (rows). When columns are selected (arguments select or j are provided), a plain data.frame is returned.

newcommand

\bq

verb

  • `
  • `

code

#1

encoding

utf-8

Details

Unlike the method for data.frame, extracting with only one index (i.e. x[i]) will select rows rather than columns.

To select rows according to presence or absence of the variables (rather than their value), a pseudo-function has may be used, e.g. subset(x, has(a, !b)) will select rows with a and without b (this is equivalent to !is.na(a) & is.na(b)). has can take any number of arguments.

Complex model terms need to be enclosed within either curly brackets or backticks (e.g {s(a,k=2)} | log(b)), except has. Backticks-quoted names must match exactly (including whitespace) the term names as returned by getAllTerms.

To select rows where one variable can be present conditional on the presence of other variable(s), the function dc (dependency chain) can be used. dc takes any number of variables as arguments, and allows a variable to be included only if all the preceding arguments are also included (e.g. subset = dc(a, b, c) allows for models of form a, a+b and a+b+c but not b, c, b+c or a+c).

See Also

dredge, subset and [.data.frame for subsetting and extracting from data.frames.

Examples

Run this code
fm1 <- lm(formula = y ~ X1 + X2 + X3 + X4, data = Cement, na.action = na.fail)

# generate models where each variable is included only if the previous
# are included too, e.g. X2 only if X1 is there, and X3 only if X2 and X1
dredge(fm1, subset = dc(X1, X2, X3, X4))

# which is equivalent to
# dredge(fm1, subset = (!X2 | X1) & (!X3 | X2) & (!X4 | X3))

# alternatively, generate "all possible" combinations
ms0 <- dredge(fm1)
# ...and afterwards select the subset of models
subset(ms0, dc(X1, X2, X3, X4))
# which is equivalent to
# subset(ms0, (has(!X2) | has(X1)) & (has(!X3) | has(X2)) & (has(!X4) | has(X3)))

# Different ways of finding a confidence set of models:
# delta(AIC) cutoff
subset(ms0, delta <= 4, recalc.weights = FALSE)
# cumulative sum of Akaike weights
subset(ms0, cumsum(weight) <= .95, recalc.weights = FALSE)
# relative likelihood
subset(ms0, (weight / weight[1]) > (1/8), recalc.weights = FALSE)

Run the code above in your browser using DataLab