These methods tidy the coefficients of mixed effects models, particularly
responses of the merMod
class
# S3 method for glmmTMB
tidy(
x,
effects = c("ran_pars", "fixed"),
component = c("cond", "zi"),
scales = NULL,
ran_prefix = NULL,
conf.int = FALSE,
conf.level = 0.95,
conf.method = "Wald",
exponentiate = FALSE,
...
)
# S3 method for glmmTMB
augment(x, data = stats::model.frame(x), newdata = NULL, ...)
# S3 method for glmmTMB
glance(x, ...)
An object of class merMod
, such as those from lmer
,
glmer
, or nlmer
A character vector including one or more of "fixed" (fixed-effect parameters), "ran_pars" (variances and covariances or standard deviations and correlations of random effect terms) or "ran_vals" (conditional modes/BLUPs/latent variable estimates)
which component to extract (e.g. cond
for conditional effects (i.e., traditional fixed effects); zi
for zero-inflation model; disp
for dispersion model
scales on which to report the variables: for random effects, the choices are ‘"sdcor"’ (standard deviations and correlations: the default if scales
is NULL
) or ‘"varcov"’ (variances and covariances). NA
means no transformation, appropriate e.g. for fixed effects; inverse-link transformations (exponentiation
or logistic) are not yet implemented, but may be in the future.
a length-2 character vector specifying the strings to use as prefixes for self- (variance/standard deviation) and cross- (covariance/correlation) random effects terms
whether to include a confidence interval
confidence level for CI
method for computing confidence intervals (see confint.merMod
)
whether to exponentiate the fixed-effect coefficient estimates and confidence intervals (common for logistic regression); if TRUE
, also scales the standard errors by the exponentiated coefficient, transforming them to the new scale
extra arguments (not used)
original data this was fitted on; if not given this will attempt to be reconstructed
new data to be used for prediction; optional
All tidying methods return a tibble
.
The structure depends on the method chosen.
tidy
returns one row for each estimated effect, either
with groups depending on the effects
parameter.
It contains the columns
the group within which the random effect is being estimated: NA
for fixed effects
level within group (NA
except for modes)
term being estimated
estimated coefficient
standard error
t- or Z-statistic (NA
for modes)
P-value computed from t-statistic (may be missing/NA)
augment
returns one row for each original observation,
with columns (each prepended by a .) added. Included are the columns
predicted values
residuals
predicted values with no random effects
glance
returns one row with the columns
the square root of the estimated residual variance
the data's log-likelihood under the model
the Akaike Information Criterion
the Bayesian Information Criterion
deviance
When the modeling was performed with na.action = "na.omit"
(as is the typical default), rows with NA in the initial data are omitted
entirely from the augmented data frame. When the modeling was performed
with na.action = "na.exclude"
, one should provide the original data
as a second argument, at which point the augmented data will contain those
rows (typically with NAs in place of the new columns). If the original data
is not provided to augment
and na.action = "na.exclude"
, a
warning is raised and the incomplete rows are dropped.
zero-inflation parameters (including the intercept) are reported on the logit scale
if (require("glmmTMB") && require("lme4")
## &&
## make sure package versions are OK
## checkDepPackageVersion(dep_pkg = "TMB",
## this_pkg = "glmmTMB",
## warn = FALSE) &&
## checkDepPackageVersion(dep_pkg = "Matrix",
## this_pkg = "TMB",
## warn = FALSE)
)
{
data("sleepstudy",package="lme4")
## original model:
if (FALSE) {
lmm1 <- glmmTMB(Reaction ~ Days + (Days | Subject), sleepstudy)
}
## load stored object
L <- load(system.file("extdata","glmmTMB_example.rda",package="broom.mixed"))
for (obj in L) {
assign(obj, glmmTMB::up2date(get(obj)))
}
tidy(lmm1)
tidy(lmm1, effects = "fixed")
tidy(lmm1, effects = "fixed", conf.int=TRUE)
tidy(lmm1, effects = "fixed", conf.int=TRUE, conf.method="uniroot")
## FIX: tidy(lmm1, effects = "ran_vals", conf.int=TRUE)
head(augment(lmm1, sleepstudy))
glance(lmm1)
## original model:
## glmm1 <- glmmTMB(incidence/size ~ period + (1 | herd),
## data = cbpp, family = binomial, weights=size)
tidy(glmm1)
tidy(glmm1, effects = "fixed")
tidy(glmm1, effects = "fixed", exponentiate=TRUE)
tidy(glmm1, effects = "fixed", conf.int=TRUE, exponentiate=TRUE)
head(augment(glmm1, cbpp))
head(augment(glmm1, cbpp, type.residuals="pearson"))
glance(glmm1)
if (FALSE) {
## profile CIs - a little bit slower but more accurate
tidy(glmm1, effects = "fixed", conf.int=TRUE, exponentiate=TRUE, conf.method="profile")
}
}
#> Loading required package: glmmTMB
#> Warning: there is no package called ‘glmmTMB’