Learn R Programming

marginaleffects (version 0.25.1)

get_predict: Get predicted values from a model object (internal function)

Description

Get predicted values from a model object (internal function)

Usage

get_predict(model, newdata, type, ...)

# S3 method for default get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for polr get_predict(model, newdata = insight::get_data(model), type = "probs", ...)

# S3 method for glmmPQL get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for MCMCglmm get_predict(model, newdata, type = "response", ndraws = 1000, ...)

# S3 method for afex_aov get_predict(model, newdata = NULL, ...)

# S3 method for glimML get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for betareg get_predict(model, newdata, type = "response", ...)

# S3 method for bife get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for biglm get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for multinom get_predict(model, newdata = insight::get_data(model), type = "probs", ...)

# S3 method for brmultinom get_predict(model, newdata = insight::get_data(model), type = "probs", ...)

# S3 method for brmsfit get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for crch get_predict(model, newdata = NULL, type = "location", ...)

# S3 method for bart get_predict(model, newdata = NULL, ...)

# S3 method for fixest get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for flexsurvreg get_predict(model, newdata, type, ...)

# S3 method for gamlss get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for glmmTMB get_predict( model, newdata = insight::get_data(model), type = "response", newparams = NULL, ... )

# S3 method for glmgee get_predict(model, newdata, ...)

# S3 method for merMod get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for lmerModLmerTest get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for lmerMod get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for mblogit get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for mhurdle get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for Learner get_predict(model, newdata, type = NULL, ...)

# S3 method for clm get_predict(model, newdata = insight::get_data(model), type = "prob", ...)

# S3 method for rq get_predict(model, newdata = insight::get_data(model), type = NULL, ...)

# S3 method for rms get_predict(model, newdata = insight::get_data(model), type = NULL, ...)

# S3 method for orm get_predict(model, newdata = insight::get_data(model), type = NULL, ...)

# S3 method for lrm get_predict(model, newdata = insight::get_data(model), type = NULL, ...)

# S3 method for ols get_predict(model, newdata = insight::get_data(model), type = NULL, ...)

# S3 method for rlmerMod get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for stanreg get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for stpm2 get_predict(model, newdata = NULL, ...)

# S3 method for pstpm2 get_predict(model, newdata = NULL, ...)

# S3 method for gsm get_predict(model, newdata = NULL, ...)

# S3 method for aft get_predict(model, newdata = NULL, ...)

# S3 method for lm get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for glm get_predict(model, newdata = insight::get_data(model), type = "response", ...)

# S3 method for svyolr get_predict(model, newdata = insight::get_data(model), type = "probs", ...)

# S3 method for svyglm get_predict( model, newdata = insight::get_data(model), type = "response", se.fit = FALSE, ... )

# S3 method for coxph get_predict(model, newdata = insight::get_data(model), type = "lp", ...)

# S3 method for model_fit get_predict(model, newdata, type = NULL, ...)

# S3 method for workflow get_predict(model, newdata, type = NULL, ...)

# S3 method for tobit1 get_predict(model, newdata = insight::get_data(model), type = "response", ...)

Value

A data.frame of predicted values with a number of rows equal to the number of rows in newdata and columns "rowid" and "estimate". A "group" column is added for multivariate models or models with categorical outcomes.

Arguments

model

Model object

newdata

Grid of predictor values at which we evaluate the slopes.

  • Warning: Please avoid modifying your dataset between fitting the model and calling a marginaleffects function. This can sometimes lead to unexpected results.

  • NULL (default): Unit-level slopes for each observed value in the dataset (empirical distribution). The dataset is retrieved using insight::get_data(), which tries to extract data from the environment. This may produce unexpected results if the original data frame has been altered since fitting the model.

  • datagrid() call to specify a custom grid of regressors. For example:

    • newdata = datagrid(cyl = c(4, 6)): cyl variable equal to 4 and 6 and other regressors fixed at their means or modes.

    • See the Examples section and the datagrid() documentation.

  • subset() call with a single argument to select a subset of the dataset used to fit the model, ex: newdata = subset(treatment == 1)

  • dplyr::filter() call with a single argument to select a subset of the dataset used to fit the model, ex: newdata = filter(treatment == 1)

  • string:

    • "mean": Slopes evaluated when each predictor is held at its mean or mode.

    • "median": Slopes evaluated when each predictor is held at its median or mode.

    • "balanced": Slopes evaluated on a balanced grid with every combination of categories and numeric variables held at their means.

    • "tukey": Slopes evaluated at Tukey's 5 numbers.

    • "grid": Slopes evaluated on a grid of representative numbers (Tukey's 5 numbers and unique values of categorical predictors).

type

string indicates the type (scale) of the predictions used to compute contrasts or slopes. This can differ based on the model type, but will typically be a string such as: "response", "link", "probs", or "zero". When an unsupported string is entered, the model-specific list of acceptable values is returned in an error message. When type is NULL, the first entry in the error message is used by default.

...

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.