safepredict has two goals: to provide a consistent interface to prediction via the safe_predict() generic, and to accurately quantify prediction uncertainty.

safe_predict():

  • always returns a tibble.
  • never drops rows with missing data.
  • always uses the same arguments in the same order.

safepredict follows the tidymodels prediction specification.

Installation

safepredict is currently in the beginning stages of development and is available only on Github. You can install it with:

Arguments

The three main arguments to safe_predict() are always the same:

  • object: A model object you would like to get predictions from.

  • new_data: Required. Data in the same format as required for the predict() method.

  • type: What kind of predictions you would like. Options are:

    type application
    response numeric predictions
    class hard class predictions
    prob class probabilities, survivor probabilities
    link glm linear predictor
    conf_int confidence intervals
    pred_int prediction intervals

Examples

Suppose you fit a logistic regression using glm:

library(tibble)

data <- tibble(
  y = as.factor(rep(c("A", "B"), each = 50)),
  x = c(rnorm(50, 1), rnorm(50, 3))
)

fit <- glm(y ~ x, data, family = binomial)

You can predict class probabilities:

or can jump straight to hard class decisions

We can also get predictions on the link scale:

or we can get confidence intervals on the response scale