---------------------------- First problem ---------------------------- > attach(ex06.3) > ex06.3 > f1=lm(dosage~drug) > boxplot(dosage~drug) > par(mfrow=c(2,2)) > plot(f1) (a) The residuals vs. predicted show variance increasing with fitted values, i.e. a megaphone opening to the right. The side-by-side boxplots also show increasing variance. However the normal probability plot looks fine. > library(MASS) > par(mfrow=c(1,1)) > boxcox(dosage~drug) (b) lambda=0 is suggested, the natural log transformation. > ldose=log(dosage) > f2=lm(ldose~drug) > anova(f2) Analysis of Variance Table Response: ldose Df Sum Sq Mean Sq F value Pr(>F) drug 3 2.4925 0.83084 8.6037 0.0001944 *** Residuals 36 3.4764 0.09657 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > lines(pairwise(f2,drug)) 4 -0.232 | 3 -0.192 | 2 0.027 | | 1 0.397 | (c) We reject H0: mu1=mu2=mu3=mu4 at the 5% level as p=0.0002. There are differences in dose across drug levels. Drugs 3 and 4 are significantly different (and better -- lower dosages are more effective) from drug 1. There is not a significant difference between 3 and 4 though. > par(mfrow=c(2,2)) > plot(f2) (d) Yes, constant variance and normality of the residuals seem fine for the log-transformed response. > qqnorm(dosage[drug==1]) > qqnorm(dosage[drug==2]) > qqnorm(dosage[drug==3]) > qqnorm(dosage[drug==4]) > brown.forsythe.test(dosage~drug) One-way analysis of means, Brown-Forsythe (unequal variances) data: dosage and drug F = 9.8651, num df = 3.000, denom df = 31.188, p-value = 9.931e-05 > oneway.test(dosage~drug) One-way analysis of means (not assuming equal variances) data: dosage and drug F = 8.0021, num df = 3.000, denom df = 19.672, p-value = 0.001105 > source("http://people.stat.sc.edu/hansont/stat506/gh.R") > gh(dosage,drug) $result1 n Mean Variance Group1 10 13.86 13.320444 Group2 10 9.73 11.549000 Group3 10 7.70 5.297778 Group4 10 7.41 5.714333 $Games.Howell t df p 1:2 2.6188885 17.90913 0.075114238 1:3 4.5145203 15.18118 0.002022012 1:4 4.6750451 15.52163 0.001401697 2:3 1.5640031 15.82156 0.425571417 2:4 1.7657355 16.15464 0.324312165 3:4 0.2763521 17.97428 0.992366287 (e) The four NPP's all look fairly straight; normality within each group is reasonable. The p-values for both Welch and Brown-Forsythe indicate we reject H0: mu1=mu2=mu3=mu4 on the original scale. The lines plot using Games-Howell is 4 3 2 1 --- ----- This is the same as what we got using Tukey on the log-transformed data. ---------------------------- Second problem ---------------------------- > attach(ex06.4) > names(ex06.4) [1] "company" "breakage" > boxcox(breakage~company) (a) The maximum is closes to zero, so we consider the log-transformation. > compare.to.best(f1,company,lowisbest=T) difference allowance * 1 - 4 1.4163417 0.4384483 * 2 - 4 0.7650023 0.4384483 * 3 - 4 0.5298419 0.4384483 best is 4 0.0000000 NA (b) Best (lowest breakage) is company 4, which is significantly better than the other three. > par(mfrow=c(2,2)) > plot(f1) (c) I think the residuals vs. predicted look fine; no evidence of non-constant variance. The normal probability plot shows a bit of curvature, but nothing that makes me worried. ---------------------------- Ex. 6.5 ---------------------------- (a) Right-opening megaphone show means variance is increasing with the response. Tells us little about normality and nothing about independence. (b) The NPP shows high curvature; these residuals are not normal. Tells us nothing about constant variance or independence. (c) Residuals vs. time order shows "clumps" of negative, then positive, then negative residuals as time increases: these are not independent. Doesn't tell us about constant variance or normality. (d) Residuals vs. predicted here shows constant variance reasonable. Tells us little about normality and nothing about independence. ---------------------------- Ex. 7.2 ---------------------------- > power.anova.test(means=c(10,11,11),ns=c(6,6,6),sigma2=4,alpha=.05) [1] 0.1170648 The power is only 0.12 under these values. > sample.size.anova(.9,.05,means=c(10,11,11),sigma2=4) $nis [1] 77 77 77 $power [1] 0.9002725 To get a power of at least 0.90 we need a sample size of n=77 in each group, giving a power of 0.90. ---------------------------- Pr. 7.2 ---------------------------- > sample.size.anova(.95,.01,means=c(45,32,60),sigma2=35) $nis [1] 4 4 4 $power [1] 0.9808418 We need n=4 in each group to achieve a power over 0.95. The actual power is 0.98.