View source: R/extract_random_coefs.R
extract_random_coefs | R Documentation |
Fixed effect + random effects.
extract_random_coefs( model, re = NULL, ci_level = 0.95, digits = 3, component = NULL, ... ) ## S3 method for class 'merMod' extract_random_coefs(model, re = NULL, ci_level = 0.95, digits = 3, ...) ## S3 method for class 'glmmTMB' extract_random_coefs( model, re = NULL, ci_level = 0.95, digits = 3, component = "cond", ... ) ## S3 method for class 'lme' extract_random_coefs(model, re = NULL, ci_level = NULL, digits = 3, ...) ## S3 method for class 'brmsfit' extract_random_coefs( model, re = NULL, ci_level = 0.95, digits = 3, component = NULL, ... ) ## S3 method for class 'stanreg' extract_random_coefs( model, re = NULL, ci_level = 0.95, digits = 3, component = NULL, ... ) ## S3 method for class 'gam' extract_random_coefs(model, re = NULL, ci_level = 0.95, digits = 3, ...) extract_coef( model, re = NULL, ci_level = 0.95, digits = 3, component = NULL, ... ) extract_random_coefficients( model, re = NULL, ci_level = 0.95, digits = 3, component = NULL, ... )
model |
A merMod, nlme, brms, or glmmTMB object |
re |
The name of the grouping variable for the random effects. |
ci_level |
Where possible, confidence level < 1, typically above 0.90. A value of 0 will not report it. Default is .95. Not applicable to nlme objects. |
digits |
Rounding. Default is 3. |
component |
For glmmTMB objects, which of the two components 'cond' or
'zi' to select. Default is 'cond'. For brmsfit objects, this can filter
results to a certain part of the output, e.g. 'sigma' or 'zi' of
distributional models, or a specific outcome of a multivariate model. In
this case |
... |
Other arguments specific to the method. For example |
Returns a data frame with random coefficients, a.k.a. random
intercepts and random slopes, and their standard errors.
r
Note that the standard errors assume independence of the conditional
variance and the fixed-effects variance, thus the standard errors are the
sum of variances for the respective fixed and random effects. See Bolker's
demo
here
and additional discussion at the
GLMM
FAQ. As noted there, this assumption may not be, and likely is not,
appropriate, and if you are really interested in an accurate uncertainty
estimate you should probably use brms
.
Please realize that this functionality is likely only appropriate for
simpler GLMM type models, and is mostly just a shortcut for those settings.
It may work for more complicated situations also, but I don't make any
guarantees. For more complex models that include multiple
outcomes/categories or have other anomalies, this function likely will not
work even if the underlying extract_fixed_effects
and
extract_random_effects
do, as naming conventions are not consistent
enough within the relative packages to deal with this in a general way. I
will continue to look into its feasibility, but don't expect much.
A data frame of the random coefficients and their standard errors.
The nlme
package only provides the coefficients with no estimated
variance, so this function doesn't add to what you get from basic
functionality for those models. In addition, nlme
adds all random
effects to the fixed effects, whereas lme4
and others only add the
effects requested.
For multicomponent glmmTMB
models, e.g. zip, please specify the component
argument.
extract_coef
and extract_random_coefficients
are aliases.
Other extract:
extract_cor_structure()
,
extract_fixed_effects()
,
extract_het_var()
,
extract_model_data()
,
extract_random_effects()
,
extract_vc()
library(lme4) library(mixedup) lmer_1 <- lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy) extract_random_coefs(lmer_1, re = 'Subject') library(glmmTMB) tmb_1 <- glmmTMB(Reaction ~ Days + (1 | Subject), data = sleepstudy) extract_random_coefs(tmb_1, re = 'Subject')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.