<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Carlisle&#39;s Blog</title>
<link>https://www.carlislerainey.com/blog/</link>
<atom:link href="https://www.carlislerainey.com/blog/index.xml" rel="self" type="application/rss+xml"/>
<description></description>
<image>
<url>https://www.carlislerainey.com/profile.png</url>
<title>Carlisle&#39;s Blog</title>
<link>https://www.carlislerainey.com/blog/</link>
<height>96</height>
<width>144</width>
</image>
<generator>quarto-1.6.42</generator>
<lastBuildDate>Sat, 30 Aug 2025 04:00:00 GMT</lastBuildDate>
<item>
  <title>A One-Page Primer on: Statistical Power</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2025-08-30-1p-statistical-power/</link>
  <description><![CDATA[ 




<blockquote class="blockquote">
<p>“Of course, investigators could not have known how underpowered their research was, as their training had not prepared them to know anything about power, let alone how to use it in research planning. One might think that after 1969, when I published my power handbook that made power analysis as easy as falling off a log, the concepts and methods of power analysis would be taken to the hearts of null hypothesis testers. So one might think. (Stay tuned.)” — <a href="https://users.cla.umn.edu/~nwaller/prelim/cohensofar.pdf">Cohen (1990)</a></p>
</blockquote>
<div style="text-align:center; margin: 1.5em 0;">
<p><a href="1p-power-analysis.pdf" class="btn btn-warning btn-lg"> <i class="bi bi-file-earmark-pdf-fill"></i> One-Page Primer </a> <a href="mailto:?subject=A One-Page Primer on Statistical Power&amp;body=Hi! This is a resource on statistical power on Carlisle Rainey's website. It's a quick, one-page primer on statistical power. The HTML version is at https://www.carlislerainey.com/1p-statistical-power; the PDF version is at https://www.carlislerainey.com/1p-statistical-power/1p-statistical-power.pdf." class="btn btn-success btn-lg"> <i class="bi bi-envelope-fill"></i> Send to My Inbox </a></p>
</div>
<div style="text-align:center; margin: 1.5em 0;">

</div>
<section id="what-is-statistical-power" class="level2">
<h2 class="anchored" data-anchor-id="what-is-statistical-power">What is statistical power?</h2>
<p>Statistical power is the chance that your data lead you to reject the null hypothesis if that null hypothesis is incorrect. Power depends on the magnitude of the effect, so you must assume an effect for a power calculation. Claims about power have the form:</p>
<p>“the experiment has <strong><em>% power to detect an effect of </em></strong>.”</p>
</section>
<section id="why-does-power-matter-to-the-researcher" class="level2">
<h2 class="anchored" data-anchor-id="why-does-power-matter-to-the-researcher">Why does power matter to the researcher?</h2>
<p>You are a clever theorist and hypothesize that X increases Y; then the null hypothesis is that X does not increase Y. You design an experiment and statistical test. You plan to reject the null hypothesis if the p-value is less than 0.05. Two types of errors can occur.</p>
<p><strong>Type I:</strong> First, you might incorrectly reject the null hypothesis. That is, the null is true, but your p-value is less than 0.05 and you reject it.</p>
<p><strong>Type II:</strong> Second, you might incorrectly fail to reject the null hypothesis. That is, the null is false (i.e., the research hypothesis is correct), but your p-value is greater than 0.05 and you do not reject the null.</p>
<p>Let’s think more on this second “error.” You’ve paid all the costs of designing and fielding an experiment. But in the end, you cannot distinguish between your research hypothesis and the null hypothesis. This is a wasted opportunity. Researchers care about statistical power because they do not want to waste their time, effort, and money.</p>
</section>
<section id="why-does-power-matter-to-the-reader" class="level2">
<h2 class="anchored" data-anchor-id="why-does-power-matter-to-the-reader">Why does power matter to the reader?</h2>
<p>When reading a paper, why should you care about power?</p>
<p><em>My perspective:</em> Power doesn’t matter after running the experiment. All relevant information is in the confidence interval. Caveat: power does change the meaning of “not significant,” but this information is in the CI.</p>
<p><em>Others’ perspective:</em> Power matters greatly after running the experiment. Authors and reviewers dismiss papers without significant findings. This significance filter combined with low power causes published estimates to diverge from the truth.</p>
</section>
<section id="how-can-i-compute-statistical-power" class="level2">
<h2 class="anchored" data-anchor-id="how-can-i-compute-statistical-power">How can I compute statistical power?</h2>
<p>To compute statistical power, first ask: “for what effect?” Identify the range of substantively interesting effects and choose the smallest effect in this range. This is the smallest effect of substantive interest (SESOI). The experiment should be well-powered for the SESOI.</p>
<p>Fancy software can compute power for you, but I like simple rules of thumb. Experiments have:</p>
<ul>
<li>80% power to detect effects that are 2.5 times the standard error, and</li>
<li>95% power to detect effects that are 3.3 times the standard error.</li>
</ul>
<p>As a reader, you can simply multiply the reported standard errors by 2.5 and ask yourself: “is this effect substantively small?” If 2.5 times the reported standard error is a substantively large effect, then the experiment is underpowered.</p>
<p>As a researcher, you can predict the standard error of a simple two-group, difference-in-means comparison using <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BSE%7D%20=%20%5Cfrac%7B%5Csigma%7D%7B%5Csqrt%7Bn%7D%7D">, where <img src="https://latex.codecogs.com/png.latex?%5Csigma"> is the standard deviation of the outcome variable and <img src="https://latex.codecogs.com/png.latex?n"> is the sample size per condition. You can obtain a suitable value of <img src="https://latex.codecogs.com/png.latex?%5Csigma"> from an existing study of the same outcome and population. Or from a pilot study, if you plan to use one. As a too-crude shortcut in a pinch, you might use range/4.</p>
<p>Regression adjustment can increase power; it shrinks the standard error by a factor of about <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B1%20-%20R%5E2%7D">, where <img src="https://latex.codecogs.com/png.latex?R%5E2"> is the <img src="https://latex.codecogs.com/png.latex?R%5E2"> of the regression of the predictors on the outcome variable. Unless predictors are highly predictive of the outcome, adjustment doesn’t matter much. However, in pre–post designs, the researcher measures the outcome before and after the treatment and adjusts for the pre-treatment measure. This shrinks the standard error at least 30%, typically 50%, and perhaps 70%. You can obtain a suitable value of <img src="https://latex.codecogs.com/png.latex?R%5E2"> from a pilot study, if you have one.</p>
</section>
<section id="what-should-i-read-next" class="level2">
<h2 class="anchored" data-anchor-id="what-should-i-read-next">What should I read next?</h2>
<p><a href="https://doi.org/10.4324/9780203771587">Cohen (1988)</a> provides the foundational introduction to power analysis; <a href="https://users.cla.umn.edu/~nwaller/prelim/cohensofar.pdf">Cohen (1990)</a> offers an engaging personal and historical perspective. <a href="https://www.pearson.com/en-us/subject-catalog/p/probability-and-statistics-classic-version/P200000006163/9780137981694">DeGroot and Schervish (2010, ch.&nbsp;9)</a> and <a href="https://doi.org/10.1201/9781003456285">Casella and Berger (2002, ch.&nbsp;8)</a> provide a thorough technical discussion. <a href="https://psycnet.apa.org/fulltext/2000-16737-001.pdf">Jones and Tukey (2000)</a> discuss Type II errs as “wasted opportunities.”</p>
<p><a href="https://doi.org/10.1177/0193841X9501900504">Bloom (1995)</a> offers a practical and intuitive approach using the minimum detectable effect. <a href="https://doi.org/10.31219/osf.io/5am9q_v3">Rainey (2025)</a> updates Bloom’s perspective. <a href="https://doi.org/10.1007/s10654-016-0149-3">Greenland et al.&nbsp;(2016)</a> offer an accessible discussion organized around potential misunderstandings. <a href="https://doi.org/10.1037/0033-2909.112.1.155">Cohen (1992)</a>, <a href="https://doi.org/10.1198/000313001317098149">Lenth (2001)</a>, and <a href="https://doi.org/10.1093/jcr/ucx110">Meyvis and van Osselaer (2018)</a> also offer practical guides.</p>
<p><a href="https://www.carlislerainey.com/papers/nme.pdf">Rainey (2014)</a>, <a href="https://www.carlislerainey.com/papers/meaningful.pdf">McCaskey and Rainey (2015)</a>, and <a href="https://doi.org/10.1177/2515245918770963">Lakens, Scheel, and Isager (2018, see esp.&nbsp;pp.&nbsp;261-263)</a> discuss the SESOI. <a href="https://doi.org/10.1002/ejsp.2752">Lovakov and Agadullina (2021)</a> offer empirical rules for effect sizes derived from social psychology. <a href="https://doi.org/10.1016/j.jpsychires.2010.10.008">Leon, Davis, and Kraemer (2011)</a> and <a href="https://doi.org/10.1016/j.jesp.2017.09.004">Albers and Lakens (2018)</a> explain why pilot data should not be used to estimate the effect for the power calculation, though <a href="https://doi.org/10.1177/1745691614528519">Marco Perugini, Gallucci, and Costantini (2014)</a> propose a conservative alternative.</p>
<p><a href="https://doi.org/10.1198/000313001300339897">Hoenig and Heisey (2001)</a> explain why power should not be used for interpreting results. <a href="https://doi.org/10.1177/1745691614551642">Gelman and Carlin (2014)</a> explain the pernicious effects of filtering on statistical significance when power is low. <a href="https://doi.org/10.1086/734279">Arel-Bundock et al.&nbsp;(2025)</a> show that observed power in political science is very low. <a href="https://doi.org/10.1111/ecoj.12461">Ioannidis, Stanley, and Doucouliagos (2017)</a> examine economics; <a href="https://doi.org/10.1037/bul0000169">Stanley, Carter, and Doucouliagos (2018)</a> examine psychology.</p>
<p>Meyvis and van Osselaer (2018) discuss regression adjustment in the context of experiments. <a href="https://doi.org/10.1017/S0003055421000241">Clifford, Sheagley, and Piston (2021)</a> show huge boosts in power of the pre–post design; <a href="https://doi.org/10.31219/osf.io/q6czp_v2">Jordan, Ollerenshaw, and Trexler (2025)</a> validate their findings.</p>
<p><a href="https://doi.org/10.1525/collabra.33267">Lakens (2022)</a> offers a broader perspective on sample size justification beyond statistical power. <a href="https://doi.org/10.1017/S0003055419000194">Blair et al.&nbsp;(2019)</a> and <a href="https://book.declaredesign.org/">Blair, Coppock, and Humphreys (2023)</a> offer a useful conceptual framework and software for comprehensive evaluation of research designs.</p>


</section>

 ]]></description>
  <category>statistical power</category>
  <category>power analysis</category>
  <category>minimum detectable effect</category>
  <category>sample size</category>
  <category>research design</category>
  <guid>https://www.carlislerainey.com/blog/2025-08-30-1p-statistical-power/</guid>
  <pubDate>Sat, 30 Aug 2025 04:00:00 GMT</pubDate>
