Description Usage Arguments Details Value See Also Examples
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
.
1 2 3 4 5 6 7 8 9 10 |
df |
A data frame of new data. |
fit |
An object of class |
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. |
nSims |
A positive integer. Determines the number of simulations to run. |
... |
Additional arguments. |
Prediction intervals are generated through simulation with the aid
arm::sim
, which simulates the uncertainty in the regression
coefficients. At the moment, only prediction intervals for Poisson,
Quasipoisson, Gaussian, and Gamma GLMs are supported. Note that if
the response is count data, prediction intervals are only
approximate. Simulation from the QuasiPoisson model is performed
with the negative binomial distribution, see Gelman and Hill
(2007).
A dataframe, df
, with predicted values, upper and lower
prediction bounds attached.
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.
1 2 3 4 5 6 7 8 | # 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"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.