Models are fitted through repeated evaluation of modified call extracted from
the global.model
(in a similar fashion as with update
). This
approach, while robust in that it can be applied to most model types through the
usual formula interface, may have considerable computational overhead.
Note that the number of combinations grows exponentially with the number of
predictors (2<U+207F>, less when
interactions are present, see below).
The fitted model objects are not stored in the result. To get (possibly a subset of)
the models, use get.models
on the object returned by dredge
.
Another way of getting all the models is to run
lapply(dredge(..., evaluate = FALSE), eval)
,
which avoids fitting the models twice.
For a list of model types that can be used as a global.model
see
the list of supported models. Modelling functions not storing
call
in their result should be evaluated via the wrapper function
created by updateable
.
Information criterion
rank
is found by a call to match.fun
and may be specified as a
function or a symbol or a character string specifying
a function to be searched for from the environment of the call to dredge
.
The function rank
must accept a model object as its first argument and
always return a scalar.
Interactions
By default, marginality constraints are respected, so “all possible
combinations” include only those containing interactions with their
respective main effects and all lower-order terms.
However, if global.model
makes an exception to this principle (e.g. due
to a nested design such as a / (b + d)
), this will be reflected in the
subset models.
Subsetting
There are three ways to constrain the resulting set of models: setting limits to
the number of terms in a model with m.lim
, binding the
term(s) to all models with fixed
, and more complex rules can be applied
using argument subset
. To be included in the selection table, the model
formulation must satisfy all these conditions.
subset
can take either a form of an expression or a matrix.
The latter should be a lower triangular matrix with logical values, where
columns and rows correspond to global.model
terms. Value
subset["a", "b"] == FALSE
will exclude any model containing both terms
a and b. demo(dredge.subset)
has examples of using the
subset
matrix in conjunction with correlation matrices to exclude models
containing collinear predictors.
Term names appearing in fixed
and subset
must be given in the
exact form as returned by getAllTerms(global.model)
, which can differ
from the original term names (e.g. the interaction term components are ordered
alphabetically).
In the form of expression
, the argument subset
acts in a similar
fashion to that in the function subset
for data.frames
: model
terms can be referred to by name as variables in the expression, with the
difference being that are interpreted as logical values (i.e. equal to
TRUE
if the term exists in the model).
The expression can contain any of the global.model
term names, as well as
names of the varying
list items. global.model
term names take
precedence when identical to names of varying
, so to avoid ambiguity
varying
variables in subset
expression should be enclosed in
V()
(e.g. V(family) == "Gamma"
assuming that
varying
is something like list(family =
c("Gamma", ...))
).
If item names in varying
are missing, the items themselves are coerced to
names. Call and symbol elements are represented as character values (via
deparse
), and everything except numeric, logical, character and
NULL
values is replaced by item numbers (e.g. varying =
list(family =
list(..., Gamma)
should be referred to as
subset = V(family) == 2
. This can quickly become confusing, therefore it
is recommended to use named lists. demo(dredge.varying)
provides examples.
The with(x)
and with(+x)
notation indicates, respectively, any and
all interactions including the main effect term x
. This is only effective
with marginality exceptions. The extended form with(x, order)
allows for
specifying the order of interaction of terms which x
is part of. For
instance, with(b, 2:3)
selects models with at least one second- or
third-order interaction of the variable b
. The second (positional)
argument is coerced to an integer vector. The “dot” notation .(x)
is
an alias for with
.
The special variable `*nvar*`
(backtick-quoted), in the subset
expression is equal to the number of
terms in the model (not the number of estimated parameters).
To make the inclusion of a model term conditional on the presence of another one,
the function dc
(“dependency chain”) can be used in
the subset
expression. dc
takes any number of term names as
arguments, and allows a term to be included only if all preceding ones
are also present (e.g. subset = dc(a, b, c)
allows for models a
,
a+b
and a+b+c
but not b
, c
, b+c
or
a+c
).
subset
expression can have a form of an unevaluated call
,
expression
object, or a one-sided formula
. See ‘Examples’.
Compound model terms (such as interactions, ‘as-is’ expressions within
I()
or smooths in gam
) should be enclosed within curly brackets
(e.g. {s(x,k=2)}
), or backticks (like non-syntactic
names, e.g.
`s(x, k = 2)`
), unless they are arguments to .
or dc
.
Backticks-quoted names must match exactly (including whitespace) the term names
as returned by getAllTerms
.
subset
expression syntax summary
a & b
indicates that model terms a and b must be
present (see Logical Operators)
{log(x,2)}
or `
log(x, 2)
`
represent a complex
model term log(x, 2)
V(x)
represents a varying
item x
with(x)
indicates that at least one term containing the main
effect term x must be present
with(+x)
indicates that all the terms containing the main
effect term x must be present
with(x, n:m)
indicates that at least one term containing an
n-th to m-th order interaction term of x must be present
dc(a, b, c,...)
‘dependency chain’: b is allowed only
if a is present, and c only if both a and b are
present, etc.
`*nvar*`
the number of terms in the model.
To simply keep certain terms in all models, use of argument fixed
is much
more efficient. The fixed
formula is interpreted in the same manner
as model formula and so the terms must not be quoted.
Missing values
Use of na.action = "na.omit"
(R's default) or "na.exclude"
in
global.model
must be avoided, as it results with sub-models fitted to
different data sets if there are missing values. An error is thrown if it is
detected.
It is a common mistake to give na.action
as an argument in the call
to dredge
(typically resulting in an error from the rank
function to which the argument is passed through ‘…’), while the
correct way
is either to pass na.action
in the call to the global model or to set
it as a global option.
Intercept
If present in the global.model
, the intercept will be included in all
sub-models.
Methods
There are subset
and
plot
methods, the latter creates a
graphical representation of model weights and per-model term sum of weights.
Coefficients can be extracted with coef
or coefTable
.