<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://bridgeslab.sph.umich.edu/protocols/index.php?action=history&amp;feed=atom&amp;title=Power_Analysis</id>
	<title>Power Analysis - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bridgeslab.sph.umich.edu/protocols/index.php?action=history&amp;feed=atom&amp;title=Power_Analysis"/>
	<link rel="alternate" type="text/html" href="https://bridgeslab.sph.umich.edu/protocols/index.php?title=Power_Analysis&amp;action=history"/>
	<updated>2026-05-31T23:47:24Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://bridgeslab.sph.umich.edu/protocols/index.php?title=Power_Analysis&amp;diff=2698&amp;oldid=prev</id>
		<title>Davebrid: Wrote page for power analysis, from Lab Documents repository</title>
		<link rel="alternate" type="text/html" href="https://bridgeslab.sph.umich.edu/protocols/index.php?title=Power_Analysis&amp;diff=2698&amp;oldid=prev"/>
		<updated>2024-08-21T16:38:17Z</updated>

		<summary type="html">&lt;p&gt;Wrote page for power analysis, from Lab Documents repository&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Commonly we want to know how to design our experiments (&amp;#039;&amp;#039;a priori&amp;#039;&amp;#039;), or how estimate how big of an effect we could have seen (&amp;#039;&amp;#039;a posteriori&amp;#039;&amp;#039;). We use two different methods for doing these kinds of analyses. One is using the [https://github.com/heliosdrm/pwr pwr package] in R. Alternatively sometimes we use [https://www.psychologie.hhu.de/arbeitsgruppen/allgemeine-psychologie-und-arbeitspsychologie/gpower.html G*Power], a standalone software with somewhat more functionality. Here we will focus on pwr, which is sufficient for most of our needs.&lt;br /&gt;
&lt;br /&gt;
= Some Definitions =&lt;br /&gt;
&lt;br /&gt;
; Effect Size&lt;br /&gt;
: The effect you expect to see, generally given as Cohen&amp;#039;s &amp;#039;&amp;#039;d&amp;#039;&amp;#039; which is calculated as expected difference between groups divided by the standard deviation &amp;lt;math&amp;gt;d=\frac{mean(group1)-mean(group2)}{sd}&amp;lt;/math&amp;gt;. If you are asking for the correlation between two parameters it is related to interested in the correlation coefficient rather than the difference between groups (r), you can use this formula &amp;lt;math&amp;gt;d= \frac{2r}{\sqrt{1 - r^2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
; Power&lt;br /&gt;
: The likelihood of being able to observe the effect size (if such an effect exists). Generally for prospective design purposes we use a power of 0.8. This is the same as one minus the false negative rate (FNR; the likelihood that an effect exists, but we cannot detect it, sometimes refered to as &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt;), so &amp;lt;math&amp;gt;Power = 1-FNR&amp;lt;/math&amp;gt;. Therefore conventionally &amp;lt;math&amp;gt;\beta=0.2&amp;lt;/math&amp;gt;. Therefore retrospectively the power says that for some particular effect size, n, and false positive rate, how likely we were to observe that effect.&lt;br /&gt;
; False Positive Rate&lt;br /&gt;
: The likelihood that we think there is a difference, when there is none, conventionally set as &amp;lt;math&amp;gt;\alpha=0.05&amp;lt;/math&amp;gt;.&lt;br /&gt;
; Sample Size&lt;br /&gt;
: The number used, be it number of participants, number of experimntal animals. &amp;#039;&amp;#039;&amp;#039;Not&amp;#039;&amp;#039;&amp;#039; the number of technical replicates&lt;br /&gt;
&lt;br /&gt;
These four parameters are related to each other such that if you know three of them, you can calculate the fourth. Some examples:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
! Missing Value&lt;br /&gt;
! Use Case&lt;br /&gt;
|-&lt;br /&gt;
| n&lt;br /&gt;
| Calculate how many needed in a group&lt;br /&gt;
|-&lt;br /&gt;
| Power&lt;br /&gt;
| Calculate likelihood of seeing an effect&lt;br /&gt;
|-&lt;br /&gt;
| Effect size&lt;br /&gt;
| Calculate detectable difference&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Power Analysis =&lt;br /&gt;
&lt;br /&gt;
::: {.cell}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r cell-code&amp;quot;&amp;gt;library(pwr)&lt;br /&gt;
#desired effect size in standard deviations&lt;br /&gt;
effect.size &amp;amp;lt;- 5 # expected difference in absolute terms&lt;br /&gt;
assay.sd &amp;amp;lt;- 3 # the standard deviation of the assay, in the same units as the effect size&lt;br /&gt;
effect.size.sd &amp;amp;lt;- effect.size/assay.sd&lt;br /&gt;
#desired false positive rate&lt;br /&gt;
fpr &amp;amp;lt;- 0.05&lt;br /&gt;
#desired power (inverse of false negative rate)&lt;br /&gt;
power &amp;amp;lt;- 0.8&lt;br /&gt;
#calculate required n&lt;br /&gt;
required.animals &amp;amp;lt;- pwr.t.test(d=effect.size.sd,&lt;br /&gt;
                               power=power,&lt;br /&gt;
                               sig.level=fpr,&lt;br /&gt;
                               alternative=&amp;amp;quot;greater&amp;amp;quot;,&lt;br /&gt;
                               type=&amp;amp;quot;two.sample&amp;amp;quot;)$n&amp;lt;/pre&amp;gt;&lt;br /&gt;
:::&lt;br /&gt;
&lt;br /&gt;
The assumptions set in this analysis are:&lt;br /&gt;
&lt;br /&gt;
* The desired effect size is 5. This is what we want to power our analysis to be able to detect.&lt;br /&gt;
* The standard deviation of the measurement is 3, in the same units as the effect size.&lt;br /&gt;
* Therefore Cohen&amp;#039;s &amp;#039;&amp;#039;d&amp;#039;&amp;#039; is 1.6666667 or the number of standard deviations we want to be able to detect.&lt;br /&gt;
* The acceptable false positive rate is 0.05. This is the percent chance that we observe something that is not actually true.&lt;br /&gt;
* The acceptable false negative rate is 0.2. This is the percent chance that we miss something that is actually true.&lt;br /&gt;
* The power of our analysis is set at 0.8.&lt;br /&gt;
&lt;br /&gt;
== Calculate Number of Animals ==&lt;br /&gt;
&lt;br /&gt;
At a standard power of 0.8 with a false positive rate of 0.05 and a desired effect size of a 5 difference in percent fat mass we would need &amp;#039;&amp;#039;&amp;#039;5.283492&amp;#039;&amp;#039;&amp;#039; animals in each group.&lt;br /&gt;
&lt;br /&gt;
== Calculate Detectable Effect Size ==&lt;br /&gt;
&lt;br /&gt;
::: {.cell}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r cell-code&amp;quot;&amp;gt;required.animals.effect &amp;amp;lt;- round(required.animals)&lt;br /&gt;
effective.d &amp;amp;lt;- pwr.t.test(power=power,&lt;br /&gt;
                               n=required.animals.effect,&lt;br /&gt;
                               sig.level=fpr,&lt;br /&gt;
                               alternative=&amp;amp;quot;greater&amp;amp;quot;,&lt;br /&gt;
                               type=&amp;amp;quot;two.sample&amp;amp;quot;)$d&amp;lt;/pre&amp;gt;&lt;br /&gt;
:::&lt;br /&gt;
&lt;br /&gt;
Based on the design above we should expect to detect an effect size of 1.7245893 standard deviations with 0.8 power, 5 animals and a FPR of 0.05.&lt;br /&gt;
&lt;br /&gt;
== Calculate Effective Power ==&lt;br /&gt;
&lt;br /&gt;
::: {.cell}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r cell-code&amp;quot;&amp;gt;required.animals.power &amp;amp;lt;- round(required.animals)&lt;br /&gt;
effective.power &amp;amp;lt;- pwr.t.test(d=effect.size.sd,&lt;br /&gt;
                               n=required.animals.power,&lt;br /&gt;
                               sig.level=fpr,&lt;br /&gt;
                               alternative=&amp;amp;quot;greater&amp;amp;quot;,&lt;br /&gt;
                               type=&amp;amp;quot;two.sample&amp;amp;quot;)$power&amp;lt;/pre&amp;gt;&lt;br /&gt;
:::&lt;br /&gt;
&lt;br /&gt;
Based on the design above we have a 77.5993902% chance of seeing a difference of 1.6666667 with 5 animals and a FPR of 0.05.&lt;br /&gt;
&lt;br /&gt;
The plot below shows how likely we are to detect a difference (the power) as we vary the number of animals (x-axis) and the desired effect size.&lt;br /&gt;
&lt;br /&gt;
::: {.cell}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r cell-code&amp;quot;&amp;gt;animals &amp;amp;lt;- seq(1:20) #animal range to test&lt;br /&gt;
effect.sizes &amp;amp;lt;- seq(1,9,by=1) # effect size range to test&lt;br /&gt;
power.table &amp;amp;lt;- expand.grid(animals=animals,effect.sizes=effect.sizes)&lt;br /&gt;
power.table$effect.sizes.sd &amp;amp;lt;- power.table$effect.sizes/assay.sd&lt;br /&gt;
&lt;br /&gt;
for (effect.size.sd in power.table$effect.sizes.sd){&lt;br /&gt;
for (n.test in power.table$animals){&lt;br /&gt;
  power.table[power.table$animals==n.test&amp;amp;amp;power.table$effect.sizes.sd==effect.size.sd,&amp;#039;power&amp;#039;] &amp;amp;lt;- &lt;br /&gt;
    pwr.t.test(d=effect.size.sd,&lt;br /&gt;
               n=n.test,&lt;br /&gt;
               sig.level=fpr,&lt;br /&gt;
               alternative=&amp;amp;quot;greater&amp;amp;quot;,&lt;br /&gt;
               type=&amp;amp;quot;two.sample&amp;amp;quot;)$power&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
library(ggplot2)&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
&lt;br /&gt;
power.table$effect.sizes.sd &amp;amp;lt;- as.factor(format(round(power.table$effect.sizes.sd,2),nsmall=2))&lt;br /&gt;
p &amp;amp;lt;- ggplot(power.table, aes(y=power,x=animals))&lt;br /&gt;
p + geom_line(aes(col=effect.sizes.sd)) +&lt;br /&gt;
  labs(y=&amp;amp;quot;Power&amp;amp;quot;,&lt;br /&gt;
       x=&amp;amp;quot;Animals&amp;amp;quot;,&lt;br /&gt;
       title=&amp;amp;quot;Effective power relative to animal numbers&amp;amp;quot;,&lt;br /&gt;
       subtitle=paste(&amp;amp;quot;Based on false positive rate of &amp;amp;quot;, fpr)) +&lt;br /&gt;
  geom_hline(yintercept=0.8, lty=2) + &lt;br /&gt;
  scale_colour_manual(&amp;amp;quot;Effect Sizes \n(Number of SD)&amp;amp;quot;, values=brewer.pal(10,&amp;#039;Blues&amp;#039;))&amp;lt;/pre&amp;gt;&lt;br /&gt;
::: {.cell-output-display} [[File:power-analysis_files/figure-html/effect-size-plot-1.png|672px]] ::: :::&lt;br /&gt;
&lt;br /&gt;
= Session Information =&lt;br /&gt;
&lt;br /&gt;
::: {.cell}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;r cell-code&amp;quot;&amp;gt;sessionInfo()&amp;lt;/pre&amp;gt;&lt;br /&gt;
::: {.cell-output .cell-output-stdout}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;R version 4.4.1 (2024-06-14)&lt;br /&gt;
Platform: x86_64-apple-darwin20&lt;br /&gt;
Running under: macOS Monterey 12.7.6&lt;br /&gt;
&lt;br /&gt;
Matrix products: default&lt;br /&gt;
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib &lt;br /&gt;
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0&lt;br /&gt;
&lt;br /&gt;
locale:&lt;br /&gt;
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8&lt;br /&gt;
&lt;br /&gt;
time zone: America/Detroit&lt;br /&gt;
tzcode source: internal&lt;br /&gt;
&lt;br /&gt;
attached base packages:&lt;br /&gt;
[1] stats     graphics  grDevices utils     datasets  methods   base     &lt;br /&gt;
&lt;br /&gt;
other attached packages:&lt;br /&gt;
[1] RColorBrewer_1.1-3 ggplot2_3.5.1      pwr_1.3-0         &lt;br /&gt;
&lt;br /&gt;
loaded via a namespace (and not attached):&lt;br /&gt;
 [1] vctrs_0.6.5       cli_3.6.3         knitr_1.48        rlang_1.1.4      &lt;br /&gt;
 [5] xfun_0.46         generics_0.1.3    jsonlite_1.8.8    labeling_0.4.3   &lt;br /&gt;
 [9] glue_1.7.0        colorspace_2.1-1  htmltools_0.5.8.1 scales_1.3.0     &lt;br /&gt;
[13] fansi_1.0.6       rmarkdown_2.27    grid_4.4.1        evaluate_0.24.0  &lt;br /&gt;
[17] munsell_0.5.1     tibble_3.2.1      fastmap_1.2.0     yaml_2.3.10      &lt;br /&gt;
[21] lifecycle_1.0.4   compiler_4.4.1    dplyr_1.1.4       pkgconfig_2.0.3  &lt;br /&gt;
[25] farver_2.1.2      digest_0.6.36     R6_2.5.1          tidyselect_1.2.1 &lt;br /&gt;
[29] utf8_1.2.4        pillar_1.9.0      magrittr_2.0.3    withr_3.0.0      &lt;br /&gt;
[33] tools_4.4.1       gtable_0.3.5     &amp;lt;/pre&amp;gt;&lt;br /&gt;
::: :::&lt;/div&gt;</summary>
		<author><name>Davebrid</name></author>
	</entry>
</feed>