[ANN] PowerAnalyses.jl

After more than a year of having to go back and forth between the R pwr package and G*Power, I finally decided that enough was enough and so there is now a Julia package for power analysis called PowerAnalyses.jl.

The aim of the package is quite straightforward and the same as the aforementioned packages: Given three parameters out of { alpha, power, effect size, sample size }, determine the fourth parameter. For example, to find the required sample size a study, use

julia> using PowerAnalyses

julia> es = 0.5
0.5

julia> alpha = 0.05
0.05

julia> power = 0.95
0.95

julia> n = get_n(OneSampleTTest(two_tails); alpha, power, es)
53.941

As a side note, this package was actually super much fun to make. The way that multiple-dispatch, Distributions.jl and Roots.jl worked together was just too good to be true :partying_face:

Specifically, for the interested people, the pwr package is full of code duplication. For example, compare:

where the code switches between qt, qchisq and other quantile functions. In Julia, that is of course just

quantile(d, beta)

for some d::UnivariateDistribution :exploding_head:

@rikh, thanks. If you think it’s appropriate, here’s a link to the Power of a test page, for users to learn more about the subject.

Nice. Yes. Good to add.

Another explanation: Statistical tests can tell you whether something is significantly different from some other thing. However, if you don’t have enough data, then there is a big chance that the test will always be not significant. For example, when you do a t-test to compare two samples of both 4 elements, the difference has to be huge for the test to say “the samples are significantly different”.

With a power analysis, you can estimate how big your sample should be (a priori power analysis) to make it less likely that you‘re wasting time on a study which would be very unlikely to find something anyway (to run an underpowered study).

(You could also just use a Bayesian analysis because it is more intuitive/coherent, but I guess that’s a discussion for another thread.)

I remember using G*Power…

So glad to never have to touch G*Power again! This is a great package - thanks @rikh!

Thanks!
Is there any advantage to adding this to the “blessed repo” HypothesisTests.jl?

I‘ve considered and tried basing the types on HypothesisTests.jl. The problem is that those types would make the API for PowerAnalyses much more complex without any clear benefit.

I haven’t yet implemented all the G*Power analyses, but yes long-term that should be possible :+1: