(1)
## (a) Write a nonparametric statistical model
# Response 5 6 7 8 8 9 10 12 15 16 17 20 21 23 30
# Rank 1 2 3 4.5 4.5 6 7 8 9 10 11 12 13 14 15
# H0: Response time is independent of Circuit type.
# HA: Response time increases when Circuit type changes.
# The hypothesis seems to be very obvious since it is common sense that change in the Circuit
# type will increase respone time or the response times of three Circuit types are not equal.
# let's look at the result from Kruskal-Wallis test.
## (b) Test the hypothesis in part (a)
library(clinfun)
## Warning: package 'clinfun' was built under R version 3.4.4
Circuit1 <- c(6,5,8,16,7)
Circuit2 <- c(9,12,10,8,15)
Circuit3 <- c(20,21,23,17,30)
Circuit <- c(Circuit1,Circuit2,Circuit3)
Response <- c(rep(1,5),rep(2,5),rep(3,5))
result <- kruskal.test(Circuit,Response)
result
##
## Kruskal-Wallis rank sum test
##
## data: Circuit and Response
## Kruskal-Wallis chi-squared = 10.374, df = 2, p-value = 0.00559
# Kruskal-Wallis rank sum test
# data: Circuit and Response
# Kruskal-Wallis chi-squared = 10.374, df = 2, p-value = 0.00559
# From the Kruskal-Wallis test, we can reject the null hypothesis
# (p-value is lower than 0.05) which means there is evidence that changes in the Circuit type
# will cause increasing response time or response times of three Circuit are not the same.
# This conclusion is what we expected.
(2)
## (a)
# let's try Jonckheere-Terpstra test and to see if there are any differences on results.
# The Jonckheere-Terpstra test shows the same results which means
# the changes in the Circuit type increases response time.
# H0: a1 = a2 = a3 = ... = ak
# HA: a1 <= a2 <= a3 <= ... <= ak (with at least one strict inequality)
## (b)
pieces <- list(Circuit1, Circuit2, Circuit3)
n <- c(5,5,5)
grp <- as.ordered(factor(rep(1:length(n),n)))
jonckheere.test(unlist(pieces),grp,alternative="increasing")
## Warning in jonckheere.test(unlist(pieces), grp, alternative = "increasing"): Sample size > 100 or data with ties
## p-value based on normal approximation. Specify nperm for permutation p-value
##
## Jonckheere-Terpstra test
##
## data:
## JT = 69.5, p-value = 0.0003612
## alternative hypothesis: increasing
# Jonckheere-Terpstra test
# data:
# JT = 69.5, p-value = 0.0003612
# alternative hypothesis: increasing
Conclusion
We can see that Kruskal-Wallis test does show the
clear evidence of changing in the Circuit type
increases response time or the response times of three
Circuit are not the same.
Furthemore, the Jonckheere-Terpstra does. However, the
Jonckheere-Terpstra test is generally more powerful
than Kruskal-Wallis test.
The Jonckheere-Terpstra test has higher probability
(p-value = 0.0003612) than Kruskal-Wallis test
(p-value = 0.00559).