Description Usage Arguments Details Value See Also Examples
This is a generic function to append prediction intervals to a data
frame. A prediction interval is made for each observation in
df
with respect to the model fit
. These intervals are
then appended to df
and returned to the user as a
data frame. fit
can be a linear, log-linear, linear mixed,
generalized linear, generalized linear mixed, or accelerated
failure time model.
1 |
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. |
... |
Additional arguments |
For more specific information about the arguments that are applicable in each method, consult:
add_pi.lm
for linear regression prediction intervals
add_pi.glm
for generalized linear regression prediction intervals
add_pi.lmerMod
for linear mixed models prediction intervals
add_pi.glmerMod
for generalized linear mixed model prediction intervals
add_pi.survreg
for accelerated failure time model prediction intervals
A dataframe, df
, with predicted values, upper and lower
prediction bounds attached.
add_ci
for confidence intervals,
add_probs
for response level probabilities, and
add_quantile
for quantiles of the conditional
response distribution.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # Fit a linear model
fit <- lm(dist ~ speed, data = cars)
# Define some new data
new_data <- cars[sample(NROW(cars), 10), ]
# Add fitted values and prediction intervals to new_data
add_pi(new_data, fit)
# Fit a Poisson model
fit2 <- glm(dist ~ speed, family = "poisson", data = cars)
# Add approximate prediction intervals to the fitted values of
# new_data
add_pi(new_data, fit2)
# Fit a linear mixed model
fit3 <- lme4::lmer(Reaction ~ Days + (1|Subject), data = lme4::sleepstudy)
# Add parametric prediction intervals for the fitted values to the
# original data
add_pi(lme4::sleepstudy, fit3, type = "parametric")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.