I want to get the P-value of two randomly distributed observations x and y, for example :
> set.seed(0) > x <- rnorm(1000, 3, 2) > y <- rnorm(2000, 4, 3)
> set.seed(0) > x <- rexp(50, 10) > y <- rexp(100, 11)
let's say that T is my test-statistic defined as mean(x) - mean(y) = 0 (this is H0), the P-value is then defined as : p-value = P[T>T_observed | H0 holds]. I tried doing this :
> 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)
then to calculate the p-value i tried this:
> 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%
obviously this doesn't seem to work, what am i missing ?