Problem 3.7

(c):

r1 <- c(3129,3000,2865,2890)
r2 <- c(3200,3300,2975,3150)
r3 <- c(2800,2900,2985,3050)
r4 <- c(2600,2700,2600,2765)
I1=4
J1=4
clm <- c(r1,r2,r3,r4)
type <- c(rep(1,4),rep(2,4),rep(3,4),rep(4,4))
dat1 <- cbind(clm,type)

dat1 <- as.data.frame(dat1)
dat1$type <- as.factor(dat1$type)

aov.model<-aov(clm~type,data=dat1)
summary(aov.model)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## type         3 489740  163247   12.73 0.000489 ***
## Residuals   12 153908   12826                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
alpha1 <- 0.05
MSE1 <- 12826
# IJ-I=4*4-4=12
CV1 <- qt(1-alpha1/2, I1*J1-I1)
CV1
## [1] 2.178813
LSD <- CV1*sqrt(MSE1*(1/J1+1/J1))
LSD
## [1] 174.482
abs(mean(r1)-mean(r2))
## [1] 185.25
abs(mean(r1)-mean(r3))
## [1] 37.25
abs(mean(r1)-mean(r4))
## [1] 304.75
abs(mean(r2)-mean(r3))
## [1] 222.5
abs(mean(r2)-mean(r4))
## [1] 490
abs(mean(r3)-mean(r4))
## [1] 267.5

null hypothesis: \(H_0: \mu_{i}-\mu_{j}=0\)

alternative hypothesis: \(H_1:\mu_{i} -\mu_{j} \ne0\)

We have 6 pairs– pair1&2, pair1&3, pair 1&4, pair 2&3, pair 2&4, pair 3&4.

Since |mean(r1)-mean(r3)|< the critical difference (37.25 < 174.4819651), reject null hypothesis. The pair 1&3 does not differ, while the rest pairs do differ.

————————————————————————————————

(d) (e):

plot(aov.model)

From the residual plot, variances can be said to be close to each other, which means variances are roughly equal. However, the variance of technique 4 is slightly higher than that of technique 1. (strong assumption)

From qqnorm plot, points are aligned by and large, so normal distributed by and large. (weak assumption)

(f): scatterplot

sdev <-c(rep(sd(r1),J1),rep(sd(r2),J1),rep(sd(r3),J1),rep(sd(r4),J1)) 
avg <- c(ave(r1), ave(r2), ave(r3), ave(r4))

plot(type, clm, ylim=range(c(avg-sdev, avg+sdev)), main="Scatterplot with average and error bar", xlab="Technique ", ylab="Tensile strength ", pch=19)

points(type,avg,pch = 15,col="red")
arrows(type, avg-sdev, type, avg+sdev, length=0.05, angle=90, code=3, col="red")

————————————————————————————————

Problem 3.10

(b):

r1 <- c(7,7,15,11,9)
r2 <- c(12,17,12,18,18)
r3 <- c(14,19,19,18,18)
r4 <- c(19,25,22,19,23)
r5 <- c(7,10,11,15,11)
I1=5
J1=5
clm <- c(r1,r2,r3,r4,r5)
type <- c(rep(1,5),rep(2,5),rep(3,5),rep(4,5),rep(5,5))
dat1 <- cbind(clm,type)

dat1 <- as.data.frame(dat1)
dat1$type <- as.factor(dat1$type)

aov.model<-aov(clm~type,data=dat1)
summary(aov.model)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## type         4  475.8  118.94   14.76 9.13e-06 ***
## Residuals   20  161.2    8.06                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
alpha1=0.05
MSE1 <- 8.06
# IJ-I=5*5-5=20
CV1 <- qt(1-alpha1/2, I1*J1-I1)
CV1
## [1] 2.085963
LSD1 <- CV1*sqrt(MSE1*(1/J1+1/J1))
LSD1
## [1] 3.745452
abs(mean(r1)-mean(r2))
## [1] 5.6
abs(mean(r1)-mean(r3))
## [1] 7.8
abs(mean(r1)-mean(r4))
## [1] 11.8
abs(mean(r1)-mean(r5))
## [1] 1
abs(mean(r2)-mean(r3))
## [1] 2.2
abs(mean(r2)-mean(r4))
## [1] 6.2
abs(mean(r2)-mean(r5))
## [1] 4.6
abs(mean(r3)-mean(r4))
## [1] 4
abs(mean(r3)-mean(r5))
## [1] 6.8
abs(mean(r4)-mean(r5))
## [1] 10.8