</item>
<item>
  <title>For Your Syllabus: Statistical Power</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2025-08-18-for-your-syllabus-power/</link>
  <description><![CDATA[ 




<p>As you prepare your courses on quantitative methods, consider including a section on <strong>statistical power</strong>.</p>
<p>Here are five readings I like and often recommend.</p>
<section id="quantitative-political-science-research-is-greatly-underpowered-arel-bundock-et-al." class="level2">
<h2 class="anchored" data-anchor-id="quantitative-political-science-research-is-greatly-underpowered-arel-bundock-et-al.">Quantitative Political Science Research is Greatly Underpowered (Arel-Bundock et al.)</h2>
<p>This paper shows that low power is a real problem—“doing what others have done” does not guarantee a well-powered study for the true effect. Instead, power requires some thinking!</p>
<p>From the abstract:<br>
&gt; “Only about 1 in 10 tests have at least 80% power to detect the consensus effects reported in the literature.”</p>
<ul>
<li>🔗 Journal DOI (<em>JOP</em>): <a href="https://doi.org/10.1086/734279" class="uri">https://doi.org/10.1086/734279</a><br>
</li>
<li>🔗 Preprint DOI (OSF): <a href="https://doi.org/10.31219/osf.io/7vy2f" class="uri">https://doi.org/10.31219/osf.io/7vy2f</a></li>
</ul>
<p><img src="https://www.carlislerainey.com/blog/2025-08-18-for-your-syllabus-power/images/arel-bundock-power-figure.png" class="img-fluid"></p>
</section>
<section id="minimum-detectable-effects-bloom-1995" class="level2">
<h2 class="anchored" data-anchor-id="minimum-detectable-effects-bloom-1995">Minimum Detectable Effects (Bloom 1995)</h2>
<p>Instead of focusing on power curves or abstract probabilities, Bloom asks a concrete question: <em>“What’s the smallest effect this design could reliably detect?”</em></p>
<p>The paper: - Defines the minimum detectable effect (MDE) clearly<br>
- Provides formulas and tables to compute it<br>
- Explains how design choices affect statistical power</p>
<ul>
<li>🔗 Journal DOI: <a href="https://doi.org/10.1177/0193841X9501900504" class="uri">https://doi.org/10.1177/0193841X9501900504</a><br>
</li>
<li>🔗 PDF: <a href="https://sites.uci.edu/gduncan/files/2021/03/Bloom-MDES-Eval-Rev-1995-Bloom.pdf" class="uri">https://sites.uci.edu/gduncan/files/2021/03/Bloom-MDES-Eval-Rev-1995-Bloom.pdf</a></li>
</ul>
<p><img src="https://www.carlislerainey.com/blog/2025-08-18-for-your-syllabus-power/images/bloom-mde-figure.png" class="img-fluid"></p>
</section>
<section id="power-rules" class="level2">
<h2 class="anchored" data-anchor-id="power-rules">Power Rules</h2>
<p>My (unpublished) paper updates Bloom’s ideas. Especially for political scientists or others using OLS and robust SEs, this paper may be useful.</p>
<p>It: 1. Builds intuition for power<br>
2. Develops simple rules for back-of-the-envelope power calculations<br>
3. Describes how to incorporate pilot data into power calculations</p>
<ul>
<li>🔗 Preprint DOI (OSF): <a href="https://doi.org/10.31219/osf.io/5am9q_v3" class="uri">https://doi.org/10.31219/osf.io/5am9q_v3</a></li>
</ul>
<p><img src="https://www.carlislerainey.com/blog/2025-08-18-for-your-syllabus-power/images/rainey-mde-figure.png" class="img-fluid"></p>
</section>
<section id="sample-size-justification-lakens-2022" class="level2">
<h2 class="anchored" data-anchor-id="sample-size-justification-lakens-2022">Sample Size Justification (Lakens 2022)</h2>
<p>Power is just one way to justify sample size. This paper offers a broader framework to align your design with your research goals.</p>
<p>Lakens outlines six common justifications: 1. Collecting data from (almost) the entire population<br>
2. Choosing a sample size based on resource constraints<br>
3. Performing an a-priori power analysis<br>
4. Planning for a desired accuracy (e.g., CI width)<br>
5. Using heuristics (e.g., 30 per group)<br>
6. Explicitly acknowledging the absence of a justification</p>
<ul>
<li>🔗 Journal DOI (open): <a href="https://doi.org/10.1525/collabra.33267" class="uri">https://doi.org/10.1525/collabra.33267</a></li>
</ul>
<p><img src="https://www.carlislerainey.com/blog/2025-08-18-for-your-syllabus-power/images/lakens-justification-table.png" class="img-fluid"></p>
</section>
<section id="declaring-and-diagnosing-research-designs-blair-et-al.-2019" class="level2">
<h2 class="anchored" data-anchor-id="declaring-and-diagnosing-research-designs-blair-et-al.-2019">Declaring and Diagnosing Research Designs (Blair et al.&nbsp;2019)</h2>
<p>The authors introduce a much more general way to think about designs. They propose the <strong>MIDA framework</strong>:</p>
<ul>
<li><p><strong>M</strong>odel: Assumptions about how the world works<br>
</p></li>
<li><p><strong>I</strong>nquiry: The specific question being asked<br>
</p></li>
<li><p><strong>D</strong>ata Strategy: The plan for collecting data<br>
</p></li>
<li><p><strong>A</strong>nswer Strategy: The method to answer the inquiry</p></li>
<li><p>🔗 Journal DOI (open): <a href="https://doi.org/10.1017/S0003055419000194" class="uri">https://doi.org/10.1017/S0003055419000194</a><br>
</p></li>
<li><p>📚 Book (open): <a href="https://book.declaredesign.org/" class="uri">https://book.declaredesign.org/</a><br>
</p></li>
<li><p>💻 R package site: <a href="https://declaredesign.org/r/declaredesign/" class="uri">https://declaredesign.org/r/declaredesign/</a></p></li>
</ul>
<p><img src="https://www.carlislerainey.com/blog/2025-08-18-for-your-syllabus-power/images/blair-mida-table.png" class="img-fluid"></p>
</section>
<section id="closing" class="level2">
<h2 class="anchored" data-anchor-id="closing">Closing</h2>
<p>These five readings complement each other really well. Students have a lot to gain from each.</p>
<table class="caption-top table">
<thead>
<tr class="header">
<th>Paper</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><a href="https://doi.org/10.1086/734279">Arel-Bundock et al.</a></td>
<td>Shows that most political science studies are underpowered; demonstrates the importance of thinking carefully about design.</td>
</tr>
<tr class="even">
<td><a href="https://doi.org/10.1177/0193841X9501900504">Bloom (1995)</a></td>
<td>Defines the minimum detectable effect (MDE) and explains how design choices influence power.</td>
</tr>
<tr class="odd">
<td><a href="https://doi.org/10.31219/osf.io/5am9q_v3">Rainey</a></td>
<td>Provides intuitive rules of thumb for power analysis, including using pilot data.</td>
</tr>
<tr class="even">
<td><a href="https://doi.org/10.1525/collabra.33267">Lakens (2022)</a></td>
<td>Broadens the discussion; outlines six ways to justify sample size beyond traditional power analysis.</td>
</tr>
<tr class="odd">
<td><a href="https://doi.org/10.1017/S0003055419000194">Blair et al.&nbsp;(2019)</a></td>
<td>Introduces the MIDA framework for formally declaring and diagnosing research designs.</td>
</tr>
</tbody>
</table>


</section>

 ]]></description>
  <category>statistical power</category>
  <category>power analysis</category>
  <category>minimum detectable effect</category>
  <category>sample size</category>
  <category>research design</category>
  <category>for your syllabus</category>
  <category>teaching</category>
  <guid>https://www.carlislerainey.com/blog/2025-08-18-for-your-syllabus-power/</guid>
  <pubDate>Mon, 18 Aug 2025 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Customize Your Terminal Prompt on macOS</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2025-03-21-customize-your-terminal-prompt-on-macOS/</link>
  <description><![CDATA[ 




<section id="motivation" class="level2">
<h2 class="anchored" data-anchor-id="motivation">Motivation</h2>
<p>This is for <strong>macOS</strong> using the default <strong>zsh</strong> shell (used in macOS Catalina and later).</p>
<p>The command prompt on macOS doesn’t look nice by default. Here’s my preferred adjustment, where the prompt shows just the current folder followed by <code>&gt;</code>.</p>
<p>Like this:</p>
<pre><code>my-folder &gt;</code></pre>
<p>Here’s what I want the Terminal to look like on macOS (when I’m working on <code>website/</code>).</p>
<div class="quarto-figure quarto-figure-left">
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2025-03-21-customize-your-terminal-prompt-on-macOS/images/macOS-terminal.png" class="img-fluid quarto-figure quarto-figure-left figure-img" style="width:6in"></p>
</figure>
</div>
<p>And Here’s what I want it to look like in RStudio.</p>
<p><img src="https://www.carlislerainey.com/blog/2025-03-21-customize-your-terminal-prompt-on-macOS/images/rstudio-terminal-01.png" class="img-fluid" style="width:2in"></p>
</section>
<section id="how-to-do-it" class="level2">
<h2 class="anchored" data-anchor-id="how-to-do-it">How to Do It</h2>
<p>Here’s how to make the change:</p>
<ol type="1">
<li>Open Terminal and run <code>open -a TextEdit ~/.zshrc</code>. This opens <code>~/.zshrc</code> in TextEdit.</li>
<li>Add <code>export PS1="%1~ &gt; "</code> to the bottom of the file.</li>
<li>Save and close TextEdit.</li>
<li>Restart Terminal or run <code>source ~/.zshrc</code> to see the new prompt.</li>
</ol>
<p>If you ever want to reset or further customize your prompt, you can edit <code>~/.zshrc</code> again and change the <code>PS1</code> line.</p>


</section>

 ]]></description>
  <guid>https://www.carlislerainey.com/blog/2025-03-21-customize-your-terminal-prompt-on-macOS/</guid>
  <pubDate>Mon, 31 Mar 2025 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Kane (2025) as a Power Paper</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2025-03-19-kane-2025-as-a-power-paper/</link>
  <description><![CDATA[ 




<p>It’s helpful to think of statistical power as determined by the ratio <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctau%7D%7BSE%7D">, where <img src="https://latex.codecogs.com/png.latex?%5Ctau"> is the treatment effect and SE is the standard error of the estimate.<sup>1</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn1"><p><sup>1</sup>&nbsp;<span class="citation" data-cites="bloom1995">Bloom (1995)</span> has a really beautiful paper on this idea. It’s one of my favorites. I also have a <a href="https://osf.io/preprints/osf/5am9q_v3">preprint</a> on the topic.</p></div></div><p><a href="https://www.carlislerainey.com/blog/2023-06-12-power-3-rule-of-364/">I like this ratio</a> because it makes two distinct tasks clear:</p>
<ol type="1">
<li>create a treatment with some oomph and</li>
<li>estimate it precisely.</li>
</ol>
<p>While pitched as a paper on null result, <span class="citation" data-cites="kane2025">Kane (2025)</span> offers a very helpful (and thorough!) list of ideas to increase statistical power.</p>
<section id="power-as-a-ratio" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="power-as-a-ratio">Power as a Ratio</h2>
<p>For a “well-powered experiment,” the task is to get the ratio <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctau%7D%7BSE%7D"> above at least 2.5 (for 80% power) and ideally to 3.3 (for 95% power).<sup>2</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn2"><p><sup>2</sup>&nbsp;Remember that “well-powered” isn’t a given. Most political science research is “greatly underpowered” <span class="citation" data-cites="arel-bundock2022">(Arel-Bundock et al. 2022)</span>.</p></div></div><p>Here’s <a href="https://osf.io/preprints/osf/5am9q_v3">the idea</a>:</p>
<blockquote class="blockquote">
<p>Power equals <img src="https://latex.codecogs.com/png.latex?1%20-%20%5CPhi_%7Bstd%7D%5Cleft(%201.64%20-%20%5Cfrac%7B%5Ctau%7D%7BSE%7D%20%5Cright)">, where <img src="https://latex.codecogs.com/png.latex?%5CPhi_%7Bstd%7D(z)"> is the standard normal CDF (as found in a standard <img src="https://latex.codecogs.com/png.latex?z"> table), <img src="https://latex.codecogs.com/png.latex?SE"> is the standard error of the estimated treatment effect, and <img src="https://latex.codecogs.com/png.latex?%5Ctau"> is the treatment effect.</p>
</blockquote>
<blockquote class="blockquote">
<p>This rule allows us to connect statistical power to the familiar <img src="https://latex.codecogs.com/png.latex?z"> table in the appendices of many statistics textbooks or the <code>pnorm()</code> function in R. But, more importantly, it drives home an important intuition—<strong>power is determined by the key ratio</strong> <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctau%7D%7BSE%7D">. To estimate power, we must make an informed assumption about the effect of interest and a good prediction of standard error of the estimate. Further, when we consider changes to the experimental design and the consequences for statistical power, it can be helpful to think about the numerator or the denominator of the key ratio <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctau%7D%7BSE%7D">: <strong>How do you make the effect as large as possible? And how do you make the estimate as precise as possible?</strong></p>
</blockquote>
<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Two Key Tasks
</div>
</div>
<div class="callout-body-container callout-body">
<ol type="1">
<li>Make the effect as large as possible.</li>
<li>Make the estimate as precise as possible.</li>
</ol>
</div>
</div>
</section>
<section id="kanes-list-and-relevance-to-the-ratio" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="kanes-list-and-relevance-to-the-ratio">Kane’s List, and Relevance to the Ratio</h2>
<p><span class="citation" data-cites="kane2025">Kane (2025)</span> offers an excellent list of options to either increase the treatment effect or shrink the standard error.</p>
<p>He pitches the list as a way to make a compelling case for null results. However, the list is also helpful for making sure that we’ve thought through the ways to maximize power. It’s a wonderful paper well worth a careful read for folks who run experiments or read experimental work.</p>
<p>I’m going to borrow his list and connect the action items to statistical power.</p>
<p>Kane arranges his list into seven “alternative explanations” for null results, which we might think of as “potential power leakages.” I recreated a version of Kane’s table (Table 1 in his paper) that contains each action item to consider. I’ve kept Kane’s labeling for the various categories, but taken some liberties in collapsing some of the action items.<sup>3</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn3"><p><sup>3</sup>&nbsp;He breaks his suggestions into to columns for the current study and future studies. For my purposes, these can be collapsed.</p></div></div><p>The table below lists all of Kane’s categories and action items and notes the pathway through which this stop might increase statistical power. While Kane doesn’t explicitly pitch the list as “ways to increase” power, we can certainly borrow it for that purpose.</p>
<div class="column-page">
<table class="caption-top table">
<thead>
<tr class="header">
<th>Kane’s Categories</th>
<th>Action Item</th>
<th>Pathway to Increase Power</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong>#1: Inattentiveness</strong></td>
<td>Include a measure of attention to the experimental manipulation (after the outcome measure)</td>
<td>NA</td>
</tr>
<tr class="even">
<td></td>
<td>Feature experiment relatively earlier in survey</td>
<td>Increase treatment effect.</td>
</tr>
<tr class="odd">
<td></td>
<td>More salient treatment content</td>
<td>Increase treatment effect.</td>
</tr>
<tr class="even">
<td></td>
<td>Consider techniques to improve respondent attentiveness</td>
<td>Increase treatment effect.</td>
</tr>
<tr class="odd">
<td></td>
<td>Use alternative survey company</td>
<td>Increase treatment effect; see <span class="citation" data-cites="stagnaro2024">Stagnaro et al. (2024)</span> for more.</td>
</tr>
<tr class="even">
<td></td>
<td>Increased (pre-treatment) screening-out of inattentive respondents</td>
<td>Increase treatment effect, though a smaller sample size will increase the standard error.</td>
</tr>
<tr class="odd">
<td><strong>#2: Failure to vary the independent variable</strong></td>
<td>Include a manipulation check after the outcome measure</td>
<td>NA</td>
</tr>
<tr class="even">
<td></td>
<td>Make treatment content more salient (e.g., appear sooner and/or more frequently)</td>
<td>Increase treatment effect.</td>
</tr>
<tr class="odd">
<td></td>
<td>Make treatment stronger (e.g., more direct, forceful language)</td>
<td>Increase treatment effect.</td>
</tr>
<tr class="even">
<td><strong>#3: Pre-treatment effect</strong></td>
<td>Include a measure to gauge how pre-treated a respondent might be (implemented prior to random assignment)</td>
<td>NA</td>
</tr>
<tr class="odd">
<td></td>
<td>Make treatment stronger (assuming no ceiling/floor effect)</td>
<td>Increase treatment effect.</td>
</tr>
<tr class="even">
<td></td>
<td>Postpone the study until treatment has lower salience in the real world</td>
<td>Increase treatment effect.</td>
</tr>
<tr class="odd">
<td></td>
<td>Investigate using a non-experimental design</td>
<td>NA</td>
</tr>
<tr class="even">
<td><strong>#4: Statistical power</strong></td>
<td>Conduct power analyses to determine necessary n size (assuming smallest meaningful effect size)</td>
<td>Decrease standard error; see <span class="citation" data-cites="bloom1995">Bloom (1995)</span> and <a href="https://osf.io/preprints/osf/5am9q_v3">this preprint</a> for more.</td>
</tr>
<tr class="odd">
<td></td>
<td>Choose sample size cognizant of number of conditions, subgroup analyses, and likely inattentiveness</td>
<td>Decrease standard error; see <span class="citation" data-cites="bloom1995">Bloom (1995)</span> and <a href="https://osf.io/preprints/osf/5am9q_v3">this preprint</a> for more.</td>
</tr>
<tr class="even">
<td></td>
<td>Use pre-registered covariates in model, blocking, or a within-subjects design</td>
<td>Decrease standard error; see <span class="citation" data-cites="blair2019">Blair et al. (2019)</span> and <span class="citation" data-cites="blair2023">Blair, Coppock, and Humphreys (2023)</span> for a framework to assess the impact of these design choices; ; see <span class="citation" data-cites="clifford2021">Clifford, Sheagley, and Piston (2021)</span> for a good approach using a pre-post design.</td>
</tr>
<tr class="odd">
<td></td>
<td>Aim to collect a larger sample</td>
<td>Decrease standard error.</td>
</tr>
<tr class="even">
<td></td>
<td>Choose sample size cognizant of quantities learned from first study: effect size, SD of Y, level of inattentiveness, and number/size of subgroup analyses</td>
<td>Decrease standard error; this <a href="https://osf.io/preprints/osf/5am9q_v3">this preprint</a> presents some ideas about how to connect power analysis to existing studies.</td>
</tr>
<tr class="odd">
<td></td>
<td>Consider an alternative design structure (e.g., within-subjects)</td>
<td>Decrease standard error.</td>
</tr>
<tr class="even">
<td><strong>#5: Poor measurement of the dependent variable</strong></td>
<td>Check Y’s criterion validity</td>
<td>Decrease standard error; perhaps also increase treatment effect.</td>
</tr>
<tr class="odd">
<td></td>
<td>If possible, use existing (validated) measures of Y</td>
<td>Decrease standard error; perhaps also increase treatment effect.</td>
</tr>
<tr class="even">
<td></td>
<td>Use an alternative and/or multiple measures of Y to reduce measurement error</td>
<td>Decrease standard error; perhaps also increase treatment effect.</td>
</tr>
<tr class="odd">
<td><strong>#6: Ceiling/Floor effect</strong></td>
<td>Use measure of Y that is unlikely to have an extremely high/low mean (e.g., scales with more extreme end-points or multi-item scales)</td>
<td>Increase treatment effect.</td>
</tr>
<tr class="even">
<td></td>
<td>Assuming population of interest remains the same, use a measure of Y with a more (conceptually) extreme range</td>
<td>Increase treatment effect.</td>
</tr>
<tr class="odd">
<td></td>
<td>Consider postponing study if ceiling/floor is due to current context</td>
<td>Increase treatment effect.</td>
</tr>
<tr class="even">
<td><strong>#7: Countervailing treatment effects</strong></td>
<td>Include a pre-treatment measure of the moderating variable, across which countervailing effects might occur</td>
<td>Increase treatment effect (by changing definition slightly); this will increase the standard error.</td>
</tr>
<tr class="odd">
<td></td>
<td>Pre-register a hypothesized interaction between treatment and moderator</td>
<td>Increase treatment effect (by changing definition slightly); this will increase the standard error.</td>
</tr>
<tr class="even">
<td></td>
<td>Include best possible (pre-treatment) measure(s) of moderating variable to improve precision</td>
<td>Decrease standard error.</td>
</tr>
</tbody>
</table>
</div>
<p>And for completeness, here is Kane’s original table:</p>
<p><img src="https://www.carlislerainey.com/blog/2025-03-19-kane-2025-as-a-power-paper/images/clipboard-1273155981.png" class="img-fluid"></p>



</section>


<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-arel-bundock2022" class="csl-entry">
Arel-Bundock, Vincent, Ryan C Briggs, Hristos Doucouliagos, Marco Mendoza Aviña, and T. D. Stanley. 2022. <span>“Quantitative Political Science Research Is Greatly Underpowered.”</span> <a href="http://dx.doi.org/10.31219/osf.io/7vy2f">http://dx.doi.org/10.31219/osf.io/7vy2f</a>.
</div>
<div id="ref-blair2019" class="csl-entry">
Blair, Graeme, Jasper Cooper, Alexander Coppock, and Macartan Humphreys. 2019. <span>“Declaring and Diagnosing Research Designs.”</span> <em>American Political Science Review</em> 113 (3): 838–59. <a href="https://doi.org/10.1017/s0003055419000194">https://doi.org/10.1017/s0003055419000194</a>.
</div>
<div id="ref-blair2023" class="csl-entry">
Blair, Graeme, Alexander Coppock, and Macartan Humphreys. 2023. <em>Research Design in the Social Sciences</em>. Princeton, NJ: Princeton University Press.
</div>
<div id="ref-bloom1995" class="csl-entry">
Bloom, Howard S. 1995. <span>“Minimum Detectable Effects.”</span> <em>Evaluation Review</em> 19 (5): 547–56. <a href="https://doi.org/10.1177/0193841x9501900504">https://doi.org/10.1177/0193841x9501900504</a>.
</div>
<div id="ref-clifford2021" class="csl-entry">
Clifford, Scott, Sheagley Geoffrey, and Spencer Piston. 2021. <span>“Increasing Precision Without Altering Treatment Effects: Repeated Measures Designs in Survey Experiments.”</span> <em>American Political Science Review</em> 115 (3): 1048–65. <a href="https://doi.org/10.1017/s0003055421000241">https://doi.org/10.1017/s0003055421000241</a>.
</div>
<div id="ref-kane2025" class="csl-entry">
Kane, John V. 2025. <span>“More Than Meets the ITT: A Guide for Anticipating and Investigating Nonsignificant Results in Survey Experiments.”</span> <em>Journal of Experimental Political Science</em> 12 (1): 110–25. <a href="https://doi.org/10.1017/xps.2024.1">https://doi.org/10.1017/xps.2024.1</a>.
</div>
<div id="ref-stagnaro2024" class="csl-entry">
Stagnaro, Michael N, James Druckman, Adam J Berinsky, Antonio A Arechar, Robb Willer, and David G Rand. 2024. <span>“Representativeness Versus Response Quality: Assessing Nine Opt-in Online Survey Samples.”</span> PsyArXiv. <a href="https://doi.org/10.31234/osf.io/h9j2d">https://doi.org/10.31234/osf.io/h9j2d</a>.
</div>
</div></section></div> ]]></description>
  <category>statistical power</category>
  <category>hypothesis tests</category>
  <category>power analysis</category>
  <category>methodology</category>
  <guid>https://www.carlislerainey.com/blog/2025-03-19-kane-2025-as-a-power-paper/</guid>
  <pubDate>Wed, 19 Mar 2025 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Statistical Power from Pilot Data: An Example</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2024-06-10-pilot-power-example/</link>
  <description><![CDATA[ 




<hr>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Power Rules
</div>
</div>
<div class="callout-body-container callout-body">
<p>This post is based on <a href="https://osf.io/preprints/osf/5am9q_v2">this paper</a> called “Power Rules.”</p>
</div>
</div>
<p>We can think of statistical power as determined by the ratio <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctau%7D%7BSE%7D">, where <img src="https://latex.codecogs.com/png.latex?%5Ctau"> is the treatment effect and SE is the standard error of the estimate. To reason about statistical power, one needs to make assumptions or predictions about the treatment effect and the standard error.</p>
<p>And as data-oriented researchers, we often want to use data to inform these predictions and assumptions. We might want to use <em>pilot</em> data.<sup>1</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn1"><p><sup>1</sup>&nbsp;Here’s how <span class="citation" data-cites="leon2011">Leon, Davis, and Kraemer (2011)</span> describe the purpose of a pilot study. “The fundamental purpose of conducting a pilot study is to examine the feasibility of an approach that is intended to ultimately be used in a larger scale study. This applies to all types of research studies. Here we use the randomized controlled clinical trial (RCT) for illustration. Prior to initiating a full scale RCT an investigator may choose to conduct a pilot study in order to evaluate the feasibility of recruitment, randomization, retention, assessment procedures, new methods, and/or implementation of the novel intervention. A pilot study, however, is not used for hypothesis testing. Instead it serves as an earlier-phase developmental function that will enhance the probability of success in the larger subsequent RCTs that are anticipated.”</p></div></div><p>Usually:</p>
<ol type="1">
<li>Pilot data are <em>not</em> useful to predict the treatment effect.</li>
<li>Pilot data are useful to predict the standard error.</li>
</ol>
<p>With a predicted standard error in hand, we can predict the minimum detectable effect, the statistical power, or the required sample size in the planned study.</p>
<p>In this post, I give an example of how this can work.</p>
<section id="predicting-the-se-from-pilot-data" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="predicting-the-se-from-pilot-data">Predicting the SE from pilot data</h2>
<p>Here’s how I suggest we use pilot data to predict the standard error in the planned study:</p>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Predicting the SE in the planned study using pilot data
</div>
</div>
<div class="callout-body-container callout-body">
<p>Conservatively, the standard error will be about <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B%5Cfrac%7Bn%5E%7Bpilot%7D%7D%7Bn%5E%7Bplanned%7D%7D%7D%20%5Ccdot%20%5Cleft%5Clbrack%20%5Cleft(%20%5Csqrt%7B%5Cfrac%7B1%7D%7Bn%5E%7Bpilot%7D%7D%7D%20+%201%20%5Cright)%20%5Ccdot%20%7B%5Cwidehat%7BSE%7D%7D_%7B%5Cwidehat%7B%5Ctau%7D%7D%5E%7Bpilot%7D%20%5Cright%5Crbrack">, where <img src="https://latex.codecogs.com/png.latex?n%5E%7Bpilot%7D"> is the number of respondents per condition in the pilot data, <img src="https://latex.codecogs.com/png.latex?SE_%7B%5Cwidehat%7B%5Ctau%7D%7D%5E%7Bpilot%7D"> is the estimated standard error using the pilot data, and <img src="https://latex.codecogs.com/png.latex?n%5E%7Bplanned%7D"> is the number of respondents per condition in the planned study.</p>
</div>
</div>
<p>The factor <img src="https://latex.codecogs.com/png.latex?%5Cleft(%20%5Csqrt%7B%5Cfrac%7B1%7D%7Bn%5E%7Bpilot%7D%7D%7D%20+%201%20%5Cright)"> nudges the standard error from the pilot study in a conservative direction, since it might be an under-estimate of the actual standard error.<sup>2</sup> For the details, see <a href="https://osf.io/preprints/osf/5am9q_v2">this paper</a>, but this conservative standard error estimate is approximately the upper bound of a 95% confidence interval for the <em>standard error</em> using the pilot data.</p>
<div class="no-row-height column-margin column-container"><div id="fn2"><p><sup>2</sup>&nbsp;More generally, we can use a bootstrap to conservatively estimate the standard error, without relying on this analytical approximation.</p></div></div></section>
<section id="example" class="level2">
<h2 class="anchored" data-anchor-id="example">Example</h2>
<section id="the-robbins-et-al.-study" class="level3">
<h3 class="anchored" data-anchor-id="the-robbins-et-al.-study">The Robbins et al.&nbsp;study</h3>
<p>As an example, let’s use half of the experiment conducted by <span class="citation" data-cites="robbins2024">Robbins et al. (2024)</span>.</p>
<p>Robbins et al.&nbsp;use a 2x2 factorial vignette design, randomly assigning each respondent to read one of four vignettes. The vignette describes a hypothetical covert operation ordered by the president that ends in either success or failure. Then, the vignette describes a whistleblower coming forward and describes the president’s opposition in Congress as either amplifying or ignoring the whistleblower.</p>



    <style>
        table {
            width: 100%;
            border-collapse: collapse;
        }
        table, th, td {
            border: 1px solid black;
        }
        th, td {
            padding: 15px;
            text-align: center;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>




<table class="caption-top table" data-quarto-postprocess="true">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th">President's Opposition in Congress</th>
<th colspan="2" data-quarto-table-cell-role="th">Outcome of Operation</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td data-quarto-table-cell-role="th"></td>
<td data-quarto-table-cell-role="th">Success</td>
<td data-quarto-table-cell-role="th">Failure</td>
</tr>
<tr class="even">
<td>Amplifies Whistleblower</td>
<td>Vignette 1: Success &amp; Amplify</td>
<td>Vignette 2: Failure &amp; Amplify</td>
</tr>
<tr class="odd">
<td>Ignores Whistleblower</td>
<td>Vignette 3: Success &amp; Ignore</td>
<td>Vignette 4: Failure &amp; Ignore</td>
</tr>
</tbody>
</table>




<p>After the vignette, the respondent is asked whether they approve of the opposition in Congress’ actions on a seven-point Likert scale from strongly approve to strongly disapprove.</p>
<p>For a simple example, let’s <strong>focus on the effect of amplifying the whistleblower when the operation succeeds</strong>. That is, let’s compare responses after Vignette 1 and Vignette 3. How much does amplifying a whistleblower increase approval <em>when the opperation succeeds</em>? We expect a small effect here, so we should pay careful attention to power.</p>
</section>
</section>
<section id="the-task" class="level2">
<h2 class="anchored" data-anchor-id="the-task">The task</h2>
<p><strong>We hoped to detect an effect as small as 0.35 points on the seven-point scale and had tentatively planned on 250 respondents per condition.</strong> To test the survey instrument and data provider, we conducted a small pilot with about 75 respondents per condition. Let’s use those pilot data to check whether 250 respondents seem sufficient.</p>
</section>
<section id="the-data" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="the-data">The data</h2>
<p>In the <a href="https://www.carlislerainey.com/crdata/">{crdata} package</a> on GitHub, you can find the the pilot data we collected leading up to the main study.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># download the {crdata} package from github</span></span>
<span id="cb1-2">remotes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install_github</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"carlislerainey/crdata"</span>)</span></code></pre></div>
</div>
<p>Now let’s load the pilot data. To focus on observations where the operation succeeds, we’re going to keep only the observations where the vignette describes a successful observation.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># load pilot data and keep only success condition</span></span>
<span id="cb2-2">robbins2_pilot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> crdata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>robbins_pilot <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">subset</span>(failure <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Success"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glimpse</span>()</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 147
Columns: 5
$ cong_overall &lt;dbl&gt; 3, 1, -2, 0, -2, -1, 0, -1, 0, 0, 0, 2, -1, 3, -3, 0, 0, …
$ failure      &lt;fct&gt; Success, Success, Success, Success, Success, Success, Suc…
$ amplify      &lt;fct&gt; Ignore, Ignore, Ignore, Amplify, Ignore, Ignore, Ignore, …
$ pid7         &lt;fct&gt; Strong Democrat, Not very strong Republican, Strong Democ…
$ pid_strength &lt;dbl&gt; 3, 2, 3, 2, 2, 3, 2, 2, 2, 2, 2, 1, 0, 3, 3, 3, 3, 1, 1, …</code></pre>
</div>
</div>
<p><code>cong_overall</code> is the respondent’s approval of Congress’ actions on a seven-point scale and <code>amplify</code> indicates whether Congress amplified the whistleblower (i.e., criticized the president).</p>
<section id="analyzing-the-pilot-data" class="level3">
<h3 class="anchored" data-anchor-id="analyzing-the-pilot-data">Analyzing the pilot data</h3>
<p>Now let’s analyze the pilot data as we plan to analyze the main data set that we plan to collect later. We’re interested in the average response in the <code>Amplify</code> and <code>Ignore</code> conditions, so let’s use a t-test.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># t test</span></span>
<span id="cb4-2">fit_pilot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t.test</span>(cong_overall <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> amplify, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> robbins2_pilot)</span></code></pre></div>
</div>
<div class="callout callout-style-default callout-caution callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Ignore the Estimated Treatment Effect
</div>
</div>
<div class="callout-body-container callout-body">
<p>It can be really tempting to look at the estimated treatment effect. In this pilot study, it’s <em>actually statistically significant.</em> I intentionally don’t show the estimated treatment effect (or quantities requiring it, like <em>p</em>-values). If we looked at these, we might make one of the following mistakes:</p>
<ol type="1">
<li>“The pilot got significant results, therefore even the pilot is sufficiently powered.”</li>
<li>“The estimate from the pilot is significant, therefore we can use the estimated treatment effect in the power analysis.”</li>
</ol>
<p>Both of these claims are misleading. The estimated treatment effect is very noisy, so ignore the estimated treatment effect.</p>
</div>
</div>
</section>
<section id="predicting-the-se-in-the-main-study" class="level3">
<h3 class="anchored" data-anchor-id="predicting-the-se-in-the-main-study">Predicting the SE in the main study</h3>
<p>To predict the standard error in the main study, we need two pieces of information from this pilot:</p>
<ol type="1">
<li>the sample size per condition and</li>
<li>the estimated standard error.</li>
</ol>
<p>We can get the number of observations per condition using <code>table()</code>.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># create a table showing the observations per condition</span></span>
<span id="cb5-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(robbins2_pilot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>amplify)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>
 Ignore Amplify 
     70      77 </code></pre>
</div>
<div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># sample size per condition</span></span>
<span id="cb7-2">n_pilot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(robbins2_pilot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>amplify))</span>
<span id="cb7-3">n_pilot</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 73.5</code></pre>
</div>
</div>
<p>And then we need the estimated standard error, which is computed by <code>t.test()</code>.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># get estimated standard error from pilot</span></span>
<span id="cb9-2">se_hat_pilot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> fit_pilot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>stderr</span>
<span id="cb9-3">se_hat_pilot</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.2761011</code></pre>
</div>
</div>
<p>Now we can predict the standard error in the planned study.</p>
<p>For the main study, we planned on about 250 respondents per condition.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">n_planned <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">250</span></span></code></pre></div>
</div>
<p>The we can conservatively predict the standard error in the full study as <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B%5Cfrac%7Bn%5E%7Bpilot%7D%7D%7Bn%5E%7Bplanned%7D%7D%7D%20%5Ccdot%20%5Cleft%5Clbrack%20%5Cleft(%20%5Csqrt%7B%5Cfrac%7B1%7D%7Bn%5E%7Bpilot%7D%7D%7D%20+%201%20%5Cright)%20%5Ccdot%20%7B%5Cwidehat%7BSE%7D%7D_%7B%5Cwidehat%7B%5Ctau%7D%7D%5E%7Bpilot%7D%20%5Cright%5Crbrack">.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">pred_se_cons <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(n_pilot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_planned)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_pilot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se_hat_pilot)</span>
<span id="cb12-2">pred_se_cons</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.1671691</code></pre>
</div>
</div>
<p>But is this standard error small enough?</p>
</section>
<section id="evaluating-the-predicted-se-in-the-main-study" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="evaluating-the-predicted-se-in-the-main-study">Evaluating the predicted SE in the main study</h3>
<p>We can convert the standard error to the minimum detectable effect with 80% power using <img src="https://latex.codecogs.com/png.latex?2.5%20%5Ctimes%20SE">.<sup>3</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn3"><p><sup>3</sup>&nbsp;See <span class="citation" data-cites="bloom1995">Bloom (1995)</span> for an excellent discussion of this rule. I also write about it <a href="https://www.carlislerainey.com/blog/2023-06-12-power-3-rule-of-364/">here</a>.</p></div></div><div class="cell">
<div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute conservative minimum detectable effect</span></span>
<span id="cb14-2"><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pred_se_cons</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.4179227</code></pre>
</div>
</div>
<p>We hoped to detect an effect as small as 0.35 points on the seven-point scale, so we’re going to need more than 250 respondents per condition!</p>
<p>We can also compute the power to detect an effect of 0.35 points on the seven-point scale.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute power as a percent</span></span>
<span id="cb16-2"><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.35</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>pred_se_cons)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.6749736</code></pre>
</div>
</div>
<p>Note that these are <em>conservative</em> estimates of the minimum detectable effect and statistical power.</p>
<p>Here’s what things look like if we remove the conservative nudge <img src="https://latex.codecogs.com/png.latex?%5Cleft(%20%5Csqrt%7B%5Cfrac%7B1%7D%7Bn%5E%7Bpilot%7D%7D%7D%20+%201%20%5Cright)"> and predict the standard error as <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B%5Cfrac%7Bn%5E%7Bpilot%7D%7D%7Bn%5E%7Bplanned%7D%7D%7D%20%5Ccdot%20%7B%5Cwidehat%7BSE%7D%7D_%7B%5Cwidehat%7B%5Ctau%7D%7D%5E%7Bpilot%7D">.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># without the conservative nudge</span></span>
<span id="cb18-2">pred_se <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(n_pilot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_planned)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se_hat_pilot</span>
<span id="cb18-3"><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pred_se  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># best guess of minimum detectable effect</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.3742673</code></pre>
</div>
<div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1"><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.35</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>pred_se)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># best guess of power</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.7573806</code></pre>
</div>
</div>
<p>As you can see, the minimum detectable effect and power are a little too low. We need more respondents!</p>
</section>
<section id="adjusting-the-sample-size" class="level3">
<h3 class="anchored" data-anchor-id="adjusting-the-sample-size">Adjusting the Sample Size</h3>
<p>Our plan of 250 respondents per condition seems too low. If we want, we can predict the sample size we need to get to 80% power using the following rule:</p>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Predicting the required sample size in the planned study using pilot data
</div>
</div>
<div class="callout-body-container callout-body">
<p>For 80% power to detect the treatment effect <img src="https://latex.codecogs.com/png.latex?%5Cwidetilde%7B%5Ctau%7D">, we will (conservatively) need about <img src="https://latex.codecogs.com/png.latex?n%5E%7Bpilot%7D%20%5Ccdot%20%5Cleft%5Clbrack%20%5Cfrac%7B2.5%7D%7B%5Cwidetilde%7B%5Ctau%7D%7D%20%5Ccdot%20%5Cleft(%20%5Csqrt%7B%5Cfrac%7B1%7D%7Bn%5E%7Bpilot%7D%7D%7D%20+%201%20%5Cright)%20%5Ccdot%20%7B%5Cwidehat%7BSE%7D%7D_%7B%5Cwidehat%7B%5Ctau%7D%7D%5E%7Bpilot%7D%20%5Cright%5Crbrack%5E%7B2%7D"> respondents per condition, where <img src="https://latex.codecogs.com/png.latex?n%5E%7Bpilot%7D"> is the number of respondents per condition in the pilot data and <img src="https://latex.codecogs.com/png.latex?SE_%7B%5Cwidehat%7B%5Ctau%7D%7D%5E%7Bpilot%7D"> is the estimated standard error using the pilot data.</p>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1">n_pilot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>((<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.35</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_pilot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se_hat_pilot))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 356.4477</code></pre>
</div>
</div>
<p>Thus to get 80% power, the pilot data suggest that we (conservatively) need about 360 respondents per condition. We used 367 in the full study. Here are the conservative predictions for 367 respondents per condition.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1">n_planned <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">367</span></span>
<span id="cb24-2">pred_se_cons <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(n_pilot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_planned)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_pilot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se_hat_pilot)</span>
<span id="cb24-3">pred_se_cons</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.1379726</code></pre>
</div>
<div class="sourceCode cell-code" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pred_se_cons  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># conservative minimum detectable effect</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.3449315</code></pre>
</div>
<div class="sourceCode cell-code" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1"><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.35</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>pred_se_cons)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># conservative power</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.8150699</code></pre>
</div>
</div>
</section>
</section>
<section id="how-did-we-do" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="how-did-we-do">How did we do?</h2>
<p>We ran the full study.<sup>4</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn4"><p><sup>4</sup>&nbsp;See <span class="citation" data-cites="robbins2024">Robbins et al. (2024)</span> for the full results.</p></div></div><div class="cell">
<div class="sourceCode cell-code" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1">robbins2_main <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> crdata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>robbins_main <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb30-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">subset</span>(failure <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Success"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb30-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glimpse</span>()</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 735
Columns: 5
$ cong_overall &lt;dbl&gt; 2, -2, -1, -3, 0, -1, -2, -1, 1, 1, 0, -3, -2, 2, 2, -3, …
$ failure      &lt;fct&gt; Success, Success, Success, Success, Success, Success, Suc…
$ amplify      &lt;fct&gt; Ignore, Amplify, Amplify, Amplify, Ignore, Ignore, Amplif…
$ pid7         &lt;fct&gt; Not very strong Republican, Not very strong Republican, S…
$ pid_strength &lt;dbl&gt; 2, 2, 3, 3, 3, 2, 0, 2, 2, 1, 2, 0, 3, 1, 2, 3, 2, 3, 2, …</code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1">fit_main <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t.test</span>(cong_overall <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> amplify, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> robbins2_main)</span>
<span id="cb32-2">fit_main<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>stderr</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.1322618</code></pre>
</div>
<div class="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1"><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.35</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>fit_main<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>stderr)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.8428563</code></pre>
</div>
</div>
<p>As you can see, the pilot data gave us a good, slightly conservative prediction. We conservatively predicted a standard error of 0.138 in the planned study and we estimated a standard error of 0.132 after running the study. We conservatively predicted our power would be about 82% to detected an effect of 0.35 on the seven-point scale, but after running the study, it seems like we had about 84% power.</p>
</section>
<section id="a-bootstrap-alternative" class="level2">
<h2 class="anchored" data-anchor-id="a-bootstrap-alternative">A bootstrap alternative</h2>
<p>We can also use the bootstrap as an alternative. There are a few ways one might approach it.</p>
<p>Here’s one:</p>
<ol type="1">
<li>Treat the pilot data as a population. Create a data set with the planned sample size by sampling with replacement from the pilot data.</li>
<li>Perform the planned analysis on each resampled data set.</li>
<li>Store the estimated standard error from each analysis.</li>
</ol>
<p>Repeat the process above many times. For each standard error estimate, compute the implied statistical power. This gives a distribution of power estimates. Find a value near the bottom of this distribution. The factor we used above—The factor <img src="https://latex.codecogs.com/png.latex?%5Cleft(%20%5Csqrt%7B%5Cfrac%7B1%7D%7Bn%5E%7Bpilot%7D%7D%7D%20+%201%20%5Cright)">—nudges the standard error to about the 2.5th percentile, so we can use that here, too.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># number of bootstrap iterations</span></span>
<span id="cb36-2">n_bs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span></span>
<span id="cb36-3"></span>
<span id="cb36-4">bs_se <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(n_bs)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># a container</span></span>
<span id="cb36-5"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>n_bs){</span>
<span id="cb36-6">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># resample 367 observations from each condition</span></span>
<span id="cb36-7">  bs_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> robbins2_main <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb36-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(amplify) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb36-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample_n</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">367</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb36-10">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># run planned analysis</span></span>
<span id="cb36-11">  bs_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t.test</span>(cong_overall <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> amplify, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> bs_data)</span>
<span id="cb36-12">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># grab se</span></span>
<span id="cb36-13">  bs_se[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bs_fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>stderr</span>
<span id="cb36-14">}</span>
<span id="cb36-15"></span>
<span id="cb36-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute 2.5th percentile of power to obtain conservative estimate</span></span>
<span id="cb36-17">pwr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.35</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>bs_se)</span>
<span id="cb36-18"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(pwr, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>     2.5% 
0.8199688 </code></pre>
</div>
</div>
<p>Using the analytical approximation, we got 0.815 as a conservative estimate of power. The bootstrap gave us 0.820 as a conservative estimate. The actual power in the full study turned out to be about 0.843. (Remember, all of these power calculations are <em>power to detected an effect of 0.35 points on the seven-point scale.</em>)</p>
</section>
<section id="the-paper" class="level2">
<h2 class="anchored" data-anchor-id="the-paper">The paper</h2>
<p>I have a <a href="https://osf.io/preprints/osf/5am9q_v2">draft of a paper</a> on these (and other) ideas. Please test them out in your own work and let me know if you have questions, comments, and suggestions. I’m interested in making the paper as clear and useful as I can.</p>



</section>


<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-bloom1995" class="csl-entry">
Bloom, Howard S. 1995. <span>“Minimum Detectable Effects.”</span> <em>Evaluation Review</em> 19 (5): 547–56. <a href="https://doi.org/10.1177/0193841x9501900504">https://doi.org/10.1177/0193841x9501900504</a>.
</div>
<div id="ref-leon2011" class="csl-entry">
Leon, Andrew C., Lori L. Davis, and Helena C. Kraemer. 2011. <span>“The Role and Interpretation of Pilot Studies in Clinical Research.”</span> <em>Journal of Psychiatric Research</em> 45 (5): 626–29. <a href="https://doi.org/10.1016/j.jpsychires.2010.10.008">https://doi.org/10.1016/j.jpsychires.2010.10.008</a>.
</div>
<div id="ref-robbins2024" class="csl-entry">
Robbins, Caroline, Alessandro Brunelli, Jose Casto, Ainsley Coty, Andrew Louis, Bryanna Major, Maria A Martinez, et al. 2024. <span>“Overt Consequences of Covert Actions: Success, Failure, and Voters’ Preferences for Legislative Oversight.”</span> SocArXiv. <a href="https://doi.org/10.31235/osf.io/9p5h8">https://doi.org/10.31235/osf.io/9p5h8</a>.
</div>
</div></section></div> ]]></description>
  <category>statistical power</category>
  <category>hypothesis tests</category>
  <category>power analysis</category>
  <category>methodology</category>
  <guid>https://www.carlislerainey.com/blog/2024-06-10-pilot-power-example/</guid>
  <pubDate>Mon, 10 Jun 2024 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Statistical Power from Pilot Data: Simulations to Illustrate</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2024-06-03-pilot-power/</link>
  <description><![CDATA[ 




<hr>
<p>We can think of statistical power as determined by the ratio <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctau%7D%7BSE%7D">, where <img src="https://latex.codecogs.com/png.latex?%5Ctau"> is the treatment effect and SE is the standard error of the estimate.<sup>1</sup> To reason about statistical power, one needs to make assumptions or predictions about the treatment effect and the standard error.</p>
<div class="no-row-height column-margin column-container"><div id="fn1"><p><sup>1</sup>&nbsp;<span class="citation" data-cites="bloom1995">Bloom (1995)</span> has a really beautiful paper on this idea. It’s one of my favorites.</p></div></div><p>In this post, I discuss ways that pilot data should and should <em>not</em> be used as part of a power analysis. I make two points:</p>
<ol type="1">
<li>Pilot data are usually <em>not</em> useful to predict the treatment effect.</li>
<li>Pilot data can be useful to predict the standard error.</li>
</ol>
<p>With a predicted standard error in hand, we can predict for the minimum detectable effect, the statistical power, or the required sample size in the planned study.</p>
<section id="pilot-data-should-not-usually-be-used-to-estimate-the-treatment-effect" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="pilot-data-should-not-usually-be-used-to-estimate-the-treatment-effect">Pilot data should not usually be used to estimate the treatment effect</h2>
<p>To compute statistical power, researchers need to make an assumption about the size of the treatment effect. It’s easy to feel lost without any guidance on what effects are reasonable to look for, so we might feel tempted to use a small pilot study to estimate the treatment effect and then use that estimate in our power analysis. This is a bad idea because the estimate of the treatment effect from a pilot study is too uncertain for a power analysis.<sup>2</sup> <span class="citation" data-cites="leon2011">Leon, Davis, and Kraemer (2011)</span> and <span class="citation" data-cites="albers2018">Albers and Lakens (2018)</span> discuss this problem in more detail.<sup>3</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn2"><p><sup>2</sup>&nbsp;The estimate of the treatment effect from a well-powered study might be too noisy as well.</p></div><div id="fn3"><p><sup>3</sup>&nbsp;<span class="citation" data-cites="perugini2014">Perugini, Gallucci, and Costantini (2014)</span> offer a potential solution if it’s important to estimate the treatment effect from pilot data, though their approach is data-hungry and very conservative. Pilot data <em>can</em> estimate/predict the <em>standard deviation</em> in the full study quite precisely even with small pilots, such as 10 respondents per condition.</p></div></div><div class="callout callout-style-default callout-warning callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Warning
</div>
</div>
<div class="callout-body-container callout-body">
<p>Do not use a small pilot study to estimate the treatment effect and then use that estimate as the treatment effect in a power analysis.</p>
</div>
</div>
</section>
<section id="pilot-data-can-be-used-to-predict-the-standard-error" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="pilot-data-can-be-used-to-predict-the-standard-error">Pilot data <em>can</em> be used to predict the standard error</h2>
<p>While pilot data might not be useful for estimating the treatment effect, <strong>pilot data are useful for estimating the standard error of the planned study.</strong> Given that power is a function of the ratio of the treatment effect and the standard error, it’s important to have a good prediction of the standard error. Further, the noisiness of this estimated standard error is predictable, so it’s easy to nudge the estimate slightly to obtain a <em>conservative</em> prediction.</p>
<p>In political science, it’s common to run pilot studies with, say, 100-200 respondents before a full-sized study of, say, 1,000 respondents. It can be very helpful to use these pilot data to confirm any preliminary power calculations.</p>
<p>Here are two helpful rules:</p>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Predicting the SE in the planned study using pilot data
</div>
</div>
<div class="callout-body-container callout-body">
<p>We can use pilot data to predict the standard error of the estimated treatment effect in a planned study. Conservatively, the standard error will be about <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B%5Cfrac%7Bn%5E%7Bpilot%7D%7D%7Bn%5E%7Bplanned%7D%7D%7D%5C%20%5Cleft%5Clbrack%20%5Cleft(%20%5Csqrt%7B%5Cfrac%7B1%7D%7Bn%5E%7Bpilot%7D%7D%7D%20+%201%20%5Cright)%20%5Ccdot%20%7B%5Cwidehat%7BSE%7D%7D_%7B%5Cwidehat%7B%5Ctau%7D%7D%5E%7Bpilot%7D%20%5Cright%5Crbrack">, where <img src="https://latex.codecogs.com/png.latex?n%5E%7Bpilot%7D"> is the number of respondents per condition in the pilot data, <img src="https://latex.codecogs.com/png.latex?SE_%7B%5Cwidehat%7B%5Ctau%7D%7D%5E%7Bpilot%7D"> is the estimated standard error using the pilot data, and <img src="https://latex.codecogs.com/png.latex?n%5E%7Bplanned%7D"> is the number of respondents per condition in the planned study.</p>
</div>
</div>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Predicting the required sample size in the planned study using pilot data
</div>
</div>
<div class="callout-body-container callout-body">
<p>We can use pilot data to conservatively predict the sample size we will need in a planned study. For 80% power to detect the treatment effect <img src="https://latex.codecogs.com/png.latex?%5Cwidetilde%7B%5Ctau%7D">, we will (conservatively) need about <img src="https://latex.codecogs.com/png.latex?n%5E%7Bpilot%7D%20%5Ccdot%20%5Cleft%5Clbrack%20%5Cfrac%7B2.5%7D%7B%5Cwidetilde%7B%5Ctau%7D%7D%20%5Ccdot%20%5Cleft(%20%5Csqrt%7B%5Cfrac%7B1%7D%7Bn%5E%7Bpilot%7D%7D%7D%20+%201%20%5Cright)%20%5Ccdot%20%7B%5Cwidehat%7BSE%7D%7D_%7B%5Cwidehat%7B%5Ctau%7D%7D%5E%7Bpilot%7D%20%5Cright%5Crbrack%5E%7B2%7D"> respondents per condition, where <img src="https://latex.codecogs.com/png.latex?n%5E%7Bpilot%7D"> is the number of respondents per condition in the pilot data and <img src="https://latex.codecogs.com/png.latex?SE_%7B%5Cwidehat%7B%5Ctau%7D%7D%5E%7Bpilot%7D"> is the estimated standard error using the pilot data.</p>
</div>
</div>
<p>Note that the factor <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B%5Cfrac%7B1%7D%7Bn%5E%7Bpilot%7D%7D%7D%20+%201"> nudges the predicted standard error in a conservative direction. See <a href="https://github.com/carlislerainey/power-rules/blob/main/power-rules.pdf">this working paper</a> for more details.</p>
<p>We can use the predicted standard error to find the minimum detectable effect (for 80% power) or the power (for a given treatment effect). Or we can use the pilot data to estimate the required sample size (for 80% power to detect a given treatment effect.)</p>
<section id="the-setting" class="level3">
<h3 class="anchored" data-anchor-id="the-setting">The setting</h3>
<p>Let’s imagine a setting where a study with 1,000 respondents has 80% power to detect an average treatment effect of 1 unit. I’m imagining that we’re using linear regression with robust standard errors to test the hypothesis that the average treatment effect is positive (aka Welch’s <em>t</em>-test). There’s just one treatment group and one control group with 500 respondents each, for 1,000 respondents total.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># set the treatment effect, SE, and sample size</span></span>
<span id="cb1-2">tau <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># treatment effect</span></span>
<span id="cb1-3">se  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tau<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.80</span>))  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># standard error for 80% power</span></span>
<span id="cb1-4">n_planned <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># sample size per condition in planned full study</span></span>
<span id="cb1-5"></span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># calculate required standard deviation to yield 80% power given the above</span></span>
<span id="cb1-7">sigma <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> se<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_planned)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span></code></pre></div>
</div>
<p>Let’s confirm that this setting does indeed give us 80% power.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_5e6a46db33d28821ec0a879324c5cb15">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">res_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># a container to collect results</span></span>
<span id="cb2-2"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>) {</span>
<span id="cb2-3">      </span>
<span id="cb2-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># simulate study</span></span>
<span id="cb2-5">  y0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_planned, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> sigma)</span>
<span id="cb2-6">  y1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> y0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> tau</span>
<span id="cb2-7">  d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length.out =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_planned))</span>
<span id="cb2-8">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, y1, y0)</span>
<span id="cb2-9">  data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(y, d)</span>
<span id="cb2-10">  </span>
<span id="cb2-11">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fit model and get standard error and p-value</span></span>
<span id="cb2-12">  fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> d, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> data)</span>
<span id="cb2-13">  tau_hat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(fit)[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d"</span>])</span>
<span id="cb2-14">  se_hat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diag</span>(sandwich<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vcovHC</span>(fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"HC2"</span>)))[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d"</span>])</span>
<span id="cb2-15">  p_value <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(tau_hat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>se_hat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower.tail =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb2-16"></span>
<span id="cb2-17">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># collect results</span></span>
<span id="cb2-18">  res_list[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(tau_hat, se_hat, p_value)</span>
<span id="cb2-19">  }</span>
<span id="cb2-20"></span>
<span id="cb2-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute power (and monte carlo error)</span></span>
<span id="cb2-22">res_list <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">power =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(p_value <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>), </span>
<span id="cb2-25">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mc_error =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(power<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> power))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()), </span>
<span id="cb2-26">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwr =</span> power <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>mc_error, </span>
<span id="cb2-27">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upr =</span> power <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>mc_error)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>   power    mc_error       lwr       upr
1 0.8023 0.003982646 0.7943347 0.8102653</code></pre>
</div>
</div>
<p>Nailed it!</p>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
DeclareDesign Alternative
</div>
</div>
<div class="callout-body-container callout-body">
<p>Alex Coppock kindly <a href="https://bsky.app/profile/aecoppock.bsky.social/post/3ktzkavgkel2o">shared</a> how one might run the same simulation using <a href="https://declaredesign.org">{DeclareDesign}</a>. Code <a href="https://gist.github.com/carlislerainey/9c5f03c6fab4131a793b3b324838fc74">here</a>.</p>
</div>
</div>
</section>
<section id="the-pilot-studies" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="the-pilot-studies">The Pilot Studies</h3>
<p>Now let’s simulate 1,000 pilot studies with 10, 30, 60, 90, and 150 respondents per condition. I’m going to grab the standard error from each but throw the estimates of the treatment effects right into the trash.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_93a417c0b8fc14008d58581b3b1ef6bb">
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># sample size per condition in pilot study</span></span>
<span id="cb4-2">n_pilot_values   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">150</span>) </span>
<span id="cb4-3"></span>
<span id="cb4-4">res_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># a container to collect results</span></span>
<span id="cb4-5">iter <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># counter to index the collection</span></span>
<span id="cb4-6"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>) {</span>
<span id="cb4-7">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (j <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(n_pilot_values)) {</span>
<span id="cb4-8">    </span>
<span id="cb4-9">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># set respondents per condition in the pilot study</span></span>
<span id="cb4-10">    n_pilot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> n_pilot_values[j]</span>
<span id="cb4-11">    </span>
<span id="cb4-12">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># simulate pilot study</span></span>
<span id="cb4-13">    y0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_pilot, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> sigma)</span>
<span id="cb4-14">    y1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> y0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> tau</span>
<span id="cb4-15">    d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length.out =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_pilot))</span>
<span id="cb4-16">    y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, y1, y0)</span>
<span id="cb4-17">    pilot_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(y, d)</span>
<span id="cb4-18">    </span>
<span id="cb4-19">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fit model and get standard error</span></span>
<span id="cb4-20">    fit_pilot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> d, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> pilot_data)</span>
<span id="cb4-21">    tau_hat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(fit_pilot)[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d"</span>])</span>
<span id="cb4-22">    pilot_se_hat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diag</span>(sandwich<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vcovHC</span>(fit_pilot, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"HC2"</span>)))[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d"</span>])</span>
<span id="cb4-23">    </span>
<span id="cb4-24">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># collect standard errors </span></span>
<span id="cb4-25">    res_list[[iter]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(pilot_se_hat, n_pilot)</span>
<span id="cb4-26">    iter <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> iter <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># update counter</span></span>
<span id="cb4-27">  }</span>
<span id="cb4-28">}</span>
<span id="cb4-29"></span>
<span id="cb4-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># combine collected results in a data frame</span></span>
<span id="cb4-31">res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(res_list) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glimpse</span>()</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 50,000
Columns: 2
$ pilot_se_hat &lt;dbl&gt; 2.7282069, 1.7541542, 1.1426683, 0.9763233, 0.7760267, 3.…
$ n_pilot      &lt;dbl&gt; 10, 30, 60, 90, 150, 10, 30, 60, 90, 150, 10, 30, 60, 90,…</code></pre>
</div>
</div>
<p>Now let’s take a look a these standard errors from the simulated pilot studies. Notice that the standard errors are all larger than the standard error in the full study. And the smaller the pilot, the larger the standard error. This makes sense.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(res, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> pilot_se_hat)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(n_pilot)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> se)</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2024-06-03-pilot-power/index_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>However, we can translate the standard error from the pilot studies into predictions for the standard errors in the full studies by multiplying the pilot standard error times <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B%5Cfrac%7Bn%5E%7Bpilot%7D%7D%7Bn%5E%7Bplanned%7D%7D%7D">.<sup>4</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn4"><p><sup>4</sup>&nbsp;In this setting, we’re planning on 500 respondents per condition.</p></div></div><div class="cell">
<div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(res, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(n_pilot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_planned)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pilot_se_hat)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(n_pilot)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> se)</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2024-06-03-pilot-power/index_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>That’s spot on! However, notice that we sometimes <em>substantially</em> underestimate the standard error. When we underestimate the standard error, we will <em>over</em>estimate the power (which is bad for us).</p>
<p>As a solution, we can gently nudge the standard error from the pilot up by a factor of <img src="https://latex.codecogs.com/png.latex?%5Cleft(%20%5Csqrt%7B%5Cfrac%7B1%7D%7Bn%5E%7Bpilot%7D%7D%7D%20+%201%20%5Cright)">, which will make “almost all” of the standard errors <em>over</em>-estimates or “conservative” (details <a href="https://github.com/carlislerainey/power-rules/blob/main/power-rules.pdf">here</a>).</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(res, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(n_pilot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_planned)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_pilot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pilot_se_hat)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb8-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(n_pilot)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> se)</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2024-06-03-pilot-power/index_files/figure-html/unnamed-chunk-7-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>This works super well.</p>
<p>But how should we use this predicted standard error to evaluate or choose a sample size?</p>
</section>
</section>
<section id="how-to-use-the-predicted-standard-error" class="level2">
<h2 class="anchored" data-anchor-id="how-to-use-the-predicted-standard-error">How to use the predicted standard error</h2>
<p>We can use these conservative standard errors to compute any of the following (conservatively, as well):</p>
<ol type="1">
<li>the minimum detectable effect with 80% power</li>
<li>the statistical power for a given treatment effect</li>
<li>the sample size required to obtain 80% power for a given treatment effect</li>
</ol>
<section id="the-minimum-detectable-effect" class="level3">
<h3 class="anchored" data-anchor-id="the-minimum-detectable-effect">The Minimum Detectable Effect</h3>
<p>First, we can compute the minimum detectable effect with 80% power. This is about 2.5 times the standard error.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute minimum detectable effect</span></span>
<span id="cb9-2">mde <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> res <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pred_se_cons =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(n_pilot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_planned)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_pilot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pilot_se_hat, </span>
<span id="cb9-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mde_cons =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pred_se_cons) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glimpse</span>()</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 50,000
Columns: 4
$ pilot_se_hat &lt;dbl&gt; 2.7282069, 1.7541542, 1.1426683, 0.9763233, 0.7760267, 3.…
$ n_pilot      &lt;dbl&gt; 10, 30, 60, 90, 150, 10, 30, 60, 90, 150, 10, 30, 60, 90,…
$ pred_se_cons &lt;dbl&gt; 0.5078358, 0.5081264, 0.4469336, 0.4578814, 0.4597523, 0.…
$ mde_cons     &lt;dbl&gt; 1.269590, 1.270316, 1.117334, 1.144704, 1.149381, 1.40411…</code></pre>
</div>
<div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plot minimum detectable effect</span></span>
<span id="cb11-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(mde, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> mde_cons)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb11-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb11-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(n_pilot)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb11-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> tau)</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2024-06-03-pilot-power/index_files/figure-html/unnamed-chunk-8-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="statistical-power" class="level3">
<h3 class="anchored" data-anchor-id="statistical-power">Statistical Power</h3>
<p>Second, we can compute the statistical power for given treatment effect. Power equals <img src="https://latex.codecogs.com/png.latex?1%20-%20%5CPhi_%7Bstd%7D%5Cleft(1.64%20-%20%5Cfrac%7B%5Ctau%7D%7BSE%7D%20%5Cright)">, where <img src="https://latex.codecogs.com/png.latex?%5CPhi_%7Bstd%7D(z)"> is <code>pnorm()</code>, <img src="https://latex.codecogs.com/png.latex?SE"> is the standard error of the estimated treatment effect, and <img src="https://latex.codecogs.com/png.latex?%5Ctau"> is the treatment effect.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute the power</span></span>
<span id="cb12-2">pwr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> res <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pred_se_cons =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(n_pilot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_planned)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_pilot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pilot_se_hat, </span>
<span id="cb12-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">power_cons =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> tau<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>pred_se_cons)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glimpse</span>()</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 50,000
Columns: 4
$ pilot_se_hat &lt;dbl&gt; 2.7282069, 1.7541542, 1.1426683, 0.9763233, 0.7760267, 3.…
$ n_pilot      &lt;dbl&gt; 10, 30, 60, 90, 150, 10, 30, 60, 90, 150, 10, 30, 60, 90,…
$ pred_se_cons &lt;dbl&gt; 0.5078358, 0.5081264, 0.4469336, 0.4578814, 0.4597523, 0.…
$ power_cons   &lt;dbl&gt; 0.6289751, 0.6285495, 0.7249028, 0.7067695, 0.7037043, 0.…</code></pre>
</div>
<div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plot the power</span></span>
<span id="cb14-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(pwr, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> power_cons)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb14-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb14-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(n_pilot)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb14-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2024-06-03-pilot-power/index_files/figure-html/unnamed-chunk-9-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="required-sample-size" class="level3">
<h3 class="anchored" data-anchor-id="required-sample-size">Required Sample Size</h3>
<p>Finally, we can compute the required sample size to obtain 80% power to detect a certain treatment effect.</p>
<p>As I described above, for 80% power to detect the treatment effect <img src="https://latex.codecogs.com/png.latex?%5Cwidetilde%7B%5Ctau%7D">, we will (conservatively) need about <img src="https://latex.codecogs.com/png.latex?n%5E%7Bpilot%7D%20%5Ccdot%20%5Cleft%5Clbrack%20%5Cfrac%7B2.5%7D%7B%5Cwidetilde%7B%5Ctau%7D%7D%20%5Ccdot%20%5Cleft(%20%5Csqrt%7B%5Cfrac%7B1%7D%7Bn%5E%7Bpilot%7D%7D%7D%20+%201%20%5Cright)%20%5Ccdot%20%7B%5Cwidehat%7BSE%7D%7D_%7B%5Cwidehat%7B%5Ctau%7D%7D%5E%7Bpilot%7D%20%5Cright%5Crbrack%5E%7B2%7D"> respondents per condition.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute the required sample size</span></span>
<span id="cb15-2">ss <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> res <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb15-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ss_cons =</span> n_pilot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>((<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>tau)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_pilot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pilot_se_hat)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb15-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glimpse</span>()</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 50,000
Columns: 3
$ pilot_se_hat &lt;dbl&gt; 2.7282069, 1.7541542, 1.1426683, 0.9763233, 0.7760267, 3.…
$ n_pilot      &lt;dbl&gt; 10, 30, 60, 90, 150, 10, 30, 60, 90, 150, 10, 30, 60, 90,…
$ ss_cons      &lt;dbl&gt; 805.9289, 806.8515, 624.2176, 655.1731, 660.5380, 985.772…</code></pre>
</div>
<div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plot the required sample size</span></span>
<span id="cb17-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(ss, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> ss_cons)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb17-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb17-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(n_pilot)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb17-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> n_planned)</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2024-06-03-pilot-power/index_files/figure-html/unnamed-chunk-10-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Sample size is an especially helpful metric, because it is the constraint and cost that researchers face most directly. Because these required sample sizes are <em>conservative</em>, they tend to be too large—but by how much? For pilots with 60 respondents per condition, the sample sizes tend to be about 30% too large. This means that researchers could have obtained 80% power with 1,000 respondents but instead used 1,300 respondents.</p>
<p>In my view, this 30% waste is not particularly concerning. It’s relatively small and the statistical power will still be less than 90% even if the sample size is increased by 30%.</p>
<p>But most importantly, almost all of the sample sizes <em>exceed</em> what we need for 80% power.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute features of the sample sizes</span></span>
<span id="cb18-2">ss <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(n_pilot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">waste =</span> ss_cons<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_planned <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_waste =</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(waste), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), </span>
<span id="cb18-6">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct_too_small =</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(ss_cons <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Respondents per condition in pilot study</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> n_pilot,</span>
<span id="cb18-8">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Average waste (needed 1,000 respondents and used 1,300 means waste is 30%)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> avg_waste, </span>
<span id="cb18-9">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Percent of sample sizes that produce less than 80% power</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> pct_too_small) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-10">  tinytable<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tt</span>()</span></code></pre></div>
<div class="cell-output-display">
 

  
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tinytable_sghpfcv67rch2nmchm9v</title>
    <style>
.table td.tinytable_css_l9xr266borlk8s1ixmid, .table th.tinytable_css_l9xr266borlk8s1ixmid {    border-bottom: solid 0.1em #d3d8dc; }
    </style>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    <script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    <script>
    MathJax = {
      tex: {
        inlineMath: [['$', '$'], ['\\(', '\\)']]
      },
      svg: {
        fontCache: 'global'
      }
    };
    </script>
  

  
    <div class="container">
      <table class="table table-borderless" id="tinytable_sghpfcv67rch2nmchm9v" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
        <thead>
        
              <tr>
                <th scope="col">Respondents per condition in pilot study</th>
                <th scope="col">Average waste (needed 1,000 respondents and used 1,300 means waste is 30%)</th>
                <th scope="col">Percent of sample sizes that produce less than 80% power</th>
              </tr>
        </thead>
        
        <tbody>
                <tr>
                  <td> 10</td>
                  <td>75%</td>
                  <td>7%</td>
                </tr>
                <tr>
                  <td> 30</td>
                  <td>41%</td>
                  <td>4%</td>
                </tr>
                <tr>
                  <td> 60</td>
                  <td>29%</td>
                  <td>3%</td>
                </tr>
                <tr>
                  <td> 90</td>
                  <td>24%</td>
                  <td>3%</td>
                </tr>
                <tr>
                  <td>150</td>
                  <td>18%</td>
                  <td>3%</td>
                </tr>
        </tbody>
      </table>
    </div>

    <script>
      function styleCell_tinytable_izejox3p7b00jb4bvuz2(i, j, css_id) {
        var table = document.getElementById("tinytable_sghpfcv67rch2nmchm9v");
        table.rows[i].cells[j].classList.add(css_id);
      }
      function insertSpanRow(i, colspan, content) {
        var table = document.getElementById('tinytable_sghpfcv67rch2nmchm9v');
        var newRow = table.insertRow(i);
        var newCell = newRow.insertCell(0);
        newCell.setAttribute("colspan", colspan);
        // newCell.innerText = content;
        // this may be unsafe, but innerText does not interpret <br>
        newCell.innerHTML = content;
      }
      function spanCell_tinytable_izejox3p7b00jb4bvuz2(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_sghpfcv67rch2nmchm9v");
        const targetRow = table.rows[i];
        const targetCell = targetRow.cells[j];
        for (let r = 0; r < rowspan; r++) {
          // Only start deleting cells to the right for the first row (r == 0)
          if (r === 0) {
            // Delete cells to the right of the target cell in the first row
            for (let c = colspan - 1; c > 0; c--) {
              if (table.rows[i + r].cells[j + c]) {
                table.rows[i + r].deleteCell(j + c);
              }
            }
          }
          // For rows below the first, delete starting from the target column
          if (r > 0) {
            for (let c = colspan - 1; c >= 0; c--) {
              if (table.rows[i + r] && table.rows[i + r].cells[j]) {
                table.rows[i + r].deleteCell(j);
              }
            }
          }
        }
        // Set rowspan and colspan of the target cell
        targetCell.rowSpan = rowspan;
        targetCell.colSpan = colspan;
      }

window.addEventListener('load', function () { styleCell_tinytable_izejox3p7b00jb4bvuz2(0, 0, 'tinytable_css_l9xr266borlk8s1ixmid') })
window.addEventListener('load', function () { styleCell_tinytable_izejox3p7b00jb4bvuz2(0, 1, 'tinytable_css_l9xr266borlk8s1ixmid') })
window.addEventListener('load', function () { styleCell_tinytable_izejox3p7b00jb4bvuz2(0, 2, 'tinytable_css_l9xr266borlk8s1ixmid') })
    </script>

  


</div>
</div>
</section>
</section>
<section id="summary" class="level2">
<h2 class="anchored" data-anchor-id="summary">Summary</h2>
<p>We think of statistical power as determined by the ratio <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctau%7D%7BSE%7D">, where <img src="https://latex.codecogs.com/png.latex?%5Ctau"> is the treatment effect and SE is the standard error of the estimate. To reason about statistical power, one needs to make assumptions or predictions about the treatment effect and the standard error.</p>
<p>I make two points in this post:</p>
<ol type="1">
<li>Pilot data are not usually useful to estimate the treatment effect.</li>
<li>Pilot data can be useful to predict the standard error.</li>
</ol>
<p>With a predicted standard error in hand, we can obtain a prediction for the minimum detectable effect, the statistical power, or the required sample size.</p>
<p>You can find more details in <a href="https://github.com/carlislerainey/power-rules/blob/main/power-rules.pdf">this paper</a>.</p>
</section>
<section id="see-also" class="level2">
<h2 class="anchored" data-anchor-id="see-also">See also</h2>
<ul>
<li><a href="https://book.declaredesign.org/lifecycle/planning.html#sec-ch21s4">Section 21.4</a> of the DeclareDesign book on piloting.</li>
<li><a href="https://declaredesign.org/blog/posts/pilot-studies.html">“Should a pilot study change your study design decisions?”</a> on the DeclareDesign blog.</li>
</ul>



</section>


<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-albers2018" class="csl-entry">
Albers, Casper, and Daniël Lakens. 2018. <span>“When Power Analyses Based on Pilot Data Are Biased: Inaccurate Effect Size Estimators and Follow-up Bias.”</span> <em>Journal of Experimental Social Psychology</em> 74 (January): 187–95. <a href="https://doi.org/10.1016/j.jesp.2017.09.004">https://doi.org/10.1016/j.jesp.2017.09.004</a>.
</div>
<div id="ref-bloom1995" class="csl-entry">
Bloom, Howard S. 1995. <span>“Minimum Detectable Effects.”</span> <em>Evaluation Review</em> 19 (5): 547–56. <a href="https://doi.org/10.1177/0193841x9501900504">https://doi.org/10.1177/0193841x9501900504</a>.
</div>
<div id="ref-leon2011" class="csl-entry">
Leon, Andrew C., Lori L. Davis, and Helena C. Kraemer. 2011. <span>“The Role and Interpretation of Pilot Studies in Clinical Research.”</span> <em>Journal of Psychiatric Research</em> 45 (5): 626–29. <a href="https://doi.org/10.1016/j.jpsychires.2010.10.008">https://doi.org/10.1016/j.jpsychires.2010.10.008</a>.
</div>
<div id="ref-perugini2014" class="csl-entry">
Perugini, Marco, Marcello Gallucci, and Giulio Costantini. 2014. <span>“Safeguard Power as a Protection Against Imprecise Power Estimates.”</span> <em>Perspectives on Psychological Science</em> 9 (3): 319–32. <a href="https://doi.org/10.1177/1745691614528519">https://doi.org/10.1177/1745691614528519</a>.
</div>
</div></section></div> ]]></description>
  <category>statistical power</category>
  <category>hypothesis tests</category>
  <category>power analysis</category>
  <category>methodology</category>
  <guid>https://www.carlislerainey.com/blog/2024-06-03-pilot-power/</guid>
  <pubDate>Mon, 03 Jun 2024 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Firth’s Logit: Some References</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2023-08-30-firth-references/</link>
  <description><![CDATA[ 




<p>In <span class="citation" data-cites="rainey2021">Rainey and McCaskey (2021)</span>, Kelly McCaskey and I offer a accessible and practical (re)introduction to Firth’s penalized maximum likelihood estimator that (1) corrects the small sample bias and (2) reduces the excessive variance of the usual maximum likelihood estimator.</p>
<p>Below, I bookmark other references that might be helpful.</p>
<div class="callout callout-style-simple callout-note no-icon">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-body-container">
<p>I’m sure there are embarrassing omissions. If you see an omission, please let me know (self-promotion is encouraged, especially not-yet-published papers).</p>
</div>
</div>
</div>
<p><a href="https://stats.stackexchange.com/a/88743">This Stack Exchange answer</a> gives a brief, but careful explanation of Firth’s logit. If you’re looking for a quick explanation, start here.</p>
<section id="the-two-main-papers" class="level3">
<h3 class="anchored" data-anchor-id="the-two-main-papers">The Two Main Papers</h3>
<ol type="1">
<li><span class="citation" data-cites="firth1993">Firth (1993)</span> originally introduced the idea. Kelly and I draw mostly on this paper—it’s a wonderful paper.</li>
<li><span class="citation" data-cites="kosmidis2021">Kosmidis and Firth (2021)</span> follow-up with additional theoretical results that are relevant for the estimator as used in practice since 1993. This happened to come out while our paper was working its way through the publication process. Most importantly, they discuss the shrinkage property of the estimator, which is what Kelly and I highlight as under-appreciated (and really important!).</li>
</ol>
<p>From my perpective, these are the two main papers to refer to if you’re concerned about small sample bias in logistic regression models.</p>
</section>
<section id="extensions" class="level3">
<h3 class="anchored" data-anchor-id="extensions">Extensions</h3>
<p>Beyond these two main papers, there have been a few extensions. <span class="citation" data-cites="zietkiewicz2023">Zietkiewicz and Kosmidis (2023)</span> talk about Firth’s logit in <em>very</em> large data sets. <span class="citation" data-cites="cook2018">Cook, Hays, and Franzese (2018)</span> make a good argument for using Firth’s estimator in panel data sets with binary outcomes and fixed effects. <span class="citation" data-cites="sterzinger2023">Sterzinger and Kosmidis (2023)</span> apply these ideas to mixed models (or random effects models). <span class="citation" data-cites="sinkovec2021">Šinkovec et al. (2021)</span> compare Firth’s approach to ridge regression, and suggest that Firth’s is superior in small or sparse data sets. <span class="citation" data-cites="puhr2017">Puhr et al. (2017)</span> study Firth’s logit in the context of rare events and propose FLIC and FLAC as alternatives.</p>
</section>
<section id="applications" class="level3">
<h3 class="anchored" data-anchor-id="applications">Applications</h3>
<ul>
<li><span class="citation" data-cites="röver2022">Röver et al. (2022)</span> offer an application of Firth’s logit to clinical trials.</li>
<li><span class="citation" data-cites="turner2012">Turner and Firth (2012)</span> offer an application to Bradley-Terry models with the {BradleyTerry2} R package.</li>
</ul>
</section>
<section id="separation-and-finiteness" class="level3">
<h3 class="anchored" data-anchor-id="separation-and-finiteness">Separation and Finiteness</h3>
<p>I learned about Firth’s estimator from <span class="citation" data-cites="zorn2005">Zorn (2005)</span>, who follows <span class="citation" data-cites="heinze2002">Heinze and Schemper (2002)</span> in suggesting it as a solution to separation. According to David Firth in <a href="https://davidfirth.github.io/blog/2023/01/05/f93-citations-and-history/">this blog post</a>, this is the application that stimulated interest in the approach after it went relatively unnoticed for a few years. <em>(Great post, I highly recommend reading it!)</em> This application piqued my interest in Firth’s estimator. Briefly, I think Firth’s default penalty might not be substantively reasonable in a given application <span class="citation" data-cites="rainey2016">(Rainey 2016)</span> (see also <span class="citation" data-cites="beiser-mcgrath2020">Beiser-McGrath (2020)</span>) and the usual likelihood ratio and score tests work well without the penalty <span class="citation" data-cites="rainey2023">(Rainey 2023)</span>.</p>
<div class="callout callout-style-simple callout-note no-icon">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-body-container">
<p>For more on Firth’s logit, see <a href="https://www.ikosmidis.com/research/">Ioannis Kosmidis</a>’ research page and Georg Heinz <a href="https://scholar.google.com/citations?user=HhfU2UQAAAAJ">Google Scholar page</a>.</p>
</div>
</div>
</div>



</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-beiser-mcgrath2020" class="csl-entry">
Beiser-McGrath, Liam F. 2020. <span>“Separation and Rare Events.”</span> <em>Political Science Research and Methods</em> 10 (2): 428–37. <a href="https://doi.org/10.1017/psrm.2020.46">https://doi.org/10.1017/psrm.2020.46</a>.
</div>
<div id="ref-cook2018" class="csl-entry">
Cook, Scott J., Jude C. Hays, and Robert J. Franzese. 2018. <span>“Fixed Effects in Rare Events Data: A Penalized Maximum Likelihood Solution.”</span> <em>Political Science Research and Methods</em> 8 (1): 92–105. <a href="https://doi.org/10.1017/psrm.2018.40">https://doi.org/10.1017/psrm.2018.40</a>.
</div>
<div id="ref-firth1993" class="csl-entry">
Firth, David. 1993. <span>“Bias Reduction of Maximum Likelihood Estimates.”</span> <em>Biometrika</em> 80 (1): 27–38. <a href="https://doi.org/10.1093/biomet/80.1.27">https://doi.org/10.1093/biomet/80.1.27</a>.
</div>
<div id="ref-heinze2002" class="csl-entry">
Heinze, Georg, and Michael Schemper. 2002. <span>“A Solution to the Problem of Separation in Logistic Regression.”</span> <em>Statistics in Medicine</em> 21 (16): 2409–19. <a href="https://doi.org/10.1002/sim.1047">https://doi.org/10.1002/sim.1047</a>.
</div>
<div id="ref-kosmidis2021" class="csl-entry">
Kosmidis, Ioannis, and David Firth. 2021. <span>“Jeffreys-Prior Penalty, Finiteness and Shrinkage in Binomial-Response Generalized Linear Models.”</span> <em>Biometrika</em> 108 (1): 71–82. <a href="https://doi.org/10.1093/biomet/asaa052">https://doi.org/10.1093/biomet/asaa052</a>.
</div>
<div id="ref-puhr2017" class="csl-entry">
Puhr, Rainer, Georg Heinze, Mariana Nold, Lara Lusa, and Angelika Geroldinger. 2017. <span>“Firth’s Logistic Regression with Rare Events: Accurate Effect Estimates and Predictions?”</span> <em>Statistics in Medicine</em>. <a href="https://doi.org/10.1002/sim.7273">https://doi.org/10.1002/sim.7273</a>.
</div>
<div id="ref-rainey2016" class="csl-entry">
Rainey, Carlisle. 2016. <span>“Dealing with Separation in Logistic Regression Models.”</span> <em>Political Analysis</em> 24 (3): 339–55. <a href="https://doi.org/10.1093/pan/mpw014">https://doi.org/10.1093/pan/mpw014</a>.
</div>
<div id="ref-rainey2023" class="csl-entry">
———. 2023. <span>“Hypothesis Tests Under Separation.”</span> <a href="http://dx.doi.org/10.31235/osf.io/bmvnu">http://dx.doi.org/10.31235/osf.io/bmvnu</a>.
</div>
<div id="ref-rainey2021" class="csl-entry">
Rainey, Carlisle, and Kelly McCaskey. 2021. <span>“Estimating Logit Models with Small Samples.”</span> <em>Political Science Research and Methods</em> 9 (3): 549–64. <a href="https://doi.org/10.1017/psrm.2021.9">https://doi.org/10.1017/psrm.2021.9</a>.
</div>
<div id="ref-röver2022" class="csl-entry">
Röver, Christian, Moreno Ursino, Tim Friede, and Sarah Zohar. 2022. <span>“A Straightforward Meta<span>-</span>Analysis Approach for Oncology Phase I Dose<span>-</span>Finding Studies.”</span> <em>Statistics in Medicine</em> 41 (20): 3915–40. <a href="https://doi.org/10.1002/sim.9484">https://doi.org/10.1002/sim.9484</a>.
</div>
<div id="ref-sinkovec2021" class="csl-entry">
Šinkovec, Hana, Georg Heinze, Rok Blagus, and Angelika Geroldinger. 2021. <span>“To Tune or Not to Tune, a Case Study of Ridge Logistic Regression in Small or Sparse Datasets.”</span> <em>BMC Medical Research Methodology</em> 21 (1). <a href="https://doi.org/10.1186/s12874-021-01374-y">https://doi.org/10.1186/s12874-021-01374-y</a>.
</div>
<div id="ref-sterzinger2023" class="csl-entry">
Sterzinger, Philipp, and Ioannis Kosmidis. 2023. <span>“Maximum Softly-Penalized Likelihood for Mixed Effects Logistic Regression.”</span> <em>Statistics and Computing</em> 33 (2). <a href="https://doi.org/10.1007/s11222-023-10217-3">https://doi.org/10.1007/s11222-023-10217-3</a>.
</div>
<div id="ref-turner2012" class="csl-entry">
Turner, Heather, and David Firth. 2012. <span>“Bradley-Terry Models in<span><em>R</em></span>: The<span><strong>BradleyTerry2</strong></span>Package.”</span> <em>Journal of Statistical Software</em> 48 (9). <a href="https://doi.org/10.18637/jss.v048.i09">https://doi.org/10.18637/jss.v048.i09</a>.
</div>
<div id="ref-zietkiewicz2023" class="csl-entry">
Zietkiewicz, Patrick, and Ioannis Kosmidis. 2023. <span>“Bounded-Memory Adjusted Scores Estimation in Generalized Linear Models with Large Data Sets.”</span> <a href="https://doi.org/10.48550/ARXIV.2307.07342">https://doi.org/10.48550/ARXIV.2307.07342</a>.
</div>
<div id="ref-zorn2005" class="csl-entry">
Zorn, Christopher. 2005. <span>“A Solution to Separation in Binary Response Models.”</span> <em>Political Analysis</em> 13 (2): 157–70. <a href="https://doi.org/10.1093/pan/mpi009">https://doi.org/10.1093/pan/mpi009</a>.
</div>
</div></section></div> ]]></description>
  <category>methodology</category>
  <category>logistic regression</category>
  <category>small samples</category>
  <category>Firth</category>
  <guid>https://www.carlislerainey.com/blog/2023-08-30-firth-references/</guid>
  <pubDate>Wed, 30 Aug 2023 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Equivalence Tests Using {marginaleffects}</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2023-08-18-equivalence-tests/</link>
  <description><![CDATA[ 




<section id="background-on-arguing-for-a-negligible-effect" class="level2">
<h2 class="anchored" data-anchor-id="background-on-arguing-for-a-negligible-effect">Background on arguing for a negligible effect</h2>
<p>I remember sitting in a talk while I was a graduate student, and the speaker said something like: “I expect no effect here, and, just as I expected, the difference is not statistically significant.” Of course, that’s not a compelling argument for a null effect. A lack of statistical significance is an absence of evidence for an effect; it is not evidence of an absence of an effect.</p>
<p>But I saw this approach taken again and again in published work. (And still do!)</p>
<p>My first publication was an <em>AJPS</em> article <span class="citation" data-cites="rainey2014">(Rainey 2014)</span> (<a href="https://www.carlislerainey.com/papers/nme.pdf">Ungated PDF</a>) explaining why this doesn’t work well and how to do it better.</p>
<p>Here’s what I wrote in that paper:</p>
<blockquote class="blockquote">
<p>Hypothesis testing is a powerful empirical argument not because it shows that the data are consistent with the research hypothesis, but because it shows that the data are inconsistent with other hypotheses (i.e., the null hypothesis). However, researchers sometimes reverse this logic when arguing for a negligible effect, showing only that the data are consistent with “no effect” and failing to show that the data are inconsistent with meaningful effects. When researchers argue that a variable has “no effect” because its confidence interval contains zero, they take no steps to rule out large, meaningful effects, making the empirical claim considerably less persuasive . <span class="citation" data-cites="altman1995 gill1999 nickerson2000">(Altman and Bland 1995; Gill 1999; Nickerson 2000)</span></p>
</blockquote>
<p>But here’s a critical point, it’s impossible to reject every hypothesis except <em>exactly</em> no effect. Instead, the researcher must define a range of substantively “negligible” effects. The researcher <em>can</em> reject the null hypothesis that the effect falls outside this range of negligible effects. However, this requires a substantive judgement about those effects that are negligible and those that are not.</p>
<p>Here’s what I wrote:</p>
<blockquote class="blockquote">
<p>Researchers who wish to argue for a negligible effect must precisely define the set of effects that are deemed “negligible” as well as the set of effects that are “meaningful.” This requires defining the smallest substantively meaningful effect, which I denote as <img src="https://latex.codecogs.com/png.latex?m">. The definition must be debated by substantive scholars for any given context because the appropriate <img src="https://latex.codecogs.com/png.latex?m"> varies widely across applications.</p>
</blockquote>
</section>
<section id="clark-and-golder-2006" class="level2">
<h2 class="anchored" data-anchor-id="clark-and-golder-2006">Clark and Golder (2006)</h2>
<p><span class="citation" data-cites="clark2006">Clark and Golder (2006)</span> offer a nice example of this sort of hypothesis. I’ll refer you there and to <span class="citation" data-cites="rainey2014">Rainey (2014)</span> for a complete discussion of their idea, but I’ll motivate it briefly here.</p>
<p>Explaining why a country might have only a few (i.e., two) parties, Clark and Golder write:</p>
<blockquote class="blockquote">
<p>First, it could be the case that the demand for parties is low because there are few social cleavages. In this situation, there would be few parties whether the electoral institutions were permissive or not. Second, it could be the case that the electoral system is not permissive. In this situation, there would be a small number of parties even if the demand for political parties were high. Only a polity characterized by both a high degree of social heterogeneity and a highly permissive electoral system is expected to produce a large number of parties. (p.&nbsp;683)</p>
</blockquote>
<p>Thus, they expect that electoral institutions won’t matter in socially homogeneous systems. And they expect that social heterogeneity won’t matter in electoral systems that are not permissive.</p>
</section>
<section id="reproducing-clark-and-golder-2006" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="reproducing-clark-and-golder-2006">Reproducing Clark and Golder (2006)</h2>
<p>Before computing their specific quantities of interest, let’s reproduce their regression model. Here’s their table that we’re trying to reproduce.</p>
<p><img src="https://www.carlislerainey.com/blog/2023-08-18-equivalence-tests/clark-golder-2006-table2.png" class="img-fluid"></p>
<p>And here’s a reproduction of their estimates using the <code>cg2006</code> data from the <a href="http://www.carlislerainey.com/crdata/">{crdata} package</a> on GitHub.<sup>1</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn1"><p><sup>1</sup>&nbsp;Run <code>?crdata::cg2006</code> for detailed documentation of this data set.</p></div></div><div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># load packages</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(sandwich)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(modelsummary)</span>
<span id="cb1-5"></span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># install my data packages from github</span></span>
<span id="cb1-7">devtools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install_github</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"carlislerainey/crdata"</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># only updates if newer version available</span></span>
<span id="cb1-8"></span>
<span id="cb1-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># load clark and golder's data set</span></span>
<span id="cb1-10">cg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> crdata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>cg2006</span>
<span id="cb1-11"></span>
<span id="cb1-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># reproduce their estimates</span></span>
<span id="cb1-13">f <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> enep <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> eneg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(average_magnitude) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> eneg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>upper_tier <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> en_pres<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>proximity</span>
<span id="cb1-14">fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(f, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> cg)</span>
<span id="cb1-15"></span>
<span id="cb1-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># regression table</span></span>
<span id="cb1-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">modelsummary</span>(fit, </span>
<span id="cb1-18">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vcov =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> country, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cluster-robust SE; multiple observations per country</span></span>
<span id="cb1-19">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fmt =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, </span>
<span id="cb1-20">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape =</span> term <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> model <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> statistic)</span></code></pre></div>
<div class="cell-output-display">
<!-- preamble start -->

    <script>

      function styleCell_7wpemef4qvgzqe5kqtya(i, j, css_id) {
          var table = document.getElementById("tinytable_7wpemef4qvgzqe5kqtya");
          var cell = table.rows[i]?.cells[j];  // Safe navigation to avoid errors
          if (cell) {
              console.log(`Styling cell at (${i}, ${j}) with class ${css_id}`);
              cell.classList.add(css_id);
          } else {
              console.warn(`Cell at (${i}, ${j}) not found.`);
          }
      }
      function insertSpanRow(i, colspan, content) {
        var table = document.getElementById('tinytable_7wpemef4qvgzqe5kqtya');
        var newRow = table.insertRow(i);
        var newCell = newRow.insertCell(0);
        newCell.setAttribute("colspan", colspan);
        // newCell.innerText = content;
        // this may be unsafe, but innerText does not interpret <br>
        newCell.innerHTML = content;
      }
      function spanCell_7wpemef4qvgzqe5kqtya(i, j, rowspan, colspan) {
        var table = document.getElementById("tinytable_7wpemef4qvgzqe5kqtya");
        const targetRow = table.rows[i];
        const targetCell = targetRow.cells[j];
        for (let r = 0; r < rowspan; r++) {
          // Only start deleting cells to the right for the first row (r == 0)
          if (r === 0) {
            // Delete cells to the right of the target cell in the first row
            for (let c = colspan - 1; c > 0; c--) {
              if (table.rows[i + r].cells[j + c]) {
                table.rows[i + r].deleteCell(j + c);
              }
            }
          }
          // For rows below the first, delete starting from the target column
          if (r > 0) {
            for (let c = colspan - 1; c >= 0; c--) {
              if (table.rows[i + r] && table.rows[i + r].cells[j]) {
                table.rows[i + r].deleteCell(j);
              }
            }
          }
        }
        // Set rowspan and colspan of the target cell
        targetCell.rowSpan = rowspan;
        targetCell.colSpan = colspan;
      }
      // tinytable span after
      window.addEventListener('load', function () {
          var cellsToStyle = [
            // tinytable style arrays after
          { positions: [ { i: 0, j: 2 },  ], css_id: 'tinytable_css_5yxdj6q8ppedbu38r2wt',}, 
          { positions: [ { i: 18, j: 2 }, { i: 18, j: 1 },  ], css_id: 'tinytable_css_j7jhhfwihktpogp4rpij',}, 
          { positions: [ { i: 10, j: 2 }, { i: 10, j: 1 },  ], css_id: 'tinytable_css_1hdcr2zh6q1ovw9425dz',}, 
          { positions: [ { i: 3, j: 1 }, { i: 4, j: 1 }, { i: 5, j: 1 }, { i: 2, j: 1 }, { i: 7, j: 1 }, { i: 8, j: 1 }, { i: 9, j: 1 }, { i: 4, j: 2 }, { i: 11, j: 1 }, { i: 12, j: 1 }, { i: 13, j: 1 }, { i: 14, j: 1 }, { i: 15, j: 1 }, { i: 16, j: 1 }, { i: 17, j: 1 }, { i: 12, j: 2 }, { i: 6, j: 1 }, { i: 14, j: 2 }, { i: 2, j: 2 }, { i: 3, j: 2 }, { i: 17, j: 2 }, { i: 5, j: 2 }, { i: 6, j: 2 }, { i: 7, j: 2 }, { i: 8, j: 2 }, { i: 9, j: 2 }, { i: 11, j: 2 }, { i: 16, j: 2 }, { i: 13, j: 2 }, { i: 15, j: 2 },  ], css_id: 'tinytable_css_xbzkpqiogs0aijjbtkek',}, 
          { positions: [ { i: 0, j: 1 },  ], css_id: 'tinytable_css_9xkd3zka0a874cbnea59',}, 
          { positions: [ { i: 1, j: 1 }, { i: 1, j: 2 },  ], css_id: 'tinytable_css_gi182u7xjtwjbinv4e5i',}, 
          { positions: [ { i: 18, j: 0 },  ], css_id: 'tinytable_css_riykb52b0qg853yk9n3d',}, 
          { positions: [ { i: 10, j: 0 },  ], css_id: 'tinytable_css_ii7gy3ugmj1cw245qvgz',}, 
          { positions: [ { i: 2, j: 0 }, { i: 3, j: 0 }, { i: 4, j: 0 }, { i: 5, j: 0 }, { i: 6, j: 0 }, { i: 7, j: 0 }, { i: 8, j: 0 }, { i: 9, j: 0 }, { i: 14, j: 0 }, { i: 11, j: 0 }, { i: 12, j: 0 }, { i: 13, j: 0 }, { i: 15, j: 0 }, { i: 16, j: 0 }, { i: 17, j: 0 },  ], css_id: 'tinytable_css_vlekgzur4laltls0548k',}, 
          { positions: [ { i: 0, j: 0 },  ], css_id: 'tinytable_css_jqdrusupnqh0epmu6j7t',}, 
          { positions: [ { i: 1, j: 0 },  ], css_id: 'tinytable_css_qbzn4qr57esute045y9g',}, 
          ];

          // Loop over the arrays to style the cells
          cellsToStyle.forEach(function (group) {
              group.positions.forEach(function (cell) {
                  styleCell_7wpemef4qvgzqe5kqtya(cell.i, cell.j, group.css_id);
              });
          });
      });
    </script>

    <style>
      /* tinytable css entries after */
      .table td.tinytable_css_5yxdj6q8ppedbu38r2wt, .table th.tinytable_css_5yxdj6q8ppedbu38r2wt { text-align: center; text-align: center; border-top: solid #d3d8dc 0.1em; text-align: center; }
      .table td.tinytable_css_j7jhhfwihktpogp4rpij, .table th.tinytable_css_j7jhhfwihktpogp4rpij { text-align: center; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_1hdcr2zh6q1ovw9425dz, .table th.tinytable_css_1hdcr2zh6q1ovw9425dz { text-align: center; border-bottom: solid black 0.05em; }
      .table td.tinytable_css_xbzkpqiogs0aijjbtkek, .table th.tinytable_css_xbzkpqiogs0aijjbtkek { text-align: center; }
      .table td.tinytable_css_9xkd3zka0a874cbnea59, .table th.tinytable_css_9xkd3zka0a874cbnea59 { text-align: center; text-align: center; border-top: solid #d3d8dc 0.1em; text-align: center; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_gi182u7xjtwjbinv4e5i, .table th.tinytable_css_gi182u7xjtwjbinv4e5i { text-align: center; border-bottom: solid #d3d8dc 0.05em; }
      .table td.tinytable_css_riykb52b0qg853yk9n3d, .table th.tinytable_css_riykb52b0qg853yk9n3d { text-align: left; border-bottom: solid #d3d8dc 0.1em; }
      .table td.tinytable_css_ii7gy3ugmj1cw245qvgz, .table th.tinytable_css_ii7gy3ugmj1cw245qvgz { text-align: left; border-bottom: solid black 0.05em; }
      .table td.tinytable_css_vlekgzur4laltls0548k, .table th.tinytable_css_vlekgzur4laltls0548k { text-align: left; }
      .table td.tinytable_css_jqdrusupnqh0epmu6j7t, .table th.tinytable_css_jqdrusupnqh0epmu6j7t { text-align: left; text-align: center; border-top: solid #d3d8dc 0.1em; text-align: center; }
      .table td.tinytable_css_qbzn4qr57esute045y9g, .table th.tinytable_css_qbzn4qr57esute045y9g { text-align: left; border-bottom: solid #d3d8dc 0.05em; }
    </style>
    <div class="container">
      <table class="table table-borderless" id="tinytable_7wpemef4qvgzqe5kqtya" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing="true">
        <thead>
<tr>
<th scope="col" align="center" colspan="1"> </th>
<th scope="col" align="center" colspan="2">(1)</th>
</tr>
        
              <tr>
                <th scope="col"> </th>
                <th scope="col">Est.</th>
                <th scope="col">S.E.</th>
              </tr>
        </thead>
        
        <tbody>
                <tr>
                  <td>(Intercept)</td>
                  <td>2.92</td>
                  <td>0.35</td>
                </tr>
                <tr>
                  <td>eneg</td>
                  <td>0.11</td>
                  <td>0.14</td>
                </tr>
                <tr>
                  <td>log(average_magnitude)</td>
                  <td>0.08</td>
                  <td>0.23</td>
                </tr>
                <tr>
                  <td>upper_tier</td>
                  <td>-0.06</td>
                  <td>0.03</td>
                </tr>
                <tr>
                  <td>en_pres</td>
                  <td>0.26</td>
                  <td>0.15</td>
                </tr>
                <tr>
                  <td>proximity</td>
                  <td>-3.10</td>
                  <td>0.46</td>
                </tr>
                <tr>
                  <td>eneg × log(average_magnitude)</td>
                  <td>0.26</td>
                  <td>0.17</td>
                </tr>
                <tr>
                  <td>eneg × upper_tier</td>
                  <td>0.06</td>
                  <td>0.02</td>
                </tr>
                <tr>
                  <td>en_pres × proximity</td>
                  <td>0.68</td>
                  <td>0.23</td>
                </tr>
                <tr>
                  <td>Num.Obs.</td>
                  <td>487</td>
                  <td></td>
                </tr>
                <tr>
                  <td>R2</td>
                  <td>0.397</td>
                  <td></td>
                </tr>
                <tr>
                  <td>R2 Adj.</td>
                  <td>0.387</td>
                  <td></td>
                </tr>
                <tr>
                  <td>AIC</td>
                  <td>1672.5</td>
                  <td></td>
                </tr>
                <tr>
                  <td>BIC</td>
                  <td>1714.3</td>
                  <td></td>
                </tr>
                <tr>
                  <td>Log.Lik.</td>
                  <td>-826.229</td>
                  <td></td>
                </tr>
                <tr>
                  <td>RMSE</td>
                  <td>1.32</td>
                  <td></td>
                </tr>
                <tr>
                  <td>Std.Errors</td>
                  <td>by: country</td>
                  <td></td>
                </tr>
        </tbody>
      </table>
    </div>
<!-- hack to avoid NA insertion in last line -->
</div>
</div>
<p>Success!</p>
<p>They use <code>averge_magnitude</code> to measure the permissiveness of the electoral system and <code>eneg</code> to measure social heterogeneity.</p>
</section>
<section id="using-comparisons-to-compute-the-effects" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="using-comparisons-to-compute-the-effects">Using <code>comparisons()</code> to compute the effects</h2>
<p>Now let’s compute the two quantities of interest. Clark and Golder argue for two negligible effects, which I make really concrete below.</p>
<ul>
<li><strong>Hypothesis 1</strong> Increasing the effective number of ethnic groups from the 10th percentile (1.06) to the 90th percentile (2.48) will not lead to a substantively meaningful change in the effective number of political parties when the district magnitude is one.</li>
<li><strong>Hypothesis 2</strong> Increasing the district magnitude from one to seven will not lead to a substantively meaningful change in the effective number of political parties when the effective number of ethnic groups is one.</li>
</ul>
<p>And comparing the U.S. and the U.K., I argue that the smallest substantively interesting effect is 0.62. In <span class="citation" data-cites="rainey2014">Rainey (2014)</span>, I made the plot below. I want to reproduce it with {marginaleffects}.</p>
<p><img src="https://www.carlislerainey.com/blog/2023-08-18-equivalence-tests/rainey-2014-cg-example.png" class="img-fluid"></p>
<p>These differences (and the 90% CIs) are really easy to compute using {marginaleffects}!<sup>2</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn2"><p><sup>2</sup>&nbsp;I’m only doing Clark and Golder’s original results, not any of the robustness checks.</p></div></div><div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># load packages</span></span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(marginaleffects)</span>
<span id="cb2-3"></span>
<span id="cb2-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># the smallest substantively interesting effect</span></span>
<span id="cb2-5">m <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.62</span></span>
<span id="cb2-6"></span>
<span id="cb2-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># a data frame setting the values of the "other" variables</span></span>
<span id="cb2-8">X_c <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb2-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">eneg =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.06</span>,  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># low value</span></span>
<span id="cb2-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">average_magnitude =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># low value</span></span>
<span id="cb2-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper_tier =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb2-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">en_pres =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, </span>
<span id="cb2-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">proximity =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb2-14">)</span>
<span id="cb2-15"></span>
<span id="cb2-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute the comparison for eneg and average magnitude</span></span>
<span id="cb2-17">c <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">comparisons</span>(fit,</span>
<span id="cb2-18">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vcov =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> country,</span>
<span id="cb2-19">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">newdata =</span> X_c, </span>
<span id="cb2-20">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"eneg"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.06</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.48</span>),         <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># low to high value</span></span>
<span id="cb2-21">                             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"average_magnitude"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>)), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># low to high value</span></span>
<span id="cb2-22">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">conf_level =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.90</span>)</span></code></pre></div>
</div>
<p>This <code>c</code> outputted from <code>comparisons()</code> is a data frame.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># default print method</span></span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(c)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>
              Term    Contrast Estimate Std. Error     z Pr(&gt;|z|)    S  5.0 %
 average_magnitude 7 - 1          0.696      0.175 3.973   &lt;0.001 13.8  0.408
 eneg              2.48 - 1.06    0.158      0.204 0.779    0.436  1.2 -0.176
 95.0 %
  0.984
  0.493

Type:  response </code></pre>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># quick look at the bare data frame</span></span>
<span id="cb5-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glimpse</span>(c)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 2
Columns: 19
$ rowid             &lt;int&gt; 1, 1
$ term              &lt;chr&gt; "average_magnitude", "eneg"
$ contrast          &lt;chr&gt; "7 - 1", "2.48 - 1.06"
$ estimate          &lt;dbl&gt; 0.6956014, 0.1584771
$ std.error         &lt;dbl&gt; 0.1750741, 0.2035052
$ statistic         &lt;dbl&gt; 3.9731830, 0.7787372
$ p.value           &lt;dbl&gt; 7.091852e-05, 4.361345e-01
$ s.value           &lt;dbl&gt; 13.783478, 1.197155
$ conf.low          &lt;dbl&gt; 0.4076302, -0.1762592
$ conf.high         &lt;dbl&gt; 0.9835727, 0.4932134
$ predicted_lo      &lt;dbl&gt; 3.034008, 3.034008
$ predicted_hi      &lt;dbl&gt; 3.729609, 3.192485
$ predicted         &lt;dbl&gt; 3.034008, 3.034008
$ eneg              &lt;dbl&gt; 1.06, 1.06
$ average_magnitude &lt;dbl&gt; 1, 1
$ upper_tier        &lt;dbl&gt; 0, 0
$ en_pres           &lt;dbl&gt; 0, 0
$ proximity         &lt;dbl&gt; 0, 0
$ enep              &lt;dbl&gt; 5.75, 5.75</code></pre>
</div>
</div>
<p>Now we can just plot the 90% CIs with <code>ggplot()</code> and check whether the entire interval falls inside the bounds.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># bind the comparisons together and plot</span></span>
<span id="cb7-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(c, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> estimate,</span>
<span id="cb7-3">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> conf.low,</span>
<span id="cb7-4">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> conf.high, </span>
<span id="cb7-5">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> term)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>m, m), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbarh</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() </span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2023-08-18-equivalence-tests/index_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>In this case, we conclude that social heterogeneity (<code>eneg</code>) has a negligible effect because the 90% CI only contains substantively negligible values. However, the 90% CI for district magnitude (<code>average_magnitude</code>) contains substantively negligible and meaningful values, so we cannot reject the null hypothesis of a meaningful effect.</p>
</section>
<section id="computing-the-tost-p-values-using-hypotheses" class="level2">
<h2 class="anchored" data-anchor-id="computing-the-tost-p-values-using-hypotheses">Computing the TOST <em>p</em>-values using <code>hypotheses()</code></h2>
<p>It’s then almost trivial to use the <code>hypotheses()</code> function to compute the TOST <em>p</em>-values.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># hypothesis tests</span></span>
<span id="cb8-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hypotheses</span>(c, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">equivalence =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>m, m))</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>
              Term Estimate Std. Error     z Pr(&gt;|z|)    S  5.0 % 95.0 %
 average_magnitude    0.696      0.175 3.973   &lt;0.001 13.8  0.408  0.984
 eneg                 0.158      0.204 0.779    0.436  1.2 -0.176  0.493
 p (NonInf) p (NonSup) p (Equiv)
     &lt;0.001     0.6671    0.6671
     &lt;0.001     0.0117    0.0117</code></pre>
</div>
</div>
<p>This doesn’t print super-nicely into this document, so let’s extract the important parts.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># hypothesis tests, extracting the important pieces</span></span>
<span id="cb10-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hypotheses</span>(c, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">equivalence =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>m, m)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb10-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(term, estimate, conf.low, conf.high, p.value.equiv)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>
              Term Estimate CI low CI high p (Equiv)
 average_magnitude    0.696  0.408   0.984    0.6671
 eneg                 0.158 -0.176   0.493    0.0117</code></pre>
