### Small Sample Size
# p=Pr(X>Y)
# H0: p=1/2
X <- c(172,165,206,184,174,142,190,169,161,200)
Y <- c(201,179,159,192,177,170,182,179,169,210)
n <- length(X)
D <- X-Y
# for Ha: p > 1/2
m <- sum(D>0) # number of positive differences
p_value <- 1-pbinom(m-1, 10, 0.5) # Pr(m >= 2)
# for Ha: p < 1/2
p_value <- pbinom(m, 10, 0.5) # Pr(m <= 2)
# for Ha: p is not equal to 1/2
p_value <- (m<0.5*n)*2* pbinom(m, 10, 0.5) + (m>=0.5*n)*2*(1-pbinom(m-1, 10, 0.5))
### Large Sample Size
Z <- (m - n/2)/sqrt(n/4)
p_value <- 2*(1-pnorm(abs(Z))) # two-sided
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment