Learn R Programming

ggeffects (version 0.3.3)

emm: Get marginal effects for model response

Description

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).

Usage

emm(model, ci.lvl = 0.95, type = c("fe", "re"), typical = "mean", ...)

Arguments

model

A fitted model object, or a list of model objects. Any model that supports common methods like predict(), family() or model.frame() should work.

ci.lvl

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).

type

Character, only applies for mixed effects models. Indicates whether predicted values should be conditioned on random effects (type = "re") or fixed effects only (type = "fe", the default). If type = "re", the uncertainty in the variance parameters is currently not taken into account. The specific levels of the random effects are not provided in the newdata-argument. Hence, if type = "re", predict() is called with re.form = NULL, i.e. predictions are conditioned on random effects only using the first level of random effects, but the uncertainty in the variance parameters is ignored.

typical

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.

...

Further arguments passed down to predict().

Value

A tibble 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.

Details

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.

Examples

Run this code
# 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