get_modeldata() retrieves the data used to fit a model. If the data was
previously attached via set_modeldata(), it is returned directly. Otherwise,
the data is retrieved from the model object or the environment using
insight::get_data().
get_modeldata(model, ...)set_modeldata(model, newdata)
get_modeldata() returns a data frame of the original data used to
fit the model, or NULL if not available. set_modeldata() returns the
model with the data attached as an attribute.
Model object
Additional arguments are passed to the predict() method
supplied by the modeling package.These arguments are particularly useful
for mixed-effects or bayesian models (see the online vignettes on the
marginaleffects website). Available arguments can vary from model to
model, depending on the range of supported arguments by each modeling
package. See the "Model-Specific Arguments" section of the
?slopes documentation for a non-exhaustive list of available
arguments.
A data frame to attach to the model object.
set_modeldata() attaches a dataset to a model object as an attribute. This
is useful when the training data may not be available in the environment where
marginaleffects functions are called, such as inside lapply(), in Shiny
apps, or in nested function calls. By attaching the data explicitly, you ensure
that marginaleffects always uses the correct dataset.