Stat 333

S. McBride

#confidence intervals for regression coefficients
data(women)
attach(women)
mod <-  lm(weight ~ height, data = women )
confint(mod, level=.9)
##                    5 %       95 %
## (Intercept) -98.030599 -77.002734
## height        3.288603   3.611397
# correlation
cor(weight, height)
## [1] 0.9954948
cor(height, weight)
## [1] 0.9954948

prediction and confidence intervals

# prediction and confidence intervals
data(women)
attach(women)    
## The following objects are masked from women (pos = 3):
## 
##     height, weight
weight.mod <- lm(weight ~ height)
# create a new data frame
newdata <- data.frame(height = 66)
# prediction interval the height is 66
(predy <- predict(weight.mod, newdata, interval="predict") )
##        fit     lwr      upr
## 1 140.1833 136.775 143.5916
# confidence interval for mean weight is 140
(confy <- predict(weight.mod, newdata, interval="confidence") )
##        fit      lwr      upr
## 1 140.1833 139.3102 141.0565
# which interval is wider?
confy %*% c(0, -1, 1)  #conf interval width
##       [,1]
## 1 1.746287
predy %*% c(0, -1, 1)  #pred interval width
##       [,1]
## 1 6.816625
# where are each centered?
confy[1] == predy[1]
## [1] TRUE

create prediction intervals for several wait times with a single call to predict)

practice all this with at least 1 data set from Tuesday