Description Usage Arguments Details Value See Also Examples
This function is one of the methods for add_pi
and is
automatically called when an object of class lm
is passed to
to add_pi
.
1 2 3 4 5 6 7 8 9 10 |
df |
A data frame of new data. |
fit |
An object of class lm. Predictions are made with this object. |
alpha |
A real number between 0 and 1. Controls the confidence level of the interval estimates. |
names |
|
yhatName |
A string. Name of the predictions vector. |
log_response |
A logical. If TRUE, prediction intervals will be generated at the response level of a log-linear model: \log(Y) = Xβ + ε. Again, these intervals will be on the scale of the original response, Y. |
... |
Additional arguments. |
Prediction intervals for lm
objects are calculated
parametrically. This function is essentially just a wrapper for
predict(fit, df, interval = "prediction")
if fit
is a
linear model. If log_response = TRUE
, prediction intervals
for the response are calculated parametrically, then the
exponential function is applied to transform them to the original
scale.
A dataframe, df
, with predicted values, upper and lower
prediction bounds attached.
add_ci.lm
for confidence intervals for
lm
objects. add_probs.lm
for conditional
probabilities of lm
objects, and
add_quantile.lm
for response quantiles of
lm
objects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # Fit a linear model
fit <- lm(dist ~ speed, data = cars)
# Add prediction intervals and fitted values to the original data
add_pi(cars, fit)
# Try to add predictions to a data frame of new data
new_data <- cars[sample(NROW(cars), 10), ]
add_pi(new_data, fit)
# Try a different confidence level
add_pi(cars, fit, alpha = 0.5)
# Add custom names to the prediction bounds.
add_pi(cars, fit, alpha = 0.5, names = c("lwr", "upr"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.