Extract term names from a fitted model object.
xNam(mod, intercept = TRUE, aliased = TRUE, list = FALSE, env = NULL)
mod | A fitted model object, or a list or nested list of such objects. |
---|---|
intercept | Logical, whether the intercept should be included. |
aliased | Logical, whether names of aliased terms should be included (see Details). |
list | Logical, whether names should be returned as a list, with all multi-coefficient terms grouped under their main term names. |
env | Environment in which to look for model data (used to construct the
model frame). Defaults to the |
A character vector or list/nested list of term names.
Extract term names from a fitted model. Names of terms for which
coefficients cannot be estimated are also included if aliased = TRUE
(default). These may be terms which are perfectly correlated with other
terms in the model, so that the model design matrix is rank deficient.
# Term names from Shipley SEM m <- shipley.sem xNam(m)#> $DD #> [1] "(Intercept)" "lat" #> #> $Date #> [1] "(Intercept)" "DD" #> #> $Growth #> [1] "(Intercept)" "Date" #> #> $Live #> [1] "(Intercept)" "Growth" #>xNam(m, intercept = FALSE)#> $DD #> [1] "lat" #> #> $Date #> [1] "DD" #> #> $Growth #> [1] "Date" #> #> $Live #> [1] "Growth" #># Model with different types of predictor (some multi-coefficient terms) d <- data.frame( y = rnorm(100), x1 = rnorm(100), x2 = as.factor(rep(c("a", "b", "c", "d"), each = 25)), x3 = rep(1, 100) ) m <- lm(y ~ poly(x1, 2) + x2 + x3, data = d) xNam(m)#> [1] "(Intercept)" "poly(x1, 2)1" "poly(x1, 2)2" "x2b" "x2c" #> [6] "x2d" "x3"xNam(m, aliased = FALSE) # drop term that cannot be estimated (x3)#> [1] "(Intercept)" "poly(x1, 2)1" "poly(x1, 2)2" "x2b" "x2c" #> [6] "x2d"xNam(m, aliased = FALSE, list = TRUE) # names as list#> $`(Intercept)` #> [1] "(Intercept)" #> #> $`poly(x1, 2)` #> [1] "poly(x1, 2)1" "poly(x1, 2)2" #> #> $x2 #> [1] "x2b" "x2c" "x2d" #>