#reading and formating the data
MT1 <-c(3129,3000,2865,2890)
MT2 <-c(3200,3300,2975,3150)
MT3 <-c(2800,2900,2985,3050)
MT4 <-c(2600,2700,2600,2765)
dat <-data.frame(cbind(MT1,MT2,MT3,MT4))
stacked_dat <- stack(dat)
anova_results <- aov(values~ind,dat = stacked_dat)#ANOVA
summary(anova_results) #ANOVA output
## Df Sum Sq Mean Sq F value Pr(>F)
## ind 3 489740 163247 12.73 0.000489 ***
## Residuals 12 153908 12826
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(agricolae)
lsd <- LSD.test(anova_results,"ind")#LSD test
print(lsd)#LSD test output
## $statistics
## MSerror Df Mean CV t.value LSD
## 12825.69 12 2931.812 3.862817 2.178813 174.4798
##
## $parameters
## test p.ajusted name.t ntr alpha
## Fisher-LSD none ind 4 0.05
##
## $means
## values std r LCL UCL Min Max Q25 Q50 Q75
## MT1 2971.00 120.55704 4 2847.624 3094.376 2865 3129 2883.75 2945.0 3032.25
## MT2 3156.25 135.97641 4 3032.874 3279.626 2975 3300 3106.25 3175.0 3225.00
## MT3 2933.75 108.27242 4 2810.374 3057.126 2800 3050 2875.00 2942.5 3001.25
## MT4 2666.25 80.97067 4 2542.874 2789.626 2600 2765 2600.00 2650.0 2716.25
##
## $comparison
## NULL
##
## $groups
## values groups
## MT2 3156.25 a
## MT1 2971.00 b
## MT3 2933.75 b
## MT4 2666.25 c
##
## attr(,"class")
## [1] "group"
As the LSD test output shows the difference between the means of all mixing techniques are significant (alpha=0.05), except the difference between mixing technique 1 and 3 (both of them have the same letter “b” in the output).
plot(anova_results,2)
By visually inspecting this plot, it seems that we have a normal distribution.
plot(anova_results,1)
This plot shows the residuals for each predicted tensile strength.
plot(stacked_dat$ind,stacked_dat$values)
This plot agrees with our conclusion in part c), where we concluded that the mean of all 4 mixing techniques are different except for mixing technique 1 and 3.
#reading data
cw15 <- c(7,7,15,11,9)
cw20 <- c(12,17,12,18,18)
cw25 <- c(14,19,19,18,18)
cw30 <- c(19,25,22,19,23)
cw35 <- c(7,10,11,15,11)
dat2 <- data.frame(cbind(cw15,cw20,cw25,cw30,cw35))
stacked_dat2 <- stack(dat2)
anova_results2 <- aov(values~ind,dat = stacked_dat2)#ANOVA
summary(anova_results2)
## Df Sum Sq Mean Sq F value Pr(>F)
## ind 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
library(agricolae)
lsd2 <- LSD.test(anova_results2,"ind")#LSD
print(lsd2)
## $statistics
## MSerror Df Mean CV t.value LSD
## 8.06 20 15.04 18.87642 2.085963 3.745452
##
## $parameters
## test p.ajusted name.t ntr alpha
## Fisher-LSD none ind 5 0.05
##
## $means
## values std r LCL UCL Min Max Q25 Q50 Q75
## cw15 9.8 3.346640 5 7.151566 12.44843 7 15 7 9 11
## cw20 15.4 3.130495 5 12.751566 18.04843 12 18 12 17 18
## cw25 17.6 2.073644 5 14.951566 20.24843 14 19 18 18 19
## cw30 21.6 2.607681 5 18.951566 24.24843 19 25 19 22 23
## cw35 10.8 2.863564 5 8.151566 13.44843 7 15 10 11 11
##
## $comparison
## NULL
##
## $groups
## values groups
## cw30 21.6 a
## cw25 17.6 b
## cw20 15.4 b
## cw35 10.8 c
## cw15 9.8 c
##
## attr(,"class")
## [1] "group"
These results show that cotton weight fo 25 and 20 and 35 and 15 have similar mean values, while every other combination results in a significance difference in means (alpha=0.05).
plot(anova_results2)
While, the normal plot shows a fairly normal distribution, these plots may not agree with the constant variance assumption. As it has been illustrated in the last graph, cotton weight of 15 might have a higher variance compared to other treatments.
power.anova.test(groups = 4,n = NULL,between.var = var(c(50,60,50,60)),within.var = 25,sig.level = 0.05,power = 0.9)
##
## Balanced one-way analysis of variance power calculation
##
## groups = 4
## n = 4.658128
## between.var = 33.33333
## within.var = 25
## sig.level = 0.05
## power = 0.9
##
## NOTE: n is number in each group
This power analysis test gave us a minimum n of 4.658128, which means that we need at least 5 observations.
power.anova.test(groups = 4,n = NULL,between.var = var(c(50,60,50,60)),within.var = 36,sig.level = 0.05,power = 0.9)
##
## Balanced one-way analysis of variance power calculation
##
## groups = 4
## n = 6.180885
## between.var = 33.33333
## within.var = 36
## sig.level = 0.05
## power = 0.9
##
## NOTE: n is number in each group
With a variance of 36, the number of required observations increases from 5 to 7.
power.anova.test(groups = 4,n = NULL,between.var = var(c(50,60,50,60)),within.var = 49,sig.level = 0.05,power = 0.9)
##
## Balanced one-way analysis of variance power calculation
##
## groups = 4
## n = 7.998751
## between.var = 33.33333
## within.var = 49
## sig.level = 0.05
## power = 0.9
##
## NOTE: n is number in each group
With the further increase of variance to 49, our required sample size increases to 8.
As the variance increases, the sample size increases with it.
These results show the importance of variance in sample size determination. It is crucial to either have a good idea about our variance by doing a preliminary study, looking at the data in the literature or at least have a good estimate of the expected variance to get a reasonable sample size.