# # Epage 41 # # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- library(alr3) data(heights) attach(heights) # 2.4.1: # postscript("../../WriteUp/Graphics/Chapter2/prob_4.eps", onefile=FALSE, horizontal=FALSE) plot( Mheight, Dheight, xlab="Mheight", ylab="Dheight" ) dev.off() m <- lm( Dheight ~ Mheight ) summary( m ) anova(m) # 2.4.2: # Mheight0 <- Mheight - mean( Mheight ) m0 <- lm( Dheight ~ Mheight0 ) summary(m0) # get the standard error of beta_1: n <- length( m0$residuals ) RSS <- sum( m0$residuals ^ 2 ) sigma_hat <- sqrt( RSS/(n-2) ) SXX <- sum( ( Mheight0 - mean(Mheight0) )^2 ) se_beta_1 <- sigma_hat / sqrt( SXX ) # get the confidence interval of beta_1: # alpha = 1 - 0.99 quant = qt( 1 - alpha/2, n-2 ) m0$coefficients[2] - quant * se_beta_1 m0$coefficients[2] + quant * se_beta_1 # 2.4.3: # predict( m0, newdata=data.frame(Mheight0=64-mean(Mheight)), interval="prediction", level=0.99 ) # # fit lwr upr # [1,] 64.58925 58.74045 70.43805 #