欲得到兩個無規分佈的觀測x和y的P值,例如:R:計算的隨機分佈的P值
> set.seed(0)
> x <- rnorm(1000, 3, 2)
> y <- rnorm(2000, 4, 3)
或:
> set.seed(0)
> x <- rexp(50, 10)
> y <- rexp(100, 11)
假設T是我的測試統計量,定義爲mean(x) - mean(y)= 0(這是H0),那麼P值定義爲:p-value = P [T> T_observed | H0成立]。
我試着這樣做:
> z <- c(x,y) # if H0 holds then x and y are distributed with the same distribution
> f <- function(x) ecdf(z) # this will get the distribution of z (x and y)
然後計算p值我想這:
> T <- replicate(10000, mean(sample(z,1000,TRUE))-mean(sample(z,2000,TRUE))) # this is
supposed to get the null distribution of mean(x) - mean(y)
> f(quantile(T,0.05)) # calculating the p-value for a significance of 5%
顯然,這似乎並沒有工作,我失去了什麼?