Learn R Programming

marginaleffects (version 0.1.0)

typical: Generate "typical" datasets for use in marginaleffects's newdata argument

Description

Generate "typical" datasets for use in marginaleffects's newdata argument

Usage

typical(..., model = NULL, data = NULL)

Arguments

...

named arguments with vectors of values for the typical variables to construct (see Examples below.) The typical data will include combinations of unique values from these vectors

model

Model object

data

data.frame (one and only one of the model and data arguments must be true).

Value

A data.frame in which each row corresponds to one combination of the named predictors supplied by the user via the ... dots. Variables which are not explicitly defined are held at their mean or mode.

Details

If typical is used in a marginaleffects or predictions call as the newdata argument, users do not need to specify the model or data argument. The data is extracted automatically from the model.

If users supply a model, the data used to fit that model is retrieved using the insight::get_data function.

Examples

Run this code
# NOT RUN {
# The output only has 2 rows, and all the variables except `hp` are at their
# mean or mode.
typical(data = mtcars, hp = c(100, 110))

# We get the same result by feeding a model instead of a data.frame
mod <- lm(mpg ~ hp, mtcars)
typical(model = mod, hp = c(100, 110))

# Use in `marginaleffects` to compute "Typical Marginal Effects"
marginaleffects(mod, newdata = typical(hp = c(100, 110)))
# }

Run the code above in your browser using DataLab