</div>
</div>
<p>Checking that the 90% CIs fall within the bounds created by the smallest substantively-meaningful effect is equivalent to checking whether the TOST <em>p</em>-value (i.e., the <code>p(Equiv)</code> column) is less than 0.05, so our conclusions are (and must be) identical.</p>
</section>
<section id="other-references" class="level2">
<h2 class="anchored" data-anchor-id="other-references">Other references</h2>
<p>For more on effective arguments for no effect, see the following:</p>
<ul>
<li><span class="citation" data-cites="lakens2017">Lakens (2017)</span> and <span class="citation" data-cites="lakens2018">Lakens, Scheel, and Isager (2018)</span> offer an accessible introduction to equivalences tests for psychologists.</li>
<li><span class="citation" data-cites="fitzgerald2025">Fitzgerald (2025)</span> offers and introduction to and argument for equivalence tests for economists.</li>
<li><span class="citation" data-cites="kane2024">Kane (2024)</span> offers an excellent summary of design considerations when arguing for no effect.</li>
<li><span class="citation" data-cites="mccaskey2015">McCaskey and Rainey (2015)</span> (<a href="https://www.carlislerainey.com/papers/meaningful.pdf">Ungated PDF</a>) argue that researchers should make “claims if and only if those claims hold for the entire confidence interval.” This extends the logic of equivalence testing to a broader collection of possible hypotheses.</li>
</ul>
</section>
<section id="final-thoughts" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="final-thoughts">Final thoughts</h2>
<ol type="1">
<li>{marginaleffects} is a great package <span class="citation" data-cites="marginaleffects">(Arel-Bundock 2024)</span>. I think it’s the first package in which the syntax matches the way I think about computing quantities of interest. That said, this is just my first try at it. But I’m very impressed so far.</li>
<li>The {marginaleffects} <a href="https://marginaleffects.com">book</a> <em>Model to Meaning</em> has a whole <a href="https://marginaleffects.com/chapters/hypothesis.html#sec-hypothesis_equivalence">chapter</a> on equivalence tests. My only caution is that there is a mismatch between 95% confidence intervals and equivalence tests. By default, {marginaleffects} reports a 95% CI, even when producing a <em>p</em>-value for an equivalence test. However, the 90% confidence interval correspondents to a size-5% equivalence test. So if you’re using {marginaleffects} to do equivalence tests, I recommend setting <code>conf_level = 0.90</code>.<sup>3</sup></li>
<li>For a more recent example, <span class="citation" data-cites="jares2024">Jares and Malhotra (2024)</span> discusses negligible effects and hypothesis tests in a way that I find clear and compelling. It’s an excellent model to follow. See pp.&nbsp;12-13. They “show that improved compensation outcomes had negligible impacts on Republican farmers’ midterm turnout and campaign contributions, even though such variation in benefits significantly affected farmers’ propensity to view the intervention as helpful.”</li>
</ol>



