Description Usage Arguments Details Value Note See Also Examples
View source: R/extract_ranef.R
Extract what would be the random effects from a mixed model from
a gam object. Assumes an mgcv model of the form gam(... + s(g, bs='re'))
.
1 | extract_ranef(model, re = NULL, ci_level = 0.95, digits = 3)
|
model |
A gam or bam model |
re |
Filter results to a specific random effect/grouping variable. |
ci_level |
Level for the confidence interval. Must be between 0 and 1. |
digits |
Rounding for the output. |
Returns a data frame of the the component
type, the estimated
random effect re
, the estimated se
, and approximate lower
and upper
bounds. Note that the standard errors are Bayesian
estimates (see gamObject
, specifically type Vp
). The re
will only reflect smooth terms whose basis function is 're', i.e. of class
random.effect
. Others will be ignored.
A tibble
or data frame with the random effect,
its standard error, and its lower and upper bounds. The bounds are based
on a simple normal approximation using the standard error.
mgcv
strips the level names for 're' smooth terms, so this attempts
to get them back. This may not work under every circumstance, but the
attempt is made to extract the names of random effect groups based on how
they are ordered in the data (which is how the model matrix would be
constructed), and in the case of random slopes, detect that second variable
in the 're' specification would be the grouping variable. This will not
work for continuous x continuous smooths of type 're', but I can't think of
a reason why you'd use that given your other options with mgcv
.
1 2 3 4 5 6 7 8 9 10 11 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.