createFormula: Create a formula with interactions and polynomials up to a...

Description Usage Arguments Value Examples

View source: R/createFormula.R

Description

Creates a formula with interactions and polynomials up to a desired order. If the input formula already includes interactions, exponents or other functions (e.g., sqrt), they are ignored.

Usage

1
2
createFormula(formula, maxExponent = 1, interactionDepth = 1,
  intercept = TRUE)

Arguments

formula

formula object: formula object without exponents or interactions. If formula is not of class formula, it is turned into one.

maxExponent

positive integer: highest exponent included in the formula. Default is 1, e.g., only linear effects.

interactionDepth

positive integer: maximum order of interaction. Default is 1, e.g., only main effects (no interactions).

intercept

logical: include intercept or not?

Value

A formula containing the original independent variables and their polynomials and interactions.

Examples

1
2
3
4
5
createFormula("y ~ x1 + x2", 2, 3)
createFormula(as.formula("y ~ x1 + x2"), interactionDepth = 2)

carFormula <- createFormula("mpg ~ cyl + disp + drat", 2, 3)
summary(lm(carFormula, mtcars))

BMSC documentation built on Aug. 2, 2019, 5:05 p.m.

Related to createFormula in BMSC...