Splus handout: Transformations and Graphical Diagnostics > #Data: brain (g) and body (kg) weights for 62 species of mammals > wts<-read.table("alr.144",header=T) > motif() > par(mfrow=c(3,3)) > plot(wts$body,wts$brain) > title("Fig 1: body vs brain weight") >#Can use the menus for this part: > wts.lm<-lm(brain~body,wts) > summary(wts.lm) Call: lm(formula = brain ~ body, data = wts) Residuals: Min 1Q Median 3Q Max -810.1 -88.52 -79.64 -13.02 2050 Coefficients: Value Std. Error t value Pr(>|t|) (Intercept) 91.0039 43.5526 2.0895 0.0409 body 0.9665 0.0477 20.2777 0.0000 Residual standard error: 334.7 on 60 degrees of freedom Multiple R-Squared: 0.8727 F-statistic: 411.2 on 1 and 60 degrees of freedom, the p-value is 0 Correlation of Coefficients: (Intercept) body -0.2176 >#Compute the studentized residuals: >#As far as I can tell, you need to use the "old" lsfit function along >#with the function "ls.diag" to compute studentized residuals. You can >#also compute the studentized residuals using the formula given in >#class, but this may result in rounding errors. #Refit the same model using lsfit. >wts.lsfit<-lsfit(wts$body,wts$brain) >ls.print(wts.lsfit) Residual Standard Error = 334.7199, Multiple R-Square = 0.8727 N = 62, F-statistic = 411.1869 on 1 and 60 df, p-value = 0 coef std.err t.stat p.value Intercept 91.0039 43.5526 2.0895 0.0409 X 0.9665 0.0477 20.2777 0.0000 > e.star<-ls.diag(wts.lsfit)$stud.res > #residual plots > plot(wts$body,e.star) > title("Figure 2") > abline(h=0) > qqnorm(e.star) > title("Figure 3") _______________________________________________________________________ > #Try transforming the response > wts2.lsfit<-lsfit(wts$body,log(wts$brain)) > ls.print(wts2.lsfit) Residual Standard Error = 2.217, Multiple R-Square = 0.1923 N = 62, F-statistic = 14.2827 on 1 and 60 df, p-value = 4e-04 coef std.err t.stat p.value Intercept 2.9030 0.2885 10.0635 0e+00 X 0.0012 0.0003 3.7792 4e-04 > e.star<-ls.diag(wts2.lsfit)$stud.res > plot(wts$body,log(wts$brain)) > title("Fig 4: body vs log(brain weight)") > plot(wts$body,e.star) > title("Figure 5") > abline(h=0) > qqnorm(e.star) > title("Figure 6") _______________________________________________________________________ > #Try transforming the response and the predictor > wts3.lsfit<-lsfit(log(wts$body),log(wts$brain)) > ls.print(wts3.lsfit) Residual Standard Error = 0.6941, Multiple R-Square = 0.9208 N = 62, F-statistic = 697.8027 on 1 and 60 df, p-value = 0 coef std.err t.stat p.value Intercept 2.1345 0.0960 22.2287 0 X 0.7517 0.0285 26.4160 0 e.star<-ls.diag(wts3.lsfit)$stud.res plot(log(wts$body),log(wts$brain)) title("Fig 7: log(body) vs log(brain weight)") #residual plots plot(log(wts$body),e.star) title("Figure 6") abline(h=0) qqnorm(e.star) title("Figure 7")