| model_terms | R Documentation |
Returns the names of any terms in a model, without needing to call
summary(). The list of model terms is especially useful when predicting
from a mgcv::gam() model using the exclude or terms argument of
mgcv::predict.gam() or mgcv::predict.bam().
model_terms(object, ...)
## S3 method for class 'gam'
model_terms(object, ...)
## S3 method for class 'gamm'
model_terms(object, ...)
## S3 method for class 'gamm4'
model_terms(object, ...)
## S3 method for class 'lm'
model_terms(object, ...)
object |
a fitted model. |
... |
arguments to be passed to other methods; not currently used. |
From the point of view of gratia, models contain two types of term:
parametric terms, and
smooth terms.
If we consider the formula y ~ fac + s(x2, by = fac) + s(x0), for a factor
fac with three levels, there are seven terms in the model:
the model constant term, with name "(Intercept)",
the parametric factor term, with names
fac2,
fac3,
the univariate smooth of x0, named "s(x0)", and
the three factor-by smooths with names
"s(x2):fac1",
"s(x2):fac2", and
"s(x2):fac3".'
model_terms() will return a vector of those names.
A character vector of model terms.
load_mgcv()
# simulate data
df <- data_sim("eg4", n = 400, dist = "normal", scale = 2, seed = 1)
# fit model
m <- gam(y ~ fac + s(x2, by = fac) + s(x0),
data = df, method = "REML")
# return the names of terms in this model
model_terms(m)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.