emm()
is a convenient shortcut to compute the estimated
marginal mean, resp. the marginal effect of the model's response
variable, with all independent variables held constant (at
their typical_value
).
emm(model, ci.lvl = 0.95, type = c("fe", "re", "fe.zi", "re.zi", "sim",
"surv", "cumhaz"), typical = "mean", condition = NULL, ...)
A fitted model object, or a list of model objects. Any model
that supports common methods like predict()
, family()
or model.frame()
should work. For ggeffect()
, any model
that is supported by effects should work, and for
ggemmeans()
, all models supported by emmeans should work.
Numeric, the level of the confidence intervals. For ggpredict()
,
use ci.lvl = NA
, if confidence intervals should not be calculated
(for instance, due to computation time). Typically, confidence intervals
based on the standard errors as returned by the predict()
function
are returned, assuming normal distribution (i.e. +/- 1.96 * SE
).
See introduction of this vignette
for more details.
Character, only applies for survival models, mixed effects models
and/or models with zero-inflation. Note: For brmsfit
-models
with zero-inflation component, there is no type = "fe.zi"
nor
type = "re.zi"
; predicted values for MixMod
-models from
GLMMadaptive with zero-inflation component always condition on
the zero-inflation part of the model (see 'Details').
"fe"
Predicted values are conditioned on the fixed effects or conditional
model only (for mixed models: predicted values are on the population-level
and _confidence intervals_ are returned). For instance, for models
fitted with zeroinfl
from pscl, this would return the
predicted mean from the count component (without zero-inflation).
For models with zero-inflation component, this type calls
predict(..., type = "link")
(however, predicted values are
back-transformed to the response scale).
"re"
This only applies to mixed models, and type = "re"
does not
condition on the zero-inflation component of the model. type = "re"
still returns population-level predictions, however, unlike type = "fe"
,
intervals also consider the uncertainty in the variance parameters (the
mean random effect variance, see Johnson et al. 2014 for details)
and hence can be considered as _prediction intervals_. For models
with zero-inflation component, this type calls
predict(..., type = "link")
(however, predicted values are
back-transformed to the response scale).
To get predicted values for each level of the random effects groups, add the
name of the related random effect term to the terms
-argument
(for more details, see this vignette).
"fe.zi"
Predicted values are conditioned on the fixed effects and the zero-inflation
component. For instance, for models fitted with zeroinfl
from pscl, this would return the predicted response (mu*(1-p)
)
and for glmmTMB, this would return the expected value mu*(1-p)
without conditioning on random effects (i.e. random effect variances
are not taken into account for the confidence intervals). For models with
zero-inflation component, this type calls predict(..., type = "response")
.
See 'Details'.
"re.zi"
Predicted values are conditioned on the zero-inflation component and
take the random effects uncertainty into account. For models fitted with
glmmTMB()
, hurdle()
or zeroinfl()
, this would return the
expected value mu*(1-p)
. For glmmTMB, prediction intervals
also consider the uncertainty in the random effects variances. This
type calls predict(..., type = "response")
. See 'Details'.
"sim"
Predicted values and confidence resp. prediction intervals are
based on simulations, i.e. calls to simulate()
. This type
of prediction takes all model uncertainty into account, including
random effects variances. Currently supported models are glmmTMB
and merMod
. See ...
for details on number of simulations.
"surv"
and "cumhaz"
Applies only to coxph
-objects from the survial-package and
calculates the survival probability or the cumulative hazard of an event.
"debug"
Only used internally.
Character vector, naming the function to be applied to the
covariates over which the effect is "averaged". The default is "mean".
See typical_value
for options.
Named character vector, which indicates covariates that
should be held constant at specific values. Unlike typical
, which
applies a function to the covariates to determine the value that is used
to hold these covariates constant, condition
can be used to define
exact values, for instance condition = c(covariate1 = 20, covariate2 = 5)
.
See 'Examples'.
A data frame with the marginal effect of the response (predicted
),
std.error
and the confidence intervals conf.low
and
conf.high
. For cumulative link-models, the marginal effect for
each level of the response variable is returned.
For linear models, the predicted value is the estimated marginal mean. Else, the predicted value is on the scale of the inverse of link function.
# NOT RUN {
data(efc)
fit <- lm(barthtot ~ c12hour + neg_c_7 + c161sex + c172code, data = efc)
emm(fit)
# Example from ?MASS::polr
library(MASS)
options(contrasts = c("contr.treatment", "contr.poly"))
house.plr <- polr(Sat ~ Infl + Type + Cont, weights = Freq, data = housing)
emm(house.plr)
# }
Run the code above in your browser using DataLab