# \[ANN\] PowerAnalyses.jl

**URL:** <https://discourse.julialang.org/t/ann-poweranalyses-jl/70581>\
**Category:** Package Announcements\
**Created:** [October 28, 2021, 7:17pm UTC](https://discourse.julialang.org/t/ann-poweranalyses-jl/70581 "2021-10-28T19:17:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [October 28, 2021, 7:17pm UTC](https://discourse.julialang.org/t/ann-poweranalyses-jl/70581/1 "2021-10-28T19:17:29Z")

</div>

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](https://github.com/rikhuijzer/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
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 🥳

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

- [pwr/pwr.t.test.R at master · heliosdrm/pwr · GitHub](https://github.com/heliosdrm/pwr/blob/master/R/pwr.t.test.R)
- [pwr/pwr.t2n.test.R at master · heliosdrm/pwr · GitHub](https://github.com/heliosdrm/pwr/blob/master/R/pwr.t2n.test.R)
- [pwr/pwr.chisq.test.R at master · heliosdrm/pwr · GitHub](https://github.com/heliosdrm/pwr/blob/master/R/pwr.chisq.test.R)

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

```julia
quantile(d, beta)

```

for some `d::UnivariateDistribution` 🤯

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 28, 2021, 8:51pm UTC](https://discourse.julialang.org/t/ann-poweranalyses-jl/70581/2 "2021-10-28T20:51:14Z")

</div>

@rikh, thanks. If you think it’s appropriate, here’s a link to the [Power of a test](https://en.wikipedia.org/wiki/Power_of_a_test) page, for users to learn more about the subject.

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [October 28, 2021, 9:04pm UTC](https://discourse.julialang.org/t/ann-poweranalyses-jl/70581/3 "2021-10-28T21:04:20Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [October 28, 2021, 9:20pm UTC](https://discourse.julialang.org/t/ann-poweranalyses-jl/70581/4 "2021-10-28T21:20:23Z")

</div>

I remember using G\*Power…

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

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [October 28, 2021, 11:26pm UTC](https://discourse.julialang.org/t/ann-poweranalyses-jl/70581/5 "2021-10-28T23:26:16Z")

</div>

Thanks!  
Is there any advantage to adding this to the “blessed repo” [HypothesisTests](https://github.com/JuliaStats/HypothesisTests.jl).jl?

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [October 29, 2021, 5:18am UTC](https://discourse.julialang.org/t/ann-poweranalyses-jl/70581/6 "2021-10-29T05:18:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [October 29, 2021, 5:19am UTC](https://discourse.julialang.org/t/ann-poweranalyses-jl/70581/7 "2021-10-29T05:19:14Z")

</div>

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