<div class="no-row-height column-margin column-container"><div id="fn3"><p><sup>3</sup>&nbsp;I would make a similar point about one-sided tests as well, but that’s less correct, because it should be a <em>one-sided</em> 95% CI.</p></div></div></section>


<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-altman1995" class="csl-entry">
Altman, D. G, and J M. Bland. 1995. <span>“Statistics Notes: Absence of Evidence Is Not Evidence of Absence.”</span> <em>BMJ</em> 311 (7003): 485–85. <a href="https://doi.org/10.1136/bmj.311.7003.485">https://doi.org/10.1136/bmj.311.7003.485</a>.
</div>
<div id="ref-marginaleffects" class="csl-entry">
Arel-Bundock, Vincent. 2024. <em>Marginaleffects: Predictions, Comparisons, Slopes, Marginal Means, and Hypothesis Tests</em>. <a href="https://marginaleffects.com/">https://marginaleffects.com/</a>.
</div>
<div id="ref-clark2006" class="csl-entry">
Clark, William Roberts, and Matt Golder. 2006. <span>“Rehabilitating Duverger<span>’</span>s Theory.”</span> <em>Comparative Political Studies</em> 39 (6): 679–708. <a href="https://doi.org/10.1177/0010414005278420">https://doi.org/10.1177/0010414005278420</a>.
</div>
<div id="ref-fitzgerald2025" class="csl-entry">
Fitzgerald, Jack. 2025. <span>“The Need for Equivalence Testing in Economics.”</span> Center for Open Science. <a href="https://doi.org/10.31222/osf.io/d7sqr_v1">https://doi.org/10.31222/osf.io/d7sqr_v1</a>.
</div>
<div id="ref-gill1999" class="csl-entry">
Gill, Jeff. 1999. <span>“The Insignificance of Null Hypothesis Significance Testing.”</span> <em>Political Research Quarterly</em> 52 (3): 647–74. <a href="https://doi.org/10.1177/106591299905200309">https://doi.org/10.1177/106591299905200309</a>.
</div>
<div id="ref-jares2024" class="csl-entry">
Jares, Jake Alton, and Neil Malhotra. 2024. <span>“Policy Impact and Voter Mobilization: Evidence from Farmers’ Trade War Experiences.”</span> <em>American Political Science Review</em> 119 (2): 847–69. <a href="https://doi.org/10.1017/s0003055424000571">https://doi.org/10.1017/s0003055424000571</a>.
</div>
<div id="ref-kane2024" class="csl-entry">
Kane, John V. 2024. <span>“More Than Meets the ITT: A Guide for Anticipating and Investigating Nonsignificant Results in Survey Experiments.”</span> <em>Journal of Experimental Political Science</em>, February, 1–16. <a href="https://doi.org/10.1017/xps.2024.1">https://doi.org/10.1017/xps.2024.1</a>.
</div>
<div id="ref-lakens2017" class="csl-entry">
Lakens, Daniël. 2017. <span>“Equivalence Tests.”</span> <em>Social Psychological and Personality Science</em> 8 (4): 355–62. <a href="https://doi.org/10.1177/1948550617697177">https://doi.org/10.1177/1948550617697177</a>.
</div>
<div id="ref-lakens2018" class="csl-entry">
Lakens, Daniël, Anne M. Scheel, and Peder M. Isager. 2018. <span>“Equivalence Testing for Psychological Research: A Tutorial.”</span> <em>Advances in Methods and Practices in Psychological Science</em> 1 (2): 259–69. <a href="https://doi.org/10.1177/2515245918770963">https://doi.org/10.1177/2515245918770963</a>.
</div>
<div id="ref-mccaskey2015" class="csl-entry">
McCaskey, Kelly, and Carlisle Rainey. 2015. <span>“Substantive Importance and the Veil of Statistical Significance.”</span> <em>Statistics, Politics and Policy</em> 6 (1-2). <a href="https://doi.org/10.1515/spp-2015-0001">https://doi.org/10.1515/spp-2015-0001</a>.
</div>
<div id="ref-nickerson2000" class="csl-entry">
Nickerson, Raymond S. 2000. <span>“Null Hypothesis Significance Testing: A Review of an Old and Continuing Controversy.”</span> <em>Psychological Methods</em> 5 (2): 241–301. <a href="https://doi.org/10.1037/1082-989x.5.2.241">https://doi.org/10.1037/1082-989x.5.2.241</a>.
</div>
<div id="ref-rainey2014" class="csl-entry">
Rainey, Carlisle. 2014. <span>“Arguing for a Negligible Effect.”</span> <em>American Journal of Political Science</em> 58 (4): 1083–91. <a href="https://doi.org/10.1111/ajps.12102">https://doi.org/10.1111/ajps.12102</a>.
</div>
</div></section></div> ]]></description>
  <category>hypothesis tests</category>
  <category>confidence intervals</category>
  <category>equivalence tests</category>
  <category>TOSTs</category>
  <category>negligible effects</category>
  <category>computing</category>
  <category>R</category>
  <category>marginaleffects</category>
  <guid>https://www.carlislerainey.com/blog/2023-08-18-equivalence-tests/</guid>
  <pubDate>Fri, 18 Aug 2023 04:00:00 GMT</pubDate>
  <media:content url="https://www.carlislerainey.com/blog/2023-08-18-equivalence-tests/rainey-2014-cg-example.png" medium="image" type="image/png" height="118" width="144"/>
