Tutorial 6 Q1 X1 = c(1.38,1.26,1.51,1.46,1.61,1.59) X2 = c(1.36,1.28,1.41,1.39,1.51,1.44) n1 = c(41,41,33,45,18,23) n2 = c(40,38,35,46,20,23) s = c(0.22,0.25,0.31,0.28,0.34,0.46,0.28,0.19,0.27,0.33,0.41,0.30) n = c(41,41,33,45,18,23,40,38,35,46,20,23) s2 = sum(s^2 *(n-1))/(sum(n)-12) d = X1-X2 w = (n1*n2)/(n1+n2) dbar = sum(w*d)/sum(w) iss = sum(w*(d-dbar)^2) F.iss = iss/5/s2 F.tss = dbar^2*sum(w)/s2 Q3 x1=c(29.33333,28.25,20.4) x2=c(28,33.5,18.166666667) x3=c(16.333333333,4.4,8.5) x4=c(13.6,12.83333333,14.2) n1=c(6,4,5) n2=c(5,4,6) n3=c(3,5,4) n4=c(5,6,5) sd1 =c(13.02,5.85,13.37) sd2 =c(10.98,2.08,12.53) sd3 =c(14.19,6.91,9) sd4 =c(10.55,10.34,8.93) sd = c(sd1,sd2,sd3,sd4) x=c(x1,x2,x3,x4) n=c(n1,n2,n3,n4) S=factor(rep(c(1,2,3),4)) T=factor(c(rep(1,3),rep(2,3),rep(3,3),rep(4,3))) options(contrasts=c("contr.treatment","contr.poly")) lm.fit=lm(x~S+T, x=T, weights=n) anova(lm.fit) V=vcov(lm.fit) (i) sd =c(13.02,5.85,13.37,10.98,2.08,12.53, 14.19,6.91,9,10.55,10.34,8.93) s2 = sum(sd^2*(n-1))/(sum(n)-12) (iii) V.b = V[4:6,4:6]/117.88*s2 b = lm.fit$coef[4:6] # The three contrasts corresponding to: # C1: b[3] # C2: b[1]-b[3] # C3: b[2]-b[3] c1 = c(0,0,1) c2 = c(1,0,-1) c3 = c(0,1,-1) L1 = t(c1)%*%b / sqrt( t(c1)%*%V.b%*%c1 ) L2 = t(c2)%*%b / sqrt( t(c2)%*%V.b%*%c2 ) L3 = t(c3)%*%b / sqrt( t(c3)%*%V.b%*%c3 ) c(L1,L2,L3) # Dunnett's critical value: d(3,40,0.05) = 2.44, d(3,60,0.05) = 2.41 Dunnett.d = (46-40)*(2.41-2.44)/(60-40)+2.44