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"), typical = "mean",
...)
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 the effects-package 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).
Character, only applies for mixed effects models and/or models with zero-inflation.
"fe"
Predicted values are conditioned on the fixed effects or conditional
model only. For instance, for models fitted with zeroinfl
from
pscl, this would return the predicted mean from the count component
(without zero-inflation). For models of class glmmTMB
, this type
calls predict(..., type = "link")
.
"re"
Predicted values are conditioned on the random effects. This only applies
to mixed models, and type = "re"
does not condition on the
zero-inflation component of the model, nor on different group levels.
type = "re"
uses the reference level in the random effects groups
(except for glmmTMB models, see below), and prediction intervals
also consider the uncertainty in the variance parameters. For models
from glmmTMB, this type calls predict(..., type = "link")
.
Note: For glmmTMB models, the random effect variances only
affect the confidence intervals of predictions, not the predicted values
themselves (because this is currently not implemented in glmmTMB),
i.e. predicted values are on population-level. 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 and for glmmTMB,
this would return the expected value mu*(1-p)
without
conditioning on random effects. For models of class glmmTMB
, this type
calls predict(..., type = "response")
.
"re.zi"
Predicted values are conditioned on the random effects and the
zero-inflation component. For models fitted with glmmTMB, this
would return the expected value mu*(1-p)
, conditioned on random
effects. Prediction intervals also consider the uncertainty in the
variance parameters. For models from glmmTMB, this type
calls simulate()
, because conditioning on random effects is
not yet implemented in predict.glmmTMB()
.
"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.
For ggpredict()
, further arguments passed down to
predict()
, and for ggeffect()
, further arguments passed
down to Effect
. If model
is of class
glmmTMB
, ...
may also be used to set the number of
simulation for bootstrapped confidence intervals, e.g. nsim = 500
.
A data frame with the marginal effect of the response (predicted
)
and the confidence intervals conf.low
and conf.high
.
For polr
-objects, 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