Search code examples
rstatisticsstatistical-test

Power analysis for two sample z-test


I need to compute the power of the statistical test that has been performed on the data. I have 2 csv files that have a sample size of 50 per file. The difference of means is statistically significant at the 0.05 level. The samples come from Normal distribution with unknown variance.

So I performed a z score test with the following code: X and Y are the two sample with sample size of 50 each.

zTest <- function(x, y) {
Difference <- (mean(x) - mean(y)) # difference between the two sample means
seDifference <- sqrt(((sd(x)^2)/length(x)) + ((sd(y)^2)/length(y))) #standard error for difference
zScore <- Difference/seDifference # z score
return(zScore) # return z score
}

The Z score value that I get is -15.78006

Now I need to compute the power of the statistical test performed above. My question is how do I find out the power from here. What is the formula? and How do I apply it in R. If you are going to suggest to use the pwr package in R then please explain how it works.

Thanks in advance and apologies if I'm being vague. I am new to power analysis.


Solution

  • I think you need the Effect Size when using pwr package.

    pwr.t.test(n = 50, d = NULL, sig.level = 0.05, power = NULL,
               type = c("two.sample"),
               alternative = c("two.sided"))
    

    where d = NULL is what you're missing

    Some explanation on effect size: http://www.ats.ucla.edu/stat/r/dae/t_test_power2.htm

    "Effect size will be the difference in means over the pooled standard deviation. The larger the effect size, the larger the power for a given sample size. Or, the larger the effect size, the smaller sample size needed to achieve the same power. So, a good estimate of effect size is the key to a good power analysis. But it is not always an easy task to determine the effect size. Good estimates of effect size come from the existing literature or from pilot studies"