add_ci.lm {ciTools}  R Documentation 
Confidence Intervals for Linear Model Predictions
Description
This function is one of the methods in add_ci
and
automatically is called when an object of class lm
is passed
to add_ci
.
Usage
## S3 method for class 'lm'
add_ci(
df,
fit,
alpha = 0.05,
names = NULL,
yhatName = "pred",
log_response = FALSE,
...
)
Arguments
df 
A data frame. 
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 vector of the predictions made for each observation in df 
log_response 
Logical. Default is 
... 
Additional arguments. 
Details
Confidence intervals for lm
objects are calculated
parametrically. This function is essentially a wrapper for
predict(fit, df, interval = "confidence")
if fit
is a
linear model. If log_response = TRUE
, confidence intervals
for the response are calculated using Wald's Method. See Meeker and
Escobar (1998) for details.
Value
A dataframe, df
, with predicted values, upper and lower
confidence bounds attached.
See Also
add_pi.lm
for prediction intervals for
lm
objects, add_probs.lm
for conditional
probabilities of lm
objects, and
add_quantile.lm
for response quantiles of
lm
objects.
Examples
# Fit a linear model
fit < lm(dist ~ speed, data = cars)
# Get fitted values for each observation in cars, and append
# confidence intervals
add_ci(cars, fit)
# Try a different confidence level
add_ci(cars, fit, alpha = 0.5)
# Try custom names for the confidence bounds
add_ci(cars, fit, alpha = 0.5, names = c("lwr", "upr"))