add_ci.glm {ciTools}  R Documentation 
This function is one of the methods for add_ci
, and is
called automatically when add_ci
is used on a fit
of
class glm
. The default method calculates confidence
intervals 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, confidence intervals may be
calculated through a nonparametric bootstrap method.
## S3 method for class 'glm'
add_ci(
df,
fit,
alpha = 0.05,
names = NULL,
yhatName = "pred",
response = TRUE,
type = "parametric",
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 character vector of length one. Name of the vector of predictions made for each observation in df 
response 
A logical. The default is 
type 
A character vector of length one. Must be 
nSims 
An integer. Number of simulations to perform if the bootstrap method is used. 
... 
Additional arguments. 
A dataframe, df
, with predicted values, upper and lower
confidence bounds attached.
add_pi.glm
for prediction intervals for
glm
objects, add_probs.glm
for conditional
probabilities of glm
objects, and
add_quantile.glm
for response quantiles of
glm
objects.
# Poisson regression
fit < glm(dist ~ speed, data = cars, family = "poisson")
add_ci(cars, fit)
# Try a different confidence level
add_ci(cars, fit, alpha = 0.5)
# Add custom names to the confidence bounds (may be useful for plotting)
add_ci(cars, fit, alpha = 0.5, names = c("lwr", "upr"))
# Logistic regression
fit2 < glm(I(dist > 30) ~ speed, data = cars, family = "binomial")
dat < cbind(cars, I(cars$dist > 30))
# Form 95% confidence intervals for the fit:
add_ci(dat, fit2)
# Form 50% confidence intervals for the fit:
add_ci(dat, fit2, alpha = 0.5)
# Make confidence intervals on the scale of the linear predictor
add_ci(dat, fit2, alpha = 0.5, response = FALSE)
# Add custom names to the confidence bounds
add_ci(dat, fit2, alpha = 0.5, names = c("lwr", "upr"))