Generate "typical" datasets for use in
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
data.frame (one and only one of the
typical is used in a
predictions call as the
newdata argument, users do not need to specify the
argument. The data is extracted automatically from the model.
If users supply a model, the data used to fit that model is retrieved using
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.
1 2 3 4 5 6 7 8 9 10
# The output only has 2 rows, and all the variables except `hp` are at their # mean or mode. typical(newdata = 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)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.