Description Usage Arguments Value Confidence vs prediction intervals Factors and novel factor levels Recommended implementations
Safely predict from a model object
1 2  safe_predict(object, new_data, type = NULL, ..., level = 0.95,
std_error = FALSE)

object 
An object or model you would like to get predictions from. 
new_data 
Required. Data in the same format as required for
the

type 
A character vector indicating what kind of predictions you would like. Options are:
In most cases, only a subset of these options are available. 
... 
Unused. 
level 
A number strictly between 
std_error 
Logical indicating whether or not calculate standard
errors for the fit at each point. Not available for all models, and can
be computationally expensive to compute. The standard error is always
the standard error for the mean, and never the standard error for
predictions. Standard errors are returned in a column called 
A tibble::tibble()
with one row for each row of new_data
.
Predictions for observations with missing data will be NA
. Returned
tibble has different columns depending on type
:
"response"
:
univariate outcome: .pred
(numeric)
multivariate outcomes: .pred_{outcome name}
(numeric) for each
outcome
"class"
: .pred_class
(factor)
"prob"
: .pred_{level}
columns (numerics between 0 and 1)
"link"
: .pred
(numeric)
"conf_int"
: .pred
, .pred_lower
, .pred_upper
(all numeric)
"pred_int"
: .pred
, .pred_lower
, .pred_upper
(all numeric)
If you request standard errors with std_error = TRUE
, an additional
column .std_error
.
For interval predictions, the tibble has additional attributes level
and interval
. The level
is the same as the level
argument and is
between 0 and 1. interval
is either "confidence"
or "prediction"
.
Some models may also set a method
attribute to detail the method
used to calculate the intervals.
For details on the difference between confidence and prediction intervals, see the online documentation. This is also available as a vignette that you can access with:
1  vignette("intervals", package = "safepredict")

We recommend using recipes::recipe()
s to consistently handle categorical
(factor) predictors. For details see:
1  vignette("novelfactorlevels", package = "safepredict")

Currently we do not have a robust way to check for novel factor levels
from within safepredict
. In practice this would require storing
information about predictors in the model object at fitting time,
and safepredict
is largely at the mercy of package writers in
that regard. Using recipes
to preprocess your data should take care
of the issue.
The goal of safepredict
is to make prediction as painless and consistent
as possible across a wide variety of model objects. In some cases, the
existing intrafrastructure is insufficient to provide a consistent and
featurerich prediction interface. As a result, we support a number of
model objects that we do not actually recommend using. In these cases,
we try to link to better and more featurerich implementations.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.