Or we can get critical value and LSD through LSD.test:

library(agricolae)
LSD.test(aov.model,"type",p.adj = "none",console=TRUE)
## 
## Study: aov.model ~ "type"
## 
## LSD t Test for clm 
## 
## Mean Square Error:  8.06 
## 
## type,  means and individual ( 95 %) CI
## 
##    clm      std r       LCL      UCL Min Max
## 1  9.8 3.346640 5  7.151566 12.44843   7  15
## 2 15.4 3.130495 5 12.751566 18.04843  12  18
## 3 17.6 2.073644 5 14.951566 20.24843  14  19
## 4 21.6 2.607681 5 18.951566 24.24843  19  25
## 5 10.8 2.863564 5  8.151566 13.44843   7  15
## 
## Alpha: 0.05 ; DF Error: 20
## Critical Value of t: 2.085963 
## 
## least Significant Difference: 3.745452 
## 
## Treatments with the same letter are not significantly different.
## 
##    clm groups
## 4 21.6      a
## 3 17.6      b
## 2 15.4      b
## 5 10.8      c
## 1  9.8      c

Assume \(\alpha = 0.05\).

null hypothesis: \(H_0: \mu_{i}-\mu_{j}=0\)

alternative hypothesis: \(H_1:\mu_{i} -\mu_{j} \ne0\)

We have 10 pairs– pair1&2, pair1&3, pair1&4, pair1&5, pair2&3, pair2&4, pair2&5, pair3&4, pair3&5, pair4&5.

Since |mean(r2)-mean(r3)| and |mean(r1)-mean(r5)|< the critical difference (2.2 and 1 < 3.7454518), reject null hypothesis. The pair 2&3 and 1&5 doe not differ, while the rest pairs do differ.

————————————————————————————————

(c):

plot(aov.model)

From the residual plot, variances are very close to each other, which means variances are roughly equal. (strong assumption)

From qqnorm plot, points are aligned by and large, so normal distributed by and large. (weak assumption)

————————————————————————————————

Problem 3.44

Here we have 4 polulations, power= 90%, error probability=0.05, type 1, variance= 25, f is actually the effect size.

mu1=50
mu2=60
mu3=50
mu4=60
mu <- c(mu1,mu2,mu3,mu4)
avemu <- mean(mu)

dif <- (mu1-avemu)^2+(mu2-avemu)^2+(mu3-avemu)^2+(mu3-avemu)^2
dif
## [1] 100
popno. <- 4 
variance <- 25
erroeprob <- 0.05
power <- 0.9
library(pwr)
pwr.anova.test(k=popno.,n=NULL,f=sqrt(dif/popno./variance),sig.level=erroeprob,power=power)
## 
##      Balanced one-way analysis of variance power calculation 
## 
##               k = 4
##               n = 4.658119
##               f = 1
##       sig.level = 0.05
##           power = 0.9
## 
## NOTE: n is number in each group

n = 4.658119, so we need 5 observations at least.

————————————————————————————————

Problem 3.54

(a):

Here we have 4 polulations, power= 90%, error probability=0.05, type 1, variance= 36, f is actually the effect size.

variance <- 36
pwr.anova.test(k=popno.,n=NULL,f=sqrt(dif/popno./variance),sig.level=erroeprob,power=power)
## 
##      Balanced one-way analysis of variance power calculation 
## 
##               k = 4
##               n = 6.180857
##               f = 0.8333333
##       sig.level = 0.05
##           power = 0.9
## 
## NOTE: n is number in each group

n = 6.180857, so we need 7 observations at least.

(b):

Here we have 4 polulations, power= 90%, error probability=0.05, type 1, variance= 49, f is actually the effect size.

variance <- 49
pwr.anova.test(k=popno.,n=NULL,f=sqrt(dif/popno./variance),sig.level=erroeprob,power=power)
## 
##      Balanced one-way analysis of variance power calculation 
## 
##               k = 4
##               n = 7.998751
##               f = 0.7142857
##       sig.level = 0.05
##           power = 0.9
## 
## NOTE: n is number in each group

n = 7.998751, so we need 8 observations at least, but 9 is safer.

(c): If variance increases, the uncertainty of the dataset increases, therefore theoretically, we need more observations to reamin the same confidence, error probability adn other parameters.

(d): Sometimes we do not have any upfront estimations on variability, using this power test to quantify the variables sampling size with a specific variance, power, error probability, diff mean and population numbers is imfomative. In similar way, we can define any parameters by feeding constant other parameters.