In: Statistics and Probability
D. The data le TreeAgeDiamSugarMaple.txt is available at the same site as the other data sets you have used in the homework assignments. The data are from 27 maple trees. The rst column of the le is x=tree diameter and the second column is y=tree age (in years). Do the following for these data:
(i) Determine a good polynomial regression model for this data using the AIC and/or BIC criteria. (Fit all polynomial regression models upto a maximum degree of 8 and then choose the best one.)
(ii) For the second degree polynomial model, test the null hypothesis that the coecient of x 2 is 0. Use a level of signicance: α = 0.05. Report the p-value as well (note that this doesn't involve α).
(iii) Produce a plot of the residuals versus the predicted values for the model chosen in part (i) above. Is there anything remarkable about the plot?
(iv) Using the model in part (i), predict the age of a tree with a diameter of 110 by using an interval in which you have 95% condence (i.e. obtain a 95% prediction interval for Y at x = 110.)
TreeAgeDiamSugarMaple Data is:
Diamet Age
2.86 1.61
4.29 3.23
8.57 6.45
14.29 8.06
15.71 14.52
17.14 22.58
20.00 24.19
54.29 37.10
60.00 40.32
88.57 32.26
100.00 46.77
102.86 51.61
105.71 58.07
108.57 37.10
114.29 37.90
177.14 78.23
178.57 100.81
252.86 76.61
254.29 90.32
311.43 134.68
397.14 96.77
491.43 151.61
560.00 163.71
531.43 140.32
532.86 112.10
545.71 109.68
541.43 123.39
please provide the R code used
R code
xy=read.table("clipboard",sep="\t",header=T)#data
entry
xy
##Answer(i)
xy.lm=lm(Diamet~Age,data=xy)
xy.lm
AIC(xy.lm)
xy.lm.2=lm(Diamet~poly(Age,2,raw=T),data=xy)
xy.lm.2
AIC(xy.lm.2)
xy.lm.3=lm(Diamet~poly(Age,3,raw=T),data=xy)
xy.lm.3
AIC(xy.lm.3)
xy.lm.4=lm(Diamet~poly(Age,4,raw=T),data=xy)
xy.lm.4
AIC(xy.lm.4)
xy.lm.5=lm(Diamet~poly(Age,5,raw=T),data=xy)
xy.lm.5
AIC(xy.lm.5)
xy.lm.6=lm(Diamet~poly(Age,6,raw=T),data=xy)
xy.lm.6
AIC(xy.lm.6)
xy.lm.7=lm(Diamet~poly(Age,7,raw=T),data=xy)
xy.lm.7
AIC(xy.lm.7)
xy.lm.8=lm(Diamet~poly(Age,8,raw=T),data=xy)
xy.lm.8
AIC(xy.lm.8)
##Answer(ii)
summary(xy.lm.2)
##Answer(iii)
plot(xy.lm.3$fitted,xy.lm.3$res,main="",xlab="fitted",ylab="residuals",pch=19)
abline(h=mean(xy.lm.3$res),col="red")
##Answer(iv)
new=data.frame(Age=110)
predict(xy.lm.3,newdata=new,interval="prediction")