term2coef: Extract the coefficient names of terms of a model.

Description Usage Arguments Details Value See Also Examples

View source: R/term2coef.R

Description

The function returns the labels of the coefficients of the model. Note: The terms are not identical to the coefficients.

Usage

1
term2coef(model, term, as.list = FALSE)

Arguments

model

a model object.

term

a character vector of term labels.

as.list

logical. Should the result be returned as a list?

Details

model is an object returned by a model fitting function (e.g., lm, aov).

The character string passed to term must not include the intercept ("(Intercept)"). All non-intercept labels in any order are allowed.

Value

either a character vector (if as.list = FALSE) or a list with character vectors (otherwise) with one list element for each element in term.

See Also

coef2term for the inverse function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
require(utils)
 
data(iris)
fit <- lm(Sepal.Length ~ poly(Sepal.Width, 3), data = iris)
summary(fit)
term2coef(fit, "poly(Sepal.Width, 3)")
 
data(warpbreaks)
fit2 <- lm(breaks ~ wool * tension, data = warpbreaks)
summary(fit2)
term2coef(fit2, c("wool", "tension"))
term2coef(fit2, c("wool", "tension"), as.list = TRUE)
term2coef(fit2, c("wool:tension"))

hohenstein/remef documentation built on Jan. 26, 2020, 12:57 a.m.