subset.model.selection: Subsetting model selection table

subset.model.selectionR Documentation

Subsetting model selection table


Extract a subset of a model selection table.


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



a model.selection object to be subsetted.


logical expressions indicating columns and rows to keep. See subset.


indices specifying elements to extract.


logical value specyfying whether Akaike weights should be normalized across the new set of models to sum to one.

logical value specyfying whether Δ_IC should be calculated for the new set of models (not done by default).


logical, see [.


further arguments passed to [.data.frame (drop).


Unlike the method for data.frame, single bracket extraction with only one index x[i] selects rows (models) 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 with subset, e.g. subset(x, has(a, !b)) will select rows with a and without b (this is equivalent to ! & has can take any number of arguments.

Complex model terms need to be enclosed within curly brackets (e.g {s(a,k=2)}), except for within has. Backticks-quoting is also possible, but then the name must match exactly (including whitespace) the term name as returned by getAllTerms.

Enclosing in I prevents the name from being interpreted as a column name.

To select rows where one variable can be present conditional on the presence of other variables, 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).


A model.selection object containing only the selected models (rows). If columns are selected (via argument select or the second index x[, j]) and not all essential columns (i.e. all except "varying" and "extra") are present in the result, a plain data.frame is returned. Similarly, modifying values in the essential columns with [<-, [[<- or $<- produces a regular data frame.


Kamil Bartoń

See Also

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


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

# 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)

MuMIn documentation built on March 31, 2023, 8:33 p.m.