# Difference between revisions of "Power"

(5 intermediate revisions by the same user not shown) | |||

Line 6: | Line 6: | ||

* [http://r-video-tutorial.blogspot.com/2017/07/power-analysis-and-sample-size.html Power analysis and sample size calculation for Agriculture] ('''pwr, lmSupport, simr''' packages are used) | * [http://r-video-tutorial.blogspot.com/2017/07/power-analysis-and-sample-size.html Power analysis and sample size calculation for Agriculture] ('''pwr, lmSupport, simr''' packages are used) | ||

* [http://daniellakens.blogspot.com/2016/11/why-within-subject-designs-require-less.html Why Within-Subject Designs Require Fewer Participants than Between-Subject Designs] | * [http://daniellakens.blogspot.com/2016/11/why-within-subject-designs-require-less.html Why Within-Subject Designs Require Fewer Participants than Between-Subject Designs] | ||

+ | |||

+ | == Binomial distribution == | ||

+ | * [https://en.wikipedia.org/wiki/Binomial_test Binomial test]. Calculating a '''p-value''' for a two-tailed test is slightly more complicated, since a binomial distribution isn't symmetric if <math>\pi _{0}\neq 0.5</math>. | ||

+ | * [https://predictivehacks.com/how-to-get-the-power-of-test-in-hypothesis-testing-with-binomial-distribution/ How To Get The Power Of Test In Hypothesis Testing With Binomial Distribution] | ||

+ | * [https://www.statology.org/binomial-test-r/ How to Perform a Binomial Test in R] | ||

+ | * [https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/binom.test ?binom.test] | ||

= Power analysis for default Bayesian t-tests = | = Power analysis for default Bayesian t-tests = | ||

http://daniellakens.blogspot.com/2016/01/power-analysis-for-default-bayesian-t.html | http://daniellakens.blogspot.com/2016/01/power-analysis-for-default-bayesian-t.html | ||

− | = Using simulation for power analysis: an example based on a stepped wedge study design | + | = Using simulation for power analysis = |

− | https://www.rdatagen.net/post/ | + | * [https://www.rdatagen.net/post/using-simulation-for-power-analysis-an-example/ An example based on a stepped wedge study design] |

+ | * [https://www.rdatagen.net/post/2021-03-16-framework-for-power-analysis-using-simulation/ Framework for power analysis using simulation] | ||

= Power analysis and sample size calculation for Agriculture = | = Power analysis and sample size calculation for Agriculture = | ||

Line 122: | Line 129: | ||

= Unbalanced randomization = | = Unbalanced randomization = | ||

[https://www.rdatagen.net/post/can-unbalanced-randomization-improve-power/ Can unbalanced randomization improve power?] | [https://www.rdatagen.net/post/can-unbalanced-randomization-improve-power/ Can unbalanced randomization improve power?] | ||

+ | |||

+ | [https://www.rdatagen.net/post/unbalanced-randomization-can-improve-power-in-some-situations/ Yes, unbalanced randomization can improve power, in some situations] |

## Revision as of 18:35, 2 May 2021

# Power analysis/Sample Size determination

- https://en.m.wikipedia.org/wiki/Power_(statistics)
- Sample size determination from Wikipedia
- Power and Sample Size Determination http://www.stat.wisc.edu/~st571-1/10-power-2.pdf#page=12
- http://biostat.mc.vanderbilt.edu/wiki/pub/Main/AnesShortCourse/HypothesisTestingPart1.pdf#page=40
- Power analysis and sample size calculation for Agriculture (
**pwr, lmSupport, simr**packages are used) - Why Within-Subject Designs Require Fewer Participants than Between-Subject Designs

## Binomial distribution

- Binomial test. Calculating a
**p-value**for a two-tailed test is slightly more complicated, since a binomial distribution isn't symmetric if [math]\displaystyle{ \pi _{0}\neq 0.5 }[/math]. - How To Get The Power Of Test In Hypothesis Testing With Binomial Distribution
- How to Perform a Binomial Test in R
- ?binom.test

# Power analysis for default Bayesian t-tests

http://daniellakens.blogspot.com/2016/01/power-analysis-for-default-bayesian-t.html

# Using simulation for power analysis

# Power analysis and sample size calculation for Agriculture

http://r-video-tutorial.blogspot.com/2017/07/power-analysis-and-sample-size.html

# Power calculation for proportions (shiny app)

https://juliasilge.shinyapps.io/power-app/

# Derive the formula/manual calculation

- One-sample 1-sided test, One sample 2-sided test
- Two-sample 2-sided T test ([math]\displaystyle{ n }[/math] is the sample size in each group)

- [math]\displaystyle{ \begin{align} Power & = P_{\mu_1-\mu_2 = \Delta}(\frac{\bar{X}_1 - \bar{X}_2}{\sqrt{\sigma^2/n + \sigma^2/n}} \gt Z_{\alpha /2}) + P_{\mu_1-\mu_2 = \Delta}(\frac{\bar{X}_1 - \bar{X}_2}{\sqrt{\sigma^2/n + \sigma^2/n}} \lt -Z_{\alpha /2}) \\ & \approx P_{\mu_1-\mu_2 = \Delta}(\frac{\bar{X}_1 - \bar{X}_2}{\sqrt{\sigma^2/n + \sigma^2/n}} \gt Z_{\alpha /2}) \\ & = P_{\mu_1-\mu_2 = \Delta}(\frac{\bar{X}_1 - \bar{X}_2 - \Delta}{\sqrt{2 * \sigma^2/n}} \gt Z_{\alpha /2} - \frac{\Delta}{\sqrt{2 * \sigma^2/n}}) \\ & = \Phi(-(Z_{\alpha /2} - \frac{\Delta}{\sqrt{2 * \sigma^2/n}})) \\ & = 1 - \beta =\Phi(Z_\beta) \end{align} }[/math]

Therefore

- [math]\displaystyle{ \begin{align} Z_{\beta} &= - Z_{\alpha/2} + \frac{\Delta}{\sqrt{2 * \sigma^2/n}} \\ Z_{\beta} + Z_{\alpha/2} & = \frac{\Delta}{\sqrt{2 * \sigma^2/n}} \\ 2 * (Z_{\beta} + Z_{\alpha/2})^2 * \sigma^2/\Delta^2 & = n \\ n & = 2 * (Z_{\beta} + Z_{\alpha/2})^2 * \sigma^2/\Delta^2 \end{align} }[/math]

```
# alpha = .05, delta = 200, n = 79.5, sigma=450
1 - pnorm(1.96 - 200*sqrt(79.5)/(sqrt(2)*450)) + pnorm(-1.96 - 200*sqrt(79.5)/(sqrt(2)*450))
# [1] 0.8
pnorm(-1.96 - 200*sqrt(79.5)/(sqrt(2)*450))
# [1] 9.58e-07
1 - pnorm(1.96 - 200*sqrt(79.5)/(sqrt(2)*450))
# [1] 0.8
```

# Calculating required sample size in R and SAS

**pwr** package is used. For two-sided test, the formula for sample size is

- [math]\displaystyle{ n_{\mbox{each group}} = \frac{2 * (Z_{\alpha/2} + Z_\beta)^2 * \sigma^2}{\Delta^2} = \frac{2 * (Z_{\alpha/2} + Z_\beta)^2}{d^2} }[/math]

where [math]\displaystyle{ Z_\alpha }[/math] is value of the Normal distribution which cuts off an upper tail probability of [math]\displaystyle{ \alpha }[/math], [math]\displaystyle{ \Delta }[/math] is the difference sought, [math]\displaystyle{ \sigma }[/math] is the presumed standard deviation of the outcome, [math]\displaystyle{ \alpha }[/math] is the type 1 error, [math]\displaystyle{ \beta }[/math] is the type II error and (Cohen's) d is the **effect size** - difference between the means divided by the pooled standard deviation.

```
# An example from http://www.stat.columbia.edu/~gelman/stuff_for_blog/c13.pdf#page=3
# Method 1.
require(pwr)
pwr.t.test(d=200/450, power=.8, sig.level=.05,
type="two.sample", alternative="two.sided")
#
# Two-sample t test power calculation
#
# n = 80.4
# d = 0.444
# sig.level = 0.05
# power = 0.8
# alternative = two.sided
#
# NOTE: n is number in *each* group
# Method 2.
2*(qnorm(.975) + qnorm(.8))^2*450^2/(200^2)
# [1] 79.5
2*(1.96 + .84)^2*450^2 / (200^2)
# [1] 79.4
```

And stats::power.t.test() function.

```
power.t.test(n = 79.5, delta = 200, sd = 450, sig.level = .05,
type ="two.sample", alternative = "two.sided")
#
# Two-sample t test power calculation
#
# n = 79.5
# delta = 200
# sd = 450
# sig.level = 0.05
# power = 0.795
# alternative = two.sided
#
# NOTE: n is number in *each* group
```

CRAN Task View: Design of Experiments

- powerAnalysis w/o vignette
- powerbydesign w/o vignette
- easypower w/ vignette
- pwr w/ vignette, https://www.statmethods.net/stats/power.html. The reference is Cohen's book.
- powerlmm Power Analysis for Longitudinal Multilevel/Linear Mixed-Effects Models.
- ssize.fdr w/o vignette
- samplesize w/o vignette
- ssizeRNA w/ vignette
- power.t.test(), power.anova.test(), power.prop.test() from stats package

# Russ Lenth Java applets

https://homepage.divms.uiowa.edu/~rlenth/Power/index.html

# Bootstrap method

The upstrap Crainiceanu & Crainiceanu, Biostatistics 2018

# Multiple Testing Case

Optimal Sample Size for Multiple Testing The Case of Gene Expression Microarrays

# Unbalanced randomization

Can unbalanced randomization improve power?

Yes, unbalanced randomization can improve power, in some situations