#### Example 1, Section 11.3 notes: # times until exhaustion when running on treadmill: x <- c(8.4, 9.0, 9.6, 10.0, 11.0) # 20 km ski race times: y <- c(71.4, 68.7, 69.4, 63.0, 62.6) # Least-squares estimates: lm(y ~ x) ## Section 11.4 calculations: summary(lm(y ~ x)) # Note: 10.112^2 = estimate of V(beta_0-hat) # Note: 1.049^2 = estimate of V(beta_1-hat) # Note: 2.077^2 = MSE, the estimate of sigma^2 ## Section 11.6 calculations: lsfit <- lm(y ~ x) 95% CI for beta_1: LCL <- summary(lsfit)[[4]]["x","Estimate"] - qt(.025, df=lsfit$df, lower=F)*summary(lsfit)[[4]]["x","Std. Error"] UCL <- summary(lsfit)[[4]]["x","Estimate"] + qt(.025, df=lsfit$df, lower=F)*summary(lsfit)[[4]]["x","Std. Error"] print(round(c(LCL,UCL),3)) # 90% CI for E(Y) at x* = 10.5: predict(lsfit, newdata=data.frame(x=10.5), interval="confidence", level=0.90) # 90% PI for Y* at x* = 10.5: predict(lsfit, newdata=data.frame(x=10.5), interval="prediction", level=0.90)