Learn R Programming

BMSC (version 0.2.1)

createFormula: Create a formula with interactions and polynomials up to a desired order

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

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

Run this code
# NOT RUN {
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))
# }

Run the code above in your browser using DataLab