
Last chance! 50% off unlimited learning
Sale ends in
This function is one of the methods for add_pi
, and is
called automatically when add_pi
is used on a fit
of
class glm
.
# S3 method for glm
add_pi(tb, fit, alpha = 0.05, names = NULL,
yhatName = "pred", nSims = 1000, type = "sim", ...)
A tibble or data frame of new data.
An object of class glm
.
A real number between 0 and 1. Controls the confidence level of the interval estimates.
NULL
or character vector of length two. If
NULL
, prediction bounds automatically will be named by
add_pi
, otherwise, the lower prediction bound will be
named names[1]
and the upper prediction bound will be
named names[2]
.
A string. Name of the predictions vector.
A positive integer. Determines the number of simulations to run.
A string. Currently type = "sim"
is the only
valid string.
Additional arguments.
A tibble, tb
, with predicted values, upper and lower
prediction bounds attached.
Prediction intervals are generated through simulation via
arm::sim
. At the moment, only prediction intervals for
Poisson GLMs with the log link function are supported. Note that if
the response is count data, prediction intervals are only
approximate.
add_ci.glm
for confidence intervals for
glm
objects, add_probs.glm
for conditional
probabilities of glm
objects, and
add_quantile.glm
for response quantiles of
glm
objects.
# NOT RUN {
# Fit a Poisson model
fit <- glm(dist ~ speed, data = cars, family = "poisson")
# Add prediction intervals and fitted values to the original data frame
add_pi(cars, fit)
# Try a different confidence level
add_pi(cars, fit, alpha = 0.5)
# Try custom names for the prediction bounds (may be useful for plotting)
add_pi(cars, fit, alpha = 0.5, names = c("lwr", "upr"))
# }
Run the code above in your browser using DataLab