</item>
<item>
  <title>Daily Writing</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2023-08-15-daily-writing/</link>
  <description><![CDATA[ 




<p>I try to write everyday.<sup>1</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn1"><p><sup>1</sup>&nbsp;See lots of caveats below!</p></div></div><p>By “writing,” I mean “pushing the paper closest to publication just a little bit closer.” I want to think about the next step on the journey to the published paper and do it. According to this loose definition of writing, it might involve data collection, data analysis, creating slides, or even writing and polishing text. It might involve organization, planning, or learning new skills. It excludes any tasks that aren’t necessary to complete the project.</p>
<p>By “everyday,” I mean at least every weekday, probably at the same time every day and probably first thing in the morning. For better or worse, academics are evaluated by their research productivity.</p>
<section id="urgency-and-importance" class="level2">
<h2 class="anchored" data-anchor-id="urgency-and-importance">Urgency and Importance</h2>
<p>President Eisenhower famously <a href="http://www.presidency.ucsb.edu/ws/?pid=9991">characterized</a> his duties: “I have two kinds of problems, the urgent and the important. The urgent are not important, and the important are never urgent.”</p>
<p>Following <a href="https://en.wikipedia.org/wiki/Time_management#The_Eisenhower_Method">Eisenhower’s Box</a>, we might assign degrees of urgency and importance to tasks in academic tasks. In graduate school, I had teaching responsibilities, RA duties, readings for seminars, homework for methods classes, preliminary exams, and administrative tasks. All of these tasks are important. They must be completed. They must be completed well. Yet I was evaluated largely on my papers. As a faculty member, little has changed.</p>
<p>Writing is important, but <em>writing never quite becomes urgent.</em> It’s easy to put off writing to prepare a lecture (or write a blog post).</p>
</section>
<section id="the-evidence" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="the-evidence">The Evidence</h2>
<p>Robert Boice <a href="https://www.amazon.com/Professors-Writers-Self-Help-Productive-Writing/dp/091350713X">studied</a> academic productivity carefully. A couple of his studies provide some evidence for my strategy to write every day.</p>
<p>First, he <a href="https://www.sciencedirect.com/science/article/pii/0005796789901447">assessed</a> how early-career academics spend their time. The figure below shows the results. Notice that these faculty spend more time in committee meetings (2 hrs.) than writing (1.5 hours).</p>
<div class="cell">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2023-08-15-daily-writing/index_files/figure-html/unnamed-chunk-1-1.png" class="img-fluid figure-img" width="576"></p>
</figure>
</div>
</div>
</div>
<p>Second, Boice <a href="https://www.sciencedirect.com/science/article/pii/0005796783900451">conducted</a> an experiment to assess the effect of writing strategies.</p>
<p>Boice randomly divided 27 academics into three groups:<sup>2</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn2"><p><sup>2</sup>&nbsp;This is a small sample, but it supports my claim so it’s okay.</p></div></div><ul>
<li>The <strong>control</strong> group agreed to defer all but the most urgent writing for ten weeks.</li>
<li>The <strong>spontaneous</strong> group agreed write when they felt like it.</li>
<li>The <strong>contingency</strong> group agreed to donate to an anti-charity if they failed to write every day.</li>
</ul>
<p>The figure below shows that regular writing routine increase production of both pages <em>and</em> ideas. Notice that the spontaneous writers barely produced more ideas and pages than the group trying to <em>avoid</em> writing.</p>
<div class="cell">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2023-08-15-daily-writing/index_files/figure-html/unnamed-chunk-2-1.png" class="img-fluid figure-img" width="576"></p>
</figure>
</div>
</div>
</div>
<p>I find these results compelling, but note that Helen Sword <a href="https://www.tandfonline.com/doi/pdf/10.1080/1360144X.2016.1210153">urges</a> some caution.</p>
</section>
<section id="how-i-do-it" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="how-i-do-it">How I Do It</h2>
<p>Everyone is different, and my own approach has evolved over time. Here are the key ingredients (for me):</p>
<ol type="1">
<li>Write for <em>two hours</em> at a regular time. Consistency is key.<sup>3</sup></li>
<li>Avoid writing outside this window. Set your window so that your window is “enough.”</li>
<li>Take breaks. I take long breaks from writing. But these are intentional and planned.<sup>4</sup></li>
<li>Family permitting, I think it’s helpful to spend a little while pushing the projects forward on the weekends, just to keep the momentum up.<sup>5</sup></li>
</ol>
<div class="no-row-height column-margin column-container"><div id="fn3"><p><sup>3</sup>&nbsp;Two hours works really well for me. My productivity degrades quickly after two hours, so it’s best to move on to less taxing tasks. But it takes me a while to get warmed up, so I need to keep moving while I’ve got momentum.</p></div><div id="fn4"><p><sup>4</sup>&nbsp;An unfortunate outcome is not writing and being stressed about not writing.</p></div><div id="fn5"><p><sup>5</sup>&nbsp;Just 15 minutes is great. This slot is perfect for proof-reading.</p></div></div><p>I admit that I deviate from the strategy above (and not always intentionally). But I’ve been at this long enough to know that a regular routine works really well for me.</p>
</section>
<section id="what-if-youre-not-ready-to-write-yet" class="level2">
<h2 class="anchored" data-anchor-id="what-if-youre-not-ready-to-write-yet">What if you’re not ready to write yet?</h2>
<p>It’s my view that PhD students should write every day, from the first day of their first semester (remember that I have a broad definition of “write”). Most students need some time before they’re ready to jump into the technical details a solo project, but there are always things to do.</p>
<p>If you can’t identify a specific task to work on, here are some resources to help you brainstorm.</p>
<ul>
<li>Plan and organize. Start by reading <a href="https://www.amazon.com/How-Write-Lot-Practical-Productive/dp/1591477433"><em>How to Write a Lot</em></a>. Perhaps read <a href="https://www.amazon.com/Getting-Things-Done-Stress-Free-Productivity/dp/0142000280"><em>Getting Things Done</em></a>. Perhaps read <a href="https://www.amazon.com/Air-Light-Time-Space-Successful/dp/0674737709"><em>Air &amp; Light &amp; Time &amp; Space</em></a> or <a href="https://www.amazon.com/Writing-Social-Scientists-Chicago-Publishing/dp/0226041328/"><em>Writing for Social Scientists</em></a>.</li>
<li>Read <a href="https://gking.harvard.edu/files/gking/files/paperspub.pdf">“Publication, Publication”</a> and the <a href="https://gking.harvard.edu/papers">updates</a>.</li>
<li>Before you can jump into a project, you need to know the literature. Spend some writing time exploring literatures that you might want to contribute to. What interests you most? The <em><a href="https://www.annualreviews.org/journal/polisci">Annual Review of Political Science</a></em> is a valuable resource.</li>
<li>Once you have a specific topic of interest, you need to learn that literature. You can spend dozens of “writing” sessions reading and taking notes. I strongly encourage you to read and take notes <em>systematically</em>, as Raul Pacheco-Vega <a href="http://www.raulpacheco.org/2016/06/synthesizing-different-bodies-of-work-in-your-literature-review-the-conceptual-synthesis-excel-dump-technique/">suggests</a> using a spreadsheet, Elaine Campbell <a href="https://alawuntoherself.com/2016/05/20/how-i-use-excel-to-manage-my-literature-review/">suggests</a> a similar method, and Katherine Firth <a href="https://researchinsiders.blog/2017/04/27/turn-your-notes-into-writing-using-the-cornell-method-second-edition/">suggests</a> a using <a href="https://en.wikipedia.org/wiki/Cornell_Notes">Cornell notes</a>.</li>
<li>Tanya Golash-Boza <a href="http://getalifephd.blogspot.com/2012/01/ten-ways-to-write-every-day.html">lists</a> ten ways to write everyday if you’ve got a paper in-progress.</li>
</ul>


</section>


 ]]></description>
  <category>writing</category>
  <guid>https://www.carlislerainey.com/blog/2023-08-15-daily-writing/</guid>
  <pubDate>Tue, 15 Aug 2023 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Benchmarking Firth’s Logit: {brglm2} versus {logistf}</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2023-08-11-benchmarking-firth/</link>
  <description><![CDATA[ 




<section id="firths-logit" class="level2">
<h2 class="anchored" data-anchor-id="firths-logit">Firth’s Logit</h2>
<p>I like Firth’s logistic regression model <span class="citation" data-cites="firth1993">(Firth 1993)</span>. I talk about that in <span class="citation" data-cites="rainey2021">Rainey and McCaskey (2021)</span> and <a href="https://twitter.com/carlislerainey/status/1686389777225113601">this Twitter thread</a>. <span class="citation" data-cites="kosmidis2021">Kosmidis and Firth (2021)</span> offer an excellent, recent follow-up as well.</p>
<p>I’ll refer you to the papers for a careful discussion of the benefits, but Firth’s penalty reduces the bias <em>and variance</em> of the logit coefficients.</p>
</section>
<section id="goals-for-benchmarking" class="level2">
<h2 class="anchored" data-anchor-id="goals-for-benchmarking">Goals for Benchmarking</h2>
<p>In this post, I want to compare the brglm2 and logistf packages. Which fits logistic regression models with Firth’s penalty the fastest?</p>
<p>These packages both fit the models almost instantly, so there is no practical difference when fitting just one model. But large Monte Carlo simulations (or perhaps bootstraps), small differences might add up to a substantial time difference.</p>
<p>Here, I benchmark the two packages for fitting logistic regression models with Firth’s penalty in a <em>small sample</em>–the results might not generalize to a larger sample. The data set comes from <span class="citation" data-cites="weisiger2014">Weisiger (2014)</span> (see <code>?crdata::weisiger2014</code>). It has only 35 observations.</p>
<p>You can find the benchmarking code as a <a href="https://gist.github.com/carlislerainey/8bf23a322252bead64d0a07391f7383d">GitHub Gist</a>.</p>
</section>
<section id="benchmarking" class="level2">
<h2 class="anchored" data-anchor-id="benchmarking">Benchmarking</h2>
<p>I benchmark four methods here.</p>
<ol type="1">
<li>A vanilla <code>glm()</code> logit model.</li>
<li>A Firth’s logit via brglm2 by supplying <code>method = brglm2::brglmFit</code> to <code>glm()</code>.</li>
<li>A Firth’s logit via logistf via <code>logistf()</code> using the default settings.</li>
<li>A Firth’s logit via logistf via <code>logistf()</code> with the argument <code>pl = FALSE</code>. This argument is important because it skips hypothesis testing using profile likelihoods, which are computationally costly.</li>
</ol>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># install crdata package to egt weisiger2014 data set</span></span>
<span id="cb1-2">remotes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install_github</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"carlislerainey/crdata"</span>)</span>
<span id="cb1-3"></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># load packages</span></span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(brglm2)</span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(logistf)</span>
<span id="cb1-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(microbenchmark)</span>
<span id="cb1-9"></span>
<span id="cb1-10"></span>
<span id="cb1-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># load data</span></span>
<span id="cb1-12">weis <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> crdata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>weisiger2014</span>
<span id="cb1-13"></span>
<span id="cb1-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># rescale weisiger2014 explanatory variables using arm::rescale()</span></span>
<span id="cb1-15">rs_weis <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> weis <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(polity_conq<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>coord, arm<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>rescale)) </span>
<span id="cb1-17"></span>
<span id="cb1-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># create functions to fit models</span></span>
<span id="cb1-19">f <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> resist <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> polity_conq <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> lndist <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> terrain <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> soldperterr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> gdppc2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> coord</span>
<span id="cb1-20">f1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>() {</span>
<span id="cb1-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(f, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> rs_weis, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"binomial"</span>)</span>
<span id="cb1-22">}</span>
<span id="cb1-23">f2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>() {</span>
<span id="cb1-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(f, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> rs_weis, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"binomial"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> brglmFit)</span>
<span id="cb1-25">}</span>
<span id="cb1-26">f3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>() {</span>
<span id="cb1-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">logistf</span>(f, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> rs_weis)</span>
<span id="cb1-28">}</span>
<span id="cb1-29">f4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>() {</span>
<span id="cb1-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">logistf</span>(f, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> rs_weis, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pl =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb1-31">}</span>
<span id="cb1-32"></span>
<span id="cb1-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># do benchmarking</span></span>
<span id="cb1-34">bm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">microbenchmark</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"regular glm()"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f1</span>(), </span>
<span id="cb1-35">               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"brglm2"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f2</span>(), </span>
<span id="cb1-36">               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logistf (default)"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f3</span>(),</span>
<span id="cb1-37">               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logistf (w/ pl = FALSE)"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f4</span>(),</span>
<span id="cb1-38">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">times =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>) </span></code></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning in microbenchmark(`regular glm()` = f1(), brglm2 = f2(), `logistf
(default)` = f3(), : less accurate nanosecond times to avoid potential integer
overflows</code></pre>
</div>
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(bm)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Unit: microseconds
                    expr      min        lq      mean    median        uq
           regular glm()  500.651  547.0425  591.5304  560.0805  584.4550
                  brglm2 2469.266 2546.9405 2735.6438 2591.5690 2672.3800
       logistf (default) 3303.329 3432.6635 3942.9122 3481.6585 3558.1235
 logistf (w/ pl = FALSE)  513.197  553.3155  594.6205  570.8225  608.9115
       max neval
  2713.708   100
  9735.983   100
 17672.148   100
  1698.343   100</code></pre>
</div>
</div>
<p>In short, logistf is slower than brglm2, but only because it computes the profile likelihood <em>p</em>-values by default. Once we skip those calculations using <code>pl = FALSE</code>, logistf is <em>much</em> faster. On average, it’s faster than <code>glm()</code>, because <code>glm()</code> has the occasional <em>really</em> slow computation.</p>
<p>Here’s a plot showing the computation times of the four fits. Remember that all of these are computed practically instantly, so it only makes a difference when the fits are done thousands of times, like in a Monte Carlo simulation.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plot times</span></span>
<span id="cb5-2">bm <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(expr) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg_time =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(time)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10e-5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># convert to milliseconds</span></span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(expr), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> avg_time)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Method"</span>, </span>
<span id="cb5-8">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Avg. Time (in milliseconds)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_flip</span>()</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2023-08-11-benchmarking-firth/index_files/figure-html/unnamed-chunk-2-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="follow-up-notes" class="level1">
<h1>Follow-Up Notes</h1>
<p>The models return <em>slightly</em> different estimates. Maybe they are using slightly different convergence tolerances. I didn’t investigate this beyond noticing it.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f2</span>()), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f4</span>()))</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>                  [,1]       [,2]
(Intercept) -0.4771934 -0.4771935
polity_conq -2.2771109 -2.2771117
lndist       3.4020241  3.4020215
terrain      1.1018696  1.1018713
soldperterr -0.5952096 -0.5952110
gdppc2      -1.1542010 -1.1541998
coord        3.0514481  3.0514473</code></pre>
</div>
</div>
<p>Ioannis Kosmidis made me aware of two things.</p>
<ol type="1">
<li>logistf has a C++ backend (thus explaining the speed).</li>
<li>brglm2 is written entirely in R. He noted that a new version is coming out soon that might be substantially faster. (brglm2 is also more general; it supports a variety of models and corrections).</li>
</ol>
<section id="computer" class="level2">
<h2 class="anchored" data-anchor-id="computer">Computer</h2>
<p>Here’s the info on my machine.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">system</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sysctl -n machdep.cpu.brand_string"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">intern =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Apple M2 Max"</code></pre>
</div>
</div>



</section>
</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-firth1993" class="csl-entry">
Firth, David. 1993. <span>“Bias Reduction of Maximum Likelihood Estimates.”</span> <em>Biometrika</em> 80 (1): 27–38. <a href="https://doi.org/10.1093/biomet/80.1.27">https://doi.org/10.1093/biomet/80.1.27</a>.
</div>
<div id="ref-kosmidis2021" class="csl-entry">
Kosmidis, Ioannis, and David Firth. 2021. <span>“Jeffreys-Prior Penalty, Finiteness and Shrinkage in Binomial-Response Generalized Linear Models.”</span> <em>Biometrika</em> 108 (1): 71–82. <a href="https://doi.org/10.1093/biomet/asaa052">https://doi.org/10.1093/biomet/asaa052</a>.
</div>
<div id="ref-rainey2021" class="csl-entry">
Rainey, Carlisle, and Kelly McCaskey. 2021. <span>“Estimating Logit Models with Small Samples.”</span> <em>Political Science Research and Methods</em> 9 (3): 549–64. <a href="https://doi.org/10.1017/psrm.2021.9">https://doi.org/10.1017/psrm.2021.9</a>.
</div>
<div id="ref-weisiger2014" class="csl-entry">
Weisiger, Alex. 2014. <span>“Victory Without Peace: Conquest, Insurgency, and War Termination.”</span> <em>Conflict Management and Peace Science</em> 31 (4): 357–82. <a href="https://doi.org/10.1177/0738894213508691">https://doi.org/10.1177/0738894213508691</a>.
</div>
</div></section></div> ]]></description>
  <category>logistic regression</category>
  <category>small samples</category>
  <category>Firth</category>
  <category>computing</category>
  <category>R</category>
  <guid>https://www.carlislerainey.com/blog/2023-08-11-benchmarking-firth/</guid>
  <pubDate>Fri, 11 Aug 2023 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Power, Part III: The Rule of 3.64 for Statistical Power</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2023-06-12-power-3-rule-of-364/</link>
  <description><![CDATA[ 




<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
A Paper
</div>
</div>
<div class="callout-body-container callout-body">
<p>This post turned out to be somewhat popular, so I’ve written up a more formal, careful description of the idea in a full-length paper. You can find the preprint “Power Rules” <a href="https://osf.io/preprints/osf/5am9q_v2">here</a>.</p>
</div>
</div>
<section id="background" class="level2">
<h2 class="anchored" data-anchor-id="background">Background</h2>
<p>I’ve wrapped up the argument that you should pursue statistical power in your experiments. In sum, you should do it for <em>you</em> (not a future Reviewer 2) and you shouldn’t see confidence intervals nestle consistently against zero.</p>
<ol type="1">
<li><a href="../../blog/2023-05-22-power-1-for-you-not-reviewer-2">“Power Is For You, Not For Reviewer 2”</a></li>
<li><a href="../../blog/2023-05-25-power-2-what-do-confidence-intervals-look-like">“What Do Confidence Intervals From Well-Powered Studies Look Like?”</a></li>
</ol>
<p>In this post, I’d like to develop the intuition for power calculations, two helpful guidelines, and one implication.</p>
<p>Main takeaway: You need the ratio of the true effect and the standard error to be more than 3.64.</p>
</section>
<section id="starting-point-the-sampling-distribution" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="starting-point-the-sampling-distribution">Starting Point: The Sampling Distribution</h2>
<p>When you run one experiment, you realize <em>one</em> of many possible patterns of randomization. This particular realization produces a single <strong>estimate</strong> of the treatment effect from a <em>distribution</em> of possible estimates. The distribution of possibilities is called a “<strong>sampling distribution</strong>.”</p>
<p>Thus, we can think of the estimate as a random variable and its distribution as the sampling distribution. The sampling distribution is key to everything I do in this post, so let’s spend some time with it.</p>
<p>Let’s imagine that we did the exact same study 50 times. Let’s say that we computed a difference-in-means in dollars ($) donated.<sup>1</sup> I refer to this difference-in-means as the estimated treatment effect. It is the estimate of the average treatment effect (in $). This estimate will vary across the many possible patterns of randomization because each pattern puts different respondents in the treatment and control group.</p>
<div class="no-row-height column-margin column-container"><div id="fn1"><p><sup>1</sup>&nbsp;I just want an easy-to-use unit here, and dollars meets that criteria. Other units work fine, too.</p></div></div><p>We can visualize this with ggnaminate. We can imagine each iteration of the study as producing a particular estimate. We continue to repeat the study and collect the estimates. Eventually, we can produce a histogram from this collection of estimates. This histogram represents the sampling distribution and is fundamental to the calculations that follow. The figure belows shows how we might collect the points into a histogram.</p>
<div class="cell page-columns page-full" data-hash="index_cache/html/unnamed-chunk-1_fd68411c54b5c41ff98040f53117b994">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(gganimate)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(magick)</span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># gif pars</span></span>
<span id="cb1-6">duration <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># must be even</span></span>
<span id="cb1-7">fps <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span></span>
<span id="cb1-8">nframes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> duration<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>fps</span>
<span id="cb1-9">scale <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span></span>
<span id="cb1-10">width <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span></span>
<span id="cb1-11">height <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span></span>
<span id="cb1-12">res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">125</span></span>
<span id="cb1-13"></span>
<span id="cb1-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># study parameters</span></span>
<span id="cb1-15">true_effect <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb1-16">se <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span></span>
<span id="cb1-17"></span>
<span id="cb1-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># number of times to repeat the study</span></span>
<span id="cb1-19">n_studies <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># nframes</span></span>
<span id="cb1-20"></span>
<span id="cb1-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># create a data frame of confidence intervals</span></span>
<span id="cb1-22">ests <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">study_id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>n_studies, </span>
<span id="cb1-23">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n_studies, true_effect, se))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reject_null =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No"</span>))</span>
<span id="cb1-25"></span>
<span id="cb1-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add two things to the data frame of confidence intervals</span></span>
<span id="cb1-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 1. an initial row with study_id = 1 and est = NA so that </span></span>
<span id="cb1-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#    the plot starts empty (gganimate would start with the </span></span>
<span id="cb1-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#    first observation in place otherwise).</span></span>
<span id="cb1-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 2. a group variable that defines the row. This is the same</span></span>
<span id="cb1-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#    as the study_id, except the dummy row from (1) and the </span></span>
<span id="cb1-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#    actual first row have different groups.</span></span>
<span id="cb1-33">animate_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb1-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">study_id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>),  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># study_id = 1, est = NA</span></span>
<span id="cb1-35">  ests                             <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># actual cis</span></span>
<span id="cb1-36">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()) </span>
<span id="cb1-38"></span>
<span id="cb1-39">split_animate_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> animate_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span>        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># group (row index)</span></span>
<span id="cb1-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">accumulate</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(.x, .y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"frame"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">frame =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(frame))</span>
<span id="cb1-44"></span>
<span id="cb1-45"></span>
<span id="cb1-46">se_lines <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tribble</span>(</span>
<span id="cb1-47">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>se_, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>label, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>chance, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>ch_loc_,  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># trailing _ means not rescaeld to study se</span></span>
<span id="cb1-48">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"True Effect"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,</span>
<span id="cb1-49">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+1 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb1-50">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+2 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>,</span>
<span id="cb1-51">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+3 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>,</span>
<span id="cb1-52">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-1 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb1-53">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-2 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>,</span>
<span id="cb1-54">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-3 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>,</span>
<span id="cb1-55">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-56">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ch_loc =</span> ch_loc_<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> true_effect,</span>
<span id="cb1-57">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> se_<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> true_effect)</span>
<span id="cb1-58"></span>
<span id="cb1-59"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># start with a ggplot</span></span>
<span id="cb1-60">gg1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(animate_data, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> est, </span>
<span id="cb1-61">                               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> study_id,</span>
<span id="cb1-62">                               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> group)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-63">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_lines, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> se, </span>
<span id="cb1-64">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(se_)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-65">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_label</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_lines, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> n_studies <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> label, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(se_))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-66">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_lines, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> ch_loc, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> chance, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-67">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>((est<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> true_effect)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>se)),</span>
<span id="cb1-68">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-69">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_rug</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sides =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b"</span>, </span>
<span id="cb1-70">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> est, </span>
<span id="cb1-71">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>((est<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> true_effect)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>se)), </span>
<span id="cb1-72">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, </span>
<span id="cb1-73">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npc"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-74">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-75">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid.minor.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-76">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate of Effect"</span>,</span>
<span id="cb1-77">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study Number"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-78">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb1-79"></span>
<span id="cb1-80"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add dyamics to the plot</span></span>
<span id="cb1-81">gg1_anim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> gg1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>  </span>
<span id="cb1-82">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transition_states</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">states =</span> group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-83">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># how points enter</span></span>
<span id="cb1-84">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter_drift</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y_mod =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-85">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter_grow</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-86">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter_fade</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-87">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># how points exit/remain</span></span>
<span id="cb1-88">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exit_fade</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-89">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exit_shrink</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-90">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">shadow_mark</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) </span>
<span id="cb1-91"></span>
<span id="cb1-92">gg1_gif<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">animate</span>(gg1_anim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nframes =</span> nframes, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">duration =</span> duration, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> width, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> height, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">units =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"in"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">res =</span> res)</span>
<span id="cb1-93"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">anim_save</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gg1.gif"</span>)</span>
<span id="cb1-94">gg1_mgif <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">image_read</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gg1.gif"</span>)</span>
<span id="cb1-95"></span>
<span id="cb1-96"></span>
<span id="cb1-97"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## plot 2: histogram</span></span>
<span id="cb1-98"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># start with a ggplot</span></span>
<span id="cb1-99">gg2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(split_animate_data, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> est, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> frame)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-100">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boundary =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-101">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_lines, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> se, </span>
<span id="cb1-102">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(se_)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-103">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_label</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_lines, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> label, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(se_)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-104">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_label</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_lines, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> ch_loc, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> chance, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-105">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#geom_density(linewidth = 2) + </span></span>
<span id="cb1-106">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_rug</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sides =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b"</span>, </span>
<span id="cb1-107">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> est, </span>
<span id="cb1-108">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>((est<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> true_effect)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>se)), </span>
<span id="cb1-109">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, </span>
<span id="cb1-110">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npc"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-111">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-112">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate of Effect"</span>,</span>
<span id="cb1-113">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-114">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb1-115"></span>
<span id="cb1-116"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add dyamics to the plot</span></span>
<span id="cb1-117">gg2_anim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> gg2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>  </span>
<span id="cb1-118">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transition_states</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">states =</span> frame)</span>
<span id="cb1-119"></span>
<span id="cb1-120">gg2_gif<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">animate</span>(gg2_anim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nframes =</span> nframes, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">duration =</span> duration, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> width, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> height, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">units =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"in"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">res =</span> res)</span>
<span id="cb1-121"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">anim_save</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gg2.gif"</span>)</span>
<span id="cb1-122">gg2_mgif <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">image_read</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gg2.gif"</span>)</span>
<span id="cb1-123"></span>
<span id="cb1-124"></span>
<span id="cb1-125"></span>
<span id="cb1-126">new_gif <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">image_append</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(gg1_mgif[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], gg2_mgif[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stack =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb1-127"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span>(i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>nframes){</span>
<span id="cb1-128">  combined_gif <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">image_append</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(gg1_mgif[i], gg2_mgif[i]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stack =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb1-129">  new_gif <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(new_gif, combined_gif)</span>
<span id="cb1-130">}</span>
<span id="cb1-131">new_gif</span></code></pre></div>
</details>
<div class="cell-output-display page-columns page-full">
<div class="page-columns page-full">
<figure class="figure page-columns page-full">
<p class="page-columns page-full"><img src="https://www.carlislerainey.com/blog/2023-06-12-power-3-rule-of-364/index_files/figure-html/unnamed-chunk-1-1.gif" class="img-fluid figure-img column-screen-inset-right"></p>
</figure>
</div>
</div>
</div>
<p>Before the study, we can predict two features of this sampling distribution.</p>
<ol type="1">
<li>First, it will usually have a bell-shaped, normal distribution.</li>
<li>Second, we can predict the standard deviation of this distribution with good accuracy before conducting a single study and excellent accuracy after just one study. We call the standard deviation of the sampling distribution the <strong>standard error</strong> or <strong>SE</strong>.</li>
</ol>
<p>For our purposes, then, we can describe the sampling distribution as normally distributed with an assumed mean and SD. The mean is the assumed true effect and the SD is the well-predicted SE.</p>
<p>This is the key claim: <strong>In order to build power into your experiment, you must build certain properties into the sampling distribution.</strong></p>
<p>The design of your experiment will not affect the normality of the sampling distribution, but it will change the true effect and the SE. Changing the true effect and the SE will change the power.</p>
</section>
<section id="thinking-about-true-effect-and-standard-error-as-targets" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="thinking-about-true-effect-and-standard-error-as-targets">Thinking about True Effect and Standard Error as <em>Targets</em></h2>
<p>I’m leaving aside how to predict the standard error of the experiment or choose the true effect. This post is about the <em>target</em> standard error and true effect.</p>
<p>Predicting the standard error is a mechanical process mixed with a little guesswork.<sup>2</sup> Choose a true effect is a mostly substantive decision.<sup>3</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn2"><p><sup>2</sup>&nbsp;I’ll suggest two methods I like. First, use <img src="https://latex.codecogs.com/png.latex?%5Ctext%7Bpredicted%20SE%7D%20=%20%5Cfrac%7B%5Ctext%7BSD%20of%20same%20outcome%20in%20different%20data%20set%7D%7D%7B0.5%20%5Csqrt%7B%5Ctext%7Bsample%20size%7D%7D%7D">. I like to confirm this estimate with a small pilot. I sample observations from this pilot data set, run the full analysis, and confirm that my prediction is close, and make any needed adjustments.</p></div><div id="fn3"><p><sup>3</sup>&nbsp;<a href="https://twitter.com/cdsamii/status/1661091885580992517?s=20">Cyrus Samii</a> likes to use the MME, I like a conservatively choosen guess of what the effect actually is.</p></div></div><p>But instead of talking about a target power, I like to talk about a target standard error (given a true effect) or a target true effect (given a standard error)—power is just not a very intuitive quantity.</p>
<p>To understand how the true effect and the SE relate to power, we need to introduce the confidence interval.</p>
</section>
<section id="testing-with-confidence-intervals" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="testing-with-confidence-intervals">Testing with Confidence Intervals</h2>
<p>I like to use 90% confidence intervals to test hypotheses (see <a href="http://www.carlislerainey.com/papers/nme.pdf">Rainey 2014</a> and <a href="http://www.carlislerainey.com/papers/meaningful.pdf">Rainey 2015</a>). In short, 90% confidence intervals correspond to one-tailed tests with size 0.05 and equivalence tests with size 0.05.] The formula for a 90% CI is <img src="https://latex.codecogs.com/png.latex?%5Ctext%7Bestimate%7D%20%5Cpm%201.64%5Ctext%7BSE%7D">. That is, we put “arms” around our estimate—one to the left and another to the right. Each arm is 1.64 standard errors long.</p>
<p>I’ll assume we have a one-sided research hypothesis that suggests a positive effect. If the lower bound (<img src="https://latex.codecogs.com/png.latex?%5Ctext%7Bestimate%7D%20-%201.64%5Ctext%7BSE%7D">) is less than zero, then we fail to reject the null hypothesis. If this lower bound is greater than zero, then we reject the null hypothesis.<sup>4</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn4"><p><sup>4</sup>&nbsp;This is equivalent to a <em>z</em>-test in a standard hypothesis testing framework using a <em>p</em>-value of less than 0.05 as the threshold for rejecting the null hypothesis.</p></div></div><p>This focus on <em>testing</em> rather than <em>estimation</em> changes the nature of the sampling distribution. Rather than an estimate along a continuous range, we get a binary outcome: either (1) reject the null hypothesis or (2) fail to reject the null hypothesis.</p>
<p>But the sampling distribution of estimates and the associated outcomes of tests are closely related. In particular, the logic of the test implies that *if the estimate falls less than 1.64 SEs above zero, we cannot reject the null.</p>
<p>We can reconstruct the figure above using this logic. Rather than plot the points continuously along the x-axis, we can color the points (and now error bars) according to whether the lower bound falls above zero or not. And we can use a bar plot showing the number of rejections and non-rejections.</p>
<div class="cell page-columns page-full" data-hash="index_cache/html/unnamed-chunk-2_e00ea8cbe8311700e42c2d417ba3af69">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(gganimate)</span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(magick)</span>
<span id="cb2-4"></span>
<span id="cb2-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># gif pars</span></span>
<span id="cb2-6">duration <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># must be even</span></span>
<span id="cb2-7">fps <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span></span>
<span id="cb2-8">nframes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> duration<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>fps</span>
<span id="cb2-9">scale <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span></span>
<span id="cb2-10">width <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span></span>
<span id="cb2-11">height <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span></span>
<span id="cb2-12">res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">125</span></span>
<span id="cb2-13"></span>
<span id="cb2-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># study parameters</span></span>
<span id="cb2-15">true_effect <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb2-16">se <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span></span>
<span id="cb2-17"></span>
<span id="cb2-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># number of times to repeat the study</span></span>
<span id="cb2-19">n_studies <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># nframes</span></span>
<span id="cb2-20"></span>
<span id="cb2-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># create a data frame of confidence intervals</span></span>
<span id="cb2-22">ests <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">study_id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>n_studies, </span>
<span id="cb2-23">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n_studies, true_effect, se))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reject_null =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No"</span>),</span>
<span id="cb2-25">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwr =</span> est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se,</span>
<span id="cb2-26">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upr =</span> est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se)</span>
<span id="cb2-27"></span>
<span id="cb2-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add two things to the data frame of confidence intervals</span></span>
<span id="cb2-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 1. an initial row with study_id = 1 and est = NA so that </span></span>
<span id="cb2-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#    the plot starts empty (gganimate would start with the </span></span>
<span id="cb2-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#    first observation in place otherwise).</span></span>
<span id="cb2-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 2. a group variable that defines the row. This is the same</span></span>
<span id="cb2-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#    as the study_id, except the dummy row from (1) and the </span></span>
<span id="cb2-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#    actual first row have different groups.</span></span>
<span id="cb2-35">animate_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb2-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">study_id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>),  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># study_id = 1, est = NA</span></span>
<span id="cb2-37">  ests                             <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># actual cis</span></span>
<span id="cb2-38">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()) </span>
<span id="cb2-40"></span>
<span id="cb2-41">split_animate_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> animate_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span>        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># group (row index)</span></span>
<span id="cb2-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">accumulate</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(.x, .y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"frame"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">frame =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(frame))</span>
<span id="cb2-46"></span>
<span id="cb2-47"></span>
<span id="cb2-48">se_lines <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tribble</span>(</span>
<span id="cb2-49">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>se_, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>label, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>chance, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>ch_loc_,  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># trailing _ means not rescaeld to study se</span></span>
<span id="cb2-50">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"True Effect"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,</span>
<span id="cb2-51">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+1 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb2-52">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+2 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>,</span>
<span id="cb2-53">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+3 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>,</span>
<span id="cb2-54">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-1 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb2-55">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-2 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>,</span>
<span id="cb2-56">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-3 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>,</span>
<span id="cb2-57">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-58">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ch_loc =</span> ch_loc_<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> true_effect,</span>
<span id="cb2-59">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> se_<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> true_effect)</span>
<span id="cb2-60"></span>
<span id="cb2-61"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># start with a ggplot</span></span>
<span id="cb2-62">gg1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(animate_data, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> est, </span>
<span id="cb2-63">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> study_id,</span>
<span id="cb2-64">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> group)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-65">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-66">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1.64 SEs"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-67">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbarh</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> lwr, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> upr, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> reject_null)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-68">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> reject_null),</span>
<span id="cb2-69">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-70">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_rug</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sides =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b"</span>, </span>
<span id="cb2-71">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> est, </span>
<span id="cb2-72">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> reject_null), </span>
<span id="cb2-73">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, </span>
<span id="cb2-74">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npc"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-75">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-76">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid.minor.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-77">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate of Effect"</span>,</span>
<span id="cb2-78">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study Number"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-79">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-80">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1b9e77"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d95f02"</span>))</span>
<span id="cb2-81"></span>
<span id="cb2-82"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add dyamics to the plot</span></span>
<span id="cb2-83">gg1_anim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> gg1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>  </span>
<span id="cb2-84">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transition_states</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">states =</span> group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-85">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># how points enter</span></span>
<span id="cb2-86">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter_drift</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y_mod =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-87">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter_grow</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-88">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter_fade</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-89">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># how points exit/remain</span></span>
<span id="cb2-90">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exit_fade</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-91">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exit_shrink</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-92">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">shadow_mark</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) </span>
<span id="cb2-93"></span>
<span id="cb2-94">gg1_gif<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">animate</span>(gg1_anim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nframes =</span> nframes, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">duration =</span> duration, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> width, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> height, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">units =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"in"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">res =</span> res)</span>
<span id="cb2-95"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">anim_save</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gg1.gif"</span>)</span>
<span id="cb2-96">gg1_mgif <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">image_read</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gg1.gif"</span>)</span>
<span id="cb2-97"></span>
<span id="cb2-98"></span>
<span id="cb2-99"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">## plot 2: histogram</span></span>
<span id="cb2-100"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># start with a ggplot</span></span>
<span id="cb2-101">gg2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(split_animate_data, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> reject_null, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> reject_null),  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-102">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-103">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-104">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reject Null"</span>,</span>
<span id="cb2-105">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-106">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-107">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.translate =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-108">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1b9e77"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d95f02"</span>))</span>
<span id="cb2-109"></span>
<span id="cb2-110"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add dyamics to the plot</span></span>
<span id="cb2-111">gg2_anim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> gg2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>  </span>
<span id="cb2-112">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transition_states</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">states =</span> frame)</span>
<span id="cb2-113"></span>
<span id="cb2-114">gg2_gif<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">animate</span>(gg2_anim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nframes =</span> nframes, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">duration =</span> duration, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> width, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> height, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">units =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"in"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">res =</span> res)</span>
<span id="cb2-115"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">anim_save</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gg2.gif"</span>)</span>
<span id="cb2-116">gg2_mgif <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">image_read</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gg2.gif"</span>)</span>
<span id="cb2-117"></span>
<span id="cb2-118"></span>
<span id="cb2-119"></span>
<span id="cb2-120">new_gif <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">image_append</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(gg1_mgif[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], gg2_mgif[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stack =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb2-121"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span>(i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>nframes){</span>
<span id="cb2-122">  combined_gif <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">image_append</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(gg1_mgif[i], gg2_mgif[i]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stack =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb2-123">  new_gif <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(new_gif, combined_gif)</span>
<span id="cb2-124">}</span>
<span id="cb2-125">new_gif</span></code></pre></div>
</details>
<div class="cell-output-display page-columns page-full">
<div class="page-columns page-full">
<figure class="figure page-columns page-full">
<p class="page-columns page-full"><img src="https://www.carlislerainey.com/blog/2023-06-12-power-3-rule-of-364/index_files/figure-html/unnamed-chunk-2-1.gif" class="img-fluid figure-img column-screen-inset-right"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="the-key-ratio" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="the-key-ratio">The Key Ratio</h2>
<p>The key to building statistical power into your experiment is to get “almost all” of the sampling distribution above 1.64 standard errors above zero. The portion of the sampling distribution that falls below 1.64 standard errors above zero does not allow the researcher to reject the null.</p>
<div class="cell page-columns page-full" data-hash="index_cache/html/unnamed-chunk-3_ae148b7ae499c1f0d3d536545760eb36">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb3-2"></span>
<span id="cb3-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># study parameters</span></span>
<span id="cb3-4">true_effect <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb3-5">se <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span></span>
<span id="cb3-6"></span>
<span id="cb3-7"></span>
<span id="cb3-8">se_lines <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tribble</span>(</span>
<span id="cb3-9">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>se_, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>label, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>chance, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>ch_loc_,  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># trailing _ means not rescaeld to study se</span></span>
<span id="cb3-10">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"True Effect"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,</span>
<span id="cb3-11">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+1 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb3-12">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+2 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>,</span>
<span id="cb3-13">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+3 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>,</span>
<span id="cb3-14">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-1 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb3-15">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-2 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>,</span>
<span id="cb3-16">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-3 SE"</span>, scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>,</span>
<span id="cb3-17">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ch_loc =</span> ch_loc_<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> true_effect,</span>
<span id="cb3-19">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> se_<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> true_effect) </span>
<span id="cb3-20"></span>
<span id="cb3-21">x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se)</span>
<span id="cb3-22">df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(x)</span>
<span id="cb3-23"></span>
<span id="cb3-24">bg_alpha <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span></span>
<span id="cb3-25"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df, </span>
<span id="cb3-27">                 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">after_stat</span>(density)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boundary =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> bg_alpha) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_lines, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> se, </span>
<span id="cb3-29">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(se_)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> bg_alpha) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_label</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_lines, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> label, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alpha</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'black'</span>, bg_alpha)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_label</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_lines, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> ch_loc, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> chance, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alpha</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'black'</span>, bg_alpha)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dnorm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate of Effect"</span>,</span>
<span id="cb3-36">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_area</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x), </span>
<span id="cb3-38">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"function"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dnorm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se),</span>
<span id="cb3-39">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d95f02"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> true_effect)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fraction rejected"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d95f02"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"segment"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xend =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yend =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1b9e77"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1.64 SEs above zero"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1b9e77"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"segment"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xend =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, </span>
<span id="cb3-44">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se), </span>
<span id="cb3-45">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yend =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se), </span>
<span id="cb3-46">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#7570b3"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-47">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"width of 90% CI"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#7570b3"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div>
</details>
<div class="cell-output-display page-columns page-full">
<div class="page-columns page-full">
<figure class="figure page-columns page-full">
<p class="page-columns page-full"><img src="https://www.carlislerainey.com/blog/2023-06-12-power-3-rule-of-364/index_files/figure-html/unnamed-chunk-3-1.png" class="img-fluid figure-img column-screen-inset-right" width="960"></p>
</figure>
</div>
</div>
</div>
<p>You’ll remember that “almost all” of the normal distribution falls within two standard errors of its mean. So as a starting point, let’s use this rule: get the sampling distribution two standard errors above 1.64 standard errors above zero. We can just add 1.64 and 2 together to get a sampling distribution 3.64 standard errors above zero. That is, we need <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctext%7Btrue%20effect%7D%7D%7B%5Ctext%7Bstandard%20error%7D%7D%20%3E%203.64">. If the true effect is larger than 3.64 standard errors, then the confidence interval will “rarely” overlap zero (about 2% of the time).</p>
<div class="cell page-columns page-full" data-hash="index_cache/html/unnamed-chunk-4_a91efc73b8d2befdc4dcd25504202cf9">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb4-2"></span>
<span id="cb4-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># study parameters</span></span>
<span id="cb4-4">true_effect <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb4-5">se <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.84</span></span>
<span id="cb4-6"></span>
<span id="cb4-7">x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se)</span>
<span id="cb4-8">df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(x)</span>
<span id="cb4-9"></span>
<span id="cb4-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df, </span>
<span id="cb4-12">                 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">after_stat</span>(density)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boundary =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> bg_alpha) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_lines, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> se, </span>
<span id="cb4-14">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(se_)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> bg_alpha) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_label</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_lines, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> label, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alpha</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'black'</span>, bg_alpha)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_label</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_lines, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> ch_loc, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> chance, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alpha</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'black'</span>, bg_alpha)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dnorm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate of Effect"</span>,</span>
<span id="cb4-21">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_area</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x), </span>
<span id="cb4-23">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"function"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dnorm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se),</span>
<span id="cb4-24">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d95f02"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> true_effect)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-25">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#annotate("label", x = 1.3, y = .1, label = "fraction rejected", color = "#d95f02", size = 6) +</span></span>
<span id="cb4-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"segment"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xend =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yend =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d95f02"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"true effect"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d95f02"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>   </span>
<span id="cb4-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"segment"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xend =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yend =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1b9e77"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1.64 SEs above zero"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1b9e77"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"segment"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xend =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, </span>
<span id="cb4-31">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">125</span>, </span>
<span id="cb4-32">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yend =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">125</span>, </span>
<span id="cb4-33">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#7570b3"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb4-34">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lineend =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"round"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linejoin =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"round"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">arrow =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrow</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"inches"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ends =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"both"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">125</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1.64 SEs"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#7570b3"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"segment"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xend =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, </span>
<span id="cb4-37">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">125</span>, </span>
<span id="cb4-38">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yend =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">125</span>, </span>
<span id="cb4-39">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb4-40">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lineend =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"round"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linejoin =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"round"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">arrow =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrow</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"inches"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ends =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"both"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (true_effect <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">125</span></span>
<span id="cb4-42">  </span>
<span id="cb4-43">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ideally 2 SEs"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"segment"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xend =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, </span>
<span id="cb4-45">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yend =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, </span>
<span id="cb4-46">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb4-47">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lineend =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"round"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linejoin =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"round"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">arrow =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrow</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"inches"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ends =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"both"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-48">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> true_effect<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ideally 3.64 SEs"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.0</span>)</span></code></pre></div>
</details>
<div class="cell-output-display page-columns page-full">
<div class="page-columns page-full">
<figure class="figure page-columns page-full">
<p class="page-columns page-full"><img src="https://www.carlislerainey.com/blog/2023-06-12-power-3-rule-of-364/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img column-screen-inset-right" width="960"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="the-resulting-guidelines" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="the-resulting-guidelines">The Resulting Guidelines</h2>
<p>There are a few ways to write the ratio:</p>
<ol type="1">
<li><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctext%7Btrue%20effect%7D%7D%7B%5Ctext%7Bstandard%20error%7D%7D%20%3E%203.64"></li>
<li><img src="https://latex.codecogs.com/png.latex?%5Ctext%7Btrue%20effect%7D%20%3E%203.64%20%5Ctimes%20%5Ctext%7Bstandard%20error%7D"></li>
<li><img src="https://latex.codecogs.com/png.latex?%5Ctext%7Bstandard%20error%7D%20%3C%20%5Cfrac%7B1%7D%7B3.64%7D%20%5Ctimes%20%5Ctext%7Btrue%20effect%7D%20%5Capprox%200.27%20%5Ctimes%20%5Ctext%7Btrue%20effect%7D"></li>
</ol>
<p>These are all the same goals. I prefer the first, but they are all equivalent targets for power.</p>
<p>I like this ratio because it points to <em>strategies</em> to increase power. You can do two things:</p>
<ol type="1">
<li>Increase the true effect.</li>
<li>Decrease the standard error.</li>
</ol>
<p>This ratio gets you thinking not <em>what</em> your power is, but <em>how to increase it</em>. Again, power isn’t <em>a</em> task for the experimenter, it’s <em>the</em> task.<sup>5</sup> <a href="https://doi.org/10.33774/apsa-2023-h4p0q-v2">Kane (2023)</a><sup>6</sup> suggests several ways researchers can increase the true effect or decrease the standard error.</p>
<div class="no-row-height column-margin column-container"><div id="fn5"><p><sup>5</sup>&nbsp;I’m leaving aside the question of how to predict the standard error or choose a true effect for a paricular design.</p></div><div id="fn6"><p><sup>6</sup>&nbsp;Kane, John V. 2023. “More Than Meets the ITT: A Guide for Investigating Null Results.” APSA Preprints. <a href="https://doi.org/10.33774/apsa-2023-h4p0q-v2">doi: 10.33774/apsa-2023-h4p0q-v2</a>.</p></div></div><p>I’ll highlight a few examples here. To increase the treatment effect, you can:</p>
<ol type="1">
<li>Increase attentiveness.</li>
<li>Ensure that respondents are not pre-treated.</li>
<li>Write strong treatments or “hit them between the eyes” <a href="https://www.jstor.org/stable/2647960">(Kuklinski <em>et al.</em> 2000)</a>.</li>
</ol>
<p>To decrease the standard error, you can:</p>
<ol type="1">
<li>Increase the sample size.</li>
<li>Use multiple measurements for the outcome.</li>
<li>Use a pre-post design <a href="https://doi.org/10.1017/S0003055421000241">(Clifford, Sheagley, and Piston 2022)</a>.</li>
</ol>
</section>
<section id="implication" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="implication">Implication</h2>
<p>If you get the ratio to 3.64, then you’ll have 98%. This is much higher than the cutoff of 80% I hear suggested most often. If you want 80% power, rather than 98% power, you can change the 3.64 to 2.48.<sup>7</sup> But notice that 3.64 and 2.48 are not very different. This has an important implication.</p>
<div class="no-row-height column-margin column-container"><div id="fn7"><p><sup>7</sup>&nbsp;Find this by adding 1.64 to <code>-qnorm(0.2)</code>.</p></div></div><p>A researcher can lower the risk of a failed study from about 1 in 5 (80% power) to about 1 in 50 (98% power) by increasing the ratio from 2.48 to 3.64. This requires increasing the treatment effect by about 50% or shrinking the standard error by about 33%. Stated differently, if you are careless and let your treatment effect fall by 33% or let your standard error increase by 50%, then your risk of a failed study increases 10-fold! Small differences can matter a lot.</p>
<p>The implication is this: when you are on the cusp of a well-powered study (about 80% power), then small increases in the ratio have a disproportionate impact on your risk of a failed study.</p>
</section>
<section id="computing-power-from-the-ratio" class="level2">
<h2 class="anchored" data-anchor-id="computing-power-from-the-ratio">Computing Power from the Ratio</h2>
<p>Following the logic of the picture above, we need to compute the fraction of the sampling distributin that lies above 1.64 SEs. The <code>pnorm()</code> function returns normal probabilities, but <em>below</em> specfic thresholds. By supplying the argument <code>lower.tail = FALSE</code>, we can get the probabilities of falling <em>above</em> a specific threshold.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_d9afb3bbe1456ba18f58ca7b98720c3e">
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">true_effect <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.00</span></span>
<span id="cb5-2">se <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span></span>
<span id="cb5-3"></span>
<span id="cb5-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute power</span></span>
<span id="cb5-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se,   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># want fraction above 1.64 SE</span></span>
<span id="cb5-6">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect,  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># mean of sampling distribution</span></span>
<span id="cb5-7">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se,  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># sd of sampling distribution</span></span>
<span id="cb5-8">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower.tail =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fraction above, not below</span></span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.8051055</code></pre>
</div>
</div>
</section>
<section id="summary" class="level2">
<h2 class="anchored" data-anchor-id="summary">Summary</h2>
<p>Statistical power is an abstract quantity. It’s easy to understand what it means, but harder to think about how to manipulate it. I explain why the target <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctext%7Btrue%20effect%7D%7D%7B%5Ctext%7Bstandard%20error%7D%7D%20%3E%202.48"> is equivalent to a target power of 80%. But you want to “almost always” reject the null, so you should shoot for <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Ctext%7Btrue%20effect%7D%7D%7B%5Ctext%7Bstandard%20error%7D%7D%20%3E%203.64">. Hopefully these guidelines help you build a bit of actionable intuition about statistical power.</p>


</section>


 ]]></description>
  <category>statistical power</category>
  <category>hypothesis tests</category>
  <category>power analysis</category>
  <category>methodology</category>
  <category>confidence intervals</category>
  <category>computing</category>
  <category>R</category>
  <guid>https://www.carlislerainey.com/blog/2023-06-12-power-3-rule-of-364/</guid>
  <pubDate>Mon, 12 Jun 2023 04:00:00 GMT</pubDate>
  <media:content url="https://www.carlislerainey.com/blog/2023-06-12-power-3-rule-of-364/twitter-card.png" medium="image" type="image/png" height="72" width="144"/>
</item>
<item>
  <title>Teaching Confidence Intervals and Hypothesis Testing with gganimate</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2023-06-01-teaching-confidence-intervals-with-gganimate/</link>
  <description><![CDATA[ 




<section id="background" class="level2">
<h2 class="anchored" data-anchor-id="background">Background</h2>
<p>When I give students formula for confidence intervals, I find that students don’t have a sharp concept of how those confidence intervals work—even if I explain the <em>components</em> of the formula well.</p>
<p>Even though they understand—seemingly very well—that the point estimate is noisy, they struggle to conceptualize that a confidence interval can often include values on the incorrect side of zero. Stated differently, they have a hard time understanding how a hypothesis test can fail to reject the null (when the null is incorrect). Their intuition suggests that a “test” should give you the correct answer.</p>
<p>Because their instincts are wrong, I want to undermine their trust in hypothesis tests. I want them to <em>feel</em> the riskiness of poorly-powered experiments that <a href="../../blog/2023-05-25-power-2-what-do-confidence-intervals-look-like">consistently nestle confidence intervals right up against zero</a>. I want them ready and eager to work hard to avoid that risk—to make sure they have adequate statistical power.</p>
<p>To help undermine their confidence in confidence intervals, I like three exercises that mimic a test with 80% power. In each case, we are assuming that we have formulated a correct hypothesis and designed an excellent experiment with 80% power.</p>
<ol type="1">
<li>First, I have students roll a six-sided die. If the die produces a <i class="bi bi-dice-6"></i>, then their study fails—they wasted their opportunity. See <a href="../../blog/2023-05-22-power-1-for-you-not-reviewer-2">this post</a> for details on this perspective. This simulates the riskiness of an experiment with 80% power quite well. They get lots of failed experiments in a short period of time. They become well-aware of the possibility of a failed study and grow increasingly interested in reducing this risk.</li>
<li>Second, I use a computer to produce a plot of many (about 50 seems right) confidence intervals from the same repeated study. I explain that the interval we will get in the study we actually conduct is like a random draw from this collection. (See below for an example of this figure.)</li>
<li>Third, I make the plot <em>dynamic</em>. I find that dynamics make the plot more memorable and convey the (appropriate) idea that hypothesis tests and confidence intervals are chaotic, noisy quantities.</li>
</ol>
<p>These exercises make it clear that failed studies are real possibilities. Hopefully they clearly see and “feel”:</p>
<blockquote class="blockquote">
<p>The hypothesis test is no oracle. It will not consistently reject the null (even when the null is wrong) unless you supply overwhelming evidence. In experimental design, that’s not a task, that’s the task.</p>
</blockquote>
<p>Below, I walk through the plots I use in parts 2 and 3.</p>
</section>
<section id="an-experiment-that-we-can-repeat" class="level2">
<h2 class="anchored" data-anchor-id="an-experiment-that-we-can-repeat">An Experiment that We Can Repeat</h2>
<p>First, let’s choose to conduct an experiment with 80% power. To get this, we’ll suppose that the true effect is 1 and the standard error is 0.4. To obtain 80% power, you can use the guideline that the standard error should be about 40% of the true effect (or the true effect divided by 2.48). I’ll show where these guidelines come from in a future post. With the true effect and standard error in hand, we can compute the long-run properties of the experiment.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-1_1a67a411c4cbb8a37b283565094b0331">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># study parameters</span></span>
<span id="cb1-4">true_effect <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb1-5">se <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.40</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 1/2.48</span></span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># identify effects of interest</span></span>
<span id="cb1-8">eoi <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tribble</span>(</span>
<span id="cb1-9">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Effect, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Description,</span>
<span id="cb1-10">  true_effect, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"True Effect (known in this exercise)"</span></span>
<span id="cb1-11">) </span>
<span id="cb1-12"></span>
<span id="cb1-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute quantities of interest regarding power</span></span>
<span id="cb1-14">eoi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Power =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, Effect, se),</span>
<span id="cb1-16">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Power =</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(Power, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb1-17">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type S</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> retrodesign<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">type_s</span>(Effect, se)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>type_s,</span>
<span id="cb1-18">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type S</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">number</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type S</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>),</span>
<span id="cb1-19">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type M</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> retrodesign<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">type_m</span>(Effect, se)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>type_m,</span>
<span id="cb1-20">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type M</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">number</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type M</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>),</span>
<span id="cb1-21">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Effect =</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">number</span>(Effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cols =</span> Effect<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type M</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-23">  kableExtra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"markdown"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)</span></code></pre></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<tbody>
<tr class="odd">
<td style="text-align: left;">Effect</td>
<td style="text-align: left;">1.00</td>
</tr>
<tr class="even">
<td style="text-align: left;">Description</td>
<td style="text-align: left;">True Effect (known in this exercise)</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Power</td>
<td style="text-align: left;">81%</td>
</tr>
<tr class="even">
<td style="text-align: left;">Type S</td>
<td style="text-align: left;">0.00</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Type M</td>
<td style="text-align: left;">1.20</td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
<section id="a-static-plot" class="level2">
<h2 class="anchored" data-anchor-id="a-static-plot">A Static Plot</h2>
<p>But these long-run properties remain a bit abstract and seem “distant” from the practical implications of our <em>particular</em> experiment. This is where the three exercises above come in handy.</p>
<p>The second exercise is a static plot. The plot shows 50 intervals; we can see that several include zero. These are wasted opporunities. We set out to reject a null hypothesis that the effect was less than or equal to zero, and we failed to do that.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-2_78347fc1f4c6c4bd4803caf03747ec05">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># number of studies to simulate</span></span>
<span id="cb2-2">n_studies <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span></span>
<span id="cb2-3"></span>
<span id="cb2-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># a data frame of studies </span></span>
<span id="cb2-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">123</span>)</span>
<span id="cb2-6">ests <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">study_id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>n_studies,</span>
<span id="cb2-7">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n_studies, true_effect, se))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reject_null =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No"</span>)) </span>
<span id="cb2-9"></span>
<span id="cb2-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plot the confidence intervals for each study</span></span>
<span id="cb2-11">gg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(ests, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> est, </span>
<span id="cb2-12">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> study_id, </span>
<span id="cb2-13">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, </span>
<span id="cb2-14">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, </span>
<span id="cb2-15">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> reject_null)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> true_effect, </span>
<span id="cb2-17">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dotted"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbarh</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_rug</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sides =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b"</span>, </span>
<span id="cb2-22">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>), </span>
<span id="cb2-23">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, </span>
<span id="cb2-24">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npc"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d95f02"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1b9e77"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># from https://colorbrewer2.org/#type=qualitative&amp;scheme=Dark2&amp;n=3</span></span>
<span id="cb2-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-27">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb2-28">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb2-29">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb2-30">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate and 90% Confidence Interval"</span>,</span>
<span id="cb2-32">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study ID"</span>, </span>
<span id="cb2-33">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reject Null?"</span>, </span>
<span id="cb2-34">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rug shows distribution of lower bound of confidence interval."</span>) </span>
<span id="cb2-35"></span>
<span id="cb2-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># print plot</span></span>
<span id="cb2-37"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(gg)</span></code></pre></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2023-06-01-teaching-confidence-intervals-with-gganimate/index_files/figure-html/unnamed-chunk-2-1.png" class="img-fluid figure-img" width="576"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="dynamic-plot" class="level2">
<h2 class="anchored" data-anchor-id="dynamic-plot">Dynamic Plot</h2>
<p>The static plot above is nice, but doesn’t convey an appropriate sense of randomness or “you don’t know what you’ll get this time.” To convey this feeling, I like to add dynamics. In particular, I like a confidence interval that’s moving and you’re not sure if it will cover zero or not. This conveys the sense that “something bad might happen” with each draw. Even though only about 10 of the 50 confidence intervals will cross zero, you feel the danger on all 50 simulations.</p>
<p>In designing this plot, two features are in tension:</p>
<ol type="1">
<li>The plot conveys the ideas.</li>
<li>The code is easy to update and understand.</li>
</ol>
<p>In the past, I’ve prioritized making the plot look <em>exactly</em> like I want. But there are concrete downsides to using hacky solutions—using functions in ways not intended. The code is brittle and difficult. For examples that clearly convey the ideas, see <a href="https://presidential-plinko.com">Presidential Plinko</a> and this <a href="https://stackoverflow.com/questions/61446108/animated-dot-histogram-built-observation-by-observation-using-gganimate-in-r">“raindrop” plot</a>. These are great ways to convey the randomness, but producing these plots requires some “tedious” coding.</p>
<p>With this code, I tried to illustrate the concept well while avoid hacky solutions to minor problems. This makes the code easier to understand, change, and update.</p>
<p>First, let’s start by creating the data frame to plot. We need to make two small changes to the data frame above. These are both hacks, but worth it.</p>
<ol type="1">
<li>Add a dummy row to the data frame to trick gganimate into starting with an empty plot.</li>
<li>Add a grouping variable to indicate the states for the transitions. This is simply a row ID variable.</li>
</ol>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-3_9b63ee8ce76ffb30d27f3e7b36871be3">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># load packages</span></span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(gganimate)</span>
<span id="cb3-3"></span>
<span id="cb3-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add two things to the data frame of confidence intervals</span></span>
<span id="cb3-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 1. an initial row with study_id = 1 and est = NA so that </span></span>
<span id="cb3-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#    the plot starts empty (gganimate would start with the </span></span>
<span id="cb3-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#    first observation in place otherwise).</span></span>
<span id="cb3-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 2. a group variable that defines the row. This is the same</span></span>
<span id="cb3-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#    as the study_id, except the dummy row from (1) and the </span></span>
<span id="cb3-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#    actual first row have different groups.</span></span>
<span id="cb3-11">animate_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb3-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">study_id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>),  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># study_id = 1, est = NA</span></span>
<span id="cb3-13">  ests                             <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># combine dummy row with ests data frame from above</span></span>
<span id="cb3-14">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>())            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># group (row index)</span></span></code></pre></div>
</details>
</div>
<p>Now let’s plot the confidence intervals much like above, except with expanded scales to give some more room for movement.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-4_bccf09b3a4e33d5f2ca2fc0b58d685fc">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="annotated-cell-4" style="background: #f1f3f5;"><pre class="sourceCode r code-annotation-code code-with-copy code-annotated"><code class="sourceCode r"><span id="annotated-cell-4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># same ggplot, except three annotated changes</span></span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-4" data-target-annotation="1">1</button><span id="annotated-cell-4-2" class="code-annotation-target">gg_exp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(animate_data, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> est,</span>
<span id="annotated-cell-4-3">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> study_id, </span>
<span id="annotated-cell-4-4">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, </span>
<span id="annotated-cell-4-5">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, </span>
<span id="annotated-cell-4-6">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> reject_null, </span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-4" data-target-annotation="2">2</button><span id="annotated-cell-4-7" class="code-annotation-target">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> group)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> true_effect, </span>
<span id="annotated-cell-4-9">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dotted"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-4-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-4-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-4-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbarh</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-4-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_rug</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sides =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b"</span>, </span>
<span id="annotated-cell-4-14">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>), </span>
<span id="annotated-cell-4-15">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, </span>
<span id="annotated-cell-4-16">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npc"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-4-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d95f02"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1b9e77"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>  </span>
<span id="annotated-cell-4-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-4-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="annotated-cell-4-20">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="annotated-cell-4-21">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="annotated-cell-4-22">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-4-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate and 90% Confidence Interval"</span>,</span>
<span id="annotated-cell-4-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study ID"</span>, </span>
<span id="annotated-cell-4-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reject Null?"</span>, </span>
<span id="annotated-cell-4-26">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rug shows distribution of lower bound of confidence interval.</span></span>
<span id="annotated-cell-4-27"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                  Solid lines shows zero.</span></span>
<span id="annotated-cell-4-28"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                  Dotted line shows the true effect."</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-4-29">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># new scales here</span></span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-4" data-target-annotation="3">3</button><span id="annotated-cell-4-30" class="code-annotation-target">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">add =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-4-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">add =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="annotated-cell-4-32">  </span>
<span id="annotated-cell-4-33"></span>
<span id="annotated-cell-4-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># print plot</span></span>
<span id="annotated-cell-4-35"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(gg_exp)</span><div class="code-annotation-gutter-bg"></div><div class="code-annotation-gutter"></div></code></pre></div>
</details>
<div class="cell-annotation">
<dl class="code-annotation-container-hidden code-annotation-container-grid">
<dt data-target-cell="annotated-cell-4" data-target-annotation="1">1</dt>
<dd>
<span data-code-cell="annotated-cell-4" data-code-lines="2" data-code-annotation="1">Use dataset with <code>group</code> variable.</span>
</dd>
<dt data-target-cell="annotated-cell-4" data-target-annotation="2">2</dt>
<dd>
<span data-code-cell="annotated-cell-4" data-code-lines="7" data-code-annotation="2">Set <code>group</code> explicitly.</span>
</dd>
<dt data-target-cell="annotated-cell-4" data-target-annotation="3">3</dt>
<dd>
<span data-code-cell="annotated-cell-4" data-code-lines="30,31" data-code-annotation="3">Expand x- and y-axis.</span>
</dd>
</dl>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2023-06-01-teaching-confidence-intervals-with-gganimate/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="576"></p>
</figure>
</div>
</div>
</div>
<p>Now let’s add the animation. I like the confidence intervals to be shooting toward zero. This gives the feeling that “it might cross!” and makes the fear of a failed study real for each simulation.</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-5_d6c5af01fb5dc06ee35cd4102c0f497e">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="annotated-cell-5" style="background: #f1f3f5;"><pre class="sourceCode r code-annotation-code code-with-copy code-annotated"><code class="sourceCode r"><span id="annotated-cell-5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add dyamics to the plot</span></span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-5" data-target-annotation="1">1</button><span id="annotated-cell-5-2" class="code-annotation-target">anim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> gg_exp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-5" data-target-annotation="2">2</button><span id="annotated-cell-5-3" class="code-annotation-target">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transition_states</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">states =</span> group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-5-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># how points enter</span></span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-5" data-target-annotation="3">3</button><span id="annotated-cell-5-5" class="code-annotation-target">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter_drift</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x_mod =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-5" data-target-annotation="4">4</button><span id="annotated-cell-5-6" class="code-annotation-target">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter_grow</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-5" data-target-annotation="5">5</button><span id="annotated-cell-5-7" class="code-annotation-target">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter_recolor</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-5" data-target-annotation="6">6</button><span id="annotated-cell-5-8" class="code-annotation-target">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ease_aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"exponential-in"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-5-9">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># how points exit/remain</span></span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-5" data-target-annotation="7">7</button><span id="annotated-cell-5-10" class="code-annotation-target">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exit_fade</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<button class="code-annotation-anchor" data-target-cell="annotated-cell-5" data-target-annotation="8">8</button><span id="annotated-cell-5-11" class="code-annotation-target">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">shadow_mark</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>)</span>
<span id="annotated-cell-5-12"></span>
<span id="annotated-cell-5-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># make magic happen!</span></span>
<span id="annotated-cell-5-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">animate</span>(anim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">duration =</span> n_studies, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, </span>
<span id="annotated-cell-5-15">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">units =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"in"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">res =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">150</span>)</span><div class="code-annotation-gutter-bg"></div><div class="code-annotation-gutter"></div></code></pre></div>
</details>
<div class="cell-annotation">
<dl class="code-annotation-container-hidden code-annotation-container-grid">
<dt data-target-cell="annotated-cell-5" data-target-annotation="1">1</dt>
<dd>
<span data-code-cell="annotated-cell-5" data-code-lines="2" data-code-annotation="1">‘gg’ is created earlier. It’s the plot we want to make dynamic.</span>
</dd>
<dt data-target-cell="annotated-cell-5" data-target-annotation="2">2</dt>
<dd>
<span data-code-cell="annotated-cell-5" data-code-lines="3" data-code-annotation="2">The <code>transition_states()</code> function from gganimate creates an animation transitioning between different states of the data. In this case, the argument <code>states</code> is set to <code>group</code>. This makes each <code>group</code> (each row in the data frame <code>animate_data</code>) appear in the plot, one at a time.</span>
</dd>
<dt data-target-cell="annotated-cell-5" data-target-annotation="3">3</dt>
<dd>
<span data-code-cell="annotated-cell-5" data-code-lines="5" data-code-annotation="3">The <code>enter_drift()</code> function describes how new data points enter the frame. <code>x_mod = 2</code> makes new data enter by drifting along the x-axis 2 points from the right of their ending position.</span>
</dd>
<dt data-target-cell="annotated-cell-5" data-target-annotation="4">4</dt>
<dd>
<span data-code-cell="annotated-cell-5" data-code-lines="6" data-code-annotation="4">The <code>enter_grow()</code> function describes how new data points enter the frame. In this case, it makes them will grow from a size of 0 to their ending size.</span>
</dd>
<dt data-target-cell="annotated-cell-5" data-target-annotation="5">5</dt>
<dd>
<span data-code-cell="annotated-cell-5" data-code-lines="7" data-code-annotation="5">The <code>enter_recolor()</code> function again describes how new data points should enter the frame. Here, it makes the points and CIs change the color from black to their ending color as they appear. I want the final color to be a bit of a surprise, so I start them as black.</span>
</dd>
<dt data-target-cell="annotated-cell-5" data-target-annotation="6">6</dt>
<dd>
<span data-code-cell="annotated-cell-5" data-code-lines="8" data-code-annotation="6">The <code>ease_aes()</code> function determines how the aesthetics of the points change over the transitions. <code>color = "exponential-in"</code> means the color change will be at an exponential rate at the start of the transition. This makes the color change really fast at the end of the transition to maintain the surprise of the result.</span>
</dd>
<dt data-target-cell="annotated-cell-5" data-target-annotation="7">7</dt>
<dd>
<span data-code-cell="annotated-cell-5" data-code-lines="10" data-code-annotation="7">The <code>exit_fade()</code> function describes how data points leave the frame. <code>alpha = 0.3</code> specifies that points will fade out to 30% transparency when they exit (when the next data point reaches its position).</span>
</dd>
<dt data-target-cell="annotated-cell-5" data-target-annotation="8">8</dt>
<dd>
<span data-code-cell="annotated-cell-5" data-code-lines="11" data-code-annotation="8"><code>shadow_mark()</code> function keeps past data points in the frame. <code>alpha = 0.3</code> sets the transparency of the shadow marks to 30% to match the <code>exit_fade()</code> transparency.</span>
</dd>
</dl>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2023-06-01-teaching-confidence-intervals-with-gganimate/index_files/figure-html/unnamed-chunk-5-1.gif" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="summary" class="level2">
<h2 class="anchored" data-anchor-id="summary">Summary</h2>
<p>The dynamic plot above is a good tool to help students understand that confidence intervals can quite easily include values on the wrong side of zero. Stated differently, it’s easy for a hypothesis test to fail to reject the null (when the null is wrong). Their intuition suggests that the test should tell you the correct answer.</p>
<p>The exercises above (appropriately) undermine their trust in hypothesis tests. I want them to feel the riskiness of poorly-powered experiments that <a href="../../blog/2023-05-25-power-2-what-do-confidence-intervals-look-like">consistently nestle confidence intervals right up against zero</a>. I want them ready to work hard to avoid that risk—to make sure they have statistical power. Hopefully, they see that carefully building power into your experiment isn’t <em>a</em> task, it’s <em>the</em> task of experimental design.</p>
<p>As a concluding example, here’s the same dynamic plot for a study with about 98% power. Notice how “safe” this study feels compared to the one above with 80% power. I think this plot does a good job a translating probabilities into an appropriate sense of “danger.”</p>
<div class="cell" data-hash="index_cache/html/unnamed-chunk-7_91c6c7359ff86daa6cc9a60562fe8217">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="annotated-cell-6" style="background: #f1f3f5;"><pre class="sourceCode r code-annotation-code code-with-copy"><code class="sourceCode r"><span id="annotated-cell-6-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># study parameters</span></span>
<span id="annotated-cell-6-2">se <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.27</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 1/3.64</span></span>
<span id="annotated-cell-6-3"></span>
<span id="annotated-cell-6-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># identify effects of interest</span></span>
<span id="annotated-cell-6-5">eoi <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tribble</span>(</span>
<span id="annotated-cell-6-6">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Effect, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Description,</span>
<span id="annotated-cell-6-7">  true_effect, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"True Effect (known in this exercise)"</span></span>
<span id="annotated-cell-6-8">) </span>
<span id="annotated-cell-6-9"></span>
<span id="annotated-cell-6-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute quantities of interest regarding power</span></span>
<span id="annotated-cell-6-11">eoi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="annotated-cell-6-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Power =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, Effect, se),</span>
<span id="annotated-cell-6-13">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Power =</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(Power, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="annotated-cell-6-14">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type S</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> retrodesign<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">type_s</span>(Effect, se)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>type_s,</span>
<span id="annotated-cell-6-15">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type S</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">number</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type S</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>),</span>
<span id="annotated-cell-6-16">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type M</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> retrodesign<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">type_m</span>(Effect, se)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>type_m,</span>
<span id="annotated-cell-6-17">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type M</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">number</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type M</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>),</span>
<span id="annotated-cell-6-18">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Effect =</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">number</span>(Effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="annotated-cell-6-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cols =</span> Effect<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type M</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="annotated-cell-6-20">  kableExtra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"markdown"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)</span>
<span id="annotated-cell-6-21"></span>
<span id="annotated-cell-6-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># a data frame of studies </span></span>
<span id="annotated-cell-6-23">ests <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">study_id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>n_studies,</span>
<span id="annotated-cell-6-24">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n_studies, true_effect, se))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="annotated-cell-6-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reject_null =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No"</span>)) </span>
<span id="annotated-cell-6-26"></span>
<span id="annotated-cell-6-27">animate_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="annotated-cell-6-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">study_id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>),  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># study_id = 1, est = NA</span></span>
<span id="annotated-cell-6-29">  ests                             <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># combine dummy row with ests data frame from above</span></span>
<span id="annotated-cell-6-30">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="annotated-cell-6-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>())            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># group (row index)</span></span>
<span id="annotated-cell-6-32"></span>
<span id="annotated-cell-6-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># same ggplot, except three annotated changes</span></span>
<span id="annotated-cell-6-34">gg_exp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(animate_data, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> est,</span>
<span id="annotated-cell-6-35">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> study_id, </span>
<span id="annotated-cell-6-36">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, </span>
<span id="annotated-cell-6-37">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, </span>
<span id="annotated-cell-6-38">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> reject_null, </span>
<span id="annotated-cell-6-39">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> group)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-6-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> true_effect, </span>
<span id="annotated-cell-6-41">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dotted"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-6-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-6-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-6-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbarh</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-6-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_rug</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sides =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b"</span>, </span>
<span id="annotated-cell-6-46">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>), </span>
<span id="annotated-cell-6-47">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, </span>
<span id="annotated-cell-6-48">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"npc"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-6-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d95f02"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yes"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1b9e77"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>  </span>
<span id="annotated-cell-6-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-6-51">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">panel.grid =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="annotated-cell-6-52">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="annotated-cell-6-53">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="annotated-cell-6-54">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-6-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate and 90% Confidence Interval"</span>,</span>
<span id="annotated-cell-6-56">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study ID"</span>, </span>
<span id="annotated-cell-6-57">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reject Null?"</span>, </span>
<span id="annotated-cell-6-58">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rug shows distribution of lower bound of confidence interval.</span></span>
<span id="annotated-cell-6-59"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                  Solid line shows zero.</span></span>
<span id="annotated-cell-6-60"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                  Dotted line shows the true effect."</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="annotated-cell-6-61">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># new scales here</span></span>
<span id="annotated-cell-6-62">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">add =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-6-63">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">add =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="annotated-cell-6-64"></span>
<span id="annotated-cell-6-65"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add dyamics to the plot</span></span>
<span id="annotated-cell-6-66">anim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> gg_exp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-6-67">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transition_states</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">states =</span> group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-6-68">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># how points enter</span></span>
<span id="annotated-cell-6-69">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter_drift</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x_mod =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-6-70">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter_grow</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-6-71">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter_recolor</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-6-72">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ease_aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"exponential-in"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-6-73">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># how points exit/remain</span></span>
<span id="annotated-cell-6-74">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exit_fade</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="annotated-cell-6-75">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">shadow_mark</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>)</span>
<span id="annotated-cell-6-76"></span>
<span id="annotated-cell-6-77"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># make magic happen!</span></span>
<span id="annotated-cell-6-78"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">animate</span>(anim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">duration =</span> n_studies, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, </span>
<span id="annotated-cell-6-79">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">units =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"in"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">res =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">150</span>)</span></code></pre></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<tbody>
<tr class="odd">
<td style="text-align: left;">Effect</td>
<td style="text-align: left;">1.00</td>
</tr>
<tr class="even">
<td style="text-align: left;">Description</td>
<td style="text-align: left;">True Effect (known in this exercise)</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Power</td>
<td style="text-align: left;">98%</td>
</tr>
<tr class="even">
<td style="text-align: left;">Type S</td>
<td style="text-align: left;">0.00</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Type M</td>
<td style="text-align: left;">1.02</td>
</tr>
</tbody>
</table>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2023-06-01-teaching-confidence-intervals-with-gganimate/index_files/figure-html/unnamed-chunk-7-1.gif" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>


</section>

 ]]></description>
  <category>methodology</category>
  <category>hypothesis tests</category>
  <category>confidence intervals</category>
  <category>computing</category>
  <category>R</category>
  <guid>https://www.carlislerainey.com/blog/2023-06-01-teaching-confidence-intervals-with-gganimate/</guid>
  <pubDate>Thu, 01 Jun 2023 04:00:00 GMT</pubDate>
  <media:content url="https://www.carlislerainey.com/blog/2023-06-01-teaching-confidence-intervals-with-gganimate/twitter-card.png" medium="image" type="image/png" height="72" width="144"/>
</item>
<item>
  <title>Power, Part II: What Do Confidence Intervals from Well-Powered Studies Look Like?</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2023-05-25-power-2-what-do-confidence-intervals-look-like/</link>
  <description><![CDATA[ 




<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
A Paper
</div>
</div>
<div class="callout-body-container callout-body">
<p>This post turned out to be somewhat popular, so I’ve written up a more formal, careful description of the idea in a full-length paper. You can find the preprint “Power Rules” <a href="https://osf.io/preprints/osf/5am9q_v2">here</a>.</p>
</div>
</div>
<section id="background" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="background">Background</h2>
<p>In this post, I address confidence intervals that are nestled right up against zero.<sup>1</sup> These intervals indicate that an estimate is “barely” significant. I want to be clear: “barely significant” is still significant, so you should still reject the null hypothesis.<sup>2</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn1"><p><sup>1</sup>&nbsp;This is the second post in a series. In my <a href="blog/2023-05-22-power-1-for-you-not-reviewer-2">previous post</a>, I mentioned two new papers that have me thinking about power: <a href="https://doi.org/10.31219/osf.io/7vy2f">Arel-Bundock <em>et al.</em>’s “Quantitative Political Science Research Is Greatly Underpowered”</a> and <a href="https://doi.org/10.33774/apsa-2023-h4p0q-v2">Kane’s “More Than Meets the ITT: A Guide for Investigating Null Results”</a>. Go check out that post and those papers if you haven’t.</p></div><div id="fn2"><p><sup>2</sup>&nbsp;I’m focusing on confidence intervals here because inference from confidence intervals is a bit more intuitive (see <a href="http://www.carlislerainey.com/papers/nme.pdf">Rainey 2014</a> and <a href="http://www.carlislerainey.com/papers/meaningful.pdf">Rainey 2015</a>. In the cases I discuss, whether one checks whether the <em>p</em>-value is less than 0.05 or checks that confidence interval contains zero are equivalent.</p></div></div><p>But I want to address a <em>feeling</em> that can come along with a confidence interval nestled right up against zero. A feeling of victory. It seems like a perfectly designed study. You rejected the null and collected just enough data to do it.</p>
<p>But instead, it should feel like a near-miss. Like an accident narrowly avoided. A confidence interval nestled right up against zero indicates that one of two things has happened: either you were (1) unlucky or (2) under-powered.</p>
<p>Because “unlucky” is always a possibility, we can’t learn much from a <em>particular</em> confidence interval, but we can learn a lot from a <em>literature</em>. A literature with well-powered studies produces confidence intervals that often fall far from zero. A well-powered literature does not produce confidence intervals that consistently nestle up against zero. Under-powered studies, though, <em>do</em> tend to produce confidence intervals that nestle right up against zero.</p>
</section>
<section id="a-simulation" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="a-simulation">A Simulation</h2>
<p>I’m going to explore the behavior of confidence intervals with a little simulation. In this simulation, I’m going to assert a standard error rather than create the standard error endogenously through sample size, etc. I use a true effect size of 0.5 and standard errors of 0.5, 0.3, 0.2, and 0.15 to create studies with 25%, 50%, 80%, and 95% power, respectively.<sup>3</sup> I think of 80% as “minimally-powered” and 95% as “well-powered.”</p>
<div class="no-row-height column-margin column-container"><div id="fn3"><p><sup>3</sup>&nbsp;I’m ignoring how to choose the true effect, estimate the standard error, and compute power. For now, I’m placing all this behind the curtain. See Daniël Lakens’ book [<em>Improving Your Statistical Inferences</em>] for discussion (h/t <a href="https://bersco.github.io">Bermond Scoggins</a>).</p></div></div><p>I’m using a one-sided test (hypothesizing a positive effect), so I’ll use 90% confidence intervals with arms that are 1.64 standard errors wide. Let’s simulate some estimates from each of our four studies and compute their confidence intervals. I simulate 5,000 confidence intervals to explore below.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># load packages</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-3"></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># create a parameter for the true effect</span></span>
<span id="cb1-5">true_effect <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># just assumed by me</span></span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># create a data frame of standard errors (with approximate power)</span></span>
<span id="cb1-8">se_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tribble</span>(</span>
<span id="cb1-9">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>se,    <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>pwr,</span>
<span id="cb1-10">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"about 25% power"</span>,</span>
<span id="cb1-11">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"about 50% power"</span>,</span>
<span id="cb1-12">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>,    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"about 80% power"</span>,</span>
<span id="cb1-13">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>,   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"about 95% power"</span></span>
<span id="cb1-14">)</span>
<span id="cb1-15"></span>
<span id="cb1-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># create function to simulate estimates for each standard error</span></span>
<span id="cb1-17">simulate_estimates <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(se, pwr) {</span>
<span id="cb1-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb1-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n_cis, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> se),</span>
<span id="cb1-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> se,</span>
<span id="cb1-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pwr =</span> pwr</span>
<span id="cb1-22">  )</span>
<span id="cb1-23">}</span>
<span id="cb1-24"></span>
<span id="cb1-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># simulate the estimates, compute the confidence intervals, and wrangle</span></span>
<span id="cb1-26">n_cis <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># the number of cis to create</span></span>
<span id="cb1-27">ci_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> se_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb1-28">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># simulate estimates</span></span>
<span id="cb1-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmap_dfr</span>(simulate_estimates) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-30">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute confidence intervals</span></span>
<span id="cb1-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwr =</span> est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se, </span>
<span id="cb1-32">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upr =</span> est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.64</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>se) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-33">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># summarize the location of the confidence interval</span></span>
<span id="cb1-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">result =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(lwr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not significant"</span>,</span>
<span id="cb1-35">                            lwr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> se <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Nestled against zero"</span>,</span>
<span id="cb1-36">                            lwr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> se<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not nestled against zero"</span>))</span></code></pre></div>
</details>
</div>
<p>Now let’s quickly confirm my power calculations by computing the proportion of confidence intervals to the right of zero. These are about right. In a later post, I’ll describe how I think about computing these quantities.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># confirm power calculations</span></span>
<span id="cb2-2">ci_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(se, pwr) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sim_pwr =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(result <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Not significant"</span>),</span>
<span id="cb2-5">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sim_pwr =</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(sim_pwr, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE =</span> se, </span>
<span id="cb2-7">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Power =</span> pwr,</span>
<span id="cb2-8">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Percent Significant</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> sim_pwr) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-9">  kableExtra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"markdown"</span>)</span></code></pre></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: right;">SE</th>
<th style="text-align: left;">Power</th>
<th style="text-align: left;">Percent Significant</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">0.15</td>
<td style="text-align: left;">about 95% power</td>
<td style="text-align: left;">96%</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.20</td>
<td style="text-align: left;">about 80% power</td>
<td style="text-align: left;">80%</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.30</td>
<td style="text-align: left;">about 50% power</td>
<td style="text-align: left;">52%</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.50</td>
<td style="text-align: left;">about 25% power</td>
<td style="text-align: left;">26%</td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
<section id="what-do-confidence-intervals-from-well-powered-studies-look-like" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="what-do-confidence-intervals-from-well-powered-studies-look-like">What Do Confidence Intervals from Well-Powered Studies Look Like?</h2>
<p>Now let’s see what these confidence intervals look like. 5,000 is too many to plot, so I sample 25. But I applied the statistical significance filter first. This mimics the publication process and makes the plots a little easier to compare. My argument doesn’t depend on this filter, though.</p>
<p>I plotted these 100 intervals below<sup>4</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn4"><p><sup>4</sup>&nbsp;4 studies x 25 simulated intervals per study = 100 intervals.</p></div></div><p>There are three important vertical lines in these plots.</p>
<ol type="1">
<li>The <strong>solid</strong> line indicates zero. All confidence intervals are above zero because I applied the significance filter.</li>
<li>The <strong>dotted</strong> line indicates one standard error above zero. This varies across panels because the standard error varies across panels.</li>
<li>The <strong>dashed</strong> line indicates the true effect of 0.5. Because I applied the significance filter, the lower-powered studies are consistently over-estimating the true effect.</li>
</ol>
<p>The intervals are green when the lower bound of the 90% confidence interval falls within one standard error of zero—that’s my definition of “nestled up against zero.” The intervals are orange when the lower bound falls further than one standard error above zero.</p>
<p>Notice how low-powered studies tend to nestle their confidence intervals right up against zero. Almost all of the confidence intervals from the study with 25% power are nestled right up against zero. Very few of the confidence intervals from the study with 95% power are nestled up against zero.</p>
<p>Again, you should apply this standard to a <em>literature</em>. You should not apply this standard to a particular study because even well-powered studies sometimes produce confidence intervals that nestle up against zero. But when you start to see confidence intervals consistently falling close to zero, you should start to assume that the literature uses under-powered studies and that the estimates in that literature are inflated due to Type M errors <a href="https://journals.sagepub.com/doi/10.1177/1745691614551642">(Gelman and Stern 2014)</a>.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">gg_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> ci_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(lwr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># apply significance filter </span></span>
<span id="cb3-3">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># sample 25 intervals (from those that are significant)</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(se, pwr) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample_n</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-6">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># create id (ordered by estimate value)</span></span>
<span id="cb3-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(se, pwr) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(est) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>())</span>
<span id="cb3-10">  </span>
<span id="cb3-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(gg_df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> est, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> lwr, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> upr, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> ci_id,</span>
<span id="cb3-12">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> result)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(pwr), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_x"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> se), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dotted"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> true_effect, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbarh</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_brewer</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qual"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">palette =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate and 90% CI"</span>,</span>
<span id="cb3-22">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb3-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Result"</span>)</span></code></pre></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2023-05-25-power-2-what-do-confidence-intervals-look-like/index_files/figure-html/unnamed-chunk-3-1.png" class="img-fluid figure-img" width="576"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="showing-this-another-way-density-of-the-lower-bounds" class="level2">
<h2 class="anchored" data-anchor-id="showing-this-another-way-density-of-the-lower-bounds">Showing This Another Way: Density of the Lower Bounds</h2>
<p>We can also plot the density of the lower bounds of these 5,000 intervals. This approach shows the “nestling” most clearly. The plots below show that the lower bounds of confidence intervals tend to nestle close to zero when the power is low, and lie further from zero when the power is high.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">gg_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> ci_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(lwr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># apply significance filter </span></span>
<span id="cb4-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(gg_df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> lwr)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(pwr), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_x"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_density</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey50"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> se_df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> se), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dotted"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Location of Lower Bound of 90% CI"</span>,</span>
<span id="cb4-9">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>,</span>
<span id="cb4-10">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Power"</span>)</span></code></pre></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://www.carlislerainey.com/blog/2023-05-25-power-2-what-do-confidence-intervals-look-like/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="showing-this-another-way-frequency-of-nestling" class="level2">
<h2 class="anchored" data-anchor-id="showing-this-another-way-frequency-of-nestling">Showing This Another Way: Frequency of Nestling</h2>
<p>Lastly, I compute the percent of confidence intervals that are nestled right up against zero. For a well-powered study with 95% power, only about 1 in 5 confidence intervals nestle up against zero. For a poorly-powered study with 25% power, about 4 in 5 of confidence intervals nestle up against zero (among those that are above zero). The table below shows the remaining frequencies.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">ci_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(se, pwr, result) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">frac =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_cis, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from =</span> result, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from =</span> frac) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Nestled, given significant</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Nestled against zero</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Not significant</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>),</span>
<span id="cb5-6">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Not nestled, given significant</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Not nestled against zero</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Not significant</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE =</span> se, </span>
<span id="cb5-8">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Power =</span> pwr,</span>
<span id="cb5-9">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Not significant</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb5-10">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Nestled against zero</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb5-11">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Not nestled against zero</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb5-12">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Nestled, given significant</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb5-13">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Not nestled, given significant</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Not significant</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Not nestled, given significant</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> scales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">percent</span>(., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">accuracy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-15">  kableExtra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>()</span></code></pre></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 3%">
<col style="width: 11%">
<col style="width: 11%">
<col style="width: 14%">
<col style="width: 17%">
<col style="width: 19%">
<col style="width: 21%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: right;">SE</th>
<th style="text-align: left;">Power</th>
<th style="text-align: left;">Not significant</th>
<th style="text-align: left;">Nestled against zero</th>
<th style="text-align: left;">Not nestled against zero</th>
<th style="text-align: left;">Nestled, given significant</th>
<th style="text-align: left;">Not nestled, given significant</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">0.15</td>
<td style="text-align: left;">about 95% power</td>
<td style="text-align: left;">4%</td>
<td style="text-align: left;">20%</td>
<td style="text-align: left;">76%</td>
<td style="text-align: left;">20%</td>
<td style="text-align: left;">80%</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.20</td>
<td style="text-align: left;">about 80% power</td>
<td style="text-align: left;">20%</td>
<td style="text-align: left;">36%</td>
<td style="text-align: left;">44%</td>
<td style="text-align: left;">45%</td>
<td style="text-align: left;">55%</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.30</td>
<td style="text-align: left;">about 50% power</td>
<td style="text-align: left;">48%</td>
<td style="text-align: left;">36%</td>
<td style="text-align: left;">17%</td>
<td style="text-align: left;">68%</td>
<td style="text-align: left;">32%</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.50</td>
<td style="text-align: left;">about 25% power</td>
<td style="text-align: left;">74%</td>
<td style="text-align: left;">21%</td>
<td style="text-align: left;">5%</td>
<td style="text-align: left;">80%</td>
<td style="text-align: left;">20%</td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
<section id="summary" class="level2">
<h2 class="anchored" data-anchor-id="summary">Summary</h2>
<p>In this post, I address confidence intervals that are nestled right up against zero. These intervals can suggest a perfectly powered study—not too much, not too little. But instead, a confidence interval nestled right up against zero indicates that one of two things has happened: either you were (1) unlucky or (2) under-powered.</p>
<p>Because “unlucky” is always a possibility, we can’t learn much from a <em>particular</em> confidence interval, but we can learn a lot from a <em>literature</em>. A literature with well-powered studies produces confidence intervals that often fall far from zero. A well-powered literature does not produce confidence intervals that consistently nestle up against zero. Under-powered studies, though, <em>do</em> tend to produce confidence intervals that nestle right up against zero.</p>
<div class="callout callout-style-simple callout-none no-icon callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Key Takeaway
</div>
</div>
<div class="callout-body-container callout-body">
<p>Under-powered studies tend to produce confidence intervals that are nestled right up against zero. Well-powered studies tend to produce confidence intervals that fall further away. A literature that produces confidence intervals that consistently nestle right up against zero is likely a collection of under-powered studies.</p>
</div>
</div>


</section>


 ]]></description>
  <category>statistical power</category>
  <category>hypothesis tests</category>
  <category>power analysis</category>
  <category>methodology</category>
  <category>confidence intervals</category>
  <category>computing</category>
  <category>R</category>
  <guid>https://www.carlislerainey.com/blog/2023-05-25-power-2-what-do-confidence-intervals-look-like/</guid>
  <pubDate>Thu, 25 May 2023 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Power, Part I: Power Is for You, Not for Reviewer Two</title>
  <dc:creator>Carlisle Rainey</dc:creator>
  <link>https://www.carlislerainey.com/blog/2023-05-22-power-1-for-you-not-reviewer-2/</link>
  <description><![CDATA[ 




<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
A Paper
</div>
</div>
<div class="callout-body-container callout-body">
<p>This post turned out to be somewhat popular, so I’ve written up a more formal, careful description of the idea in a full-length paper. You can find the preprint “Power Rules” <a href="https://osf.io/preprints/osf/5am9q_v3">here</a>.</p>
</div>
</div>
<section id="background" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="background">Background</h2>
<p>There’s been some really good work lately on statistical power. I’ll point you to two really great papers.</p>
<ol type="1">
<li>Arel-Bundock, Vincent, Ryan C. Briggs, Hristos Doucouliagos, Marco Mendoza Aviña, and T.D. Stanley. 2022. “Quantitative Political Science Research Is Greatly Underpowered.” OSF Preprints. July 5. <a href="https://doi.org/10.31219/osf.io/7vy2f">doi: 10.31219/osf.io/7vy2f</a>.</li>
<li>Kane, John V. 2023. “More Than Meets the ITT: A Guide for Investigating Null Results .” APSA Preprints. <a href="https://doi.org/10.33774/apsa-2023-h4p0q-v2">doi: 10.33774/apsa-2023-h4p0q-v2</a>.</li>
</ol>
<p>I’ve been long interested in statistical power (see <a href="http://www.carlislerainey.com/papers/nme.pdf">Rainey 2014</a><sup>1</sup> and <a href="http://www.carlislerainey.com/papers/meaningful.pdf">Rainey 2015</a><sup>2</sup>), and these new papers have me thinking even more about the importance of power.</p>
<div class="no-row-height column-margin column-container"><div id="fn1"><p><sup>1</sup>&nbsp;Rainey, Carlisle. 2014. “Arguing for a Negligible Effect.” <em>American Journal of Political Science</em> 58(4): 1083-1091.</p></div><div id="fn2"><p><sup>2</sup>&nbsp;McCaskey, Kelly and Carlisle Rainey. 2015. “Substantive Importance and the Veil of Statistical Significance.” Statistics, Politics, and Policy 6(1-2): 77-96.</p></div></div><p>In this post, I argue that statistical power isn’t something ancillary. Power is <em>primary</em>. I also argue that power isn’t something you–the researcher–build to satisfy an especially cranky Reviewer 2, it’s something you do for <em>yourself</em>, to make sure that your study succeeds.</p>
</section>
<section id="the-hypothesis-testing-framework" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="the-hypothesis-testing-framework">The Hypothesis Testing Framework</h2>
<p>In the hypothesis testing framework, you consider two hypotheses: the null hypothesis and the alternative hypothesis.</p>
<p>The hypothesis test is all about arguing <em>against</em> the null hypothesis <img src="https://latex.codecogs.com/png.latex?H_0"> (leaving the alternative <img src="https://latex.codecogs.com/png.latex?H_A"> as the only remaining possibility). You will (try to) show that your data would be “unusual” if the null hypothesis were correct.<sup>3</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn3"><p><sup>3</sup>&nbsp;When hypothesizing about the average treatment effect (ATE), this can take a variety of forms. The form doesn’t really matter.</p></div></div><p>If the data would <em>NOT</em> be unusual under the null hypothesis, then you <em>do not</em> reject the null hypothesis.</p>
</section>
<section id="intepreting-a-failure-to-reject" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="intepreting-a-failure-to-reject">Intepreting a Failure to Reject</h2>
<p>A failure to reject means that the data “would not be unusual under the null hypothesis.” This does not imply that you should conclude the data are <em>only</em> consistent with the null. Indeed, there is a sharp asymmetry in hypothesis testing. I describe this in my <a href="(http://www.carlislerainey.com/papers/nme.pdf)">2014 <em>AJPS</em></a>:</p>
<blockquote class="blockquote">
<p>Political scientists commonly interpret a lack of statistical significance (i.e., a failure to reject the null) as evidence for a negligible effect (Gill 1999), but this approach acts as a broken compass… If the sample size is too small, the researcher often concludes that the effect is negligible even though the data are also consistent with large, meaningful effects. This occurs because the small sample leads to a large confidence interval, which is likely to contain both “no effect” and large effects.</p>
</blockquote>
<p><a href="https://www.jstor.org/stable/449153">Gill (1999)</a><sup>4</sup> describes this more forcefully:</p>
<div class="no-row-height column-margin column-container"><div id="fn4"><p><sup>4</sup>&nbsp;Gill, Jeff. 1999. “The Insignificance of Null Hypothesis Significance Testing.” <em>Political Research Quarterly</em> 52(3): 647-674.</p></div></div><blockquote class="blockquote">
<p>We teach graduate students to be very careful when describing the occurrence of not rejecting the null hypothesis. This is because failing to reject the null hypothesis does not rule out an infinite number of other competing research hypotheses. Null hypothesis significance testing is asymmetric: if the test statistic is sufficiently atypical given the null hypothesis then the null hypothesis is rejected, but if the test statistic is insufficiently atypical given the null hypothesis then the null hypothesis is not accepted. This is a double standard: H1 is held innocent until proven guilty and Ho is held guilty until proven innocent (Rozeboom 1960)…</p>
</blockquote>
<blockquote class="blockquote">
<p>There are two problems that develop as a result of asymmetry. The first is a misinterpretation of the asymmetry to assert that finding a non-statistically significant difference or effect is evidence that it is equal to zero or nearly zero. Regarding the impact of this acceptance error Schmidt (1996: 126) asserts that this: “belief held by many researchers is the most devastating of all to the research enterprise.” This acceptance of the null hypothesis is damaging because it inhibits the exploration of competing research hypotheses. The second problem pertains to the correct interpretation of failing to reject the null hypotheses. Failing to reject the null hypothesis essentially provides almost no information about the state of the world. It simply means that given the evidence at hand one cannot make an assertion about some relationship: all you can conclude is that you can’t conclude that the null was false (Cohen 1962).</p>
</blockquote>
<p>There are many incorrect, but somewhat innocent interpretations of <em>p</em>-values. Interpreting a lack of statistical significance as evidence for the null is incorrect <em>and wildly misleading</em> in many cases.</p>
<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Important Point
</div>
</div>
<div class="callout-body-container callout-body">
<p>A non-statistically significant difference is not evidence that an effect is equal to zero or nearly zero. Interpreting a non-statistically significant effect otherwise is “devastating.”</p>
</div>
</div>
</section>
<section id="the-implication-of-a-non-conclusion" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="the-implication-of-a-non-conclusion">The Implication of a Non-Conclusion</h2>
<p>If you cannot draw a conclusion then, what exactly has happened? Obtaining <img src="https://latex.codecogs.com/png.latex?p%20%3E%200.05"> will not be an “error” because you won’t make a strong claim that the research hypothesis is wrong. Instead, you will simply admit that you failed to uncover evidence against the null. Failing to uncover evidence isn’t an error.</p>
<p>Indeed, <a href="https://psycnet.apa.org/fulltext/2000-16737-001.pdf">Jones and Tukey (2000)</a><sup>5</sup> write:</p>
<div class="no-row-height column-margin column-container"><div id="fn5"><p><sup>5</sup>&nbsp;Jones, Lyle V., and John W. Tukey. 2000. “A Sensible Formulation of the Significance Test.” <em>Psychological Methods</em> 5(4): 411-414.</p></div></div><blockquote class="blockquote">
<p>A conclusion is in error only when it is “a reversal,” when it asserts one direction while the (unknown) truth is the other direction. Asserting that the direction is not yet established may constitute a wasted opportunity, but it is not an error.</p>
</blockquote>
<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Important Point
</div>
</div>
<div class="callout-body-container callout-body">
<p>Failing to uncover evidence isn’t an “error,” it is a “wasted effort.”</p>
</div>
</div>
<p>This is worth emphasizing in a different way. Tests are not magical tools that tell you which hypothesis is correct. Instead, tests summarize the evidence against the null. There are two critical pieces to “evidence against the null”: (1) the amount of evidence and (2) whether the evidence is against the null. If you buy your own argument that the null is false (surely you do!), then (2) is taken care of. Only the amount of evidence remains, and you–the researcher–choose the amount of evidence to supply.</p>
</section>
<section id="the-implication-for-power-calculations" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="the-implication-for-power-calculations">The Implication for Power Calculations</h2>
<p>This perspective helps motivate power calculations. By their design, tests control the error rate in certain situations (when then null is correct). You do not need to worry about Type I errors. First, the test controls the error rate under the null. Second, you are pretty sure the null is wrong (see your theory section).</p>
<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Important Point
</div>
</div>
<div class="callout-body-container callout-body">
<p>The hypothesis test takes care of the the Type I error rate. If you choose a properly-sized test, you don’t need to worry about those errors any more.</p>
</div>
</div>
<p>If you aren’t worried about Type I errors, what are you worried about? They only thing left to worry about is wasting your time and money. <strong>Statistical power</strong> is the chance not of wasting your time and money.</p>
<p>Power isn’t a secondary quantity that you compute for thoroughness or in anticipation of a comment from Reviewer 2. Power is something that you build <em>for yourself</em>.</p>
<p>Statisticians talk a lot about Type I errors because that’s their contribution. It’s your job to bring the power.</p>
<p>And importantly, power is under your control. <a href="https://doi.org/10.33774/apsa-2023-h4p0q-v2">Kane</a> provides a rich summary of ways to increase the power of your experiment. At a minimum, you have brute force control through sample size.</p>
<p>Power isn’t an ancillary concern, it’s the entire game from the very beginning of the planning stage. It should be at the forefront of the researchers mind from the very beginning. You should want the power as high as possible.<sup>6</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn6"><p><sup>6</sup>&nbsp;I hear that 80% is the standard, but I’m pretty uncomfortable spending dozens of hours and thousands of dollars running for a 1 in 5 chance of wasting my time. I want that chance as close to zero as I can get it. I want power close to 100%. 99% power and 80% power might both seem “high” or “acceptable,” but these are not the same. 80% power means 1 in 5 studies fail. 99% power means that 1 in 100 studies fail.</p></div></div><p>You have to supply a test <em>overwhelming</em> evidence to consistently reject the null. Careful power calculations help you make sure you succeed in this war against the null.</p>
<p>Power isn’t about Type S and M errors (<a href="https://journals.sagepub.com/doi/pdf/10.1177/1745691614551642">Gelman and Carlin 2014</a>)<sup>7</sup>. Power is about you protecting yourself from a failed study. And that seems like a protection worth pursuing carefully.<sup>8</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn7"><p><sup>7</sup>&nbsp;Gelman, Andrew, and John Carlin. “Beyond Power Calculations: Assessing Type S (Sign) and Type M (Magnitude) Errors.” <em>Perspectives on Psychological Science</em> 9(6): 641-651.</p></div><div id="fn8"><p><sup>8</sup>&nbsp;Of course it’s also about Type S and M errors, but those are discipline-level concerns. I’m talking about <em>your</em> incentives as a researcher.</p></div></div></section>
<section id="summary" class="level2">
<h2 class="anchored" data-anchor-id="summary">Summary</h2>
<p>Here are the takeaways:</p>
<ol type="1">
<li>Statistical power is the chance of using your time and money productively (i.e., not wasting it).</li>
<li>Statistical power is under your control (see <a href="https://doi.org/10.33774/apsa-2023-h4p0q-v2">Kane</a>).</li>
<li>Your power might be (much) lower than you think–you should check (see <a href="https://doi.org/10.31219/osf.io/7vy2f">Arel-Bundock <em>et al</em></a>.).</li>
<li>Power should be a <em>primary</em> concern throughout the design. The researcher should care deeply about power, perhaps more than anything else.</li>
</ol>
<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Important Point
</div>
</div>
<div class="callout-body-container callout-body">
<p>The hypothesis test is no oracle. It will not consistently reject the null (even when the null is wrong) unless you supply overwhelming evidence. In experimental design, that’s not <em>a</em> task, that’s <em>the</em> task.</p>
</div>
</div>


</section>


 ]]></description>
  <category>statistical power</category>
  <category>hypothesis tests</category>
  <category>power analysis</category>
  <category>methodology</category>
  <guid>https://www.carlislerainey.com/blog/2023-05-22-power-1-for-you-not-reviewer-2/</guid>
  <pubDate>Sun, 21 May 2023 04:00:00 GMT</pubDate>
</item>
</channel>
</rss>
