add_pi.negbin: Prediction Intervals for Negative Binomial Linear Models

Description Usage Arguments Details Value See Also Examples

View source: R/add_pi_negbin.R

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## S3 method for class 'negbin'
add_pi(
  df,
  fit,
  alpha = 0.05,
  names = NULL,
  yhatName = "pred",
  nSims = 2000,
  ...
)

Arguments

df

A data frame of new data.

fit

An object of class negbin.

alpha

A real number between 0 and 1. Controls the confidence level of the interval estimates.

names

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].

yhatName

A string. Name of the predictions vector.

nSims

A positive integer. Determines the number of simulations to run.

...

Additional arguments.

Details

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 over-dispersion 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.

Value

A dataframe, df, with predicted values, upper and lower prediction bounds attached.

See Also

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.

Examples

1
2
3
4
5
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"))

ciTools documentation built on Jan. 13, 2021, 7 a.m.