This function takes as an argument a list of character strings representing formulae and returns a potentially shortened list without formulae containing certain combinations of variables.
.removeVerbotenVariableCombos(forms, verbotenCombos)
A list of character elements representing formulae.
List of characters each representing a formula.
Either NULL
(default) in which case forms
is returned without any manipulation. Alternatively, this argument can be used to specify variables or terms that should not occur in the same formula. The argument verbotenCombos
is composed of a list of lists. Each sublist comprises names of two variables or terms stated as characters followed by two logical values (TRUE
/FALSE
). The second variable/term is removed from the model if the first is in the model. If the first logical value is TRUE
then the second variable/term is removed if the first variable appears alone in the formula (e.g., not in an interaction with another variable). If the first logical value is FALSE
then the second variable/term is removed if the first variable/term appears in any term (e.g., as an interaction with another term).
Examples:
verbotenCombos=list(list('x1', 'x2', TRUE, TRUE))
: Removes x2
if x1
occurs in the model as a linear term.
verbotenCombos=list(list('x1', 'x2', FALSE, TRUE))
: Removes the linear term x2
if x1
occurred in any term in the model.
verbotenCombos=list(list('x1', 'x2', TRUE, FALSE))
: Removes any term with x2
if the linear term x1
occurred in the model.
verbotenCombos=list(list('x1', 'x2', FALSE, FALSE))
: Removes any term with x2
if any term had x1
.
Quadratic terms and interaction terms can also be stated, so:
verbotenCombos=list(list('x1', 'x1:x2', TRUE, TRUE))
: Removes x1:x2
if x1
were in the model.
verbotenCombos=list(list('x1', 'I(x2^2)', TRUE, TRUE))
: Removes I(x2^2)
.
Note that inexact matching can remove terms incorrectly if inexact matches exist between names of terms or variables. For example, if using an inexact match, then verbotenCombos(list('x1', 'x2', FALSE, FALSE))
will find any term that has an x1
(e.g., x11
) and if it exists, remove any term with an x2
(e.g., x25
). Note that reciprocally removing predictors makes little sense since, for example list(list('x1', 'x2', FALSE, FALSE), list('x2', 'x1', FALSE, FALSE))
removes all formulae with x2
if x1
appears then tries to find any models with x2
that have x1
(of which there are none).