makeFormulae: Make all possible formula

View source: R/makeFormulae.r

makeFormulaeR Documentation

Make all possible formula

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). You can use this argument, for example, to exclude specific interactions (e.g., 'x1:x2', but also include the converse, 'x2:x1'), or power terms (e.g., 'I(x1^2)'). Note that to ensure proper matching, you need to use a double backslash in front of each parenthesis and caret ((^)) character.} \item{verbotenCombos}{List of lists: Used to specify specific combinations of terms that should not occur together. See Details below. Ignored if NULL (default).} \item{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.} \item{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.} \item{returnFx}{Function used to generate the class of the output objects. Sensible functions in include as.formula (default) or as.character.} \item{verbose}{Logical: If TRUE then display progress. Default is FALSE.} } { A vector of formulae. } { 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. } { 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:

  • 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 occurrs in any term in the model.

  • verbotenCombos=list(list('x1', 'x2', TRUE, FALSE)): Removes any term with x2 if the linear term x1 occurrs in the model.

  • verbotenCombos=list(list('x1', 'x2', FALSE, FALSE)): Removes any term with x2 if any term has x1.

Quadratic terms and interaction terms can also be used, 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) if x1 occurs in the model.

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). } { 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) }


adamlilith/statisfactory documentation built on Jan. 3, 2024, 10:37 p.m.