R: Get marginal effects for model response

emm {ggeffects} | R Documentation

## 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"`, prediction intervals also consider the uncertainty in the variance parameters.
`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()`.

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

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

### Examples

    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)

[Package ggeffects version 0.4.0 Index]