add_pi.negbin {ciTools}  R Documentation 
This function is one of the methods for add_pi
, and is
called automatically when add_pi
is used on a fit
of
class negbin
.
## S3 method for class 'negbin'
add_pi(
df,
fit,
alpha = 0.05,
names = NULL,
yhatName = "pred",
nSims = 2000,
...
)
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 for negative binomial fits are formed through a two part simulation scheme:
1. Model coefficients are generated through a parametric bootstrap procedure that simulates the uncertainty in the regression coefficients.
2. Random draws from the negative binomial distribution are taken with a mean that varies based on the model coefficients determined in step (1) and overdispersion parameter that is taken from the original fitted model.
Quantiles of the simulated responses are taken at the end to produce intervals of the desired level.
A dataframe, df
, with predicted values, upper and lower
prediction bounds attached.
add_ci.negbin
for confidence intervals for
negbin
objects, add_probs.negbin
for conditional
probabilities of negbin
objects, and
add_quantile.negbin
for response quantiles of
negbin
objects.
x1 < rnorm(100, mean = 1)
y < MASS::rnegbin(n = 100, mu = exp(1 + x1), theta = 5)
df < data.frame(x1 = x1, y = y)
fit < MASS::glm.nb(y ~ x1, data = df)
add_pi(df, fit, names = c("lpb", "upb"))