x<-c(13, 12.5, 13.5, 14.2, 11.5, 12.5, 15, 15.5, 13.5, 13, 16, 15.5, 13.7, 12, 14.5)
Q<-sum(x>14)
# p vrijednost
n<-length(x)
pbinom(6, n, 0.5)>0.05
## [1] TRUE
# prihvatamo H_0
# H0(m=4) H1(m<4)
x<-c(4.4, 3.9, 5.2, 4.6, 4.3, 3.6, 4.4, 5.5, 3.8, 4.7, 4.1, 3.8, 4.8, 4.5, 5.6, 4.1, 4.5, 4)
q<-sum(x>4)
p<-pbinom(q,18,1/2)
p
## [1] 0.9845581
# blizu 1, prihvatamo H0
x <- c(0.75, 1.0, 0.69, 0.8, 0.57, 0.9, 1.5, 0.95, 0.6, 0.5, 0.62, 1.7, 0.53, 1.1, 1.2, 2.0, 0.65, 0.79, 0.61)
m0 <- 0.7
d <- x-m0
d
## [1] 0.05 0.30 -0.01 0.10 -0.13 0.20 0.80 0.25 -0.10 -0.20 -0.08
## [12] 1.00 -0.17 0.40 0.50 1.30 -0.05 0.09 -0.09
sort(abs(d))
## [1] 0.01 0.05 0.05 0.08 0.09 0.09 0.10 0.10 0.13 0.17 0.20 0.20 0.25 0.30
## [15] 0.40 0.50 0.80 1.00 1.30
wilcox.test(x, mu = 0.7, alternative = "greater")
##
## Wilcoxon signed rank test
##
## data: x
## V = 141, p-value = 0.03314
## alternative hypothesis: true location is greater than 0.7
x<-c(2.7, 10.5, 3.8, 15.2, 5.7, 3.5, 2.1, 4.0, 3.7)
wilcox.test(x, mu = 3, alternative = "greater")
##
## Wilcoxon signed rank test
##
## data: x
## V = 39, p-value = 0.02734
## alternative hypothesis: true location is greater than 3
}
novi 5 4.3 7.3 2.1 9.8 6.9 10 1.5 8.2 7.3
drugi 6.1 4.5 6.0 2.0 7.5 8 9.2 1 8 6.9
Za \(\alpha=0.05\) testom znakova ispitati da li je novi bolji od sapuna drugog proizvođača.
x <- c(5, 4.3, 7.3, 2.1 , 9.8, 6.9, 10, 1.5, 8.2, 7.3)
y <- c(6.1, 4.5, 6.0, 2.0, 7.5, 8, 9.2, 1, 8, 6.9)
d <- x - y
q <- sum(d < 0) # Q _
p <- pbinom(q, 10, 0.5)
p
## [1] 0.171875
p > 0.05
## [1] TRUE
A <- c(1.5, 1.4, 1.4, 1, 1.1, 0.9, 1.3, 1.2, 1.1, 0.9, 0.7, 1.8)
B <- c(2, 1.8, 0.7, 1.3, 1.2, 1.5, 1.1, 0.9, 1.5, 1.7, 0.9, 0.9)
Pretpostavljajući simetriju razlike ovih podataka, Vilkoksonovim testom označenih rangova ispitati navedenu tvrdnju za \(\alpha=0.05\).
A <- c(1.5, 1.4, 1.4, 1, 1.1, 0.9, 1.3, 1.2, 1.1, 0.9, 0.7, 1.8)
B <- c(2, 1.8, 0.7, 1.3, 1.2, 1.5, 1.1, 0.9, 1.5, 1.7, 0.9, 0.9)
d<-A-B
wilcox.test(d, mu=0, alternative = "less")
##
## Wilcoxon signed rank test
##
## data: d
## V = 28, p-value = 0.2119
## alternative hypothesis: true location is less than 0
# ili
wilcox.test(A, B, alternative = "less", paired = T)
##
## Wilcoxon signed rank test
##
## data: A and B
## V = 28, p-value = 0.2119
## alternative hypothesis: true location shift is less than 0
x <- c(8.1, 7.9, 9.0, 4.3, 7.0, 9.1, 7.2, 8, 9, 3.1)
y <- c(9.1, 6.3, 2.5, 6.0, 0, 2, 7, 5.5, 1, 9, 9.7, 5.1)
# Napomena: U ovom slucaju nemamo uparene podatke vec dva nezavisna uzorka!
wilcox.test(x,y, alternative = "greater")
## Warning in wilcox.test.default(x, y, alternative = "greater"): cannot
## compute exact p-value with ties
##
## Wilcoxon rank sum test with continuity correction
##
## data: x and y
## W = 82, p-value = 0.07779
## alternative hypothesis: true location shift is greater than 0