# Example 6.6, Confidence Interval for Future College GPA # Data set: gpa2 # Function for result reporting source("_report.R") # Load the data, create new variables and estimate the model load("gpa2.Rdata") data$hsizesq=(data$hsize)^2 data$sat0=data$sat-1200 data$hsperc0=data$hsperc-30 data$hsize0=data$hsize-5 data$hsizesq0=data$hsizesq-25 model=lm(colgpa~sat0+hsperc0+hsize0+hsizesq0,data=data) dig=c(3,5,5,5,5,3) # Recap the model { cat("This example closely follows Example 6.5. The regression result in the previous example was") reportreg(model,dig,adj=T) cat(", sigmahat = ", sprintf("%.3f",round((summary(model)$sigma),3)), sep="") } # Proceed to prediction interval see0hat=sprintf("%.3f",round(sqrt(as.numeric(printse(model,1,dig[1]))^2+round((summary(model)$sigma),3)^2),3)) cat("In the previous example, we obtained a 95% confidence interval for EXPECTED colgpa among all students at the given values of the independent variables, which is ", printcoef(model,1,dig[1]), " ± 1.96 * ", printse(model,1,dig[1]), ", or (", round(as.numeric(printcoef(model,1,dig[1]))-1.96*as.numeric(printse(model,1,dig[1])),2), ",", round(as.numeric(printcoef(model,1,dig[1]))+1.96*as.numeric(printse(model,1,dig[1])),2), ")", "\nNow, we want a 95% confidence interval for any PARTICULAR student with these characteristics. Since se(y0hat) = ", printse(model,1,dig[1]), " and sigmahat = ", sprintf("%.3f",round((summary(model)$sigma),3)), ", we have se(e0hat) = (", printse(model,1,dig[1]), "^2 + ", sprintf("%.3f",round((summary(model)$sigma),3)), "^2)^(1/2) = ", see0hat, ", which is much larger than se(y0hat) and very close to sigmahat. With this SE, we can obtain the prediction interval: ", printcoef(model,1,dig[1]), " ± 1.96 * ", see0hat, ", or (", round(as.numeric(printcoef(model,1,dig[1]))-1.96*as.numeric(see0hat),2), ",", round(as.numeric(printcoef(model,1,dig[1]))+1.96*as.numeric(see0hat),2), "), much wider than the previous interval. This indicates that based on the factors included in the regression, we cannot accurately predict an individual’s future colgpa", sep="")