add_ci.negbin {ciTools} R Documentation

## Confidence Intervals for Negative Binomial Linear Model Predictions

### Description

This function is one of the methods for add_ci, and is called automatically when add_ci is used on a fit of class negbin.

### Usage

## S3 method for class 'negbin'
add_ci(
df,
fit,
alpha = 0.05,
names = NULL,
yhatName = "pred",
response = TRUE,
type = "parametric",
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, confidence bounds automatically will be named by add_ci, otherwise, the lower confidence bound will be named names[1] and the upper confidence bound will be named names[2]. yhatName A string. Name of the vector of predictions made for each observation in df response A logical. The default is TRUE. If TRUE, the confidence intervals will be determined for the expected response; if FALSE, confidence intervals will be made on the scale of the linear predictor. type A string. Must be type = "parametric" or type = "boot". type determines the method used to compute the confidence intervals. nSims An integer. Number of simulations to perform if the bootstrap method is used. ... Additional arguments.

### Details

The default link function is log-link. Confidence Intervals are determined by making an interval on the scale of the linear predictor, then applying the inverse link function from the model fit to transform the linear level confidence intervals to the response level. Alternatively, bootstrap confidence intervals may be formed. The bootstrap intervals are formed by first resampling cases from the data frame used to calculate fit, then bias corrected and accelerated intervals are calculated. See boot::boot.ci for more details.

### Value

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

### See Also

add_pi.negbin for prediction intervals for negbin objects, add_probs.negbin for conditional probabilities of negbin objects, and add_quantile.negbin for response quantiles of negbin objects.

### Examples

x1 <- rnorm(300, mean = 1)
y <- MASS::rnegbin(n = 300, mu = exp(5 + 0.5 * x1), theta = 2)
df <- data.frame(x1 = x1, y = y)
fit <- MASS::glm.nb(y ~ x1, data = df)
df <- df[sample(100),]
add_ci(df, fit, names = c("lcb", "ucb"))



[Package ciTools version 0.6.1 Index]