Learn R Programming

ggeffects (version 0.3.3)

ggeffect: Get marginal effects from model terms

Description

ggeffect() computes marginal effects of model terms. It internally calls Effect and puts the result into tidy data frames. eff() is an alias for ggeffect().

Usage

ggeffect(model, terms, ci.lvl = 0.95, x.as.factor = FALSE, ...)

eff(model, terms, ci.lvl = 0.95, x.as.factor = FALSE, ...)

Arguments

model

A fitted model object, or a list of model objects. Any model that is supported by the effects-package should work.

terms

Character vector with the names of those terms from model, for which marginal effects should be displayed. At least one term is required to calculate effects, maximum length is three terms, where the second and third term indicate the groups, i.e. predictions of first term are grouped by the levels of the second (and third) term. Indicating levels in square brackets allows for selecting only specific groups. Term name and levels in brackets must be separated by a whitespace character, e.g. terms = c("age", "education [1,3]"). Numeric ranges, separated with colon, are also allowed: terms = c("education", "age [30:60]"). See 'Examples'. All remaining covariates that are not specified in terms are held constant (if full.data = FALSE, the default) or are set to the values from the observations (i.e. are kept as they happen to be; see 'Details').

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

x.as.factor

Logical, if TRUE, preserves factor-class as x-column in the returned data frame. By default, the x-column is always numeric.

...

Further arguments passed down to Effect.

Value

A tibble (with ggeffects class attribute) with consistent data columns:

x

the values of the model predictor to which the effect pertains, used as x-position in plots.

predicted

the predicted values, used as y-position in plots.

conf.low

the lower bound of the confidence interval for the predicted values.

conf.high

the upper bound of the confidence interval for the predicted values.

group

the grouping level from the second term in terms, used as grouping-aesthetics in plots.

facet

the grouping level from the third term in terms, used to indicate facets in plots.

Examples

Run this code
# NOT RUN {
data(efc)
fit <- lm(barthtot ~ c12hour + neg_c_7 + c161sex + c172code, data = efc)
ggeffect(fit, terms = "c12hour")

mydf <- ggeffect(fit, terms = c("c12hour", "c161sex"))
plot(mydf)

# }

Run the code above in your browser using DataLab