add_predictions {actxps}R Documentation

Add predictions to a data frame

Description

Attach predicted values from a model to a data frame with exposure-level records.

Usage

add_predictions(.data, model, ..., col_expected = NULL)

Arguments

.data

A data frame, preferably with the class exposed_df

model

A model object that has an S3 method for predict()

...

Additional arguments passed to predict()

col_expected

NULL or a character vector containing column names for each value returned by predict()

Details

This function attaches predictions from a model to a data frame that preferably has the class exposed_df. The model argument must be a model object that has an S3 method for the predict() function. This method must have new data for predictions as the second argument.

The col_expected argument is optional.

Value

A data frame or exposed_df object with one of more new columns containing predictions.

Examples

expo <- expose_py(census_dat, "2019-12-31") |>
  mutate(surrender = status == "Surrender")
mod <- glm(surrender ~ inc_guar + pol_yr, expo, family = 'binomial')
add_predictions(expo, mod, type = 'response')


[Package actxps version 1.5.0 Index]