################# ##### Problem 1 ################# Davis <- read.table('http://math.uttyler.edu/nathan/classes/statistics/data/davis.data',header=TRUE) attach(Davis) m1.1 <- lm(weight ~ repwt) summary(m1.1) # #Coefficients: # Estimate Std. Error t value Pr(>|t|) #(Intercept) 5.46083 3.05765 1.786 0.0758 . #repwt 0.92636 0.04556 20.333 <2e-16 *** # #Residual standard error: 8.456 on 179 degrees of freedom #Multiple R-squared: 0.6979, Adjusted R-squared: 0.6962 #F-statistic: 413.4 on 1 and 179 DF, p-value: < 2.2e-16 confint(m1.1) # # 2.5 % 97.5 % #(Intercept) -0.5728405 11.494497 #repwt 0.8364585 1.016265 plot(repwt,weight) abline(m1.1) identify(repwt,weight) dev.copy2eps(file='weight.eps') m1.2 <- lm(weight ~ repwt,subset=-12) summary(m1.2) # #Coefficients: # Estimate Std. Error t value Pr(>|t|) #(Intercept) 2.83349 0.81208 3.489 0.000611 *** #repwt 0.95715 0.01209 79.168 < 2e-16 *** # #Residual standard error: 2.241 on 178 degrees of freedom #Multiple R-squared: 0.9724, Adjusted R-squared: 0.9722 #F-statistic: 6268 on 1 and 178 DF, p-value: < 2.2e-16 confint(m1.2) # # 2.5 % 97.5 % #(Intercept) 1.2309416 4.436043 #repwt 0.9332893 0.981006 detach() ################# ##### Problem 2 ################# Prostate <- read.table('http://math.uttyler.edu/nathan/classes/statistics/data/prostate.data',header=TRUE) attach(Prostate) right.order <- data.frame(lpsa,lcavol,lweight,svi,lbph,age,lcp,pgg45,gleason) detach(Prostate) r.sqs <- sapply(2:9, function(i){summary(lm(lpsa~.,data=data.frame(right.order[1:i])))$r.squared}) rses <- sapply(2:9, function(i){summary(lm(lpsa~.,data=data.frame(right.order[1:i])))$sigma}) r.sqs rses plot(c(1,8),c(.50,.80),type='n',main='r^2=blue, rse=red',xlab='# x terms in model',ylab='') points(1:8,r.sqs,col='blue') points(1:8,rses,col='red') lines(1:8,r.sqs,col='blue',lty=3) lines(1:8,rses,col='red',lty=3) dev.copy2eps(file='prob2.eps') ################# ##### Problem 3 ################# m3 <- lm(lpsa ~ .,data=Prostate) confint(m3) confint(m3,level=.9)