makeFormulae {statisfactory}R Documentation

Make all possible formula

Description

This functions creates a list of formulae that contain all possible linear, quadratic, and two-way interaction terms from individual terms in an object of class formula. The formulae respect marginality conditions (i.e., they will always include lower-order terms if higher-order terms are included in a formula). Note that if there are more than several terms (i.e., >=3) and interactions and/or quadratic terms are desired, then formula generation may take a long time.

Usage

makeFormulae(
  formula,
  intercept = TRUE,
  interceptOnly = TRUE,
  linearOnly = TRUE,
  quad = TRUE,
  ia = TRUE,
  verboten = NULL,
  verbotenCombos = NULL,
  minTerms = NULL,
  maxTerms = NULL,
  returnFx = stats::as.formula,
  verbose = FALSE
)

Arguments

formula

A formula object with just linear terms.

intercept

Logical, if TRUE (default) then all models include an intercept. If FALSE then then formula will specify that regression occurs through the origin (e.g., y ~ -1 + etc.)

interceptOnly

Logical, if TRUE then an intercept-only model is included in final set.

linearOnly

Logical, if TRUE (default) then models with only linear terms are included in final set (plus other kinds of models if desired).

quad

Logical, if TRUE (default), then include quadratic terms.

ia

Logical, if TRUE (default), then include 2-way interaction terms.

verboten

Character vector of terms that should not appear in the models. Ignored if NULL (default). Note that using this argument only makes sense if interaction or quadratic terms are specified (if you don't a particular term to appear anywhere in the model it will be faster to remove it from formula).

verbotenCombos

List of lists, used to specify specific combinations of terms that should not occur together. See section Details below. Ignored if NULL (default).

minTerms

Either a positive integer representing the minimum number of terms required to be in a model, or NULL (default) in which case the smallest model can have just one term.

maxTerms

Either a positive integer representing the maximum number of terms allowed to be in a model, or NULL (default) in which case there is no practical limit on the number of terms in a model.

returnFx

Function used to generate the class of the output objects. Sensible functions in include as.formula (default) or as.character.

verbose

Logical, if TRUE then display progress. Default is FALSE.

Details

The argument verbotenCombos 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:

Quadratic terms and interaction terms can also be used, so:

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 will be none after the first set is removed).

Value

A vector of formulae.

Examples


makeFormulae(y ~ x1 + x2 + x3, maxTerms=3)
makeFormulae(y ~ x1 + x2 + x3, ia=FALSE, maxTerms=3)
verboten <- c('x1:x2', 'I(x1^2)')
makeFormulae(y ~ x1 + x2 + x3, verboten=verboten, maxTerms=3)

makeFormulae(y ~ x1 + x2 + x3, maxTerms=3)
verbotenCombos <- list(list('x1', 'x2', TRUE, TRUE))
makeFormulae(y ~ x1 + x2 + x3, verbotenCombos=verbotenCombos, maxTerms=3)


[Package statisfactory version 1.0.4 Index]