Linear effect equation:
$$x_{ij}= \mu _{u}+\tau _{i}+\varepsilon _{ij}$$
Null hypotheses = \(H_{0}:\mu_{ 1}=\mu_{ 2}=\mu_{ 3}=\mu_{ 4}=\mu_{ 5}=\mu_{ 6}\)
Alternative Hypotheses = Atleast one mu differs
#Input data
Method1 <- c(0.34,0.12,1.23,0.7,1.75,0.12)
Method2 <- c(0.91,2.94,2.14,2.36,2.86,4.55)
Method3 <- c(6.31,8.37,9.75,6.09,9.82,7.24)
Method4 <- c(17.15,11.82,10.97,17.2,14.35,16.82)
dat<-data.frame(Method1, Method2, Method3, Method4)
#Transform data
library(tidyr)
dat<-pivot_longer(dat,c(Method1, Method2, Method3, Method4))
colnames(dat) <- c("Method", "Discharge")
#b. Conduct ANOVA and check Normality and Equal variance of Residual
anova_model <- aov(Discharge~Method, data = dat)
plot(anova_model)
Comments:
1)The Q-Q Residuals has the first two data and the last data is far from the normal line. The residual appear not normal.
2)The Residuals vs Factor shows that Method 4 has much higher variation than Method 1. It is not appear that the variance is constant
kruskal.test(Discharge~Method, data = dat)
##
## Kruskal-Wallis rank sum test
##
## data: Discharge by Method
## Kruskal-Wallis chi-squared = 21.156, df = 3, p-value = 9.771e-05
Comment: Reject the Ho with P value = 9.771e-05
library(MASS)
boxcox(dat$Discharge~dat$Method)
#Sellect lamda = 0.5
#Transform data with lamda = 0.5
lamda = 0.5
dat$Discharge = dat$Discharge^lamda
#Conduct ANOVA with transformed data
anova_model_new = aov(Discharge~Method, data = dat)
summary(anova_model_new)
## Df Sum Sq Mean Sq F value Pr(>F)
## Method 3 32.69 10.898 81.17 2.27e-11 ***
## Residuals 20 2.69 0.134
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(anova_model_new)
Comments:
1)After transformation, the variation of the residuals are equal. However, the Q-Q plot still show some data far from normal line.
2)Reject Ho with P value = 2.27e-11
It is a good idea to include this at the end of every RMarkdown document
#Input data
Method1 <- c(0.34,0.12,1.23,0.7,1.75,0.12)
Method2 <- c(0.91,2.94,2.14,2.36,2.86,4.55)
Method3 <- c(6.31,8.37,9.75,6.09,9.82,7.24)
Method4 <- c(17.15,11.82,10.97,17.2,14.35,16.82)
dat<-data.frame(Method1, Method2, Method3, Method4)
#Transform data
library(tidyr)
dat<-pivot_longer(dat,c(Method1, Method2, Method3, Method4))
colnames(dat) <- c("Method", "Discharge")
#b. Conduct ANOVA and check Normality and Equal variance of Residual
anova_model <- aov(Discharge~Method, data = dat)
plot(anova_model)
## The Q-Q Residuals has the first two data and the last data is far from the normal line. The residual appear not normal.
## The Residuals vs Factor shows that Method 4 has much higher variation than Method 1. It is not appear that the variance is constant
#c. Kruskal-Wallace test
?kruskal.test
kruskal.test(Discharge~Method, data = dat)
# Reject the Ho with P value = 9.771e-05
#d. Box Cox transformation
library(MASS)
boxcox(dat$Discharge~dat$Method)
#Sellect lamda = 0.5
#Transform data with lamda = 0.5
lamda = 0.5
dat$Discharge = dat$Discharge^lamda
#Conduct ANOVA with transformed data
anova_model_new = aov(Discharge~Method, data = dat)
summary(anova_model_new)
plot(anova_model_new)
#After transformation, the variation of the residuals are equal. However, the Q-Q plot still show some data far from normal line.
#Reject Ho with P value = 2.27e-11