Description Usage Arguments Value Examples
Safe predictions from a loess object
1 2 3  ## S3 method for class 'loess'
safe_predict(object, new_data, type = c("response",
"conf_int", "pred_int"), ..., std_error = FALSE, level = 0.95)

object 
A 
new_data 
TODO 
type 
What kind of predictions to return. Options are:

... 
Unused. 
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 
level 
A number strictly between 
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  fit < loess(mpg ~ wt, mtcars)
safe_predict(fit, mtcars)
safe_predict(fit, mtcars, std_error = TRUE)
# the default behavior of loess() is return NA for values
# outside the range of the training data:
safe_predict(fit, data.frame(wt = 1:10))
# to enable extrapolation, use:
fit2 < loess(
mpg ~ wt,
mtcars,
control = loess.control(surface = "direct")
)
safe_predict(fit2, data.frame(wt = 1:10), type = "pred_int", level = 0.9)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.