#install.packages("tidyverse")
library(tidyr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
method<-c(rep(1,6),rep(2,6),rep(3,6),rep(4,6))
method<-as.factor(method)
obs<-c(0.34,0.12,1.23,0.70,1.75,0.12,
0.91,2.94,2.14,2.36,2.86,4.55,
6.31,8.37,9.75,6.09,9.82,7.24,
17.15,11.82,10.97,17.20,14.35,16.82)
df<-data.frame(method,obs)
H0: tau_1 = tau_2 = tau_3 = tau_4 = 0 (all method means equal)
HA: at least one method mean is different
m0 <- aov(obs ~ method, data=df)
summary(m0)
## Df Sum Sq Mean Sq F value Pr(>F)
## method 3 708.7 236.2 76.29 4e-11 ***
## Residuals 20 61.9 3.1
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(m0)
#Conclusion: At least one method’s mean discharge is different.
boxplot(obs~method, data = df, main="boxplot of discharge by method", xlab = "Method", ylab = "Discharge")
library("MASS")
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
bc<-boxcox(obs~method)
lambda=0.5
obs<-obs^(lambda)
boxcox(obs~method)
boxplot(obs~method, data = df, main="boxplot of discharge by method lambda 0.5", xlab = "Method", ylab = "Discharge")
# Kruskal–Wallis, α=0.05
kruskal.test(obs ~ method, data=df)
##
## Kruskal-Wallis rank sum test
##
## data: obs by method
## Kruskal-Wallis chi-squared = 21.156, df = 3, p-value = 9.771e-05