subformula: Calculate Subformulas

Description Usage Arguments Details Value Examples

View source: R/subformula.R

Description

A formula sub is a subformula of formula if (i) all the terms on the right hand side of sub are terms of formula and (ii) their left hand sides are identical. subformula finds every subformula of formula that contains each term in protected.

Usage

1
subformula(formula, protected = NULL, data = NULL)

Arguments

formula

an object of class "formula" (or one that can be coerced to that class via formula).

protected

a vector or formula specifying which covariates are protected. Protected formulas appear in all subformulas.

data

an optional data frame (or object coercible by as.data.frame to a data frame). Used to fill out formulas as y ~ ..

Details

Protected terms will appear in every subformula. If the supplied formula includes the term 0 or -1, none of the subformulas will include the intercept. Otherwise, the intercept will be interpreted as being protected. If formula is is coerced to a formula object, its associated environment will be NULL. All subformulas will inherit their .Environment attribute from formula.

Value

subformula returns a list of formula objects.

Examples

1
2
3
subformula(z ~ x + y)
subformula(y ~ x + y + y^2, protected = ~ x)
subformula(y ~ x + y + t + I(t^2), protected = c("x","I(t^2)"))

Example output

[[1]]
z ~ 1

[[2]]
z ~ x

[[3]]
z ~ y

[[4]]
z ~ x + y

[[1]]
y ~ x

[[2]]
y ~ x + y

[[1]]
y ~ x + I(t^2)

[[2]]
y ~ x + y + I(t^2)

[[3]]
y ~ x + t + I(t^2)

[[4]]
y ~ x + y + t + I(t^2)

subformula documentation built on Nov. 16, 2019, 1:07 a.m.