<?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>Less Likely</title>
<link>https://lesslikely.com/blog.html</link>
<atom:link href="https://lesslikely.com/blog.xml" rel="self" type="application/rss+xml"/>
<description>Articles on statistical science and its applications to medicine and nutrition, with reproducible examples and interactive explanations.</description>
<image>
<url>https://lesslikely.com/images/Archives.jpg</url>
<title>Less Likely</title>
<link>https://lesslikely.com/blog.html</link>
</image>
<generator>quarto-1.10.18</generator>
<lastBuildDate>Thu, 01 Oct 2026 04:00:00 GMT</lastBuildDate>
<item>
  <title>Climbing Down the Ladder: Abstraction, Dashboards, and Forking Paths</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/statistics/ladder-dashboards.html</link>
  <description><![CDATA[ 





<!-- Canonical primary source: Gelman & Fung, "The Ladder of Abstraction in
     Statistical Graphics" — linked in the opening paragraph and in the bib. -->
<p>Gelman and Fung argue that statistical graphics confuse people because they are more abstract than they look, and that the fix is to build a <em>sequence</em> of graphs, starting from a concrete special case and adding one level of abstraction at a time<span class="citation" data-cites="gelman2025ladder"><sup>1</sup></span>. Their ladder is drawn by the author and climbed in one direction. This article is about what happens when the reader holds the rope: interactive dashboards make the ladder <strong>two-way</strong>, which keeps abstract summaries honest but also turns every slicer into a forking path<span class="citation" data-cites="gelman2014forking"><sup>2</sup></span>.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Summary of the original argument
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<!-- TODO: 3–5 sentences in your own words. Do not reproduce their figures;
     describe the basketball and income–voting examples and link to the PDF. -->
</div>
</div>
</div>
<section id="the-ladder-is-a-narrative-structure-and-dashboards-invert-it" class="level2">
<h2 class="anchored" data-anchor-id="the-ladder-is-a-narrative-structure-and-dashboards-invert-it">The ladder is a narrative structure, and dashboards invert it</h2>
<!-- Argument: the paper's ladder is author-driven (closest to Segel & Heer's
     "martini glass"). Dashboards follow Shneiderman's mantra — overview first,
     then zoom/filter, then details on demand — which starts at the TOP rung.
     So the reader's first view is the most abstract one, exactly what the
     ladder warns against. -->
<p><span class="citation" data-cites="segel2010narrative shneiderman1996eyes"><sup>3, 4</sup></span></p>
</section>
<section id="each-of-the-eight-abstraction-strategies-is-already-a-dashboard-control" class="level2">
<h2 class="anchored" data-anchor-id="each-of-the-eight-abstraction-strategies-is-already-a-dashboard-control">Each of the eight abstraction strategies is already a dashboard control</h2>
<div id="tbl-map" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-map-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1: Mapping the paper’s strategies to BI features.
</figcaption>
<div aria-describedby="tbl-map-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th>Gelman &amp; Fung strategy</th>
<th>Dashboard control</th>
<th>Example below</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Concrete case / representative example</td>
<td>Drillthrough, tooltip page</td>
<td>Rung 1</td>
</tr>
<tr class="even">
<td>Expand temporal coverage</td>
<td>Time-intelligence, prior-year overlay</td>
<td>Rung 2</td>
</tr>
<tr class="odd">
<td>Single → multiple samples</td>
<td>Small multiples</td>
<td>Rung 3</td>
</tr>
<tr class="even">
<td>Statistical averages</td>
<td>Aggregated measure vs.&nbsp;baseline</td>
<td>Rung 4</td>
</tr>
<tr class="odd">
<td>Abstract space</td>
<td>Scatter of derived metrics</td>
<td>Rung 5</td>
</tr>
<tr class="even">
<td>Subgroups</td>
<td>Slicers, segments, decomposition tree</td>
<td>Forking-paths section</td>
</tr>
<tr class="odd">
<td>Let fixed parameters vary</td>
<td>Field / what-if parameters</td>
<td>Widget</td>
</tr>
<tr class="even">
<td>Modeled or optimized values</td>
<td>Forecast, budget</td>
<td>(not shown)</td>
</tr>
</tbody>
</table>
</div>
</figure>
</div>
</section>
<section id="a-simulated-retail-chain-climbs-the-ladder-in-five-rungs" class="level2">
<h2 class="anchored" data-anchor-id="a-simulated-retail-chain-climbs-the-ladder-in-five-rungs">A simulated retail chain climbs the ladder in five rungs</h2>
<p>The data are simulated so that ground truth is known: 60 stores, three regions, two site types, and three years of weekly fuel margin and gallons sold. Store volume varies and its mix shifts over time. <strong>By construction, region and site type have no effect on margin.</strong> Store-specific levels and gradual changes, seasonality, and noise affect margin.</p>
<section id="rung-1-one-store-one-year" class="level3">
<h3 class="anchored" data-anchor-id="rung-1-one-store-one-year">Rung 1: one store, one year</h3>
<div class="cell">
<div class="code-copy-outer-scaffold"><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">sales <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(store_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> focus_store, year <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;">2026</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-3">  <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>(wk, margin_cpg)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</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="cb1-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</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-6">  <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;">"Week of year"</span>, <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;">"Margin (cents per gallon)"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div id="fig-rung1" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rung1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://lesslikely.com/statistics/ladder-dashboards_files/figure-html/fig-rung1-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-rung1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Store 1, weekly fuel margin, 2026. Every point is a real week.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="rung-2-the-same-store-three-years" class="level3">
<h3 class="anchored" data-anchor-id="rung-2-the-same-store-three-years">Rung 2: the same store, three years</h3>
<p>Prior years become context, the variation-as-uncertainty move from the original paper, instead of error bars.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><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">sales <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(store_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> focus_store) <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;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(wk, margin_cpg, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> year,</span>
<span id="cb2-4">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> year <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;">2026</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> year <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;">2026</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_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;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TRUE</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;">"black"</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;">FALSE</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;">"grey70"</span>),</span>
<span id="cb2-7">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide =</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-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_linewidth_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;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">TRUE</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</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;">FALSE</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>),</span>
<span id="cb2-9">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide =</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-10">  <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;">"text"</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;">52</span>, <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;">max</span>(sales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>margin_cpg[sales<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>store_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> focus_store]),</span>
<span id="cb2-11">           <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;">"2026"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</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;">vjust =</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-12">  <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;">"Week of year"</span>, <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;">"Margin (cents per gallon)"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div id="fig-rung2" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rung2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://lesslikely.com/statistics/ladder-dashboards_files/figure-html/fig-rung2-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-rung2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Store 1. 2026 in black; 2024–2025 in grey.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="rung-3-twelve-stores-as-small-multiples" class="level3">
<h3 class="anchored" data-anchor-id="rung-3-twelve-stores-as-small-multiples">Rung 3: twelve stores as small multiples</h3>
<div class="cell">
<div class="code-copy-outer-scaffold"><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">sales <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>(store_id <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;">12</span>, year <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;">2026</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-3">  <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>(wk, margin_cpg)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</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="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> store_id, <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;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> label_both) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-6">  <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;">"Week of year"</span>, <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;">"Margin (CPG)"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div id="fig-rung3" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rung3-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://lesslikely.com/statistics/ladder-dashboards_files/figure-html/fig-rung3-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-rung3-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: Twelve stores, 2026, shared axes. Store 1 is the first panel.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="rung-4-the-chain-average-with-a-variation-band" class="level3">
<h3 class="anchored" data-anchor-id="rung-4-the-chain-average-with-a-variation-band">Rung 4: the chain average, with a variation band</h3>
<div class="cell">
<div class="code-copy-outer-scaffold"><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">rung4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> sales <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>(year <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;">2026</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(wk) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">avg =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(margin_cpg),</span>
<span id="cb4-5">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lo  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(margin_cpg, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>),</span>
<span id="cb4-6">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hi  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(margin_cpg, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-7">  <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>(wk)) <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;">geom_ribbon</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;">ymin =</span> lo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> hi), <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;">"grey85"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</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;">y =</span> avg)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-10">  <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;">"Week of year"</span>, <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;">"Margin (CPG)"</span>)</span>
<span id="cb4-11"></span>
<span id="cb4-12">rung4</span>
<span id="cb4-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggsave</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"../images/ladder-dashboards.png"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot =</span> rung4,</span>
<span id="cb4-14">       <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;">height =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dpi =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">150</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bg =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div id="fig-rung4" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rung4-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://lesslikely.com/statistics/ladder-dashboards_files/figure-html/fig-rung4-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-rung4-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: Equal-weight average across stores in 2026 (line); band shows the 25th–75th percentile across store-weeks.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="rung-5-every-store-becomes-a-dot" class="level3">
<h3 class="anchored" data-anchor-id="rung-5-every-store-becomes-a-dot">Rung 5: every store becomes a dot</h3>
<p>Rung 1 was an entire line. Here it is a single labelled dot, which is the “this line is now that dot” move that makes the original paper work.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(store_summary, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(mean_margin, volatility)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</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="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</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;">filter</span>(store_summary, store_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> focus_store),</span>
<span id="cb5-4">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</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;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-5">  <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> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(store_summary, store_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> focus_store),</span>
<span id="cb5-6">            <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;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Store 1 (rung 1)"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</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.15</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;">"Mean margin (CPG)"</span>, <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;">"Volatility (SD of weekly margin)"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div id="fig-rung5" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-rung5-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://lesslikely.com/statistics/ladder-dashboards_files/figure-html/fig-rung5-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-rung5-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: Each store’s three-year mean margin against its week-to-week volatility. Store 1 is labelled.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
</section>
<section id="letting-readers-climb-freely-produces-confident-nonsense" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="letting-readers-climb-freely-produces-confident-nonsense">Letting readers climb freely produces confident nonsense</h2>
<!-- Core contribution of the response. The ladder assumes the author chose the
     rungs. In a dashboard, the reader picks subgroups after seeing the data.
     Cite Zgraggen et al.: n = 28, > 60% of reported insights false, mean FDR
     0.74 ± 0.30. Then demonstrate it on our null data. -->
<div class="cell">
<div class="code-copy-outer-scaffold"><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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Every slice a reader can click: region x site type x year x quarter.</span></span>
<span id="cb6-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Each slice is compared with the rest of the chain, store as the unit.</span></span>
<span id="cb6-3">slice_tests <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>(sales) {</span>
<span id="cb6-4">  store_q <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> sales <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-5">    <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;">quarter =</span> (wk <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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">13</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;">|&gt;</span></span>
<span id="cb6-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(store_id, region, site_type, year, quarter) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(margin_cpg), <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>
<span id="cb6-8"></span>
<span id="cb6-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(store_q<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>region), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(store_q<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>site_type),</span>
<span id="cb6-10">              <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;">2024</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;">2026</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q =</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;">4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-11">    <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;">out =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmap</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(r, s, y, q), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(r, s, y, q) {</span>
<span id="cb6-12">      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;">filter</span>(store_q, year <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> y, quarter <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> q) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-13">        <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;">in_slice =</span> region <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> r <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> site_type <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> s)</span>
<span id="cb6-14">      p <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;">tryCatch</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t.test</span>(m <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> in_slice, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value,</span>
<span id="cb6-15">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">error =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(e) <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA_real_</span>)</span>
<span id="cb6-16">      <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;">n_stores =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>in_slice), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p =</span> p)</span>
<span id="cb6-17">    })) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(out) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-19">    <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;">s_value =</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;">log2</span>(p), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p_bh =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">p.adjust</span>(p, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BH"</span>))</span>
<span id="cb6-20">}</span>
<span id="cb6-21"></span>
<span id="cb6-22">results <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;">slice_tests</span>(sales)</span>
<span id="cb6-23">n_tests <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;">sum</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;">is.na</span>(results<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p))</span>
<span id="cb6-24">max_s   <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;">max</span>(results<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>s_value, <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>
<span id="cb6-25"></span>
<span id="cb6-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Repeat on many independent null chains to see how often a reader "finds" something.</span></span>
<span id="cb6-27">n_sims <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;">200</span></span>
<span id="cb6-28">sims <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;">map_dfr</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(n_sims), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(i) {</span>
<span id="cb6-29">  r <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;">slice_tests</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">make_sales</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> i))</span>
<span id="cb6-30">  <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;">any_raw =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any</span>(r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p <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 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>
<span id="cb6-31">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">any_bh  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">any</span>(r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p_bh <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 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>
<span id="cb6-32">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_raw   =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p <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 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>
<span id="cb6-33">})</span>
<span id="cb6-34">pct_any_raw <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;">round</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</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>(sims<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>any_raw))</span>
<span id="cb6-35">pct_any_bh  <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;">round</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</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>(sims<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>any_bh))</span></code></pre></div></div>
</div>
<p>A reader who slices by region, site type, year, and quarter makes 72 comparisons. In the chain plotted above, the most surprising slice carries an S-value of 4.6 bits<sup>1</sup>, on data where no region or site-type effect exists. Across 200 independently simulated null chains, <strong>72%</strong> let a reader find at least one slice with <em>p</em> &lt; 0.05. After a Benjamini–Hochberg correction across the slices, 8% still do<span class="citation" data-cites="zgraggen2018investigating pu2018garden"><sup>5, 6</sup></span>.</p>
<div class="no-row-height column-margin column-container"><div id="fn1"><p><sup>1</sup>&nbsp;See <a href="../statistics/s-values.html">S-values</a> for why bits are a more honest scale than <em>p</em> here.</p></div></div><div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-2-contents" aria-controls="callout-2" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Why the “discoveries” cluster by slice
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-2" class="callout-2-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<p>Store effects are fixed across time, so a region × site-type cell that happened to draw a few high-margin stores looks “significant” in quarter after quarter. The repetition feels like replication. It is the same stores counted again.</p>
</div>
</div>
</div>
</section>
<section id="five-rules-extend-the-ladder-to-two-way-travel" class="level2">
<h2 class="anchored" data-anchor-id="five-rules-extend-the-ladder-to-two-way-travel">Five rules extend the ladder to two-way travel</h2>
<ol type="1">
<li><strong>Anchor every abstract view to a concrete case.</strong> Hover or click on a dot to reach its line (rung 5 → rung 1).</li>
<li><strong>Say which rung you are on.</strong> Dynamic titles stating the metric, grain, filters, and <em>n</em>. Titles dominate recall: in one experiment with 200 participants, 34% of recalled messages matched a misleading title and 14% matched the chart<span class="citation" data-cites="kong2019trust"><sup>7</sup></span>.</li>
<li><strong>Keep encodings fixed across rungs.</strong> Same colour, same meaning; shared axes in small multiples.</li>
<li><strong>Show <em>n</em> and suppress anecdotes.</strong> Flag any slice below a minimum number of units.</li>
<li><strong>Separate exploring from confirming.</strong> Save a pattern found by slicing as a candidate hypothesis, then evaluate it with a design suited to the claim. A later period checks persistence; it does not by itself establish a causal explanation.</li>
</ol>
</section>
<section id="a-dashboard-should-preserve-the-question-as-the-view-changes" class="level2">
<h2 class="anchored" data-anchor-id="a-dashboard-should-preserve-the-question-as-the-view-changes">A dashboard should preserve the question as the view changes</h2>
<p>A dashboard lets readers move among displays, but not every movement means the same thing. Changing a chart can leave the question intact; changing the stores or the measure can change what is being described.</p>
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th>Movement</th>
<th>Fuel-margin example</th>
<th>Make explicit</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong>Representation</strong></td>
<td>Show the same stores and measure as a trend, distribution, or scatterplot</td>
<td>The population, metric, units, and period stay fixed</td>
</tr>
<tr class="even">
<td><strong>Aggregation</strong></td>
<td>Move from chain to region to store</td>
<td>What each mark represents and how values are combined</td>
</tr>
<tr class="odd">
<td><strong>Population</strong></td>
<td>Filter to highway stores in one region</td>
<td>Which stores remain, how many, which are excluded, and the comparison group</td>
</tr>
<tr class="even">
<td><strong>Question</strong></td>
<td>Switch from margin per gallon to total margin dollars, or from level to volatility</td>
<td>Metric, denominator, units, weighting, and what the comparison means</td>
</tr>
<tr class="odd">
<td><strong>Comparison</strong></td>
<td>Compare with budget, prior year, or peer stores</td>
<td>Which reference defines better or worse performance</td>
</tr>
</tbody>
</table>
<p>An illustrative drill path might begin with a chain-level decline, identify the regions contributing to it, inspect the distribution across stores, select one store, and descend to its weekly history and source records. That is a design scenario, not a finding from the simulated series above. At every step, keep a small reference view of the chain and the original period. Show the selected stores alongside a named benchmark: the whole chain, the rest of the chain, comparable stores, or the same stores in another period. A changing chart is much easier to interpret when the reader can still see what it changed from.</p>
<p>Each view should answer a part of the business question. The overview shows margin dollars, gallons, and cents per gallon; the store distribution shows whether the movement is widespread or concentrated; subgroup comparisons show where to investigate; and store histories expose the weeks behind the summary. Provide an obvious route back to the overview, preserving the reader’s selection. A drillthrough to source records should carry the selected store and period so that the detail actually explains the mark the reader clicked.</p>
<section id="aggregation-is-another-movement" class="level3">
<h3 class="anchored" data-anchor-id="aggregation-is-another-movement">Aggregation is another movement</h3>
<p>“Average store margin” gives each store equal weight. “Margin per gallon across the chain” weights stores by gallons sold: total margin dollars divided by total gallons, expressed in cents per gallon. Neither is universally correct; the appropriate measure depends on the decision. The second measure needs volume data, so the simulation now includes store-week gallons and deliberately lets sales mix shift while leaving the margin-generating process independent of region and site type.</p>
<p>The figure compares the equal-store average with the current-volume-weighted margin and a version using each store’s average 2024 volume as a fixed weight. The latter keeps the store roster and weights fixed, making changes in store margins easier to distinguish from changes in sales mix. In this simulation, store-specific margin drift is generated independently of a deliberate shift in gallons toward stores with higher baseline margins; holding 2024 weights fixed removes that mix shift from the weighted comparison.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><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>(chain_weekly, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(wk, margin_cpg, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> weighting)) <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_line</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;">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;">"Week of 2026"</span>, <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;">"Margin (cents per gallon)"</span>,</span>
<span id="cb7-4">       <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;">"Weighting"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div id="fig-aggregation" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-aggregation-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://lesslikely.com/statistics/ladder-dashboards_files/figure-html/fig-aggregation-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-aggregation-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6: Three 2026 chain summaries: equal store weights, current gallon weights, and fixed 2024 gallon weights.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The simulation keeps the same 60 stores in every year, so its annual equal-store comparison is a same-store comparison by construction. The North rows below show what a population filter does to both the included count and the observed average; they do not estimate a regional effect. Comparing the current-volume and fixed-2024-weighted columns holds the store-level margins constant within each year while changing the weights. A real dashboard should also report when stores enter or leave the available population. Fixed weights are a useful question to ask, not a uniquely correct adjustment.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><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">annual_diagnostics <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb8-3">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Year =</span> year,</span>
<span id="cb8-4">    <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;">Stores in chain</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_stores,</span>
<span id="cb8-5">    <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;">Equal-store mean (cpg)</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(equal_store, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb8-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;">Current-volume mean (cpg)</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(current_mix, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb8-7">    <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;">Fixed-2024-weight mean (cpg)</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(fixed_mix, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb8-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;">North stores</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> north_n,</span>
<span id="cb8-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;">North mean (cpg)</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(north_mean, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb8-10">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-11">  knitr<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></div>
<div id="tbl-aggregation" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-aggregation-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;2: Equal-store, volume-weighted, fixed-weight, and filtered-population summaries.
</figcaption>
<div aria-describedby="tbl-aggregation-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<table class="cell caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 3%">
<col style="width: 12%">
<col style="width: 17%">
<col style="width: 20%">
<col style="width: 22%">
<col style="width: 10%">
<col style="width: 13%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: right;">Year</th>
<th style="text-align: right;">Stores in chain</th>
<th style="text-align: right;">Equal-store mean (cpg)</th>
<th style="text-align: right;">Current-volume mean (cpg)</th>
<th style="text-align: right;">Fixed-2024-weight mean (cpg)</th>
<th style="text-align: right;">North stores</th>
<th style="text-align: right;">North mean (cpg)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">2024</td>
<td style="text-align: right;">60</td>
<td style="text-align: right;">34.2</td>
<td style="text-align: right;">33.9</td>
<td style="text-align: right;">33.9</td>
<td style="text-align: right;">25</td>
<td style="text-align: right;">33.6</td>
</tr>
<tr class="even">
<td style="text-align: right;">2025</td>
<td style="text-align: right;">60</td>
<td style="text-align: right;">34.4</td>
<td style="text-align: right;">34.8</td>
<td style="text-align: right;">34.1</td>
<td style="text-align: right;">25</td>
<td style="text-align: right;">33.9</td>
</tr>
<tr class="odd">
<td style="text-align: right;">2026</td>
<td style="text-align: right;">60</td>
<td style="text-align: right;">34.4</td>
<td style="text-align: right;">35.6</td>
<td style="text-align: right;">34.2</td>
<td style="text-align: right;">25</td>
<td style="text-align: right;">34.1</td>
</tr>
</tbody>
</table>
</div>
</div>
</figure>
</div>
</div>
<p>For the annual table, each store’s margin is itself weighted by its weekly gallons. Weighting those annual store rates by annual volume then reproduces total chain margin dollars divided by total chain gallons. An unweighted average of weekly rates would answer a different question and need not reconcile to that ratio.</p>
</section>
<section id="give-executives-and-analysts-different-starting-points" class="level3">
<h3 class="anchored" data-anchor-id="give-executives-and-analysts-different-starting-points">Give executives and analysts different starting points</h3>
<p>An executive overview can start with a few decision-relevant metrics, trends, and distributions, then offer guided routes into exceptions. An analyst view can expose flexible dimensions, alternative measures, side-by-side subgroup comparisons, and detailed records. These are two entry points into the same underlying data, not two incompatible definitions of performance. Both views should carry the metric definition, filters, benchmark, data freshness, and coverage; readers should be able to return to the overview without losing the analysis they were exploring.</p>
<p>For the executive, the opening view should answer: what changed, how much does it matter, and where should we look? For the analyst, the next views should support asking whether the pattern persists under a different aggregation, comparison, or population. A useful control for both is to <strong>pin two selections side by side</strong>, such as highway and neighborhood stores. Keep the measure, period, and axes consistent, and show each selection’s store count and gallons. This makes the comparison inspectable without relying on memory of the chart that appeared before the last filter change.</p>
<p>A compact context strip can accompany every view: metric and units, grain, period, active filters, benchmark, included and missing units, and data refresh time. Export that context with the chart. Otherwise, a screenshot of a subgroup can circulate as if it described the entire chain.</p>
</section>
<section id="describe-a-slice-before-generalizing-from-it" class="level3">
<h3 class="anchored" data-anchor-id="describe-a-slice-before-generalizing-from-it">Describe a slice before generalizing from it</h3>
<p>“Highway stores had lower observed margin last month” describes the selected data. “Highway stores systematically underperform” generalizes beyond those observations; “highway locations cause lower margin” makes a causal claim. Filtering is useful for description. The inferential risk begins when a pattern selected after exploration is treated as a persistent effect, a forecast, or a cause. Pu and Kay distinguish exploratory tasks that retrieve or describe observed data from claims that generalize beyond those data<span class="citation" data-cites="pu2018garden"><sup>6</sup></span>.</p>
<p>For a pattern worth pursuing, save the question, filters, comparison, metric, data version, and proposed follow-up that produced it, then evaluate it with a design suited to the claim. Keep the exploratory status visible when the finding is shared. Recording the path makes it reviewable; it does not validate the conclusion or account for all the other paths considered. A later period can test whether the pattern persists, but seeing the same stores again is not an independent replication and cannot establish a causal explanation on its own.</p>
</section>
</section>
<section id="try-climbing-it-yourself" class="level2">
<h2 class="anchored" data-anchor-id="try-climbing-it-yourself">Try climbing it yourself</h2>
<!-- Progressive enhancement: everything above reads without JavaScript.
     The widget only adds reader control. -->
<div class="cell">
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ojs_define</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sales_ojs =</span> sales <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(year <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;">2026</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-2">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(store_id, wk, margin_cpg))</span>
<span id="cb9-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ojs_define</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stores_ojs =</span> store_summary)</span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb10" data-startfrom="451" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 450;"><span id="cb10-451">viewof rung <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">radio</span>(</span>
<span id="cb10-452">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1 · One store"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2 · Twelve stores"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"3 · Chain average"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4 · Store space"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb10-453">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1 · One store"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rung"</span>}</span>
<span id="cb10-454">)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb11" data-startfrom="460" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 459;"><span id="cb11-460">sales <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transpose</span>(sales_ojs)</span>
<span id="cb11-461">storesD <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transpose</span>(stores_ojs)</span>
<span id="cb11-462"></span>
<span id="cb11-463">rung <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1 · One store"</span></span>
<span id="cb11-464">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Margin (CPG)"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Week"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-465">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(sales<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">store_id</span> <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"wk"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margin_cpg"</span>})]})</span>
<span id="cb11-466"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> rung <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2 · Twelve stores"</span></span>
<span id="cb11-467">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Margin (CPG)"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Week"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-468">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb11-469">        Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(sales<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">store_id</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">store_id</span> <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-470">                   {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"wk"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margin_cpg"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"store_id"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#bbb"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-471">        Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(sales<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">store_id</span> <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"wk"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margin_cpg"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>})</span>
<span id="cb11-472">      ]})</span>
<span id="cb11-473"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> rung <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"3 · Chain average"</span></span>
<span id="cb11-474">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Margin (CPG)"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Week"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-475">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb11-476">        Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">areaY</span>(sales<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">groupX</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p25"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p75"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-477">                   {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"wk"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margin_cpg"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margin_cpg"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#ddd"</span>}))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-478">        Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(sales<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">groupX</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"wk"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"margin_cpg"</span>}))</span>
<span id="cb11-479">      ]})</span>
<span id="cb11-480">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mean margin (CPG)"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Volatility"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-481">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb11-482">        Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>(storesD<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean_margin"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"volatility"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#999"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">tip</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-483">                           <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">channels</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">store</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"store_id"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">region</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"region"</span>}})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-484">        Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>(storesD<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">store_id</span> <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-485">                 {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean_margin"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"volatility"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-486">        Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(storesD<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">store_id</span> <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-487">                  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean_margin"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"volatility"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Store 1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">dx</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>})</span>
<span id="cb11-488">      ]})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-3" data-nodetype="expression">

</div>
</div>
</div>
</div>
</section>
<section id="related-reading" class="level2">
<h2 class="anchored" data-anchor-id="related-reading">Related reading</h2>
<ul>
<li><a href="../statistics/s-values.html">S-values</a></li>
<li><!-- TODO: second statistics/ article, e.g. a multiple-comparisons or graphics post --></li>
</ul>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body" data-entry-spacing="2" data-line-spacing="2">
<div id="ref-gelman2025ladder" class="csl-entry">
1. Gelman A, Fung K. (2025). <span>“The ladder of abstraction in statistical graphics.”</span> <a href="https://sites.stat.columbia.edu/gelman/research/published/ladder.pdf">https://sites.stat.columbia.edu/gelman/research/published/ladder.pdf</a>.
</div>
<div id="ref-gelman2014forking" class="csl-entry">
2. Gelman A, Loken E. (2014). <span>“The statistical crisis in science.”</span> <em>American Scientist</em>. <strong>102</strong>:460–465. doi: <a href="https://doi.org/10.1511/2014.111.460">10.1511/2014.111.460</a>.
</div>
<div id="ref-segel2010narrative" class="csl-entry">
3. Segel E, Heer J. (2010). <span>“Narrative visualization: Telling stories with data.”</span> <em>IEEE Transactions on Visualization and Computer Graphics</em>. <strong>16</strong>:1139–1148. doi: <a href="https://doi.org/10.1109/TVCG.2010.179">10.1109/TVCG.2010.179</a>.
</div>
<div id="ref-shneiderman1996eyes" class="csl-entry">
4. Shneiderman B. (1996). <span>“The eyes have it: A task by data type taxonomy for information visualizations.”</span> In: Proceedings 1996 IEEE symposium on visual languages. p. 336–343. doi: <a href="https://doi.org/10.1109/VL.1996.545307">10.1109/VL.1996.545307</a>.
</div>
<div id="ref-zgraggen2018investigating" class="csl-entry">
5. Zgraggen E, Zhao Z, Zeleznik R, Kraska T. (2018). <span>“Investigating the effect of the multiple comparisons problem in visual analysis.”</span> In: Proceedings of the 2018 CHI conference on human factors in computing systems. doi: <a href="https://doi.org/10.1145/3173574.3174053">10.1145/3173574.3174053</a>.
</div>
<div id="ref-pu2018garden" class="csl-entry">
6. Pu X, Kay M. (2018). <span>“The garden of forking paths in visualization: A design space for reliable exploratory visual analytics.”</span> In: Proceedings of the 2018 IEEE evaluation and beyond – methodological approaches for visualization (BELIV). <a href="https://mucollective.northwestern.edu/files/2018-ForkingPaths-BELIV.pdf">https://mucollective.northwestern.edu/files/2018-ForkingPaths-BELIV.pdf</a>.
</div>
<div id="ref-kong2019trust" class="csl-entry">
7. Kong H-K, Liu Z, Karahalios K. (2019). <span>“Trust and recall of information across varying degrees of title-visualization misalignment.”</span> In: Proceedings of the 2019 CHI conference on human factors in computing systems. doi: <a href="https://doi.org/10.1145/3290605.3300576">10.1145/3290605.3300576</a>.
</div>
</div>


<!-- -->

</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>statistics</category>
  <category>visualization</category>
  <category>data analysis</category>
  <guid>https://lesslikely.com/statistics/ladder-dashboards.html</guid>
  <pubDate>Thu, 01 Oct 2026 04:00:00 GMT</pubDate>
  <media:content url="https://lesslikely.com/images/ladder-dashboards.png" medium="image" type="image/png" height="81" width="144"/>
</item>
<item>
  <title></title>
  <dc:creator>Zad Rafi</dc:creator>
  <dc:creator>Kremu </dc:creator>
  <link>https://lesslikely.com/statistics/nyc-comparator-dashboard.html</link>
  <description><![CDATA[ undefined ]]></description>
  <category>statistics</category>
  <category>causal inference</category>
  <category>interactive</category>
  <guid>https://lesslikely.com/statistics/nyc-comparator-dashboard.html</guid>
  <pubDate>Thu, 01 Oct 2026 04:00:00 GMT</pubDate>
  <media:content url="https://lesslikely.com/images/HomeLogo-static.webp" medium="image" type="image/webp"/>
</item>
<item>
  <title>How much can six months tell us? NYC comparator methods lab</title>
  <dc:creator>Zad Rafi</dc:creator>
  <dc:creator>Kremu </dc:creator>
  <link>https://lesslikely.com/statistics/nyc-comparator-lab.html</link>
  <description><![CDATA[ 





<div class="cell">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><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;">suppressPackageStartupMessages</span>({</span>
<span id="cb1-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(dplyr)</span>
<span id="cb1-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb1-4">})</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"nyc-comparator/R/rebuttal_funs.R"</span>)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"nyc-comparator/R/simulate_demo.R"</span>)</span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"nyc-comparator/R/verify_dashboard.R"</span>)</span>
<span id="cb1-8"></span>
<span id="cb1-9">DEMO <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</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;">file.exists</span>(params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>data_path)</span>
<span id="cb1-10">raw  <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;">if</span> (DEMO) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simulate_demo</span>() <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.csv</span>(params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>data_path)</span>
<span id="cb1-11">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;">prep_panel</span>(raw) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">balance_panel</span>(params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>start, params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>end)</span>
<span id="cb1-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">verify_dashboard_inputs</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"nyc-comparator"</span>, DEMO, params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>start, params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>end, params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>event, params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>focus)</span>
<span id="cb1-13"></span>
<span id="cb1-14">focus <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>focus</span>
<span id="cb1-15">event <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.Date</span>(params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>event)</span>
<span id="cb1-16">pre <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pre; n_post <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n_post</span>
<span id="cb1-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(focus <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>city)</span>
<span id="cb1-18"></span>
<span id="cb1-19">g_eq  <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;">gap_series</span>(d, focus, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"equal"</span>)</span>
<span id="cb1-20">g_pop <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;">gap_series</span>(d, focus, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pop"</span>)</span>
<span id="cb1-21"></span>
<span id="cb1-22">nyc_base_rate <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(city <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> focus, month <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> event) <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;">slice_tail</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> pre) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(rate)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>()</span>
<span id="cb1-27">pct <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>(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%+.0f%%"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> nyc_base_rate)</span>
<span id="cb1-28">pm <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>(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"±%.0f%%"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> nyc_base_rate))</span>
<span id="cb1-29">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>(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%.2f"</span>, x)</span>
<span id="cb1-30"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_set</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>))</span></code></pre></div></div>
</details>
</div>
<div class="callout callout-style-simple callout-warning">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-body-container">
<p><strong>DEMO DATA.</strong> No input file was found at the configured path, so every number below comes from a synthetic panel. These simulated numbers cannot support claims about actual NYC outcomes.</p>
<p>The bundled simulation uses seed 2026 and sets NYC’s added post-event effect to zero. Shared shocks multiply the cities’ different baseline rates, so additive level-gap parallel trends need not hold even without a policy effect. Thus, this demo combines count noise with simulated drift, seasonality and model dependence. It does not measure power to detect an observed policy effect.</p>
</div>
</div>
</div>
<p>Six months is not a lot of data. The <a href="https://cityoutcomes.com/">City Outcomes NYC Comparator Lab</a> compares New York with a set of peer cities, and its homicide tab (checked October 1, 2026) discloses limited pretrend power and the components of its uncertainty. Here, we’d like to walk through how much the answer from a design like that can move when we change the baseline, the peer weights, or the noise model.</p>
<p>This methods lab adapts material supplied by Kremu. <strong>All bundled results use simulated data</strong>, not observed NYC outcomes. Thus, it evaluates analytical choices, and it says nothing about the effects of Zohran Mamdani’s policies. We would need real data, and a reconciliation with that tab, before calling any of this an empirical replication or refutation.</p>
<p>There is also an <a href="../statistics/nyc-comparator-dashboard.html">interactive dashboard</a> that runs the same estimators. If some of the terms below are unfamiliar, the posts on <a href="../statistics/s-values.html">S-values</a> and <a href="../statistics/assumptions.html">model assumptions</a> cover the background.</p>
<section id="what-this-document-does-and-does-not-claim" class="level2">
<h2 class="anchored" data-anchor-id="what-this-document-does-and-does-not-claim">What this document does and does not claim</h2>
<p>It <strong>does not</strong> claim the new administration changed homicide in either direction.</p>
<p>What it does is show how baseline choices, weighting, placebo comparisons, and assumed drift change an analysis. However, with synthetic inputs, it cannot test the site’s empirical conclusion.</p>
</section>
<section id="fixed-primary-specification" class="level2">
<h2 class="anchored" data-anchor-id="fixed-primary-specification">Fixed primary specification</h2>
<p>These are the analysis choices that came with the supplied material. No timestamped registration record was included, so we don’t claim preregistration here. Still, fixing one specification up front helps us tell the primary calculation apart from the exploratory settings.</p>
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th>Choice</th>
<th>Value</th>
<th>Why</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Outcome</td>
<td>Monthly homicide rate per 100k</td>
<td>The site’s headline tab</td>
</tr>
<tr class="even">
<td>Event date</td>
<td>Jan 2026</td>
<td>Same as the site</td>
</tr>
<tr class="odd">
<td>Post window</td>
<td>6 months</td>
<td>All available data</td>
</tr>
<tr class="even">
<td>Primary baseline</td>
<td>Mean of the last 12 pre-event months</td>
<td>A single-month baseline is noisy</td>
</tr>
<tr class="odd">
<td>Replication baseline</td>
<td>t−1 only, equal weights</td>
<td>Matches the conventional baseline and weighting rule; real-data replication remains unverified</td>
</tr>
<tr class="even">
<td>Peer weights</td>
<td>Equal (primary) and population-pooled</td>
<td>The site uses equal</td>
</tr>
<tr class="odd">
<td>Diagnostics</td>
<td>Placebo ranks, three noise summaries and a historical-window sensitivity</td>
<td>One treated unit</td>
</tr>
<tr class="even">
<td>Sensitivity</td>
<td>Year-over-year seasonal check; linear-drift tipping point</td>
<td>Pretrend power is low</td>
</tr>
</tbody>
</table>
</section>
<section id="demonstrating-the-conventional-estimator" class="level2">
<h2 class="anchored" data-anchor-id="demonstrating-the-conventional-estimator">1. Demonstrating the conventional estimator</h2>
<div class="cell">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><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">site_est <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;">did_estimate</span>(g_eq, event, pre, n_post, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">baseline =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"last"</span>)</span>
<span id="cb2-2">ep <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;">event_path</span>(g_eq, event) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(rel_month <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</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;">48</span>)</span>
<span id="cb2-3">latest <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;">tail</span>(ep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>effect, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div></div>
</details>
</div>
<p>Let’s start with the conventional estimator. Using the site’s method (equal-weighted peers, rebased to t−1), the mean post-period change in the NYC–peer gap relative to December 2025 is <strong>0.03</strong> per 100k/month. The latest single-month gap change is <strong>0.07</strong>.</p>
<div class="cell">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><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;">ggplot</span>(ep, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(rel_month, effect)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</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;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey60"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-3">  <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="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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</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-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</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;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-5">  <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;">"Months relative to event"</span>, <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;">"NYC minus peers (per 100k)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-event" class="quarto-float quarto-figure quarto-figure-center anchored" alt="Synthetic focal-city minus peer-rate changes relative to December 2025.">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-event-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://lesslikely.com/statistics/nyc-comparator-lab_files/figure-html/fig-event-1.png" class="img-fluid figure-img" alt="Synthetic focal-city minus peer-rate changes relative to December 2025." width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-event-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Synthetic event-study path (rebased so t−1 = 0).
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="the-point-estimate-depends-on-unforced-choices" class="level2">
<h2 class="anchored" data-anchor-id="the-point-estimate-depends-on-unforced-choices">2. The point estimate depends on unforced choices</h2>
<div class="cell">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><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">variants <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tibble<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;">tibble</span>(</span>
<span id="cb4-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Specification =</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;">"Site: t-1 baseline, equal weights"</span>,</span>
<span id="cb4-3">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"12-month mean baseline, equal weights (primary)"</span>,</span>
<span id="cb4-4">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"12-month mean baseline, population weights"</span>,</span>
<span id="cb4-5">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"6-month mean baseline, equal weights"</span>,</span>
<span id="cb4-6">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"24-month mean baseline, equal weights"</span>,</span>
<span id="cb4-7">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year-over-year, same months (seasonality-robust)"</span>),</span>
<span id="cb4-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Estimate =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(site_est,</span>
<span id="cb4-9">               <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">did_estimate</span>(g_eq,  event, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, n_post),</span>
<span id="cb4-10">               <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">did_estimate</span>(g_pop, event, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, n_post),</span>
<span id="cb4-11">               <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">did_estimate</span>(g_eq,  event, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,  n_post),</span>
<span id="cb4-12">               <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">did_estimate</span>(g_eq,  event, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>, n_post),</span>
<span id="cb4-13">               <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">yoy_estimate</span>(g_eq, event, n_post))</span>
<span id="cb4-14">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <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;">% of NYC baseline</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pct</span>(Estimate))</span>
<span id="cb4-15">knitr<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>(variants <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <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;">Estimate =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f2</span>(Estimate)))</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 64%">
<col style="width: 11%">
<col style="width: 23%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Specification</th>
<th style="text-align: left;">Estimate</th>
<th style="text-align: left;">% of NYC baseline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Site: t-1 baseline, equal weights</td>
<td style="text-align: left;">0.03</td>
<td style="text-align: left;">+9%</td>
</tr>
<tr class="even">
<td style="text-align: left;">12-month mean baseline, equal weights (primary)</td>
<td style="text-align: left;">0.00</td>
<td style="text-align: left;">+1%</td>
</tr>
<tr class="odd">
<td style="text-align: left;">12-month mean baseline, population weights</td>
<td style="text-align: left;">-0.06</td>
<td style="text-align: left;">-18%</td>
</tr>
<tr class="even">
<td style="text-align: left;">6-month mean baseline, equal weights</td>
<td style="text-align: left;">0.06</td>
<td style="text-align: left;">+18%</td>
</tr>
<tr class="odd">
<td style="text-align: left;">24-month mean baseline, equal weights</td>
<td style="text-align: left;">0.02</td>
<td style="text-align: left;">+6%</td>
</tr>
<tr class="even">
<td style="text-align: left;">Year-over-year, same months (seasonality-robust)</td>
<td style="text-align: left;">-0.05</td>
<td style="text-align: left;">-16%</td>
</tr>
</tbody>
</table>
</div>
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><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">primary <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;">did_estimate</span>(g_eq, event, pre, n_post)</span></code></pre></div></div>
</details>
</div>
<p>NYC’s baseline rate is <strong>0.32</strong> per 100k per month. As we can see from the table, the estimate depends on choices that nothing forces on us. That spread across defensible specifications is itself a form of uncertainty, and the illustrative intervals below condition on whichever specification was chosen.</p>
<p>A note on the percentage column. It divides the estimated change in the NYC–peer gap by NYC’s 12-month baseline rate, so it should not be read as NYC’s own percentage rate change (both NYC and peer rates enter the contrast). Thus, a value below −100% can occur even when every homicide rate is nonnegative.</p>
</section>
<section id="how-big-an-effect-could-six-months-detect" class="level2">
<h2 class="anchored" data-anchor-id="how-big-an-effect-could-six-months-detect">3. How big an effect could six months detect?</h2>
<p>With a single treated unit, the variance model does most of the work. The site’s methodology, checked October 1, 2026, discloses cross-peer variation, Poisson count variance, and Newey–West slope uncertainty. We don’t reproduce its full interval calculation here. Instead, here’s a table of three illustrative noise summaries and a historical-window sensitivity:</p>
<div class="cell">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><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">fake <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;">seq</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2019-01-01"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.Date</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2025-01-01"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>)</span>
<span id="cb6-2">itp  <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;">in_time_placebos</span>(g_eq, fake, pre, n_post)</span>
<span id="cb6-3">isp  <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;">in_space_placebos</span>(d, event, pre, n_post, params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>noise_window)</span>
<span id="cb6-4">n_itp <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;">sum</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;">is.na</span>(itp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate))</span>
<span id="cb6-5"></span>
<span id="cb6-6">se_tbl <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tibble<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;">tibble</span>(</span>
<span id="cb6-7">  <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;">Variance model</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Focal count-only component (independent Poisson reference)"</span>,</span>
<span id="cb6-8">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NYC's own in-time placebos"</span>,</span>
<span id="cb6-9">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cross-city placebo spread (alternative diagnostic)"</span>,</span>
<span id="cb6-10">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Own history omitting 2020–2023 events (sensitivity)"</span>),</span>
<span id="cb6-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE =</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;">poisson_se</span>(d, focus, event, pre, n_post),</span>
<span id="cb6-12">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(itp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate, <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>
<span id="cb6-13">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(isp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate[isp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>city <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> focus], <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>
<span id="cb6-14">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(itp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(itp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>fake_event, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%Y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</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;">"2019"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2024"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2025"</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>
<span id="cb6-15">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-16">  <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;">Normal reference band (±1.96 × summary)</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%s to %s"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f2</span>(primary <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.96</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> SE), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f2</span>(primary <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.96</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> SE)),</span>
<span id="cb6-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;">MDE (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> <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;">mde</span>(SE)),</span>
<span id="cb6-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;">MDE as % of NYC baseline</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mde</span>(SE)))</span>
<span id="cb6-19">knitr<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>(se_tbl <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <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;">SE =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f2</span>(SE)))</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 40%">
<col style="width: 3%">
<col style="width: 27%">
<col style="width: 11%">
<col style="width: 17%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Variance model</th>
<th style="text-align: left;">SE</th>
<th style="text-align: left;">Normal reference band (±1.96 × summary)</th>
<th style="text-align: left;">MDE (80% power)</th>
<th style="text-align: left;">MDE as % of NYC baseline</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Focal count-only component (independent Poisson reference)</td>
<td style="text-align: left;">0.03</td>
<td style="text-align: left;">-0.05 to 0.06</td>
<td style="text-align: left;">0.08</td>
<td style="text-align: left;">±26%</td>
</tr>
<tr class="even">
<td style="text-align: left;">NYC’s own in-time placebos</td>
<td style="text-align: left;">0.12</td>
<td style="text-align: left;">-0.23 to 0.23</td>
<td style="text-align: left;">0.33</td>
<td style="text-align: left;">±103%</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Cross-city placebo spread (alternative diagnostic)</td>
<td style="text-align: left;">0.28</td>
<td style="text-align: left;">-0.55 to 0.56</td>
<td style="text-align: left;">0.79</td>
<td style="text-align: left;">±249%</td>
</tr>
<tr class="even">
<td style="text-align: left;">Own history omitting 2020–2023 events (sensitivity)</td>
<td style="text-align: left;">0.03</td>
<td style="text-align: left;">-0.05 to 0.06</td>
<td style="text-align: left;">0.08</td>
<td style="text-align: left;">±26%</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The minimum detectable effect (MDE) shown here is a normal-approximation planning calculation for 80% power at a two-sided 5% threshold, conditional on the chosen standard error and model. Smaller effects would be detected less often. However, these approximate summaries do not establish the actual power of the site’s design.</p>
<p>These summaries measure different sources of variation. The count-only component excludes peer counts and dependence. The in-time spread includes count variation and historical change, while the cross-city spread also includes differences between cities. Thus, we treat the bands as descriptive normal references (±1.96 times each summary), without demonstrated 95% coverage. The sensitivity row uses only the 2019, 2024 and 2025 events. It exposes the consequence of omitting 2020–2023 events, but does not establish that three draws provide a better reference. Choosing that summary also changes the approximate MDE and compatibility curve.</p>
<p>Differences in city size can create heteroskedasticity and distort inference with few treated groups<span class="citation" data-cites="ferman2019"><sup>1</sup></span>. That said, this synthetic example does not establish that the site’s intervals overstate NYC uncertainty. The in-time placebos use NYC’s own history, which seems like the most relevant reference, but there are only 7 draws, so we should treat that SE as rough. The intervals above also use the normal multiplier 1.96. An illustrative <em>t</em> reference with 6 degrees of freedom and the same SD would use 2.45 instead, which widens the in-time interval by about 25%. The placebo windows overlap from one year to the next as well, so the draws are not independent, and the <em>t</em> reference should not be taken as a validated correction.</p>
</section>
<section id="which-effect-sizes-are-compatible-with-the-data" class="level2">
<h2 class="anchored" data-anchor-id="which-effect-sizes-are-compatible-with-the-data">4. Which effect sizes are compatible with the data?</h2>
<div class="cell">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><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">se_mid <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> se_tbl<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;">2</span>]</span>
<span id="cb7-2">hyp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> nyc_base_rate <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;">c</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 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.25</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>)</span>
<span id="cb7-3">sv <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;">s_values</span>(primary, se_mid, hyp) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-4">  <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;">Hypothesized change</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pct</span>(hypothesis),</span>
<span id="cb7-5">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%.2f"</span>, p), <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;">S-value (bits)</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%.1f"</span>, s_bits)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</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;">Hypothesized change</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>, p, <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;">S-value (bits)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)</span>
<span id="cb7-7">knitr<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>(sv)</span></code></pre></div></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: left;">Hypothesized change</th>
<th style="text-align: left;">p</th>
<th style="text-align: left;">S-value (bits)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">-50%</td>
<td style="text-align: left;">0.16</td>
<td style="text-align: left;">2.6</td>
</tr>
<tr class="even">
<td style="text-align: left;">-25%</td>
<td style="text-align: left;">0.48</td>
<td style="text-align: left;">1.1</td>
</tr>
<tr class="odd">
<td style="text-align: left;">+0%</td>
<td style="text-align: left;">0.98</td>
<td style="text-align: left;">0.0</td>
</tr>
<tr class="even">
<td style="text-align: left;">+25%</td>
<td style="text-align: left;">0.51</td>
<td style="text-align: left;">1.0</td>
</tr>
<tr class="odd">
<td style="text-align: left;">+50%</td>
<td style="text-align: left;">0.18</td>
<td style="text-align: left;">2.5</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The table uses NYC’s in-time SE. An S-value of <em>s</em> bits is about as surprising as seeing <em>s</em> heads in a row from a fair coin (the <a href="../statistics/s-values.html">S-values post</a> goes through this in detail). An S-value below 2 bits corresponds to a <em>P</em>-value above 0.25 under the stated normal model. It is NOT the probability that a hypothesis is true.</p>
<div class="cell">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><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">grid <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;">seq</span>(primary <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;">4</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;">max</span>(se_tbl<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SE), primary <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;">4</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;">max</span>(se_tbl<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;">length.out =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">400</span>)</span>
<span id="cb8-2">curves <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;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(se_tbl)), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(i)</span>
<span id="cb8-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">model =</span> se_tbl<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;">Variance model</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>[i], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">h =</span> grid,</span>
<span id="cb8-4">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">s_values</span>(primary, se_tbl<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SE[i], grid)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>()</span>
<span id="cb8-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(curves, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(h, p, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> model)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</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;">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="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey60"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-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;">"Hypothesized effect (per 100k/month)"</span>, <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;">"p-value"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</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="cb8-8">  <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;">"bottom"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.direction =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"vertical"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-curve" class="quarto-float quarto-figure quarto-figure-center anchored" alt="Compatibility curves under four illustrative noise summaries, including a historical-window sensitivity.">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-curve-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://lesslikely.com/statistics/nyc-comparator-lab_files/figure-html/fig-curve-1.png" class="img-fluid figure-img" alt="Compatibility curves under four illustrative noise summaries, including a historical-window sensitivity." width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-curve-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: P-value (compatibility) function for the primary estimate under each variance model.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="is-nyc-unusual-among-its-peers-in-space-permutation" class="level2">
<h2 class="anchored" data-anchor-id="is-nyc-unusual-among-its-peers-in-space-permutation">5. Is NYC unusual among its peers? (in-space permutation)</h2>
<div class="cell">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><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">nyc_row  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> isp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(city <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> focus)</span>
<span id="cb9-2">p_ratio  <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;">perm_p</span>(isp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ratio, nyc_row<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ratio)</span>
<span id="cb9-3">p_est    <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;">perm_p</span>(isp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> isp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pre_rmspe, nyc_row<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> nyc_row<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pre_rmspe)</span>
<span id="cb9-4">rank_r   <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;">rank</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;">replace</span>(isp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ratio, <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;">is.finite</span>(isp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ratio), <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA_real_</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ties.method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"min"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.last =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"keep"</span>)[isp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>city <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> focus]</span></code></pre></div></div>
</details>
</div>
<p>Each city takes a turn as the focus against all other cities, so NYC remains in a peer city’s comparator pool. Both RMSPE windows use that city’s pre-baseline mean as their center, with a 24-month pre noise window. We retain this descriptive leave-one-out diagnostic, but a real treatment effect could also enter placebo comparator pools.</p>
<p>Among 30 finite ratios, NYC ranks <strong>16</strong>. The upper-tail ratio share is <strong>0.53</strong>, and the two-sided share for the standardized estimate is <strong>0.97</strong>. The ratio share has a floor of 1/30 when the focal ratio is finite and included. These are descriptive rankings, which are a long way from a fitted synthetic-control or calibrated randomization analysis.</p>
<div class="cell">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(isp, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(city, ratio), ratio, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> city <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> focus)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-2">  <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 class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_flip</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-3">  <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;">"grey70"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"firebrick"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">guide =</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="cb10-4">  <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="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>, <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;">"Post / pre RMSPE"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-perm" class="quarto-float quarto-figure quarto-figure-center anchored" alt="Synthetic cities ranked by post-period to pre-period RMSPE ratio.">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-perm-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://lesslikely.com/statistics/nyc-comparator-lab_files/figure-html/fig-perm-1.png" class="img-fluid figure-img" alt="Synthetic cities ranked by post-period to pre-period RMSPE ratio." width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-perm-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: Post/pre RMSPE ratio for every city treated as the focus.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="is-january-2026-unusual-in-nycs-own-history-in-time-placebos" class="level2">
<h2 class="anchored" data-anchor-id="is-january-2026-unusual-in-nycs-own-history-in-time-placebos">6. Is January 2026 unusual in NYC’s own history? (in-time placebos)</h2>
<div class="cell">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><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">itp_plot <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>(itp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <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;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Placebo"</span>),</span>
<span id="cb11-2">                      tibble<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;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fake_event =</span> event, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> primary, <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;">"Actual"</span>))</span>
<span id="cb11-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(itp_plot, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(fake_event, estimate, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> type)) <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;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</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;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey60"</span>) <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_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</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>
<span id="cb11-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_colour_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="at" style="color: #657422;
background-color: null;
font-style: inherit;">Actual =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"firebrick"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Placebo =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey40"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-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;">"Event date"</span>, <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;">"DiD estimate (per 100k/month)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)</span>
<span id="cb11-8">p_time <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;">perm_p</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(itp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate, primary), primary)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-itp" class="quarto-float quarto-figure quarto-figure-center anchored" alt="Synthetic estimates at January placebo dates and the analysis date.">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-itp-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://lesslikely.com/statistics/nyc-comparator-lab_files/figure-html/fig-itp-1.png" class="img-fluid figure-img" alt="Synthetic estimates at January placebo dates and the analysis date." width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-itp-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: NYC estimate at fake January event dates vs the real one.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Across 8 January start dates (the analysis date included), the share with an estimate at least as large in magnitude as the analysis-date estimate is <strong>1.00</strong>. Missing-window estimates are excluded from both the share and its denominator. However, the 2020–2023 event windows include simulated pandemic-era shocks, so the sensitivity row above shows the spread after omitting them. The 2025 placebo’s post window also overlaps the primary baseline, making these draws dependent.</p>
</section>
<section id="how-much-trend-violation-would-flip-the-reading" class="level2">
<h2 class="anchored" data-anchor-id="how-much-trend-violation-would-flip-the-reading">7. How much trend violation would flip the reading?</h2>
<div class="cell">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><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">sl  <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;">pre_slope</span>(g_eq, event, params<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>noise_window)</span>
<span id="cb12-2">lag <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;">trend_lag</span>(pre, n_post)</span>
<span id="cb12-3">delta_grid <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;">seq</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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</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;">121</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;">max</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(sl[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope"</span>]), sl[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"se"</span>])</span>
<span id="cb12-4">adj <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;">drift_adjust</span>(primary, se_mid, delta_grid, lag)</span>
<span id="cb12-5">breakdown <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> primary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> lag</span></code></pre></div></div>
</details>
</div>
<p>The pre-period slope of the gap is <strong>0.0002</strong> per month (naive OLS SE 0.0038; its ±1.96 × SE reference runs from -0.0073 to 0.0077), and the baseline and post midpoints are 9 months apart. This reference ignores serial correlation and has no demonstrated coverage. Thus, a differential drift of just <strong>0.0004</strong> per month would fully account for the point estimate.</p>
<div class="cell">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(adj, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(delta, estimate)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-2">  <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;">"rect"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> sl[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope"</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.96</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sl[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"se"</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> sl[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope"</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.96</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sl[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"se"</span>],</span>
<span id="cb13-3">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</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;">ymax =</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;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_ribbon</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;">ymin =</span> lo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> hi), <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.25</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</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;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</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;">linetype =</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="cb13-6">  <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;">"Assumed drift (per 100k per month)"</span>, <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;">"Adjusted estimate"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-trend" class="quarto-float quarto-figure quarto-figure-center anchored" alt="Adjusted synthetic estimate and interval across assumed linear drifts.">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-trend-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://lesslikely.com/statistics/nyc-comparator-lab_files/figure-html/fig-trend-1.png" class="img-fluid figure-img" alt="Adjusted synthetic estimate and interval across assumed linear drifts." width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-trend-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: Estimate after removing an assumed linear differential drift. Shaded: naive OLS slope reference (±1.96 SE), ignoring serial correlation.
</figcaption>
</figure>
</div>
</div>
</div>
<p>This is a linear drift scenario, motivated by work on sensitivity to parallel-trend violations<span class="citation" data-cites="rambachan2023"><sup>2</sup></span>. It does not implement <code>HonestDiD</code>, and it does not propagate uncertainty in the assumed drift.</p>
</section>
<section id="scorecard" class="level2">
<h2 class="anchored" data-anchor-id="scorecard">8. Scorecard</h2>
<div class="cell">
<details class="code-fold">
<summary>Show code</summary>
<div class="code-copy-outer-scaffold"><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">tibble<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;">tibble</span>(</span>
<span id="cb14-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Check =</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;">"Conventional estimator"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Specification spread (six report choices)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Approximate MDE (in-time summary)"</span>,</span>
<span id="cb14-3">            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Permutation rank"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"In-time rank"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Drift breakdown"</span>),</span>
<span id="cb14-4">  <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;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f2</span>(site_est),</span>
<span id="cb14-5">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%s to %s"</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;">min</span>(variants<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Estimate, <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>
<span id="cb14-6">                     <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;">max</span>(variants<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Estimate, <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>
<span id="cb14-7">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mde</span>(se_mid)),</span>
<span id="cb14-8">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%d / %d (tail share = %.2f)"</span>, rank_r, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.finite</span>(isp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ratio)), p_ratio),</span>
<span id="cb14-9">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p = %.2f"</span>, p_time),</span>
<span id="cb14-10">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%.4f per month"</span>, breakdown))</span>
<span id="cb14-11">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> knitr<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></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 60%">
<col style="width: 40%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Check</th>
<th style="text-align: left;">Result</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Conventional estimator</td>
<td style="text-align: left;">0.03</td>
</tr>
<tr class="even">
<td style="text-align: left;">Specification spread (six report choices)</td>
<td style="text-align: left;">-0.06 to 0.06</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Approximate MDE (in-time summary)</td>
<td style="text-align: left;">±103%</td>
</tr>
<tr class="even">
<td style="text-align: left;">Permutation rank</td>
<td style="text-align: left;">16 / 30 (tail share = 0.53)</td>
</tr>
<tr class="odd">
<td style="text-align: left;">In-time rank</td>
<td style="text-align: left;">p = 1.00</td>
</tr>
<tr class="even">
<td style="text-align: left;">Drift breakdown</td>
<td style="text-align: left;">0.0004 per month</td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
<section id="limitations-of-this-methods-demonstration" class="level2">
<h2 class="anchored" data-anchor-id="limitations-of-this-methods-demonstration">Limitations of this methods demonstration</h2>
<ul>
<li>We were not given a real homicide input file or a preregistration record. Thus, no empirical replication or policy-effect conclusion has been established.</li>
<li>Placebo ranks require exchangeability to be interpreted as calibrated <em>P</em>-values. Cities and historical dates are not randomly assigned, so we treat these ranks as descriptive diagnostics. The normal intervals and MDEs condition on illustrative variance models.</li>
<li>We only cover homicide. Other outcomes would need separate checks of their measurement, geography, timing and comparator definitions.</li>
<li>Council on Criminal Justice (CCJ) mid-year data are preliminary and subject to revision, so it’s worth recording the date the data were pulled.</li>
<li>The permutation p has a floor of 1/N. The in-time placebos have few draws.</li>
<li>The linear-drift calculation is illustrative and does not implement HonestDiD robust inference.</li>
</ul>
<p>As a rule, we’d look to the whole specification table and the interval estimates before any single point estimate, and we’d hold off on any reading of the real site until the real data have been run through the same checks.</p>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body" data-entry-spacing="2" data-line-spacing="2">
<div id="ref-ferman2019" class="csl-entry">
1. Ferman B, Pinto C. (2019). <span>“Inference in differences-in-differences with few treated groups and heteroskedasticity.”</span> <em>The Review of Economics and Statistics</em>. <strong>101</strong>:452–467. doi: <a href="https://doi.org/10.1162/rest_a_00759">10.1162/rest_a_00759</a>.
</div>
<div id="ref-rambachan2023" class="csl-entry">
2. Rambachan A, Roth J. (2023). <span>“A more credible approach to parallel trends.”</span> <em>The Review of Economic Studies</em>. <strong>90</strong>:2555–2591. doi: <a href="https://doi.org/10.1093/restud/rdad018">10.1093/restud/rdad018</a>.
</div>
</div>


<!-- -->

</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>statistics</category>
  <category>causal inference</category>
  <category>interactive</category>
  <guid>https://lesslikely.com/statistics/nyc-comparator-lab.html</guid>
  <pubDate>Thu, 01 Oct 2026 04:00:00 GMT</pubDate>
  <media:content url="https://lesslikely.com/images/HomeLogo-static.webp" medium="image" type="image/webp"/>
</item>
<item>
  <title>The P-value Is Not a Verdict: An Interactive Consonance Curve</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/statistics/consonance-explorer.html</link>
  <description><![CDATA[ 





<p>A single <em>P</em>-value gives us one number about one hypothesis. The <em>P-value function</em> takes the same test statistic and applies it to <strong>every</strong> candidate parameter value at once, and (as a result) it contains every compatibility interval at every level as a horizontal slice.<sup>1</sup> None of the mathematics below is new. It is the usual normal approximation that most of us already rely on, except that here we draw it in full instead of evaluating it at one point.</p>
<div class="no-row-height column-margin column-container"><div id="fn1"><p><sup>1</sup>&nbsp;If we slice the curve at height <img src="https://latex.codecogs.com/png.latex?p%20=%200.05"> and read off the x-coordinates, we get the 95% limits. If we slice at <img src="https://latex.codecogs.com/png.latex?p%20=%200.01">, we get the 99% limits. Thus, the interval was never a separate calculation.</p></div></div><p>The display itself is quite old. Poole called for it in 1987<span class="citation" data-cites="poole1987"><sup>1</sup></span>, Sullivan and Foster catalogued its uses in 1990<span class="citation" data-cites="sullivan1990"><sup>2</sup></span>, and it has sat in <em>Modern Epidemiology</em> ever since. So what has changed? For one, it now costs nothing to render. We also have what I think is a better vocabulary for the vertical axis, where we speak of <strong>compatibility</strong> in place of confidence and <strong>surprisal</strong> in place of significance<span class="citation" data-cites="rafi2020"><sup>3</sup></span>.</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">
<span class="screen-reader-only">Tip</span>Definitions, once
</div>
</div>
<div class="callout-body-container callout-body">
<p>A <strong>P-value function</strong> (equivalently, a consonance or compatibility curve) plots, for every candidate parameter value <img src="https://latex.codecogs.com/png.latex?%5Cmu">, the P-value from testing <img src="https://latex.codecogs.com/png.latex?%5Cmu"> against the data under the full set of analysis assumptions.</p>
<p>An <strong>S-value</strong> is the Shannon transform <img src="https://latex.codecogs.com/png.latex?s%20=%20-%5Clog_2%20p">: the number of consecutive heads from a fair coin that would be exactly as surprising as the observed test statistic, if <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and every other assumption were correct.</p>
<p>A <strong>95% compatibility interval</strong> is the set of <img src="https://latex.codecogs.com/png.latex?%5Cmu"> whose P-value exceeds 0.05. It is a horizontal slice through the curve, so we don’t need to treat it as a separate object.</p>
</div>
</div>
<section id="the-explorer" class="level2">
<h2 class="anchored" data-anchor-id="the-explorer">The explorer</h2>
<p>Let’s start with the explorer itself. When we move the sliders, everything recomputes in the browser (there is no server involved).</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb1" data-startfrom="37" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 36;"><span id="cb1-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Observable Plot's tip/pointer marks need &gt;= 0.6.11; Quarto embeds an older</span></span>
<span id="cb1-38"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// build, so pin an explicit version. See README for how to vendor this locally</span></span>
<span id="cb1-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// if you'd rather not depend on a CDN at page load.</span></span>
<span id="cb1-40">Plot <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://cdn.jsdelivr.net/npm/@observablehq/plot@0.6/+esm"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb2" data-startfrom="45" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 44;"><span id="cb2-45"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> { consonanceCurve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> testValue<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> seFromRatioCI } <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"./ojs/stats.js"</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb3" data-startfrom="50" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 49;"><span id="cb3-50"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Inverse standard normal CDF (Acklam's rational approximation; |error| &lt; 4e-9</span></span>
<span id="cb3-51"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// over the levels used here, verified against scipy).</span></span>
<span id="cb3-52"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//</span></span>
<span id="cb3-53"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// </span><span class="al" style="color: #AD0000;
background-color: null;
font-style: inherit;">TODO</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(stats.js): seFromRatioCI already needs this internally. Export it from</span></span>
<span id="cb3-54"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// ./ojs/stats.js and delete this cell rather than maintaining two copies.</span></span>
<span id="cb3-55">zq <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> (L) {</span>
<span id="cb3-56">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> p <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> L) <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-57">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.969683028665376e+01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.209460984245205e+02</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.759285104469687e+02</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-58">             <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.383577518672690e+02</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.066479806614716e+01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.506628277459239e+00</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-59">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.447609879822406e+01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.615858368580409e+02</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.556989798598866e+02</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-60">             <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.680131188771972e+01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.328068155288572e+01</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-61">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">7.784894002430293e-03</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.223964580411365e-01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.400758277161838e+00</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-62">             <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.549732539343734e+00</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.374664141464968e+00</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.938163982698783e+00</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-63">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">7.784695709041462e-03</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.224671290700398e-01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.445134137142996e+00</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-64">             <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.754408661907416e+00</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-65">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> lo <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02425</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> hi <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> lo<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-66">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-67">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> lo) {</span>
<span id="cb3-68">    q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" 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="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(p))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-69">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> (((((c[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>c[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>c[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>c[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>c[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>c[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb3-70">           ((((d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-71">  }</span>
<span id="cb3-72">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> hi) {</span>
<span id="cb3-73">    q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> p <span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-74">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> (((((a[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>a[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>a[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>a[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>a[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>a[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb3-75">           (((((b[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>b[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>b[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>b[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>b[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>r<span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-76">  }</span>
<span id="cb3-77">  q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" 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="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> p))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-78">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(((((c[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>c[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>c[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>c[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>c[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>c[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb3-79">          ((((d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q<span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb3-80">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb4" data-startfrom="85" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 84;"><span id="cb4-85">viewof est <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb4-86">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Point estimate (rate ratio)"</span></span>
<span id="cb4-87">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb5" data-startfrom="92" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 91;"><span id="cb5-92">viewof cir <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.05</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb5-93">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.60</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Interval ratio (upper ÷ lower)"</span></span>
<span id="cb5-94">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb6" data-startfrom="99" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 98;"><span id="cb6-99">viewof mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb6-100">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Value being tested (μ)"</span></span>
<span id="cb6-101">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb7" data-startfrom="106" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 105;"><span id="cb7-106">viewof level <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.50</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.995</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb7-107">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.005</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Compatibility level to slice at"</span></span>
<span id="cb7-108">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb8" data-startfrom="113" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 112;"><span id="cb8-113"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Parameterising by the interval *ratio* rather than by two independent limits</span></span>
<span id="cb8-114"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// guarantees the interval always brackets the estimate — one less way for a</span></span>
<span id="cb8-115"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// reader to produce a nonsensical figure.</span></span>
<span id="cb8-116">limits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ({</span>
<span id="cb8-117">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> est <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(cir)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb8-118">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> est <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(cir)</span>
<span id="cb8-119">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-8" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb9" data-startfrom="124" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 123;"><span id="cb9-124">se <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seFromRatioCI</span>(limits<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> limits<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-9" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb10" data-startfrom="129" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 128;"><span id="cb10-129"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// The slice at an arbitrary level, derived from the same SE. This is the whole</span></span>
<span id="cb10-130"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// claim of footnote 1 made draggable: the interval is a horizontal cut, not a</span></span>
<span id="cb10-131"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// second computation.</span></span>
<span id="cb10-132">slice <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ({</span>
<span id="cb10-133">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">p</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> level<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb10-134">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> est <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">zq</span>(level) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> se)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb10-135">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> est <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">zq</span>(level) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> se)</span>
<span id="cb10-136">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-10" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb11" data-startfrom="141" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 140;"><span id="cb11-141">curve <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">consonanceCurve</span>(est<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> se<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">from</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">to</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">600</span>})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-11" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb12" data-startfrom="146" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 145;"><span id="cb12-146">atMu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">testValue</span>(est<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> se<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> mu)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-12" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb13" data-startfrom="151" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 150;"><span id="cb13-151"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div style="</span></span>
<span id="cb13-152"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  border-left: 3px solid currentColor;</span></span>
<span id="cb13-153"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  padding: 0.6em 1em;</span></span>
<span id="cb13-154"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  margin: 1.2em 0;</span></span>
<span id="cb13-155"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  font-size: 0.95em;</span></span>
<span id="cb13-156"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  line-height: 1.7;</span></span>
<span id="cb13-157"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;</span></span>
<span id="cb13-158"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>est<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt;</span></span>
<span id="cb13-159"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  (95% compatibility interval</span></span>
<span id="cb13-160"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>limits<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt; to</span></span>
<span id="cb13-161"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>limits<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt;)</span></span>
<span id="cb13-162"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;br&gt;</span></span>
<span id="cb13-163"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  Testing μ = &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>mu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt;:</span></span>
<span id="cb13-164"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;em&gt;P&lt;/em&gt; = &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>atMu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> atMu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toExponential</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> atMu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt;,</span></span>
<span id="cb13-165"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;em&gt;S&lt;/em&gt; = &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>atMu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> bits&lt;/strong&gt;</span></span>
<span id="cb13-166"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;br&gt;</span></span>
<span id="cb13-167"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;span style="opacity:0.75"&gt;</span></span>
<span id="cb13-168"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    The data are no more surprising against μ = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>mu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> than</span></span>
<span id="cb13-169"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>atMu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> consecutive heads from a fair coin.</span></span>
<span id="cb13-170"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;/span&gt;</span></span>
<span id="cb13-171"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;br&gt;</span></span>
<span id="cb13-172"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;span style="opacity:0.75"&gt;</span></span>
<span id="cb13-173"><span class="vs" 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;">100</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> level)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">% slice (at &lt;em&gt;P&lt;/em&gt; = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>slice<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">):</span></span>
<span id="cb13-174"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>slice<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt; to</span></span>
<span id="cb13-175"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>slice<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt;</span></span>
<span id="cb13-176"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;/span&gt;</span></span>
<span id="cb13-177"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/div&gt;`</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-13" data-nodetype="expression">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb14" data-startfrom="182" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 181;"><span id="cb14-182">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb14-183">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">280</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-184">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginLeft</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-185">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginBottom</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-186">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"13px"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-187">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rate ratio →"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">ticks</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span><span class="op" 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="op" 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 class="op" 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="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">tickFormat</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-188">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"↑ P-value"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">percent</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-189">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb14-190">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">areaY</span>(curve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-191">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(curve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-192">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// The draggable slice, drawn as a segment between the two limits rather</span></span>
<span id="cb14-193">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// than a full-width rule: the horizontal extent *is* the interval.</span></span>
<span id="cb14-194">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([slice<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"3 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-195">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">link</span>([slice]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lower"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"upper"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.85</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-196">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>([{<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> slice<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> slice<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> slice<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> slice<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span>}]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-197">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>([{<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.42</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> slice<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span>}]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="vs" 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;">100</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> level)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">% slice`</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">dy</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textAnchor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-198">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.55</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-199">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([mu]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-200">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>([atMu]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.5</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-201">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tip</span>(curve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pointerX</span>({</span>
<span id="cb14-202">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-203">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> [</span>
<span id="cb14-204">        <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Rate ratio  </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-205">        <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`P-value     </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toExponential</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-206">        <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`S-value     </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> bits`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb14-207">        <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Sits on the </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;">100</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">% interval limit`</span></span>
<span id="cb14-208">      ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</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;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb14-209">    }))</span>
<span id="cb14-210">  ]</span>
<span id="cb14-211">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-14" data-nodetype="expression">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb15" data-startfrom="216" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 215;"><span id="cb15-216">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb15-217">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">220</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-218">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginLeft</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-219">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginBottom</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-220">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"13px"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-221">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rate ratio →"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">ticks</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span><span class="op" 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="op" 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 class="op" 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="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">tickFormat</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-222">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"↑ S-value (bits of information against)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">clamp</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-223">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb15-224">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(curve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"s"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-225">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.32</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"3 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-226">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>([{<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.42</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.32</span>}]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S = 4.3 bits (P = 0.05)"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">dy</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textAnchor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-227">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.55</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-228">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([mu]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-229">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>([atMu]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"s"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.5</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-230">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tip</span>(curve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pointerX</span>({</span>
<span id="cb15-231">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"s"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-232">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Rate ratio  </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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;">}\n</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">S-value     </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> bits`</span></span>
<span id="cb15-233">    }))</span>
<span id="cb15-234">  ]</span>
<span id="cb15-235">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-15" data-nodetype="expression">

</div>
</div>
</div>
<section id="calibrating-bits" class="level3">
<h3 class="anchored" data-anchor-id="calibrating-bits">Calibrating bits</h3>
<p>Why bother with the S-value at all? Mostly because “P = 0.05” doesn’t carry much intuition, and “significant” tends to carry the wrong one. Bits seem to be easier to think about, since most of us have a physical sense of what flipping a coin is like. If we drag μ above, we can watch the coins change.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb16" data-startfrom="244" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 243;"><span id="cb16-244"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// A physical calibration strip. Whole bits are drawn as coins; the fractional</span></span>
<span id="cb16-245"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// remainder is drawn as a partial coin, because rounding 4.31 up to 5 would</span></span>
<span id="cb16-246"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// quietly overstate the evidence by a factor of ~1.6.</span></span>
<span id="cb16-247">coins <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb16-248">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> whole <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">floor</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(atMu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb16-249">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> frac <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(atMu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> whole<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb16-250">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> cells <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb16-251">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> whole<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) cells<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb16-252">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (frac <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>) cells<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>(frac)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb16-253">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div style="margin: 0.8em 0 1.4em;"&gt;</span></span>
<span id="cb16-254"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;div style="display:flex; flex-wrap:wrap; gap:5px; align-items:center; min-height:22px;"&gt;</span></span>
<span id="cb16-255"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">      </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>cells<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;span style="</span></span>
<span id="cb16-256"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">        display:inline-block; width:18px; height:18px; border-radius:50%;</span></span>
<span id="cb16-257"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">        border:1.5px solid currentColor;</span></span>
<span id="cb16-258"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">        background: linear-gradient(to right, currentColor </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;">100</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>f)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">%, transparent </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;">100</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>f)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">%);</span></span>
<span id="cb16-259"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">        opacity:0.8;"&gt;&lt;/span&gt;`</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb16-260"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">      </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>atMu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;span style="opacity:0.7; font-size:0.9em;"&gt;… and </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>(atMu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> more&lt;/span&gt;`</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">``</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb16-261"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;/div&gt;</span></span>
<span id="cb16-262"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;div style="opacity:0.7; font-size:0.9em; margin-top:0.5em;"&gt;</span></span>
<span id="cb16-263"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">      </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>atMu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> bits against μ = </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>mu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">.</span></span>
<span id="cb16-264"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">      </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>atMu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Less surprising than a single coin flip."</span></span>
<span id="cb16-265">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> atMu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.32</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Less surprising than the conventional 0.05 threshold."</span></span>
<span id="cb16-266">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"More surprising than the conventional 0.05 threshold."</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb16-267"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;/div&gt;</span></span>
<span id="cb16-268"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;/div&gt;`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb16-269">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-16" data-nodetype="declaration">

</div>
</div>
</div>
<div class="callout callout-style-default callout-warning callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-2-contents" aria-controls="callout-2" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Warning</span>What the coins do not license
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-2" class="callout-2-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<p>The S-value measures how surprising the data are <em>given the whole model</em>, and <img src="https://latex.codecogs.com/png.latex?%5Cmu"> is only one part of that model. Every bit is also a bit against the assumed absence of uncontrolled confounding, selection effects, measurement error, and misspecified model form. Thus, a large S-value tells us that the data are hard to reconcile with <img src="https://latex.codecogs.com/png.latex?%5Cmu"> together with everything else that we assumed. However, it cannot tell us which of those assumptions to give up. In observational work, the “everything else” is usually the weaker link.</p>
</div>
</div>
</div>
</section>
</section>
<section id="a-worked-example-one-data-set-four-analyses" class="level2">
<h2 class="anchored" data-anchor-id="a-worked-example-one-data-set-four-analyses">A worked example: one data set, four analyses</h2>
<p>Brown and colleagues studied serotonergic antidepressant use in pregnancy and autism spectrum disorder in 35,906 Ontario births, of which 2,837 pregnancies (7.9%) were exposed<span class="citation" data-cites="brown2017"><sup>4</sup></span>. They reported four hazard ratios from the same cohort under progressively stronger confounding control. This is the example reanalysed at length in<span class="citation" data-cites="rafi2020"><sup>3</sup></span>, and the working code for that paper lives <a href="../statistics/rg2020bmc">here</a>.</p>
<p>Before anything else, let’s look at the point estimates.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb17" data-startfrom="288" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 287;"><span id="cb17-288">brown <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb17-289">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">key</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"crude"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Crude"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>                 <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.16</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">lower</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.86</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">ciLabel</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1.64 – 2.86"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">control</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"None"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb17-290">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">key</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"adj"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Covariate-adjusted"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.59</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.17</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.17</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">ciLabel</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1.17 – 2.17"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">control</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Regression adjustment"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb17-291">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">key</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"iptw"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>   <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"HdPS IPT-weighted"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>     <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.997</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">ciLabel</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0.997 – 2.59"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">control</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"High-dimensional propensity score"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb17-292">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">key</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sib"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sibling-matched"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>       <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.60</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.69</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.74</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">ciLabel</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0.69 – 3.74"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">control</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Within-family (shared confounders)"</span>}</span>
<span id="cb17-293">]</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-17" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb18" data-startfrom="298" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 297;"><span id="cb18-298">brownStats <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> brown<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb18-299">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> s <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seFromRatioCI</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb18-300">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">testValue</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb18-301">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">se</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">pNull</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">sNull</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">ratio</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb18-302">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-18" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb19" data-startfrom="307" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 306;"><span id="cb19-307">Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(</span>
<span id="cb19-308">  brownStats<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({</span>
<span id="cb19-309">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Analysis</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb19-310">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Confounding control"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">control</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb19-311">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">HR</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb19-312">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"95% CI"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ciLabel</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb19-313">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Interval ratio"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb19-314">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P (vs HR = 1)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pNull</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pNull</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toExponential</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pNull</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb19-315">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S (bits)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sNull</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb19-316">  }))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb19-317">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">rows</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">layout</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>}</span>
<span id="cb19-318">)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-19" data-nodetype="expression">

</div>
</div>
</div>
<p>Three of the four point estimates are 1.59, 1.60 and 1.61. By the conventional reading, one of them is a finding and two of them are nothing. However, the estimate barely changes between them. What changes is the width of the interval, which grows from a ratio of 1.9 to 5.4 across the three adjusted analyses, as each one trades precision for stronger confounding control. So the verdicts flip while the estimate stays where it was.</p>
<p>The published conclusion was that exposure “was not associated with” autism. I don’t think the arithmetic supports that sentence, since the IPT-weighted analysis puts <img src="https://latex.codecogs.com/png.latex?P%20=%200.0505"> against the null (4.31 bits of surprise), and its interval runs to 2.59.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb20" data-startfrom="327" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 326;"><span id="cb20-327">viewof shown <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">checkbox</span>(brown<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb20-328">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> brown<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb20-329">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">format</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb20-330">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Analyses to overlay"</span></span>
<span id="cb20-331">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-20" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb21" data-startfrom="336" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 335;"><span id="cb21-336">brownCurves <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> shown<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flatMap</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb21-337">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> s <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seFromRatioCI</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb21-338">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">consonanceCurve</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">from</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">to</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>})</span>
<span id="cb21-339">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(pt <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>pt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">analysis</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label</span>}))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb21-340">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-21" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb22" data-startfrom="345" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 344;"><span id="cb22-345">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb22-346">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">320</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-347">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginLeft</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-348">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginBottom</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-349">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"13px"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-350">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-351">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hazard ratio →"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">ticks</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span><span class="op" 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="op" 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 class="op" 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="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">tickFormat</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-352">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"↑ P-value"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-353">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb22-354">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"3 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-355">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.55</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-356">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(brownCurves<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"analysis"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"analysis"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-357">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// P = 1 exactly at the point estimate, so each dot sits at the apex of its curve.</span></span>
<span id="cb22-358">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>(shown<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hr"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-359">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tip</span>(brownCurves<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pointer</span>({</span>
<span id="cb22-360">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"analysis"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-361">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> [</span>
<span id="cb22-362">        d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">analysis</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-363">        <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Hazard ratio  </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-364">        <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`P-value       </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toExponential</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb22-365">        <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`S-value       </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> bits`</span></span>
<span id="cb22-366">      ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</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;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb22-367">    }))</span>
<span id="cb22-368">  ]</span>
<span id="cb22-369">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-22" data-nodetype="expression">

</div>
</div>
</div>
<p>If we uncheck the crude analysis, the remaining three curves are nearly concentric, with the same peak and different widths. That is what a precision problem looks like, and it gives us little reason to think the analyses disagree about the size of the effect. Now, let’s test a value other than the null:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb23" data-startfrom="376" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 375;"><span id="cb23-376">viewof muBrown <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb23-377">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Test every analysis against this hazard ratio"</span></span>
<span id="cb23-378">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-23" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb24" data-startfrom="383" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 382;"><span id="cb24-383">Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(</span>
<span id="cb24-384">  brownStats<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb24-385">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">testValue</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> muBrown)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb24-386">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb24-387">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Analysis</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb24-388">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">HR</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb24-389">      [<span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`P (vs </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>muBrown<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">)`</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toExponential</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb24-390">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S (bits)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb24-391">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Reading</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Highly compatible"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.32</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Compatible"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Poorly compatible"</span></span>
<span id="cb24-392">    }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb24-393">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb24-394">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">rows</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">layout</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"auto"</span>}</span>
<span id="cb24-395">)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-24" data-nodetype="expression">

</div>
</div>
</div>
<p>If we set the slider to 1.5, the four analyses give <img src="https://latex.codecogs.com/png.latex?S"> = 6.6, 0.5, 0.4 and 0.2 bits. Three of the four find a 50% increase in hazard <em>less</em> surprising than a single coin flip. Thus, against this hypothesis, the analysis that was “not significant” and the analysis that was “significant” are saying nearly the same thing.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-3-contents" aria-controls="callout-3" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Why the null gets a curve and not a verdict
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-3" class="callout-3-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<p>Testing HR = 1 is a legitimate question. However, if we report only that test, and only its dichotomised outcome, we discard the answer to every other question that the same data address. Some of those are questions the reader may care about more, such as whether an effect large enough to change prescribing can be ruled out. On these data, it cannot be ruled out, since the IPT-weighted 95% interval reaches 2.59, and even the 50% interval runs from 1.37 to 1.90.</p>
</div>
</div>
</div>
</section>
<section id="what-more-data-would-do" class="level2">
<h2 class="anchored" data-anchor-id="what-more-data-would-do">What more data would do</h2>
<p>Precision and the parameter value are two separate things, but a single <em>P</em>-value fuses them into one number. To pull them apart, we can hold the IPT-weighted estimate fixed and vary only the amount of information (the standard error scales as <img src="https://latex.codecogs.com/png.latex?1/%5Csqrt%7Bk%7D"> when the sample size is multiplied by <img src="https://latex.codecogs.com/png.latex?k">).</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb25" data-startfrom="412" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 411;"><span id="cb25-412">viewof kInfo <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb25-413">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sample size multiplier (k)"</span></span>
<span id="cb25-414">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-25" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb26" data-startfrom="419" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 418;"><span id="cb26-419">base <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">se</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seFromRatioCI</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.997</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</span>)})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-26" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb27" data-startfrom="424" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 423;"><span id="cb27-424">scaled <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">se</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> base<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(kInfo)})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-27" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb28" data-startfrom="429" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 428;"><span id="cb28-429">scaledCurve <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">consonanceCurve</span>(base<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> scaled<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">from</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">to</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-28" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb29" data-startfrom="434" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 433;"><span id="cb29-434">baseCurve <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">consonanceCurve</span>(base<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> base<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">from</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">to</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-29" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb30" data-startfrom="439" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 438;"><span id="cb30-439">scaledAtNull <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">testValue</span>(base<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> scaled<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se</span><span class="op" 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></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-30" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb31" data-startfrom="444" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 443;"><span id="cb31-444"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div style="border-left:3px solid currentColor; padding:0.6em 1em; margin:1.2em 0; font-size:0.95em; line-height:1.7;"&gt;</span></span>
<span id="cb31-445"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  At &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>kInfo<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">×&lt;/strong&gt; the original sample size, with the estimate held at</span></span>
<span id="cb31-446"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;strong&gt;1.61&lt;/strong&gt;:</span></span>
<span id="cb31-447"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  95% interval</span></span>
<span id="cb31-448"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>(base<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hr</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">zq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> scaled<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt; to</span></span>
<span id="cb31-449"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>(base<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hr</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">zq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> scaled<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt;,</span></span>
<span id="cb31-450"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;em&gt;P&lt;/em&gt; = &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>scaledAtNull<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> scaledAtNull<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toExponential</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> scaledAtNull<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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 class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt;</span></span>
<span id="cb31-451"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  against the null,</span></span>
<span id="cb31-452"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;em&gt;S&lt;/em&gt; = &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>scaledAtNull<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> bits&lt;/strong&gt;.</span></span>
<span id="cb31-453"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/div&gt;`</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-31" data-nodetype="expression">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb32" data-startfrom="458" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 457;"><span id="cb32-458">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb32-459">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">280</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb32-460">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginLeft</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb32-461">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginBottom</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb32-462">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"13px"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb32-463">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hazard ratio →"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">ticks</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span><span class="op" 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="op" 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 class="op" 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="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">tickFormat</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb32-464">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"↑ P-value"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb32-465">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb32-466">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"3 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb32-467">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.55</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb32-468">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(baseCurve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.30</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2 3"</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb32-469">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">areaY</span>(scaledCurve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb32-470">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(scaledCurve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb32-471">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>([{<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> base<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.5</span>})</span>
<span id="cb32-472">  ]</span>
<span id="cb32-473">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-32" data-nodetype="expression">

</div>
</div>
</div>
<p>The dashed ghost curve is the study as it was published. If we push <img src="https://latex.codecogs.com/png.latex?k"> to 4, the null falls well outside the 95% interval, even though the estimate hasn’t moved at all. If we pull <img src="https://latex.codecogs.com/png.latex?k"> down to 0.3, the same estimate becomes compatible with almost everything between 0.7 and 3.9.</p>
<p>I think this deserves some attention, because it seems to be the mechanism behind a lot of “failure to replicate” reporting. A study that reports <img src="https://latex.codecogs.com/png.latex?P%20=%200.04"> and a study that reports <img src="https://latex.codecogs.com/png.latex?P%20=%200.12"> can have identical point estimates and differ only in how many people they enrolled. Neither of those numbers is a property of the effect.</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">
<span class="screen-reader-only">Important</span>The one thing this widget cannot show
</div>
</div>
<div class="callout-body-container callout-body">
<p>Scaling the standard error only models <em>random</em> error. Multiplying the sample size by 16 does nothing to confounding, selection, or measurement error, since those biases do not shrink with <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7Bn%7D">, and past some sample size they dominate entirely. Thus, a very narrow curve can still be centred in the wrong place, and it will look far more convincing than it should. If we want those biases quantified (instead of assumed away), we need a bias analysis, and adding more subjects won’t help.</p>
</div>
</div>
</section>
<section id="do-two-estimates-conflict" class="level2">
<h2 class="anchored" data-anchor-id="do-two-estimates-conflict">Do two estimates conflict?</h2>
<p>We often hear something like “Study A was significant, study B was not, so they disagree.” However, that compares two verdicts and says nothing direct about the two estimates. The comparison that actually answers the question has a curve of its own. Under independence, the log ratio-of-ratios has standard error <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7Bse_A%5E2%20+%20se_B%5E2%7D">, and the null of <em>no difference</em> sits at a ratio of 1.</p>
<p>Study A is the explorer at the top of this page, and we can set study B here.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb33" data-startfrom="494" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 493;"><span id="cb33-494">viewof estB <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.05</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study B: point estimate"</span>})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-33" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb34" data-startfrom="499" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 498;"><span id="cb34-499">viewof cirB <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.05</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.60</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study B: interval ratio"</span>})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-34" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb35" data-startfrom="504" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 503;"><span id="cb35-504">limitsB <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> estB <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(cirB)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> estB <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(cirB)})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-35" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb36" data-startfrom="509" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 508;"><span id="cb36-509">seB <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seFromRatioCI</span>(limitsB<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> limitsB<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-36" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb37" data-startfrom="514" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 513;"><span id="cb37-514">diff <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">ratio</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> est <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> estB<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">se</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(se <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> se <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> seB <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> seB)})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-37" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb38" data-startfrom="519" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 518;"><span id="cb38-519"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// The ratio of ratios can leave a fixed window entirely (A/B ranges from 0.125</span></span>
<span id="cb38-520"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// to 8 across the slider limits), so the domain follows the estimate instead of</span></span>
<span id="cb38-521"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// silently cropping the peak off the plot.</span></span>
<span id="cb38-522">diffDomain <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ({</span>
<span id="cb38-523">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">from</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> diff<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio</span> <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb38-524">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">to</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> diff<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio</span> <span class="op" 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>
<span id="cb38-525">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-38" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb39" data-startfrom="530" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 529;"><span id="cb39-530">diffCurve <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">consonanceCurve</span>(diff<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> diff<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">from</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> diffDomain<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">from</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">to</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> diffDomain<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">to</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-39" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb40" data-startfrom="535" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 534;"><span id="cb40-535">diffAtNull <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">testValue</span>(diff<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> diff<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se</span><span class="op" 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></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-40" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb41" data-startfrom="540" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 539;"><span id="cb41-540"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div style="border-left:3px solid currentColor; padding:0.6em 1em; margin:1.2em 0; font-size:0.95em; line-height:1.7;"&gt;</span></span>
<span id="cb41-541"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  Study A: &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>est<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt; (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>limits<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">–</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>limits<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">),</span></span>
<span id="cb41-542"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;em&gt;P&lt;/em&gt; vs 1 = &lt;strong&gt;</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;">testValue</span>(est<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> se<span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt;&lt;br&gt;</span></span>
<span id="cb41-543"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  Study B: &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>estB<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt; (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>limitsB<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">–</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>limitsB<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">),</span></span>
<span id="cb41-544"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;em&gt;P&lt;/em&gt; vs 1 = &lt;strong&gt;</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;">testValue</span>(estB<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> seB<span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt;&lt;br&gt;</span></span>
<span id="cb41-545"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;span style="opacity:0.9"&gt;Ratio of ratios A ÷ B = &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>diff<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt;</span></span>
<span id="cb41-546"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  (95% CI </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>(diff<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">zq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> diff<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">–</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>(diff<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">zq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> diff<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">),</span></span>
<span id="cb41-547"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;em&gt;P&lt;/em&gt; for no difference = &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>diffAtNull<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/strong&gt;,</span></span>
<span id="cb41-548"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;em&gt;S&lt;/em&gt; = &lt;strong&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>diffAtNull<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> bits&lt;/strong&gt;&lt;/span&gt;</span></span>
<span id="cb41-549"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/div&gt;`</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-41" data-nodetype="expression">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb42" data-startfrom="554" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 553;"><span id="cb42-554">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb42-555">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">250</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb42-556">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginLeft</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb42-557">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginBottom</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb42-558">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"13px"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb42-559">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ratio of ratios (A ÷ B) →"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [diffDomain<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">from</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> diffDomain<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">to</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">tickFormat</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb42-560">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"↑ P-value for the difference"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb42-561">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb42-562">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">areaY</span>(diffCurve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb42-563">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(diffCurve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb42-564">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"3 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb42-565">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4 3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.55</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb42-566">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>([diffAtNull]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.5</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb42-567">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tip</span>(diffCurve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pointerX</span>({</span>
<span id="cb42-568">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb42-569">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Ratio of ratios  </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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;">}\n</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">P-value          </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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;">}\n</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">S-value          </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</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="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> bits`</span></span>
<span id="cb42-570">    }))</span>
<span id="cb42-571">  ]</span>
<span id="cb42-572">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-42" data-nodetype="expression">

</div>
</div>
</div>
<p>With the defaults (A at 1.61 with <img src="https://latex.codecogs.com/png.latex?P%20=%200.051">, and B at 1.05 with <img src="https://latex.codecogs.com/png.latex?P%20=%200.684">), the two studies land on opposite sides of the conventional threshold. However, their ratio of ratios is 1.53 (95% interval 0.90 to 2.61), and the difference carries 3.1 bits of information. That is fewer than the 4.3 bits that the 0.05 convention itself demands, and fewer than four coin flips. So the two verdicts disagree, while the direct comparison gives us little evidence of a difference.</p>
<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">
<span class="screen-reader-only">Warning</span>This does not apply to the four Brown analyses
</div>
</div>
<div class="callout-body-container callout-body">
<p>The overlay in the previous section shows four analyses of the <em>same</em> subjects. Their estimates are strongly correlated, so <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7Bse_A%5E2%20+%20se_B%5E2%7D"> badly overstates the standard error of their difference, and the resulting P-value is not interpretable. Thus, this widget should only be used for studies that are actually independent. For nested analyses of one data set, I’d stick with the overlay itself as the summary (same peak, different width).</p>
</div>
</div>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-6-contents" aria-controls="callout-6" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Why two panels instead of one with two axes
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-6" class="callout-6-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<p>A P-value and an S-value are the same quantity on different scales, so a dual axis is technically defensible. However, I still think it is a bad idea. Readers reliably misread which curve belongs to which axis, and the visual slope of the P-value curve near the tails is uninformative in the same region where the S-value is most informative. Two stacked panels that share an x-axis cost one extra inch of page, and they remove the ambiguity.</p>
</div>
</div>
</div>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-7-contents" aria-controls="callout-7" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Things this figure deliberately does not do
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-7" class="callout-7-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<ul>
<li><strong>No shading of “significant” regions.</strong> The whole point of the curve is that there is no cliff at 0.05.</li>
<li><strong>No default null at 1.</strong> The μ slider starts at 1 only because that is the conventional test value, and I wouldn’t treat it as privileged.</li>
<li><strong>No P-value below about 1e-300.</strong> Double precision runs out. The implementation stays accurate to roughly z = 37, which is far past the point where the normal approximation itself becomes the binding constraint.</li>
<li><strong>No normality diagnostics.</strong> Every curve here assumes that the log estimate is approximately normal with the reported standard error. The published interval already made that same assumption, so the curve adds nothing new here and only makes the assumption visible across the whole range.</li>
</ul>
</div>
</div>
</div>
</section>
<section id="interactive-table" class="level2">
<h2 class="anchored" data-anchor-id="interactive-table">Interactive table</h2>
<p>Here’s the same idea applied to tabular results. The table is searchable, and it can be sorted by clicking the column headers, which is most of what makes a long results table usable. These are the Brown analyses again, with each row carrying its own P-value against whichever hypothesis we choose.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb43" data-startfrom="604" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 603;"><span id="cb43-604">viewof muTable <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hypothesis tested in the table (μ)"</span>})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-43" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb44" data-startfrom="609" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 608;"><span id="cb44-609">tableRows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> brownStats<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb44-610">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">testValue</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> muTable)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb44-611">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb44-612">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Analysis</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb44-613">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hazard ratio"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb44-614">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"95% CI"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ciLabel</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb44-615">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SE (log scale)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb44-616">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toExponential</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb44-617">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S (bits)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb44-618">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb44-619">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-44" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb45" data-startfrom="624" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 623;"><span id="cb45-624">viewof tableSearch <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">search</span>(tableRows<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">placeholder</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Filter analyses…"</span>})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-45" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb46" data-startfrom="629" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 628;"><span id="cb46-629">Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(tableSearch<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb46-630">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">sort</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S (bits)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb46-631">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">reverse</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb46-632">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">rows</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span></span>
<span id="cb46-633">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-46" data-nodetype="expression">

</div>
</div>
</div>
</section>
<section id="how-to-report-this" class="level2">
<h2 class="anchored" data-anchor-id="how-to-report-this">How to report this</h2>
<p>None of this requires a new statistic, a new threshold, or new software. I’d suggest four sentences that can go straight into a results section:</p>
<ol type="1">
<li>Report the estimate and interval <strong>without</strong> the word “significant” (for example, “HR 1.61, 95% compatibility interval 0.997 to 2.59”).</li>
<li>Report the P-value <strong>as a number</strong> instead of as an inequality against 0.05, and say which hypothesis it tests.</li>
<li>Report at least one P-value for a <strong>non-null</strong> hypothesis that matters clinically or practically. If the data cannot distinguish the null from a 60% increase, then that is the finding.</li>
<li>Say that the interval and the P-value are conditional on the <strong>entire</strong> model, and that the parameter is only one part of it.</li>
</ol>
<p>What if a reviewer asks for the significance verdict back? I’d point them to the curve, since it contains their verdict as one horizontal slice, along with every slice they did not ask for.</p>
</section>
<section id="reader-infrastructure-that-is-already-on" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="reader-infrastructure-that-is-already-on">Reader infrastructure that is already on</h2>
<p>Lastly, three of the things that people associate with Gwern’s pages happen to be Quarto defaults, and they need no code at all:</p>
<ul>
<li><strong>Citation popups.</strong> Hover any <code>@citekey</code> reference.</li>
<li><strong>Footnote popups.</strong> Hover the marker on <sup>2</sup> above.</li>
<li><strong>Cross-reference popups.</strong> Hover any <code>@fig-</code> or <code>@tbl-</code> reference.</li>
</ul>
<div class="no-row-height column-margin column-container"><div id="fn2"><p><sup>2</sup>&nbsp;It helps to put the 0.05 convention in bits. It amounts to 4.32 bits of information against the tested hypothesis, or roughly the surprise of four consecutive heads. I doubt that many of us would abandon a belief on four coin flips.</p></div></div><p>All three are controlled by <code>citations-hover</code>, <code>footnotes-hover</code> and <code>crossrefs-hover</code>, which default to <code>true</code>. The margin placement of footnotes here comes from <code>reference-location: margin</code> in this document’s front matter.</p>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body" data-entry-spacing="2" data-line-spacing="2">
<div id="ref-poole1987" class="csl-entry">
1. Poole C. (1987). <span>“Beyond the confidence interval.”</span> <em>American Journal of Public Health</em>. <strong>77</strong>:195–199. doi: <a href="https://doi.org/10.2105/ajph.77.2.195">10.2105/ajph.77.2.195</a>.
</div>
<div id="ref-sullivan1990" class="csl-entry">
2. Sullivan KM, Foster DA. (1990). <span>“Use of the confidence interval function.”</span> <em>Epidemiology</em>. <strong>1</strong>:39–42. doi: <a href="https://doi.org/10.1097/00001648-199001000-00009">10.1097/00001648-199001000-00009</a>.
</div>
<div id="ref-rafi2020" class="csl-entry">
3. Rafi Z, Greenland S. (2020). <span>“Semantic and cognitive tools to aid statistical science: Replace confidence and significance by compatibility and surprise.”</span> <em>BMC Medical Research Methodology</em>. <strong>20</strong>:244. doi: <a href="https://doi.org/10.1186/s12874-020-01105-9">10.1186/s12874-020-01105-9</a>.
</div>
<div id="ref-brown2017" class="csl-entry">
4. Brown HK, Ray JG, Wilton AS, Lunsky Y, Gomes T, Vigod SN. (2017). <span>“Association between serotonergic antidepressant use during pregnancy and autism spectrum disorder in children.”</span> <em>JAMA</em>. <strong>317</strong>:1544–1552. doi: <a href="https://doi.org/10.1001/jama.2017.3415">10.1001/jama.2017.3415</a>.
</div>
</div>


<!-- -->

</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>statistics</category>
  <category>interactive</category>
  <guid>https://lesslikely.com/statistics/consonance-explorer.html</guid>
  <pubDate>Thu, 24 Sep 2026 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Constructing Likelihood Functions in R, Stata, Python, Julia, MATLAB, and SQL</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/statistics/likelihood-polyglot.html</link>
  <description><![CDATA[ 





<hr>
<p>In this post, I’d like to build the same likelihood function three different ways, and to do so in six languages. The likelihood function, its deviance transform, the <em>P</em>-value (compatibility) function, and the <em>S</em>-value function are all coordinate views of the same thing. Thus, a script that can build one of them can build the rest. Each language section below carries the same self-checks:</p>
<ul>
<li>the from-scratch MLE must reproduce the packaged estimator,</li>
<li>the likelihood peak must land on the known estimator, and</li>
<li>the <img src="https://latex.codecogs.com/png.latex?1/6.83"> support interval must reproduce the 95% interval, since <img src="https://latex.codecogs.com/png.latex?%5Cexp(-1.96%5E2/2)%20=%201/6.83">.</li>
</ul>
<p>If a chunk runs silently, then every check passed. The running example for the summary-statistic construction is the Brown et al.&nbsp;(2017) JAMA HDPS-adjusted hazard ratio, HR <img src="https://latex.codecogs.com/png.latex?=%201.61"> (0.997, 2.59).</p>
<p>However, there are also several variations of likelihood, of which we only touch on one. For a clear explanation of the differences between these various likelihoods, see<span class="citation" data-cites="cole2013 coxPrinciplesStatisticalInference2006"><sup>1, 2</sup></span>.</p>
<section id="maximum-likelihood-from-scratch" class="level2">
<h2 class="anchored" data-anchor-id="maximum-likelihood-from-scratch">Maximum likelihood from scratch</h2>
<p>Let’s start by fitting a normal linear model and a logistic regression, where we write the log-likelihood ourselves, maximize it, and then check the result against the built-in estimator. There is one trick that we use everywhere, which is to parameterize with <img src="https://latex.codecogs.com/png.latex?%5Cln%5Csigma"> so that the scale parameter stays positive during optimization.</p>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-1-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-1" aria-controls="tabset-1-1" aria-selected="true" href="">R</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-2" aria-controls="tabset-1-2" aria-selected="false" href="">Stata</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-3-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-3" aria-controls="tabset-1-3" aria-selected="false" href="">Python</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-4-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-4" aria-controls="tabset-1-4" aria-selected="false" href="">Julia</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-5-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-5" aria-controls="tabset-1-5" aria-selected="false" href="">MATLAB</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-6-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-6" aria-controls="tabset-1-6" aria-selected="false" href="">SQL</a></li></ul>
<div class="tab-content">
<div id="tabset-1-1" class="tab-pane active" aria-labelledby="tabset-1-1-tab">
<p>Base R needs no helper package for this. We run <code>optim</code> on a hand-written negative log-likelihood and check it against <code>lm</code> and <code>glm</code>.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ---- Part A: normal linear model ----</span></span>
<span id="cb1-4">n <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;">200</span></span>
<span id="cb1-5">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>(n)</span>
<span id="cb1-6">y <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;">2</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.75</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x <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;">rnorm</span>(n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>)</span>
<span id="cb1-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;">cbind</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, x)</span>
<span id="cb1-8"></span>
<span id="cb1-9">negloglik_normal <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>(theta, y, X) {</span>
<span id="cb1-10">  beta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> theta[<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;">2</span>]; log_sigma <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> theta[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]</span>
<span id="cb1-11">  <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;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> X <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%*%</span> beta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(log_sigma), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">log =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>))</span>
<span id="cb1-12">}</span>
<span id="cb1-13"></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;">optim</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;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), negloglik_normal, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y, <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;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BFGS"</span>)</span>
<span id="cb1-15">b_ml <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]; sigma_ml <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;">exp</span>(fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>])</span>
<span id="cb1-16"></span>
<span id="cb1-17">ols <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> x)</span>
<span id="cb1-18">sigma_ols_nscaled <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>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">residuals</span>(ols)<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> n)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ML sigma uses n, not n-k</span></span>
<span id="cb1-19"></span>
<span id="cb1-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(b_ml <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;">coef</span>(ols)[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>]]) <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;">1e-4</span>,</span>
<span id="cb1-21">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(sigma_ml <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> sigma_ols_nscaled) <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;">1e-3</span>)</span>
<span id="cb1-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part A validation PASSED: optim MLE reproduces lm</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb1-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Part A validation PASSED: optim MLE reproduces lm</span></span>
<span id="cb1-24"></span>
<span id="cb1-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ---- Part B: logistic regression ----</span></span>
<span id="cb1-26">n2 <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;">300</span></span>
<span id="cb1-27">x2 <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>(n2)</span>
<span id="cb1-28">y2 <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;">runif</span>(n2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plogis</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.4</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.9</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x2))</span>
<span id="cb1-29">X2 <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;">cbind</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, x2)</span>
<span id="cb1-30"></span>
<span id="cb1-31">negloglik_logit <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>(beta, y, X) {</span>
<span id="cb1-32">  xb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> X <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%*%</span> beta</span>
<span id="cb1-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log1p</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>xb))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>y <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;">log1p</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(xb))<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> y))</span>
<span id="cb1-34">}</span>
<span id="cb1-35"></span>
<span id="cb1-36">fit2 <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;">optim</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;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), negloglik_logit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">X =</span> X2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BFGS"</span>)</span>
<span id="cb1-37">glmfit <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;">glm</span>(y2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">binomial</span>())</span>
<span id="cb1-38"></span>
<span id="cb1-39"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(fit2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par[<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;">coef</span>(glmfit)[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x2"</span>]]) <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;">1e-4</span>,</span>
<span id="cb1-40">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>fit2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>value <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;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">logLik</span>(glmfit))) <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;">1e-4</span>)</span>
<span id="cb1-41"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part B validation PASSED: optim MLE reproduces glm</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb1-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Part B validation PASSED: optim MLE reproduces glm</span></span></code></pre></div></div>
</div>
</div>
<div id="tabset-1-2" class="tab-pane" aria-labelledby="tabset-1-2-tab">
<p>The <code>lf</code> evaluator receives one linear predictor per equation and fills in the observation-level log likelihood (see <code>[R] ml</code>).</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<pre><code>#&gt; Number of observations (_N) was 0, now 200.
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; Initial:      Log likelihood =  -806.4418
#&gt; Alternative:  Log likelihood = -450.70073
#&gt; Rescale:      Log likelihood = -429.09515
#&gt; Rescale eq:   Log likelihood = -374.61873
#&gt; Iteration 0:  Log likelihood = -374.61873  
#&gt; Iteration 1:  Log likelihood = -348.89609  
#&gt; Iteration 2:  Log likelihood = -343.02889  
#&gt; Iteration 3:  Log likelihood = -342.99237  
#&gt; Iteration 4:  Log likelihood = -342.99235  
#&gt; 
#&gt;                                                         Number of obs =  
#&gt; &gt;   200
#&gt;                                                         Wald chi2(1)  =  
#&gt; &gt; 72.77
#&gt; Log likelihood = -342.99235                             Prob &gt; chi2   = 0
#&gt; &gt; .0000
#&gt; 
#&gt; -------------------------------------------------------------------------
#&gt; &gt; -----
#&gt;            y | Coefficient  Std. err.      z    P&gt;|z|     [95% conf. inte
#&gt; &gt; rval]
#&gt; -------------+-----------------------------------------------------------
#&gt; &gt; -----
#&gt; mu           |
#&gt;            x |   .8119551   .0951852     8.53   0.000     .6253954    .99
#&gt; &gt; 85147
#&gt;        _cons |   1.868002   .0954381    19.57   0.000     1.680947    2.0
#&gt; &gt; 55057
#&gt; -------------+-----------------------------------------------------------
#&gt; &gt; -----
#&gt; lnsigma      |
#&gt;        _cons |   .2960232        .05     5.92   0.000      .198025    .39
#&gt; &gt; 40214
#&gt; -------------------------------------------------------------------------
#&gt; &gt; -----
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; Part A validation PASSED: ml reproduces regress
#&gt; 
#&gt; 
#&gt; Number of observations (_N) was 0, now 300.
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; Initial:      Log likelihood = -207.94415
#&gt; Alternative:  Log likelihood =  -205.2231
#&gt; Rescale:      Log likelihood = -204.28183
#&gt; Iteration 0:  Log likelihood = -204.28183  
#&gt; Iteration 1:  Log likelihood = -187.36811  
#&gt; Iteration 2:  Log likelihood = -187.34499  
#&gt; Iteration 3:  Log likelihood = -187.34499  
#&gt; 
#&gt;                                                         Number of obs =  
#&gt; &gt;   300
#&gt;                                                         Wald chi2(1)  =  
#&gt; &gt; 28.32
#&gt; Log likelihood = -187.34499                             Prob &gt; chi2   = 0
#&gt; &gt; .0000
#&gt; 
#&gt; -------------------------------------------------------------------------
#&gt; &gt; -----
#&gt;            y | Coefficient  Std. err.      z    P&gt;|z|     [95% conf. inte
#&gt; &gt; rval]
#&gt; -------------+-----------------------------------------------------------
#&gt; &gt; -----
#&gt;            x |   .7507449   .1410829     5.32   0.000     .4742275    1.0
#&gt; &gt; 27262
#&gt;        _cons |  -.3434135    .124075    -2.77   0.006     -.586596    -.1
#&gt; &gt; 00231
#&gt; -------------------------------------------------------------------------
#&gt; &gt; -----
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; Part B validation PASSED: ml reproduces logit</code></pre>
</div>
</div>
<div id="tabset-1-3" class="tab-pane" aria-labelledby="tabset-1-3-tab">
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb3-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> optimize</span>
<span id="cb3-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy.stats <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> norm</span>
<span id="cb3-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> statsmodels.api <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> sm</span>
<span id="cb3-5"></span>
<span id="cb3-6">rng <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.default_rng(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>)</span>
<span id="cb3-7"></span>
<span id="cb3-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ---- Part A: normal linear model ----</span></span>
<span id="cb3-9">n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span></span>
<span id="cb3-10">x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, n)</span>
<span id="cb3-11">y <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> rng.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>, n)</span>
<span id="cb3-12">X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.add_constant(x)</span>
<span id="cb3-13"></span>
<span id="cb3-14"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> negloglik_normal(theta, y, X):</span>
<span id="cb3-15">    beta, log_sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> theta[:<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], theta[<span class="op" 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>
<span id="cb3-16">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>np.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(norm.logpdf(y, loc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">@</span> beta, scale<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>np.exp(log_sigma)))</span>
<span id="cb3-17"></span>
<span id="cb3-18">fit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> optimize.minimize(negloglik_normal, np.zeros(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>), args<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(y, X), method<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BFGS"</span>)</span>
<span id="cb3-19">b_ml, sigma_ml <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> fit.x[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], np.exp(fit.x[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb3-20"></span>
<span id="cb3-21">ols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.OLS(y, X).fit()</span>
<span id="cb3-22">sigma_ols_nscaled <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.sqrt(ols.ssr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> n)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ML sigma uses n, not n-k</span></span>
<span id="cb3-23"></span>
<span id="cb3-24"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">assert</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(b_ml <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> ols.params[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-4</span></span>
<span id="cb3-25"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">assert</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(sigma_ml <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> sigma_ols_nscaled) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-3</span></span>
<span id="cb3-26"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part A validation PASSED: scipy MLE reproduces OLS"</span>)</span>
<span id="cb3-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Part A validation PASSED: scipy MLE reproduces OLS</span></span>
<span id="cb3-28"></span>
<span id="cb3-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ---- Part B: logistic regression ----</span></span>
<span id="cb3-30">n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span></span>
<span id="cb3-31">x2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, n)</span>
<span id="cb3-32">y2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (rng.uniform(size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>n) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> np.exp(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x2)))).astype(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">float</span>)</span>
<span id="cb3-33">X2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.add_constant(x2)</span>
<span id="cb3-34"></span>
<span id="cb3-35"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> negloglik_logit(beta, y, X):</span>
<span id="cb3-36">    xb <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">@</span> beta</span>
<span id="cb3-37">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> np.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(np.logaddexp(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>xb)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> np.logaddexp(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, xb)<span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> y))</span>
<span id="cb3-38"></span>
<span id="cb3-39">fit2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> optimize.minimize(negloglik_logit, np.zeros(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), args<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(y2, X2), method<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BFGS"</span>)</span>
<span id="cb3-40">logit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.Logit(y2, X2).fit(disp<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb3-41"></span>
<span id="cb3-42"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">assert</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(fit2.x[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> logit.params[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-4</span></span>
<span id="cb3-43"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">assert</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>fit2.fun <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> logit.llf) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-4</span></span>
<span id="cb3-44"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part B validation PASSED: scipy MLE reproduces Logit"</span>)</span>
<span id="cb3-45"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Part B validation PASSED: scipy MLE reproduces Logit</span></span></code></pre></div></div>
</div>
</div>
<div id="tabset-1-4" class="tab-pane" aria-labelledby="tabset-1-4-tab">
<p>A note on versions: the current Optim.jl rejects the old <code>autodiff = :forward</code> symbol (it now wants an <code>ADTypes</code> object). However, the default finite-difference gradient is robust across versions and is plenty for what we need here. The trailing semicolons matter for the <em>output</em> and have nothing to do with the math. Julia echoes the value of every top-level expression, so without them each <code>randn(rng, n)</code> would dump a 200-element vector into the page. I’ve deliberately left three kinds of line unsuppressed, because what they echo seems worth reading. These are the <code>DataFrame</code>s (which self-truncate with <code>⋮</code> and a rows-omitted note), the fitted models (<code>lm</code>/<code>glm</code> print a coefficient table with standard errors and intervals, which is what the assertions below check), and the bare <code>p</code> on a plotting chunk’s last line, which is what emits the figure.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb4-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">using</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Distributions</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Optim</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">GLM</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">DataFrames</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Random</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Statistics</span></span>
<span id="cb4-2"></span>
<span id="cb4-3">rng <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">MersenneTwister</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>);</span>
<span id="cb4-4"></span>
<span id="cb4-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ---- Part A: normal linear model ----</span></span>
<span id="cb4-6">n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>;</span>
<span id="cb4-7">x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randn</span>(rng, n);</span>
<span id="cb4-8">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span> x <span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randn</span>(rng, n);</span>
<span id="cb4-9">X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hcat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ones</span>(n), x);</span>
<span id="cb4-10"></span>
<span id="cb4-11"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">negloglik_normal</span>(theta)</span>
<span id="cb4-12">    beta, log_sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> theta[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>], theta[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]</span>
<span id="cb4-13">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">-sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">logpdf</span>.(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Normal</span>.(X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> beta, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(log_sigma)), y))</span>
<span id="cb4-14"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span>;</span>
<span id="cb4-15"></span>
<span id="cb4-16">fit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">optimize</span>(negloglik_normal, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">zeros</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">BFGS</span>());</span>
<span id="cb4-17">b_ml, sigma_ml <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Optim.<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">minimizer</span>(fit)[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>], <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(Optim.<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">minimizer</span>(fit)[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]);</span>
<span id="cb4-18"></span>
<span id="cb4-19">df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">DataFrame</span>(y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> y, x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> x)</span>
<span id="cb4-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 200×2 DataFrame</span></span>
<span id="cb4-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Row │ y          x</span></span>
<span id="cb4-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;      │ Float64    Float64</span></span>
<span id="cb4-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ─────┼────────────────────────</span></span>
<span id="cb4-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    1 │  2.51681    1.53733</span></span>
<span id="cb4-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    2 │  2.49614    0.67567</span></span>
<span id="cb4-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    3 │  3.53854    0.529915</span></span>
<span id="cb4-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    4 │  2.40127   -0.469345</span></span>
<span id="cb4-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    5 │  2.47939   -0.344731</span></span>
<span id="cb4-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    6 │  1.25291    0.00596521</span></span>
<span id="cb4-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    7 │ -0.12643   -1.52318</span></span>
<span id="cb4-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    8 │  2.20185    0.390072</span></span>
<span id="cb4-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   ⋮  │     ⋮           ⋮</span></span>
<span id="cb4-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  194 │  1.6941     1.13584</span></span>
<span id="cb4-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  195 │  0.352342   1.1385</span></span>
<span id="cb4-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  196 │  1.16013   -0.839467</span></span>
<span id="cb4-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  197 │  4.71371    1.00806</span></span>
<span id="cb4-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  198 │  0.659784  -1.24059</span></span>
<span id="cb4-38"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  199 │  1.914     -0.300155</span></span>
<span id="cb4-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  200 │  0.488223  -0.759049</span></span>
<span id="cb4-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;               185 rows omitted</span></span>
<span id="cb4-41">ols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(<span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@formula</span>(y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x), df)</span>
<span id="cb4-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64</span><span class="re">}}}</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}, Matrix{Float64}}</span></span>
<span id="cb4-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb4-44"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; y ~ 1 + x</span></span>
<span id="cb4-45"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb4-46"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Coefficients:</span></span>
<span id="cb4-47"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ────────────────────────────────────────────────────────────────────────</span></span>
<span id="cb4-48"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                 Coef.  Std. Error      t  Pr(&gt;|t|)  Lower 95%  Upper 95%</span></span>
<span id="cb4-49"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ────────────────────────────────────────────────────────────────────────</span></span>
<span id="cb4-50"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; (Intercept)  2.06123     0.111722  18.45    &lt;1e-44   1.84091     2.28154</span></span>
<span id="cb4-51"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; x            0.820263    0.111287   7.37    &lt;1e-11   0.600803    1.03972</span></span>
<span id="cb4-52"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ────────────────────────────────────────────────────────────────────────</span></span>
<span id="cb4-53">sigma_ols_nscaled <span class="op" 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;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">residuals</span>(ols) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.^</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> n);</span>
<span id="cb4-54"></span>
<span id="cb4-55"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@assert</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(b_ml <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(ols)[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-4</span></span>
<span id="cb4-56"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@assert</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(sigma_ml <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> sigma_ols_nscaled) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-3</span></span>
<span id="cb4-57"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">println</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part A validation PASSED: Optim MLE reproduces lm"</span>)</span>
<span id="cb4-58"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Part A validation PASSED: Optim MLE reproduces lm</span></span>
<span id="cb4-59"></span>
<span id="cb4-60"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ---- Part B: logistic regression ----</span></span>
<span id="cb4-61">n2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span>;</span>
<span id="cb4-62">x2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randn</span>(rng, n2);</span>
<span id="cb4-63">y2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Float64</span>.(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rand</span>(rng, n2) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">./</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>.(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">-</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span> x2))));</span>
<span id="cb4-64">X2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hcat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ones</span>(n2), x2);</span>
<span id="cb4-65"></span>
<span id="cb4-66"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log1pexp</span>(u) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> u <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span> ? u <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log1p</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(u));</span>
<span id="cb4-67"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">negloglik_logit</span>(beta) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span></span>
<span id="cb4-68">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log1pexp</span>.(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">-</span>(X2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> beta)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span> y2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log1pexp</span>.(X2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> beta) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.-</span> y2));</span>
<span id="cb4-69"></span>
<span id="cb4-70">fit2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">optimize</span>(negloglik_logit, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">zeros</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">BFGS</span>());</span>
<span id="cb4-71">df2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">DataFrame</span>(y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> y2, x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> x2)</span>
<span id="cb4-72"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 300×2 DataFrame</span></span>
<span id="cb4-73"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Row │ y        x</span></span>
<span id="cb4-74"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;      │ Float64  Float64</span></span>
<span id="cb4-75"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ─────┼─────────────────────</span></span>
<span id="cb4-76"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    1 │     1.0   0.64402</span></span>
<span id="cb4-77"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    2 │     0.0  -0.883275</span></span>
<span id="cb4-78"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    3 │     0.0  -0.746231</span></span>
<span id="cb4-79"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    4 │     0.0   2.32986</span></span>
<span id="cb4-80"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    5 │     1.0   1.89985</span></span>
<span id="cb4-81"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    6 │     0.0  -0.931408</span></span>
<span id="cb4-82"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    7 │     1.0  -0.316581</span></span>
<span id="cb4-83"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    8 │     1.0   0.801148</span></span>
<span id="cb4-84"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   ⋮  │    ⋮         ⋮</span></span>
<span id="cb4-85"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  294 │     1.0  -0.198019</span></span>
<span id="cb4-86"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  295 │     0.0  -0.0022127</span></span>
<span id="cb4-87"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  296 │     1.0   0.10344</span></span>
<span id="cb4-88"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  297 │     0.0  -0.831018</span></span>
<span id="cb4-89"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  298 │     1.0   0.177091</span></span>
<span id="cb4-90"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  299 │     0.0  -1.0159</span></span>
<span id="cb4-91"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  300 │     0.0  -0.478225</span></span>
<span id="cb4-92"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;            285 rows omitted</span></span>
<span id="cb4-93">logit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(<span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@formula</span>(y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x), df2, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Binomial</span>(), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">LogitLink</span>())</span>
<span id="cb4-94"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; StatsModels.TableRegressionModel{GeneralizedLinearModel{GLM.GlmResp{Vector{Float64}, Binomial{Float64}, LogitLink}, GLM.DensePredChol{Float64, CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64</span><span class="re">}}}</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}, Matrix{Float64}}</span></span>
<span id="cb4-95"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb4-96"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; y ~ 1 + x</span></span>
<span id="cb4-97"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb4-98"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Coefficients:</span></span>
<span id="cb4-99"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ─────────────────────────────────────────────────────────────────────────</span></span>
<span id="cb4-100"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                  Coef.  Std. Error      z  Pr(&gt;|z|)  Lower 95%  Upper 95%</span></span>
<span id="cb4-101"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ─────────────────────────────────────────────────────────────────────────</span></span>
<span id="cb4-102"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; (Intercept)  -0.385155    0.127502  -3.02    0.0025  -0.635055  -0.135256</span></span>
<span id="cb4-103"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; x             0.881431    0.144892   6.08    &lt;1e-08   0.597447   1.16541</span></span>
<span id="cb4-104"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ─────────────────────────────────────────────────────────────────────────</span></span>
<span id="cb4-105"></span>
<span id="cb4-106"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@assert</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(Optim.<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">minimizer</span>(fit2)[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(logit)[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-4</span></span>
<span id="cb4-107"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@assert</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>Optim.<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">minimum</span>(fit2) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">loglikelihood</span>(logit)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-4</span></span>
<span id="cb4-108"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">println</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Part B validation PASSED: Optim MLE reproduces glm"</span>)</span>
<span id="cb4-109"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Part B validation PASSED: Optim MLE reproduces glm</span></span></code></pre></div></div>
</div>
</div>
<div id="tabset-1-5" class="tab-pane" aria-labelledby="tabset-1-5-tab">
<p><code>fminunc</code> is the Optimization Toolbox analogue of <code>optim</code>/<code>minimize</code>. Without the toolbox, <code>fminsearch</code> (Nelder–Mead, base MATLAB) reaches the same optimum, although more slowly. We use the same <img src="https://latex.codecogs.com/png.latex?%5Cln%5Csigma"> parameterization as everywhere else.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode matlab code-with-copy"><code class="sourceCode matlab"><span id="cb5-1"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">rng</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'twister'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-2"></span>
<span id="cb5-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% ---- Part A: normal linear model ----</span></span>
<span id="cb5-4"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">n</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-5"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">randn</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-6"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">y</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span> <span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">randn</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-7"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">X</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ones</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-8"></span>
<span id="cb5-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% theta = [b0; b1; log_sigma]</span></span>
<span id="cb5-10"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">negloglik_normal</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">@</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">th</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sum</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">log</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">normpdf</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">X</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">th</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">exp</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">th</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)))))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-11"></span>
<span id="cb5-12"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">opts</span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">optimset</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'TolX'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'TolFun'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'MaxFunEvals'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e4</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-13"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">fit</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">fminsearch</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">negloglik_normal</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">opts</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-14"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b_ml</span>     <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">fit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-15"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sigma_ml</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">exp</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">fit</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-16"></span>
<span id="cb5-17"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b_ols</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">X</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span>                        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% backslash = least squares</span></span>
<span id="cb5-18"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">resid</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">y</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">X</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b_ols</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-19"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sigma_ols_nscaled</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sum</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">resid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.^</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">n</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span>   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% ML sigma uses n, not n-k</span></span>
<span id="cb5-20"></span>
<span id="cb5-21"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">assert</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">abs</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b_ml</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b_ols</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))            <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-4</span>)</span>
<span id="cb5-22"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">assert</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">abs</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sigma_ml</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sigma_ols_nscaled</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-3</span>)</span>
<span id="cb5-23"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">disp</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Part A validation PASSED: fminsearch MLE reproduces backslash'</span>)</span>
<span id="cb5-24"></span>
<span id="cb5-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% ---- Part B: logistic regression ----</span></span>
<span id="cb5-26"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">n2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-27"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">randn</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">n2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-28"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">y2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">double</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">rand</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">n2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">./</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">exp</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x2</span>))))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-29"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">X2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ones</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">n2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-30"></span>
<span id="cb5-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% log1p(exp(u)) via a numerically safe branch, as in the other languages</span></span>
<span id="cb5-32"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">log1pexp</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">@</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">u</span>) (<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">u</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">u</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">u</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">log1p</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">exp</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">min</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">u</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>)))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-33"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">negloglik_logit</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">@</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b</span>) <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sum</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">log1pexp</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">X2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">y2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">log1pexp</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">X2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">y2</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-34"></span>
<span id="cb5-35"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">fit2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">fminsearch</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">negloglik_logit</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">opts</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-36"></span>
<span id="cb5-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% glmfit needs the Statistics and Machine Learning Toolbox; it prepends the</span></span>
<span id="cb5-38"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% intercept itself, so pass x2 rather than X2.</span></span>
<span id="cb5-39"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b_glm</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">glmfit</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">y2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'binomial'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'link'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'logit'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb5-40"></span>
<span id="cb5-41"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">assert</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">abs</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">fit2</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b_glm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-4</span>)</span>
<span id="cb5-42"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">disp</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Part B validation PASSED: fminsearch MLE reproduces glmfit'</span>)</span></code></pre></div></div>
</div>
</div>
<div id="tabset-1-6" class="tab-pane" aria-labelledby="tabset-1-6-tab">
<p>In SQL, the closed forms (<code>REGR_SLOPE</code> and <code>REGR_INTERCEPT</code>) <em>are</em> the ML estimates, and a grid search plays the role of the optimizer. The chunks below <strong>execute at render time</strong> against an in-process DuckDB that is seeded in the setup chunk, so every number on this page is query output and nothing was transcribed by hand. The dialect is ANSI where it counts. The Snowflake originals only differ in how the rows get generated (<code>GENERATOR</code>/<code>SEQ4</code> for <code>generate_series</code>, <code>UNIFORM</code> for <code>random</code>).</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode sql code-with-copy"><code class="sourceCode sql"><span id="cb6-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-- The data is simulated in the setup chunk above (n = 200,</span></span>
<span id="cb6-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-- y = 2 + 0.75x + N(0, 1.5)) via Box-Muller, since neither DuckDB nor</span></span>
<span id="cb6-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-- Snowflake ships a normal deviate. Note the two-stage CTE: you cannot write</span></span>
<span id="cb6-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-- AVG(POWER(y - REGR_INTERCEPT(y,x) OVER () ..., 2)) -- an aggregate may not</span></span>
<span id="cb6-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-- contain a window call. Compute the coefficients first, then the residual</span></span>
<span id="cb6-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-- variance against them.</span></span>
<span id="cb6-7"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">WITH</span> coef <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb6-8">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">regr_slope</span>(y, x) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> b1, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">regr_intercept</span>(y, x) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> b0</span>
<span id="cb6-9">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">FROM</span> mytable</span>
<span id="cb6-10">)</span>
<span id="cb6-11"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> c.b1 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> b1_mle,</span>
<span id="cb6-12">       c.b0 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> b0_mle,</span>
<span id="cb6-13">       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-- ML sigma^2 (divides by n, not n-k):</span></span>
<span id="cb6-14">       <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">avg</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">power</span>(d.y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> c.b0 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> c.b1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> d.x, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> sigma2_mle</span>
<span id="cb6-15"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">FROM</span> mytable d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">CROSS</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">JOIN</span> coef c</span>
<span id="cb6-16"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">GROUP</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">BY</span> c.b1, c.b0;</span></code></pre></div></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>1 records</caption>
<thead>
<tr class="header">
<th style="text-align: right;">b1_mle</th>
<th style="text-align: right;">b0_mle</th>
<th style="text-align: right;">sigma2_mle</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">0.595</td>
<td style="text-align: right;">1.84</td>
<td style="text-align: right;">2.46</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>These estimates are real query output. If we pull the same rows into R, we can confirm that SQL is computing the maximum likelihood fit (and not something that only resembles it):</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">d   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> DBI<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;">dbGetQuery</span>(con, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SELECT * FROM mytable"</span>)</span>
<span id="cb7-2">ols <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> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d)</span>
<span id="cb7-3">sql <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> DBI<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;">dbGetQuery</span>(con, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb7-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  WITH coef AS (SELECT regr_slope(y,x) AS b1, regr_intercept(y,x) AS b0 FROM mytable)</span></span>
<span id="cb7-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  SELECT c.b1, c.b0, avg(power(d.y - c.b0 - c.b1*d.x, 2)) AS s2</span></span>
<span id="cb7-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  FROM mytable d CROSS JOIN coef c GROUP BY c.b1, c.b0;"</span>)</span>
<span id="cb7-7"></span>
<span id="cb7-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(sql<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>b1 <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;">coef</span>(ols)[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>]]) <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;">1e-12</span>,</span>
<span id="cb7-9">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(sql<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>s2 <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;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">residuals</span>(ols)<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;">nrow</span>(d)) <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;">1e-12</span>)</span>
<span id="cb7-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SQL b1 = %.12f</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"> lm b1 = %.12f</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, sql<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>b1, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(ols)[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>]]))</span>
<span id="cb7-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; SQL b1 = 0.595368434861</span></span>
<span id="cb7-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  lm b1 = 0.595368434861</span></span>
<span id="cb7-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"validation PASSED: REGR_SLOPE == lm, to machine precision</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb7-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; validation PASSED: REGR_SLOPE == lm, to machine precision</span></span></code></pre></div></div>
</div>
</div>
</div>
</div>
</section>
<section id="likelihood-function-from-summary-statistics" class="level2">
<h2 class="anchored" data-anchor-id="likelihood-function-from-summary-statistics">Likelihood function from summary statistics</h2>
<p>A point estimate and a 95% interval on the ratio scale are enough for us to reconstruct the whole function. We recover the standard error from the width of the interval, lay down a grid, and then transform one <img src="https://latex.codecogs.com/png.latex?z"> per grid point.</p>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-2-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-1" aria-controls="tabset-2-1" aria-selected="true" href="">R</a></li><li class="nav-item"><a class="nav-link" id="tabset-2-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-2" aria-controls="tabset-2-2" aria-selected="false" href="">Stata</a></li><li class="nav-item"><a class="nav-link" id="tabset-2-3-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-3" aria-controls="tabset-2-3" aria-selected="false" href="">Python</a></li><li class="nav-item"><a class="nav-link" id="tabset-2-4-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-4" aria-controls="tabset-2-4" aria-selected="false" href="">Julia</a></li><li class="nav-item"><a class="nav-link" id="tabset-2-5-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-5" aria-controls="tabset-2-5" aria-selected="false" href="">MATLAB</a></li><li class="nav-item"><a class="nav-link" id="tabset-2-6-tab" data-bs-toggle="tab" data-bs-target="#tabset-2-6" aria-controls="tabset-2-6" aria-selected="false" href="">SQL</a></li></ul>
<div class="tab-content">
<div id="tabset-2-1" class="tab-pane active" aria-labelledby="tabset-2-1-tab">
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">point <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.61</span>; LL <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.997</span>; UL <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.59</span></span>
<span id="cb8-2">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;">log</span>(UL <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> LL) <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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.96</span>)</span>
<span id="cb8-3"></span>
<span id="cb8-4">hr <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;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.0</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;">600</span>)</span>
<span id="cb8-5">z  <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;">log</span>(hr) <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>(point)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> se</span>
<span id="cb8-6"></span>
<span id="cb8-7">support  <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;">exp</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(z<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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb8-8">deviance <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> z<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>
<span id="cb8-9">pvalue   <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;">2</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(z)))</span>
<span id="cb8-10">svalue   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</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;">log2</span>(pvalue)</span>
<span id="cb8-11"></span>
<span id="cb8-12">inside <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> hr[support <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;">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;">6.83</span>]</span>
<span id="cb8-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(inside) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> LL) <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.02</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(inside) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> UL) <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.02</span>)</span>
<span id="cb8-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"validation PASSED: 1/6.83 LI == 95% CI</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb8-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; validation PASSED: 1/6.83 LI == 95% CI</span></span>
<span id="cb8-16"></span>
<span id="cb8-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(hr, support, <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;">"l"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">log =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#007C7C"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb8-18">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xaxt =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"n"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hazard Ratio (HR)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative likelihood"</span>,</span>
<span id="cb8-19">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative Likelihood Function"</span>)</span>
<span id="cb8-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">axis</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;">at =</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.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</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 class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>))</span>
<span id="cb8-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v =</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;">lty =</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;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d46c5b"</span>)</span>
<span id="cb8-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">h =</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;">6.83</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-7-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-2-2" class="tab-pane" aria-labelledby="tabset-2-2-tab">
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<pre><code>#&gt; Number of observations (_N) was 0, now 600.
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 1/6.83 support interval: 1.0025 to 2.5918
#&gt; 
#&gt; 
#&gt; 
#&gt; validation PASSED: 1/6.83 LI == 95% CI</code></pre>
</div>
</div>
<div id="tabset-2-3" class="tab-pane" aria-labelledby="tabset-2-3-tab">
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb10-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy.stats <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> norm</span>
<span id="cb10-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb10-4"></span>
<span id="cb10-5">point, LL, UL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.997</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</span></span>
<span id="cb10-6">se <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.log(UL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> LL) <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.96</span>)</span>
<span id="cb10-7"></span>
<span id="cb10-8">hr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.linspace(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">600</span>)</span>
<span id="cb10-9">z <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (np.log(hr) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> np.log(point)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> se</span>
<span id="cb10-10"></span>
<span id="cb10-11">support  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.exp(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(z<span class="op" 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="op" 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>
<span id="cb10-12">deviance <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> z<span class="op" 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>
<span id="cb10-13">pvalue   <span class="op" 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="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> norm.cdf(np.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(z)))</span>
<span id="cb10-14">svalue   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>np.log2(pvalue)</span>
<span id="cb10-15"></span>
<span id="cb10-16">inside <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> hr[support <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span>]</span>
<span id="cb10-17"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">assert</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(inside.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">min</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> LL) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">and</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(inside.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> UL) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span></span>
<span id="cb10-18"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"validation PASSED: 1/6.83 LI == 95% CI"</span>)</span>
<span id="cb10-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; validation PASSED: 1/6.83 LI == 95% CI</span></span>
<span id="cb10-20"></span>
<span id="cb10-21">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.5</span>))</span>
<span id="cb10-22">ax.plot(hr, support, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#007C7C"</span>)</span>
<span id="cb10-23">ax.axvline(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, ls<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">":"</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d46c5b"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> ax.axhline(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>)</span>
<span id="cb10-24">ax.set_xscale(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> ax.set_xticks([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</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 class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>])</span>
<span id="cb10-25">ax.set_xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hazard Ratio (HR)"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> ax.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative likelihood"</span>)</span>
<span id="cb10-26">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative Likelihood Function"</span>)</span>
<span id="cb10-27">plt.show()</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-9-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-2-4" class="tab-pane" aria-labelledby="tabset-2-4-tab">
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb11-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">using</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Distributions</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Plots</span></span>
<span id="cb11-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gr</span>();</span>
<span id="cb11-3"></span>
<span id="cb11-4">point, LL, UL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.997</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</span>;</span>
<span id="cb11-5">se <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(UL <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> LL) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.96</span>);</span>
<span id="cb11-6"></span>
<span id="cb11-7">hr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.0</span>; length <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">600</span>);</span>
<span id="cb11-8">z <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>.(hr) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(point)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">./</span> se;</span>
<span id="cb11-9"></span>
<span id="cb11-10">support  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>.(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">-</span>(z <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.^</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">./</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>);</span>
<span id="cb11-11">deviance <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> z <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.^</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>;</span>
<span id="cb11-12">pvalue   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cdf</span>.(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Normal</span>(), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>.(z)));</span>
<span id="cb11-13">svalue   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log2</span>.(pvalue);</span>
<span id="cb11-14"></span>
<span id="cb11-15">inside <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> hr[support <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span>];</span>
<span id="cb11-16"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@assert</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">minimum</span>(inside) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> LL) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">maximum</span>(inside) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> UL) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span></span>
<span id="cb11-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">println</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"validation PASSED: 1/6.83 LI == 95% CI"</span>)</span>
<span id="cb11-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; validation PASSED: 1/6.83 LI == 95% CI</span></span>
<span id="cb11-19"></span>
<span id="cb11-20">p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(hr, support; xscale <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>log10, legend <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">false</span>,</span>
<span id="cb11-21">         xlabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hazard Ratio (HR)"</span>, ylabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative likelihood"</span>,</span>
<span id="cb11-22">         title <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative Likelihood Function"</span>);</span>
<span id="cb11-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hline!</span>(p, [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span>]; color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>gray, alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>);</span>
<span id="cb11-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vline!</span>(p, [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0</span>]; linestyle <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>dot, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>red);</span>
<span id="cb11-25">p</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-10-J1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="300"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-2-5" class="tab-pane" aria-labelledby="tabset-2-5-tab">
<p><code>normcdf</code> needs the Statistics Toolbox. However, the <code>erfc</code> form below is base MATLAB and gives the identical two-sided tail, so this tab runs either way.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode matlab code-with-copy"><code class="sourceCode matlab"><span id="cb12-1"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">point</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">LL</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.997</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">UL</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-2"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">se</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">log</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">UL</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">LL</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.96</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-3"></span>
<span id="cb12-4"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">hr</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">linspace</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">600</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">';</span></span>
<span id="cb12-5"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">z</span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">log</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">hr</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">log</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">point</span>)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">se</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-6"></span>
<span id="cb12-7"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">support</span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">exp</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">z</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.^</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-8"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">deviance</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">z</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.^</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% two-sided p; erfc form avoids the Statistics Toolbox dependency</span></span>
<span id="cb12-10"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pvalue</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">erfc</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">abs</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">z</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-11"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">svalue</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">log2</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">pvalue</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-12"></span>
<span id="cb12-13"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">inside</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">hr</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">support</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-14"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">assert</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">abs</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">min</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">inside</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">LL</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">abs</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">max</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">inside</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">UL</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>)</span>
<span id="cb12-15"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">disp</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'validation PASSED: 1/6.83 LI == 95% CI'</span>)</span>
<span id="cb12-16"></span>
<span id="cb12-17"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">figure</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-18"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">semilogx</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">hr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">support</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'LineWidth'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Color'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.486</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.486</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-19"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">xticks</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span> <span class="fl" 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 class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-20"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">xline</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>      <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">':'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Color'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.831</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.424</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.357</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-21"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">yline</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'--'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Color'</span><span class="op" 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 class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-22"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">xlabel</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Hazard Ratio (HR)'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ylabel</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Relative likelihood'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb12-23"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">title</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Relative Likelihood Function'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div></div>
</div>
</div>
<div id="tabset-2-6" class="tab-pane" aria-labelledby="tabset-2-6-tab">
<p>Neither Snowflake nor DuckDB ships <code>erf()</code>, so for <img src="https://latex.codecogs.com/png.latex?%5CPhi"> we use the Abramowitz–Stegun 26.2.17 polynomial (<img src="https://latex.codecogs.com/png.latex?%7C%5Ctext%7Berror%7D%7C%20%3C%207.5%5Ctimes10%5E%7B-8%7D"> per tail). SQL does not plot anything. It returns a table, and something else has to draw it (Power BI, or in this case R).</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode sql code-with-copy"><code class="sourceCode sql"><span id="cb13-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">WITH</span> params <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb13-2">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</span>:<span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">:DOUBLE</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> point,</span>
<span id="cb13-3">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.997</span>) <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.96</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> se</span>
<span id="cb13-4">),</span>
<span id="cb13-5">grid <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb13-6">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (i <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.0</span> <span class="op" 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 class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">599</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> hr</span>
<span id="cb13-7">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">FROM</span> generate_series(<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;">600</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> t(i)</span>
<span id="cb13-8">),</span>
<span id="cb13-9">lik <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb13-10">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> g.hr,</span>
<span id="cb13-11">         (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(g.hr) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(p.point)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> p.se                     <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> z,</span>
<span id="cb13-12">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">power</span>((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(g.hr) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(p.point)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> p.se, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" 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="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> support,</span>
<span id="cb13-13">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">power</span>((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(g.hr) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(p.point)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> p.se, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)           <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> deviance</span>
<span id="cb13-14">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">FROM</span> grid g <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">CROSS</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">JOIN</span> params p</span>
<span id="cb13-15">),</span>
<span id="cb13-16">pv <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb13-17">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> hr, z, support, deviance,</span>
<span id="cb13-18">         <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> ( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>z<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>z<span class="op" 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="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pi()) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span></span>
<span id="cb13-19">               ( <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.319381530</span> <span class="op" 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="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2316419</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(z)))</span>
<span id="cb13-20">               <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.356563782</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">power</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2316419</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(z)), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb13-21">               <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.781477937</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">power</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2316419</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(z)), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb13-22">               <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.821255978</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">power</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2316419</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(z)), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb13-23">               <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.330274429</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">power</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2316419</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(z)), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>) ) ) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> pvalue</span>
<span id="cb13-24">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">FROM</span> lik</span>
<span id="cb13-25">)</span>
<span id="cb13-26"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> hr, support, deviance, pvalue, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(pvalue)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> svalue</span>
<span id="cb13-27"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">FROM</span> pv <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">ORDER</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">BY</span> hr <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">LIMIT</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>;</span></code></pre></div></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>5 records</caption>
<thead>
<tr class="header">
<th style="text-align: right;">hr</th>
<th style="text-align: right;">support</th>
<th style="text-align: right;">deviance</th>
<th style="text-align: right;">pvalue</th>
<th style="text-align: right;">svalue</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">0.500</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">23.1</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">19.3</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.506</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">22.6</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">18.9</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.512</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">22.2</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">18.6</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.518</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">21.7</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">18.3</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.523</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">21.3</td>
<td style="text-align: right;">0</td>
<td style="text-align: right;">17.9</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>All four coordinate views come out of that one query. The <img src="https://latex.codecogs.com/png.latex?1/6.83"> interval that it returns is <img src="https://latex.codecogs.com/png.latex?%5B1.0025,%202.5918%5D">, compared to the reported <img src="https://latex.codecogs.com/png.latex?%5B0.997,%202.59%5D">, and the Abramowitz–Stegun polynomial tracks R’s <code>pnorm</code> to <img src="https://latex.codecogs.com/png.latex?1.5%5Ctimes10%5E%7B-7%7D">:</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">cur <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> DBI<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;">dbGetQuery</span>(con, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb14-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  WITH params AS (SELECT 1.61::DOUBLE AS point, ln(2.59/0.997)/(2*1.96) AS se),</span></span>
<span id="cb14-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  grid AS (SELECT 0.5 + (i-1)*(4.0-0.5)/599 AS hr FROM generate_series(1,600) AS t(i)),</span></span>
<span id="cb14-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  lik AS (SELECT g.hr, (ln(g.hr)-ln(p.point))/p.se AS z,</span></span>
<span id="cb14-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                 exp(-power((ln(g.hr)-ln(p.point))/p.se,2)/2) AS support,</span></span>
<span id="cb14-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                 power((ln(g.hr)-ln(p.point))/p.se,2) AS deviance</span></span>
<span id="cb14-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">          FROM grid g CROSS JOIN params p),</span></span>
<span id="cb14-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  pv AS (SELECT hr, z, support, deviance,</span></span>
<span id="cb14-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">           2 * ( exp(-z*z/2)/sqrt(2*pi()) *</span></span>
<span id="cb14-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">             ( 0.319381530*(1/(1+0.2316419*abs(z)))</span></span>
<span id="cb14-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">             - 0.356563782*power(1/(1+0.2316419*abs(z)),2)</span></span>
<span id="cb14-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">             + 1.781477937*power(1/(1+0.2316419*abs(z)),3)</span></span>
<span id="cb14-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">             - 1.821255978*power(1/(1+0.2316419*abs(z)),4)</span></span>
<span id="cb14-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">             + 1.330274429*power(1/(1+0.2316419*abs(z)),5) ) ) AS pvalue</span></span>
<span id="cb14-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">         FROM lik)</span></span>
<span id="cb14-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  SELECT hr, support, deviance, pvalue, -ln(pvalue)/ln(2) AS svalue</span></span>
<span id="cb14-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  FROM pv ORDER BY hr;"</span>)</span>
<span id="cb14-18"></span>
<span id="cb14-19">inside <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cur<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>hr[cur<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>support <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;">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;">6.83</span>]</span>
<span id="cb14-20">exact  <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;">2</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(cur<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>hr) <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>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb14-21">                             (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</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.997</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.96</span>)))))</span>
<span id="cb14-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(inside) <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.997</span>) <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.02</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(inside) <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.59</span>) <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.02</span>,</span>
<span id="cb14-23">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(cur<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pvalue <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> exact)) <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;">1e-6</span>)</span>
<span id="cb14-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1/6.83 interval: [%.4f, %.4f]</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(inside), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(inside)))</span>
<span id="cb14-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 1/6.83 interval: [1.0025, 2.5918]</span></span>
<span id="cb14-26"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"max |Abramowitz-Stegun - pnorm| = %.2e</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb14-27">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(cur<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pvalue <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> exact))))</span>
<span id="cb14-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; max |Abramowitz-Stegun - pnorm| = 1.49e-07</span></span>
<span id="cb14-29"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S-value at HR = 1: %.2f bits</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb14-30">            cur<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>svalue[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which.min</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(cur<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>hr <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>
<span id="cb14-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; S-value at HR = 1: 4.27 bits</span></span>
<span id="cb14-32"></span>
<span id="cb14-33">op <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;">par</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mfrow =</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;">2</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;">mar =</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;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb14-34">panel <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>(y, ylab, main, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">href =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) {</span>
<span id="cb14-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(cur<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>hr, y, <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;">"l"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">log =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#007C7C"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb14-36">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xaxt =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"n"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hazard Ratio"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylab =</span> ylab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main =</span> main)</span>
<span id="cb14-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">axis</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;">at =</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.5</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;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>))</span>
<span id="cb14-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v =</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;">lty =</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;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d46c5b"</span>)</span>
<span id="cb14-39">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</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;">is.na</span>(href)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">h =</span> href, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb14-40">}</span>
<span id="cb14-41"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">panel</span>(cur<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>support,  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative likelihood"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Support"</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;">6.83</span>)</span>
<span id="cb14-42"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">panel</span>(cur<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>deviance, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Deviance"</span>,            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Deviance"</span>,  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.84</span>)</span>
<span id="cb14-43"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">panel</span>(cur<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pvalue,   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P-value"</span>,             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P-value (compatibility)"</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>)</span>
<span id="cb14-44"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">panel</span>(cur<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>svalue,   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bits of information"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S-value"</span>,   <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.32</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-12-4.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">par</span>(op)</span></code></pre></div></div>
</div>
<p>The dotted vertical line marks HR <img src="https://latex.codecogs.com/png.latex?=%201">. If we read the bottom-right panel, the S-value there is 4.27 bits, which is about as much evidence against the null as five straight heads (and that is not very much).</p>
</div>
</div>
</div>
</section>
<section id="the-inverse-route-sweeping-levels-instead-of-parameters-with-cifunction" class="level2">
<h2 class="anchored" data-anchor-id="the-inverse-route-sweeping-levels-instead-of-parameters-with-cifunction">The inverse route: sweeping levels instead of parameters with <code>cifunction</code></h2>
<p>Everything above builds the curve by sweeping the <strong>parameter</strong> axis, where we fix a grid of candidate values, compute one <img src="https://latex.codecogs.com/png.latex?z"> (or one refit) per value, and read off a <em>P</em>-value. However, there is a second route to the same object that works from the other side. We can sweep the <strong>confidence level</strong> from 0 to 99.99% and compute the interval limits at each level. If we plot the limits against the levels, we trace the same curve. Thus, the two constructions are inverse functions of each other, since the <em>P</em>-value function evaluated at a level’s limit returns that level’s <img src="https://latex.codecogs.com/png.latex?%5Calpha">.</p>
<p>A <strong>confidence interval function</strong> (also called a confidence curve, <em>P</em>-value function, or consonance function) displays every confidence interval around an estimate at once. Ariel Linden’s <a href="https://lesslikely.com/statistics/cifunction/"><code>cifunction</code></a> Stata module implements the level-sweeping construction directly, and the R equivalent is <a href="https://github.com/zadrafi/concurve">concurve</a>. We only need to install it once from SSC:</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb16-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">ssc</span> install cifunction</span>
<span id="cb16-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">ssc</span> install getregstats   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// helper: recover SEs from p-values or CI limits</span></span></code></pre></div></div>
</div>
<p>There is one convention that we need to respect here. With <code>eform</code>, <code>cifunction</code> takes <code>se()</code> on the <strong>ratio scale</strong> (the delta-method SE, <img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7BHR%7D%20%5Ctimes%20SE(%5Cln%20%5Cwidehat%7BHR%7D)">), does its computation on the log scale, and then back-transforms. We’ll use the same Brown et al.&nbsp;example as above, and assert the saved output against both the reported interval and the manual z-grid construction:</p>
<div class="cell" data-layout-align="center" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb17-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">version</span> 16</span>
<span id="cb17-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">all</span></span>
<span id="cb17-3"></span>
<span id="cb17-4">* <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SE</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">on</span> the <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">scale</span> from the reported interval, then the <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">ratio</span>-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">scale</span></span>
<span id="cb17-5">* (delta-method) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SE</span> that -cifunction- expects with -<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">eform</span>-</span>
<span id="cb17-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scalar</span> se_log   = <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(2.59 / 0.997) / (2 * 1.96)</span>
<span id="cb17-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scalar</span> se_ratio = 1.61 * se_log</span>
<span id="cb17-8"></span>
<span id="cb17-9"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">tempfile</span> cif</span>
<span id="cb17-10">cifunction 1.61, se(<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`=se_ratio'</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">eform</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">saving</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"`cif'"</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span>)</span>
<span id="cb17-11"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">use</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"`cif'"</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb17-12"></span>
<span id="cb17-13">* check 1: the 95% <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">row</span> reproduces the reported interval</span>
<span id="cb17-14"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">quietly</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">summarize</span> lcl1 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(cilev - 95) &lt; 0.005</span>
<span id="cb17-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scalar</span> l95 = <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">mean</span>)</span>
<span id="cb17-16"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">quietly</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">summarize</span> ucl1 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(cilev - 95) &lt; 0.005</span>
<span id="cb17-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scalar</span> u95 = <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">mean</span>)</span>
<span id="cb17-18"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">display</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cifunction 95% limits: "</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> result %6.4f l95 <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb17-19">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" to "</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> result %6.4f u95</span>
<span id="cb17-20"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">assert</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(l95 - 0.997) &lt; 0.02</span>
<span id="cb17-21"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">assert</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(u95 - 2.59)  &lt; 0.02</span>
<span id="cb17-22"></span>
<span id="cb17-23">* check 2: the <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">two</span> routes are inverses -- the z-<span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span> P-<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">value</span> evaluated <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">at</span></span>
<span id="cb17-24">* each level's limit returns that level's <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">alpha</span></span>
<span id="cb17-25"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">generate</span> p_upper = 2 * (1 - <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(ucl1) - <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(1.61)) / se_log)))</span>
<span id="cb17-26"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">generate</span> p_lower = 2 * (1 - <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(lcl1) - <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(1.61)) / se_log)))</span>
<span id="cb17-27"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">assert</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(p_upper - plev) &lt; 1e-4</span>
<span id="cb17-28"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">assert</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(p_lower - plev) &lt; 1e-4</span>
<span id="cb17-29"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">display</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> result <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"validation PASSED: level sweep == parameter sweep"</span></span>
<span id="cb17-30">#&gt; cifunction 95% limits: 0.9989 to 2.5949</span>
<span id="cb17-31">#&gt; </span>
<span id="cb17-32">#&gt; </span>
<span id="cb17-33">#&gt; </span>
<span id="cb17-34">#&gt; </span>
<span id="cb17-35">#&gt; </span>
<span id="cb17-36">#&gt; </span>
<span id="cb17-37">#&gt; </span>
<span id="cb17-38">#&gt; validation PASSED: <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">level</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sweep</span> == parameter <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sweep</span></span></code></pre></div></div>
</div>
</section>
<section id="profile-likelihood-for-a-regression-coefficient" class="level2">
<h2 class="anchored" data-anchor-id="profile-likelihood-for-a-regression-coefficient">Profile likelihood for a regression coefficient</h2>
<p>Here, we use what is sometimes called the offset trick. To fix the coefficient of <img src="https://latex.codecogs.com/png.latex?x"> at <img src="https://latex.codecogs.com/png.latex?b">, we move <img src="https://latex.codecogs.com/png.latex?bx"> into an offset and refit the model without <img src="https://latex.codecogs.com/png.latex?x">. The refit re-maximizes the intercept and the other covariates at every grid point, and that is what makes it a <em>profile</em> likelihood (as opposed to a slice through the likelihood at the MLEs).</p>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-3-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-3-1" aria-controls="tabset-3-1" aria-selected="true" href="">R</a></li><li class="nav-item"><a class="nav-link" id="tabset-3-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-3-2" aria-controls="tabset-3-2" aria-selected="false" href="">Stata</a></li><li class="nav-item"><a class="nav-link" id="tabset-3-3-tab" data-bs-toggle="tab" data-bs-target="#tabset-3-3" aria-controls="tabset-3-3" aria-selected="false" href="">Python</a></li><li class="nav-item"><a class="nav-link" id="tabset-3-4-tab" data-bs-toggle="tab" data-bs-target="#tabset-3-4" aria-controls="tabset-3-4" aria-selected="false" href="">Julia</a></li><li class="nav-item"><a class="nav-link" id="tabset-3-5-tab" data-bs-toggle="tab" data-bs-target="#tabset-3-5" aria-controls="tabset-3-5" aria-selected="false" href="">MATLAB</a></li><li class="nav-item"><a class="nav-link" id="tabset-3-6-tab" data-bs-toggle="tab" data-bs-target="#tabset-3-6" aria-controls="tabset-3-6" aria-selected="false" href="">SQL</a></li></ul>
<div class="tab-content">
<div id="tabset-3-1" class="tab-pane active" aria-labelledby="tabset-3-1-tab">
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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="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;">1031</span>)</span>
<span id="cb18-2">n <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;">300</span></span>
<span id="cb18-3">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>(n)</span>
<span id="cb18-4">w <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>(n)</span>
<span id="cb18-5">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;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plogis</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.3</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.8</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x <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.4</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>w))</span>
<span id="cb18-6"></span>
<span id="cb18-7">full  <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;">glm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> w, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">binomial</span>())</span>
<span id="cb18-8">bhat  <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;">coef</span>(full)[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>]]</span>
<span id="cb18-9">sehat <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>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diag</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vcov</span>(full)))[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>]]</span>
<span id="cb18-10"></span>
<span id="cb18-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># offset trick: fix the coefficient of x at b and refit without x, so the</span></span>
<span id="cb18-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># intercept and w are re-maximized at every grid point</span></span>
<span id="cb18-13">grid <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;">seq</span>(bhat <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;">4</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sehat, bhat <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;">4</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sehat, <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;">121</span>)</span>
<span id="cb18-14">ll <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;">vapply</span>(grid, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(b)</span>
<span id="cb18-15">  <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;">logLik</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> w, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">binomial</span>(), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">offset =</span> b<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x))),</span>
<span id="cb18-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb18-17"></span>
<span id="cb18-18">support  <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;">exp</span>(ll <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;">max</span>(ll))</span>
<span id="cb18-19">deviance <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</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>(ll <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;">max</span>(ll))</span>
<span id="cb18-20"></span>
<span id="cb18-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(grid[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which.max</span>(support)] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> bhat) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diff</span>(grid)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb18-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"validation PASSED: profile peak == full-model MLE</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb18-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; validation PASSED: profile peak == full-model MLE</span></span>
<span id="cb18-24"></span>
<span id="cb18-25">si <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;">range</span>(grid[support <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;">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;">6.83</span>])</span>
<span id="cb18-26"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1/6.83 support interval: [%.4f, %.4f]   Wald 95%% CI: [%.4f, %.4f]</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb18-27">            si[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], si[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>], bhat <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.96</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sehat, bhat <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.96</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sehat))</span>
<span id="cb18-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 1/6.83 support interval: [0.5593, 1.1148]   Wald 95% CI: [0.5459, 1.1090]</span></span>
<span id="cb18-29"></span>
<span id="cb18-30"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(grid, support, <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;">"l"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#007C7C"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb18-31">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coefficient of x (log-odds scale)"</span>,</span>
<span id="cb18-32">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative likelihood"</span>,</span>
<span id="cb18-33">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Profile Likelihood Function"</span>)</span>
<span id="cb18-34"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v =</span> bhat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</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;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray40"</span>)</span>
<span id="cb18-35"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">h =</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;">6.83</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-15-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-3-2" class="tab-pane" aria-labelledby="tabset-3-2-tab">
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<pre><code>#&gt; Number of observations (_N) was 0, now 300.
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; (file /var/folders/p4/rr9th0593k1_k0bf90vnc57w0000gn/T//S_93650.000001
#&gt;     not found)
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; profile peak =  0.748198   full-model MLE =  0.748198
#&gt; 
#&gt; 
#&gt; 
#&gt; 1/6.83 support interval: [0.4730, 1.0430]   Wald 95% CI: [0.4593, 1.0371]
#&gt; 
#&gt; 
#&gt; 
#&gt; Part B validation PASSED: profile peak and support interval check out
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; file profile_likelihood_logit.svg saved as SVG format
#&gt; 
#&gt; 
#&gt; All likelihood-function constructions validated.</code></pre>
<p><img src="https://lesslikely.com/statistics/profile_likelihood_logit.svg" class="img-fluid"></p>
</div>
</div>
<div id="tabset-3-3" class="tab-pane" aria-labelledby="tabset-3-3-tab">
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb20-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb20-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> statsmodels.api <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> sm</span>
<span id="cb20-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb20-4"></span>
<span id="cb20-5">rng <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.default_rng(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>)</span>
<span id="cb20-6">n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span></span>
<span id="cb20-7">x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, n)</span>
<span id="cb20-8">w <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, n)</span>
<span id="cb20-9">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (rng.uniform(size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>n) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> np.exp(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>w)))).astype(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">float</span>)</span>
<span id="cb20-10"></span>
<span id="cb20-11">X_full <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.add_constant(np.column_stack([x, w]))</span>
<span id="cb20-12">full <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.GLM(y, X_full, family<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>sm.families.Binomial()).fit()</span>
<span id="cb20-13">bhat, sehat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> full.params[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], full.bse[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb20-14">X_nuis <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.add_constant(w)</span>
<span id="cb20-15"></span>
<span id="cb20-16">grid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.linspace(bhat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sehat, bhat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sehat, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">121</span>)</span>
<span id="cb20-17">ll <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([</span>
<span id="cb20-18">    sm.GLM(y, X_nuis, family<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>sm.families.Binomial(), offset<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>b<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x).fit().llf</span>
<span id="cb20-19">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> grid</span>
<span id="cb20-20">])</span>
<span id="cb20-21">support <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.exp(ll <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> ll.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>())</span>
<span id="cb20-22"></span>
<span id="cb20-23"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">assert</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">abs</span>(grid[np.argmax(support)] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> bhat) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> grid[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> grid[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]</span>
<span id="cb20-24"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"validation PASSED: profile peak == full-model MLE"</span>)</span>
<span id="cb20-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; validation PASSED: profile peak == full-model MLE</span></span>
<span id="cb20-26"></span>
<span id="cb20-27">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots(figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.5</span>))</span>
<span id="cb20-28">ax.plot(grid, support, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#007C7C"</span>)</span>
<span id="cb20-29">ax.axvline(bhat, ls<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"--"</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</span>)</span>
<span id="cb20-30">ax.axhline(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>)</span>
<span id="cb20-31">ax.set_xlabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coefficient of x (log-odds)"</span>)</span>
<span id="cb20-32">ax.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative likelihood"</span>)</span>
<span id="cb20-33">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Profile Likelihood Function"</span>)</span>
<span id="cb20-34">plt.show()</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-17-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-3-4" class="tab-pane" aria-labelledby="tabset-3-4-tab">
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb21-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">using</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Distributions</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">GLM</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">DataFrames</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Random</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Plots</span></span>
<span id="cb21-2"></span>
<span id="cb21-3">rng <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">MersenneTwister</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>);</span>
<span id="cb21-4">n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span>;</span>
<span id="cb21-5">x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randn</span>(rng, n);</span>
<span id="cb21-6">w <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randn</span>(rng, n);</span>
<span id="cb21-7">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Float64</span>.(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rand</span>(rng, n) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">./</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>.(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">-</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span> w))));</span>
<span id="cb21-8">df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">DataFrame</span>(y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> y, x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> x, w <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> w)</span>
<span id="cb21-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 300×3 DataFrame</span></span>
<span id="cb21-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Row │ y        x            w</span></span>
<span id="cb21-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;      │ Float64  Float64      Float64</span></span>
<span id="cb21-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ─────┼──────────────────────────────────</span></span>
<span id="cb21-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    1 │     0.0   1.53733      0.212606</span></span>
<span id="cb21-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    2 │     1.0   0.67567      2.18329</span></span>
<span id="cb21-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    3 │     0.0   0.529915    -0.411984</span></span>
<span id="cb21-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    4 │     0.0  -0.469345     0.243801</span></span>
<span id="cb21-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    5 │     0.0  -0.344731     0.181979</span></span>
<span id="cb21-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    6 │     1.0   0.00596521   0.102878</span></span>
<span id="cb21-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    7 │     0.0  -1.52318     -0.446261</span></span>
<span id="cb21-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    8 │     1.0   0.390072    -1.61528</span></span>
<span id="cb21-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   ⋮  │    ⋮          ⋮           ⋮</span></span>
<span id="cb21-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  294 │     1.0  -1.21183      0.133128</span></span>
<span id="cb21-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  295 │     1.0   0.35636     -0.373798</span></span>
<span id="cb21-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  296 │     1.0   0.125155     0.561362</span></span>
<span id="cb21-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  297 │     0.0  -1.63194     -0.0784788</span></span>
<span id="cb21-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  298 │     0.0  -0.464039    -0.214666</span></span>
<span id="cb21-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  299 │     1.0   1.21094     -0.392618</span></span>
<span id="cb21-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  300 │     1.0  -1.2263      -0.228791</span></span>
<span id="cb21-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                         285 rows omitted</span></span>
<span id="cb21-30"></span>
<span id="cb21-31">full <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(<span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@formula</span>(y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> w), df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Binomial</span>(), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">LogitLink</span>())</span>
<span id="cb21-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; StatsModels.TableRegressionModel{GeneralizedLinearModel{GLM.GlmResp{Vector{Float64}, Binomial{Float64}, LogitLink}, GLM.DensePredChol{Float64, CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64</span><span class="re">}}}</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}, Matrix{Float64}}</span></span>
<span id="cb21-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb21-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; y ~ 1 + x + w</span></span>
<span id="cb21-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb21-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Coefficients:</span></span>
<span id="cb21-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ─────────────────────────────────────────────────────────────────────────</span></span>
<span id="cb21-38"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                  Coef.  Std. Error      z  Pr(&gt;|z|)  Lower 95%  Upper 95%</span></span>
<span id="cb21-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ─────────────────────────────────────────────────────────────────────────</span></span>
<span id="cb21-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; (Intercept)  -0.378416    0.133353  -2.84    0.0045  -0.639782  -0.117049</span></span>
<span id="cb21-41"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; x             1.07021     0.160245   6.68    &lt;1e-10   0.756132   1.38428</span></span>
<span id="cb21-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; w             0.475207    0.130953   3.63    0.0003   0.218545   0.73187</span></span>
<span id="cb21-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ─────────────────────────────────────────────────────────────────────────</span></span>
<span id="cb21-44">bhat, sehat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(full)[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>], <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stderror</span>(full)[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>];</span>
<span id="cb21-45"></span>
<span id="cb21-46">grid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(bhat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sehat, bhat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sehat; length <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">121</span>);</span>
<span id="cb21-47">ll <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">loglikelihood</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(<span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@formula</span>(y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> w), df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Binomial</span>(), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">LogitLink</span>();</span>
<span id="cb21-48">                        offset <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span> x)) for b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> grid];</span>
<span id="cb21-49">support <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>.(ll <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">maximum</span>(ll));</span>
<span id="cb21-50"></span>
<span id="cb21-51"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@assert</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(grid[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">argmax</span>(support)] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> bhat) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> grid[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> grid[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb21-52"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">println</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"validation PASSED: profile peak == full-model MLE"</span>)</span>
<span id="cb21-53"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; validation PASSED: profile peak == full-model MLE</span></span>
<span id="cb21-54"></span>
<span id="cb21-55">p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(grid, support; legend <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">false</span>,</span>
<span id="cb21-56">         xlabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coefficient of x (log-odds)"</span>,</span>
<span id="cb21-57">         ylabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative likelihood"</span>,</span>
<span id="cb21-58">         title <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Profile Likelihood Function"</span>);</span>
<span id="cb21-59"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vline!</span>(p, [bhat]; linestyle <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>dash, color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>gray);</span>
<span id="cb21-60"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hline!</span>(p, [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span>]; color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>gray, alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>);</span>
<span id="cb21-61">p</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-18-J1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="300"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-3-5" class="tab-pane" aria-labelledby="tabset-3-5-tab">
<p><code>glmfit</code> takes an <code>'Offset'</code> name–value pair, so the offset trick carries over directly. We fix the coefficient of <img src="https://latex.codecogs.com/png.latex?x"> at <img src="https://latex.codecogs.com/png.latex?b">, push <img src="https://latex.codecogs.com/png.latex?bx"> into the offset, and refit on <img src="https://latex.codecogs.com/png.latex?w"> alone, so that the intercept and <img src="https://latex.codecogs.com/png.latex?w"> are re-maximized at every point.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode matlab code-with-copy"><code class="sourceCode matlab"><span id="cb22-1"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">rng</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'twister'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-2"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">n</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-3"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">randn</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-4"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">w</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">randn</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-5"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">y</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">double</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">rand</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">./</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">exp</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">w</span>))))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-6"></span>
<span id="cb22-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% full fit: MLE and Wald SE define the grid</span></span>
<span id="cb22-8">[<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b_full</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">stats</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">glmfit</span>([<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">w</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'binomial'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'link'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'logit'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-9"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bhat</span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">b_full</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-10"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sehat</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">stats</span>.<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">se</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-11"></span>
<span id="cb22-12"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">grid</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">linspace</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bhat</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sehat</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bhat</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sehat</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">121</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">';</span></span>
<span id="cb22-13"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ll</span>   <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">zeros</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">size</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">grid</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-14"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">k</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">numel</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">grid</span>)</span>
<span id="cb22-15">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% offset fixes b*x; only the intercept and w are re-estimated</span></span>
<span id="cb22-16">    [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">dev</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">glmfit</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">w</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'binomial'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'link'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'logit'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span></span>
<span id="cb22-17">                      <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Offset'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">grid</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">k</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">x</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-18">    <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ll</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">k</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">dev</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span>   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% glmfit returns deviance = -2*loglik (up to a constant)</span></span>
<span id="cb22-19"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb22-20"></span>
<span id="cb22-21"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">support</span>  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">exp</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ll</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">max</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ll</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-22"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">deviance</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ll</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">max</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ll</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-23"></span>
<span id="cb22-24">[<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">imax</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">max</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">support</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-25"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">assert</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">abs</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">grid</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">imax</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bhat</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">grid</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">grid</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb22-26"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">disp</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'validation PASSED: profile peak == full-model MLE'</span>)</span>
<span id="cb22-27"></span>
<span id="cb22-28"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">si</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">min</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">grid</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">support</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">max</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">grid</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">support</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span>))]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-29"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">fprintf</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'1/6.83 support interval: [%.4f, %.4f]   Wald 95%% CI: [%.4f, %.4f]\n'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span></span>
<span id="cb22-30">        <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">si</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">si</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bhat</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.96</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sehat</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bhat</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.96</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">sehat</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-31"></span>
<span id="cb22-32"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">figure</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-33"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">plot</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">support</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'LineWidth'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Color'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.486</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.486</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-34"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">xline</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">bhat</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>   <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'--'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Color'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-35"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">yline</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'--'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Color'</span><span class="op" 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 class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-36"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">xlabel</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Coefficient of x (log-odds scale)'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-37"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">ylabel</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Relative likelihood'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb22-38"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">title</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">'Profile Likelihood Function'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div></div>
</div>
<p>For the binomial family, <code>glmfit</code>’s deviance is <img src="https://latex.codecogs.com/png.latex?-2%5Cell"> up to an additive constant that does not depend on the parameters. Thus, it cancels in <code>ll - max(ll)</code>, which is all that the relative likelihood needs.</p>
</div>
<div id="tabset-3-6" class="tab-pane" aria-labelledby="tabset-3-6-tab">
<p>SQL cannot iteratively refit a GLM (there is no IRLS), so a logistic profile is out of scope. However, for the <strong>normal linear model</strong>, the conditional MLEs of the intercept and <img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2"> given a fixed slope are closed-form. Thus, profiling collapses to one <code>AVG</code> per candidate slope, which means that a single <code>GROUP BY</code> does the work of a refit loop. The profile-grid MLE matches <code>REGR_SLOPE</code> exactly here, and the peak and the closed form agree to the last printed digit, since both are computed from the same rows. (One thing to watch for with dialects: Snowflake rejects correlated scalar subqueries here, and the <code>CROSS JOIN</code> + <code>GROUP BY</code> below is the idiom that works.)</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode sql code-with-copy"><code class="sourceCode sql"><span id="cb23-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-- One AVG per candidate slope: profiling collapses to a GROUP BY because the</span></span>
<span id="cb23-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-- conditional MLEs of the intercept and sigma^2 given a fixed slope are</span></span>
<span id="cb23-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-- closed-form. No refit loop, no IRLS.</span></span>
<span id="cb23-4"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">WITH</span> closed <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb23-5">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">regr_slope</span>(y, x) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> b1, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">FROM</span> mytable</span>
<span id="cb23-6">),</span>
<span id="cb23-7">m <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb23-8">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">avg</span>(x) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> xbar, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">avg</span>(y) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> ybar <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">FROM</span> mytable</span>
<span id="cb23-9">),</span>
<span id="cb23-10">grid <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb23-11">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> c.b1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (g.i <span class="op" 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="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">400</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> b_cand</span>
<span id="cb23-12">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">FROM</span> generate_series(<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;">401</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> g(i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">CROSS</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">JOIN</span> closed c</span>
<span id="cb23-13">),</span>
<span id="cb23-14">prof <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb23-15">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> g.b_cand,</span>
<span id="cb23-16">         <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(c.n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.0</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span></span>
<span id="cb23-17">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">avg</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">power</span>(d.y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> (m.ybar <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> g.b_cand <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> m.xbar)</span>
<span id="cb23-18">                          <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> g.b_cand <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> d.x, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> prof_loglik</span>
<span id="cb23-19">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">FROM</span> grid g</span>
<span id="cb23-20">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">CROSS</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">JOIN</span> mytable d</span>
<span id="cb23-21">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">CROSS</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">JOIN</span> m</span>
<span id="cb23-22">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">CROSS</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">JOIN</span> closed c</span>
<span id="cb23-23">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">GROUP</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">BY</span> g.b_cand, c.n</span>
<span id="cb23-24">)</span>
<span id="cb23-25"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> b_cand,</span>
<span id="cb23-26">       <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(prof_loglik <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(prof_loglik) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">OVER</span> ()) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> support</span>
<span id="cb23-27"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">FROM</span> prof <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">ORDER</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">BY</span> b_cand <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">LIMIT</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>;</span></code></pre></div></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>5 records</caption>
<thead>
<tr class="header">
<th style="text-align: right;">b_cand</th>
<th style="text-align: right;">support</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">0.295</td>
<td style="text-align: right;">0.012</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.297</td>
<td style="text-align: right;">0.013</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.298</td>
<td style="text-align: right;">0.013</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.300</td>
<td style="text-align: right;">0.014</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.301</td>
<td style="text-align: right;">0.014</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>That returns all 401 grid points (truncated to five above). SQL has no plotting layer, so we hand the result set to whatever draws the charts, which here is R:</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">prof <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> DBI<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;">dbGetQuery</span>(con, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb24-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  WITH closed AS (SELECT regr_slope(y,x) AS b1, count(*) AS n FROM mytable),</span></span>
<span id="cb24-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  m AS (SELECT avg(x) AS xbar, avg(y) AS ybar FROM mytable),</span></span>
<span id="cb24-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  grid AS (SELECT c.b1 - 0.3 + (g.i-1) * 0.6/400 AS b_cand</span></span>
<span id="cb24-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">           FROM generate_series(1,401) AS g(i) CROSS JOIN closed c),</span></span>
<span id="cb24-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  prof AS (</span></span>
<span id="cb24-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    SELECT g.b_cand,</span></span>
<span id="cb24-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">           -(c.n/2.0) * ln(avg(power(d.y - (m.ybar - g.b_cand*m.xbar)</span></span>
<span id="cb24-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                                         - g.b_cand*d.x, 2))) AS prof_loglik</span></span>
<span id="cb24-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    FROM grid g CROSS JOIN mytable d CROSS JOIN m CROSS JOIN closed c</span></span>
<span id="cb24-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    GROUP BY g.b_cand, c.n)</span></span>
<span id="cb24-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  SELECT b_cand, exp(prof_loglik - max(prof_loglik) OVER ()) AS support</span></span>
<span id="cb24-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  FROM prof ORDER BY b_cand;"</span>)</span>
<span id="cb24-14"></span>
<span id="cb24-15">b1_sql <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> sql<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>b1</span>
<span id="cb24-16">peak   <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> prof<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>b_cand[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which.max</span>(prof<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>support)]</span>
<span id="cb24-17">si     <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;">range</span>(prof<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>b_cand[prof<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>support <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;">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;">6.83</span>])</span>
<span id="cb24-18">ci     <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;">confint</span>(ols, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>)</span>
<span id="cb24-19"></span>
<span id="cb24-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># the two self-checks from the top of the post</span></span>
<span id="cb24-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(peak <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> b1_sql) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diff</span>(prof<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>b_cand)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb24-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"profile peak = %.10f   REGR_SLOPE = %.10f</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, peak, b1_sql))</span>
<span id="cb24-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; profile peak = 0.5953684349   REGR_SLOPE = 0.5953684349</span></span>
<span id="cb24-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1/6.83 support interval: [%.4f, %.4f]</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, si[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], si[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]))</span>
<span id="cb24-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 1/6.83 support interval: [0.3989, 0.7919]</span></span>
<span id="cb24-26"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm 95%% CI:               [%.4f, %.4f]</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>, ci[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], ci[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]))</span>
<span id="cb24-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; lm 95% CI:               [0.3974, 0.7933]</span></span>
<span id="cb24-28"></span>
<span id="cb24-29"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(prof<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>b_cand, prof<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>support, <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;">"l"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#007C7C"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb24-30">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Candidate slope"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative likelihood"</span>,</span>
<span id="cb24-31">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Profile Likelihood Computed Entirely in SQL"</span>)</span>
<span id="cb24-32"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v =</span> b1_sql, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</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;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray40"</span>)</span>
<span id="cb24-33"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">h =</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;">6.83</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb24-34"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">segments</span>(si[<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;">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;">6.83</span>, si[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</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;">6.83</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d46c5b"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb24-35"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(b1_sql, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.55</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"REGR_SLOPE"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cex =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray30"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pos =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb24-36"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(si), <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;">6.83</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.055</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1/6.83 support interval"</span>,</span>
<span id="cb24-37">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cex =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d46c5b"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-20-4.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>The support interval drawn in orange and the Wald interval from <code>lm</code> agree to about three decimals. This is the same identity that the R, Python, and Julia sections check, except that here every number is produced by a <code>GROUP BY</code>.</p>
</div>
</div>
</div>
</section>
<section id="existing-r-tools-as-alternatives" class="level2">
<h2 class="anchored" data-anchor-id="existing-r-tools-as-alternatives">Existing R tools as alternatives</h2>
<p>Everything above builds the likelihood by hand. In R, we usually don’t have to, since several packages will do the maximizing and profiling for us, and their output can be reshaped into the same five-column object that <code>concurve</code> plots. The one helper below is all the glue that we need. For a longer treatment, see the concurve vignettes on <a href="https://stat.lesslikely.com/concurve/articles/likelihood-tools.html">likelihood tools</a> and <a href="https://stat.lesslikely.com/concurve/articles/likelihood.html">profile likelihoods</a>.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(concurve)</span>
<span id="cb25-2"></span>
<span id="cb25-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Reshape any (parameter grid, log-likelihood) pair into concurve's format.</span></span>
<span id="cb25-4">as_concurve_lik <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>(values, loglik) {</span>
<span id="cb25-5">  loglik_rel <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> loglik <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;">max</span>(loglik)</span>
<span id="cb25-6">  support    <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;">exp</span>(loglik_rel)</span>
<span id="cb25-7">  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>(</span>
<span id="cb25-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values        =</span> values,</span>
<span id="cb25-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">likelihood    =</span> support,</span>
<span id="cb25-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">loglikelihood =</span> loglik_rel,</span>
<span id="cb25-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">support       =</span> support,</span>
<span id="cb25-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">deviancestat  =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>loglik_rel</span>
<span id="cb25-13">  )</span>
<span id="cb25-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">class</span>(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;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data.frame"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"concurve"</span>)</span>
<span id="cb25-15">  df</span>
<span id="cb25-16">}</span>
<span id="cb25-17"></span>
<span id="cb25-18"><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="cb25-19">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;">50</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">9.3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.2</span>)</span>
<span id="cb25-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(x))</span>
<span id="cb25-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; mean   sd </span></span>
<span id="cb25-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 9.41 2.96</span></span></code></pre></div></div>
</div>
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-4-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-4-1" aria-controls="tabset-4-1" aria-selected="true" href="">optim</a></li><li class="nav-item"><a class="nav-link" id="tabset-4-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-4-2" aria-controls="tabset-4-2" aria-selected="false" href="">maxLik</a></li><li class="nav-item"><a class="nav-link" id="tabset-4-3-tab" data-bs-toggle="tab" data-bs-target="#tabset-4-3" aria-controls="tabset-4-3" aria-selected="false" href="">bbmle</a></li><li class="nav-item"><a class="nav-link" id="tabset-4-4-tab" data-bs-toggle="tab" data-bs-target="#tabset-4-4" aria-controls="tabset-4-4" aria-selected="false" href="">cond</a></li></ul>
<div class="tab-content">
<div id="tabset-4-1" class="tab-pane active" aria-labelledby="tabset-4-1-tab">
<p>This is base R with no dependencies. <code>optim</code> finds the MLE, and the Hessian gives us Wald standard errors. To <em>profile</em> <img src="https://latex.codecogs.com/png.latex?%5Cmu">, we substitute the conditional MLE of <img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2"> at each grid point instead of holding <img src="https://latex.codecogs.com/png.latex?%5Csigma"> fixed.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">nll_normal <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>(theta, x) {</span>
<span id="cb26-2">  mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> theta[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]; sigma <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> theta[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]</span>
<span id="cb26-3">  <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;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> sigma, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">log =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>))</span>
<span id="cb26-4">}</span>
<span id="cb26-5"></span>
<span id="cb26-6">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;">optim</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</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;">sigma =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>), nll_normal, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x,</span>
<span id="cb26-7">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BFGS"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hessian =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb26-8">fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par</span>
<span id="cb26-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    mu sigma </span></span>
<span id="cb26-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  9.41  2.93</span></span>
<span id="cb26-11"><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>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">solve</span>(fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>hessian)))</span>
<span id="cb26-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    mu sigma </span></span>
<span id="cb26-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 0.415 0.293</span></span>
<span id="cb26-14"></span>
<span id="cb26-15">n <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;">length</span>(x)</span>
<span id="cb26-16">mu_grid <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;">seq</span>(fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</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>, fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</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;">length.out =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4000</span>)</span>
<span id="cb26-17">loglik_mu <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;">vapply</span>(mu_grid, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(m) {</span>
<span id="cb26-18">  sigma2_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;">mean</span>((x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> m)<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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># conditional MLE of sigma^2 given mu</span></span>
<span id="cb26-19">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>(n <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;">log</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> pi) <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>(sigma2_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;">1</span>)</span>
<span id="cb26-20">}, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb26-21"></span>
<span id="cb26-22">lik_optim <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_concurve_lik</span>(mu_grid, loglik_mu)</span>
<span id="cb26-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(mu_grid[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which.max</span>(loglik_mu)] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>]]) <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;">1e-2</span>)</span>
<span id="cb26-24"></span>
<span id="cb26-25"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggcurve</span>(lik_optim, <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;">"l1"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nullvalue =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>]], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb26-26">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xaxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(mu),</span>
<span id="cb26-27">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Likelihood for the Mean (via optim profiling)"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-22-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-4-2" class="tab-pane" aria-labelledby="tabset-4-2-tab">
<p><code>maxLik</code> maximizes the log-likelihood directly, with no sign flipping, and prints a summary with standard errors.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(maxLik)</span>
<span id="cb27-2"></span>
<span id="cb27-3">loglik_normal <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>(theta, x) {</span>
<span id="cb27-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> theta[<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;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(theta[<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;">log =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>))</span>
<span id="cb27-5">}</span>
<span id="cb27-6">theta_mle <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;">maxLik</span>(loglik_normal, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</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;">sig2 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x)</span>
<span id="cb27-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(theta_mle)</span>
<span id="cb27-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; --------------------------------------------</span></span>
<span id="cb27-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Maximum Likelihood estimation</span></span>
<span id="cb27-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Newton-Raphson maximisation, 7 iterations</span></span>
<span id="cb27-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Return code 8: successive function values within relative tolerance limit (reltol)</span></span>
<span id="cb27-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Log-Likelihood: -125 </span></span>
<span id="cb27-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 2  free parameters</span></span>
<span id="cb27-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Estimates:</span></span>
<span id="cb27-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;      Estimate Std. error t value Pr(&gt; t)    </span></span>
<span id="cb27-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; mu      9.410      0.415   22.66 &lt; 2e-16 ***</span></span>
<span id="cb27-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; sig2    8.602      1.712    5.02 5.1e-07 ***</span></span>
<span id="cb27-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ---</span></span>
<span id="cb27-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1</span></span>
<span id="cb27-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; --------------------------------------------</span></span>
<span id="cb27-21"></span>
<span id="cb27-22">loglik_mu2 <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;">vapply</span>(mu_grid, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(m) {</span>
<span id="cb27-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">loglik_normal</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(m, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>((x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> m)<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;">x =</span> x)</span>
<span id="cb27-24">}, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb27-25"></span>
<span id="cb27-26"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(theta_mle)[[<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> fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>]]) <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;">1e-3</span>)</span>
<span id="cb27-27"></span>
<span id="cb27-28"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggcurve</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_concurve_lik</span>(mu_grid, loglik_mu2), <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;">"l1"</span>,</span>
<span id="cb27-29">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nullvalue =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(theta_mle)[[<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;">2</span>),</span>
<span id="cb27-30">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xaxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(mu),</span>
<span id="cb27-31">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Likelihood for the Mean (via maxLik)"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-23-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-4-3" class="tab-pane" aria-labelledby="tabset-4-3-tab">
<p><code>bbmle::mle2</code> is the only route here that does the profiling for us. <code>profile()</code> returns the signed square-root deviance <img src="https://latex.codecogs.com/png.latex?z">, so the relative log-likelihood is <img src="https://latex.codecogs.com/png.latex?-z%5E2/2">.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(bbmle)</span>
<span id="cb28-2"></span>
<span id="cb28-3">nll <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>(mu, sigma) <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;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> sigma, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">log =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>))</span>
<span id="cb28-4">m <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;">mle2</span>(nll, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start =</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;">mu =</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;">sigma =</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;">data =</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;">x =</span> x))</span>
<span id="cb28-5"></span>
<span id="cb28-6">pr    <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;">profile</span>(m)</span>
<span id="cb28-7">pr_mu <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.data.frame</span>(pr)</span>
<span id="cb28-8">pr_mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pr_mu[pr_mu<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>param <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;">"mu"</span>, ]</span>
<span id="cb28-9"></span>
<span id="cb28-10">mu_vals <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pr_mu[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"par.vals.mu"</span>]]</span>
<span id="cb28-11"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(mu_vals)) mu_vals <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pr_mu[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>]]</span>
<span id="cb28-12"></span>
<span id="cb28-13">lik_bbmle <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_concurve_lik</span>(mu_vals, <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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> pr_mu<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z<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>
<span id="cb28-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(m)[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>]]) <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;">1e-3</span>)</span>
<span id="cb28-15"></span>
<span id="cb28-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggcurve</span>(lik_bbmle, <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;">"l1"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nullvalue =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(m)[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>]], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb28-17">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xaxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(mu),</span>
<span id="cb28-18">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Profile Likelihood for the Mean (via bbmle)"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-24-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-4-4" class="tab-pane" aria-labelledby="tabset-4-4-tab">
<p>For a binary outcome that carries many nuisance parameters, <code>cond</code> gives us <em>exact conditional</em> likelihood inference, where the nuisance parameters are conditioned out instead of being profiled.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cond)</span>
<span id="cb29-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(babies)</span>
<span id="cb29-3"></span>
<span id="cb29-4">mod_babies <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;">glm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(r1, r2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> day <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> lull <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>
<span id="cb29-5">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> binomial, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> babies)</span>
<span id="cb29-6">cond_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;">cond</span>(mod_babies, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">offset =</span> lullyes)</span>
<span id="cb29-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(cond_fit)</span>
<span id="cb29-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb29-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Formula:  cbind(r1, r2) ~ day + lull - 1</span></span>
<span id="cb29-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Family:  binomial</span></span>
<span id="cb29-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Offset:  lullyes</span></span>
<span id="cb29-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb29-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;           Estimate   Std. Error </span></span>
<span id="cb29-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; uncond.        1.43        0.734</span></span>
<span id="cb29-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; cond.          1.27        0.689</span></span>
<span id="cb29-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb29-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Confidence intervals</span></span>
<span id="cb29-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; --------------------</span></span>
<span id="cb29-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  level = 95 %</span></span>
<span id="cb29-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                                            lower two-sided upper</span></span>
<span id="cb29-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Wald pivot                              -0.00651            2.87</span></span>
<span id="cb29-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Wald pivot (cond. MLE)                  -0.08020            2.62</span></span>
<span id="cb29-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Likelihood root                          0.12300            3.09</span></span>
<span id="cb29-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Modified likelihood root                 0.01070            2.76</span></span>
<span id="cb29-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Modified likelihood root (cont. corr.)  -0.15200            3.10</span></span>
<span id="cb29-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb29-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Diagnostics:</span></span>
<span id="cb29-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ----------- </span></span>
<span id="cb29-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   INF    NP </span></span>
<span id="cb29-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 0.076 0.289 </span></span>
<span id="cb29-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb29-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Approximation based on 20 points</span></span>
<span id="cb29-33"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(cond_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">which =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-25-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
<section id="the-pitfall-slicing-is-not-profiling" class="level3">
<h3 class="anchored" data-anchor-id="the-pitfall-slicing-is-not-profiling">The pitfall: slicing is not profiling</h3>
<p>Fixing a nuisance parameter, instead of re-maximizing it, is probably the most common way to get this wrong. If we hold <img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2%20=%201"> here, we get a likelihood that is far too narrow, because the real <img src="https://latex.codecogs.com/png.latex?%5Csigma"> is about 3.2. The interval that it implies is roughly a third of the width that it should be:</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">loglik_slice <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;">vapply</span>(mu_grid, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(m) <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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>((x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> m)<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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb30-2">lik_slice    <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_concurve_lik</span>(mu_grid, loglik_slice)</span>
<span id="cb30-3"></span>
<span id="cb30-4">w <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>(o) {</span>
<span id="cb30-5">  s <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;">curve_support</span>(o, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span>)</span>
<span id="cb30-6">  s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>upper.limit <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> s<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>lower.limit</span>
<span id="cb30-7">}</span>
<span id="cb30-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">slice_width =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(lik_slice), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">profile_width =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(lik_optim))</span>
<span id="cb30-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   slice_width profile_width </span></span>
<span id="cb30-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;         0.554         1.658</span></span>
<span id="cb30-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(lik_slice) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>(lik_optim))</span>
<span id="cb30-12"></span>
<span id="cb30-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggcurve</span>(lik_slice, <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;">"l1"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nullvalue =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>]], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb30-14">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xaxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(mu),</span>
<span id="cb30-15">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"WRONG: mean likelihood with sigma^2 fixed at 1"</span>,</span>
<span id="cb30-16">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Too narrow -- the real sigma is about 3.2, not 1"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-26-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="profile-likelihood-from-profilelikelihood" class="level3">
<h3 class="anchored" data-anchor-id="profile-likelihood-from-profilelikelihood">Profile likelihood from <code>ProfileLikelihood</code></h3>
<p><code>profilelike.glm</code> profiles one coefficient of a GLM over a grid, and <code>curve_lik</code> turns that straight into a <code>concurve</code> object, which then gives us all four coordinate views from the top of this post off a single fit. As a self-check, the profile’s peak must reproduce the coefficient from the ordinary <code>glm</code>.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ProfileLikelihood)</span>
<span id="cb31-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(dataglm)</span>
<span id="cb31-3"></span>
<span id="cb31-4">xx <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;">profilelike.glm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> x2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dataglm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">profile.theta =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>,</span>
<span id="cb31-5">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lo.theta =</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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hi.theta =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.2</span>,</span>
<span id="cb31-6">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">binomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</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;">round =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb31-7">lik_pl <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;">curve_lik</span>(xx, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dataglm)</span>
<span id="cb31-8"></span>
<span id="cb31-9">si <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;">curve_support</span>(lik_pl[[<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;">6.83</span>)</span>
<span id="cb31-10">si</span></code></pre></div></div>
<div class="cell-output-display">
<div class="kable-table">
<table class="caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: right;">k</th>
<th style="text-align: right;">support.level</th>
<th style="text-align: right;">lower.limit</th>
<th style="text-align: right;">upper.limit</th>
<th style="text-align: right;">mle</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">6.83</td>
<td style="text-align: right;">0.146</td>
<td style="text-align: right;">0.098</td>
<td style="text-align: right;">2.91</td>
<td style="text-align: right;">1.36</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="code-copy-outer-scaffold"><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"></span>
<span id="cb32-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># the profile peak must land on the full-model MLE</span></span>
<span id="cb32-3">mod_pl <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;">glm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> x2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> group, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dataglm,</span>
<span id="cb32-4">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">binomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>))</span>
<span id="cb32-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(si<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>mle <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;">coef</span>(mod_pl)[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>]]) <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.01</span>)</span>
<span id="cb32-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"validation PASSED: profile peak == glm coefficient</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb32-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; validation PASSED: profile peak == glm coefficient</span></span></code></pre></div></div>
</div>
<p>Here’s the same object shown four ways (relative likelihood, log-likelihood, likelihood, and deviance):</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggcurve</span>(lik_pl[[<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;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"l1"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nullvalue =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-28-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggcurve</span>(lik_pl[[<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;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"l2"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-28-2.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggcurve</span>(lik_pl[[<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;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"l3"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-28-3.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggcurve</span>(lik_pl[[<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;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-28-4.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="profile-versus-wald-and-where-the-16.83-interval-lands" class="level3">
<h3 class="anchored" data-anchor-id="profile-versus-wald-and-where-the-16.83-interval-lands">Profile versus Wald, and where the 1/6.83 interval lands</h3>
<p><code>curve_lik_glm</code> profiles a coefficient directly. If we compare it against the Wald normal approximation on the same grid, we can see the skew that the Wald interval discards. We can also see that the Wald support interval reproduces its own consonance interval, which is the identity from the top of this post:</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1">mod <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;">glm</span>(am <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> mpg, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> binomial, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> mtcars)</span>
<span id="cb37-2">est <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;">coef</span>(mod)[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mpg"</span>]]</span>
<span id="cb37-3">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>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diag</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vcov</span>(mod)))[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mpg"</span>]]</span>
<span id="cb37-4"></span>
<span id="cb37-5">lik_prof <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;">curve_lik_glm</span>(mod, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mpg"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)</span>
<span id="cb37-6">grid     <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> lik_prof[[<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>values</span>
<span id="cb37-7">lik_wald <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_concurve_lik</span>(grid, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(grid, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> est, <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;">log =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>))</span>
<span id="cb37-8"></span>
<span id="cb37-9">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;">curve_analytic</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> est, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dist =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"z"</span>)</span>
<span id="cb37-10">ci95 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cons[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]][<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which.min</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(cons[[<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>intrvl.level <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.95</span>)),</span>
<span id="cb37-11">                  <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;">"lower.limit"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"upper.limit"</span>)]</span>
<span id="cb37-12"></span>
<span id="cb37-13">out <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;">rbind</span>(</span>
<span id="cb37-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;">profile 1/6.83 support</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">curve_support</span>(lik_prof[[<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;">6.83</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;">"lower.limit"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"upper.limit"</span>)]),</span>
<span id="cb37-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;">Wald    1/6.83 support</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">curve_support</span>(lik_wald,      <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</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;">"lower.limit"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"upper.limit"</span>)]),</span>
<span id="cb37-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;">Wald    95% consonance</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>(ci95)</span>
<span id="cb37-17">)</span>
<span id="cb37-18">out</span>
<span id="cb37-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                        lower.limit upper.limit</span></span>
<span id="cb37-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; profile 1/6.83 support      0.1218       0.588</span></span>
<span id="cb37-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Wald    1/6.83 support      0.0818       0.532</span></span>
<span id="cb37-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Wald    95% consonance      0.0819       0.532</span></span>
<span id="cb37-23"></span>
<span id="cb37-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Wald support interval and Wald consonance interval agree to ~1e-3</span></span>
<span id="cb37-25"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopifnot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(out[<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> out[<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;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-3</span>)</span>
<span id="cb37-26"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"validation PASSED: Wald 1/6.83 support == Wald 95% consonance</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb37-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; validation PASSED: Wald 1/6.83 support == Wald 95% consonance</span></span></code></pre></div></div>
</div>
<p>As we can see, the profile curve leans to the right of the symmetric Wald curve, and that lean is the information that a Wald interval throws away:</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_compare</span>(lik_prof[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]], lik_wald, <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;">"l1"</span>,</span>
<span id="cb38-2">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xaxis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(beta[mpg]))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-30-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
</section>
<section id="validation-status" class="level2">
<h2 class="anchored" data-anchor-id="validation-status">Validation status</h2>
<table class="caption-top table">
<thead>
<tr class="header">
<th>Language</th>
<th>Runtime validated</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Python</td>
<td>yes, all asserts pass</td>
<td>scipy/statsmodels/matplotlib</td>
</tr>
<tr class="even">
<td>Julia</td>
<td>yes, all asserts pass (numerics)</td>
<td>Plots.jl output not exercised</td>
</tr>
<tr class="odd">
<td>MATLAB</td>
<td>yes, executes at render via <code>matlab -batch</code></td>
<td><code>fminsearch</code> is base MATLAB; <code>glmfit</code>/<code>normcdf</code> need the Statistics Toolbox</td>
</tr>
<tr class="even">
<td>SQL (DuckDB, live)</td>
<td>yes, executes at render; asserts vs <code>lm</code>/<code>pnorm</code></td>
<td>agreement to machine precision; plotting delegated to R</td>
</tr>
<tr class="odd">
<td>SQL (Snowflake)</td>
<td>yes, all three parts run live there</td>
<td>same logic, dialect differs in row generation</td>
</tr>
<tr class="even">
<td>Stata</td>
<td>syntax verified against <code>[R] ml</code>, <code>[P] postfile</code></td>
<td>run once locally; asserts are the safety net</td>
</tr>
<tr class="odd">
<td>Stata <code>cifunction</code></td>
<td>asserts against reported CI + z-grid construction</td>
<td>SSC module; conventions per the <a href="https://lesslikely.com/statistics/cifunction/">cifunction guide</a></td>
</tr>
</tbody>
</table>
</section>
<section id="package-citations" class="level2">
<h2 class="anchored" data-anchor-id="package-citations">Package Citations</h2>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Statamarkdown"</span>)</span>
<span id="cb39-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; To cite package ‘Statamarkdown’ in publications use:</span></span>
<span id="cb39-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb39-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   Hemken D, Palmer T (2026). _Statamarkdown: 'Stata' Markdown_. doi:10.32614/CRAN.package.Statamarkdown</span></span>
<span id="cb39-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   &lt;https://doi.org/10.32614/CRAN.package.Statamarkdown&gt;. R package version 1.1.0,</span></span>
<span id="cb39-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   &lt;https://CRAN.R-project.org/package=Statamarkdown&gt;.</span></span>
<span id="cb39-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb39-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; A BibTeX entry for LaTeX users is</span></span>
<span id="cb39-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb39-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   @Manual{,</span></span>
<span id="cb39-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     title = {Statamarkdown: 'Stata' Markdown},</span></span>
<span id="cb39-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     author = {Doug Hemken and Tom Palmer},</span></span>
<span id="cb39-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     year = {2026},</span></span>
<span id="cb39-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     note = {R package version 1.1.0},</span></span>
<span id="cb39-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     url = {https://CRAN.R-project.org/package=Statamarkdown},</span></span>
<span id="cb39-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     doi = {10.32614/CRAN.package.Statamarkdown},</span></span>
<span id="cb39-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   }</span></span>
<span id="cb39-18"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reticulate"</span>)</span>
<span id="cb39-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; To cite package ‘reticulate’ in publications use:</span></span>
<span id="cb39-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb39-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   Kalinowski T, Ushey K, Allaire J, Tang Y (2026). _reticulate: Interface to 'Python'_.</span></span>
<span id="cb39-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   doi:10.32614/CRAN.package.reticulate &lt;https://doi.org/10.32614/CRAN.package.reticulate&gt;. R package version 1.47.0,</span></span>
<span id="cb39-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   &lt;https://CRAN.R-project.org/package=reticulate&gt;.</span></span>
<span id="cb39-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb39-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; A BibTeX entry for LaTeX users is</span></span>
<span id="cb39-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb39-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   @Manual{,</span></span>
<span id="cb39-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     title = {reticulate: Interface to 'Python'},</span></span>
<span id="cb39-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     author = {Tomasz Kalinowski and Kevin Ushey and JJ Allaire and Yuan Tang},</span></span>
<span id="cb39-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     year = {2026},</span></span>
<span id="cb39-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     note = {R package version 1.47.0},</span></span>
<span id="cb39-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     url = {https://CRAN.R-project.org/package=reticulate},</span></span>
<span id="cb39-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     doi = {10.32614/CRAN.package.reticulate},</span></span>
<span id="cb39-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   }</span></span>
<span id="cb39-35"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"JuliaCall"</span>)</span>
<span id="cb39-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; To cite package ‘JuliaCall’ in publications use:</span></span>
<span id="cb39-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb39-38"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   Li C (2019). “JuliaCall: an R package for seamless integration between R and Julia.” _The Journal of Open Source</span></span>
<span id="cb39-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   Software_, *4*(35), 1284. doi:10.21105/joss.01284 &lt;https://doi.org/10.21105/joss.01284&gt;.</span></span>
<span id="cb39-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb39-41"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; A BibTeX entry for LaTeX users is</span></span>
<span id="cb39-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb39-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   @Article{JuliaCall,</span></span>
<span id="cb39-44"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     author = {Changcheng Li},</span></span>
<span id="cb39-45"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     title = {{JuliaCall}: an {R} package for seamless integration between {R} and {Julia}},</span></span>
<span id="cb39-46"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     journal = {The Journal of Open Source Software},</span></span>
<span id="cb39-47"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     publisher = {The Open Journal},</span></span>
<span id="cb39-48"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     year = {2019},</span></span>
<span id="cb39-49"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     volume = {4},</span></span>
<span id="cb39-50"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     number = {35},</span></span>
<span id="cb39-51"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     pages = {1284},</span></span>
<span id="cb39-52"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     doi = {10.21105/joss.01284},</span></span>
<span id="cb39-53"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   }</span></span></code></pre></div></div>
</div>
<hr>
</section>
<section id="statistical-environments" class="level2">
<h2 class="anchored" data-anchor-id="statistical-environments">Statistical Environments</h2>
<hr>
<section id="r-environment" class="level5">
<h5 class="anchored" data-anchor-id="r-environment">R Environment</h5>
<hr>
<div class="cell" data-layout-align="center">
<pre><code>#&gt; ─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#&gt;  setting  value
#&gt;  version  R version 4.6.1 (2026-06-24)
#&gt;  os       macOS Golden Gate 27.0.1
#&gt;  system   aarch64, darwin25.4.0
#&gt;  ui       unknown
#&gt;  language (EN)
#&gt;  collate  C.UTF-8
#&gt;  ctype    C.UTF-8
#&gt;  tz       America/New_York
#&gt;  date     2026-10-10
#&gt;  pandoc   3.12 @ /opt/homebrew/bin/ (via rmarkdown)
#&gt;  quarto   1.10.18 @ /usr/local/bin/quarto
#&gt; 
#&gt; ─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#&gt;  package           * version    date (UTC) lib source
#&gt;  abind               1.4-8      2024-09-12 [1] CRAN (R 4.6.1)
#&gt;  Amelia            * 1.8.3      2024-11-08 [1] CRAN (R 4.6.1)
#&gt;  arm                 1.15-3     2026-04-15 [1] CRAN (R 4.6.1)
#&gt;  arrayhelpers        1.1-2      2026-07-24 [1] CRAN (R 4.6.1)
#&gt;  backports           1.5.1      2026-04-03 [1] CRAN (R 4.6.1)
#&gt;  base              * 4.6.1      2026-06-24 [2] local
#&gt;  base64enc           0.1-6      2026-02-02 [1] CRAN (R 4.6.1)
#&gt;  bayesplot         * 1.16.0     2026-08-25 [1] CRAN (R 4.6.1)
#&gt;  bbmle             * 1.0.26     2026-08-31 [1] CRAN (R 4.6.1)
#&gt;  bdsmatrix           1.3-7      2024-03-02 [1] CRAN (R 4.6.1)
#&gt;  bitops              1.1-0      2026-07-30 [1] CRAN (R 4.6.1)
#&gt;  blogdown          * 1.24       2026-06-19 [1] CRAN (R 4.6.1)
#&gt;  boot              * 1.3-32     2025-08-29 [1] CRAN (R 4.6.1)
#&gt;  bootImpute        * 1.3.0      2025-12-15 [1] CRAN (R 4.6.1)
#&gt;  bridgesampling      1.2-1      2025-11-19 [1] CRAN (R 4.6.1)
#&gt;  brms              * 2.23.0     2025-09-09 [1] CRAN (R 4.6.1)
#&gt;  Brobdingnag         1.3-1      2026-09-12 [1] CRAN (R 4.6.1)
#&gt;  broom             * 1.0.13     2026-05-14 [1] CRAN (R 4.6.1)
#&gt;  broom.mixed       * 0.2.9.7    2026-02-17 [1] CRAN (R 4.6.1)
#&gt;  Cairo             * 1.7-0      2025-10-29 [1] CRAN (R 4.6.1)
#&gt;  car               * 3.1-5      2026-02-03 [1] CRAN (R 4.6.1)
#&gt;  carData           * 3.0-6      2026-01-30 [1] CRAN (R 4.6.1)
#&gt;  caTools             1.18.4     2026-07-20 [1] CRAN (R 4.6.1)
#&gt;  checkmate         * 2.3.4      2026-02-03 [1] CRAN (R 4.6.1)
#&gt;  class               7.3-24     2026-08-03 [1] CRAN (R 4.6.1)
#&gt;  cli               * 3.6.6      2026-04-09 [1] CRAN (R 4.6.1)
#&gt;  clipr               0.8.1      2026-05-25 [1] CRAN (R 4.6.1)
#&gt;  cluster             2.1.8.3    2026-07-30 [1] CRAN (R 4.6.1)
#&gt;  coda              * 0.19-4.1   2024-01-31 [1] CRAN (R 4.6.1)
#&gt;  codetools           0.2-20     2024-03-31 [1] CRAN (R 4.6.0)
#&gt;  colorspace        * 2.1-4      2026-10-08 [1] CRAN (R 4.6.1)
#&gt;  compiler            4.6.1      2026-06-24 [2] local
#&gt;  concurve          * 3.0.5      2026-09-28 [1] local
#&gt;  cond              * 1.2-4      2025-05-25 [1] CRAN (R 4.6.1)
#&gt;  cowplot           * 1.2.0      2025-07-07 [1] CRAN (R 4.6.1)
#&gt;  crayon              1.5.3      2024-06-20 [1] CRAN (R 4.6.1)
#&gt;  curl                8.0.0      2026-08-25 [1] CRAN (R 4.6.1)
#&gt;  data.table          1.18.6.1   2026-08-24 [1] CRAN (R 4.6.1)
#&gt;  datasets          * 4.6.1      2026-06-24 [2] local
#&gt;  DBI               * 1.3.0      2026-02-25 [1] CRAN (R 4.6.1)
#&gt;  DEoptimR            1.2-2      2026-09-25 [1] CRAN (R 4.6.1)
#&gt;  desc                1.4.3      2023-12-10 [1] CRAN (R 4.6.1)
#&gt;  details             0.4.0      2025-02-09 [1] CRAN (R 4.6.0)
#&gt;  dichromat           2.0-1      2026-07-22 [1] CRAN (R 4.6.1)
#&gt;  digest              0.6.39     2025-11-19 [1] CRAN (R 4.6.1)
#&gt;  distributional      0.9.0      2026-09-08 [1] CRAN (R 4.6.1)
#&gt;  doParallel        * 1.0.17     2022-02-07 [1] CRAN (R 4.6.1)
#&gt;  doRNG               1.8.6.3    2026-02-05 [1] CRAN (R 4.6.1)
#&gt;  dplyr             * 1.2.1      2026-04-03 [1] CRAN (R 4.6.1)
#&gt;  duckdb              1.5.6      2026-09-29 [1] CRAN (R 4.6.1)
#&gt;  e1071               1.7-17     2025-12-18 [1] CRAN (R 4.6.1)
#&gt;  emmeans             2.0.4      2026-07-15 [1] CRAN (R 4.6.1)
#&gt;  estimability        2.0.0      2026-06-26 [1] CRAN (R 4.6.1)
#&gt;  evaluate            1.0.5      2025-08-27 [1] CRAN (R 4.6.1)
#&gt;  extremevalues       2.4.1      2024-12-17 [1] CRAN (R 4.6.1)
#&gt;  farver              2.1.2      2024-05-13 [1] CRAN (R 4.6.1)
#&gt;  fastmap             1.2.0      2024-05-15 [1] CRAN (R 4.6.1)
#&gt;  forcats           * 1.0.1      2025-09-25 [1] CRAN (R 4.6.1)
#&gt;  foreach           * 1.5.2      2022-02-02 [1] CRAN (R 4.6.1)
#&gt;  foreign             0.8-91     2026-01-29 [1] CRAN (R 4.6.1)
#&gt;  Formula             1.2-6      2026-08-03 [1] CRAN (R 4.6.1)
#&gt;  fs                  2.1.0      2026-04-18 [1] CRAN (R 4.6.1)
#&gt;  furrr               0.4.0      2026-03-31 [1] CRAN (R 4.6.1)
#&gt;  future            * 1.76.0     2026-09-24 [1] CRAN (R 4.6.1)
#&gt;  future.apply      * 1.20.2     2026-02-20 [1] CRAN (R 4.6.1)
#&gt;  gamlss            * 5.5-5      2026-10-06 [1] CRAN (R 4.6.1)
#&gt;  gamlss.data       * 6.0-7      2025-09-04 [1] CRAN (R 4.6.1)
#&gt;  gamlss.dist       * 6.1-11     2026-09-10 [1] CRAN (R 4.6.1)
#&gt;  generics            0.1.4      2025-05-09 [1] CRAN (R 4.6.1)
#&gt;  ggcorrplot        * 0.3.0      2026-07-24 [1] CRAN (R 4.6.1)
#&gt;  ggdist              3.3.3      2025-04-23 [1] CRAN (R 4.6.1)
#&gt;  ggplot2           * 4.0.3      2026-04-22 [1] CRAN (R 4.6.1)
#&gt;  ggtext            * 0.2.0      2026-08-28 [1] CRAN (R 4.6.1)
#&gt;  glmnet              5.1        2026-09-24 [1] CRAN (R 4.6.1)
#&gt;  globals             0.19.1     2026-03-13 [1] CRAN (R 4.6.1)
#&gt;  glue                1.8.1      2026-04-17 [1] CRAN (R 4.6.1)
#&gt;  graphics          * 4.6.1      2026-06-24 [2] local
#&gt;  grDevices         * 4.6.1      2026-06-24 [2] local
#&gt;  grid              * 4.6.1      2026-06-24 [2] local
#&gt;  gridExtra           2.3.1      2026-06-25 [1] CRAN (R 4.6.1)
#&gt;  gridtext            0.1.6      2026-02-19 [1] CRAN (R 4.6.0)
#&gt;  gtable              0.3.6      2024-10-25 [1] CRAN (R 4.6.1)
#&gt;  gtsummary         * 2.6.1      2026-09-04 [1] CRAN (R 4.6.1)
#&gt;  here              * 1.0.2      2025-09-15 [1] CRAN (R 4.6.1)
#&gt;  Hmisc             * 5.3-0      2026-09-06 [1] CRAN (R 4.6.1)
#&gt;  hms                 1.1.4      2025-10-17 [1] CRAN (R 4.6.1)
#&gt;  htmlTable           2.5.0      2026-04-22 [1] CRAN (R 4.6.1)
#&gt;  htmltools         * 0.5.9      2025-12-04 [1] CRAN (R 4.6.1)
#&gt;  htmlwidgets         1.6.4      2023-12-06 [1] CRAN (R 4.6.1)
#&gt;  httr                1.4.9      2026-09-01 [1] CRAN (R 4.6.1)
#&gt;  ImputeRobust      * 1.3-1      2018-11-30 [1] CRAN (R 4.6.1)
#&gt;  inline              0.3.21     2025-01-09 [1] CRAN (R 4.6.1)
#&gt;  insight             1.5.4      2026-09-05 [1] CRAN (R 4.6.1)
#&gt;  iterators         * 1.0.14     2022-02-05 [1] CRAN (R 4.6.1)
#&gt;  itertools           0.1-3      2014-03-12 [1] CRAN (R 4.6.1)
#&gt;  jomo                2.7-6      2023-04-15 [1] CRAN (R 4.6.1)
#&gt;  jsonlite            2.0.0      2025-03-27 [1] CRAN (R 4.6.1)
#&gt;  JuliaCall           0.17.6     2024-12-07 [1] CRAN (R 4.6.1)
#&gt;  kableExtra        * 1.4.1      2026-07-08 [1] CRAN (R 4.6.1)
#&gt;  knitr             * 1.52       2026-09-06 [1] CRAN (R 4.6.1)
#&gt;  labeling            0.4.3      2023-08-29 [1] CRAN (R 4.6.1)
#&gt;  laeken              0.5.3      2024-01-25 [1] CRAN (R 4.6.1)
#&gt;  latex2exp         * 0.9.8      2026-01-09 [1] CRAN (R 4.6.1)
#&gt;  lattice           * 0.23-1     2026-08-12 [1] CRAN (R 4.6.1)
#&gt;  lifecycle           1.0.5      2026-01-08 [1] CRAN (R 4.6.1)
#&gt;  listenv             1.1.0      2026-10-04 [1] CRAN (R 4.6.1)
#&gt;  lme4                2.0-6      2026-07-16 [1] CRAN (R 4.6.1)
#&gt;  lmtest              0.9-40     2022-03-21 [1] CRAN (R 4.6.1)
#&gt;  loo               * 2.10.1     2026-07-24 [1] CRAN (R 4.6.1)
#&gt;  lubridate         * 1.9.5      2026-02-04 [1] CRAN (R 4.6.1)
#&gt;  magick              2.9.1      2026-02-28 [1] CRAN (R 4.6.1)
#&gt;  magrittr          * 2.0.5      2026-04-04 [1] CRAN (R 4.6.1)
#&gt;  MASS              * 7.3-66     2026-07-15 [1] CRAN (R 4.6.1)
#&gt;  Matrix            * 1.7-6      2026-07-25 [1] CRAN (R 4.6.1)
#&gt;  MatrixModels        0.5-4      2025-03-26 [1] CRAN (R 4.6.1)
#&gt;  matrixStats         1.5.0      2025-01-07 [1] CRAN (R 4.6.1)
#&gt;  maxLik            * 1.6-10     2026-10-01 [1] CRAN (R 4.6.1)
#&gt;  mcmc                0.9-8      2023-11-16 [1] CRAN (R 4.6.1)
#&gt;  MCMCpack          * 1.7-1      2024-08-27 [1] CRAN (R 4.6.1)
#&gt;  methods           * 4.6.1      2026-06-24 [2] local
#&gt;  mgcv              * 1.9-4      2025-11-07 [1] CRAN (R 4.6.0)
#&gt;  mi                * 1.3.1      2026-07-28 [1] CRAN (R 4.6.1)
#&gt;  mice              * 3.19.0     2025-12-10 [1] CRAN (R 4.6.1)
#&gt;  miceadds          * 3.20-10    2026-05-28 [1] CRAN (R 4.6.1)
#&gt;  miceFast          * 0.9.1      2026-02-26 [1] CRAN (R 4.6.1)
#&gt;  minqa               1.2.8      2024-08-17 [1] CRAN (R 4.6.1)
#&gt;  miscTools         * 0.6-30     2026-01-20 [1] CRAN (R 4.6.1)
#&gt;  missForest        * 1.6.1      2025-10-26 [1] CRAN (R 4.6.1)
#&gt;  mitml             * 0.4-5      2023-03-08 [1] CRAN (R 4.6.1)
#&gt;  mitools             2.7        2026-08-31 [1] CRAN (R 4.6.1)
#&gt;  multcomp            1.4-32     2026-08-21 [1] CRAN (R 4.6.1)
#&gt;  mvtnorm           * 1.4-2      2026-07-12 [1] CRAN (R 4.6.1)
#&gt;  nlme              * 3.1-171    2026-09-01 [1] CRAN (R 4.6.1)
#&gt;  nloptr              2.2.1      2025-03-17 [1] CRAN (R 4.6.1)
#&gt;  nnet                7.3-21     2026-08-03 [1] CRAN (R 4.6.1)
#&gt;  numDeriv            2016.8-1.1 2019-06-06 [1] CRAN (R 4.6.1)
#&gt;  opdisDownsampling   1.7        2026-09-04 [1] CRAN (R 4.6.1)
#&gt;  otel                0.2.0      2025-08-29 [1] CRAN (R 4.6.1)
#&gt;  pan                 2.0        2026-06-30 [1] CRAN (R 4.6.1)
#&gt;  parallel          * 4.6.1      2026-06-24 [2] local
#&gt;  parallelly        * 1.48.0     2026-06-29 [1] CRAN (R 4.6.1)
#&gt;  pbmcapply         * 1.5.1      2022-04-28 [1] CRAN (R 4.6.1)
#&gt;  performance       * 0.18.2     2026-09-10 [1] CRAN (R 4.6.1)
#&gt;  pillar              1.11.1     2025-09-17 [1] CRAN (R 4.6.1)
#&gt;  pkgbuild            1.4.8      2025-05-26 [1] CRAN (R 4.6.1)
#&gt;  pkgconfig           2.0.3      2019-09-22 [1] CRAN (R 4.6.1)
#&gt;  plyr                1.8.9      2023-10-02 [1] CRAN (R 4.6.1)
#&gt;  png                 0.1-9      2026-03-15 [1] CRAN (R 4.6.0)
#&gt;  polspline           1.1.25     2024-05-10 [1] CRAN (R 4.6.1)
#&gt;  posterior         * 1.7.0      2026-04-01 [1] CRAN (R 4.6.1)
#&gt;  pracma              2.4.6      2025-10-22 [1] CRAN (R 4.6.1)
#&gt;  prettyunits         1.2.0      2023-09-24 [1] CRAN (R 4.6.1)
#&gt;  ProfileLikelihood * 1.3        2023-08-25 [1] CRAN (R 4.6.1)
#&gt;  progress          * 1.2.3      2023-12-06 [1] CRAN (R 4.6.1)
#&gt;  proxy               0.4-29     2025-12-29 [1] CRAN (R 4.6.1)
#&gt;  purrr             * 1.2.2      2026-04-10 [1] CRAN (R 4.6.1)
#&gt;  qqconf              1.3.2      2023-04-14 [1] CRAN (R 4.6.1)
#&gt;  qqplotr           * 0.0.7      2025-09-05 [1] CRAN (R 4.6.1)
#&gt;  quantreg          * 6.1        2025-03-10 [1] CRAN (R 4.6.1)
#&gt;  QuickJSR            1.11.0     2026-08-21 [1] CRAN (R 4.6.1)
#&gt;  R6                  2.6.1      2025-02-15 [1] CRAN (R 4.6.1)
#&gt;  randomForest      * 4.7-1.2    2024-09-22 [1] CRAN (R 4.6.1)
#&gt;  ranger              0.18.0     2026-01-16 [1] CRAN (R 4.6.1)
#&gt;  rbibutils           2.4.1      2026-01-21 [1] CRAN (R 4.6.1)
#&gt;  RColorBrewer        1.1-3      2022-04-03 [1] CRAN (R 4.6.1)
#&gt;  Rcpp              * 1.1.2      2026-07-05 [1] CRAN (R 4.6.1)
#&gt;  RcppParallel        6.2.1      2026-08-27 [1] CRAN (R 4.6.1)
#&gt;  Rdpack              2.6.6      2026-02-08 [1] CRAN (R 4.6.1)
#&gt;  readr             * 2.2.0      2026-02-19 [1] CRAN (R 4.6.1)
#&gt;  reformulas          0.4.4      2026-02-02 [1] CRAN (R 4.6.1)
#&gt;  rematch2            2.1.2      2020-05-01 [1] CRAN (R 4.6.1)
#&gt;  reshape2          * 1.4.5      2025-11-12 [1] CRAN (R 4.6.1)
#&gt;  reticulate        * 1.47.0     2026-09-03 [1] CRAN (R 4.6.1)
#&gt;  rlang               1.3.0      2026-07-05 [1] CRAN (R 4.6.1)
#&gt;  rmarkdown         * 2.32       2026-09-01 [1] CRAN (R 4.6.1)
#&gt;  rms               * 8.1-1      2026-02-18 [1] CRAN (R 4.6.1)
#&gt;  rngtools            1.5.2      2021-09-20 [1] CRAN (R 4.6.1)
#&gt;  robustbase          0.99-7     2026-02-05 [1] CRAN (R 4.6.1)
#&gt;  rpart               4.1.27     2026-03-27 [1] CRAN (R 4.6.0)
#&gt;  rprojroot           2.1.1      2025-08-26 [1] CRAN (R 4.6.1)
#&gt;  rstan             * 2.32.7     2025-03-10 [1] CRAN (R 4.6.1)
#&gt;  rstantools          2.7.1      2026-09-04 [1] Github (stan-dev/rstantools@4d84659)
#&gt;  rstudioapi          0.19.0     2026-06-11 [1] CRAN (R 4.6.1)
#&gt;  S7                  0.2.2      2026-04-22 [1] CRAN (R 4.6.1)
#&gt;  sandwich            3.1-3      2026-08-03 [1] CRAN (R 4.6.1)
#&gt;  scales              1.4.0      2025-04-24 [1] CRAN (R 4.6.1)
#&gt;  sessioninfo         1.2.4      2026-06-04 [1] CRAN (R 4.6.1)
#&gt;  shape               1.4.6.1    2024-02-23 [1] CRAN (R 4.6.1)
#&gt;  showtext          * 0.9-8      2026-03-21 [1] CRAN (R 4.6.1)
#&gt;  showtextdb        * 3.0        2020-06-04 [1] CRAN (R 4.6.1)
#&gt;  sp                  2.2-3      2026-07-19 [1] CRAN (R 4.6.1)
#&gt;  SparseM           * 1.84-2     2024-07-17 [1] CRAN (R 4.6.1)
#&gt;  splines           * 4.6.1      2026-06-24 [2] local
#&gt;  StanHeaders       * 2.39.1     2026-09-02 [1] CRAN (R 4.6.1)
#&gt;  Statamarkdown     * 1.1.0      2026-09-23 [1] CRAN (R 4.6.1)
#&gt;  statmod           * 1.5.2      2026-05-17 [1] CRAN (R 4.6.1)
#&gt;  stats             * 4.6.1      2026-06-24 [2] local
#&gt;  stats4            * 4.6.1      2026-06-24 [2] local
#&gt;  stringi             1.8.9      2026-08-04 [1] CRAN (R 4.6.1)
#&gt;  stringr           * 1.6.0      2025-11-04 [1] CRAN (R 4.6.1)
#&gt;  survival          * 3.8-12     2026-09-09 [1] CRAN (R 4.6.1)
#&gt;  svglite           * 2.2.2      2025-10-21 [1] CRAN (R 4.6.1)
#&gt;  svgPanZoom          0.3.4      2020-02-15 [1] CRAN (R 4.6.1)
#&gt;  svUnit              1.0.8      2025-08-26 [1] CRAN (R 4.6.1)
#&gt;  sysfonts          * 0.8.9      2024-03-02 [1] CRAN (R 4.6.1)
#&gt;  systemfonts         1.3.2      2026-03-05 [1] CRAN (R 4.6.1)
#&gt;  tensorA             0.36.2.1   2023-12-13 [1] CRAN (R 4.6.0)
#&gt;  texPreview        * 2.1.0      2024-01-24 [1] CRAN (R 4.6.0)
#&gt;  textshaping         1.0.5      2026-03-06 [1] CRAN (R 4.6.0)
#&gt;  TH.data             1.1-5      2025-11-17 [1] CRAN (R 4.6.0)
#&gt;  tibble            * 3.3.1      2026-01-11 [1] CRAN (R 4.6.1)
#&gt;  tidybayes         * 3.0.7      2024-09-15 [1] CRAN (R 4.6.1)
#&gt;  tidyr             * 1.3.2      2025-12-19 [1] CRAN (R 4.6.1)
#&gt;  tidyselect          1.2.1      2024-03-11 [1] CRAN (R 4.6.1)
#&gt;  tidyverse         * 2.0.0      2023-02-22 [1] CRAN (R 4.6.1)
#&gt;  timechange          0.4.0      2026-01-29 [1] CRAN (R 4.6.1)
#&gt;  tinytex           * 0.61       2026-09-17 [1] CRAN (R 4.6.1)
#&gt;  tools               4.6.1      2026-06-24 [2] local
#&gt;  twosamples          2.0.1      2023-06-23 [1] CRAN (R 4.6.1)
#&gt;  tzdb                0.5.0      2025-03-15 [1] CRAN (R 4.6.1)
#&gt;  utils             * 4.6.1      2026-06-24 [2] local
#&gt;  V8                  8.2.0      2026-04-21 [1] CRAN (R 4.6.0)
#&gt;  vcd                 1.4-14     2026-07-29 [1] CRAN (R 4.6.1)
#&gt;  vctrs               0.7.3      2026-04-11 [1] CRAN (R 4.6.1)
#&gt;  VIM               * 7.3.1      2026-09-11 [1] CRAN (R 4.6.1)
#&gt;  viridisLite         0.4.3      2026-02-04 [1] CRAN (R 4.6.1)
#&gt;  wesanderson       * 0.3.7      2023-10-31 [1] CRAN (R 4.6.1)
#&gt;  whisker             0.4.1      2022-12-05 [1] CRAN (R 4.6.1)
#&gt;  withr               3.0.3      2026-06-19 [1] CRAN (R 4.6.1)
#&gt;  xfun              * 0.61       2026-09-16 [1] CRAN (R 4.6.1)
#&gt;  xgboost             3.2.1.1    2026-03-18 [1] CRAN (R 4.6.1)
#&gt;  xml2                1.6.0      2026-06-22 [1] CRAN (R 4.6.1)
#&gt;  xtable            * 1.8-8      2026-02-22 [1] CRAN (R 4.6.1)
#&gt;  yaml                2.3.12     2025-12-10 [1] CRAN (R 4.6.1)
#&gt;  yardstick         * 1.4.0      2026-04-07 [1] CRAN (R 4.6.1)
#&gt;  zoo                 1.9-1      2026-09-25 [1] CRAN (R 4.6.1)
#&gt; 
#&gt;  [1] /opt/homebrew/lib/R/4.6/site-library
#&gt;  [2] /opt/homebrew/Cellar/r/4.6.1/lib/R/library
#&gt;  * ── Packages attached to the search path.
#&gt; 
#&gt; ─ External software ────────────────────────────────────────────────────────────────────────────────────────────────────────────
#&gt;  setting        value
#&gt;  cairo          1.18.6
#&gt;  cairoFT        2.14.3/2.18.1
#&gt;  pango
#&gt;  png
#&gt;  jpeg
#&gt;  tiff
#&gt;  tcl            9.0
#&gt;  curl           8.7.1
#&gt;  zlib           1.2.12
#&gt;  bzlib          1.0.8, 13-Jul-2019
#&gt;  xz             5.8.4
#&gt;  deflate
#&gt;  zstd           1.5.7
#&gt;  PCRE           10.49 2026-09-28
#&gt;  ICU            78.1
#&gt;  TRE            TRE 0.8.0 R_fixes (BSD)
#&gt;  iconv          Apple or GNU libiconv 1.11 /usr/lib/libiconv.2.dylib
#&gt;  readline       8.3
#&gt;  BLAS           /opt/homebrew/Cellar/openblas/0.3.34/lib/libopenblasp-r0.3.34.dylib
#&gt;  lapack         /opt/homebrew/Cellar/r/4.6.1/lib/R/lib/libRlapack.dylib
#&gt;  lapack_version 3.12.1
#&gt; 
#&gt; ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#&gt; $RNGkind
#&gt; [1] "Mersenne-Twister" "Inversion"        "Rejection"</code></pre>
</div>
<hr>
</section>
<section id="stata-environment" class="level5">
<h5 class="anchored" data-anchor-id="stata-environment">Stata Environment</h5>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb41" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb41-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">linesize</span> 255</span>
<span id="cb41-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">display</span> %tcMonth_dd,CCYY_hh:MM_am now()</span>
<span id="cb41-3">about</span>
<span id="cb41-4">#&gt;    October 10,2026 2:25 am</span>
<span id="cb41-5">#&gt; </span>
<span id="cb41-6">#&gt; </span>
<span id="cb41-7">#&gt; StataNow/MP 19.5 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> Mac (Apple Silicon)</span>
<span id="cb41-8">#&gt; Revision 12 Aug 2026</span>
<span id="cb41-9">#&gt; Copyright 1985-2025 StataCorp LLC</span>
<span id="cb41-10">#&gt; </span>
<span id="cb41-11">#&gt; Total physical <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">memory</span>: 48.01 GB</span>
<span id="cb41-12">#&gt; </span>
<span id="cb41-13">#&gt; Stata license: Single-user 2-core , expiring  6 Feb 2027</span>
<span id="cb41-14">#&gt; Serial number: 501909358563</span>
<span id="cb41-15">#&gt;   Licensed to: Zad Rafi</span>
<span id="cb41-16">#&gt; </span></code></pre></div></div>
</div>
<hr>
</section>
</section>
<section id="references" class="level2">



<!-- -->


</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><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" data-entry-spacing="2" data-line-spacing="2">
<div id="ref-cole2013" class="csl-entry">
1. Cole SR, Chu H, Greenland S. (2013). <span>“Maximum likelihood, profile likelihood, and penalized likelihood: A primer.”</span> <em>American Journal of Epidemiology</em>. <strong>179</strong>:252–260. doi: <a href="https://doi.org/10.1093/aje/kwt245">10.1093/aje/kwt245</a>. <a href="https://doi.org/10.1093/aje/kwt245">https://doi.org/10.1093/aje/kwt245</a>.
</div>
<div id="ref-coxPrinciplesStatisticalInference2006" class="csl-entry">
2. Cox DR. (2006). <span>“Principles of <span>Statistical Inference</span>.”</span> <span>Cambridge University Press</span>.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{rafi2026,
  author = {Rafi, Zad and Rafi, Zad},
  title = {Constructing {Likelihood} {Functions} in {R,} {Stata,}
    {Python,} {Julia,} {MATLAB,} and {SQL}},
  date = {2026-09-24},
  url = {https://lesslikely.com/statistics/likelihood-polyglot.html},
  langid = {en-US}
}
</code></pre></div></section></div> ]]></description>
  <category>statistics</category>
  <guid>https://lesslikely.com/statistics/likelihood-polyglot.html</guid>
  <pubDate>Thu, 24 Sep 2026 04:00:00 GMT</pubDate>
  <media:content url="https://lesslikely.com/images/sensitivity.png" medium="image" type="image/png" height="122" width="144"/>
</item>
<item>
  <title>How to Be a Good Collaborator to a Statistician and a Data Engineer</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/statistics/good-collaborator.html</link>
  <description><![CDATA[ 





<hr>
<p>Most projects that fail seem to fail because of the collaboration, and much less often because of anything technical. They usually fail early, and for reasons that rarely get written up (a question that was never pinned down, a column whose meaning changed in 2023, a “quick pull” that later ended up as the number in the board deck). The statistician gets blamed for the estimate and the data engineer gets blamed for the pipeline. However, the decisive errors were usually committed by well-meaning people who thought they were being helpful by not bothering anyone.</p>
<p>The influential statistician and geneticist Ronald A. Fisher put it elegantly in his 1938 presidential address to the Indian Statistical Congress:</p>
<blockquote class="blockquote">
<p>To consult the statistician after an experiment is finished is often merely to ask him to conduct a post mortem examination. He can perhaps say what the experiment died of.<span class="citation" data-cites="fisher1938"><sup>1</sup></span>.</p>
</blockquote>
<p>In this post, I’d like to go through the habits that help us avoid the post mortem. I’ve deliberately made it two-sided, since collaborators owe analysts some specific things and analysts owe collaborators some specific things back (and I don’t think “the data wasn’t clean” counts as a professional deliverable).</p>
<hr>
<section id="why-this-is-harder-than-it-looks" class="level2">
<h2 class="anchored" data-anchor-id="why-this-is-harder-than-it-looks">Why This Is Harder Than It Looks</h2>
<p>Many of us have the intuition that a well-specified question has one obvious analysis. That intuition is wrong, and we can measure how wrong it is.</p>
<p>In the best-known demonstration, 29 teams comprising 61 analysts were given the same dataset and the same question, which was whether soccer referees give more red cards to dark-skin-toned players. The 29 analyses used 21 unique combinations of covariates. The estimated effects ranged from an odds ratio of 0.89 to 2.93 (median 1.31), and 20 teams (69%) reported a statistically significant positive effect while 9 (31%) did not. Neither the analysts’ prior beliefs, nor their expertise, nor peer ratings of analysis quality explained the spread<span class="citation" data-cites="silberzahn2018"><sup>2</sup></span>.</p>
<p>The same pattern shows up in neuroimaging. Seventy teams analysed one fMRI dataset against nine pre-specified hypotheses, and <strong>no two teams chose identical workflows.</strong> The resulting variation in hypothesis-test outcomes was substantial, even between teams whose intermediate statistical maps were highly correlated<span class="citation" data-cites="botviniknezer2020"><sup>3</sup></span>.</p>
<p>Does this mean that analysis is arbitrary? I don’t think so. What it suggests is that <strong>the analysis is underdetermined by the question</strong>, and that the gap gets filled by defensible-looking judgment calls (the same garden of forking paths that makes untested model <a href="../statistics/assumptions">assumptions</a> so consequential). Every one of those calls is a place where the collaborator’s context (what the variable actually measures, which exclusions are clinically or commercially sensible, what decision the number feeds) either arrives in time or doesn’t.</p>
<div class="callout callout-style-default callout-note 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">
<span class="screen-reader-only">Note</span>The Load-Bearing Claim
</div>
</div>
<div class="callout-body-container callout-body">
<p>The variation in results across competent analysts is large enough that a collaborator’s contribution (supplying the context that narrows the set of defensible choices) should be seen as part of the estimate, and I wouldn’t call it a courtesy.</p>
</div>
</div>
<hr>
</section>
<section id="what-you-owe-the-statistician" class="level2">
<h2 class="anchored" data-anchor-id="what-you-owe-the-statistician">What You Owe the Statistician</h2>
<section id="in-research-settings" class="level3">
<h3 class="anchored" data-anchor-id="in-research-settings">In Research Settings</h3>
<p><strong>Bring them in at the design stage.</strong> The change that probably matters most is about timing. Kass and colleagues put “statistical analysis is more than a set of computations” and “plan ahead, really ahead” near the top of their ten rules for effective statistical practice, because analysis choices are constrained by design choices that have already been locked in by the time most people call<span class="citation" data-cites="kass2016"><sup>4</sup></span>. A statistician who is consulted at design can still change the sample size. However, one who is consulted at submission can do little more than change how the results are worded.</p>
<p><strong>State the estimand before the method.</strong> Asking “can you run a regression” skips the question that matters, which is what quantity we want, in what population, under what contrast, and with what handling of intercurrent events. If we cannot say it in a sentence, then that is a finding in itself, and it is worth knowing before any data are collected.</p>
<p><strong>Disclose everything that has already been looked at.</strong> I don’t think of selective reporting as a moral failing that has to be confessed. It is a fact about the data-generating process, and it changes what the numbers mean. An analyst who learns on submission day that eleven subgroup comparisons were already run has been handed a different problem from the one they thought they were solving.</p>
<p><strong>Settle authorship and credit at the start.</strong> The ASA’s <em>Ethical Guidelines for Statistical Practice</em> (eight principles across 72 elements, approved in 2022) put responsibilities to stakeholders and the integrity of data and methods on the same footing<span class="citation" data-cites="asa2022"><sup>5</sup></span>. Statisticians are expected to refuse to produce misleading analyses. That obligation is much easier to honour when they are a named collaborator than when they are an unacknowledged service provider who is paid by the hour.</p>
<p><strong>Accept that the honest answer may be “this design can’t answer that.”</strong> Sometimes the most valuable thing a statistician does is to say that the study is not powered to detect the thing we care about. If we treat that as obstruction when it is really information, we are likely to end up with an underpowered study <em>and</em> a strained relationship.</p>
</section>
<section id="in-industry-and-analytics-settings" class="level3">
<h3 class="anchored" data-anchor-id="in-industry-and-analytics-settings">In Industry and Analytics Settings</h3>
<p><strong>Bring the decision along with the query.</strong> “Pull last quarter’s same-store sales by region” is a specification. “We’re deciding whether to close three underperforming stores and I need to know whether the recent dip is real” is a problem. The second one lets the analyst point out that the first request would have been misleading (because, say, the comp-store definition excludes the exact stores being evaluated).<br>
<br>
</p>
<p><strong>Define the metric once, in writing, and stop redefining it in meetings.</strong> Most “the numbers don’t match” escalations seem to be two correct calculations of two different things. Thus, a metric definition should name its grain, its filters, its date logic, its denominator, and its owner.</p>
<p><strong>Say what happens if the number is wrong.</strong> An estimate for a monthly newsletter and an estimate that feeds a pricing change deserve different levels of scrutiny, and analysts cannot calibrate effort that they cannot see. So, we should tell them how far the consequences would reach (the blast radius).</p>
<p><strong>Give real deadlines and real slack.</strong> I wouldn’t call “EOD” a deadline when the request requires joining three source systems. In practice, it amounts to asking for an unvalidated guess that will carry the requester’s name.</p>
<hr>
</section>
</section>
<section id="what-you-owe-the-data-engineer" class="level2">
<h2 class="anchored" data-anchor-id="what-you-owe-the-data-engineer">What You Owe the Data Engineer</h2>
<p>Data engineers are the ones who find out that the business logic is inconsistent, usually at 2 a.m. Their constraints are rarely matters of preference, so it helps to treat them as fixed.</p>
<p><strong>Send the reproduction.</strong> “The dashboard looks off” costs an engineer hours. Compare that with “Row for store 412, 2026-07-14, shows fuel gallons of 0 but the POS extract shows 8,431 (here’s the query)”, which costs minutes.</p>
<p><strong>A defect report has four parts.</strong> Telling an engineer or statistician that a number is wrong (and nothing more) hands them a search problem with no search criteria. A usable report specifies:</p>
<ol type="1">
<li><strong>What is wrong:</strong> the exact rows, cells, or figures, with the query or filter that reproduces them.</li>
<li><strong>Why it is wrong:</strong> the business or domain fact that contradicts it (“these stores were acquired in March, so they can’t have January comp sales”).</li>
<li><strong>What correct looks like:</strong> the expected value or behaviour, with the independent source it comes from (the POS extract, the vendor invoice, the trial protocol).</li>
<li><strong>How to build the correct logic:</strong> the rule in implementable terms (“exclude stores from the comp base until they have 13 full months of history, keyed on <code>acquisition_date</code>, not <code>open_date</code>”).</li>
</ol>
<p>The fourth part is the one that collaborators most often skip, probably because it feels like doing the engineer’s job. However, the collaborator is the only person who <em>knows</em> the rule. The engineer can translate a rule into SQL in an afternoon, but they cannot come up with the rule itself. If they are forced to guess, the business logic has been delegated to the person with the least context for it, which is how the definition-drift problem below gets started in the first place.</p>
<p><strong>Announce upstream changes before they ship.</strong> A renamed field, a new store format, a changed promotion code, a vendor migration, and so on. Every one of these breaks something downstream. A two-line heads-up costs roughly nothing, whereas finding out through a silently wrong report can cost quite a lot.</p>
<p><strong>Understand that “just add a column” is rarely just adding a column.</strong> It may mean a backfill, a grain change, a contract change with every downstream consumer, and a reconciliation against numbers that people have already quoted externally.</p>
<p><strong>Stop building shadow pipelines.</strong> The spreadsheet that we maintain because the official table was inconvenient will eventually be cited in a meeting as a source of truth, and then someone will have to reconcile it. If the official table is wrong, it is better to file that as a defect than to route around it.</p>
<p><strong>Treat data quality as a shared problem.</strong> In dbt Labs’ 2025 practitioner survey (459 respondents, collected October–December 2024, and a self-selected industry sample as opposed to a probability sample), poor data quality was the most commonly cited challenge, named by more than 56% of respondents<span class="citation" data-cites="dbt2025"><sup>6</sup></span>. Data quality originates in operational systems and business processes. Thus, most of it sits outside the data team’s control, and escalating it to the data team (as if it were a service-desk ticket) is unlikely to fix it.</p>
<hr>
</section>
<section id="what-statisticians-and-data-engineers-owe-back" class="level2">
<h2 class="anchored" data-anchor-id="what-statisticians-and-data-engineers-owe-back">What Statisticians and Data Engineers Owe Back</h2>
<p>The obligations run in both directions, and this seems to be the part that pieces like this one tend to skip over.</p>
<p><strong>Learn the domain well enough to be wrong intelligently.</strong> Vance and Smith’s ASCCR framework (Attitude, Structure, Content, Communication, Relationship) is drawn from directing statistical collaboration labs across more than 900 direct projects and the supervision of 4,000 more, and it puts <em>Attitude</em> and <em>Relationship</em> on equal footing with <em>Content</em><span class="citation" data-cites="vance2019"><sup>7</sup></span>. The framework exists because technically correct work that nobody can understand has an effect size of zero.</p>
<p><strong>Report uncertainty as uncertainty.</strong> We should give the interval and the assumptions that it rests on. Treating a <em>P</em>-value as a binary verdict throws away most of what the analysis produced, since it is continuous evidence. This is the case for <a href="../statistics/s-values">S-values</a> and for the full <a href="../statistics/cifunction">compatibility/consonance function</a> over a single dichotomized interval.</p>
<p><strong>Say what would change your mind.</strong> Before running the analysis, we can state which results would be surprising and what we would do about them. This is the analyst-side equivalent of pre-registration, and it costs nothing.</p>
<p><strong>Make it reproducible or don’t ship it.</strong> Given the demonstrated spread across analysts<span class="citation" data-cites="silberzahn2018 botviniknezer2020"><sup>2, 3</sup></span>, I’d hesitate to call an analysis a result if its choices aren’t recorded. That means code in version control, the query saved next to the number, and the exclusions written down.</p>
<p><strong>Push back early and in writing.</strong> An analyst who accepts an impossible framing in the meeting, and then privately resents it for six weeks, has probably chosen the worst option available.</p>
<p><strong>Explain the constraint along with the refusal.</strong> “That’s a three-week change because the fact table’s grain is transaction-line and you’re asking for basket-level” is a sentence that a business partner can act on. “That’s not possible” gives them nothing to act on.</p>
<hr>
</section>
<section id="everything-runs-on-assumptions-so-write-them-down" class="level2">
<h2 class="anchored" data-anchor-id="everything-runs-on-assumptions-so-write-them-down">Everything Runs on Assumptions, So Write Them Down</h2>
<p>Every model is a bundle of <a href="../statistics/assumptions">assumptions</a>: linearity, exchangeability, missingness mechanisms, and the proposition that the measurement instrument measures the thing. However, so is everything else in the collaboration. We assume that the chair holds, the laptop boots, the warehouse job ran last night, the engineer understood the ticket, and the stakeholder meant what the ticket says. I don’t believe there is any assumption-free work. There is work whose assumptions are written down, and there is work whose assumptions are discovered later, at a worse time, by someone angrier.</p>
<p>The problem doesn’t come from <em>making</em> assumptions. It comes from what I’d call <em>laundering</em> them, which is letting them pass silently into the result so that the final number looks cleaner than the process that produced it. The analyst-variability results above<span class="citation" data-cites="silberzahn2018 botviniknezer2020"><sup>2, 3</sup></span> are an example of this, with dozens of defensible assumption sets, each of them invisible in its own write-up and only visible when they are laid side by side.</p>
<p>So the practice that I’d suggest, for both sides of the table, is a two-column ledger. For each assumption, we state:</p>
<ol type="1">
<li><strong>The assumption</strong>, in one falsifiable sentence.</li>
<li><strong>What is different if it’s wrong</strong>, meaning which conclusions survive, which die, and what we’d check first.</li>
</ol>
<p>Here’s a short worked example:</p>
<table class="caption-top table">
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>
<tr class="header">
<th>Assumption</th>
<th>If it’s wrong</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>The nightly load completed before the snapshot</td>
<td>Yesterday’s figures are partial; totals are biased downward; check the job log before anything else</td>
</tr>
<tr class="even">
<td><code>acquisition_date</code> marks when a store enters the comp base</td>
<td>Comp growth mixes organic and acquired stores; the trend is uninterpretable; re-key the base</td>
</tr>
<tr class="odd">
<td>Missingness in loyalty ID is unrelated to basket size</td>
<td>Basket-level estimates are biased toward small transactions; bound the effect or model the missingness</td>
</tr>
<tr class="even">
<td>The stakeholder’s “sales” means net of returns</td>
<td>Every reconciliation against finance fails by the return rate; re-confirm the definition</td>
</tr>
</tbody>
</table>
<p>Two things tend to happen when we do this. First, most of the second column turns out to be checkable in minutes, so a general worry about the number becomes a short list of things to verify. Second, the disagreements move to where they belong. “Your number is wrong” becomes “I don’t accept row three,” which is a conversation that two professionals can actually finish. An assumption that is stated along with the consequence of its failure can be tested like a hypothesis, whereas one that is left implicit tends to surface later, when it is much more expensive.</p>
</section>
<section id="an-intake-template" class="level2">
<h2 class="anchored" data-anchor-id="an-intake-template">An Intake Template</h2>
<p>I’d put this at the top of every request. If it cannot be filled in, then the work probably isn’t ready to start.</p>
<table class="caption-top table">
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>
<tr class="header">
<th>Field</th>
<th>Why it matters</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong>Decision</strong></td>
<td>What action changes based on the answer</td>
</tr>
<tr class="even">
<td><strong>Question</strong></td>
<td>One sentence, in domain language</td>
</tr>
<tr class="odd">
<td><strong>Estimand / metric</strong></td>
<td>Quantity, population, contrast, grain, denominator</td>
</tr>
<tr class="even">
<td><strong>Population &amp; exclusions</strong></td>
<td>Who’s in, who’s out, and why</td>
</tr>
<tr class="odd">
<td><strong>Time window</strong></td>
<td>Including how “current” is defined</td>
</tr>
<tr class="even">
<td><strong>Known data issues</strong></td>
<td>Migrations, backfills, definition changes</td>
</tr>
<tr class="odd">
<td><strong>Prior looks</strong></td>
<td>What has already been run or explored</td>
</tr>
<tr class="even">
<td><strong>Blast radius</strong></td>
<td>External? Regulatory? Internal only?</td>
</tr>
<tr class="odd">
<td><strong>Deadline &amp; slack</strong></td>
<td>Real date, and what happens if it slips</td>
</tr>
<tr class="even">
<td><strong>Owner</strong></td>
<td>Who signs off on the definition</td>
</tr>
<tr class="odd">
<td><strong>Assumption ledger</strong></td>
<td>Each assumption, and what changes if it’s wrong</td>
</tr>
</tbody>
</table>
</section>
<section id="two-checklists" class="level2">
<h2 class="anchored" data-anchor-id="two-checklists">Two Checklists</h2>
<hr>
<section id="before-you-ask" class="level3">
<h3 class="anchored" data-anchor-id="before-you-ask">Before You Ask</h3>
<ul class="task-list">
<li><label><input type="checkbox">I can state the decision this informs.</label></li>
<li><label><input type="checkbox">I have written down the metric definition, including denominator and grain.</label></li>
<li><label><input type="checkbox">I have disclosed every prior analysis and every look at the data.</label></li>
<li><label><input type="checkbox">I have flagged upstream changes in the relevant period.</label></li>
<li><label><input type="checkbox">If I’m reporting a defect: I’ve stated what’s wrong, why it’s wrong, what correct looks like, and the rule for building it.</label></li>
<li><label><input type="checkbox">I have given a real deadline and said what depends on it.</label></li>
<li><label><input type="checkbox">I have said what I expect to see, so a surprise is legible as a surprise.</label></li>
</ul>
</section>
<section id="before-you-deliver" class="level3">
<h3 class="anchored" data-anchor-id="before-you-deliver">Before You Deliver</h3>
<ul class="task-list">
<li><label><input type="checkbox">The analysis runs from raw source to final number without manual steps.</label></li>
<li><label><input type="checkbox">Exclusions and analytic choices are documented, including rejected alternatives.</label></li>
<li><label><input type="checkbox">Uncertainty is reported as an interval with stated assumptions.</label></li>
<li><label><input type="checkbox">I have named the assumption most likely to be wrong.</label></li>
<li><label><input type="checkbox">Someone in the domain has read the summary and understood it.</label></li>
<li><label><input type="checkbox">The number is reconciled against whatever the organisation already believes.</label></li>
</ul>
</section>
</section>
<section id="the-failure-modes-worth-naming" class="level2">
<h2 class="anchored" data-anchor-id="the-failure-modes-worth-naming">The Failure Modes Worth Naming</h2>
<hr>
<p><strong>The post-mortem request.</strong> The design is locked, the data are collected, and the ask is to find something (see Fisher, above).</p>
<p><strong>The definition drift.</strong> There are two teams, two correct numbers, and one metric name. I suspect this costs more meeting-hours annually than any modelling error.</p>
<p><strong>The heroic pull.</strong> An engineer bypasses the pipeline under deadline pressure, the one-off ends up being relied upon, and six months later nobody remembers the filters.</p>
<p><strong>The silent constraint.</strong> The analyst knows that the design cannot support the claim, says so once, softly, in a meeting, and is not heard. The remedy here is simply to write it down.</p>
<p>None of this is sophisticated, and I think that’s rather the point. The returns to being a good collaborator seem to come almost entirely from unglamorous, cheap, and early habits, and hardly at all from anyone being cleverer.</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">
<span class="screen-reader-only">Tip</span>One-Line Summary
</div>
</div>
<div class="callout-body-container callout-body">
<p>Bring the decision, define the metric, disclose the prior looks, and warn about upstream changes. On the other side, explain the constraint, report the uncertainty, and make it reproducible.</p>
</div>
</div>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body" data-entry-spacing="2" data-line-spacing="2">
<div id="ref-fisher1938" class="csl-entry">
1. Fisher RA. (1938). <span>“Presidential address to the first indian statistical congress.”</span> <em>Sankhy<span class="nocase">ā</span>: The Indian Journal of Statistics</em>. <strong>4</strong>:14–17.
</div>
<div id="ref-silberzahn2018" class="csl-entry">
2. <span class="nocase">Silberzahn R, Uhlmann EL, Martin DP, Anselmi P, Aust F, Awtrey E, et al.</span> (2018). <span>“Many analysts, one data set: Making transparent how variations in analytic choices affect results.”</span> <em>Advances in Methods and Practices in Psychological Science</em>. <strong>1</strong>:337–356. doi: <a href="https://doi.org/10.1177/2515245917747646">10.1177/2515245917747646</a>.
</div>
<div id="ref-botviniknezer2020" class="csl-entry">
3. <span class="nocase">Botvinik-Nezer R, Holzmeister F, Camerer CF, Dreber A, Huber J, Johannesson M, et al.</span> (2020). <span>“Variability in the analysis of a single neuroimaging dataset by many teams.”</span> <em>Nature</em>. <strong>582</strong>:84–88. doi: <a href="https://doi.org/10.1038/s41586-020-2314-9">10.1038/s41586-020-2314-9</a>.
</div>
<div id="ref-kass2016" class="csl-entry">
4. Kass RE, Caffo BS, Davidian M, Meng X-L, Yu B, Reid N. (2016). <span>“Ten simple rules for effective statistical practice.”</span> <em>PLOS Computational Biology</em>. <strong>12</strong>:e1004961. doi: <a href="https://doi.org/10.1371/journal.pcbi.1004961">10.1371/journal.pcbi.1004961</a>.
</div>
<div id="ref-asa2022" class="csl-entry">
5. American Statistical Association. (2022). <span>“Ethical guidelines for statistical practice.”</span> <a href="https://www.amstat.org/docs/default-source/amstat-documents/EthicalGuidelines.pdf">https://www.amstat.org/docs/default-source/amstat-documents/EthicalGuidelines.pdf</a>.
</div>
<div id="ref-dbt2025" class="csl-entry">
6. <span class="nocase">dbt Labs</span>. (2025). <span>“The 2025 state of analytics engineering report.”</span> <a href="https://www.getdbt.com/resources/state-of-analytics-engineering-2025">https://www.getdbt.com/resources/state-of-analytics-engineering-2025</a>.
</div>
<div id="ref-vance2019" class="csl-entry">
7. Vance EA, Smith HS. (2019). <span>“The <span>ASCCR</span> frame for learning essential collaboration skills.”</span> <em>Journal of Statistics Education</em>. <strong>27</strong>:265–274. doi: <a href="https://doi.org/10.1080/10691898.2019.1687370">10.1080/10691898.2019.1687370</a>.
</div>
</div>


<!-- -->

</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{rafi2026,
  author = {Rafi, Zad and Rafi, Zad},
  title = {How to {Be} a {Good} {Collaborator} to a {Statistician} and a
    {Data} {Engineer}},
  date = {2026-08-11},
  url = {https://lesslikely.com/statistics/good-collaborator.html},
  langid = {en-US}
}
</code></pre></div></section></div> ]]></description>
  <category>statistics</category>
  <guid>https://lesslikely.com/statistics/good-collaborator.html</guid>
  <pubDate>Tue, 11 Aug 2026 04:00:00 GMT</pubDate>
</item>
<item>
  <title>The Octagon Is a One-Trial Experiment</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/statistics/mma-single-event.html</link>
  <description><![CDATA[ 





<p>Jon Jones was, by almost any measure, the most complete mixed martial artist ever assembled. In 2023, he returned from a three-year layoff to fight Ciryl Gane for the heavyweight championship, and he won by submission in the first round of a fight that was not particularly close.</p>
<p>Now, let’s imagine that we had never seen Jones fight, that we watched exactly one round of that contest, and that someone then asked us: <em>what is the probability Jones wins this match?</em></p>
<p>For a frequentist, this is a problem. Frequency-based probability is formally defined as a limiting ratio (the number of times an event occurs divided by the number of opportunities, as the number of opportunities goes to infinity). A single fight is one trial, and we cannot take a limit over one data point. Thus, strictly speaking, the frequentist cannot assign a probability to this specific contest.</p>
<p>I don’t think this is a minor inconvenience. It is one of the oldest and most discussed objections in the philosophy of probability, usually called the <em>single-case problem</em>, and it is treated at length by Hájek (2009) and Gillies (2000).</p>
<p>However, most people watching that fight thought Jones was a heavy favorite, and they were right. I’d argue that they were right <em>in a way that a frequentist framework, properly applied, can actually explain</em>, although the explanation looks a bit different from what the objection implies.</p>
<p>The standard critique goes something like this. Frequentism requires repeatable experiments, and a unique event (<em>this</em> fight, on <em>this</em> night, with <em>this</em> version of these two people) can’t be repeated. Therefore, frequentism is useless for one-off events. Bayesians, by contrast, treat probability as a degree of belief updated on evidence, which works fine for singular events.</p>
<p>The critique is fair as far as it goes. However, it seems to conflate two things, which are the probability of <em>a fight type</em> and the probability of <em>this specific fight</em>.</p>
<p>When a model estimates that Jones wins a matchup like his bout with Gane with, say, a 70% probability, it makes no claim about a unique and unrepeatable event. The claim is about a <em>class</em> of contests (fights between a wrestler of Jones’s profile and a striker of Gane’s profile, under roughly these conditions). In other words, the probability is a statement about the <em>reference class</em>, and the individual fight only inherits it.</p>
<p>This is how von Mises originally framed it, where probability is always about collectives and never about single instances. So what we need is the right collective, and (as we’ll see below) choosing that collective is the hard part.</p>
<hr>
<iframe src="../MMA Calibration Explorer (standalone).html" width="100%" height="800" frameborder="0"></iframe>
<hr>
<section id="the-empirical-floor-what-the-betting-market-knows" class="level2">
<h2 class="anchored" data-anchor-id="the-empirical-floor-what-the-betting-market-knows">The empirical floor: what the betting market knows</h2>
<hr>
<p>Betting markets in MMA aggregate the predictions of many informed people, and their track record gives us a useful empirical anchor.</p>
<div class="callout callout-style-default callout-note 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">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>The numbers in this section come from market data and were not produced by controlled experiments. They describe the aggregate accuracy of odds-setters and bettors, and they say nothing direct about the underlying probability of any single fight.</p>
</div>
</div>
<p>Across all UFC fights, favorites win somewhere in the range of 60 to 65 percent of the time, which means that underdogs pull off upsets in more than a third of all fights. That 35-to-40 percent upset rate is notably higher than what we see in most major team sports.</p>
<p>Heavy favorites do better. UFC odds priced between -400 and -900 (implying an 80-to-90 percent win probability) have returned an 88 to 93 percent win rate since 2013. At the other end, fights where the odds land between +100 and -122 (roughly a coin flip) have resolved in favor of the nominal favorite only 51 percent of the time.</p>
<p>Thus, the market <em>does</em> seem to predict fight outcomes with meaningful accuracy when there is a real skill gap between the fighters. When the gap is small, its predictions fail, or at least flatten out.</p>
<hr>
</section>
<section id="skill-is-real-one-fight-is-still-noisy" class="level2">
<h2 class="anchored" data-anchor-id="skill-is-real-one-fight-is-still-noisy">Skill is real; one fight is still noisy</h2>
<hr>
<p>Here’s the central claim, stated as plainly as I can: <strong>a fighter being more skilled than their opponent does not mean they win every fight.</strong> It means that their <em>probability</em> of winning a single fight is greater than 0.5, and perhaps substantially so. However, a 70% win probability is also a 30% loss probability.</p>
<p>This may sound trivial, but I don’t think it is. It is, in miniature, the same confusion we see when applied researchers treat a statistically meaningful estimate as proof that the effect always occurs. The estimate describes a distribution, and a single draw from that distribution can land almost anywhere within it.</p>
<p>When Georges St-Pierre was 170 pounds of organized violence in his prime, his aggregate probability of winning any given welterweight fight was very high. However, any single fight carried:</p>
<ul>
<li>Opponent stylistic advantages that a model underweights</li>
<li>Chance of injury at any moment</li>
<li>Variance in execution (did the game plan hold? did the cuts go as expected?)</li>
<li>Pure stochastic noise (scrambles in grappling are notoriously non-deterministic)</li>
</ul>
<p>A single punch, a well-timed submission, or a referee stoppage can override any statistical edge a fighter might carry on paper, and a scramble on the mat can convert a dominant position into a finished fight in one second.</p>
<p>If we ran that version of GSP against a solid but beatable opponent ten times, we’d expect him to win eight or nine of them. In one fight, we’d still expect him to win, although “expect” here is a probabilistic statement and comes with no guarantee.</p>
<hr>
</section>
<section id="the-reference-class-problem-is-the-real-fight" class="level2">
<h2 class="anchored" data-anchor-id="the-reference-class-problem-is-the-real-fight">The reference-class problem is the real fight</h2>
<hr>
<p>Choosing the right reference class is where frequentist analysis actually gets difficult in MMA, and it is probably where most naive applications go wrong.</p>
<p>Holmes, McHale, and Żychaluk (2023) proposed a Markov chain simulation approach that explicitly estimates fighters’ skills in key aspects of the sport (striking, grappling, clinch work, etc.) and then simulates the fight, instead of simply predicting a binary outcome. Why does this matter? Because the outcome of a fight is a poor fit for a single draw from a bivariate distribution. It is the aggregate result of hundreds of micro-decisions, each of which has its own stochastic component.</p>
<p>When we model it that way (as they did, comparing favorably to bookmaker odds), we are treating the fight as a sequence of probabilistic events from a well-defined class. Here, the frequentist framework is doing real work, and it is simply being applied at the level of <em>techniques and positions</em> instead of <em>whole fights</em>.</p>
<p>I think this is a defensible and scientifically useful construction. It is also the same move that statisticians make in clinical medicine, where we cannot run a randomized trial on a specific patient, but we can estimate their probability of response from a well-defined reference population and then use that estimate to guide the decision.</p>
<hr>
</section>
<section id="what-this-means-for-how-you-talk-about-fight-outcomes" class="level2">
<h2 class="anchored" data-anchor-id="what-this-means-for-how-you-talk-about-fight-outcomes">What this means for how you talk about fight outcomes</h2>
<hr>
<p>The mistake that most analysts (and most fans) seem to make is a binary one, where the favorite “should” win, the underdog “shouldn’t,” and an upset is a surprise that requires an explanation.</p>
<p>A better way to look at it is that a fight between a 70% favorite and a 30% underdog has no predetermined outcome and is a draw from a distribution with that shape. Three out of ten times, the underdog wins, and when that happens we don’t need a special explanation for it, since it is what we should expect the distribution to produce.</p>
<p>An upset <em>does</em> warrant an explanation if upsets happen at a rate <em>higher</em> than the odds imply (i.e., if the market is miscalibrated). The Fightful analysis of heavy favorites suggests that the market is reasonably calibrated at the extremes and noisier in the middle.</p>
<p>The key methodological point is that <strong>a single fight is a sample of size one from a fighter’s underlying skill distribution.</strong> Skilled fighters have higher-mean distributions with less variance, while fighters with fight-ending power but defensive liabilities have wide distributions. Thus, the outcome of one draw does tell us something, but probably not very much.</p>
<p>This is why it is statistically incoherent to say, after a single upset, that the underdog was “always better.” It is equally incoherent to say, after a dominant win, that the favorite “always wins this,” since in both cases we would be reading a great deal into one draw.</p>
<hr>
</section>
<section id="the-bayesian-objection-and-why-it-doesnt-fully-resolve-things" class="level2">
<h2 class="anchored" data-anchor-id="the-bayesian-objection-and-why-it-doesnt-fully-resolve-things">The Bayesian objection, and why it doesn’t fully resolve things</h2>
<hr>
<p>Bayesians handle this better in some respects. They assign a prior belief about the outcome, update on the evidence, and end up with a posterior. For singular events, this seems to be the most coherent framework, since a posterior probability represents a degree of belief about <em>this specific contest</em> and does not need a reference class to be meaningful.</p>
<p>However, the Bayesian approach faces its own problem in combat sports, which is that we need a prior, and priors in MMA are hard to specify. Two fighters may never have faced similar opponents, may have competed in different promotions, and may have trained specifically for this contest in ways the market cannot observe.</p>
<p>In practice, I think the most useful approach is an instrumental one, with less concern for doctrine. We build the best reference class we can using comparable fights and fighters, fit a model, and interpret the output as a probability statement about <em>the type of contest this represents</em>, while acknowledging that any single fight is an unreliable single observation of the underlying process.</p>
<p>That is what frequentism looks like in practice. It does not claim that probabilities can’t apply to single fights, and it only demands that we ground the probability in something empirically defined.</p>
<hr>
</section>
<section id="the-upshot" class="level2">
<h2 class="anchored" data-anchor-id="the-upshot">The upshot</h2>
<hr>
<p>MMA really is less predictable than most sports. The upset rate is substantially higher than in major team sports, and the mechanisms seem clear enough, since it is a sport defined by rapid phase transitions (standup, clinch, ground), each of which carries its own variance.</p>
<p>I wouldn’t treat that unpredictability as a flaw in the analysis, because it is a property of the process itself. A skilled fighter’s edge is real and measurable in the aggregate (the betting market shows this plainly at heavy price differentials). However, it is not deterministic in a single contest.</p>
<p>The fighter who “should” win is the one with the higher probability under the best available model. Whether they win <em>this time</em> is a separate question, and anyone who collapses the two has made the same mistake that researchers make when they treat a significant p-value as proof that the effect always occurs.</p>
<p>As a rule, then, I’d treat one fight as one trial, and I’d look to the distribution (and the reference class behind it) before reading much into any single result.</p>
<hr>
<p><em>See also:</em> <a href="../statistics/s-values.html"><em>Semantic and Cognitive Tools to Aid Statistical Science</em></a>, which makes the case for replacing “significant” with “compatible” and describing what the data are more and less consistent with.</p>
<hr>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<hr>
<div id="refs">

</div>


<!-- -->

</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>statistics</category>
  <guid>https://lesslikely.com/statistics/mma-single-event.html</guid>
  <pubDate>Tue, 23 Jun 2026 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Multi-Language Code Examples</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/statistics/code-examples.html</link>
  <description><![CDATA[ 





<section id="introduction" class="level2">
<h2 class="anchored" data-anchor-id="introduction">Introduction</h2>
<p>In this post, I’d like to show how we can include Stata, Julia, and pseudocode in statistical posts on Less Likely.</p>
</section>
<section id="stata-examples" class="level2">
<h2 class="anchored" data-anchor-id="stata-examples">Stata Examples</h2>
<p>Let’s start with Stata. Here, the code is only included for syntax highlighting and is not executed:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb1-1">* ============================================</span>
<span id="cb1-2">* Example: Linear Regression Analysis</span>
<span id="cb1-3">* ============================================</span>
<span id="cb1-4"></span>
<span id="cb1-5">* Load example dataset</span>
<span id="cb1-6"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">sysuse</span> auto, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb1-7"></span>
<span id="cb1-8">* Descriptive <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">statistics</span></span>
<span id="cb1-9"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">summarize</span> price mpg <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">weight</span> foreign</span>
<span id="cb1-10"></span>
<span id="cb1-11">* Create a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">scatter</span> plot</span>
<span id="cb1-12"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">scatter</span> price mpg, <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Price vs. MPG"</span>)</span>
<span id="cb1-13"></span>
<span id="cb1-14">* Run linear regression</span>
<span id="cb1-15"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">regress</span> price mpg <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">weight</span> foreign</span>
<span id="cb1-16"></span>
<span id="cb1-17">* Store <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span></span>
<span id="cb1-18"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">store</span> model1</span>
<span id="cb1-19"></span>
<span id="cb1-20">* Display results with confidence intervals</span>
<span id="cb1-21"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">regress</span> price mpg <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">weight</span> foreign, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">level</span>(95)</span>
<span id="cb1-22"></span>
<span id="cb1-23">* Test joint significance</span>
<span id="cb1-24"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">test</span> mpg <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">weight</span></span>
<span id="cb1-25"></span>
<span id="cb1-26">* Predict <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">fitted</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">values</span></span>
<span id="cb1-27"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">predict</span> price_hat</span>
<span id="cb1-28"></span>
<span id="cb1-29">* Calculate residuals</span>
<span id="cb1-30"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">predict</span> residuals, residuals</span>
<span id="cb1-31"></span>
<span id="cb1-32">* Plot residuals</span>
<span id="cb1-33"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">scatter</span> residuals price_hat, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb1-34">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">yline</span>(0) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb1-35">  <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Residual Plot"</span>)</span></code></pre></div></div>
<section id="advanced-stata-panel-data-analysis" class="level3">
<h3 class="anchored" data-anchor-id="advanced-stata-panel-data-analysis">Advanced Stata: Panel Data Analysis</h3>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb2-1">* ============================================</span>
<span id="cb2-2">* Panel Data Example</span>
<span id="cb2-3">* ============================================</span>
<span id="cb2-4"></span>
<span id="cb2-5">* Load panel dataset</span>
<span id="cb2-6"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">webuse</span> nlswork, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb2-7"></span>
<span id="cb2-8">* Declare panel structure</span>
<span id="cb2-9">xtset idcode <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">year</span></span>
<span id="cb2-10"></span>
<span id="cb2-11">* Summary <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">statistics</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">by</span> panel</span>
<span id="cb2-12"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">xtsum</span> ln_wage age</span>
<span id="cb2-13"></span>
<span id="cb2-14">* Fixed <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">effects</span> regression</span>
<span id="cb2-15"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">xtreg</span> ln_wage age tenure, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">fe</span></span>
<span id="cb2-16"></span>
<span id="cb2-17">* Random <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">effects</span> regression</span>
<span id="cb2-18"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">xtreg</span> ln_wage age tenure, re</span>
<span id="cb2-19"></span>
<span id="cb2-20">* Hausman <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">test</span></span>
<span id="cb2-21"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">hausman</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">fe</span> re</span></code></pre></div></div>
</section>
</section>
<section id="julia-examples" class="level2">
<h2 class="anchored" data-anchor-id="julia-examples">Julia Examples</h2>
<p>Next, here’s some Julia code for a few basic summaries and a regression:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ============================================</span></span>
<span id="cb3-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example: Linear Regression in Julia</span></span>
<span id="cb3-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ============================================</span></span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">using</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">DataFrames</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Statistics</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">GLM</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Plots</span></span>
<span id="cb3-6"></span>
<span id="cb3-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create sample data</span></span>
<span id="cb3-8">n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span></span>
<span id="cb3-9">x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randn</span>(n)</span>
<span id="cb3-10">y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randn</span>(n) <span class="op" 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-11"></span>
<span id="cb3-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create DataFrame</span></span>
<span id="cb3-13">df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">DataFrame</span>(x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> x, y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> y)</span>
<span id="cb3-14"></span>
<span id="cb3-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Fit linear model</span></span>
<span id="cb3-16">model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(<span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@formula</span>(y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x), df)</span>
<span id="cb3-17"></span>
<span id="cb3-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Display results</span></span>
<span id="cb3-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">println</span>(model)</span>
<span id="cb3-20"></span>
<span id="cb3-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot data and fitted line</span></span>
<span id="cb3-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scatter</span>(x, y, label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data"</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>)</span>
<span id="cb3-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot!</span>(x, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">predict</span>(model), label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Fitted Line"</span>, linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb3-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlabel!</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X"</span>)</span>
<span id="cb3-25"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylabel!</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y"</span>)</span>
<span id="cb3-26"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">title!</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Linear Regression"</span>)</span></code></pre></div></div>
<section id="advanced-julia-bootstrap-confidence-intervals" class="level3">
<h3 class="anchored" data-anchor-id="advanced-julia-bootstrap-confidence-intervals">Advanced Julia: Bootstrap Confidence Intervals</h3>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ============================================</span></span>
<span id="cb4-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Bootstrap Example</span></span>
<span id="cb4-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ============================================</span></span>
<span id="cb4-4"></span>
<span id="cb4-5"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">using</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Distributions</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">StatsBase</span></span>
<span id="cb4-6"></span>
<span id="cb4-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Define a function to bootstrap</span></span>
<span id="cb4-8"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootstrap_mean</span>(data, n_bootstrap<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)</span>
<span id="cb4-9">    n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(data)</span>
<span id="cb4-10">    bootstrap_means <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">zeros</span>(n_bootstrap)</span>
<span id="cb4-11"></span>
<span id="cb4-12">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>n_bootstrap</span>
<span id="cb4-13">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Resample with replacement</span></span>
<span id="cb4-14">        sample <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rand</span>(data, n)</span>
<span id="cb4-15">        bootstrap_means[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(sample)</span>
<span id="cb4-16">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb4-17"></span>
<span id="cb4-18">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> bootstrap_means</span>
<span id="cb4-19"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb4-20"></span>
<span id="cb4-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate sample data</span></span>
<span id="cb4-22">data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randn</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.0</span></span>
<span id="cb4-23"></span>
<span id="cb4-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Perform bootstrap</span></span>
<span id="cb4-25">bootstrap_samples <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootstrap_mean</span>(data)</span>
<span id="cb4-26"></span>
<span id="cb4-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Calculate confidence interval</span></span>
<span id="cb4-28">ci_lower <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(bootstrap_samples, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>)</span>
<span id="cb4-29">ci_upper <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(bootstrap_samples, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>)</span>
<span id="cb4-30"></span>
<span id="cb4-31"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">println</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"95% Bootstrap CI: ["</span>, ci_lower, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>, ci_upper, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"]"</span>)</span>
<span id="cb4-32"></span>
<span id="cb4-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot bootstrap distribution</span></span>
<span id="cb4-34"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">histogram</span>(bootstrap_samples,</span>
<span id="cb4-35">         bins<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>,</span>
<span id="cb4-36">         label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bootstrap Distribution"</span>,</span>
<span id="cb4-37">         xlabel<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sample Mean"</span>,</span>
<span id="cb4-38">         ylabel<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Frequency"</span>)</span>
<span id="cb4-39"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vline!</span>([ci_lower, ci_upper],</span>
<span id="cb4-40">       label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"95% CI"</span>,</span>
<span id="cb4-41">       linewidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb4-42">       color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=:</span>red)</span></code></pre></div></div>
</section>
</section>
<section id="pseudocode-examples" class="level2">
<h2 class="anchored" data-anchor-id="pseudocode-examples">Pseudocode Examples</h2>
<section id="example-1-algorithm-block" class="level3">
<h3 class="anchored" data-anchor-id="example-1-algorithm-block">Example 1: Algorithm Block</h3>
<div class="algorithm">
<p><strong>Algorithm 1</strong> Bootstrap Confidence Interval</p>
<p><strong>Input:</strong> Data <img src="https://latex.codecogs.com/png.latex?X%20=%20%5C%7Bx_1,%20x_2,%20...,%20x_n%5C%7D">, statistic <img src="https://latex.codecogs.com/png.latex?%5Ctheta(X)">, confidence level <img src="https://latex.codecogs.com/png.latex?%5Calpha"></p>
<p><strong>Output:</strong> Confidence interval <img src="https://latex.codecogs.com/png.latex?%5B%5Ctheta_L,%20%5Ctheta_U%5D"></p>
<ol type="1">
<li><strong>for</strong> <img src="https://latex.codecogs.com/png.latex?b%20=%201"> <strong>to</strong> <img src="https://latex.codecogs.com/png.latex?B"> <strong>do</strong>
<ul>
<li>Draw bootstrap sample <img src="https://latex.codecogs.com/png.latex?X_b%5E*"> by sampling <img src="https://latex.codecogs.com/png.latex?n"> observations from <img src="https://latex.codecogs.com/png.latex?X"> with replacement</li>
<li>Calculate <img src="https://latex.codecogs.com/png.latex?%5Ctheta_b%5E*%20=%20%5Ctheta(X_b%5E*)"></li>
</ul></li>
<li><strong>end for</strong></li>
<li>Sort <img src="https://latex.codecogs.com/png.latex?%5C%7B%5Ctheta_1%5E*,%20%5Ctheta_2%5E*,%20...,%20%5Ctheta_B%5E*%5C%7D"> in ascending order</li>
<li>Set <img src="https://latex.codecogs.com/png.latex?%5Ctheta_L%20=%20%5Ctext%7Bquantile%7D(%5Ctheta%5E*,%20%5Calpha/2)"></li>
<li>Set <img src="https://latex.codecogs.com/png.latex?%5Ctheta_U%20=%20%5Ctext%7Bquantile%7D(%5Ctheta%5E*,%201-%5Calpha/2)"></li>
<li><strong>return</strong> <img src="https://latex.codecogs.com/png.latex?%5B%5Ctheta_L,%20%5Ctheta_U%5D"></li>
</ol>
</div>
</section>
<section id="example-2-simple-pseudocode-block" class="level3">
<h3 class="anchored" data-anchor-id="example-2-simple-pseudocode-block">Example 2: Simple Pseudocode Block</h3>
<pre class="pseudocode"><code>ALGORITHM: Linear Regression via Gradient Descent
INPUT: X (n × p design matrix), y (n × 1 response vector), learning rate α
OUTPUT: β (p × 1 coefficient vector)

1. Initialize β = 0, iteration = 0, maxiter = 1000
2. REPEAT until convergence OR iteration &gt; maxiter:
   a. Compute predictions: ŷ = Xβ
   b. Compute residuals: r = y - ŷ
   c. Compute gradient: ∇L = -2X'r/n
   d. Update parameters: β = β - α∇L
   e. iteration = iteration + 1
3. RETURN β</code></pre>
</section>
<section id="example-3-detailed-algorithm-with-comments" class="level3">
<h3 class="anchored" data-anchor-id="example-3-detailed-algorithm-with-comments">Example 3: Detailed Algorithm with Comments</h3>
<div class="algorithm">
<p><strong>Algorithm 2</strong> Maximum Likelihood Estimation</p>
<p><strong>Input:</strong> Data <img src="https://latex.codecogs.com/png.latex?X">, log-likelihood function <img src="https://latex.codecogs.com/png.latex?%5Cell(%5Ctheta%7CX)">, initial value <img src="https://latex.codecogs.com/png.latex?%5Ctheta_0"></p>
<p><strong>Output:</strong> <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Ctheta%7D_%7BMLE%7D"></p>
<ol type="1">
<li>Set <img src="https://latex.codecogs.com/png.latex?%5Ctheta%20%5Cleftarrow%20%5Ctheta_0">, <img src="https://latex.codecogs.com/png.latex?t%20%5Cleftarrow%200"></li>
<li><strong>while</strong> not converged <strong>do</strong>
<ul>
<li>Compute score function: <img src="https://latex.codecogs.com/png.latex?s(%5Ctheta)%20=%20%5Cnabla_%5Ctheta%20%5Cell(%5Ctheta%7CX)"></li>
<li>Compute Hessian: <img src="https://latex.codecogs.com/png.latex?H(%5Ctheta)%20=%20%5Cnabla%5E2_%5Ctheta%20%5Cell(%5Ctheta%7CX)"></li>
<li>Update: <img src="https://latex.codecogs.com/png.latex?%5Ctheta%20%5Cleftarrow%20%5Ctheta%20-%20H(%5Ctheta)%5E%7B-1%7Ds(%5Ctheta)"></li>
<li>Check convergence: <strong>if</strong> <img src="https://latex.codecogs.com/png.latex?%5C%7Cs(%5Ctheta)%5C%7C%20%3C%20%5Cepsilon"> <strong>then</strong> break</li>
<li><img src="https://latex.codecogs.com/png.latex?t%20%5Cleftarrow%20t%20+%201"></li>
<li><strong>if</strong> <img src="https://latex.codecogs.com/png.latex?t%20%3E%20%5Ctext%7Bmax%5C_iterations%7D"> <strong>then</strong> break</li>
</ul></li>
<li><strong>end while</strong></li>
<li>Compute standard errors: <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BSE%7D(%5Chat%7B%5Ctheta%7D)%20=%20%5Csqrt%7B%5Ctext%7Bdiag%7D(-H(%5Chat%7B%5Ctheta%7D)%5E%7B-1%7D)%7D"></li>
<li><strong>return</strong> <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Ctheta%7D_%7BMLE%7D"></li>
</ol>
</div>
</section>
</section>
<section id="comparing-approaches" class="level2">
<h2 class="anchored" data-anchor-id="comparing-approaches">Comparing Approaches</h2>
<p>Here’s how the same (very simple) analysis looks when we write it in each language:</p>
<section id="task-calculate-mean-and-95-ci" class="level3">
<h3 class="anchored" data-anchor-id="task-calculate-mean-and-95-ci">Task: Calculate Mean and 95% CI</h3>
<p><strong>R:</strong></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">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;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</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;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb6-2">mean_val <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>(data)</span>
<span id="cb6-3">ci <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>(data)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>conf.int</span></code></pre></div></div>
<p><strong>Julia:</strong></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb7-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">using</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Statistics</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">HypothesisTests</span></span>
<span id="cb7-2">data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randn</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span></span>
<span id="cb7-3">mean_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(data)</span>
<span id="cb7-4">ci <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">confint</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">OneSampleTTest</span>(data))</span></code></pre></div></div>
<p><strong>Stata:</strong></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb8-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb8-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span> 100</span>
<span id="cb8-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">generate</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">data</span> = rnormal(5, 2)</span>
<span id="cb8-4"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">mean</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">data</span></span></code></pre></div></div>
<p><strong>Python:</strong></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb9-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> scipy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> stats</span>
<span id="cb9-3">data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb9-4">mean_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.mean(data)</span>
<span id="cb9-5">ci <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> stats.t.interval(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(data)<span class="op" 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>
<span id="cb9-6">                      loc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>mean_val,</span>
<span id="cb9-7">                      scale<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>stats.sem(data))</span></code></pre></div></div>
</section>
</section>
<section id="best-practices" class="level2">
<h2 class="anchored" data-anchor-id="best-practices">Best Practices</h2>
<ol type="1">
<li><strong>Use syntax highlighting for display-only code.</strong> Most readers only need to see the code.</li>
<li><strong>Execute code sparingly.</strong> I’d only execute it when the output is essential to the post.</li>
<li><strong>Document the setup.</strong> We should note the required packages and their versions.</li>
<li><strong>Test before publishing.</strong> The code should run without errors.</li>
<li><strong>Provide context.</strong> It helps to explain what the code does and why it is there.</li>
</ol>
</section>
<section id="resources" class="level2">
<h2 class="anchored" data-anchor-id="resources">Resources</h2>
<ul>
<li><a href="https://quarto.org/docs/computations/stata.html">Quarto Stata Documentation</a></li>
<li><a href="https://quarto.org/docs/computations/julia.html">Quarto Julia Documentation</a></li>
<li><a href="https://highlightjs.org/static/demo/">Highlight.js Language Support</a></li>
</ul>
</section>
<section id="conclusion" class="level2">
<h2 class="anchored" data-anchor-id="conclusion">Conclusion</h2>
<p>With support for several languages in place, we can share statistical methods and algorithms in whichever language suits the analysis and the audience. I’d also suggest reading the documentation linked above before executing Stata or Julia chunks.</p>


<!-- -->

</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>statistics</category>
  <category>programming</category>
  <category>tutorial</category>
  <guid>https://lesslikely.com/statistics/code-examples.html</guid>
  <pubDate>Tue, 06 Jan 2026 05:00:00 GMT</pubDate>
</item>
<item>
  <title>A Critical Look At The REDUCE-IT Trial</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/medicine/reduce-it.html</link>
  <description><![CDATA[ 




<p>It’s finally here. The results of the REDUCE-IT trial were presented today at the American Heart Association conference and the paper is also up on <a href="https://www.nejm.org/doi/full/10.1056/NEJMoa1812792"><em>The New England Journal of Medicine</em>.</a> I’ve been excited to see the results of this trial ever since the announcement in September (which I wrote about <a href="../medicine/vascepa-reduce-it">here</a>) so let’s get right into it.</p>
<p>I’ll just copy and paste what I’d written before in September regarding the inclusion/criteria and statistical analyses so that I can get right into the results. You can skip this section and go to the results if you’d like or you can reread it to get reacquainted with the trial design.</p>
<hr>
<p><strong>September 2018:</strong></p>
<p>That’s why I thought it would be a good time to review the preregistration protocol of the REDUCE-IT trial on <a href="https://clinicaltrials.gov/ct2/show/study/NCT01492361">ClinicalTrials.gov</a> and a <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5396348/">detailed paper</a> that describes the rationale behind the study design. Let’s get into it.</p>
<p>So very clearly, the authors state what the study here is doing,</p>
<blockquote class="blockquote">
<p>“AMR101 (icosapent ethyl [ethyl-EPA]) is a highly purified ethyl ester of eicosapentaenoic acid (EPA) being developed by Amarin Pharma Inc.&nbsp;for the treatment of hypertriglyceridemia.</p>
</blockquote>
<p>The purpose of this study is to evaluate whether this drug, combined with a statin therapy, will be superior to the statin therapy alone, when used as a prevention in reducing long-term cardiovascular events in high-risk patients with mixed dyslipidemia.”</p>
<p>Comparing statins + highly purified, high doses of EPA to statins alone. Why are they using such high doses? The authors explain here,</p>
<blockquote class="blockquote">
<p>“It is worth noting that the promising results from JELIS occurred with a high‐purity EPA preparation dosed at 1.8 g/d in a Japanese population, for whom the baseline EPA levels are higher than in western populations due to greater dietary intake of marine omega‐3 fatty acids.</p>
<p>Icosapent ethyl 12‐week dosing at 4 g/d in a high‐risk population similar to that within the Reduction of Cardiovascular Events with Icosapent Ethyl–Intervention Trial (REDUCE‐IT) who had persistent elevations of TG after treatment with statins resulted in significant reductions in TG and atherogenic lipoproteins, as well as comparable plasma EPA levels as the 1.8 g/d dosing group in JELIS._</p>
<p>T herefore, a dose of 4 g/d was selected as the dose for further study. In this context, REDUCE‐IT was designed to determine if treatment with icosapent ethyl 4 g/d vs placebo would reduce ischemic events in patients at increased CV risk already being treated with statins.”</p>
</blockquote>
<p>Also “worth noting” that the <a href="https://www.ncbi.nlm.nih.gov/pubmed/17398308">JELIS trial</a> was included in both meta-analyses mentioned at the beginning of the blog post.</p>
<p>The primary outcome is a composite endpoint that consists of CV death, MI, stroke, coronary revascularization, and hospitalization for unstable angina. Whenever I hear composite endpoint, I often become skeptical because I’ve seen composite endpoints abused or misused in several ways, resulting in very misleading results. There was a very nice post on composite endpoints by Hilda Bastian <a href="https://statistically-funny.blogspot.com/2015/02/lets-play-outcome-mash-up-clinical.html">here</a>.</p>
<p>The study (REDUCE-IT) enrolled 8,000 participants and began in 2011 and ended in 2018.</p>
<p>Why 8,000 participants?</p>
<p>The authors explain here,</p>
<blockquote class="blockquote">
<p>“The sample‐size calculation was based on a hazard ratio assumption of 0.85. Therefore, 1612 events would be required to have approximately 90% power with a 1‐sided α‐level of 2.5% and with 2 interim analyses. This results in a total target sample size of 7990 patients.</p>
<p>Approximately 70% of randomized patients were to be in CV risk stratum 1 (established CVD) and approximately 30% of randomized patients were to be in CV risk stratum 2 (high‐risk primary prevention defined by diabetes mellitus and other risk factors). Randomization was stratified by CV risk strata, ezetimibe use, and by geographical region.”</p>
</blockquote>
<p>The design power calculations seem like they were based on very optimistic expectations of the effect size, and apparently, justifiably so!</p>
<p>A bit unfortunate that there is no mention anywhere of what statistical analyses they planned on doing exactly.</p>
<p>In order for participants to be eligible for the trial:</p>
<ul>
<li><p>they had to be over the age of 45</p></li>
<li><p>have high levels of triglycerides (hypertriglyceridemia) originally &gt;150 mg/dL but then changed to &gt;200 mg/dL via a protocol change</p></li>
<li><p>been on statins for at least a month</p></li>
<li><p>they had to have a history of heart disease</p></li>
<li><p>There’s a bunch of exclusion criteria too that I don’t really feel the need to go over, but you can see them listed out on the registry.</p></li>
</ul>
<p>Also, worth mentioning of course that the trial is funded by Amarin, AKA the manufacturer of Vascepa.</p>
<hr>
<section id="november-2018" class="level2">
<h2 class="anchored" data-anchor-id="november-2018"><strong>November 2018</strong></h2>
</section>
<section id="results" class="level2">
<h2 class="anchored" data-anchor-id="results">Results:</h2>
<p>Quick Characteristics of Participants</p>
<ul>
<li><p>Median Age: 64 years old</p></li>
<li><p>Females: 28.8%</p></li>
<li><p>Median LDL: 75.0 mg/dL</p></li>
<li><p>Median HDL: 40 mg/dL</p></li>
<li><p>Median Triglycerides: 216.0 mg/dL</p></li>
</ul>
</section>
<section id="changes-in-lipids" class="level2">
<h2 class="anchored" data-anchor-id="changes-in-lipids">Changes in Lipids:</h2>
<p>The median change in <strong>triglycerides</strong> from baseline to 1 year was a <strong>decrease of 18.3%</strong> (−39.0 mg per deciliter) for the Vascepa group and an <strong>increase of 2.2%</strong> (4.5 mg per deciliter).</p>
<p>A <strong>between-group</strong> comparison of change scores shows that the median group reduction was <strong>19.7% higher</strong> (44.5 mg/dL, p&lt;0.001) in the Vascepa group than it was in the placebo group.</p>
<p><strong>LDL</strong> increased in both groups from baseline to year 1, however, the Vascepa group had a <strong>6.6%</strong> (5.0 mg per deciliter, p&lt;0.001) <strong>lower increase</strong> than the placebo group.</p>
</section>
<section id="differences-in-clinical-endpoints-what-we-really-care-about" class="level2">
<h2 class="anchored" data-anchor-id="differences-in-clinical-endpoints-what-we-really-care-about">Differences in Clinical Endpoints (what we <em>really</em> care about):</h2>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700143/Site/PrimaryEndpoint.png" alt="Survival curve showing the primary endpoints for the REDUCE-IT trial"></p>
<hr>
<p>A total of 1606 participants experienced one of the primary end-point events.</p>
<p>Approximately <strong>17.2%</strong> of the participants in the Vascepa group experienced a primary end-point whereas <strong>22.2%</strong> of the participants in the control group experienced a primary end-point.</p>
<p>Thus, the <strong>between-group difference</strong> is <strong>4.8%</strong> (95% CI, 3.1 to 6.5). The results are: (hazard ratio, 0.75; 95% confidence interval [CI], 0.68 to 0.83; P&lt;0.001).</p>
<p>So very clearly we can see that there was a statistically significant difference and the confidence interval leans towards an effect.</p>
<blockquote class="blockquote">
<p>The authors calculated a number needed to treat for this between-group difference (NNT: 21 (95% CI, 15 to 33)) and its confidence interval which slightly makes me laugh. I’ve <a href="../statistics/problems-with-nnt">written about the NNT</a> before and its flaws and the reality is that it doesn’t do what it claims to do and has very bizarre statistical properties.</p>
</blockquote>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700144/Site/SecondaryEndpoint.png" alt="Survival curve showing the secondary endpoints for the REDUCE-IT trial"></p>
<hr>
<p>With regards to secondary efficacy end-point events, 11.2% of the participants in the Vascepa group experienced an event compared to 14.8% of the participants in the placebo group.</p>
<p>The absolute between-group difference was <strong>3.6%</strong> (95% CI, 2.1 to 5.0).</p>
<p>Again, very clearly a difference.</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700119/Site/Figure-2.jpg" alt="A forest plot showing prespecified subgroup analyses for the REDUCE-IT trial"></p>
<hr>
<p>They also ran prespecified subgroup analyses to see whether the effects would be influenced. What was interesting to me was when they claimed this:</p>
<blockquote class="blockquote">
<p>“Baseline triglyceride levels (≥150 vs.&nbsp;&lt;150 mg per deciliter or ≥200 or &lt;200 mg per deciliter) had no influence on the primary or key secondary efficacy end points (Figures 2 and Figure 3).”</p>
</blockquote>
<p>This is interesting to me because there were so few patients that were enrolled into the trial with triglyceride levels that were beneath 150 or hovering around 150. This is very clearly reflected by the wide confidence intervals in that subgroup which can be seen in the figure above. This is because the protocol changed early in the trial to restrict participant inclusion to people with higher triglycerides,</p>
<blockquote class="blockquote">
<p>“The first protocol amendment in May 2013 changed the lower limit of the acceptable triglyceride level from 150 mg per deciliter to 200 mg per deciliter (2.26 mmol per liter), with no allowance for variability.”</p>
</blockquote>
<p>Whereas originally, it was,</p>
<blockquote class="blockquote">
<p>“Eligible patients had a fasting triglyceride level of 150 to 499 mg per deciliter (1.69 to 5.63 mmol per liter)… because of the intraindividual variability of triglyceride levels, the initial protocol allowed for a 10% lower triglyceride level from the target lower limit, which permitted patients to be enrolled if they had a triglyceride level of at least 135 mg per deciliter (1.52 mmol per liter).”</p>
</blockquote>
<p>Seems like more data is needed to say anything about this with confidence.</p>
</section>
<section id="hierarchical-tests" class="level2">
<h2 class="anchored" data-anchor-id="hierarchical-tests">Hierarchical Tests</h2>
<p>For their prespecified hierarchical tests, this is what they found:</p>
<ul>
<li><p>Rates of Composite Ischemic Endpoints + Rates of Cardiovascular Death: (Vascepa: 4.3% vs.&nbsp;Placebo: 5.2%; hazard ratio, 0.80; 95% CI, 0.66 to 0.98; P=0.03)</p></li>
<li><p>Rate of Death From Any Cause: Vascepa: 6.7% vs.&nbsp;Placebo: 7.6% (hazard ratio, 0.87; 95% CI, 0.74 to 1.02).</p></li>
<li><p>Doesn’t seem to be statistically significant, but the coverage of the intervals leans towards an effect.</p></li>
<li><p>Rates of Adjudicated Sudden Cardiac Death: Vascepa: 1.5% vs.&nbsp;Placebo: 2.1% (hazard ratio, 0.69; 95% CI, 0.50 to 0.96)</p></li>
<li><p>Rates of Cardiac Arrest: Vascepa: 0.5% vs.&nbsp;Placebo: 1.0% (hazard ratio, 0.52; 95% CI, 0.31 to 0.86)</p></li>
</ul>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700125/Site/Hierarchial-Testing.jpg" alt="A forest plot showing hierarchial analyses for the REDUCE-IT trial"></p>
<hr>
<p>So most seem to favor the Vascepa group.</p>
</section>
<section id="safety" class="level2">
<h2 class="anchored" data-anchor-id="safety">Safety</h2>
<p>What about its safety? A look at the <a href="https://www.nejm.org/doi/suppl/10.1056/NEJMoa1812792/suppl_file/nejmoa1812792_appendix.pdf">supplementary appendix</a> gives us this:</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700144/Site/Serious-Adverse-Events.png" alt="Table showing the number of serious adverse events per group in the REDUCE-IT trial"></p>
<hr>
<p>The analyses failed to show any statistically significant differences for serious treatment-emergent adverse events.</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700108/Site/Adverse-Events.png" alt="Table showing the number of adverse events per group in the REDUCE-IT trial"></p>
<hr>
<p>However, among other treatment-emergent adverse events, Peripheral Edema, Constipation, and Atrial Fibrillation were significantly more frequent in the Vascepa group.</p>
<p>There you have it.</p>
</section>
<section id="conclusions" class="level2">
<h2 class="anchored" data-anchor-id="conclusions">Conclusions</h2>
<p>The results of this large trial clearly suggest that Vascepa had a notable effect on triglycerides and clinical endpoints. These data along with the results from the <a href="https://www.ncbi.nlm.nih.gov/pubmed/17398308">JELIS</a> trial should be considered as supporting evidence for the hypothesis that high doses of EPA (not your over-the-counter normal fish oil) may have an effect on cardiovascular disease events (even though JELIS was an open-label study).</p>
<p>Hopefully, future meta-analyses make high doses of EPA an inclusion criteria to avoid pooling null results from trials using smaller dosages, where it may be more difficult to see an effect. Currently, there are a few other ongoing trials that are also using high doses of EPA:</p>
<blockquote class="blockquote">
<p>“Ongoing trials of moderate-to-high doses of pure EPA ethyl ester will provide further information on the effects of these agents. These trials include the Randomized Trial for Evaluation in Secondary Prevention Efficacy of Combination Therapy–Statin and EPA (RESPECT-EPA; UMIN Clinical Trials Registry number, <a href="https://upload.umin.ac.jp/cgi-open-bin/ctr_e/ctr_view.cgi?recptno=R000014051">UMIN000012069</a>), a secondary prevention outcomes trial involving statin-treated patients in Japan, and the Effect of Vascepa on Improving Coronary Atherosclerosis in People with High Triglycerides Taking Statin Therapy (EVAPORATE; ClinicalTrials.gov number, <a href="https://clinicaltrials.gov/ct2/show/NCT02926027">NCT02926027)</a>, which is examining changes in coronary plaque over 9 to 18 months.”</p>
</blockquote>
<p>Even though REDUCE-IT has been successful, it is only <em>one</em> trial, and it’s always worth remembering what the history of fish is, even though this trial didn’t look at fish oil but rather a pharmaceutical formulation of EPA.</p>
<hr>
</section>
<section id="a-brief-timeline-of-fish-oil" class="level2">
<h2 class="anchored" data-anchor-id="a-brief-timeline-of-fish-oil">A Brief Timeline of Fish Oil</h2>
<ul>
<li><p><strong>1970s</strong> | <a href="https://www.ncbi.nlm.nih.gov/pubmed/7435433">A group of explorers</a> noticed that people who consumed fish also had lower incidences of heart disease.</p></li>
<li><p><strong>1980s</strong>-<strong>1990s</strong> | <a href="https://www.ncbi.nlm.nih.gov/pubmed/3990713?access_num=3990713&amp;link_type=MED&amp;dopt=Abstract">Early</a> observational <a href="https://www.ncbi.nlm.nih.gov/pubmed/9091800?access_num=9091800&amp;link_type=MED&amp;dopt=Abstract">studies</a> also saw a connection between fish consumption and heart disease risk</p></li>
<li><p><strong>1990s</strong> | <a href="https://www.ncbi.nlm.nih.gov/pubmed/9310278?access_num=9310278&amp;link_type=MED&amp;dopt=Abstract">A few</a> randomized trials <a href="https://www.ncbi.nlm.nih.gov/pubmed/10465168?access_num=10465168&amp;link_type=MED&amp;dopt=Abstract">were</a> conducted to see the effects of fish oil supplementation and CVD outcomes</p></li>
<li><p><strong>2002</strong> | The American Heart Association put out <a href="http://circ.ahajournals.org/content/106/21/2747?ijkey=a0bd0a11dda35f2aa109c24a01266ea89e3d0121&amp;keytype2=tf_ipsecsha">a statement</a> suggesting that fish oil supplementation was beneficial for fatal outcomes</p></li>
<li><p><strong>2002</strong> - <strong>2016</strong> | Several <a href="http://www.thelancet.com/article/S0140-6736(07)60527-3/abstract">randomized trials</a> and <a href="https://www.ncbi.nlm.nih.gov/pubmed/15495044">systematic reviews</a> found inconsistent evidence for the effects of fish oil supplementation and CVD outcomes</p></li>
<li><p><strong>2016</strong> | The American Heart Association creates <a href="http://circ.ahajournals.org/content/135/15/e867.long">a scientific advisory group</a> to look at all the evidence and concludes that despite the controversy, there was a small benefit from fish oil and it could be worth it for people who had a history of CVD events.</p></li>
<li><p><strong>2018</strong> | <a href="https://www.ncbi.nlm.nih.gov/pubmed/29387889">Large meta-analysis</a> published in <em><strong>JAMA</strong></em> with 77,000 + participants found no benefit from fish oil supplementation on real clinical endpoints.</p></li>
<li><p><strong>Mid - 2018</strong> | Most <a href="https://www.cochranelibrary.com/cdsr/doi/10.1002/14651858.CD003177.pub3/full">comprehensive meta-analysis</a> and systematic review with 112,000 participants by Cochrane finds very small benefits to several CVD-related outcomes.</p></li>
<li><p><strong>Late 2018</strong> | <a href="https://investor.amarincorp.com/news-releases/news-release-details/reduce-ittm-cardiovascular-outcomes-study-vascepar-icosapent">Announcement</a> by the manufacturer of <a href="https://www.vascepa.com/">Vascepa</a> exclaiming that high-doses of fish oil in the REDUCE-IT trial had a large effect (25% reduction) on CVD outcomes.</p></li>
</ul>
<hr>
<blockquote class="blockquote">
<p>Edit: It came to my attention after writing this blog post that the placebo formulation included large amounts of mineral oil. Thus, the control arm was taking mineral oil + statins, while the intervention group was taking Vascepa + statins. This is problematic because mineral oil is a <a href="https://www.webmd.com/drugs/2/drug-153865/mineral-oil-laxative-oral/details">known</a> laxative and could possibly interfere with the absorption of statins. Some data to suggest this is the change in LDL within the control arm. LDL increased after the trial, which doesn’t make much sense given that they were taking statins.</p>
<p>We have sufficient evidence from the literature to suggest that statins should lower LDL. It is also worth pointing out that side effects like diarrhea were far more prevalent within the control group in a 7,000+ clinical trial. Thus, I suspect that the control group may have been given enough mineral oil that it possibly interfered with the absorption of statins within the gut, thus reducing their efficacy, and making the difference between the Vascepa group and control group even more substantial.</p>
</blockquote>
<p>Amarin, the manufacturer of Vascepa, has responded to some of these criticisms <a href="../uploads/amarin-response.pdf">here</a>.</p>


<!-- -->

</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>medicine</category>
  <guid>https://lesslikely.com/medicine/reduce-it.html</guid>
  <pubDate>Tue, 06 Jan 2026 05:00:00 GMT</pubDate>
  <media:content url="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700143/Site/PrimaryEndpoint.png" medium="image" type="image/png"/>
</item>
<item>
  <title>Seductive Surrogates Can Be Deadly</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/medicine/seductive-surrogates.html</link>
  <description><![CDATA[ 




<p>In clinical trials, it’s not always possible to measure hard endpoints like cardiovascular disease events and cancer remission rates. Studies that use clinical outcomes often dichotomize these variables, and as a result, they need to have a large number of participants and be long in duration to detect differences between groups.</p>
<p>Again, this type of research is expensive and not always feasible. In many scenarios, a more practical alternative is to focus on intermediate markers. Intermediate markers are biomarkers associated with a clinical outcome.<span class="citation" data-cites="hulley2007"><sup>1</sup></span></p>
<p>For example, C-reactive protein (CRP) is a molecule that is strongly associated with inflammation, and you can often find that CRP levels increase when inflammation increases.<span class="citation" data-cites="bray2016w chew2012jets pepys2003jci"><sup>2–4</sup></span> Because inflammation is associated with coronary heart disease (CHD)<span class="citation" data-cites="Frangogiannis2012-fo Hansson2005-wz Libby2006-ch Ruparelia2017-nf"><sup>5–8</sup></span>, an investigator may choose to focus on decreasing levels of inflammation in a clinical trial (measured by CRP), rather than focus on how many CHD-related deaths the intervention prevents.</p>
<p>If the changes in an intermediate marker can robustly predict changes in a hard endpoint, and if it’s part of the primary pathway of the clinical outcome, then your biomarker can be considered a surrogate marker for that clinical outcome.<span class="citation" data-cites="hulley2007"><sup>1</sup></span> (I’m not sure if CRP is a good surrogate outcome for CHD events, just used it as an example).</p>
<p>Low-density lipoprotein (LDL) is considered an excellent surrogate marker for CHD because reducing LDL levels also seems to reduce the number of CHD events.<span class="citation" data-cites="Cholesterol_Treatment_Trialists_CTT_Collaboration2015-ni Taylor2013-te"><sup>9,10</sup></span> Unfortunately, this can all go wrong if the intermediate marker is associated with a clinical outcome, but is not involved in the causal pathway of the outcome and is confounded by other phenomena.</p>
<section id="torcetrapib" class="level2">
<h2 class="anchored" data-anchor-id="torcetrapib">Torcetrapib</h2>
<p>A great example of this is the story of high-density lipoprotein (HDL) and myocardial infarction (heart attacks). Several studies had found associations between low levels of HDL, often considered <em>“good cholesterol,”</em> and heart attacks.<span class="citation" data-cites="assmann1996a Curb2004-ee Gordon1977-le Gordon1989-mc Rahilly-Tierney2011-ox Sharrett2001-su Turner1998-gv"><sup>11–17</sup></span></p>
<p>So, it shouldn’t come as a surprise that a drug (torcetrapib) was produced by Pfizer that attempted to increase the amount of HDL with the hopes that it would reduce the number of CVD events.</p>
<p>A group of researchers administered the drug to thousands of patients.<span class="citation" data-cites="Barter2007-if"><sup>18</sup></span> The drug was successful in changing the lipids of the participants to more favorable numbers. Patients who received the drug had a 24.9% decrease in LDL and a 72.1% increase in HDL. Seems pretty great. However, the number of deaths increased by 58% and the number of heart attacks increased by 21%.</p>
<p>A systematic review and meta-analysis<span class="citation" data-cites="Briel2009-yo"><sup>19</sup></span> published in the BMJ a few years later concluded the following after pooling studies that focused on interventions that primarily increased HDL and interventions that primarily decreased LDL,</p>
<blockquote class="blockquote">
<p>“Available data suggest that simply increasing the amount of circulating high-density lipoprotein cholesterol does not reduce the risk of coronary heart disease events, coronary heart disease deaths, or total deaths. The results support reduction in low-density lipoprotein cholesterol as the primary goal for lipid modifying interventions.”</p>
</blockquote>
<p>Svensson<span class="citation" data-cites="Svensson2013-vq"><sup>20</sup></span> provides us with a very lovely table showing other scenarios for which a drug had a favorable effect on a surrogate marker but had a negative impact on the clinical outcome.</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700145/Site/Surrogates.png" alt="Surrogate endpoints and how they've conflicted with clinical endpoints." style="width:80%"></p>
<hr>
<p>What does this tell us? That focusing only on improving surrogate markers is not a very good idea if there is not much concordance between trials that focus on surrogates and trials that focus on hard endpoints. Until we’ve established a robust causal link between a surrogate marker and a hard endpoint, we shouldn’t be seduced by surrogates.</p>
<hr>
<section id="references" class="level3">



<!-- -->


</section>
</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><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">
<div id="ref-hulley2007" class="csl-entry">
<div class="csl-left-margin">1. </div><div class="csl-right-inline">Hulley SB. <em>Designing <span>Clinical</span> <span>Research</span></em>. Lippincott Williams &amp; Wilkins; 2007.</div>
</div>
<div id="ref-bray2016w" class="csl-entry">
<div class="csl-left-margin">2. </div><div class="csl-right-inline">Bray C, Bell LN, Liang H, et al. Erythrocyte <span>Sedimentation</span> <span>Rate</span> and <span>C</span>-<span>Reactive</span> <span>Protein</span> <span>Measurements</span> and <span>Their</span> <span>Relevance</span> in <span>Clinical</span> <span>Medicine</span>. <em>WMJ : official publication of the State Medical Society of Wisconsin</em>. 2016;115(6):317-321.</div>
</div>
<div id="ref-chew2012jets" class="csl-entry">
<div class="csl-left-margin">3. </div><div class="csl-right-inline">Chew KS. What’s new in <span>Emergencies</span> <span>Trauma</span> and <span>Shock</span>? <span>C</span>-<span>Reactive</span> protein as a potential clinical biomarker for influenza infection: <span>More</span> questions than answers. <em>Journal of Emergencies, Trauma, and Shock</em>. 2012;5(2):115. doi:<a href="https://doi.org/10.4103/0974-2700.96477">10.4103/0974-2700.96477</a></div>
</div>
<div id="ref-pepys2003jci" class="csl-entry">
<div class="csl-left-margin">4. </div><div class="csl-right-inline">Pepys MB, Hirschfield GM. C-reactive protein: <span>A</span> critical update. <em>Journal of Clinical Investigation</em>. 2003;111(12):1805-1812. doi:<a href="https://doi.org/10.1172/JCI18921">10.1172/JCI18921</a></div>
</div>
<div id="ref-Frangogiannis2012-fo" class="csl-entry">
<div class="csl-left-margin">5. </div><div class="csl-right-inline">Frangogiannis NG. Regulation of the inflammatory response in cardiac repair. <em>Circulation Research</em>. 2012;110(1):159-173. doi:<a href="https://doi.org/10.1161/CIRCRESAHA.111.243162">10.1161/CIRCRESAHA.111.243162</a></div>
</div>
<div id="ref-Hansson2005-wz" class="csl-entry">
<div class="csl-left-margin">6. </div><div class="csl-right-inline">Hansson GK. Inflammation, atherosclerosis, and coronary artery disease. <em>New England Journal of Medicine</em>. 2005;352(16):1685-1695. doi:<a href="https://doi.org/10.1056/NEJMra043430">10.1056/NEJMra043430</a></div>
</div>
<div id="ref-Libby2006-ch" class="csl-entry">
<div class="csl-left-margin">7. </div><div class="csl-right-inline">Libby P. Inflammation and cardiovascular disease mechanisms. <em>American Journal of Clinical Nutrition</em>. 2006;83(2):456S-460S. doi:<a href="https://doi.org/10.1093/ajcn/83.2.456S">10.1093/ajcn/83.2.456S</a></div>
</div>
<div id="ref-Ruparelia2017-nf" class="csl-entry">
<div class="csl-left-margin">8. </div><div class="csl-right-inline">Ruparelia N, Chai JT, Fisher EA, Choudhury RP. Inflammatory processes in cardiovascular disease: <span>A</span> route to targeted therapies. <em>Nature Reviews Cardiology</em>. 2017;14(3):133-144. doi:<a href="https://doi.org/10.1038/nrcardio.2016.185">10.1038/nrcardio.2016.185</a></div>
</div>
<div id="ref-Cholesterol_Treatment_Trialists_CTT_Collaboration2015-ni" class="csl-entry">
<div class="csl-left-margin">9. </div><div class="csl-right-inline">Cholesterol Treatment Trialists’ (CTT) Collaboration, Fulcher J, O’Connell R, et al. Efficacy and safety of <span>LDL</span>-<span>Lowering</span> therapy among men and women: <span>Meta</span>-analysis of individual data from 174,000 participants in 27 randomised trials. <em>Lancet (London, England)</em>. 2015;385(9976):1397-1405. doi:<a href="https://doi.org/10.1016/S0140-6736(14)61368-4">10.1016/S0140-6736(14)61368-4</a></div>
</div>
<div id="ref-Taylor2013-te" class="csl-entry">
<div class="csl-left-margin">10. </div><div class="csl-right-inline">Taylor F, Huffman MD, Macedo AF, et al. Statins for the primary prevention of cardiovascular disease. <em>Cochrane Database Syst Rev</em>. 2013;(1):CD004816. doi:<a href="https://doi.org/10.1002/14651858.CD004816.pub5">10.1002/14651858.CD004816.pub5</a></div>
</div>
<div id="ref-assmann1996a" class="csl-entry">
<div class="csl-left-margin">11. </div><div class="csl-right-inline">Assmann G, Schulte H, Eckardstein A von, Huang Y. High-density lipoprotein cholesterol as a predictor of coronary heart disease risk. <span>The</span> <span>PROCAM</span> experience and pathophysiological implications for reverse cholesterol transport. <em>Atherosclerosis</em>. 1996;124 Suppl:S11-20.</div>
</div>
<div id="ref-Curb2004-ee" class="csl-entry">
<div class="csl-left-margin">12. </div><div class="csl-right-inline">Curb JD, Abbott RD, Rodriguez BL, et al. A prospective study of <span>HDL</span>-<span>C</span> and cholesteryl ester transfer protein gene mutations and the risk of coronary heart disease in the elderly. <em>Journal of Lipid Research</em>. 2004;45(5):948-953. doi:<a href="https://doi.org/10.1194/jlr.M300520-JLR200">10.1194/jlr.M300520-JLR200</a></div>
</div>
<div id="ref-Gordon1977-le" class="csl-entry">
<div class="csl-left-margin">13. </div><div class="csl-right-inline">Gordon T, Castelli WP, Hjortland MC, Kannel WB, Dawber TR. High density lipoprotein as a protective factor against coronary heart disease. <span>The</span> <span>Framingham</span> <span>Study</span>. <em>American Journal of Medicine</em>. 1977;62(5):707-714.</div>
</div>
<div id="ref-Gordon1989-mc" class="csl-entry">
<div class="csl-left-margin">14. </div><div class="csl-right-inline">Gordon DJ, Probstfield JL, Garrison RJ, et al. High-density lipoprotein cholesterol and cardiovascular disease. <span>Four</span> prospective <span>American</span> studies. <em>Circulation</em>. 1989;79(1):8-15.</div>
</div>
<div id="ref-Rahilly-Tierney2011-ox" class="csl-entry">
<div class="csl-left-margin">15. </div><div class="csl-right-inline">Rahilly-Tierney CR, Spiro A 3rd, Vokonas P, Gaziano JM. Relation between high-density lipoprotein cholesterol and survival to age 85 years in men (from the <span>VA</span> normative aging study). <em>American Journal of Cardiology</em>. 2011;107(8):1173-1177. doi:<a href="https://doi.org/10.1016/j.amjcard.2010.12.015">10.1016/j.amjcard.2010.12.015</a></div>
</div>
<div id="ref-Sharrett2001-su" class="csl-entry">
<div class="csl-left-margin">16. </div><div class="csl-right-inline">Sharrett AR, Ballantyne CM, Coady SA, et al. Coronary heart disease prediction from lipoprotein cholesterol levels, triglycerides, lipoprotein(a), apolipoproteins <span>A</span>-<span>I</span> and <span>B</span>, and <span>HDL</span> density subfractions: <span>The</span> <span>Atherosclerosis</span> <span>Risk</span> in <span>Communities</span> (<span>ARIC</span>) <span>Study</span>. <em>Circulation</em>. 2001;104(10):1108-1113.</div>
</div>
<div id="ref-Turner1998-gv" class="csl-entry">
<div class="csl-left-margin">17. </div><div class="csl-right-inline">Turner RC, Millns H, Neil HA, et al. Risk factors for coronary artery disease in non-insulin dependent diabetes mellitus: <span>United</span> <span>Kingdom</span> <span>Prospective</span> <span>Diabetes</span> <span>Study</span> (<span>UKPDS</span>: 23). <em>BMJ (Clinical research ed)</em>. 1998;316(7134):823-828.</div>
</div>
<div id="ref-Barter2007-if" class="csl-entry">
<div class="csl-left-margin">18. </div><div class="csl-right-inline">Barter PJ, Caulfield M, Eriksson M, et al. Effects of torcetrapib in patients at high risk for coronary events. <em>New England Journal of Medicine</em>. 2007;357(21):2109-2122. doi:<a href="https://doi.org/10.1056/NEJMoa0706628">10.1056/NEJMoa0706628</a></div>
</div>
<div id="ref-Briel2009-yo" class="csl-entry">
<div class="csl-left-margin">19. </div><div class="csl-right-inline">Briel M, Ferreira-Gonzalez I, You JJ, et al. Association between change in high density lipoprotein cholesterol and cardiovascular disease morbidity and mortality: <span>Systematic</span> review and meta-regression analysis. <em>BMJ (Clinical research ed)</em>. 2009;338:b92. doi:<a href="https://doi.org/10.1136/bmj.b92">10.1136/bmj.b92</a></div>
</div>
<div id="ref-Svensson2013-vq" class="csl-entry">
<div class="csl-left-margin">20. </div><div class="csl-right-inline">Svensson S, Menkes DB, Lexchin J. Surrogate outcomes in clinical trials: <span>A</span> cautionary tale. <em>JAMA Intern Med</em>. 2013;173(8):611-612. doi:<a href="https://doi.org/10.1001/jamainternmed.2013.3037">10.1001/jamainternmed.2013.3037</a></div>
</div>
</div></section></div> ]]></description>
  <category>medicine</category>
  <guid>https://lesslikely.com/medicine/seductive-surrogates.html</guid>
  <pubDate>Tue, 06 Jan 2026 05:00:00 GMT</pubDate>
  <media:content url="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700145/Site/Surrogates.png" medium="image" type="image/png"/>
</item>
<item>
  <title>How Did We Figure Out Smoking Causes Lung Cancer?</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/medicine/smoking-and-lung-cancer.html</link>
  <description><![CDATA[ 




<p>Proving a cause and effect relationship isn’t easy. Causality is complex, and there are thousands of <a href="https://plato.stanford.edu/entries/kant-hume-causality/">philosophical</a> and <a href="https://link.springer.com/chapter/10.1007%2F978-1-4612-2404-4_3">mathematical texts</a> on it that are beyond my understanding. However, I do understand enough to discuss how we arrive at cause and effect relationships in the sciences.</p>
<p>One of the first things drilled into students in a research methods course is that correlation does not equal causation. It’s also taught in a cult-like way that one of the best ways to prove causality in the health and social sciences is with a perfectly designed <a href="https://www.ncbi.nlm.nih.gov/pubmedhealth/PMHT0025811/">randomized controlled trial</a> (RCT). Why?</p>
<p>A few reasons:</p>
<ul>
<li><p>you can compare what you’re testing to a control, to see if it’s better or worseand if the effects can be ruled out by the placebo or <a href="https://en.wikipedia.org/wiki/Nocebo">nocebo effect</a>, or through phenomena like <a href="../statistics/control-group-effects">regression towards the mean</a></p></li>
<li><p>you break the spurious links between <a href="https://en.wikipedia.org/wiki/Confounding">confounders</a> through <a href="../statistics/equal-covariates">randomization (reducing selection bias</a>)</p></li>
<li><p>and you have the sequence of events mapped out (addressing temporal problems, so you know which variable came first and caused the other)</p></li>
</ul>
<p>These are difficult to do with observational/epidemiological studies. There are always some spurious links that have nothing to do with the phenomena of interest as seen below:</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700110/Site/chart.jpg" alt="Spurious associations such as the number of letters in the winning word of the spelling bee and the number of people killed by venomous spiders"></p>
<hr>
<p>So perfect RCTs are believed to be one of the best ways to prove causality, and at some point in history, we determined that smoking causes lung cancer in humans. Does that mean we recruited participants, randomized them to a group, and made them smoke?</p>
<p>Nope. Although several unethical experiments on humans have been carried out in the past, this was not one of them. Institutional Review Boards wouldn’t allow an investigation like that, where participants could potentially be harmed to such a large degree.</p>
<p>Wait, if there are no RCTs testing the effects of cigarettes, then how did we determine that <em>smoking causes lung cancer</em>? In the mid-1900s, two researchers (Richard Doll and Austin Bradford Hill) <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC437141/">produced data</a> showing that smoking frequency was <strong>strongly</strong> correlated with lung cancer incidence. The data were compelling. Look at the numbers below.</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700109/Site/britishdoctors.png" alt="Data from the British Doctor's study"></p>
<hr>
<p>But again, these were associations from observational studies (case controls), not experiments. What if people who had lung cancer also had genes that made them more likely to smoke? What if they happened to be drawn to smoking? You couldn’t dismiss these possibilities with correlations.</p>
<p>This is what legendary statistician, empiricist, and <strong>potato scientist</strong>, <a href="../statistics/classical-lehmann">Ronald A. Fisher</a>, exclaimed at the time.</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1559517576/Site/fisher_old.jpg" alt="Picture of Ronald A. Fisher" style="width:40%"></p>
<hr>
<p>Fisher was often a critic of these findings and of the surgeon general’s report, that smoking causes lung cancer. He claimed that these conclusions were purely correlational and it’s also what tobacco companies exclaimed to defend their highly profitable product. And they weren’t wrong.</p>
<p>Alright, we’re in a dilemma. Perfectly designed randomized trials are the one of best ways to establish causality, but you can’t conduct randomized experiments to see whether smoking causes cancer, because it’s unethical, so you’re limited to epidemiological/observational studies.</p>
<p>So researchers have to work with what they have. And that’s what they did in the mid-1900s. There were already <a href="http://tobaccocontrol.bmj.com/content/21/2/87">suspicions</a> at the time, that consumption of tobacco products caused harmful gene mutations from studies carried out in animal models. Specific compounds found in tobacco products had also been established as carcinogens decades before the surgeon general’s report, and researchers were already open to the idea that smoking wasn’t the greatest habit. Unfortunately, rigorous human data were missing.</p>
<p>The results from the <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC437141/">British Doctor’s Study</a> (the study conducted by Richard Doll and Austin Bradford Hill) was the nail in the coffin because it provided evidence (although correlational) that smoking frequency increased the incidence rates of lung cancer.</p>
<p>One of the researchers on that original paper (Austin Bradford Hill) went on to establish the <a href="../statistics/bradford-hill-criteria">Bradford Hill Criteria</a>, a set of viewpoints that Hill had discussed in a speech that he believed helped establish the link between smoking and lung cancer.</p>
<p>Interestingly enough, he was also a pioneer of the randomized controlled trial!</p>
<hr>
<center>
<img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700109/Site/bradfordhill.jpg" alt="Picture of Austin Bradford Hill" style="width:30%">
</center>
<hr>
<p>In Hill’s speech, he exclaimed that one could potentially arrive at causality from nine viewpoints:</p>
<ol type="1">
<li><p>The strength of the association</p></li>
<li><p>Consistency</p></li>
<li><p>Specificity</p></li>
<li><p>Temporality</p></li>
<li><p>Dose dependency</p></li>
<li><p>Biological mechanism</p></li>
<li><p>Coherence</p></li>
<li><p>Experiment</p></li>
<li><p>Analogy</p></li>
</ol>
<p>The relationship between smoking and lung cancer fit many of these scenarios. There was a biological mechanism (DNA damage from carcinogens in tobacco products), the effect sizes of the associations were large, there was a dose-dependent relationship (groups that smoked more had a higher incidence of lung cancer), there was consistency amongst the data observed, and there was coherence ( multiple lines of evidence to support a relationship: animal models, cellular biology, molecular, and epidemiological, etc.). <a href="https://www.nature.com/articles/d41586-018-01023-3">Robust research</a> needs multiple lines of evidence.</p>
<p>Even without experiments, the evidence from multiple lines was <strong>overwhelming</strong>.</p>
<p>It’s still worth mentioning that epidemiology has its limits. Temporality is often a problem because it’s hard to figure out which variable caused the other, and not all confounding variables can be adjusted for (<a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2744485/">over adjustment bias</a> can be a problem and there will always be residual confounding), but if there are multiple lines of evidence to suggest a relationship, then there could be one.</p>


<!-- -->


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>medicine</category>
  <guid>https://lesslikely.com/medicine/smoking-and-lung-cancer.html</guid>
  <pubDate>Tue, 06 Jan 2026 05:00:00 GMT</pubDate>
  <media:content url="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700110/Site/cigarettes.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>The Rise, Fall, and Rise Again of Fish Oil?</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/medicine/vascepa-reduce-it.html</link>
  <description><![CDATA[ 




<p>With the exception of this past week, it hasn’t been a very good year for fish oil. In early 2018, a large meta-analysis and systematic review of several randomized trials was <a href="https://jamanetwork.com/journals/jamacardiology/fullarticle/2670752">published in <em>JAMA</em></a>.</p>
<p>This large pooled analysis (77,000 + participants) assessed the impact of supplementing fish oil on cardiovascular disease events and found that there was no statistically significant effect (p=.10). The relative risks (RR) and coverage of the confidence intervals (CI) also suggested a very small effect (RR: <strong>0.97,</strong> 95% CI: <strong>0.93</strong> to <strong>1.01</strong>) for any major vascular event.</p>
<p>A few months later Cochrane came out with their own <a href="https://doi.org/10.1002/14651858.CD003177.pub3">systematic review and meta-analysis</a> which was more comprehensive (79 studies, <strong>112,000</strong> participants) than the <em>JAMA</em> meta-analysis but also came to very similar conclusions of there being a small effect for several outcomes.</p>
<p>Cochrane Primary Outcomes Results:</p>
<ul>
<li><p>All-Cause Mortality: (RR: <strong>0.98</strong>, 95% CI: <strong>0.93</strong> to <strong>1.03</strong>)</p></li>
<li><p>Cardiovascular Mortality: (RR: <strong>0.95</strong>, 95% CI: <strong>0.87</strong> to <strong>1.03</strong>)</p></li>
<li><p>Combined Cardiovascular Events: (RR: <strong>0.99</strong>, 95% CI: <strong>0.94</strong> to <strong>1.04</strong>)</p></li>
<li><p>Coronary Heart Mortality: (RR: <strong>0.93</strong>, 95% CI: <strong>0.79</strong> to <strong>1.09</strong>)</p></li>
<li><p>Coronary Heart Disease Events: (RR: <strong>0.93</strong>, 95% CI: <strong>0.88</strong> to <strong>0.97</strong>)</p></li>
<li><p>Stroke: (RR: <strong>1.06</strong>, 95% CI: <strong>0.96</strong> to <strong>1.16</strong>)</p></li>
<li><p>Arrhythmia: (RR: <strong>0.97</strong>, 95% CI: <strong>0.90</strong> to <strong>1.05</strong>)</p></li>
</ul>
<p>At this time, it wasn’t looking particularly good for fish oil. Science-Based Medicine wrote an article titled, “<a href="https://sciencebasedmedicine.org/no-benefit-from-fish-oil/">No Benefit from Fish Oil,</a>” which largely suggested that fish oil had little utility based on the 2018 meta-analyses.</p>
<p>While these two recent meta-analyses of fish oil were very comprehensive, they weren’t able to include the results of two trials (<a href="https://clinicaltrials.gov/ct2/show/NCT02104817">STRENGTH</a> &amp; <a href="https://clinicaltrials.gov/ct2/show/NCT01492361">REDUCE-IT</a>) that were using extremely high doses of fish oil (3-4 g/d) because those trials were still ongoing, and the data were not available.</p>
<p>A few days ago, Amarin (the manufacturer of the patented, high-dose, purified EPA product, Vascepa) <a href="https://investor.amarincorp.com/news-releases/news-release-details/reduce-ittm-cardiovascular-outcomes-study-vascepar-icosapent">made an announcement</a> that the results from the REDUCE-IT trial suggested a fairly notable reduction in CVD events (25% reduction in the relative risk, apparently, RR: <strong>0.75</strong>, p&lt;0.001).</p>
<p>Several reports of this announcement declared it as a major event in the field of cardiology, comparable to the significance of statins. Of course, many folks (including myself) are still skeptical and will remain so until the results are published.</p>
<p>For those who are unaware, fish oil has had one of the most interesting histories of all nutritional supplements that are available today. I’ve used this timeline before in a <a href="../medicine/fish-oil-cvd">previous blog post</a> but have updated it to include the newer events/studies.</p>
<hr>
<section id="a-brief-timeline-of-fish-oil" class="level2">
<h2 class="anchored" data-anchor-id="a-brief-timeline-of-fish-oil">A Brief Timeline of Fish Oil</h2>
<ul>
<li><p><strong>1970s</strong> | <a href="https://www.ncbi.nlm.nih.gov/pubmed/7435433">A group of explorers</a> noticed that people who consumed fish also had lower incidences of heart disease.</p></li>
<li><p><strong>1980s</strong>-<strong>1990s</strong> | <a href="https://www.ncbi.nlm.nih.gov/pubmed/3990713?access_num=3990713&amp;link_type=MED&amp;dopt=Abstract">Early</a> observational <a href="https://www.ncbi.nlm.nih.gov/pubmed/9091800?access_num=9091800&amp;link_type=MED&amp;dopt=Abstract">studies</a> also saw a connection between fish consumption and heart disease risk</p></li>
<li><p><strong>1990s</strong> | <a href="https://www.ncbi.nlm.nih.gov/pubmed/9310278?access_num=9310278&amp;link_type=MED&amp;dopt=Abstract">A few</a> randomized trials <a href="https://www.ncbi.nlm.nih.gov/pubmed/10465168?access_num=10465168&amp;link_type=MED&amp;dopt=Abstract">were</a> conducted to see the effects of fish oil supplementation and CVD outcomes</p></li>
<li><p><strong>2002</strong> | The American Heart Association put out <a href="http://circ.ahajournals.org/content/106/21/2747?ijkey=a0bd0a11dda35f2aa109c24a01266ea89e3d0121&amp;keytype2=tf_ipsecsha">a statement</a> suggesting that fish oil supplementation was beneficial for fatal outcomes</p></li>
<li><p><strong>2002</strong> - <strong>2016</strong> | Several <a href="http://www.thelancet.com/article/S0140-6736(07)60527-3/abstract">randomized trials</a> and <a href="https://www.ncbi.nlm.nih.gov/pubmed/15495044">systematic reviews</a> found inconsistent evidence for the effects of fish oil supplementation and CVD outcomes</p></li>
<li><p><strong>2016</strong> | The American Heart Association creates <a href="http://circ.ahajournals.org/content/135/15/e867.long">a scientific advisory group</a> to look at all the evidence and concludes that despite the controversy, there was a small benefit from fish oil and it could be worth it for people who had a history of CVD events.</p></li>
<li><p><strong>2018</strong> | <a href="https://www.ncbi.nlm.nih.gov/pubmed/29387889">Large meta-analysis</a> published in <em><strong>JAMA</strong></em> with 77,000 + participants found no benefit from fish oil supplementation on real clinical endpoints.</p></li>
<li><p><strong>Mid - 2018</strong> | Most <a href="https://www.cochranelibrary.com/cdsr/doi/10.1002/14651858.CD003177.pub3/full">comprehensive meta-analysis</a> and systematic review with 112,000 participants by Cochrane finds very small benefits to several CVD-related outcomes.</p></li>
<li><p><strong>Late 2018</strong> | <a href="https://investor.amarincorp.com/news-releases/news-release-details/reduce-ittm-cardiovascular-outcomes-study-vascepar-icosapent">Announcement</a> by the manufacturer of <a href="https://www.vascepa.com/">Vascepa</a> exclaiming that high-doses of fish oil in the REDUCE-IT trial had a large effect (25% reduction) on CVD outcomes.</p></li>
</ul>
<hr>
<p>Fish oil was accompanied by a lot of hype in the early days and little evidence, but eventually, like most things, it took a beating once several research groups started prodding the existing evidence.</p>
<p>The results of this trial (when they are presented in November at the AHA conference) and when they are published in a peer-reviewed journal, may potentially change the minds of skeptics everywhere.</p>
<p>That’s why I thought it would be a good time to review the preregistration protocol of the REDUCE-IT trial on <a href="https://clinicaltrials.gov/ct2/show/study/NCT01492361">ClinicalTrials.gov</a> and a <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5396348/">detailed paper</a> that describes the rationale behind the study design. Let’s get into it.</p>
<p>So very clearly, the authors state what the study here is doing,</p>
<blockquote class="blockquote">
<p>“AMR101 (icosapent ethyl [ethyl-EPA]) is a highly purified ethyl ester of eicosapentaenoic acid (EPA) being developed by Amarin Pharma Inc.&nbsp;for the treatment of hypertriglyceridemia.</p>
<p>The purpose of this study is to evaluate whether this drug, combined with a statin therapy, will be superior to the statin therapy alone, when used as a prevention in reducing long-term cardiovascular events in high-risk patients with mixed dyslipidemia.”</p>
</blockquote>
<p>Comparing statins + highly purified, high doses of EPA to statins alone. Why are they using such high doses? The authors explain here,</p>
<blockquote class="blockquote">
<p>“It is worth noting that the promising results from JELIS occurred with a high‐purity EPA preparation dosed at 1.8 g/d in a Japanese population, for whom the baseline EPA levels are higher than in western populations due to greater dietary intake of marine omega‐3 fatty acids.</p>
<p>Icosapent ethyl 12‐week dosing at 4 g/d in a high‐risk population similar to that within the Reduction of Cardiovascular Events with Icosapent Ethyl–Intervention Trial (REDUCE‐IT) who had persistent elevations of TG after treatment with statins resulted in significant reductions in TG and atherogenic lipoproteins, as well as comparable plasma EPA levels as the 1.8 g/d dosing group in JELIS.</p>
<p>Therefore, a dose of 4 g/d was selected as the dose for further study. In this context, REDUCE‐IT was designed to determine if treatment with icosapent ethyl 4 g/d vs placebo would reduce ischemic events in patients at increased CV risk already being treated with statins.”</p>
</blockquote>
<p>Also “worth noting” that the <a href="https://www.ncbi.nlm.nih.gov/pubmed/17398308">JELIS</a> trial was included in both meta-analyses mentioned at the beginning of the blog post.</p>
<p>The primary outcome is a composite endpoint that consists of CV death, MI, stroke, coronary revascularization, and hospitalization for unstable angina. Whenever I hear composite endpoint, I often become skeptical because I’ve seen composite endpoints abused or misused in several ways, resulting in very misleading results. There was a very nice post on composite endpoints by Hilda Bastian <a href="https://statistically-funny.blogspot.com/2015/02/lets-play-outcome-mash-up-clinical.html">here</a>.</p>
<p>The study (REDUCE-IT) enrolled 8,000 participants and began in 2011 and ended in 2018.</p>
<p>Why 8,000 participants?</p>
<p>The authors explain here,</p>
<blockquote class="blockquote">
<p>“The sample‐size calculation was based on a hazard ratio assumption of 0.85. Therefore, 1612 events would be required to have approximately 90% power with a 1‐sided α‐level of 2.5% and with 2 interim analyses. This results in a total target sample size of 7990 patients.</p>
<p>Approximately 70% of randomized patients were to be in CV risk stratum 1 (established CVD) and approximately 30% of randomized patients were to be in CV risk stratum 2 (high‐risk primary prevention defined by diabetes mellitus and other risk factors). Randomization was stratified by CV risk strata, ezetimibe use, and by geographical region.”</p>
</blockquote>
<p>The design power calculations seem like they were based on very optimistic expectations of the effect size, and apparently, justifiably so!</p>
<p>A bit unfortunate that there is no mention anywhere of what statistical analyses they planned on doing exactly.</p>
<p>In order for participants to be eligible for the trial:</p>
<ul>
<li><p>they had to be over the age of 45</p></li>
<li><p>have high levels of triglycerides (hypertriglyceridemia)</p></li>
<li><p>been on statins for at least a month</p></li>
<li><p>they had to have a history of heart disease</p></li>
</ul>
<p>There’s a bunch of exclusion criteria too that I don’t really feel the need to go over, but you can see them listed out on the registry.</p>
<p>Also, worth mentioning of course that the trial is funded by Amarin, AKA the manufacturer of Vascepa.</p>
<p>Even though my title mentions “<strong>fish oil</strong>” it really is important to point out that this is NOT the average fish oil supplement that you’ll get over the counter. It’s a highly purified substance, that’s currently being prescribed by doctors in high dosages for hypertriglyceridemia. It is a drug.</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700147/Site/Vascepa-v-Common.png" alt="Vascepa versus normal fish oil" style="width:70%"></p>
<hr>
<p>An extremely expensive one (<a href="https://www.singlecare.com/prescription/vascepa">$250+ for a 30 day supply…</a> ) that most insurance companies will not cover unless your blood tests show an indication of <a href="https://vascepasavings.com/">high triglycerides</a>.</p>
<p>So, while the substance technically is fish oil, a very purified, high-dose version of it, the results of the REDUCE-IT trial are not evidence of your average fish oil supplement having these same effects.</p>
<p>I look forward to hearing about the results of this study in November.</p>
<p><strong>Edit</strong>: I’ve covered that study in this <a href="../medicine/reduce-it">blog post</a>.</p>


<!-- -->

</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>medicine</category>
  <guid>https://lesslikely.com/medicine/vascepa-reduce-it.html</guid>
  <pubDate>Tue, 06 Jan 2026 05:00:00 GMT</pubDate>
  <media:content url="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700147/Site/Vascepa-v-Common.png" medium="image" type="image/png"/>
</item>
<item>
  <title>Revisiting Eggs and Dietary Cholesterol</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/nutrition/revisiting-eggs.html</link>
  <description><![CDATA[ 




<p>Buckle up, folks. This is going to be a long one. In this post, I want to discuss three main things:</p>
<ul>
<li><a href="../nutrition/eggs-cholesterol/#a-summary-of-the-jama-study">the recent study published in <em>JAMA</em> about eggs.</a>
<ul>
<li><a href="../nutrition/eggs-cholesterol/#a-summary-of-the-jama-study">a summary of the methods and results.</a></li>
<li><a href="../nutrition/eggs-cholesterol/#how-did-the-media-respond">how the media reported the results.</a></li>
<li><a href="../nutrition/eggs-cholesterol/#how-reliable-are-the-measurements-and-analyses">discussion of measurement and analyses.</a></li>
</ul></li>
<li><a href="../nutrition/eggs-cholesterol/#does-dietary-cholesterol-impact-serum-cholesterol">whether dietary cholesterol impacts serum cholesterol.</a>
<ul>
<li><a href="../nutrition/eggs-cholesterol/#brief-timeline-of-dietary-cholesterol">a brief history of cholesterol research.</a></li>
<li><a href="../nutrition/eggs-cholesterol/#what-do-reviews-of-randomized-trials-say">what the most current research indicates.</a></li>
</ul></li>
<li><a href="../nutrition/eggs-cholesterol/#wait-so-should-we-be-worried-about-eggs">whether we should be worried about eggs.</a></li>
</ul>
<p>Let’s get right into it.</p>
<hr>
<section id="a-summary-of-the-jama-study" class="level2">
<h2 class="anchored" data-anchor-id="a-summary-of-the-jama-study">A Summary of the <em>JAMA</em> Study</h2>
<p>Last week, a nutritional epidemiological study (from now on nutri epi) published in <em>JAMA</em> posited that egg consumption was associated with an increased risk of cardiovascular disease incidence.<span class="citation" data-cites="zhongAssociationsDietaryCholesterol2019"><sup>1</sup></span> The results gained significant coverage from the media.</p>
<p>With that coverage came the usual criticism of “<em>correlation not being causation</em>,” and how nutri epi studies produce findings that are often contradicted by randomized trials, etc. Unlike many of these <em>surface-level</em> criticisms, I want to dive a little deeper into the findings of this study and the utility and limitations of studies like this. But first, a quick summary of the study.</p>
</section>
<section id="whos-being-studied" class="level2">
<h2 class="anchored" data-anchor-id="whos-being-studied">Who’s Being Studied?</h2>
<p>This study included data from <strong>six prospective cohorts</strong> and had a total sample size of <strong>29,615 adults</strong>. That’s a lot of people. Those who follow nutrition studies should be familiar with many of the cohorts included such as:</p>
<ul>
<li>the Atherosclerosis Risk in Communities (ARIC) Study</li>
<li>the Coronary Artery Risk Development in Young Adults (CARDIA) Study</li>
<li>the Framingham Heart Study (FHS)</li>
<li>the Framingham Offspring Study (FOS)</li>
<li>the Jackson Heart Study (JHS)</li>
<li>the Multi-Ethnic Study of Atherosclerosis (MESA)</li>
</ul>
<p>Data collection started in early 1985 and halted in the summer of 2016 (nearly <strong>31 years of data</strong>). The project was involved in answering the question of whether dietary cholesterol was associated with cardiovascular disease incidence.</p>
</section>
<section id="what-and-how-were-the-data-collected" class="level2">
<h2 class="anchored" data-anchor-id="what-and-how-were-the-data-collected">What and How Were the Data Collected?</h2>
<p>So how were dietary data collected? The authors give a very brief description in the methods,</p>
<blockquote class="blockquote">
<p>Using a standardized protocol and data dictionary, diet data were harmonized cohort by cohort. Briefly, <strong>consumption frequencies were converted into estimated number per day</strong> using the middle value (eg, 3-4 times per week = 0.5 times per day).</p>
</blockquote>
<p>However, a look at the supplementary files gives us more insight into how the data were collected:</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700113/Site/eggs-ffq.png" alt="A table describing the data collection methods for the six cohorts"></p>
<hr>
<p>So they mainly used various food frequency questionnaires which differed depending on the cohort.</p>
<p>The primary outcomes were…</p>
<hr>
<blockquote class="blockquote">
<p>The primary outcomes were <strong>incident CVD and all-cause mortality</strong>. Incident CVD was a <strong>composite end point</strong> of fatal and nonfatal coronary heart disease (0), stroke, heart failure, and CVD death from other causes.</p>
</blockquote>
<hr>
<p>Here are some of the covariates they collected data for</p>
<hr>
<blockquote class="blockquote">
<p>Standardized questionnaires and laboratory protocols were used to collect information on the following variables: <em>age, sex, race/ethnicity, education, lifestyle factors (including smoking, alcohol intake, and physical activity), body mass index (BMI, calculated as weight in kilograms divided by height in meters squared), blood pressure, lipid profile, medication use, and medical conditions</em>.</p>
</blockquote>
<hr>
<p>and what they adjusted for in their three statistical models. Let’s focus mainly on model 2 since they use that as a reference.</p>
<hr>
<blockquote class="blockquote">
<p>Models were sequentially adjusted for age, sex, race/ethnicity (white, black, Hispanic, Chinese), education (&lt;high school, high school, some college or more) (model 1); plus total energy, smoking status (current, former, never), smoking pack-years (0, 0.1-4.9, 5.0-9.9, 10-19.9, 20-29.9, 30-39.9, ≥40), cohort-specific physical activity z score, alcohol intake (gram), use of hormone therapy (y/n) (model 2);</p>
</blockquote>
<hr>
</section>
<section id="what-were-the-results" class="level2">
<h2 class="anchored" data-anchor-id="what-were-the-results">What Were the Results?</h2>
<p>The authors graphed the hazard ratios by the amount of dietary cholesterol consumed per day (mg) for CVD incidence…</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700114/Site/eggs-figure-1.png" alt="Graphed models of the associations of dietary cholesterol intake and CVD incidence"></p>
<hr>
<p>So what were the main results that the authors reported?</p>
<blockquote class="blockquote">
<p>Based on model 2, <strong>each additional 300 mg of dietary cholesterol consumed per day</strong> was significantly associated with higher risk of incident CVD (adjusted HR, <strong>1.17</strong> [95% CI, <strong>1.09-1.26</strong>]; adjusted ARD, <strong>3.24%</strong> [95% CI, <strong>1.39%-5.08%</strong>]; Figure 2A) and all-cause mortality (adjusted HR, <strong>1.18</strong> [95% CI, <strong>1.10-1.26</strong>]; adjusted ARD, <strong>4.43%</strong> [95% CI, <strong>2.51%-6.36%</strong>]; Figure 2B).</p>
</blockquote>
<hr>
<p>So a <strong>17% increase</strong> in the risk of incident CVD where a <strong>9% increase</strong> all the way up to a <strong>26% increase</strong> were reasonably compatible with the data and its assumptions. The results are practically the same for all-cause mortality.</p>
<p>The authors also adjusted for individual foods or combinations of foods to see how the effect deviated with model 2 being used as the reference.</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700114/Site/eggs-figure-2.png" alt="Forest plot of dietary cholesterol and CVD incidence"></p>
<hr>
<ul>
<li><p>For <strong>incident CVD</strong> (shown above), the effect estimate <strong>increased</strong> from <em>17% to 20%</em> when adjusted for <em>eggs alone</em>, and <strong>decreased</strong> to <em>13%</em> when adjusted for <em>eggs, unprocessed red meat, and processed meat</em>.</p></li>
<li><p>For <strong>all-cause mortality</strong> (graph not shown), the effect estimate <strong>dropped</strong> from a <em>17% increase</em> to a <em>13% increase</em> when adjusted for <em>eggs alone</em> and <strong>dropped</strong> to a <em>5% increase</em> when adjusted for <em>eggs, unprocessed red meat, and processed meat</em>.</p></li>
</ul>
<p>Here’s what the authors concluded:</p>
<blockquote class="blockquote">
<p>The current study found that the <strong>significant associations of dietary cholesterol consumption with incident CVD and all-cause mortality were independent of fat amount and quality of the diet</strong>. Further, the significant association between egg consumption and incident CVD was <strong>fully accounted for by the cholesterol content in eggs</strong>…</p>
</blockquote>
<hr>
<blockquote class="blockquote">
<p>Mechanistically, eggs and processed or unprocessed red meat are rich in other nutrients such as choline, iron, carnitine, and added sodium (for processed meat) that have been implicated in CVD risk via different pathways.</p>
</blockquote>
<p>And then they discuss the limitations of their study:</p>
<blockquote class="blockquote">
<p>First, appropriate interpretation of the study findings requires <strong>consideration of measurement error for self-reported diet data</strong>. Further, <strong>this study relied on single measurement of egg and dietary cholesterol consumption</strong>. Exposure misclassification may be of concern, but results were similar when censoring participants at different time points…</p>
<p>…Fifth, generalizing our results to non-US populations requires caution due to different nutrition and food environments and chronic disease epidemiology. Sixth, the <strong>study findings are observational and cannot establish causality</strong>.</p>
</blockquote>
<p>Interestingly enough, right after saying the results cannot establish causality, they write this,</p>
<blockquote class="blockquote">
<p>Among US adults, higher consumption of dietary cholesterol or eggs was significantly associated with higher risk of incident CVD and all-cause mortality in a dose-response manner. <strong>These results should be considered in the development of dietary guidelines and updates.</strong></p>
</blockquote>
<p>Well, I have <em>a lot</em> to say, but let’s first take a look at how the media interpreted and reported these results. For that, we shall consult the Google oracle.</p>
</section>
<section id="how-did-the-media-respond" class="level2">
<h2 class="anchored" data-anchor-id="how-did-the-media-respond">How Did the Media Respond?</h2>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700132/Site/media_eggs.png" alt="The media response to the publication of the JAMA egg study"></p>
<hr>
<p>This is one of my favorite ones.</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700113/Site/eggs_media_reporting.png" alt="Fear mongering headlines about eggs"></p>
<hr>
<p>Okay, now that we’ve done that, we can discuss the measurements and analyses.</p>
</section>
<section id="how-reliable-are-the-measurements-and-analyses" class="level2">
<h2 class="anchored" data-anchor-id="how-reliable-are-the-measurements-and-analyses">How Reliable Are the Measurements and Analyses?</h2>
<p>As the authors mentioned in the methods, and supplementary files, most of the dietary data were collected via a food frequency questionnaire (FFQ). This is important for a couple of reasons, and I’m going to dive a little deeper than the usual <em>“FFQ data are useless”</em>.</p>
<p>FFQ data are known to suffer from serious measurement error, and there is a giant body of literature on this. For example, such data can be prone to classical measurement error (<img src="https://latex.codecogs.com/png.latex?W_%7Bij%7D=X_%7Bi%7D+%20%5Cepsilon_%7Bij%7D">), systematic error, heteroscedastic error, and differential error.</p>
<p>Methods like regression calibration, moment reconstruction, multiple imputation, and graphical methods can be used to help address many of these errors, along with sensitivity analyses. For a more detailed read of this, see <a href="https://onlinelibrary.wiley.com/doi/abs/10.1002/sim.6095">Keogh &amp; White, 2014</a>.<span class="citation" data-cites="keoghToolkitMeasurementError2014"><sup>2</sup></span></p>
<p>Unfortunately, the authors of the <em>JAMA</em> study hardly bothered with this, and merely pointed out in their limitations section that their study was limited by measurement error.</p>
<blockquote class="blockquote">
<p>This study has several limitations. First, appropriate interpretation of the study findings requires <strong>consideration of measurement error for self-reported diet data</strong>. Further, <strong>this study relied on single measurement of egg and dietary cholesterol consumption</strong>. Exposure misclassification may be of concern, but results were similar when censoring participants at different time points…</p>
</blockquote>
<p>This isn’t something to take this lightly given how serious of a problem it is. There have been extensive criticisms published of FFQs with one of the most prominent of reviews stating the following six arguments as to why memory-based questionnaires should not be used.<span class="citation" data-cites="archerControversyDebateMemoryBased2018"><sup>3</sup></span></p>
<ol type="1">
<li>The use of memory-based methods is founded upon two inter-related logical fallacies: a category error and reification</li>
<li>Human memory and recall are not valid instruments for scientific data collection</li>
<li>The measurement errors of memory-based dietary assessment methods are neither quantifiable nor falsifiable; this renders these methods and data pseudoscientific</li>
<li>The post hoc process of pseudoquantification is impermissible and invalid</li>
<li>Memory-based dietary data were repeatedly demonstrated to be physiologically implausible (i.e., meaningless numbers)</li>
<li>The failure to cite or acknowledge contrary evidence and empirical refutations contributed to a fictional discourse on diet-disease relations</li>
</ol>
<p>The authors don’t even believe that the measurement error from memory-based questionnaires can even be addressed! They conclude the following:</p>
<blockquote class="blockquote">
<p>Our conclusion is that nutrition epidemiology is a degenerating research paradigm in which the use of expedient but <strong>nonfalsifiable anecdotal evidence impeded scientific progress</strong> and engendered a fictional discourse on diet-health relations. The continued funding and use of memory-based methods such as Food Frequency Questionnaires and 24-hour dietary interviews is anathema to evidence-based public policy.</p>
<p>Thus, our recommendation is simply that <strong>the use of memory-based methods must stop and all previous articles presenting memory-based methods data and conclusions must be corrected</strong> to include contrary evidence and address the consequences of a half century of pseudoscientific claims.</p>
</blockquote>
<p>Ouch. Those are quite polarizing statements. Some researchers have argued that Archer et al have overstated their case against FFQs, but agree that FFQs are far from perfect.<span class="citation" data-cites="subarAddressingCurrentCriticism2015"><sup>4</sup></span> This discussion isn’t new though. FFQs have been criticized for so long that they’ve spurred parody videos like the one below:</p>
<hr>
<p>Those are some of the issues with the measurements, now onto the analyses (I’ll be using many of the arguments from my <a href="../nutrition/nutritional-epidemiology">nutri epi blog post</a>). Unfortunately, the analytical plans of studies like this are rarely registered in advance, especially because data collection for many of these studies began decades ago, and most of the analyses are often viewed as being “exploratory.” This means that there is a <em>great deal</em> of analytical flexibility in what covariates to include in a model.</p>
<p>Some of the biggest critics of this have been statistician Stan Young and meta-researcher John Ioannidis. Young wrote the following in the journal <em>Significance</em>.<span class="citation" data-cites="youngDemingDataObservational2011"><sup>5</sup></span></p>
<blockquote class="blockquote">
<p>For example, consider the use of linear regression to adjust the risk levels of two treatments to the same background level of risk. There can be many covariates, and each set of covariates can be in or out of the model. <strong>With ten covariates, there are over 1000 possible models.</strong> Consider a maze as a metaphor for modelling (Figure 3).</p>
<figure class="figure">
<img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700169/Site/young_maze.png" alt="Analytical flexibility depicted by attempting to get through a maze" style="width:60%" class="figure-img">
<center>
<figcaption>
The maze of forking paths.
</figcaption>
</center>
</figure>
<p>The red line traces the correct path out of the maze. The path through the maze looks simple, once it is known. Returning to a linear regression model, terms can be put into and taken out of a regression model. <strong>Once you get a p‐value smaller than 0.05, the model can be frozen and the model selection justified</strong> after the fact. It is easy to justify each turn.</p>
</blockquote>
<p>Patel, Burford, and Ioannidis call this flexibility and its impact on the effect size, the <em>“vibration of effects.”</em><span class="citation" data-cites="Patel2015-kk"><sup>6</sup></span> In their study (which I’ve mentioned several times in previous blog posts), they downloaded several variables from the NHANES dataset that were linked to all-cause mortality and were able to substantially change the effect size by including certain covariates and excluding others,</p>
<blockquote class="blockquote">
<p>Ioannidis and colleagues <strong>downloaded 13 variables from the NHANES dataset that were linked to all-cause mortality</strong>, and that had a substantial number of participants associated with each variable (at least 1000 participants and 100 deaths). From those 13 variables, <strong>they were able to produce 8,192 different statistical models that all resulted in different hazard ratios</strong>.</p>
</blockquote>
<p>Their recommendations were to report all possible statistical models from all possible combinations of covariates and to report the median of all these models, rather than selectively reporting a few models. And to note whether there was something called a <em>“Janus effect”</em>, where the effect size would go in both directions.</p>
<blockquote class="blockquote">
<p>In the last pattern, as exemplified by <strong>α-tocopherol</strong>, the estimated HRs can be both greater and less than the null value (HR &gt; 1 and HR ≤ 1) depending on what adjustments were made. <strong>We call this the Janus effect after the two-headed representation of the ancient Roman god.</strong></p>
<p>For α-tocopherol, most of the HR and p-values were concentrated around 1 and non-significance, respectively… <strong>The Janus effect is common</strong>: 131 (31%) of the 417 variables had their 99th percentile HR&gt;1 and their 1st percentile HR&lt;1.</p>
</blockquote>
<p>However, statistician/epidemiologist, Sander Greenland has been a <a href="../uploads/SanderGreenland.pdf">critic of meta-research</a> and epidemiological studies that lack biochemical sophistication and lump several compounds together as if they were the same and behaved the same in the body.</p>
<blockquote class="blockquote">
<p>“For nutrition, <strong>the lack of biochemistry sophistication among the trial designers leads to a lot of dubious and noncomparable studies</strong>, while the meta-analysts and reviewers do a lot of <strong>distortive lumping</strong>, e.g., talking about “vitamin E” as if that were a <strong>single entity</strong>.</p>
<p>A recent review by prominent authors didn’t even notice that almost <strong>all trials used the racemic synthetic mixture, dl-alpha-tocopheryl, (which they misidentify with “alpha tocopherol”)</strong> with vastly diferent and unjustifed dosages, and <strong>which hardly resembles the eight or so natural d-tocopherols or d-tocotrienols that account for dietary intake.</strong>”<span class="citation" data-cites="Patel2015-kk"><sup>6</sup></span></p>
</blockquote>
<hr>
<p>Ioannidis and Young are also prominent critics of the fact that nutri epi studies and randomized trials have poor concordance. For example, in Young’s 2011 paper published in <em>Significance</em> (which Ioannidis cites often), he (Young) states the following,</p>
<blockquote class="blockquote">
<p>We ourselves carried out an informal but comprehensive accounting of 12 randomised clinical trials that tested observational claims – see Table 1. <strong>The 12 clinical trials tested 52 observational claims. They all confirmed no claims in the direction of the observational claims</strong>. We repeat that figure: <strong>0 out of 52</strong>. To put it another way, <strong>100% of the observational claims failed to replicate</strong>.</p>
<p>In fact, <strong>five claims (9.6%) are statistically significant in the clinical trials in the opposite direction</strong> to the observational claim. To us, a false discovery rate of over 80% is potent evidence that the observational study process is not in control. The problem, which has been recognised at least since 1988, is systemic.</p>
</blockquote>
<p>This seems pretty bad. I can agree with Young and Ioannidis that nutri epi studies can often produce much noise given the analytical flexibility and measurement error. However, I’m not particularly convinced by the poor concordance data for two reasons.</p>
<ol type="1">
<li><p>Most RCTs have designs that are likely to be underpowered for an effect size of interest. Contrast this with nutri epi studies which are often enormous and span decades. So fixating on statistical significance with this in mind makes little sense to me.</p></li>
<li><p>Statistical significance has far more utility in studies that have some random mechanism, whether that be random assignment or random sampling. Otherwise, they make little sense to fixate on, especially in nutri epi studies. Greenland, 1990 summarizes this well below.<span class="citation" data-cites="greenlandRandomizationStatisticsCausal1990"><sup>7</sup></span></p></li>
</ol>
<blockquote class="blockquote">
<p><strong>Randomization provides the key link between inferential statistics and causal parameters</strong>. Inferential statistics, such as <strong>P values</strong>, <strong>confidence intervals</strong>, and <strong>likelihood ratios</strong>, <strong>have very limited meaning in causal analysis</strong> when the mechanism of exposure assignment is <strong>largely unknown or is known to be nonrandom</strong>. It is my impression that such statistics are often given a weight of authority appropriate only in randomized studies</p>
</blockquote>
<p>I’m reasonably confident that Greenland has changed his mind since then on the appropriate weight of authority such statistics should be given, even in randomized studies. Especially given the recent <em>Nature</em> commentary he published on the problems with statistical significance and dichotomous thinking.<span class="citation" data-cites="amrheinScientistsRiseStatistical2019"><sup>8</sup></span></p>
<p>In the same 1990 paper, Greenland also points out the problems with several probabilistic arguments that are used to justify classical statistics in areas where the exposure is unknown or unlikely to be random. He proposes some possible solutions:</p>
<blockquote class="blockquote">
<p>In causal analysis of observational data, valid use of inferential statistics as measures of compatibility, conflict, or support depends crucially on randomization assumptions about which we are at best agnostic and more usually doubtful. Among the possible remedies are:</p>
<ul>
<li>Restrain our interpretation of classical statistics by explicating and <strong>criticizing any randomization assumptions</strong> that are necessary for probabilistic interpretations;</li>
<li>train our students and retrain ourselves to <strong>focus on nonprobabilistic interpretations</strong> of inferential statistics;</li>
<li><strong>deemphasize inferential statistics</strong> in favor of <strong>pure data descriptors, such as graphs and tables</strong>;</li>
<li>expand our analytic repertoire to include more elaborate techniques that depend on <strong>assumptions in the “agnostic”</strong> rather than the “doubtful” realm, and <strong>subject the results of these techniques to influence and sensitivity analysis.</strong></li>
</ul>
<p>These are neither mutually exclusive nor exhaustive possibilities, but I think any one of them would constitute an improvement over much of what we have done in the past.</p>
</blockquote>
<hr>
<p>Now, with all of these nuances in mind, how convincing is this observational study that has produced a hazard ratio of <strong>1.17</strong> with a 95% CI ranging from <strong>1.09 - 1.26</strong>? I don’t think it’s that convincing. I’m not saying that dietary cholesterol or eggs don’t impact CVD incidence and serum cholesterol, but just that I don’t find <strong>this</strong> study’s data to be very convincing.</p>
<p><a href="https://www.methodsman.com/blog/eggs-mortality">Perry Wilson</a> also has an interesting argument where he utilized graphical methods to assess the plausibility of the results,</p>
<hr>
</section>
<section id="does-dietary-cholesterol-impact-serum-cholesterol" class="level2">
<h2 class="anchored" data-anchor-id="does-dietary-cholesterol-impact-serum-cholesterol">Does Dietary Cholesterol Impact Serum Cholesterol?</h2>
<p>This has been a very controversial subject ever since dietary cholesterol was first implicated in cardiovascular disease in the 1900s with one of the most famous epidemiological studies being the Seven Countries Study.<span class="citation" data-cites="feinleibSevenCountriesMultivariate1981"><sup>9</sup></span> I’m not going to touch on that study since I wouldn’t be doing it justice, but there’s plenty of reading material out there.</p>
<p>But here’s a very brief timeline of dietary cholesterol:</p>
<hr>
</section>
<section id="brief-timeline-of-dietary-cholesterol" class="level2">
<h2 class="anchored" data-anchor-id="brief-timeline-of-dietary-cholesterol">Brief Timeline of Dietary Cholesterol</h2>
<blockquote class="blockquote">
<ul>
<li><strong>1950s</strong> <strong>|</strong> Dietary cholesterol is implicated in heart disease.<span class="citation" data-cites="duffPathologyAtherosclerosis1951"><sup>10</sup></span></li>
<li><strong>Late 1900s</strong> <strong>|</strong> Seven Countries Study is published.<span class="citation" data-cites="feinleibSevenCountriesMultivariate1981"><sup>9</sup></span></li>
<li><strong>Late 1900s</strong> <strong>|</strong> Metabolic ward experiments find that dietary cholesterol impacts serum cholesterol.<span class="citation" data-cites="clarkeDietaryLipidsBlood1997"><sup>11</sup></span></li>
<li><strong>Late 1900s</strong> <strong>|</strong> Other trials fail to find an effect.<span class="citation" data-cites="bowmanEffectDietaryFat1988a"><sup>12</sup></span></li>
<li><strong>Late 1900s - Early 2000s</strong> <strong>|</strong> Government agencies and medical organization recommend limiting dietary cholesterol.<span class="citation" data-cites="brownawellCholesterolWhereScience2010"><sup>13</sup></span></li>
<li><strong>2013</strong> <strong>|</strong> American Heart Association states that there’s insufficient evidence whether removing cholesterol is beneficial.<span class="citation" data-cites="eckel2013AHAACC2014"><sup>14</sup></span></li>
<li><strong>2015</strong> <strong>|</strong> Dietary guidelines drop arbitrary recommendations on limiting dietary cholesterol, but still recommend little intake.</li>
</ul>
</blockquote>
<hr>
<p>Wow, that can be pretty confusing and frustrating… Wait till you see the next study I talk about.</p>
</section>
<section id="what-do-reviews-of-randomized-trials-say" class="level2">
<h2 class="anchored" data-anchor-id="what-do-reviews-of-randomized-trials-say">What Do Reviews of Randomized Trials Say?</h2>
<p>A few months ago, a <strong>meta-regression of only randomized controlled trials</strong> that were at least two weeks long (and a million other inclusion/exclusion criteria) was published in <em>The American Journal of Clinical Nutrition</em>.<span class="citation" data-cites="Vincent2019-yc"><sup>15</sup></span> This study was interested in assessing the relationship between dietary cholesterol and serum cholesterol. Here are some characteristics of the study:</p>
<ul>
<li>Included <strong>55 randomized trials</strong> (<strong>2,652 subjects</strong>), with 44 being <strong>crossover trials</strong>.</li>
<li>Used <strong>Bayesian methods</strong> with <strong>uninformed priors</strong>.</li>
<li>Used the <strong>Mensink equation</strong> to subtract the impact of fatty acids on cholesterol to isolate the impact of dietary cholesterol better.</li>
<li>Explored both linear and nonlinear models.</li>
</ul>
<p>So what were the results?</p>
<p>The nonlinear models better fit the data than the linear model and at <strong>100 mg/d of dietary cholesterol change</strong>, there was an associated <strong>4.58 mg/dL change in LDL cholesterol</strong>. The <strong>linear model</strong> estimated this change to be <strong>1.90 mg/dL</strong>, which is similar to estimates found by the meta-analysis of metabolic ward studies.<span class="citation" data-cites="clarkeDietaryLipidsBlood1997"><sup>11</sup></span> At 200-400 mg/d of dietary cholesterol change, the nonlinear and linear models had substantial differences in their estimations (see the table below and then the graph).</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700133/Site/makitable.png" alt="Table of changes in LDL associated with dietary cholesterol"></p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700132/Site/makigraph.png" alt="Linear, MM, and Hill models graphed"></p>
<hr>
<p>Wow. So dietary cholesterol does indeed impact serum cholesterol (LDL)! Here’s what the authors write in their conclusion…</p>
<blockquote class="blockquote">
<p>The meta-regression analyses presented herein indicate that, after providing a theoretical control for intakes of SFAs, MUFAs, PUFAs, and when possible, TFAs, <strong>there is a positive, dose-related trend between changes in cholesterol intake and changes in circulating LDL cholesterol</strong>, a finding that is consistent with the published literature.</p>
<p>The nonlinear dose-response shapes (MM and Hill) best fit the data. <strong>For a 100-mg/d increase in dietary cholesterol intake</strong>, circulating <strong>LDL-cholesterol concentrations</strong> are predicted to <strong>increase</strong> by <strong>1.90 mg/dL</strong> (linear model), <strong>4.46 mg/dL</strong> (MM model), or <strong>4.58 mg/dL</strong> (Hill model).</p>
</blockquote>
<p>Then they discuss the practical significance of this.</p>
<blockquote class="blockquote">
<p>The results from these meta-analyses have potential implications for dietary recommendations. For comparison, the equation given by Mensink et al.&nbsp;predicts a change of 1.23 mg/dL for each 1% increase in SFAs in exchange for carbohydrate.</p>
<p>Therefore, based on the nonlinear models, <strong>increasing dietary cholesterol by 100 mg/d</strong> would be predicted to have an effect comparable to that of <strong>increasing dietary SFAs by 3.7%</strong>, and <strong>increasing dietary cholesterol by 200 mg/d</strong> is predicted to be comparable to <strong>increasing dietary SFAs by 5.5%</strong>.</p>
<p><strong>A large egg contains ∼185 mg cholesterol and would therefore be expected to increase the LDL-cholesterol concentration by 6.5 mg/dL</strong> based on the nonlinear models. However, the majority of dietary cholesterol is not attributable to egg intake in the United States, except for individuals in the highest quartile of TC intake.</p>
<p>According to a recent publication reporting dietary sources of cholesterol in US adults aged ≥20 y based on NHANES 2013–2014 data, mean dietary cholesterol intake was 293 mg/d and the <strong>primary dietary cholesterol source in the overall population was meat</strong> (defined as poultry, mixed dishes, red meat, processed meat, and seafood), which <strong>accounted for 42% of dietary cholesterol</strong>.</p>
</blockquote>
</section>
<section id="wait-so-should-we-be-worried-about-eggs" class="level2">
<h2 class="anchored" data-anchor-id="wait-so-should-we-be-worried-about-eggs">Wait, so Should We Be Worried About Eggs?</h2>
<p>I’m going to argue that we probably shouldn’t. The reason is that just because a food contains dietary cholesterol doesn’t mean it will be absorbed efficiently in the gastrointestinal tract. Foods are not homogenous and do not contain the same nutrients, anti-nutrients, and minerals. Consuming eggs in a sitting is not the same as consuming pure dietary cholesterol nor is it the same as consuming other foods high in cholesterol (poultry, red meat, and processed meat).</p>
<p>This also seems to be supported by a few randomized crossover trials that have shown that the cholesterol in eggs doesn’t seem to be well absorbed.<span class="citation" data-cites="kimDietaryCholesterolContained2018a"><sup>16</sup></span> Several other trials have also failed to show an effect on serum cholesterol.<span class="citation" data-cites="bowmanEffectDietaryFat1988a chenowethInfluenceDietaryCholesterol1981 vorsterEggIntakeDoes1992"><sup>12,17,18</sup></span> Is it possible that these trials were just underpowered in the first place? Very possible.</p>
<p>This all needs to be taken into account with the fact that in addition to the randomized trials included in the meta-regression mentioned above,<span class="citation" data-cites="Vincent2019-yc"><sup>15</sup></span> there exists a plethora of metabolic ward studies suggesting an effect of dietary cholesterol on serum cholesterol.<span class="citation" data-cites="clarkeDietaryLipidsBlood1997"><sup>11</sup></span> However, many of the metabolic ward trials included in the prominent meta-analysis by Clarke et al<span class="citation" data-cites="clarkeDietaryLipidsBlood1997"><sup>11</sup></span> were also nonrandomized,</p>
<blockquote class="blockquote">
<p>Solid food diets were assessed in 72 of these reports among 129 groups of subjects in <strong>395 experiments</strong> with various designs (<strong>109 randomised crossover</strong>, <strong>57 randomised</strong> or <strong>matched parallel</strong>, <strong>77 non-randomised Latin square</strong>, and <strong>152 non-randomised sequential</strong>).</p>
</blockquote>
<p>So while there is plenty of evidence suggesting that a diet high in dietary cholesterol impacts serum cholesterol, the evidence to suggest that eggs in particular have this effect seems far less concrete. There also may be a number of nutrients found in eggs that inhibit cholesterol absorption.<span class="citation" data-cites="jeschFoodIngredientsThat2017 kuangImpactEggNutrient2018"><sup>19,20</sup></span> Here are some excerpts from Kuang et al<span class="citation" data-cites="kuangImpactEggNutrient2018"><sup>20</sup></span></p>
<blockquote class="blockquote">
<p>Yang et al.&nbsp;reported that <strong>dietary PUFAs, PC, and SM significantly inhibit the uptake of cholesterol in Caco-2 monolayer</strong>, which may have potential therapeutic effect on reducing cholesterol absorption as functional food ingredients [44, 45]….</p>
</blockquote>
<blockquote class="blockquote">
<p><strong>Ezetimibe reduces the absorption of cholesterol</strong> in the small intestine by inhibiting the activity of NPC1L1 protein [52].</p>
</blockquote>
<blockquote class="blockquote">
<p>Therefore, <strong>consuming eggs may inhibit the intestinal absorption of cholesterol via the phospholipids in eggs.</strong> A fundamental question is how this biological effect is regulated.</p>
</blockquote>
<p>How convincing is this evidence? I’m still not sure. Much of it seems to be very preliminary, but I’m leaning towards the idea that most people probably don’t have to worry about eggs, especially since Americans don’t even get most of their dietary cholesterol from eggs.<span class="citation" data-cites="Vincent2019-yc"><sup>15</sup></span> I don’t find the existing data for eggs (including those from this study) to be convincing. More <em>better</em> research is needed.</p>
<blockquote class="blockquote">
<p>We need <em>less research</em>, <em>better research</em>, and research done for the <em>right reasons</em>.<span class="citation" data-cites="altmanScandalPoorMedical1994"><sup>21</sup></span> - <a href="https://en.wikipedia.org/wiki/Doug_Altman">Doug Altman</a></p>
</blockquote>
<p>See my other articles on nutritional epidemiology:</p>
<ul>
<li><p><a href="../nutrition/nutritional-epidemiology">How Useful Is Nutritional Epidemiology?</a></p></li>
<li><p><a href="../nutrition/moderate-carbohydrate-intake">Is Moderate Carbohydrate Intake the Best?</a></p></li>
<li><p><a href="../nutrition/protein-heart-failure">Does Protein Increase the Risk of Heart Failure?</a></p></li>
</ul>
<hr>
<section id="references" class="level3">



<!-- -->


</section>
</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><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">
<div id="ref-zhongAssociationsDietaryCholesterol2019" class="csl-entry">
<div class="csl-left-margin">1. </div><div class="csl-right-inline">Zhong VW, Horn LV, Cornelis MC, et al. Associations of <span>Dietary Cholesterol</span> or <span>Egg Consumption With Incident Cardiovascular Disease</span> and <span>Mortality</span>. <em>JAMA</em>. 2019;321(11):1081-1095. doi:<a href="https://doi.org/10.1001/jama.2019.1572">10.1001/jama.2019.1572</a></div>
</div>
<div id="ref-keoghToolkitMeasurementError2014" class="csl-entry">
<div class="csl-left-margin">2. </div><div class="csl-right-inline">Keogh RH, White IR. A toolkit for measurement error correction, with a focus on nutritional epidemiology. <em>Statistics in Medicine</em>. 2014;33(12):2137-2155. doi:<a href="https://doi.org/10.1002/sim.6095">10.1002/sim.6095</a></div>
</div>
<div id="ref-archerControversyDebateMemoryBased2018" class="csl-entry">
<div class="csl-left-margin">3. </div><div class="csl-right-inline">Archer E, Marlow ML, Lavie CJ. Controversy and debate: <span>Memory</span>-<span>Based Methods Paper</span> 1: The fatal flaws of food frequency questionnaires and other memory-based dietary assessment methods. <em>Journal of Clinical Epidemiology</em>. 2018;104:113-124. doi:<a href="https://doi.org/10.1016/j.jclinepi.2018.08.003">10.1016/j.jclinepi.2018.08.003</a></div>
</div>
<div id="ref-subarAddressingCurrentCriticism2015" class="csl-entry">
<div class="csl-left-margin">4. </div><div class="csl-right-inline">Subar AF, Freedman LS, Tooze JA, et al. Addressing <span>Current Criticism Regarding</span> the <span>Value</span> of <span>Self</span>-<span>Report Dietary Data12</span>. <em>The Journal of Nutrition</em>. 2015;145(12):2639-2645. doi:<a href="https://doi.org/10.3945/jn.115.219634">10.3945/jn.115.219634</a></div>
</div>
<div id="ref-youngDemingDataObservational2011" class="csl-entry">
<div class="csl-left-margin">5. </div><div class="csl-right-inline">Young SS, Karr A. Deming, data and observational studies. <em>Significance</em>. 2011;8(3):116-120. doi:<a href="https://doi.org/10.1111/j.1740-9713.2011.00506.x">10.1111/j.1740-9713.2011.00506.x</a></div>
</div>
<div id="ref-Patel2015-kk" class="csl-entry">
<div class="csl-left-margin">6. </div><div class="csl-right-inline">Patel CJ, Burford B, Ioannidis JPA. Assessment of vibration of effects due to model specification can demonstrate the instability of observational associations. <em>J Clin Epidemiol</em>. 2015;68(9):1046-1058. doi:<a href="https://doi.org/10.1016/j.jclinepi.2015.05.029">10.1016/j.jclinepi.2015.05.029</a></div>
</div>
<div id="ref-greenlandRandomizationStatisticsCausal1990" class="csl-entry">
<div class="csl-left-margin">7. </div><div class="csl-right-inline">Greenland S. Randomization, statistics, and causal inference. <em>Epidemiology</em>. 1990;1(6):421-429. doi:<a href="https://doi.org/10.1097/00001648-199011000-00003">10.1097/00001648-199011000-00003</a></div>
</div>
<div id="ref-amrheinScientistsRiseStatistical2019" class="csl-entry">
<div class="csl-left-margin">8. </div><div class="csl-right-inline">Amrhein V, Greenland S, McShane B. Scientists rise up against statistical significance. <em>Nature</em>. 2019;567(7748):305. doi:<a href="https://doi.org/10.1038/d41586-019-00857-9">10.1038/d41586-019-00857-9</a></div>
</div>
<div id="ref-feinleibSevenCountriesMultivariate1981" class="csl-entry">
<div class="csl-left-margin">9. </div><div class="csl-right-inline">Feinleib M. Seven <span>Countries</span>: <span>A Multivariate Analysis</span> of <span>Death</span> and <span>Coronary Heart Disease</span>. <em>JAMA</em>. 1981;245(5):511-512. doi:<a href="https://doi.org/10.1001/jama.1981.03310300063026">10.1001/jama.1981.03310300063026</a></div>
</div>
<div id="ref-duffPathologyAtherosclerosis1951" class="csl-entry">
<div class="csl-left-margin">10. </div><div class="csl-right-inline">Duff GL, McMILLAN GC. <a href="https://www.ncbi.nlm.nih.gov/pubmed/14837929">Pathology of atherosclerosis</a>. <em>The American Journal of Medicine</em>. 1951;11(1):92-108.</div>
</div>
<div id="ref-clarkeDietaryLipidsBlood1997" class="csl-entry">
<div class="csl-left-margin">11. </div><div class="csl-right-inline">Clarke R, Frost C, Collins R, Appleby P, Peto R. <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2125600">Dietary lipids and blood cholesterol: Quantitative meta-analysis of metabolic ward studies</a>. <em>BMJ (Clinical research ed)</em>. 1997;314(7074):112-117.</div>
</div>
<div id="ref-bowmanEffectDietaryFat1988a" class="csl-entry">
<div class="csl-left-margin">12. </div><div class="csl-right-inline">Bowman MP, Van Doren J, Taper LJ, Thye FW, Ritchey SJ. Effect of dietary fat and cholesterol on plasma lipids and lipoprotein fractions in normolipidemic men. <em>The Journal of Nutrition</em>. 1988;118(5):555-560. doi:<a href="https://doi.org/10.1093/jn/118.5.555">10.1093/jn/118.5.555</a></div>
</div>
<div id="ref-brownawellCholesterolWhereScience2010" class="csl-entry">
<div class="csl-left-margin">13. </div><div class="csl-right-inline">Brownawell AM, Falk MC. Cholesterol: Where science and public health policy intersect. <em>Nutrition Reviews</em>. 2010;68(6):355-364. doi:<a href="https://doi.org/10.1111/j.1753-4887.2010.00294.x">10.1111/j.1753-4887.2010.00294.x</a></div>
</div>
<div id="ref-eckel2013AHAACC2014" class="csl-entry">
<div class="csl-left-margin">14. </div><div class="csl-right-inline"><span class="nocase">Eckel RH, Jakicic JM, Ard JD, et al.</span> 2013 <span>AHA</span>/<span>ACC</span> guideline on lifestyle management to reduce cardiovascular risk: A report of the <span>American College</span> of <span>Cardiology</span>/<span>American Heart Association Task Force</span> on <span>Practice Guidelines</span>. <em>Journal of the American College of Cardiology</em>. 2014;63(25 Pt B):2960-2984. doi:<a href="https://doi.org/10.1016/j.jacc.2013.11.003">10.1016/j.jacc.2013.11.003</a></div>
</div>
<div id="ref-Vincent2019-yc" class="csl-entry">
<div class="csl-left-margin">15. </div><div class="csl-right-inline">Vincent MJ, Allen B, Palacios OM, Haber LT, Maki KC. Meta-regression analysis of the effects of dietary cholesterol intake on <span>LDL</span> and <span>HDL</span> cholesterol. <em>Am J Clin Nutr</em>. 2019;109(1):7-16. doi:<a href="https://doi.org/10.1093/ajcn/nqy273">10.1093/ajcn/nqy273</a></div>
</div>
<div id="ref-kimDietaryCholesterolContained2018a" class="csl-entry">
<div class="csl-left-margin">16. </div><div class="csl-right-inline">Kim JE, Campbell WW. Dietary <span>Cholesterol Contained</span> in <span>Whole Eggs Is Not Well Absorbed</span> and <span>Does Not Acutely Affect Plasma Total Cholesterol Concentration</span> in <span>Men</span> and <span>Women</span>: <span>Results</span> from 2 <span>Randomized Controlled Crossover Studies</span>. <em>Nutrients</em>. 2018;10(9). doi:<a href="https://doi.org/10.3390/nu10091272">10.3390/nu10091272</a></div>
</div>
<div id="ref-chenowethInfluenceDietaryCholesterol1981" class="csl-entry">
<div class="csl-left-margin">17. </div><div class="csl-right-inline">Chenoweth W, Ullmann M, Simpson R, Leveille G. Influence of dietary cholesterol and fat on serum lipids in men. <em>The Journal of Nutrition</em>. 1981;111(12):2069-2080. doi:<a href="https://doi.org/10.1093/jn/111.12.2069">10.1093/jn/111.12.2069</a></div>
</div>
<div id="ref-vorsterEggIntakeDoes1992" class="csl-entry">
<div class="csl-left-margin">18. </div><div class="csl-right-inline">Vorster HH, Benadé AJ, Barnard HC, et al. Egg intake does not change plasma lipoprotein and coagulation profiles. <em>The American Journal of Clinical Nutrition</em>. 1992;55(2):400-410. doi:<a href="https://doi.org/10.1093/ajcn/55.2.400">10.1093/ajcn/55.2.400</a></div>
</div>
<div id="ref-jeschFoodIngredientsThat2017" class="csl-entry">
<div class="csl-left-margin">19. </div><div class="csl-right-inline">Jesch ED, Carr TP. Food <span>Ingredients That Inhibit Cholesterol Absorption</span>. <em>Preventive Nutrition and Food Science</em>. 2017;22(2):67-80. doi:<a href="https://doi.org/10.3746/pnf.2017.22.2.67">10.3746/pnf.2017.22.2.67</a></div>
</div>
<div id="ref-kuangImpactEggNutrient2018" class="csl-entry">
<div class="csl-left-margin">20. </div><div class="csl-right-inline">Kuang H, Yang F, Zhang Y, Wang T, Chen G. The <span>Impact</span> of <span>Egg Nutrient Composition</span> and <span>Its Consumption</span> on <span>Cholesterol Homeostasis</span>. <em>Cholesterol</em>. 2018. doi:<a href="https://doi.org/10.1155/2018/6303810">10.1155/2018/6303810</a></div>
</div>
<div id="ref-altmanScandalPoorMedical1994" class="csl-entry">
<div class="csl-left-margin">21. </div><div class="csl-right-inline">Altman DG. The scandal of poor medical research. <em>BMJ</em>. 1994;308(6924):283-284. doi:<a href="https://doi.org/10.1136/bmj.308.6924.283">10.1136/bmj.308.6924.283</a></div>
</div>
</div></section></div> ]]></description>
  <category>nutrition</category>
  <guid>https://lesslikely.com/nutrition/revisiting-eggs.html</guid>
  <pubDate>Tue, 06 Jan 2026 05:00:00 GMT</pubDate>
  <media:content url="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1554700113/Site/eggs_media_reporting.png" medium="image" type="image/png"/>
</item>
<item>
  <title>Confidence, Posteriors, and the Bootstrap</title>
  <dc:creator>Zad Rafi</dc:creator>
  <dc:creator>Sir Panda</dc:creator>
  <link>https://lesslikely.com/statistics/bootstrap.html</link>
  <description><![CDATA[ 





<hr>
<section id="the-power-of-the-bootstrap" class="level2">
<h2 class="anchored" data-anchor-id="the-power-of-the-bootstrap">The Power of the Bootstrap</h2>
<hr>
<p>The bootstrap<span class="citation" data-cites="Efron_1979 coxStatisticalThinking21st2017"><sup>1, 2</sup></span> is an incredibly powerful method of approximation. Indeed, frequentists are even able to approximate posterior distributions using it, In an excerpt from the paper below, Efron describes how these procedures are similar and gives examples using the parametric bootstrap.</p>
<hr>
<blockquote class="blockquote">
<p>The point of this brief note is to say that in some situations the bootstrap, in particular the parametric bootstrap, offers an easier path toward the calculation of Bayes posterior distributions. An important but somewhat under-appreciated article by Newton and Raftery (1994) made the same point using nonparametric bootstrapping. By “going parametric,” we can illustrate more explicitly the bootstrap/MCMC connection. The arguments here will be made mainly in terms of a simple example, with no attempt at the mathematical justifications seen in Newton and Raftery.</p>
<p>It is not really surprising that the bootstrap and MCMC share some overlapping territory. Both are general-purpose computer-based algorithmic methods for assessing statistical accuracy, and both enable the statistician to deal effectively with nuisance parameters, obtaining inferences for the interesting part of the problem. On the less salubrious side, both share the tendency of general-purpose algorithms toward overuse.</p>
<p>Of course the two methodologies operate in competing inferential realms: frequentist for the bootstrap, Bayesian for MCMC. Here, as in Newton and Raftery, we leap over that divide, bringing bootstrap calculations to bear on the Bayesian world. The working assumption is that we have a Bayesian prior in mind and the only question is how to compute its posterior distribution. Arguments about the merits of Bayesian versus frequentist analysis will not be taken up here, except for our main point that the two camps share some common ground.</p>
</blockquote>
<hr>
<p>However, they can not only approximate posterior distributions, but confidence distributions too. Confidence distributions are an incredibly dense and technical topic and is practically an umbrella term to refer to multiple concepts, for example, they can refer to confidence curves, confidence densities and deviance functions. For a definitive source to learn more about what they are, see the following<span class="citation" data-cites="coleSurprise2020 brownAssociationAntenatalExposure2017"><sup>3, 4</sup></span></p>
<hr>
<p>In a paper prepared for Efron’s Fisher lecture, he writes that confidence distributions may provide the key to syncretism between frequentist and bayesian motivations:</p>
<hr>
<blockquote class="blockquote">
<p>Fiducial distributions, or confidence densities, of- fer a way to finesse this difficulty. A good argument can be made that the confidence density is the posterior density for the parameter of interest, after all of the nuisance parameters have been integrated out in an objective way. If this argument turns out to be valid, then our progress in constructing approximate confidence intervals, and approximate confidence densities, could lead to an easier use of Bayesian thinking in practical problems. This is all quite speculative, but here is a safe prediction for the 21st century: statisticians will be asked to solve bigger and more complicated prob- lems. I believe that there is a good chance that objective Bayes methods will be developed for such problems, and that something like fiducial infer- ence will play an important role in this develop- ment. Maybe Fisher’s biggest blunder will become a big hit in the 21st century!</p>
</blockquote>
<hr>
<p>Indeed, some authors have shown that the bootstrap distribution is equal to the confidence distribution because it meets the definition of a confidence distribution.<span class="citation" data-cites="efronFisher21stCentury1998 efronAutomaticConstructionBootstrap2018 xieConfidenceDistributionFrequentist2013"><sup>5–7</sup></span>. Some have even referred to posteriors as a quick and dirty approximation to confidence distributions.<span class="citation" data-cites="fraserBayesPosteriorJust2011"><sup>8</sup></span></p>
<hr>
<section id="properties-of-confidence-distributions" class="level3">
<h3 class="anchored" data-anchor-id="properties-of-confidence-distributions">Properties of Confidence Distributions</h3>
<hr>
<p>Xie and Singh, as summarized by Fraser define these properties as:</p>
<hr>
<blockquote class="blockquote">
<p>The first is the classical definition CL and defines the confidence distribution function as the distribution function version of the confidence quantile function <img src="https://latex.codecogs.com/png.latex?%CE%B8"> ̃<img src="https://latex.codecogs.com/png.latex?%CE%B2">, where <img src="https://latex.codecogs.com/png.latex?(%E2%88%92%E2%88%9E,%CE%B8%20%CC%83%CE%B2(y0))"> is a <img src="https://latex.codecogs.com/png.latex?%CE%B2"> level confidence interval.</p>
</blockquote>
<hr>
<blockquote class="blockquote">
<p>The second definition (2.1) identifies a confidence distribution function <img src="https://latex.codecogs.com/png.latex?H(%CE%B8;y)"> as a distribution function in θ for each given y and as a pivot with a uniform distribution for eachθ. But this also closely identifies with what Fisher (1930) offered: fiducial but with Fisher’s promotion replaced by a claim that the argument is pure frequentist. Of course it is pure frequentist just as Fisher (1930) was pure frequentist, except for Fisher’s accompanying claim to having purer probabilities, which was then a direct confrontation to the Bayes aficionados of the time.</p>
</blockquote>
<hr>
<blockquote class="blockquote">
<p>The third definition (2.2) essentially gives just the quantile equivalent say <img src="https://latex.codecogs.com/png.latex?%CE%B8%20%CC%83u(y">) of the distribution function where u is Uniform (0,1). Aren’t confidence quantile and confidence upper bound just different labelling for the same object? Confidence distributions can have many properties: the distribution function should of course be <img src="https://latex.codecogs.com/png.latex?Uniform(0,1)">, but also it should inherit continuity when present in the model, should use all available information, and should generally be sensible. These properties aren’t really addressed in the authors’ proposal. A promotion of confidence distributions should acknowledge these inherent issues and also mention marginal and conditional conflicts as discussed in the literature.</p>
</blockquote>
<hr>
<p>The bootstrap distribution and the asymptotic consonance distribution would be defined as:</p>
<p><img src="https://latex.codecogs.com/png.latex?H_%7Bn%7D(%5Ctheta)=1-P%5Cleft(%5Chat%7B%5Ctheta%7D-%5Chat%7B%5Ctheta%7D%5E%7B*%7D%20%5Cleq%20%5Chat%7B%5Ctheta%7D-%5Ctheta%20%7C%20%5Cmathbf%7Bx%7D%5Cright)=P%5Cleft(%5Chat%7B%5Ctheta%7D%5E%7B*%7D%20%5Cleq%20%5Ctheta%20%7C%20%5Cmathbf%7Bx%7D%5Cright)"></p>
<hr>
<p>Efron writes,</p>
<hr>
<blockquote class="blockquote">
<p>As the authors point out, all of this has something to do with the bootstrap. Let <img src="https://latex.codecogs.com/png.latex?%CE%B8%CB%86%E2%88%97i,i=1,2,...,B"> represent B bootstrap replications ofθˆ, an estimator of parameter θ(possibly in the presence of nuisance parameters). The <img src="https://latex.codecogs.com/png.latex?%CE%B1">-th empirical quantile of the θˆ∗’s is then theupper endpoint of a first-order accurate-levelαconfidence interval. In this sense, the bootstrap distribution is an approximate confidence distribution. The BCa density, Efron &amp; Tibshirani (1998), improves the confidence accuracy by reweighting the <img src="https://latex.codecogs.com/png.latex?B%CE%B8%CB%86%E2%88%97"> values. Let Gˆbe this empirical cdf, and <img src="https://latex.codecogs.com/png.latex?z0"> and a be the bias correction and acceleration constants in my 1987 paper. Rather than equal weights 1/B, the BCa density puts weight proportional to <img src="https://latex.codecogs.com/png.latex?%CF%86(z%CE%B8i/(1+az%CE%B8i)%E2%88%92z0)(1+az%CE%B8i)2%CF%86(z%CE%B8i+z0)%5Bz%CE%B8i=%25%E2%88%921G%CB%86(%CE%B8%CB%86%E2%88%97i)%E2%88%92z0%5Don%CE%B8%CB%86%E2%88%97i">. The reweighted bootstrap distribution then becomes a second-order accurate confidence distribution. Efron (2012) discusses this construction in the context of objective Bayes inference.</p>
</blockquote>
<hr>
<p>Fraser, however, argues that the connection is nothing special</p>
<hr>
<blockquote class="blockquote">
<p>The bootstrap.The bootstrap as in Section 2.3 provides an approximation to the distributions described by a model, and in doing this the bootstrap can also eliminate the influence of nuisance parameters. It can be applied to statistics or to pivots, with faster effect using suitable pivots. It can be used with least squares, or with maximum like lihood statistics, or with statistical quantities, or anywhere where distributions are wanted. Ofcourse confidence calculations are just one such use but there are many others including of course testing. So there is no particular attachment of the bootstrap to confidence distribution functions other than providing an approximate means of calculation for such.</p>
</blockquote>
<hr>
<p>Certain bootstrap methods such as the <code>BCa</code> method and <code>t</code>-bootstrap method also yield second order accuracy of consonance distributions.</p>
<p><img src="https://latex.codecogs.com/png.latex?H_%7Bn%7D(%5Ctheta)=1-P%5Cleft(%5Cfrac%7B%5Chat%7B%5Ctheta%7D%5E%7B*%7D-%5Chat%7B%5Ctheta%7D%7D%7B%5Cwidehat%7BS%20E%7D%5E%7B*%7D%5Cleft(%5Chat%7B%5Ctheta%7D%5E%7B*%7D%5Cright)%7D%20%5Cleq%20%5Cfrac%7B%5Chat%7B%5Ctheta%7D-%5Ctheta%7D%7B%5Cwidehat%7BS%20E%7D(%5Chat%7B%5Ctheta%7D)%7D%20%7C%20%5Cmathbf%7Bx%7D%5Cright)"></p>
<p>Here, I demonstrate how to use these particular bootstrap methods to arrive at consonance curves and densities.</p>
<p>We’ll use the <code>Iris</code> dataset and construct a function that’ll yield a correlation coefficient and we will try to estimate the confidence intervals for them.</p>
<hr>
</section>
</section>
<section id="the-nonparametric-bootstrap" class="level2">
<h2 class="anchored" data-anchor-id="the-nonparametric-bootstrap">The Nonparametric Bootstrap</h2>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">iris <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> datasets<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>iris</span>
<span id="cb1-2">foo <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>(data, indices) {</span>
<span id="cb1-3">  dt <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> data[indices, ]</span>
<span id="cb1-4">  <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;">cor</span>(dt[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], dt[, <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;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span>))</span>
<span id="cb1-5">}</span></code></pre></div></div>
</div>
<hr>
<p>We can now use the <code>curve_boot()</code> method to construct a function. The default method used for this function is the “<code>Bca</code>” method provided by the <a href="https://cran.r-project.org/package=bcaboot"><code>bcaboot</code></a> package (also written by Efron).</p>
<hr>
<p>I will suppress the output of the function because it is unnecessarily long. But we’ve placed all the estimates into a list object called y.</p>
<p>The first item in the list will be the consonance distribution constructed by typical means, while the third item will be the bootstrap approximation to the consonance distribution.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">ggplot2<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;">qplot</span>(boot<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;">boot</span>(iris, foo, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geom =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"histogram"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_light</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/bootstrap_files/figure-html/unnamed-chunk-5-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><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;">ggcurve</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> y[[<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;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cd"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nullvalue =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</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;">"red"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_light</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/bootstrap_files/figure-html/unnamed-chunk-5-2.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>We can also print out a table for TeX documents</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">ztable</span>(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;">curve_table</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> y[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]))</span></code></pre></div></div>
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; color: rgba(119, 119, 119, 1) !important;"></th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Lower Limit</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Upper Limit</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Interval Width</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Interval Level (%)</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">CDF</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">P-value</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">S-value (bits)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">2500</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.14</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.10</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.05</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">25.0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.62</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.75</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.42</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">5000</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.17</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.07</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.10</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">50.0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.75</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.50</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">7500</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.20</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.03</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.17</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">75.0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.88</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.25</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.00</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">8000</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.21</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.19</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">80.0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.90</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.20</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.32</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">8500</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.22</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.21</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">85.0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.92</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.15</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.74</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">9000</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.24</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.24</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">90.0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.95</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.10</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">3.32</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">9500</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.26</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.03</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.29</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">95.0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.98</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.05</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">4.32</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">9750</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.28</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.05</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.33</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">97.5</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.99</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.03</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">5.32</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">9900</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.30</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.07</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.38</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">99.0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">6.64</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<p>More bootstrap replications will lead to a smoother function. But for now, we can compare these two functions to see how similar they are.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">result <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;">curve_from_se</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">measure =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean"</span>)</span>
<span id="cb5-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggcurve</span>(result[[<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;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nullvalue =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/bootstrap_files/figure-html/unnamed-chunk-7-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="576"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><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>
<span id="cb6-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Odds ratio with SE (on log scale internally)</span></span>
<span id="cb6-3">result <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;">curve_from_se</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</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;">se =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">measure =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ratio"</span>)</span>
<span id="cb6-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggcurve</span>(result[[<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;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nullvalue =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/bootstrap_files/figure-html/unnamed-chunk-7-2.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="576"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>If we wanted to look at the bootstrap standard errors, we could do so by loading the fifth item in the list</p>
<hr>
<hr>
<p>where in the top row, <code>theta</code> is the point estimate, and <code>sdboot</code> is the bootstrap estimate of the standard error, <code>sdjack</code> is the jacknife estimate of the standard error. <code>z0</code> is the bias correction value and <code>a</code> is the acceleration constant.</p>
<p>The values in the second row are essentially the internal standard errors of the estimates in the top row.</p>
<hr>
<p>One can also construct the confidence density, here I provide an example from the pvaluefunction R package The consonance curve and density are nearly identical. With more bootstrap replications, they are very likely to converge. [aadland2015ajcn]</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">library</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pvaluefunctions"</span>)</span>
<span id="cb7-2">result <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bcaboot<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;">bcajack</span>(</span>
<span id="cb7-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> iris, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">func =</span> foo,</span>
<span id="cb7-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</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;">100</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">verbose =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb7-5">)</span>
<span id="cb7-6"></span>
<span id="cb7-7">bca <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>(result[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lims"</span>]][, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb7-8"></span>
<span id="cb7-9">ggplot2<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;">qplot</span>(bca<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>result...lims......<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geom =</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="cb7-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_less</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/bootstrap_files/figure-html/unnamed-chunk-9-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
</section>
<section id="the-parametric-bootstrap" class="level2">
<h2 class="anchored" data-anchor-id="the-parametric-bootstrap">The Parametric Bootstrap</h2>
<hr>
<p>For the examples above, we mainly used nonparametric bootstrap methods. Here I show an example using the parametric <code>Bca</code> bootstrap and the results it yields.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">data</span>(diabetes, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">package =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bcaboot"</span>)</span>
<span id="cb8-2">X <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> diabetes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>x</span>
<span id="cb8-3">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;">scale</span>(diabetes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">center =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scale =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb8-4">lm.model <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> X <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>
<span id="cb8-5">mu.hat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> lm.model<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>fitted.values</span>
<span id="cb8-6">sigma.hat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> stats<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;">sd</span>(lm.model<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>residuals)</span>
<span id="cb8-7">t0 <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;">summary</span>(lm.model)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>adj.r.squared</span>
<span id="cb8-8">y.star <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;">sapply</span>(mu.hat, rnorm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> sigma.hat)</span>
<span id="cb8-9">tt <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;">apply</span>(y.star, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(y) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</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> X <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>adj.r.squared)</span>
<span id="cb8-10">b.star <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> y.star <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%*%</span> X</span></code></pre></div></div>
</div>
<hr>
<p>Now, we’ll use the same function, but set the method to <code>bcapar</code> for the parametric method.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">bcadf <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (bcaboot<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;">bcapar</span>(</span>
<span id="cb9-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t0 =</span> t0, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</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;">100</span>),</span>
<span id="cb9-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tt =</span> tt, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bb =</span> b.star, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb9-4">)[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lims"</span>]][, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span></code></pre></div></div>
</div>
<hr>
<p>Now we can look at our outputs.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">ggplot2<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;">qplot</span>((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>(bcadf)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geom =</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="cb10-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_less</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/bootstrap_files/figure-html/unnamed-chunk-12-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>That concludes our demonstration of the bootstrap method to approximate consonance functions.</p>
<hr>
<p><strong>See also:</strong> <a href="../statistics/sensitivity.html"><em>What Makes a Sensitivity Analysis?</em></a> — the hub piece tying this material to the broader cluster on assumptions, robustness, and what happens when models bend.</p>
<hr>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<hr>


<!-- -->


</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><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" data-entry-spacing="2" data-line-spacing="2">
<div id="ref-Efron_1979" class="csl-entry">
1. Efron B. (1979). <span>“Bootstrap methods: Another look at the jackknife.”</span> <em>The Annals of Statistics</em>. <strong>7</strong>:1–26. doi: <a href="https://doi.org/10.1214/aos/1176344552">10.1214/aos/1176344552</a>. <a href="https://projecteuclid.org/journals/annals-of-statistics/volume-7/issue-1/Bootstrap-Methods-Another-Look-at-the-Jackknife/10.1214/aos/1176344552.full">https://projecteuclid.org/journals/annals-of-statistics/volume-7/issue-1/Bootstrap-Methods-Another-Look-at-the-Jackknife/10.1214/aos/1176344552.full</a>.
</div>
<div id="ref-coxStatisticalThinking21st2017" class="csl-entry">
2. Cox DR, Efron B. (2017). <span>“Statistical thinking for 21st century scientists.”</span> <em>Science Advances</em>. <strong>3</strong>:e1700768. doi: <a href="https://doi.org/10.1126/sciadv.1700768">10.1126/sciadv.1700768</a>.
</div>
<div id="ref-coleSurprise2020" class="csl-entry">
3. Cole SR, Edwards JK, Greenland S. (2020). <span>“Surprise!”</span> <em>American Journal of Epidemiology</em>. doi: <a href="https://doi.org/10/gg63md">10/gg63md</a>.
</div>
<div id="ref-brownAssociationAntenatalExposure2017" class="csl-entry">
4. Brown HK, Hussain-Shamsy N, Lunsky Y, Dennis C-LE, Vigod SN. (2017). <span>“The association between antenatal exposure to selective serotonin reuptake inhibitors and autism: <span>A</span> systematic review and meta-analysis.”</span> <em>The Journal of Clinical Psychiatry</em>. <strong>78</strong>:e48–e58. doi: <a href="https://doi.org/10.4088/JCP.15r10194">10.4088/JCP.15r10194</a>.
</div>
<div id="ref-efronFisher21stCentury1998" class="csl-entry">
5. Efron B. (1998). <span>“R. <span>A</span>. <span>Fisher</span> in the 21st century (<span>Invited</span> paper presented at the 1996 <span>R</span>. <span>A</span>. <span>Fisher Lecture</span>).”</span> <em>Statistical Science</em>. <strong>13</strong>:95–122. doi: <a href="https://doi.org/10/cxg354">10/cxg354</a>.
</div>
<div id="ref-efronAutomaticConstructionBootstrap2018" class="csl-entry">
6. Efron B, Narasimhan B. (2018). <span>“The automatic construction of bootstrap confidence intervals.”</span> :17.
</div>
<div id="ref-xieConfidenceDistributionFrequentist2013" class="csl-entry">
7. Xie M, Singh K. (2013). <span>“Confidence <span>Distribution</span>, the <span>Frequentist Distribution Estimator</span> of a <span>Parameter</span>: <span>A Review</span>.”</span> <em>International Statistical Review</em>. <strong>81</strong>:3–39. doi: <a href="https://doi.org/10.1111/insr.12000">10.1111/insr.12000</a>.
</div>
<div id="ref-fraserBayesPosteriorJust2011" class="csl-entry">
8. Fraser DaS. (2011). <span>“Is <span>Bayes Posterior</span> just <span>Quick</span> and <span>Dirty Confidence</span>?”</span> <em>Statistical Science</em>. <strong>26</strong>:299–316. doi: <a href="https://doi.org/10/df4n7n">10/df4n7n</a>.
</div>
</div></section></div> ]]></description>
  <category>statistics</category>
  <guid>https://lesslikely.com/statistics/bootstrap.html</guid>
  <pubDate>Sun, 12 Jan 2025 05:00:00 GMT</pubDate>
  <media:content url="https://raw.githubusercontent.com/stan-dev/logos/master/logo.png" medium="image" type="image/png"/>
</item>
<item>
  <title>Computing Confidence Interval Functions with cifunction</title>
  <dc:creator>Zad Rafi</dc:creator>
  <dc:creator>Zad R</dc:creator>
  <link>https://lesslikely.com/statistics/cifunction.html</link>
  <description><![CDATA[ 





<section id="overview" class="level2" data-number="1">
<h2 data-number="1" class="anchored" data-anchor-id="overview"><span class="header-section-number">1</span> Overview</h2>
<p>Most of the time, we only report a confidence interval at a single level (typically 95%). However, that one interval throws away a fair amount of information about the data, since it invites us to sort values into those inside the interval and those outside of it. The <strong>confidence interval function</strong> (CI-function) gives us a more complete picture by displaying all possible confidence intervals at once. In this post, I’d like to go through <code>cifunction</code>, a Stata package written by Ariel Linden that computes and plots these functions.</p>
<div class="callout callout-style-default callout-note 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">
<span class="screen-reader-only">Note</span>Alternative Names
</div>
</div>
<div class="callout-body-container callout-body">
<p>The CI-function has gone by several names in the literature:</p>
<ul>
<li><strong>Confidence curve</strong><span class="citation" data-cites="birnbaum1961confidence"><sup>1</sup></span></li>
<li><strong>P-value function</strong><span class="citation" data-cites="poole1987beyond miettinen1985theoretical"><sup>2, 3</sup></span></li>
<li><strong>Consonance interval</strong><span class="citation" data-cites="folks1981ideas"><sup>4</sup></span></li>
<li><strong>Confidence density</strong><span class="citation" data-cites="xieConfidenceDistributionFrequentist2013"><sup>5</sup></span></li>
</ul>
</div>
</div>
</section>
<section id="installation" class="level2" data-number="2">
<h2 data-number="2" class="anchored" data-anchor-id="installation"><span class="header-section-number">2</span> Installation</h2>
<p>Let’s start by installing <code>cifunction</code> from SSC (Statistical Software Components):</p>
<div class="cell" data-layout-align="center">
<pre class="ssc cell-code"><code></code></pre>
</div>
</section>
<section id="syntax" class="level2" data-number="3">
<h2 data-number="3" class="anchored" data-anchor-id="syntax"><span class="header-section-number">3</span> Syntax</h2>
<p><code>{stata, echo=TRUE, collectcode=TRUE, statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP"}cifunction #b, se(#) [options]</code></p>
<section id="required-arguments" class="level3" data-number="3.1">
<h3 data-number="3.1" class="anchored" data-anchor-id="required-arguments"><span class="header-section-number">3.1</span> Required Arguments</h3>
<table class="caption-top table">
<caption>Required parameters for cifunction</caption>
<colgroup>
<col style="width: 45%">
<col style="width: 54%">
</colgroup>
<thead>
<tr class="header">
<th>Argument</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>#b</code></td>
<td>Point estimate (coefficient or exponentiated value like OR, HR, IRR)</td>
</tr>
<tr class="even">
<td><code>se(#)</code></td>
<td>Standard error of the estimate</td>
</tr>
</tbody>
</table>
</section>
<section id="optional-arguments" class="level3" data-number="3.2">
<h3 data-number="3.2" class="anchored" data-anchor-id="optional-arguments"><span class="header-section-number">3.2</span> Optional Arguments</h3>
<table class="caption-top table">
<caption>Optional parameters for cifunction</caption>
<colgroup>
<col style="width: 40%">
<col style="width: 59%">
</colgroup>
<thead>
<tr class="header">
<th>Option</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>df(#)</code></td>
<td>Degrees of freedom (for t-distributed estimates)</td>
</tr>
<tr class="even">
<td><code>eform</code></td>
<td>Indicates coefficient is exponentiated (OR, RR, IRR)</td>
</tr>
<tr class="odd">
<td><code>figure[(options)]</code></td>
<td>Produces CI-function plot with optional twoway options</td>
</tr>
<tr class="even">
<td><code>saving(filename, replace)</code></td>
<td>Saves results to file</td>
</tr>
</tbody>
</table>
</section>
</section>
<section id="understanding-ci-functions" class="level2" data-number="4">
<h2 data-number="4" class="anchored" data-anchor-id="understanding-ci-functions"><span class="header-section-number">4</span> Understanding CI-Functions</h2>
<p>So what are we looking at when we plot one of these? A CI-function shows the relationship between confidence levels and their corresponding confidence intervals, and there are a few features that we can read off the curve:</p>
<ul>
<li><strong>Peak of the curve</strong>: this is where the point estimate sits</li>
<li><strong>Concentration around the peak</strong>: this reflects the precision of the estimate</li>
<li><strong>Narrow curve</strong>: high precision (usually a large sample size)</li>
<li><strong>Broad curve</strong>: low precision (usually a small sample size)</li>
</ul>
<section id="advantages-over-single-level-cis" class="level3" data-number="4.1">
<h3 data-number="4.1" class="anchored" data-anchor-id="advantages-over-single-level-cis"><span class="header-section-number">4.1</span> Advantages Over Single-Level CIs</h3>
<ol type="1">
<li><strong>Complete information</strong>: we can see how compatible every value is with the data</li>
<li><strong>Precision visualization</strong>: the width of the curve directly shows how precise the estimate is</li>
<li><strong>Multiple comparisons</strong>: we can see whether the data provide any reassurance about null effects</li>
<li><strong>Graded interpretation</strong>: it moves us away from binary “significant/non-significant” thinking</li>
</ol>
<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">
<span class="screen-reader-only">Tip</span>Interpretation Guide
</div>
</div>
<div class="callout-body-container callout-body">
<p>Values toward the peak are more compatible with the observed data (assuming that the statistical model is correct). Thus, the curve shows us that statistical evidence changes gradually, and it does not suggest any particular cutoff.</p>
</div>
</div>
</section>
</section>
<section id="practical-examples" class="level2" data-number="5">
<h2 data-number="5" class="anchored" data-anchor-id="practical-examples"><span class="header-section-number">5</span> Practical Examples</h2>
<section id="example-1-basic-risk-ratio" class="level3" data-number="5.1">
<h3 data-number="5.1" class="anchored" data-anchor-id="example-1-basic-risk-ratio"><span class="header-section-number">5.1</span> Example 1: Basic Risk Ratio</h3>
<p>First, we’ll reproduce Figure 1 from Sullivan and Foster (1990):</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb2-1">* Get standard <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">error</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> RR=2.0 with <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">p</span>=0.05</span>
<span id="cb2-2">getregstats 2.0, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">p</span>(0.05) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mod</span>(rr)</span>
<span id="cb2-3"></span>
<span id="cb2-4">* Create CI-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> with <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>-scaled x-axis</span>
<span id="cb2-5">cifunction 2.0, se(.707306) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">eform</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb2-6">    fig(<span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xscale</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>) xlab(0.5 1 2 5 10) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb2-7">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Risk Ratio (Log Scale)"</span>))</span>
<span id="cb2-8">##              | Risk Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Inte</span>
<span id="cb2-9">## &gt; rval]</span>
<span id="cb2-10">## -------------+-----------------------------------------------------------</span>
<span id="cb2-11">## &gt; -----</span>
<span id="cb2-12">##    Estimates |          2    .707306    -1.96   0.050            1       </span>
<span id="cb2-13">## &gt;     4</span>
<span id="cb2-14">## -------------------------------------------------------------------------</span>
<span id="cb2-15">## &gt; -----</span></code></pre></div></div>
</div>
</section>
<section id="example-2-age-stratified-rate-ratios" class="level3" data-number="5.2">
<h3 data-number="5.2" class="anchored" data-anchor-id="example-2-age-stratified-rate-ratios"><span class="header-section-number">5.2</span> Example 2: Age-Stratified Rate Ratios</h3>
<p>Next, we’ll use the Doll-Hill smoking data, stratified by age group:</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb3-1">* Load <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">data</span> and <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">fit</span> models</span>
<span id="cb3-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">webuse</span> dollhill3, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb3-3"></span>
<span id="cb3-4">* Fit Poisson models <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> each age category</span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">forvalues</span> i = 1/4 {</span>
<span id="cb3-6">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">poisson</span> deaths smokes <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> agecat==<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`i'</span>, exposure(pyears) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">irr</span></span>
<span id="cb3-7">}</span>
<span id="cb3-8"></span>
<span id="cb3-9">* Plot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">all</span> four age-stratified CI-functions</span>
<span id="cb3-10">cifunction 5.736638 2.138812 1.46824 1.35606, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb3-11">    se(4.181258 .6520701 .295728 .2748845) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">eform</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb3-12">    fig(<span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xscale</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">xlabel</span>(.3 .5 1 2 5 10 20 50 100) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb3-13">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">legend</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(1 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35-44"</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(2 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45-54"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb3-14">           <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(3 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55-64"</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(4 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65-74"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb3-15">           <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age Group"</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">size</span>(small))) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb3-16">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rate Ratio (Log Scale)"</span>))</span>
<span id="cb3-17">## (Doll and Hill (1966))</span>
<span id="cb3-18">## </span>
<span id="cb3-19">## </span>
<span id="cb3-20">## Iteration 0:  Log likelihood = -4.0705386  </span>
<span id="cb3-21">## Iteration 1:  Log likelihood = -3.9613823  </span>
<span id="cb3-22">## Iteration 2:  Log likelihood = -3.9612634  </span>
<span id="cb3-23">## Iteration 3:  Log likelihood = -3.9612634  </span>
<span id="cb3-24">## </span>
<span id="cb3-25">## Poisson regression                                      Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span> =  </span>
<span id="cb3-26">## &gt;     2</span>
<span id="cb3-27">##                                                         LR <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1)    =  </span>
<span id="cb3-28">## &gt;  9.73</span>
<span id="cb3-29">##                                                         Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>   = 0</span>
<span id="cb3-30">## &gt; .0018</span>
<span id="cb3-31">## Log likelihood = -3.9612634                             Pseudo R2     = 0</span>
<span id="cb3-32">## &gt; .5511</span>
<span id="cb3-33">## </span>
<span id="cb3-34">## -------------------------------------------------------------------------</span>
<span id="cb3-35">## &gt; -----</span>
<span id="cb3-36">##       deaths |        IRR   Std. err.      z    P&gt;|z|     [95% conf. inte</span>
<span id="cb3-37">## &gt; rval]</span>
<span id="cb3-38">## -------------+-----------------------------------------------------------</span>
<span id="cb3-39">## &gt; -----</span>
<span id="cb3-40">##       smokes |   5.736638   4.181258     2.40   0.017     1.374811    23.</span>
<span id="cb3-41">## &gt; 93712</span>
<span id="cb3-42">##        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   .0001064   .0000753   -12.94   0.000     .0000266    .00</span>
<span id="cb3-43">## &gt; 04256</span>
<span id="cb3-44">##   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(pyears) |          1  (exposure)</span>
<span id="cb3-45">## -------------------------------------------------------------------------</span>
<span id="cb3-46">## &gt; -----</span>
<span id="cb3-47">## Note: <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span> baseline incidence rate.</span>
<span id="cb3-48">## </span>
<span id="cb3-49">## Iteration 0:  Log likelihood = -5.4793565  </span>
<span id="cb3-50">## Iteration 1:  Log likelihood = -5.4104407  </span>
<span id="cb3-51">## Iteration 2:  Log likelihood =   -5.41027  </span>
<span id="cb3-52">## Iteration 3:  Log likelihood =   -5.41027  </span>
<span id="cb3-53">## </span>
<span id="cb3-54">## Poisson regression                                      Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span> =  </span>
<span id="cb3-55">## &gt;     2</span>
<span id="cb3-56">##                                                         LR <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1)    =  </span>
<span id="cb3-57">## &gt;  7.59</span>
<span id="cb3-58">##                                                         Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>   = 0</span>
<span id="cb3-59">## &gt; .0059</span>
<span id="cb3-60">## Log likelihood = -5.41027                               Pseudo R2     = 0</span>
<span id="cb3-61">## &gt; .4123</span>
<span id="cb3-62">## </span>
<span id="cb3-63">## -------------------------------------------------------------------------</span>
<span id="cb3-64">## &gt; -----</span>
<span id="cb3-65">##       deaths |        IRR   Std. err.      z    P&gt;|z|     [95% conf. inte</span>
<span id="cb3-66">## &gt; rval]</span>
<span id="cb3-67">## -------------+-----------------------------------------------------------</span>
<span id="cb3-68">## &gt; -----</span>
<span id="cb3-69">##       smokes |   2.138812   .6520701     2.49   0.013     1.176691    3.8</span>
<span id="cb3-70">## &gt; 87609</span>
<span id="cb3-71">##        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   .0011243   .0003246   -23.52   0.000     .0006385    .00</span>
<span id="cb3-72">## &gt; 19798</span>
<span id="cb3-73">##   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(pyears) |          1  (exposure)</span>
<span id="cb3-74">## -------------------------------------------------------------------------</span>
<span id="cb3-75">## &gt; -----</span>
<span id="cb3-76">## Note: <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span> baseline incidence rate.</span>
<span id="cb3-77">## </span>
<span id="cb3-78">## Iteration 0:  Log likelihood = -6.2456963  </span>
<span id="cb3-79">## Iteration 1:  Log likelihood = -6.1713863  </span>
<span id="cb3-80">## Iteration 2:  Log likelihood =  -6.171298  </span>
<span id="cb3-81">## Iteration 3:  Log likelihood =  -6.171298  </span>
<span id="cb3-82">## </span>
<span id="cb3-83">## Poisson regression                                      Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span> =  </span>
<span id="cb3-84">## &gt;     2</span>
<span id="cb3-85">##                                                         LR <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1)    =  </span>
<span id="cb3-86">## &gt;  4.01</span>
<span id="cb3-87">##                                                         Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>   = 0</span>
<span id="cb3-88">## &gt; .0453</span>
<span id="cb3-89">## Log likelihood = -6.171298                              Pseudo R2     = 0</span>
<span id="cb3-90">## &gt; .2450</span>
<span id="cb3-91">## </span>
<span id="cb3-92">## -------------------------------------------------------------------------</span>
<span id="cb3-93">## &gt; -----</span>
<span id="cb3-94">##       deaths |        IRR   Std. err.      z    P&gt;|z|     [95% conf. inte</span>
<span id="cb3-95">## &gt; rval]</span>
<span id="cb3-96">## -------------+-----------------------------------------------------------</span>
<span id="cb3-97">## &gt; -----</span>
<span id="cb3-98">##       smokes |    1.46824    .295728     1.91   0.057     .9893522     2.</span>
<span id="cb3-99">## &gt; 17893</span>
<span id="cb3-100">##        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   .0049037   .0009267   -28.14   0.000     .0033858    .00</span>
<span id="cb3-101">## &gt; 71021</span>
<span id="cb3-102">##   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(pyears) |          1  (exposure)</span>
<span id="cb3-103">## -------------------------------------------------------------------------</span>
<span id="cb3-104">## &gt; -----</span>
<span id="cb3-105">## Note: <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span> baseline incidence rate.</span>
<span id="cb3-106">## </span>
<span id="cb3-107">## Iteration 0:  Log likelihood = -6.1640322  </span>
<span id="cb3-108">## Iteration 1:  Log likelihood = -6.1203079  </span>
<span id="cb3-109">## Iteration 2:  Log likelihood = -6.1202768  </span>
<span id="cb3-110">## Iteration 3:  Log likelihood = -6.1202768  </span>
<span id="cb3-111">## </span>
<span id="cb3-112">## Poisson regression                                      Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span> =  </span>
<span id="cb3-113">## &gt;     2</span>
<span id="cb3-114">##                                                         LR <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1)    =  </span>
<span id="cb3-115">## &gt;  2.43</span>
<span id="cb3-116">##                                                         Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>   = 0</span>
<span id="cb3-117">## &gt; .1189</span>
<span id="cb3-118">## Log likelihood = -6.1202768                             Pseudo R2     = 0</span>
<span id="cb3-119">## &gt; .1658</span>
<span id="cb3-120">## </span>
<span id="cb3-121">## -------------------------------------------------------------------------</span>
<span id="cb3-122">## &gt; -----</span>
<span id="cb3-123">##       deaths |        IRR   Std. err.      z    P&gt;|z|     [95% conf. inte</span>
<span id="cb3-124">## &gt; rval]</span>
<span id="cb3-125">## -------------+-----------------------------------------------------------</span>
<span id="cb3-126">## &gt; -----</span>
<span id="cb3-127">##       smokes |    1.35606   .2748845     1.50   0.133     .9114509    2.0</span>
<span id="cb3-128">## &gt; 17551</span>
<span id="cb3-129">##        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   .0108317    .002047   -23.95   0.000     .0074789    .01</span>
<span id="cb3-130">## &gt; 56877</span>
<span id="cb3-131">##   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(pyears) |          1  (exposure)</span>
<span id="cb3-132">## -------------------------------------------------------------------------</span>
<span id="cb3-133">## &gt; -----</span>
<span id="cb3-134">## Note: <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span> baseline incidence rate.</span></code></pre></div></div>
</div>
<p>Here, the CI-functions let us see patterns across subgroups (in this case, how the smoking-mortality relationship varies by age).</p>
</section>
<section id="example-3-crude-vs-adjusted-estimates" class="level3" data-number="5.3">
<h3 data-number="5.3" class="anchored" data-anchor-id="example-3-crude-vs-adjusted-estimates"><span class="header-section-number">5.3</span> Example 3: Crude vs Adjusted Estimates</h3>
<p>Now, let’s compare the crude and pooled odds ratios from Mann et al.&nbsp;(1976):</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb4-1">* Case-control analysis</span>
<span id="cb4-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">cci</span> 10 36 5 40, woolf</span>
<span id="cb4-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">cci</span> 18 78 7 86, woolf</span>
<span id="cb4-4"></span>
<span id="cb4-5">* Get standard errors</span>
<span id="cb4-6">getregstats 2.835165, ucl(7.151794) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mod</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">or</span>)</span>
<span id="cb4-7">getregstats 2.222222, ucl(7.118025) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mod</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">or</span>)</span>
<span id="cb4-8"></span>
<span id="cb4-9">* Compare crude vs pooled <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span></span>
<span id="cb4-10">cifunction 2.222222 2.835165, se(1.319891 1.33843) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">eform</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb4-11">    fig(<span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xscale</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">xlabel</span>(.2 .5 1 2 5 10 20) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb4-12">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">legend</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(1 Crude) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(2 Pooled)) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb4-13">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Odds Ratio (Log Scale)"</span>))</span>
<span id="cb4-14">##                                                          Proportion</span>
<span id="cb4-15">##                  |   Exposed   Unexposed  |      Total      exposed</span>
<span id="cb4-16">## -----------------+------------------------+------------------------</span>
<span id="cb4-17">##            Cases |        10          36  |         46       0.2174</span>
<span id="cb4-18">##         Controls |         5          40  |         45       0.1111</span>
<span id="cb4-19">## -----------------+------------------------+------------------------</span>
<span id="cb4-20">##            Total |        15          76  |         91       0.1648</span>
<span id="cb4-21">##                  |                        |</span>
<span id="cb4-22">##                  |      Point estimate    |    [95% conf. interval]</span>
<span id="cb4-23">##                  |------------------------+------------------------</span>
<span id="cb4-24">##       Odds <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">ratio</span> |         2.222222       |      .69377    7.118025 (Wool</span>
<span id="cb4-25">## &gt; f)</span>
<span id="cb4-26">##  Attr. frac. ex. |              .55       |      -.4414    .8595116 (Wool</span>
<span id="cb4-27">## &gt; f)</span>
<span id="cb4-28">##  Attr. frac. pop |         .1195652       |</span>
<span id="cb4-29">##                  +-------------------------------------------------</span>
<span id="cb4-30">##                                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1) =     1.87  Pr&gt;<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span> = 0.1719</span>
<span id="cb4-31">## </span>
<span id="cb4-32">## </span>
<span id="cb4-33">##                                                          Proportion</span>
<span id="cb4-34">##                  |   Exposed   Unexposed  |      Total      exposed</span>
<span id="cb4-35">## -----------------+------------------------+------------------------</span>
<span id="cb4-36">##            Cases |        18          78  |         96       0.1875</span>
<span id="cb4-37">##         Controls |         7          86  |         93       0.0753</span>
<span id="cb4-38">## -----------------+------------------------+------------------------</span>
<span id="cb4-39">##            Total |        25         164  |        189       0.1323</span>
<span id="cb4-40">##                  |                        |</span>
<span id="cb4-41">##                  |      Point estimate    |    [95% conf. interval]</span>
<span id="cb4-42">##                  |------------------------+------------------------</span>
<span id="cb4-43">##       Odds <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">ratio</span> |         2.835165       |    1.123936    7.151794 (Wool</span>
<span id="cb4-44">## &gt; f)</span>
<span id="cb4-45">##  Attr. frac. ex. |         .6472868       |    .1102698    .8601749 (Wool</span>
<span id="cb4-46">## &gt; f)</span>
<span id="cb4-47">##  Attr. frac. pop |         .1213663       |</span>
<span id="cb4-48">##                  +-------------------------------------------------</span>
<span id="cb4-49">##                                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1) =     5.18  Pr&gt;<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span> = 0.0228</span>
<span id="cb4-50">## </span>
<span id="cb4-51">## </span>
<span id="cb4-52">## </span>
<span id="cb4-53">## -------------------------------------------------------------------------</span>
<span id="cb4-54">## &gt; -----</span>
<span id="cb4-55">##              | Odds Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Inte</span>
<span id="cb4-56">## &gt; rval]</span>
<span id="cb4-57">## -------------+-----------------------------------------------------------</span>
<span id="cb4-58">## &gt; -----</span>
<span id="cb4-59">##    Estimates |   2.835165   1.338429     2.21   0.027     1.123936    7.1</span>
<span id="cb4-60">## &gt; 51794</span>
<span id="cb4-61">## -------------------------------------------------------------------------</span>
<span id="cb4-62">## &gt; -----</span>
<span id="cb4-63">## </span>
<span id="cb4-64">## </span>
<span id="cb4-65">## </span>
<span id="cb4-66">## -------------------------------------------------------------------------</span>
<span id="cb4-67">## &gt; -----</span>
<span id="cb4-68">##              | Odds Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Inte</span>
<span id="cb4-69">## &gt; rval]</span>
<span id="cb4-70">## -------------+-----------------------------------------------------------</span>
<span id="cb4-71">## &gt; -----</span>
<span id="cb4-72">##    Estimates |   2.222222   1.319891     1.34   0.179     .6937698    7.1</span>
<span id="cb4-73">## &gt; 18025</span>
<span id="cb4-74">## -------------------------------------------------------------------------</span>
<span id="cb4-75">## &gt; -----</span></code></pre></div></div>
</div>
</section>
<section id="example-4-multi-study-comparison" class="level3" data-number="5.4">
<h3 data-number="5.4" class="anchored" data-anchor-id="example-4-multi-study-comparison"><span class="header-section-number">5.4</span> Example 4: Multi-Study Comparison</h3>
<p>We can also compare results across four geographic regions (Gufferman et al.&nbsp;1984):</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb5-1">* Get standard errors from confidence limits</span>
<span id="cb5-2">getregstats 0.7, <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">l</span>(.2) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mod</span>(rr)</span>
<span id="cb5-3">getregstats 1.2, <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">l</span>(.8) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mod</span>(rr)</span>
<span id="cb5-4">getregstats 1.3, <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">l</span>(.5) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mod</span>(rr)</span>
<span id="cb5-5">getregstats 3.6, <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">l</span>(1.3) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mod</span>(rr)</span>
<span id="cb5-6"></span>
<span id="cb5-7">* Plot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">all</span> studies</span>
<span id="cb5-8">cifunction .7 1.2 1.3 3.6, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb5-9">    se(.4474236 .2482485 .6337692 1.870876) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">eform</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb5-10">    fig(<span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xscale</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">xlabel</span>(.05 .1 .2 .5 1 2 5 10 30) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb5-11">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">legend</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(1 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Finland"</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(2 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NO/LA"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb5-12">           <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(3 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Denmark"</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(4 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Upstate NY"</span>)) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb5-13">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative Risk (Log Scale)"</span>))</span>
<span id="cb5-14">##              | Risk Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Inte</span>
<span id="cb5-15">## &gt; rval]</span>
<span id="cb5-16">## -------------+-----------------------------------------------------------</span>
<span id="cb5-17">## &gt; -----</span>
<span id="cb5-18">##    Estimates |         .7   .4474236    -0.56   0.577           .2       </span>
<span id="cb5-19">## &gt;  2.45</span>
<span id="cb5-20">## -------------------------------------------------------------------------</span>
<span id="cb5-21">## &gt; -----</span>
<span id="cb5-22">## </span>
<span id="cb5-23">## </span>
<span id="cb5-24">## </span>
<span id="cb5-25">## -------------------------------------------------------------------------</span>
<span id="cb5-26">## &gt; -----</span>
<span id="cb5-27">##              | Risk Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Inte</span>
<span id="cb5-28">## &gt; rval]</span>
<span id="cb5-29">## -------------+-----------------------------------------------------------</span>
<span id="cb5-30">## &gt; -----</span>
<span id="cb5-31">##    Estimates |        1.2   .2482485     0.88   0.378           .8       </span>
<span id="cb5-32">## &gt;   1.8</span>
<span id="cb5-33">## -------------------------------------------------------------------------</span>
<span id="cb5-34">## &gt; -----</span>
<span id="cb5-35">## </span>
<span id="cb5-36">## </span>
<span id="cb5-37">## </span>
<span id="cb5-38">## -------------------------------------------------------------------------</span>
<span id="cb5-39">## &gt; -----</span>
<span id="cb5-40">##              | Risk Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Inte</span>
<span id="cb5-41">## &gt; rval]</span>
<span id="cb5-42">## -------------+-----------------------------------------------------------</span>
<span id="cb5-43">## &gt; -----</span>
<span id="cb5-44">##    Estimates |        1.3   .6337692     0.54   0.590           .5       </span>
<span id="cb5-45">## &gt;  3.38</span>
<span id="cb5-46">## -------------------------------------------------------------------------</span>
<span id="cb5-47">## &gt; -----</span>
<span id="cb5-48">## </span>
<span id="cb5-49">## </span>
<span id="cb5-50">## </span>
<span id="cb5-51">## -------------------------------------------------------------------------</span>
<span id="cb5-52">## &gt; -----</span>
<span id="cb5-53">##              | Risk Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Inte</span>
<span id="cb5-54">## &gt; rval]</span>
<span id="cb5-55">## -------------+-----------------------------------------------------------</span>
<span id="cb5-56">## &gt; -----</span>
<span id="cb5-57">##    Estimates |        3.6   1.870876     2.46   0.014          1.3    9.9</span>
<span id="cb5-58">## &gt; 69231</span>
<span id="cb5-59">## -------------------------------------------------------------------------</span>
<span id="cb5-60">## &gt; -----</span></code></pre></div></div>
</div>
<p>As we can see from the plot, it becomes fairly easy to tell which studies had greater precision and how their point estimates compare.</p>
</section>
<section id="example-5-meta-analysis-context" class="level3" data-number="5.5">
<h3 data-number="5.5" class="anchored" data-anchor-id="example-5-meta-analysis-context"><span class="header-section-number">5.5</span> Example 5: Meta-Analysis Context</h3>
<p>Lastly, here’s an example taken from Rothman et al.&nbsp;(2008), Figure 10.5:</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb6-1">* Get standard errors</span>
<span id="cb6-2">getregstats 0.87, <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">l</span>(0.70) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">model</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">or</span>)</span>
<span id="cb6-3"></span>
<span id="cb6-4">* Compare individual study vs meta-analysis</span>
<span id="cb6-5">cifunction 0.87 0.88, se(.0965065 .0658232) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">eform</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb6-6">    fig(xlab(.5(.1)1.3) <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Odds Ratio"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb6-7">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">legend</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(1 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Eisenberger et al (1998)"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb6-8">           <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(2 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Summary of 10 studies"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb6-9">           <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">ring</span>(0) <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">position</span>(11))) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb6-10">    sav(figdata, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span>)</span>
<span id="cb6-11">##              | Odds Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Inte</span>
<span id="cb6-12">## &gt; rval]</span>
<span id="cb6-13">## -------------+-----------------------------------------------------------</span>
<span id="cb6-14">## &gt; -----</span>
<span id="cb6-15">##    Estimates |        .87   .0965065    -1.26   0.209           .7    1.0</span>
<span id="cb6-16">## &gt; 81286</span>
<span id="cb6-17">## -------------------------------------------------------------------------</span>
<span id="cb6-18">## &gt; -----</span></code></pre></div></div>
</div>
</section>
</section>
<section id="output-variables" class="level2" data-number="6">
<h2 data-number="6" class="anchored" data-anchor-id="output-variables"><span class="header-section-number">6</span> Output Variables</h2>
<p>When we use <code>saving()</code>, cifunction stores the following variables:</p>
<table class="caption-top table">
<caption>Variables saved in output dataset</caption>
<thead>
<tr class="header">
<th>Variable</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>cilev</code></td>
<td>Confidence levels (0 to 99.99)</td>
</tr>
<tr class="even">
<td><code>plev</code></td>
<td>P-values (0.0001 to 1.0)</td>
</tr>
<tr class="odd">
<td><code>sval</code></td>
<td>S-values (Shannon information, see<span class="citation" data-cites="greenland2019valid"><sup>6</sup></span>)</td>
</tr>
<tr class="even">
<td><code>lcl#</code></td>
<td>Lower confidence limits for estimate #</td>
</tr>
<tr class="odd">
<td><code>ucl#</code></td>
<td>Upper confidence limits for estimate #</td>
</tr>
</tbody>
</table>
<div class="callout callout-style-default callout-note 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">
<span class="screen-reader-only">Note</span>S-Values
</div>
</div>
<div class="callout-body-container callout-body">
<p>S-values measure the information against a null hypothesis (or any other test hypothesis) in bits. An S-value of 4.32 corresponds to p=0.05 (roughly 4.3 bits of information against the null). See<span class="citation" data-cites="greenland2019valid"><sup>6</sup></span> for the details.</p>
</div>
</div>
</section>
<section id="best-practices" class="level2" data-number="7">
<h2 data-number="7" class="anchored" data-anchor-id="best-practices"><span class="header-section-number">7</span> Best Practices</h2>
<ol type="1">
<li><strong>Use the log scale</strong> for ratio measures (OR, RR, HR, IRR)</li>
<li><strong>Label the curves clearly</strong> when plotting more than one estimate</li>
<li><strong>Save the output data</strong> so that we can analyze it further or build custom plots</li>
<li><strong>Consider the degrees of freedom</strong> when the estimates come from a regression</li>
<li><strong>Look at the whole curve</strong> instead of focusing on any single cutoff</li>
</ol>
</section>
<section id="theoretical-foundation" class="level2" data-number="8">
<h2 data-number="8" class="anchored" data-anchor-id="theoretical-foundation"><span class="header-section-number">8</span> Theoretical Foundation</h2>
<p>CI-functions rest on the idea that statistical evidence is continuous, and that we lose something when we dichotomize it. As<span class="citation" data-cites="poole1987beyond"><sup>2</sup></span> argues:</p>
<blockquote class="blockquote">
<p>“The P-value function provides a convenient way to present the information in the data concerning the magnitude of an effect… [It] avoids the arbitrariness of any single significance level.”</p>
</blockquote>
<p>This also seems to fit with more recent calls to move beyond <em>P</em>-value thresholds<span class="citation" data-cites="wasserstein2019moving"><sup>7</sup></span>, since the curve presents the full gradient of statistical evidence.</p>
</section>
<section id="comparison-with-other-approaches" class="level2" data-number="9">
<h2 data-number="9" class="anchored" data-anchor-id="comparison-with-other-approaches"><span class="header-section-number">9</span> Comparison with Other Approaches</h2>
<table class="caption-top table">
<caption>Comparison of uncertainty visualization methods</caption>
<thead>
<tr class="header">
<th>Approach</th>
<th>Information Provided</th>
<th>Computational Complexity</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Single CI</td>
<td>One interval at one level</td>
<td>Low</td>
</tr>
<tr class="even">
<td>Multiple CIs</td>
<td>Discrete intervals</td>
<td>Low</td>
</tr>
<tr class="odd">
<td>CI-function</td>
<td>Continuous curve of all intervals</td>
<td>Low</td>
</tr>
<tr class="even">
<td>Bootstrap distribution</td>
<td>Empirical sampling distribution</td>
<td>High</td>
</tr>
<tr class="odd">
<td>Likelihood profile</td>
<td>Likelihood across parameter space</td>
<td>Medium-High</td>
</tr>
</tbody>
</table>
</section>
<section id="limitations" class="level2" data-number="10">
<h2 data-number="10" class="anchored" data-anchor-id="limitations"><span class="header-section-number">10</span> Limitations</h2>
<p>However, there are a few things that a CI-function cannot do for us:</p>
<ul>
<li>It assumes that the statistical model is correctly specified</li>
<li>It does not account for unmeasured confounding or bias</li>
<li>It cannot compensate for poor study design or execution</li>
<li>Interpreting it requires some understanding of continuous evidence</li>
</ul>
<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">
<span class="screen-reader-only">Warning</span>Model Assumptions
</div>
</div>
<div class="callout-body-container callout-body">
<p>CI-functions, like all frequentist intervals, are only valid to the extent that the underlying statistical model and its assumptions are appropriate for the data.</p>
</div>
</div>
</section>
<section id="citation" class="level2" data-number="11">
<h2 data-number="11" class="anchored" data-anchor-id="citation"><span class="header-section-number">11</span> Citation</h2>
<p><code>cifunction</code> is free research software. If you use it, please cite it as:</p>
<blockquote class="blockquote">
<p>Linden, A. (2019). CIFUNCTION: Stata module for computing and graphically displaying all possible confidence intervals around a point estimate. Statistical Software Components, Boston College Department of Economics.</p>
</blockquote>
</section>
<section id="author" class="level2" data-number="12">
<h2 data-number="12" class="anchored" data-anchor-id="author"><span class="header-section-number">12</span> Author</h2>
<p><strong>Ariel Linden</strong> President, Linden Consulting Group, LLC Email: alinden@lindenconsulting.org</p>
</section>
<section id="see-also" class="level2" data-number="13">
<h2 data-number="13" class="anchored" data-anchor-id="see-also"><span class="header-section-number">13</span> See Also</h2>
<ul>
<li><code>getregstats</code> (SSC): Helper for obtaining standard errors</li>
<li><code>niceloglabels</code> (SSC): Improved logarithmic axis labels</li>
<li><code>concurve</code> (R package): Similar functionality in R</li>
</ul>
</section>
<section id="references" class="level2" data-number="14">
<h2 data-number="14" class="anchored" data-anchor-id="references"><span class="header-section-number">14</span> References</h2>
<div id="refs" class="references csl-bib-body" data-entry-spacing="2" data-line-spacing="2">
<div id="ref-birnbaum1961confidence" class="csl-entry">
1. Birnbaum A. (1961). <span>“Confidence curves: An omnibus technique for estimation and testing statistical hypotheses.”</span> <em>Journal of the American Statistical Association</em>. <strong>56</strong>:246–249.
</div>
<div id="ref-poole1987beyond" class="csl-entry">
2. Poole C. (1987). <span>“Beyond the confidence interval.”</span> <em>American Journal of Public Health</em>. <strong>77</strong>:195–199.
</div>
<div id="ref-miettinen1985theoretical" class="csl-entry">
3. Miettinen OS. (1985). <span>“Theoretical epidemiology: Principles of occurrence research in medicine.”</span> New York: John Wiley &amp; Sons.
</div>
<div id="ref-folks1981ideas" class="csl-entry">
4. Folks JL. (1981). <span>“Ideas of statistics.”</span> New York: John Wiley &amp; Sons.
</div>
<div id="ref-xieConfidenceDistributionFrequentist2013" class="csl-entry">
5. Xie M, Singh K. (2013). <span>“Confidence <span>Distribution</span>, the <span>Frequentist Distribution Estimator</span> of a <span>Parameter</span>: <span>A Review</span>.”</span> <em>International Statistical Review</em>. <strong>81</strong>:3–39. doi: <a href="https://doi.org/10.1111/insr.12000">10.1111/insr.12000</a>.
</div>
<div id="ref-greenland2019valid" class="csl-entry">
6. Greenland S. (2019). <span>“Valid p-values behave exactly as they should: Some misleading criticisms of p-values and their resolution with s-values.”</span> <em>The American Statistician</em>. <strong>73</strong>:106–114. doi: <a href="https://doi.org/10.1080/00031305.2018.1529625">10.1080/00031305.2018.1529625</a>.
</div>
<div id="ref-wasserstein2019moving" class="csl-entry">
7. Wasserstein RL, Schirm AL, Lazar NA. (2019). <span>“Moving to a world beyond "p &lt; 0.05".”</span> <em>The American Statistician</em>. <strong>73</strong>:1–19. doi: <a href="https://doi.org/10.1080/00031305.2019.1583913">10.1080/00031305.2019.1583913</a>.
</div>
</div>
<hr>
</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section id="appendix-technical-details" class="level2 appendix" data-number="15"><h2 class="anchored quarto-appendix-heading"><span class="header-section-number">15</span> Appendix: Technical Details</h2><div class="quarto-appendix-contents">

<section id="mathematical-formulation" class="level3" data-number="15.1">
<h3 data-number="15.1" class="anchored" data-anchor-id="mathematical-formulation"><span class="header-section-number">15.1</span> Mathematical Formulation</h3>
<p>For a normally distributed estimator <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Ctheta%7D"> with standard error <img src="https://latex.codecogs.com/png.latex?SE(%5Chat%7B%5Ctheta%7D)">, the confidence limits at level <img src="https://latex.codecogs.com/png.latex?(1-%5Calpha)"> are:</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Ctheta%7D%20%5Cpm%20z_%7B1-%5Calpha/2%7D%20%5Ccdot%20SE(%5Chat%7B%5Ctheta%7D)"></p>
<p>The CI-function plots these limits across all values of <img src="https://latex.codecogs.com/png.latex?%5Calpha%20%5Cin%20%5B0,%201%5D">.</p>
<p>For t-distributed estimators (when degrees of freedom are specified):</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Ctheta%7D%20%5Cpm%20t_%7B1-%5Calpha/2,%20df%7D%20%5Ccdot%20SE(%5Chat%7B%5Ctheta%7D)"></p>
</section>
<section id="exponentiated-coefficients" class="level3" data-number="15.2">
<h3 data-number="15.2" class="anchored" data-anchor-id="exponentiated-coefficients"><span class="header-section-number">15.2</span> Exponentiated Coefficients</h3>
<p>When <code>eform</code> is specified, computations occur on the log scale:</p>
<ol type="1">
<li>Transform: <img src="https://latex.codecogs.com/png.latex?%5Clog(%5Chat%7B%5Ctheta%7D)"> with <img src="https://latex.codecogs.com/png.latex?SE(%5Clog(%5Chat%7B%5Ctheta%7D))"></li>
<li>Compute CI limits on log scale</li>
<li>Back-transform: <img src="https://latex.codecogs.com/png.latex?%5Cexp(limits)"></li>
</ol>
<p>Thus, the intervals are symmetric on the log scale and keep their proper geometric interpretation.</p>
<hr>
<p><strong>Last updated:</strong> 2026-10-01 <strong>Source code:</strong> Available on request <strong>License:</strong> Free for academic and non-commercial use</p>


<!-- -->

</section>
</div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@article{rafi2024,
  author = {Rafi, Zad and R, Zad},
  title = {Computing {Confidence} {Interval} {Functions} with
    Cifunction},
  journal = {Less Likely},
  date = {2024-03-23},
  url = {https://lesslikely.com/statistics/cifunction},
  langid = {en-US},
  abstract = {The cifunction package for Stata computes and plots all
    possible confidence intervals around a point estimate, which gives
    us what is known as a confidence interval function (also called a
    confidence curve, P-value function, or consonance interval). Here,
    we go through how to use it, since the curve tells us more than a
    single interval at one level by showing the full range of values
    that are compatible with the data at every confidence level.}
}
</code></pre></div></section></div> ]]></description>
  <category>statistics</category>
  <category>stata</category>
  <category>confidence intervals</category>
  <category>data visualization</category>
  <category>statistical methods</category>
  <guid>https://lesslikely.com/statistics/cifunction.html</guid>
  <pubDate>Sat, 23 Mar 2024 04:00:00 GMT</pubDate>
  <media:content url="https://lesslikely.com/images/HomeLogo-static.png" medium="image" type="image/png" height="92" width="144"/>
</item>
<item>
  <title>Your Models Are Neither Useful Nor Approximate</title>
  <dc:creator>Zad Rafi</dc:creator>
  <dc:creator>Sir Panda</dc:creator>
  <link>https://lesslikely.com/statistics/assumptions.html</link>
  <description><![CDATA[ 





<hr>
<blockquote class="blockquote">
<p><em>If the assumptions of a model are not derived from theory, and if predictions are not tested against reality, then deductions from the model must be quite shaky. However, without the model, the data cannot be used to answer the research question.</em> <strong><em>Indeed, the research hypothesis may not really be translatable into an empirical claim except as a statement about nominal significance levels of coefficients in a model.</em></strong> - <a href="https://www.jstor.org/stable/270939">David Freedman</a>, 1991</p>
</blockquote>
<hr>
<section id="statistical-models-as-approximations" class="level2">
<h2 class="anchored" data-anchor-id="statistical-models-as-approximations">Statistical Models as Approximations</h2>
<hr>
<p>Scientific inference is a highly complex process often accompanied by numerical outputs from statistical models. To some, such outputs are not convincing as they believe that anyone can lie with numbers, but the reality is that it is a lot easier to lie without them, making them crucial because if deployed correctly, they may be close approximations to reality. The presence of a statistical model can allow others to view an answer to a complex question from a numerical standpoint that many may be able to verify.</p>
<hr>
<p><img src="https://lesslikely.com/images/approximation.png" class="img-fluid"></p>
<hr>
<p>Unfortunately, there are rampant issues in the building, reporting, and interpretation of such statistical models, and such issues can lead to devastating policies. We have elsewhere reviewed proposals to reform terminology and improve interpretations of conventional statistics by emphasizing logical and information concepts over probability concepts (1–3), as the latter has continued to confuse even well-credentialed statisticians familiar with the misinterpretations.</p>
<hr>
</section>
<section id="what-goes-into-a-model" class="level2">
<h2 class="anchored" data-anchor-id="what-goes-into-a-model">What Goes into a Model?</h2>
<hr>
<p>We here focus on how common descriptions of statistical outputs can be technically accurate yet still mislead when there is considerable uncertainty about what are known as background or auxiliary assumptions. Such uncertainty is typical in many contexts, where assumptions may include both mathematical and methodological ones:</p>
<p>For example, in the popular regression book by Gelman, the following assumptions are given for regression models in decreasing order of importance:</p>
<hr>
<ul>
<li>validity</li>
</ul>
<hr>
<ul>
<li>additivity and linearity</li>
</ul>
<hr>
<ul>
<li>independence of errors</li>
</ul>
<hr>
<ul>
<li>equal variance of errors</li>
</ul>
<hr>
<ul>
<li>normality of errors</li>
</ul>
<hr>
<p>This is typical to see in many regression modeling books, but important methodological assumptions underlying the model are rarely discussed such as:</p>
<hr>
<ul>
<li>patient outcomes are independent</li>
</ul>
<hr>
<ul>
<li>interactions and trends follow the regression model used for analysis (e.g., linear or logistic)</li>
</ul>
<hr>
<ul>
<li>no uncontrolled confounding</li>
</ul>
<hr>
<ul>
<li>subject-selection bias</li>
</ul>
<hr>
<ul>
<li>measurement error</li>
</ul>
<hr>
<ul>
<li>sparse-data bias</li>
</ul>
<hr>
<ul>
<li>no selective reporting of results* based on their P-values, interval estimates, or any other output – or if there is such selection, any bias it could produce has been adjusted for (or blocked) in the computation and presentation of the final results.</li>
</ul>
<hr>
<figure class="figure">
<p><img src="https://res.cloudinary.com/less-likely/image/upload/v1605000180/Site/pvalueassumptions.svg" alt="P-value assumptions" width="800" style="cursor: zoom-in" class="figure-img"></p>
<figcaption>
Conditional versus unconditional interpretations of P-values, S-values, and compatibility intervals (CIs). (A) Conditional interpretation, in which background model assumptions, such as no systematic error, are assumed to be correct; thus,the information provided by the P-value and S-value is targeted towards the test hypothesis. (B)Unconditional interpretation, in which no aspect of the statistical model is assumed to be correct; thus,the information provided by the P-value and S-value is targeted toward the entire test model.
</figcaption>
</figure>
<hr>
<p>In addition to these general statistical and methodological assumptions, many assume that the statistical model being fit is answering a proper scientific question that has been translated into a statistical one, with assumptions that match or approximate reality. When there is a disconnect between the scientific question and the statistical one being answered by the model, the analyst is committing a type-III error, and will produce statistical outputs with of little use, unless the assumption violations of the chosen and reported are interrogated/varied and considered in the overall analysis.</p>
<p>Many are not aware of what a type-III error is due to the focus on type-I and type-II errors. I paste the following definition from the APA dictionary, which I found myself agreeing with:</p>
<hr>
<blockquote class="blockquote">
<p>Type-III Error: the error that occurs when there is a discrepancy between the research focus and the hypothesis actually tested. For example, a Type III error would have happened if a researcher collected data on individual differences within a sample and determined the causes of variation but the question of interest concerned differences between populations. In other words, a Type III error involves providing the right answer for the wrong question. Also called Type 0 error.</p>
</blockquote>
<hr>
</section>
<section id="violation-of-assumptions" class="level2">
<h2 class="anchored" data-anchor-id="violation-of-assumptions">Violation of Assumptions</h2>
<hr>
<p>Misleading interpretations arise because the descriptions of such statistical outputs are conditional on such assumptions (i.e., they treat them as given/being true), and so do not factor uncertainty regarding the assumptions into their assessments. While various risk-assessment methods can incorporate additional sources in quantified uncertainties, such methods demand considerably more skilled user input than do conventional regression methods (5–9) and still do not account for unquantified sources of uncertainty. We thus present a more direct and nontechnical approach based on logic and associated language to honor assumption uncertainty, called deconditioning.</p>
<p>For example, suppose that a model assumes independence, a common assumption in many statistical models, but this violated due to the presence of a correlation, this will lead to P-values that are invalid, demonstrable by their failure to achieve asymptotic uniformity.</p>
<p>For example, a model that is approximately correct will generate P-values that are asymptotically uniform (a characteristic used to assess the validity of P-values)</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">#' @title Simulation of valid P-values where test hypothesis is true</span></span>
<span id="cb1-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param X The first variable we are simulating</span></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param Y The second variable we are simulating</span></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param n.sim # The number of simulations</span></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param t The object storing the t-test results</span></span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param t.sim # Empty numeric vector to contain values</span></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param n.samp # Sample size in each group</span></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @NOTE The null hypothesis does not have to be 0, it can be any value.</span></span>
<span id="cb1-9"></span>
<span id="cb1-10">n.sim <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="cb1-11">t.sim <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.sim)</span>
<span id="cb1-12">n.samp <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;">1000</span></span>
<span id="cb1-13"></span>
<span id="cb1-14"><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.sim) {</span>
<span id="cb1-15">  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>(n.samp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</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;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-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;">rnorm</span>(n.samp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</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;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-17">  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, Y)</span>
<span id="cb1-18">  t <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>(X, Y,</span>
<span id="cb1-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</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;">paired =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb1-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var.equal =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df)</span>
<span id="cb1-21">  t.sim[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> t[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]]}</span></code></pre></div></div>
</div>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/assumptions_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">#' @title Simulation of invalid P-values where test hypothesis is false</span></span>
<span id="cb2-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param n_simulations # The number of simulations</span></span>
<span id="cb2-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param p_values The object storing the t-test results</span></span>
<span id="cb2-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param p_value_data # Empty numeric vector to contain values</span></span>
<span id="cb2-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param n_subjects # Sample size in each group</span></span>
<span id="cb2-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param correlation # correlation to violate independence</span></span>
<span id="cb2-7"></span>
<span id="cb2-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(MASS)</span>
<span id="cb2-9">n_simulations <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;">1000</span></span>
<span id="cb2-10">n_subjects <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-11">correlation <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>
<span id="cb2-12"></span>
<span id="cb2-13">generate_correlated_data <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>(n_subjects, correlation) {</span>
<span id="cb2-14">    Sigma <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;">matrix</span>(correlation, n_subjects, n_subjects) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-15">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diag</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> correlation, n_subjects)</span>
<span id="cb2-16">    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;">mvrnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</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;">mu =</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>, n_subjects),</span>
<span id="cb2-17">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Sigma =</span> Sigma)</span>
<span id="cb2-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(data)</span>
<span id="cb2-19">}</span>
<span id="cb2-20">run_simulation <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>(n_subjects, correlation) {</span>
<span id="cb2-21">    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;">generate_correlated_data</span>(n_subjects, correlation)</span>
<span id="cb2-22">    t_test_result <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>(data[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, ], data[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, ])</span>
<span id="cb2-23">    t_test_p_value <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> t_test_result<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value</span>
<span id="cb2-24">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(t_test_p_value)</span>
<span id="cb2-25">}</span>
<span id="cb2-26">p_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;">replicate</span>(n_simulations, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">run_simulation</span>(n_subjects,</span>
<span id="cb2-27">    correlation))</span>
<span id="cb2-28">p_value_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>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PValue =</span> p_values)</span></code></pre></div></div>
</div>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/assumptions_files/figure-html/unnamed-chunk-7-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>Deconditioning shifts the logical status of assumptions in the description of results from what is assumed as given (conditioned on) to an integral part of what is being checked by common statistics. This shift makes clear that the results might be explained by violations of background assumptions rather than, or in addition to, failure of a targeted hypothesis. Such deconditioning does not change calculations; hence it does not change any P-value, interval estimate, or posterior distribution. Instead, it provides a different interpretation of these statistics, one arising naturally in thorough contextual discussions, but which deserves more emphasis in basic statistical practice, including teaching and presentations.</p>
<p>In philosophical accounts of theory testing, it is well recognized that an apparent violations of a hypothesis may instead be due to violation of background or auxiliary assumptions (10–13). Among these assumptions are researcher competence and integrity in the conduct and reporting of statistical analyses which have come under scrutiny in the “replication crisis”) as well as common statistical assumptions such as linearity, outcome independence, and effect homogeneity, and methodological assumptions such as no uncontrolled confounding or selection bias. Perhaps because of this generality, we have found that our recommendation to decondition inferences (present inferences using an unconditional interpretation) (1,3) is often difficult for statistically sophisticated readers to comprehend or accept, and is even resisted, misunderstood, and misrepresented by some reviewers</p>
<hr>
<p><strong>See also:</strong> <a href="../statistics/sensitivity.html"><em>What Makes a Sensitivity Analysis?</em></a> — the hub piece tying this material to the broader cluster on assumptions, robustness, and what happens when models bend.</p>


<!-- -->

</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{rafi2024,
  author = {Rafi, Zad and Panda, Sir},
  title = {Your {Models} {Are} {Neither} {Useful} {Nor} {Approximate}},
  date = {2024-01-01},
  url = {https://lesslikely.com/statistics/assumptions},
  langid = {en-US},
  abstract = {A discussion about models and the assumptions that
    underlie them.}
}
</code></pre></div></section></div> ]]></description>
  <category>statistics</category>
  <guid>https://lesslikely.com/statistics/assumptions.html</guid>
  <pubDate>Mon, 01 Jan 2024 05:00:00 GMT</pubDate>
  <media:content url="https://lesslikely.com/images/approximation.png" medium="image" type="image/png" height="89" width="144"/>
</item>
<item>
  <title>Using Stata: Producing Consonance Functions</title>
  <dc:creator>Zad Rafi</dc:creator>
  <dc:creator>Sir Panda</dc:creator>
  <link>https://lesslikely.com/statistics/stata.html</link>
  <description><![CDATA[ 





<hr>
<p>Although <code>concurve</code> was originally designed to be used in <code>R</code>, it is possible to achieve very similar results in <code>Stata</code>. We can use some datasets that are built into <code>Stata</code> to show how to achieve this. I’ll use the <code>Statamarkdown</code> R package so that I can obtain Stata outputs using RMarkdown via my Stata 16 package.</p>
<p>First, let’s load the <em>auto2</em> dataset which contains data about cars and their characteristics.</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb1-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">sysuse</span> auto2</span>
<span id="cb1-2">#&gt; (1978 automobile <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">data</span>)</span></code></pre></div></div>
</div>
<hr>
<p>Browse the data set in your data browser to get more familiar with some of the variables. Let’s say we’re interested in the relationship between miles per gallon and price. We could fit a very simple linear model to assess that relationship.</p>
<p>First, let’s visualize the data with a scatter plot.</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb2-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">sysuse</span> auto2</span>
<span id="cb2-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">scatter</span> price mpg, mcolor(<span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">dkorange</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">scale</span>(0.70)</span>
<span id="cb2-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">graph</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">export</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scatter.svg"</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span></span>
<span id="cb2-4">#&gt; (1978 automobile <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">data</span>)</span>
<span id="cb2-5">#&gt; </span>
<span id="cb2-6">#&gt; </span>
<span id="cb2-7">#&gt; file <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">scatter</span>.svg saved <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> SVG <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">format</span></span></code></pre></div></div>
</div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/scatter.svg" style="width:150.0%;height:150.0%" class="figure-img"></p>
<figcaption>scatter</figcaption>
</figure>
</div>
<p>That’s what our data looks like. Clearly there seems to be an inverse relationship between miles per gallon and price.</p>
<p>Now we could fit a very simple linear model with miles per gallon being the predictor and price being the outcome and get some estimates of the relationship.</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb3-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">sysuse</span> auto2</span>
<span id="cb3-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">regress</span> price mpg</span>
<span id="cb3-3">#&gt; (1978 automobile <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">data</span>)</span>
<span id="cb3-4">#&gt; </span>
<span id="cb3-5">#&gt; </span>
<span id="cb3-6">#&gt;       Source |       SS           df       MS      Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span>   =        74</span>
<span id="cb3-7">#&gt; -------------+----------------------------------   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">F</span>(1, 72)        =     20.26</span>
<span id="cb3-8">#&gt;        Model |   139449474         1   139449474   Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">F</span>        =    0.0000</span>
<span id="cb3-9">#&gt;     Residual |   495615923        72  6883554.48   R-squared       =    0.2196</span>
<span id="cb3-10">#&gt; -------------+----------------------------------   Adj R-squared   =    0.2087</span>
<span id="cb3-11">#&gt;        Total |   635065396        73  8699525.97   Root MSE        =    2623.7</span>
<span id="cb3-12">#&gt; </span>
<span id="cb3-13">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb3-14">#&gt;        price | Coefficient  Std. err.      t    P&gt;|t|     [95% conf. interval]</span>
<span id="cb3-15">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb3-16">#&gt;          mpg |  -238.8943   53.07669    -4.50   0.000    -344.7008   -133.0879</span>
<span id="cb3-17">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   11253.06   1170.813     9.61   0.000     8919.088    13587.03</span>
<span id="cb3-18">#&gt; ------------------------------------------------------------------------------</span></code></pre></div></div>
</div>
<hr>
<p>That’s what our output looks like.</p>
<p>Our output also gives us 95% consonance (confidence) intervals by default. But suppose we wished to fit a fractional polynomial model and graph it and get the confidence bands, here’s what we would do.</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb4-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">sysuse</span> auto2</span>
<span id="cb4-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">mfp</span>: <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">glm</span> price mpg</span>
<span id="cb4-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">twoway</span> (fpfitci price mpg, estcmd(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">glm</span>) fcolor(<span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">dkorange</span>%20) alcolor(%40))  || <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">scatter</span> price mpg, mcolor(<span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">dkorange</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">scale</span>(0.75)</span>
<span id="cb4-4"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">graph</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">export</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mfp.svg"</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span></span>
<span id="cb4-5">#&gt; (1978 automobile <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">data</span>)</span>
<span id="cb4-6">#&gt; </span>
<span id="cb4-7">#&gt; </span>
<span id="cb4-8">#&gt; Deviance <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">model</span> with <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">all</span> terms untransformed = 1373.079, 74 observations</span>
<span id="cb4-9">#&gt; </span>
<span id="cb4-10">#&gt; Variable     Model (vs.)   Deviance  Dev <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diff</span>.   P      Powers   (vs.)</span>
<span id="cb4-11">#&gt; ----------------------------------------------------------------------</span>
<span id="cb4-12">#&gt; mpg          Lin.   FP2    1373.079    19.565  0.000+   1         -2 -2</span>
<span id="cb4-13">#&gt;              FP1           1356.927     3.413  0.182    -2        </span>
<span id="cb4-14">#&gt;              Final         1356.927                     -2</span>
<span id="cb4-15">#&gt; </span>
<span id="cb4-16">#&gt; </span>
<span id="cb4-17">#&gt; Transformations <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> covariates:</span>
<span id="cb4-18">#&gt; </span>
<span id="cb4-19">#&gt; -&gt; <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">gen</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">double</span> Impg__1 = X^-2-.2204707671 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">e</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">sample</span>) </span>
<span id="cb4-20">#&gt;    (where: X = mpg/10)</span>
<span id="cb4-21">#&gt; </span>
<span id="cb4-22">#&gt; Final multivariable fractional polynomial <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">model</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> price</span>
<span id="cb4-23">#&gt; --------------------------------------------------------------------</span>
<span id="cb4-24">#&gt;     Variable |    -----Initial-----          -----Final-----</span>
<span id="cb4-25">#&gt;              |   df     Select   Alpha    Status    df    Powers</span>
<span id="cb4-26">#&gt; -------------+------------------------------------------------------</span>
<span id="cb4-27">#&gt;          mpg |    4     1.0000   0.0500     <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span>      2     -2</span>
<span id="cb4-28">#&gt; --------------------------------------------------------------------</span>
<span id="cb4-29">#&gt; </span>
<span id="cb4-30">#&gt; Generalized linear models                         Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span>   =         74</span>
<span id="cb4-31">#&gt; Optimization     : ML                             Residual df     =         72</span>
<span id="cb4-32">#&gt;                                                   Scale parameter =    5533697</span>
<span id="cb4-33">#&gt; Deviance         =  398426217.4                   (1/df) Deviance =    5533697</span>
<span id="cb4-34">#&gt; Pearson          =  398426217.4                   (1/df) Pearson  =    5533697</span>
<span id="cb4-35">#&gt; </span>
<span id="cb4-36">#&gt; Variance <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>: <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">V</span>(u) = 1                       [Gaussian]</span>
<span id="cb4-37">#&gt; Link <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>    : g(u) = u                       [Identity]</span>
<span id="cb4-38">#&gt; </span>
<span id="cb4-39">#&gt;                                                   AIC             =    18.3909</span>
<span id="cb4-40">#&gt; Log likelihood   = -678.4632599                   BIC             =   3.98e+08</span>
<span id="cb4-41">#&gt; </span>
<span id="cb4-42">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb4-43">#&gt;              |                 OIM</span>
<span id="cb4-44">#&gt;        price | Coefficient  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">std</span>. err.      z    P&gt;|z|     [95% conf. interval]</span>
<span id="cb4-45">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb4-46">#&gt;      Impg__1 |   13163.85   2013.016     6.54   0.000      9218.41    17109.29</span>
<span id="cb4-47">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   5538.395   289.7737    19.11   0.000     4970.449    6106.341</span>
<span id="cb4-48">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb4-49">#&gt; Deviance = 1356.927.</span>
<span id="cb4-50">#&gt; </span>
<span id="cb4-51">#&gt; </span>
<span id="cb4-52">#&gt; file <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">mfp</span>.svg saved <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> SVG <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">format</span></span></code></pre></div></div>
</div>
<hr>
<p>That’s what our model looks graphed.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/mfp.svg" style="width:150.0%;height:150.0%" class="figure-img"></p>
<figcaption>fractional polynomial model</figcaption>
</figure>
</div>
<p>Now suppose we got a single estimate (point or interval) for a parameter, and we wanted all the intervals for it at every level.</p>
<p>Here’s the code that we’ll be using to achieve that in Stata.</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<pre><code>#&gt; no; dataset in memory has changed since last saved
#&gt; r(4);
#&gt; 
#&gt; r(4);</code></pre>
</div>
<hr>
<p>That’s a lot and may seem intimidating at first, but I’ll explain it line by line.</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb6-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">postfile</span> topost <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">level</span> pvalue svalue lointerval upinterval <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">using</span> my_new_data, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span></span>
<span id="cb6-2">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb6-3">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span></code></pre></div></div>
</div>
<hr>
<p>“<strong>postfile</strong>” is the command that will be responsible for pasting the data from our overall loop into a new dataset. Here, we are telling <code>Stata</code> that the internal <code>Stata</code> memory used to hold these results (the post) will be named “<strong>topost</strong>” and that it will have five variables, “<strong>level</strong>”, “<strong>pvalue</strong>”, “<strong>svalue</strong>”, “<strong>lointerval</strong>”, and “<strong>upinterval</strong>.”</p>
<ul>
<li><p>“<strong>level</strong>” will contain the consonance level that corresponds to the limits of the interval, with “<strong>lointerval</strong>” being the lower bound of the interval and “<strong>upinterval</strong>” being the upper bound.</p></li>
<li><p>“<strong>pvalue</strong>”is computed by taking 1 - “<strong>level</strong>”, which is alpha.</p></li>
<li><p>“<strong>svalue</strong>”is computed by taking the <img src="https://latex.codecogs.com/png.latex?-log_%7B2%7D"> of the computed P-value, and this column will be used to plot the surprisal function.</p></li>
<li><p>“<strong>my_new_data</strong>” is the filename that we’ve assigned to our new dataset.</p></li>
<li><p>“<strong>replace</strong>” indicates that if there is an existing filename that already exists, we’re willing to relace it.</p></li>
</ul>
<p>Here are the next few major lines</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<pre><code>#&gt; no; dataset in memory has changed since last saved
#&gt; r(4);
#&gt; 
#&gt; 
#&gt; post topost not found
#&gt; r(111);
#&gt; 
#&gt; r(111);</code></pre>
</div>
<hr>
<p>The command “<strong>forvalues</strong>” is responsible for taking a set of numbers that we provide it, and running the contents within the braces through those numbers. So here, we’ve set the local macro “<strong>i</strong>” to contain numbers between 10 and 99.99 for our consonance levels. Why 10? <code>Stata</code> cannot compute consonance intervals lower than 10%.</p>
<p>Our next line contains the actual contents of what we want to do. Here, it says that we will run a simple linear regression where mpg is the predictor and where price is the outcome, and that the outputs for each loop will be suppressed, hence the “<strong>quiet</strong>.”</p>
<p>Then, we have the command “<strong>level</strong>” with the local macro “<strong>i</strong>” inside of it. As you may already know, “<strong>level</strong>” dictates the consonance level that <code>Stata</code> provides us. By default, this is set to 95%, but here, we’ve set it “<strong>i</strong>”, which we established via “<strong>forvalues</strong>” as being set to numbers between 10 and 99.</p>
<p>The next line two lines</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<pre><code>#&gt; no; dataset in memory has changed since last saved
#&gt; r(4);</code></pre>
</div>
<hr>
<p>indicate that we will take variables of a certain class r(), (this class contains the interval bounds we need) and place them within a matrix called E. Then we will list the contents of this matrix.</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb9-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">post</span> topost (<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`i'</span>) (1-<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`i'</span>/100) ( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(1-<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`i'</span>/100)/<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(2) * -1) (E[5,1]) (E[6,1])</span>
<span id="cb9-2">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb9-3">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span>
<span id="cb9-4">#&gt; </span>
<span id="cb9-5">#&gt; </span>
<span id="cb9-6">#&gt; <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">post</span> topost <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> found</span>
<span id="cb9-7">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(111);</span>
<span id="cb9-8">#&gt; </span>
<span id="cb9-9">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(111);</span></code></pre></div></div>
</div>
<hr>
<p>From the contents of this matrix list, we will take the estimates from the <em>fifth</em> and <em>sixth</em> rows (look at the last two paranthesis of this line of code above and then the image below) in the <em>first</em> column which contain our consonance limits, with the fifth row containing the lower bound of the interval and the sixth containing the upper bound.</p>
<figure class="figure">
<p><img src="https://lesslikely.com/images/matrix.png" width="700" style="cursor: zoom-in" class="figure-img"></p>
<figcaption>
Trace plot of imputed datasets.
</figcaption>
</figure>
<figure class="figure">
<p><img src="https://lesslikely.com/images/matrix.png" width="700" style="cursor: zoom-in" class="figure-img"></p>
<figcaption>
Trace plot of imputed datasets.
</figcaption>
</figure>
<p><img src="https://lesslikely.com/images/matrix.png" style="width:150.0%;height:150.0%"></p>
<p>We will place the contents from the fifth row into the second variable we set originally for our new dataset, which was “<strong>lointerval</strong>.” The contents of the sixth row will be placed into “<strong>upinterval</strong>.”</p>
<p>All potential values of “<strong>i</strong>” (10-99) will be placed into the first variable that we set, “<strong>level</strong>”. From this first variable, we can compute the second variable we set up, which was “<strong>Pvalue</strong>” and we’ve done that here by subtracting “<strong>level</strong>” from 1 and then dividing the whole equation by 100, so that our P-value can be on the proper scale. Our third variable, which is the longest, computes the “<strong>Svalue</strong>” by using the previous variable, the “<strong>Pvalue</strong>” and taking the <img src="https://latex.codecogs.com/png.latex?-log_%7B2%7D"> of it.</p>
<p>The relationships between the variables on this line and the variables we set up in the very first line are dictated by the order of the commands we have set, and therefore they correspond to the same order.</p>
<p>“post topost” is writing the results from each loop as new observations in this data structure.</p>
<p>With that, our loop has concluded, and we can now tell <code>Stata</code> that “post” is no longer needed</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb10-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">postclose</span> topost</span>
<span id="cb10-2">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb10-3">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span>
<span id="cb10-4">#&gt; </span>
<span id="cb10-5">#&gt; </span>
<span id="cb10-6">#&gt; <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">post</span> topost <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> found</span>
<span id="cb10-7">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(111);</span>
<span id="cb10-8">#&gt; </span>
<span id="cb10-9">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(111);</span></code></pre></div></div>
</div>
<p>We then tell <code>Stata</code> to clear its memory to make room for the new dataset we just created and we can list the contents of this new dataset.</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb11-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">use</span> my_new_data, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb11-2"><span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">list</span></span>
<span id="cb11-3">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb11-4">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span></code></pre></div></div>
</div>
<p>Now we have an actual dataset with all the consonance intervals at all the levels we wanted, ranging from 10% all the way up to 99%.</p>
<p>In order to get a function, we’ll need to be able to graph these results, and that can be tricky since for each observation we have one y value (the consonance level), and two x values, the lower bound of the interval and the upper bound of the interval.</p>
<p>So a typical scatterplot will not work, since <code>Stata</code> will only accept one x value. To bypass this, we’ll have to use a paired-coordinate scatterplot which will allow us to plot two different y variables and two different x variables.</p>
<p>Of course, we don’t need two y variables, so we can set both options to the variable “<strong>level</strong>”, and then we can set our first x variable to “<strong>lointerval</strong>” and the second x variable to “<strong>upinterval</strong>.”</p>
<p>This can all be done with the following commands, which will also allow us to set the title and subtitle of the graph, along with the titles of the axes.</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb12-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">twoway</span> (pcscatter <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">level</span> lointerval <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">level</span> upinterval), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb12-2"><span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">ytitle</span>(Consonance Level (%)) <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xtitle</span>(Consonance Limits) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb12-3"><span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span>(Consonance Curve) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb12-4"><span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">subtitle</span>(A <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> comprised <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> several consonance intervals <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">at</span> various <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">levels</span>.)</span>
<span id="cb12-5">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb12-6">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span>
<span id="cb12-7">#&gt; </span>
<span id="cb12-8">#&gt; </span>
<span id="cb12-9">#&gt; <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">variable</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">level</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> found</span>
<span id="cb12-10">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(111);</span>
<span id="cb12-11">#&gt; </span>
<span id="cb12-12">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(111);</span></code></pre></div></div>
</div>
<hr>
<p>However, I would recommend using the menu to customize the plots as much as possible. Simply go to the <strong>Graphics</strong> menu and select <strong>Twoway Graphs</strong>. Then create a new plot definition, and select the <strong>Advanced plots</strong> and choose a paired coordinate scatterplot and fill in the y variables, both of which will be “<strong>levels</strong>” and the x variables, which will be “<strong>lointerval</strong>” and “<strong>upinterval</strong>”.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-20-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img"></p>
</figure>
</div>
<p>So now, here’s what our confidence/consonance function looks like.</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb13-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb13-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">sysuse</span> auto2</span>
<span id="cb13-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">postfile</span> topost <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">level</span> pvalue svalue lointerval upinterval <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">using</span> my_new_data, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span></span>
<span id="cb13-4"></span>
<span id="cb13-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">forvalues</span> i = 10/99.9 {</span>
<span id="cb13-6">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">quietly</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">regress</span> price <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">weight</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">level</span>(<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`i'</span>)</span>
<span id="cb13-7">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span> E = <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">table</span>)</span>
<span id="cb13-8">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">quietly</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">list</span> E</span>
<span id="cb13-9">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">post</span> topost (<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`i'</span>) (1-<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`i'</span>/100) ( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(1-<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`i'</span>/100)/<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(2) * -1) (E[5,1]) (E[6,1])</span>
<span id="cb13-10">    }</span>
<span id="cb13-11"></span>
<span id="cb13-12"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">postclose</span> topost</span>
<span id="cb13-13"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">use</span> my_new_data, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb13-14"></span>
<span id="cb13-15"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">twoway</span> (pcscatter pvalue lointerval pvalue upinterval, mcolor(<span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">maroon</span>)), <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">ytitle</span>(Consonance Level (%)) <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xtitle</span>(Consonance Limits) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">scale</span>(0.75) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb13-16"><span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span>(Consonance Curve) <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">subtitle</span>(A <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> comprised <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> several consonance intervals <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">at</span> various <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">levels</span>.)</span>
<span id="cb13-17"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">graph</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">export</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"confidence.svg"</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span></span>
<span id="cb13-18">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb13-19">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span>
<span id="cb13-20">#&gt; </span>
<span id="cb13-21">#&gt; </span>
<span id="cb13-22">#&gt; </span>
<span id="cb13-23">#&gt; (1978 automobile <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">data</span>)</span>
<span id="cb13-24">#&gt; </span>
<span id="cb13-25">#&gt; </span>
<span id="cb13-26">#&gt; </span>
<span id="cb13-27">#&gt; </span>
<span id="cb13-28">#&gt; </span>
<span id="cb13-29">#&gt; </span>
<span id="cb13-30">#&gt; file confidence.svg saved <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> SVG <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">format</span></span></code></pre></div></div>
</div>
<hr>
<p><img src="https://lesslikely.com/images/confidence.svg" class="img-fluid"></p>
<hr>
<p>Pretty neat, eh? And below is what our surprisal function looks like, which is simply the <img src="https://latex.codecogs.com/png.latex?-%5Clog_%7B2%7D">(<em>p</em>) transformation of the observed P-value. For a more comprehensive discussion on surprisals, <a href="">see this page</a> and check out some of the references at the bottom.</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb14-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb14-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">sysuse</span> auto2</span>
<span id="cb14-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">postfile</span> topost <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">level</span> pvalue svalue lointerval upinterval <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">using</span> my_new_data, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span></span>
<span id="cb14-4"></span>
<span id="cb14-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">forvalues</span> i = 10/99.9 {</span>
<span id="cb14-6">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">quietly</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">regress</span> price <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">weight</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">level</span>(<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`i'</span>)</span>
<span id="cb14-7">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span> E = <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">table</span>)</span>
<span id="cb14-8">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">quietly</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">list</span> E</span>
<span id="cb14-9">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">post</span> topost (<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`i'</span>) (1-<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`i'</span>/100) ( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(1-<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`i'</span>/100)/<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(2) * -1) (E[5,1]) (E[6,1])</span>
<span id="cb14-10">    }</span>
<span id="cb14-11"></span>
<span id="cb14-12"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">postclose</span> topost</span>
<span id="cb14-13"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">use</span> my_new_data, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb14-14"></span>
<span id="cb14-15"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">twoway</span> (pcscatter svalue lointerval svalue upinterval, mcolor(<span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">maroon</span>)), <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">ytitle</span>(Consonance Level (%)) <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xtitle</span>(Consonance Limits)  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">scale</span>( 0.75) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb14-16"><span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span>(Surprisal Curve) <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">subtitle</span>(A <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> comprised <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> several consonance intervals <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">at</span> various <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">levels</span>.)</span>
<span id="cb14-17"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">graph</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">export</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"surprisal.svg"</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span></span>
<span id="cb14-18">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb14-19">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span>
<span id="cb14-20">#&gt; </span>
<span id="cb14-21">#&gt; </span>
<span id="cb14-22">#&gt; </span>
<span id="cb14-23">#&gt; (1978 automobile <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">data</span>)</span>
<span id="cb14-24">#&gt; </span>
<span id="cb14-25">#&gt; </span>
<span id="cb14-26">#&gt; </span>
<span id="cb14-27">#&gt; </span>
<span id="cb14-28">#&gt; </span>
<span id="cb14-29">#&gt; </span>
<span id="cb14-30">#&gt; file surprisal.svg saved <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> SVG <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">format</span></span></code></pre></div></div>
</div>
<hr>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://stat.lesslikely.com/concurve/articles/surprisal.svg" style="width:150.0%;height:150.0%" class="figure-img"></p>
<figcaption>Surprisal Function</figcaption>
</figure>
</div>
<hr>
<p>It’s clear that in both plots, we’re missing values of intervals with a confidence/consonance level of less than 10%, but unfortunately, this is the best <code>Stata</code> can do, and what we’ll have to work with. It may not look as pretty as an output from <code>R</code>, but it’s far more useful than blankly staring at a 95% interval and thinking that it is the only piece of information we have regarding compatibility of different effect estimates.</p>
<p>The code that I have pasted above can be used for most commands in <code>Stata</code> that have an option to calculate a consonance level. Thus, if there’s an option for “<strong>level</strong>”, then the commands above will work to produce a data set of several consonance intervals. Though I am seriously hoping that a Stata expert will see this post and point out how I am wrong.</p>
<p>Now, suppose we wished to fit a generalized linear model, here’s what our code would look like.</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<pre><code>#&gt; no; dataset in memory has changed since last saved
#&gt; r(4);
#&gt; 
#&gt; 
#&gt; 
#&gt; (1978 automobile data)
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt;      +---------------------------------------------------+
#&gt;      | level   pvalue     svalue   lointer~l   upinter~l |
#&gt;      |---------------------------------------------------|
#&gt;   1. |    10       .9   .1520031    -245.564   -232.2247 |
#&gt;   2. |    11      .89   .1681228   -246.2351   -231.5536 |
#&gt;   3. |    12      .88   .1844246   -246.9073   -230.8814 |
#&gt;   4. |    13      .87   .2009127   -247.5808   -230.2079 |
#&gt;   5. |    14      .86   .2175914   -248.2557    -229.533 |
#&gt;      |---------------------------------------------------|
#&gt;   6. |    15      .85   .2344653   -248.9321   -228.8566 |
#&gt;   7. |    16      .84   .2515388   -249.6102   -228.1785 |
#&gt;   8. |    17      .83   .2688168     -250.29   -227.4987 |
#&gt;   9. |    18      .82   .2863042   -250.9717    -226.817 |
#&gt;  10. |    19      .81   .3040062   -251.6554   -226.1333 |
#&gt;      |---------------------------------------------------|
#&gt;  11. |    20       .8   .3219281   -252.3412   -225.4475 |
#&gt;  12. |    21      .79   .3400754   -253.0292   -224.7595 |
#&gt;  13. |    22      .78    .358454   -253.7197    -224.069 |
#&gt;  14. |    23      .77   .3770697   -254.4126   -223.3761 |
#&gt;  15. |    24      .76   .3959287   -255.1083   -222.6804 |
#&gt;      |---------------------------------------------------|
#&gt;  16. |    25      .75   .4150375   -255.8067    -221.982 |
#&gt;  17. |    26      .74   .4344028    -256.508   -221.2807 |
#&gt;  18. |    27      .73   .4540316   -257.2125   -220.5762 |
#&gt;  19. |    28      .72   .4739312   -257.9202   -219.8685 |
#&gt;  20. |    29      .71   .4941091   -258.6312   -219.1575 |
#&gt;      |---------------------------------------------------|
#&gt;  21. |    30       .7   .5145732   -259.3459   -218.4428 |
#&gt;  22. |    31      .69   .5353317   -260.0642   -217.7244 |
#&gt;  23. |    32      .68   .5563933   -260.7865   -217.0022 |
#&gt;  24. |    33      .67    .577767   -261.5129   -216.2758 |
#&gt;  25. |    34      .66   .5994621   -262.2435   -215.5452 |
#&gt;      |---------------------------------------------------|
#&gt;  26. |    35      .65   .6214884   -262.9785   -214.8102 |
#&gt;  27. |    36      .64   .6438562   -263.7183   -214.0704 |
#&gt;  28. |    37      .63   .6665763   -264.4628   -213.3259 |
#&gt;  29. |    38      .62   .6896599   -265.2124   -212.5762 |
#&gt;  30. |    39      .61   .7131189   -265.9673   -211.8213 |
#&gt;      |---------------------------------------------------|
#&gt;  31. |    40       .6   .7369656   -266.7278   -211.0609 |
#&gt;  32. |    41      .59   .7612131    -267.494   -210.2947 |
#&gt;  33. |    42      .58   .7858752   -268.2662   -209.5225 |
#&gt;  34. |    43      .57   .8109662   -269.0446    -208.744 |
#&gt;  35. |    44      .56   .8365012   -269.8297    -207.959 |
#&gt;      |---------------------------------------------------|
#&gt;  36. |    45      .55   .8624965   -270.6215   -207.1672 |
#&gt;  37. |    46      .54   .8889687   -271.4204   -206.3683 |
#&gt;  38. |    47      .53   .9159358   -272.2268   -205.5619 |
#&gt;  39. |    48      .52   .9434165    -273.041   -204.7477 |
#&gt;  40. |    49      .51   .9714308   -273.8633   -203.9254 |
#&gt;      |---------------------------------------------------|
#&gt;  41. |    50       .5          1    -274.694   -203.0947 |
#&gt;  42. |    51      .49   1.029146   -275.5337    -202.255 |
#&gt;  43. |    52      .48   1.058894   -276.3825   -201.4061 |
#&gt;  44. |    53      .47   1.089267   -277.2411   -200.5475 |
#&gt;  45. |    54      .46   1.120294   -278.1099   -199.6788 |
#&gt;      |---------------------------------------------------|
#&gt;  46. |    55      .45   1.152003   -278.9893   -198.7994 |
#&gt;  47. |    56      .44   1.184425   -279.8798   -197.9089 |
#&gt;  48. |    57      .43   1.217591    -280.782   -197.0067 |
#&gt;  49. |    58      .42   1.251539   -281.6965   -196.0922 |
#&gt;  50. |    59      .41   1.286304   -282.6239   -195.1648 |
#&gt;      |---------------------------------------------------|
#&gt;  51. |    60       .4   1.321928   -283.5648   -194.2239 |
#&gt;  52. |    61      .39   1.358454     -284.52   -193.2687 |
#&gt;  53. |    62      .38   1.395929   -285.4902   -192.2985 |
#&gt;  54. |    63      .37   1.434403   -286.4762   -191.3125 |
#&gt;  55. |    64      .36   1.473931   -287.4789   -190.3098 |
#&gt;      |---------------------------------------------------|
#&gt;  56. |    65      .35   1.514573   -288.4992   -189.2894 |
#&gt;  57. |    66      .34   1.556393   -289.5383   -188.2504 |
#&gt;  58. |    67      .33   1.599462   -290.5971   -187.1916 |
#&gt;  59. |    68      .32   1.643856   -291.6769   -186.1118 |
#&gt;  60. |    69      .31    1.68966    -292.779   -185.0097 |
#&gt;      |---------------------------------------------------|
#&gt;  61. |    70       .3   1.736966   -293.9048   -183.8839 |
#&gt;  62. |    71      .29   1.785875   -295.0559   -182.7328 |
#&gt;  63. |    72      .28   1.836501   -296.2341   -181.5546 |
#&gt;  64. |    73      .27   1.888969   -297.4413   -180.3474 |
#&gt;  65. |    74      .26   1.943416   -298.6794   -179.1092 |
#&gt;      |---------------------------------------------------|
#&gt;  66. |    75      .25          2   -299.9511   -177.8376 |
#&gt;  67. |    76      .24   2.058894   -301.2588   -176.5299 |
#&gt;  68. |    77      .23   2.120294   -302.6054   -175.1833 |
#&gt;  69. |    78      .22   2.184425   -303.9944   -173.7943 |
#&gt;  70. |    79      .21   2.251539   -305.4294   -172.3592 |
#&gt;      |---------------------------------------------------|
#&gt;  71. |    80       .2   2.321928   -306.9149   -170.8738 |
#&gt;  72. |    81      .19   2.395929   -308.4555   -169.3331 |
#&gt;  73. |    82      .18   2.473931   -310.0572   -167.7315 |
#&gt;  74. |    83      .17   2.556393   -311.7264   -166.0623 |
#&gt;  75. |    84      .16   2.643856   -313.4709   -164.3178 |
#&gt;      |---------------------------------------------------|
#&gt;  76. |    85      .15   2.736966   -315.2999   -162.4888 |
#&gt;  77. |    86      .14   2.836501   -317.2245   -160.5642 |
#&gt;  78. |    87      .13   2.943416   -319.2578   -158.5308 |
#&gt;  79. |    88      .12   3.058894   -321.4166   -156.3721 |
#&gt;  80. |    89      .11   3.184425   -323.7211   -154.0676 |
#&gt;      |---------------------------------------------------|
#&gt;  81. |    90       .1   3.321928   -326.1977    -151.591 |
#&gt;  82. |    91      .09   3.473931   -328.8804   -148.9082 |
#&gt;  83. |    92      .08   3.643856    -331.815   -145.9737 |
#&gt;  84. |    93      .07   3.836501   -335.0646   -142.7241 |
#&gt;  85. |    94      .06   4.058894   -338.7206   -139.0681 |
#&gt;      |---------------------------------------------------|
#&gt;  86. |    95      .05   4.321928   -342.9227    -134.866 |
#&gt;  87. |    96      .04   4.643856   -347.9005   -129.8882 |
#&gt;  88. |    97      .03   5.058894   -354.0756   -123.7131 |
#&gt;  89. |    98      .02   5.643856   -362.3692   -115.4195 |
#&gt;  90. |    99      .01   6.643856   -375.6108   -102.1779 |
#&gt;      +---------------------------------------------------+
#&gt; 
#&gt; 
#&gt; command ytitle is unrecognized
#&gt; r(199);
#&gt; 
#&gt; r(199);</code></pre>
</div>
<hr>
<p>We simply replace the first line within the loop with our intended command, just as I’ve replaced</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb16-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">regress</span> price mpg</span>
<span id="cb16-2">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb16-3">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span>
<span id="cb16-4">#&gt; </span>
<span id="cb16-5">#&gt; </span>
<span id="cb16-6">#&gt; </span>
<span id="cb16-7">#&gt;       Source |       SS           df       MS      Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span>   =        74</span>
<span id="cb16-8">#&gt; -------------+----------------------------------   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">F</span>(1, 72)        =     20.26</span>
<span id="cb16-9">#&gt;        Model |   139449474         1   139449474   Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">F</span>        =    0.0000</span>
<span id="cb16-10">#&gt;     Residual |   495615923        72  6883554.48   R-squared       =    0.2196</span>
<span id="cb16-11">#&gt; -------------+----------------------------------   Adj R-squared   =    0.2087</span>
<span id="cb16-12">#&gt;        Total |   635065396        73  8699525.97   Root MSE        =    2623.7</span>
<span id="cb16-13">#&gt; </span>
<span id="cb16-14">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb16-15">#&gt;        price | Coefficient  Std. err.      t    P&gt;|t|     [95% conf. interval]</span>
<span id="cb16-16">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb16-17">#&gt;          mpg |  -238.8943   53.07669    -4.50   0.000    -344.7008   -133.0879</span>
<span id="cb16-18">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   11253.06   1170.813     9.61   0.000     8919.088    13587.03</span>
<span id="cb16-19">#&gt; ------------------------------------------------------------------------------</span></code></pre></div></div>
</div>
<hr>
<p>with</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb17-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">glm</span> price mpg</span>
<span id="cb17-2">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb17-3">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span>
<span id="cb17-4">#&gt; </span>
<span id="cb17-5">#&gt; </span>
<span id="cb17-6">#&gt; </span>
<span id="cb17-7">#&gt; Iteration 0:  Log likelihood = -686.53958  </span>
<span id="cb17-8">#&gt; </span>
<span id="cb17-9">#&gt; Generalized linear models                         Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span>   =         74</span>
<span id="cb17-10">#&gt; Optimization     : ML                             Residual df     =         72</span>
<span id="cb17-11">#&gt;                                                   Scale parameter =    6883554</span>
<span id="cb17-12">#&gt; Deviance         =  495615922.6                   (1/df) Deviance =    6883554</span>
<span id="cb17-13">#&gt; Pearson          =  495615922.6                   (1/df) Pearson  =    6883554</span>
<span id="cb17-14">#&gt; </span>
<span id="cb17-15">#&gt; Variance <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>: <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">V</span>(u) = 1                       [Gaussian]</span>
<span id="cb17-16">#&gt; Link <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>    : g(u) = u                       [Identity]</span>
<span id="cb17-17">#&gt; </span>
<span id="cb17-18">#&gt;                                                   AIC             =   18.60918</span>
<span id="cb17-19">#&gt; Log likelihood   = -686.5395809                   BIC             =   4.96e+08</span>
<span id="cb17-20">#&gt; </span>
<span id="cb17-21">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb17-22">#&gt;              |                 OIM</span>
<span id="cb17-23">#&gt;        price | Coefficient  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">std</span>. err.      z    P&gt;|z|     [95% conf. interval]</span>
<span id="cb17-24">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb17-25">#&gt;          mpg |  -238.8943   53.07669    -4.50   0.000    -342.9227    -134.866</span>
<span id="cb17-26">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   11253.06   1170.813     9.61   0.000      8958.31    13547.81</span>
<span id="cb17-27">#&gt; ------------------------------------------------------------------------------</span></code></pre></div></div>
</div>
<hr>
<p>If we wanted fit something more complex, like a multilevel mixed model that used restricted maximum likelihood, here’s what our code would look like:</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<pre><code>#&gt; no; dataset in memory has changed since last saved
#&gt; r(4);
#&gt; 
#&gt; 
#&gt; 
#&gt; (1978 automobile data)
#&gt; 
#&gt; 
#&gt; variable outcome not found
#&gt; r(111);
#&gt; 
#&gt; r(111);</code></pre>
</div>
<hr>
<p>Basically, our code doesn’t really change that much and with only a few lines of it, we are able to produce graphical tools that can better help us interpret the wide range of effect sizes that are compatible with the model and its assumptions.</p>
<hr>
<section id="using-the-cifunction-command-for-confidence-interval-functions" class="level3">
<h3 class="anchored" data-anchor-id="using-the-cifunction-command-for-confidence-interval-functions">Using the <code>cifunction</code> Command for Confidence Interval Functions</h3>
<p>An alternative approach to producing confidence interval functions in Stata is to use the <code>cifunction</code> command, which computes and graphically displays all possible confidence intervals around a point estimate.</p>
<p>The <code>cifunction</code> command is an immediate command that allows you to specify a point estimate and standard error, and it will produce a confidence interval function (also called a confidence curve, P-value function, or consonance interval).</p>
<section id="syntax" class="level4">
<h4 class="anchored" data-anchor-id="syntax">Syntax</h4>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb19-1">cifunction #b , se(#) [ df(#) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">eform</span> figure[(twoway_options)] <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">saving</span>(filename, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span>) ]</span></code></pre></div></div>
<p>Where <code>#b</code> can be specified as a coefficient or exponentiated value (e.g., OR, HR, IRR).</p>
</section>
<section id="options" class="level4">
<h4 class="anchored" data-anchor-id="options">Options</h4>
<ul>
<li><strong>se(#)</strong>: specifies the standard error of the estimate (required)</li>
<li><strong>df(#)</strong>: specify the degrees of freedom if #b is t-distributed</li>
<li><strong>eform</strong>: indicate that the coefficient is exponentiated (e.g., OR, RR, IRR)</li>
<li><strong>figure[(twoway_options)]</strong>: produces a confidence interval function plot</li>
<li><strong>saving(filename, replace)</strong>: save results to filename</li>
</ul>
</section>
<section id="example-1-simple-risk-ratio" class="level4">
<h4 class="anchored" data-anchor-id="example-1-simple-risk-ratio">Example 1: Simple Risk Ratio</h4>
<p>Reproduce a confidence interval function for a risk ratio of 2.0 with p-value of 0.05. First, we use <code>getregstats</code> to get the standard error:</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb20-1">getregstats 2.0, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">p</span>(0.05) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mod</span>(rr)</span>
<span id="cb20-2">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb20-3">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span>
<span id="cb20-4">#&gt; </span>
<span id="cb20-5">#&gt; </span>
<span id="cb20-6">#&gt; </span>
<span id="cb20-7">#&gt; </span>
<span id="cb20-8">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb20-9">#&gt;              | Risk Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Interval]</span>
<span id="cb20-10">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb20-11">#&gt;    Estimates |          2    .707306    -1.96   0.050            1           4</span>
<span id="cb20-12">#&gt; ------------------------------------------------------------------------------</span></code></pre></div></div>
</div>
<p>Then use <code>cifunction</code> specifying the point estimate and standard error. We modify the figure to improve presentation:</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb21-1">cifunction 2.0, se(.707306) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">eform</span> fig(<span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xscale</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>) xlab(0.5 1 2 5 10) <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Risk Ratio (Log Scale)"</span>))</span>
<span id="cb21-2">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb21-3">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span></code></pre></div></div>
</div>
</section>
<section id="example-2-multiple-rate-ratios-by-age-group" class="level4">
<h4 class="anchored" data-anchor-id="example-2-multiple-rate-ratios-by-age-group">Example 2: Multiple Rate Ratios by Age Group</h4>
<p>For multiple estimates across age groups from the <code>dollhill3</code> dataset:</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb22-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">webuse</span> dollhill3, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb22-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">poisson</span> deaths smokes <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> agecat==1, exposure(pyears) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">irr</span></span>
<span id="cb22-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">poisson</span> deaths smokes <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> agecat==2, exposure(pyears) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">irr</span></span>
<span id="cb22-4"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">poisson</span> deaths smokes <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> agecat==3, exposure(pyears) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">irr</span></span>
<span id="cb22-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">poisson</span> deaths smokes <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> agecat==4, exposure(pyears) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">irr</span></span>
<span id="cb22-6">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb22-7">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span>
<span id="cb22-8">#&gt; </span>
<span id="cb22-9">#&gt; </span>
<span id="cb22-10">#&gt; (Doll and Hill (1966))</span>
<span id="cb22-11">#&gt; </span>
<span id="cb22-12">#&gt; </span>
<span id="cb22-13">#&gt; Iteration 0:  Log likelihood = -4.0705386  </span>
<span id="cb22-14">#&gt; Iteration 1:  Log likelihood = -3.9613823  </span>
<span id="cb22-15">#&gt; Iteration 2:  Log likelihood = -3.9612634  </span>
<span id="cb22-16">#&gt; Iteration 3:  Log likelihood = -3.9612634  </span>
<span id="cb22-17">#&gt; </span>
<span id="cb22-18">#&gt; Poisson regression                                      Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span> =      2</span>
<span id="cb22-19">#&gt;                                                         LR <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1)    =   9.73</span>
<span id="cb22-20">#&gt;                                                         Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>   = 0.0018</span>
<span id="cb22-21">#&gt; Log likelihood = -3.9612634                             Pseudo R2     = 0.5511</span>
<span id="cb22-22">#&gt; </span>
<span id="cb22-23">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb22-24">#&gt;       deaths |        IRR   Std. err.      z    P&gt;|z|     [95% conf. interval]</span>
<span id="cb22-25">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb22-26">#&gt;       smokes |   5.736638   4.181258     2.40   0.017     1.374811    23.93712</span>
<span id="cb22-27">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   .0001064   .0000753   -12.94   0.000     .0000266    .0004256</span>
<span id="cb22-28">#&gt;   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(pyears) |          1  (exposure)</span>
<span id="cb22-29">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb22-30">#&gt; Note: <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span> baseline incidence rate.</span>
<span id="cb22-31">#&gt; </span>
<span id="cb22-32">#&gt; </span>
<span id="cb22-33">#&gt; Iteration 0:  Log likelihood = -5.4793565  </span>
<span id="cb22-34">#&gt; Iteration 1:  Log likelihood = -5.4104407  </span>
<span id="cb22-35">#&gt; Iteration 2:  Log likelihood =   -5.41027  </span>
<span id="cb22-36">#&gt; Iteration 3:  Log likelihood =   -5.41027  </span>
<span id="cb22-37">#&gt; </span>
<span id="cb22-38">#&gt; Poisson regression                                      Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span> =      2</span>
<span id="cb22-39">#&gt;                                                         LR <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1)    =   7.59</span>
<span id="cb22-40">#&gt;                                                         Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>   = 0.0059</span>
<span id="cb22-41">#&gt; Log likelihood = -5.41027                               Pseudo R2     = 0.4123</span>
<span id="cb22-42">#&gt; </span>
<span id="cb22-43">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb22-44">#&gt;       deaths |        IRR   Std. err.      z    P&gt;|z|     [95% conf. interval]</span>
<span id="cb22-45">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb22-46">#&gt;       smokes |   2.138812   .6520701     2.49   0.013     1.176691    3.887609</span>
<span id="cb22-47">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   .0011243   .0003246   -23.52   0.000     .0006385    .0019798</span>
<span id="cb22-48">#&gt;   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(pyears) |          1  (exposure)</span>
<span id="cb22-49">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb22-50">#&gt; Note: <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span> baseline incidence rate.</span>
<span id="cb22-51">#&gt; </span>
<span id="cb22-52">#&gt; </span>
<span id="cb22-53">#&gt; Iteration 0:  Log likelihood = -6.2456963  </span>
<span id="cb22-54">#&gt; Iteration 1:  Log likelihood = -6.1713863  </span>
<span id="cb22-55">#&gt; Iteration 2:  Log likelihood =  -6.171298  </span>
<span id="cb22-56">#&gt; Iteration 3:  Log likelihood =  -6.171298  </span>
<span id="cb22-57">#&gt; </span>
<span id="cb22-58">#&gt; Poisson regression                                      Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span> =      2</span>
<span id="cb22-59">#&gt;                                                         LR <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1)    =   4.01</span>
<span id="cb22-60">#&gt;                                                         Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>   = 0.0453</span>
<span id="cb22-61">#&gt; Log likelihood = -6.171298                              Pseudo R2     = 0.2450</span>
<span id="cb22-62">#&gt; </span>
<span id="cb22-63">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb22-64">#&gt;       deaths |        IRR   Std. err.      z    P&gt;|z|     [95% conf. interval]</span>
<span id="cb22-65">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb22-66">#&gt;       smokes |    1.46824    .295728     1.91   0.057     .9893522     2.17893</span>
<span id="cb22-67">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   .0049037   .0009267   -28.14   0.000     .0033858    .0071021</span>
<span id="cb22-68">#&gt;   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(pyears) |          1  (exposure)</span>
<span id="cb22-69">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb22-70">#&gt; Note: <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span> baseline incidence rate.</span>
<span id="cb22-71">#&gt; </span>
<span id="cb22-72">#&gt; </span>
<span id="cb22-73">#&gt; Iteration 0:  Log likelihood = -6.1640322  </span>
<span id="cb22-74">#&gt; Iteration 1:  Log likelihood = -6.1203079  </span>
<span id="cb22-75">#&gt; Iteration 2:  Log likelihood = -6.1202768  </span>
<span id="cb22-76">#&gt; Iteration 3:  Log likelihood = -6.1202768  </span>
<span id="cb22-77">#&gt; </span>
<span id="cb22-78">#&gt; Poisson regression                                      Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span> =      2</span>
<span id="cb22-79">#&gt;                                                         LR <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1)    =   2.43</span>
<span id="cb22-80">#&gt;                                                         Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>   = 0.1189</span>
<span id="cb22-81">#&gt; Log likelihood = -6.1202768                             Pseudo R2     = 0.1658</span>
<span id="cb22-82">#&gt; </span>
<span id="cb22-83">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb22-84">#&gt;       deaths |        IRR   Std. err.      z    P&gt;|z|     [95% conf. interval]</span>
<span id="cb22-85">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb22-86">#&gt;       smokes |    1.35606   .2748845     1.50   0.133     .9114509    2.017551</span>
<span id="cb22-87">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   .0108317    .002047   -23.95   0.000     .0074789    .0156877</span>
<span id="cb22-88">#&gt;   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(pyears) |          1  (exposure)</span>
<span id="cb22-89">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb22-90">#&gt; Note: <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span> baseline incidence rate.</span></code></pre></div></div>
</div>
<p>Then we can use <code>cifunction</code> with multiple estimates:</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb23-1">cifunction 5.736638 2.138812 1.46824 1.35606, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb23-2">  se(4.181258 .6520701 .295728 .2748845) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">eform</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb23-3">  fig(<span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xscale</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">xlabel</span>(.3 .5 1 2 5 10 20 50 100) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb23-4">      <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">legend</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(1 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"35-44"</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(2 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45-54"</span>) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(3 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"55-64"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb23-5">             <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">label</span>(4 <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"65-74"</span>) <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age Group"</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">size</span>(small))) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb23-6">      <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rate Ratio (Log Scale)"</span>))</span>
<span id="cb23-7">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb23-8">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span></code></pre></div></div>
</div>
</section>
<section id="example-3-comparing-crude-and-pooled-estimates" class="level4">
<h4 class="anchored" data-anchor-id="example-3-comparing-crude-and-pooled-estimates">Example 3: Comparing Crude and Pooled Estimates</h4>
<p>Using case-control data to compare crude and pooled odds ratios:</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<pre><code>#&gt; no; dataset in memory has changed since last saved
#&gt; r(4);
#&gt; 
#&gt; 
#&gt; 
#&gt;                                                          Proportion
#&gt;                  |   Exposed   Unexposed  |      Total      exposed
#&gt; -----------------+------------------------+------------------------
#&gt;            Cases |        10          36  |         46       0.2174
#&gt;         Controls |         5          40  |         45       0.1111
#&gt; -----------------+------------------------+------------------------
#&gt;            Total |        15          76  |         91       0.1648
#&gt;                  |                        |
#&gt;                  |      Point estimate    |    [95% conf. interval]
#&gt;                  |------------------------+------------------------
#&gt;       Odds ratio |         2.222222       |      .69377    7.118025 (Woolf)
#&gt;  Attr. frac. ex. |              .55       |      -.4414    .8595116 (Woolf)
#&gt;  Attr. frac. pop |         .1195652       |
#&gt;                  +-------------------------------------------------
#&gt;                                chi2(1) =     1.87  Pr&gt;chi2 = 0.1719
#&gt; 
#&gt; 
#&gt;                                                          Proportion
#&gt;                  |   Exposed   Unexposed  |      Total      exposed
#&gt; -----------------+------------------------+------------------------
#&gt;            Cases |        18          78  |         96       0.1875
#&gt;         Controls |         7          86  |         93       0.0753
#&gt; -----------------+------------------------+------------------------
#&gt;            Total |        25         164  |        189       0.1323
#&gt;                  |                        |
#&gt;                  |      Point estimate    |    [95% conf. interval]
#&gt;                  |------------------------+------------------------
#&gt;       Odds ratio |         2.835165       |    1.123936    7.151794 (Woolf)
#&gt;  Attr. frac. ex. |         .6472868       |    .1102698    .8601749 (Woolf)
#&gt;  Attr. frac. pop |         .1213663       |
#&gt;                  +-------------------------------------------------
#&gt;                                chi2(1) =     5.18  Pr&gt;chi2 = 0.0228
#&gt; 
#&gt; 
#&gt; 
#&gt; ------------------------------------------------------------------------------
#&gt;              | Odds Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Interval]
#&gt; -------------+----------------------------------------------------------------
#&gt;    Estimates |   2.835165   1.338429     2.21   0.027     1.123936    7.151794
#&gt; ------------------------------------------------------------------------------
#&gt; 
#&gt; 
#&gt; 
#&gt; ------------------------------------------------------------------------------
#&gt;              | Odds Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Interval]
#&gt; -------------+----------------------------------------------------------------
#&gt;    Estimates |   2.222222   1.319891     1.34   0.179     .6937698    7.118025
#&gt; ------------------------------------------------------------------------------</code></pre>
</div>
<p>Then compare them with <code>cifunction</code>:</p>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<pre><code>#&gt; no; dataset in memory has changed since last saved
#&gt; r(4);</code></pre>
</div>
</section>
<section id="output-from-cifunction" class="level4">
<h4 class="anchored" data-anchor-id="output-from-cifunction">Output from <code>cifunction</code></h4>
<p>The <code>cifunction</code> command produces and stores several variables when the <code>saving()</code> option is specified:</p>
<ul>
<li><strong>cilev</strong>: sequencing range of CIs (from 0 to 99.99)</li>
<li><strong>plev</strong>: sequencing range of P-values (from 0.0001 to 1.0)</li>
<li><strong>sval</strong>: S-values computed for respective plev values</li>
<li><strong>lcl(#)</strong>: computed lower confidence limits</li>
<li><strong>ucl(#)</strong>: computed upper confidence limits</li>
</ul>
</section>
<section id="references-for-cifunction" class="level4">
<h4 class="anchored" data-anchor-id="references-for-cifunction">References for <code>cifunction</code></h4>
<ul>
<li>Birnbaum, A. 1961. Confidence curves: An omnibus technique for estimation and testing statistical hypotheses. <em>Journal of the American Statistical Association</em> 56: 246-249.</li>
<li>Folks, J. F. 1981. Ideas of Statistics. New York: John Wiley &amp; Sons.</li>
<li>Greenland, S. 2019. Valid P-Values Behave Exactly as They Should: Some Misleading Criticisms of P-Values and Their Resolution With S-Values. <em>The American Statistician</em> 73(sup1): 106-114.</li>
<li>Sullivan, K. M., and Foster, D. 1990. Confidence curves versus confidence intervals. <em>American Journal of Public Health</em> 80(4): 452-453.</li>
</ul>
<hr>
</section>
</section>
<section id="cite-r-packages" class="level2">
<h2 class="anchored" data-anchor-id="cite-r-packages">Cite R Packages</h2>
<div class="cell" data-layout-align="center" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb26-1">about</span>
<span id="cb26-2">#&gt; no; dataset <span class="kw" 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;">memory</span> has changed since <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">last</span> saved</span>
<span id="cb26-3">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(4);</span>
<span id="cb26-4">#&gt; </span>
<span id="cb26-5">#&gt; </span>
<span id="cb26-6">#&gt; </span>
<span id="cb26-7">#&gt; StataNow/MP 19.5 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> Mac (Apple Silicon)</span>
<span id="cb26-8">#&gt; Revision 12 Aug 2026</span>
<span id="cb26-9">#&gt; Copyright 1985-2025 StataCorp LLC</span>
<span id="cb26-10">#&gt; </span>
<span id="cb26-11">#&gt; Total physical <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">memory</span>: 48.01 GB</span>
<span id="cb26-12">#&gt; </span>
<span id="cb26-13">#&gt; Stata license: Single-user 2-core , expiring  6 Feb 2027</span>
<span id="cb26-14">#&gt; Serial number: 501909358563</span>
<span id="cb26-15">#&gt;   Licensed to: Zad Rafi</span>
<span id="cb26-16">#&gt; </span></code></pre></div></div>
</div>
</section>
<section id="session-info" class="level2">
<h2 class="anchored" data-anchor-id="session-info">Session info</h2>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1">si <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;">sessionInfo</span>()</span>
<span id="cb27-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(si, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">RNG =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">locale =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb27-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; R version 4.6.1 (2026-06-24)</span></span>
<span id="cb27-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Platform: aarch64-apple-darwin25.4.0</span></span>
<span id="cb27-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Running under: macOS Golden Gate 27.0.1</span></span>
<span id="cb27-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb27-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Matrix products: default</span></span>
<span id="cb27-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; BLAS:   /opt/homebrew/Cellar/openblas/0.3.34/lib/libopenblasp-r0.3.34.dylib </span></span>
<span id="cb27-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; LAPACK: /opt/homebrew/Cellar/r/4.6.1/lib/R/lib/libRlapack.dylib;  LAPACK version 3.12.1</span></span>
<span id="cb27-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb27-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Random number generation:</span></span>
<span id="cb27-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  RNG:     Mersenne-Twister </span></span>
<span id="cb27-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Normal:  Inversion </span></span>
<span id="cb27-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Sample:  Rejection </span></span>
<span id="cb27-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  </span></span>
<span id="cb27-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; locale:</span></span>
<span id="cb27-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [1] C.UTF-8/C.UTF-8/C.UTF-8/C/C.UTF-8/C.UTF-8</span></span>
<span id="cb27-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb27-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; time zone: America/New_York</span></span>
<span id="cb27-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; tzcode source: internal</span></span>
<span id="cb27-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb27-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; attached base packages:</span></span>
<span id="cb27-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [1] splines   grid      stats4    parallel  stats     graphics  grDevices</span></span>
<span id="cb27-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [8] utils     datasets  methods   base     </span></span>
<span id="cb27-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb27-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; other attached packages:</span></span>
<span id="cb27-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [1] cli_3.6.6             texPreview_2.1.0      tinytex_0.61         </span></span>
<span id="cb27-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [4] rmarkdown_2.32        brms_2.23.0           bootImpute_1.3.0     </span></span>
<span id="cb27-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [7] knitr_1.52            boot_1.3-32           gtsummary_2.6.1      </span></span>
<span id="cb27-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [10] reshape2_1.4.5        ProfileLikelihood_1.3 ImputeRobust_1.3-1   </span></span>
<span id="cb27-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [13] gamlss_5.5-5          gamlss.dist_6.1-11    gamlss.data_6.0-7    </span></span>
<span id="cb27-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [16] mvtnorm_1.4-2         performance_0.18.2    summarytools_1.1.5   </span></span>
<span id="cb27-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [19] tidybayes_3.0.7       htmltools_0.5.9       Statamarkdown_1.1.0  </span></span>
<span id="cb27-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [22] car_3.1-5             carData_3.0-6         qqplotr_0.0.7        </span></span>
<span id="cb27-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [25] ggcorrplot_0.3.0      mitml_0.4-5           pbmcapply_1.5.1      </span></span>
<span id="cb27-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [28] Amelia_1.8.3          Rcpp_1.1.2            blogdown_1.24        </span></span>
<span id="cb27-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [31] doParallel_1.0.17     iterators_1.0.14      foreach_1.5.2        </span></span>
<span id="cb27-38"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [34] lattice_0.23-1        bayesplot_1.16.0      wesanderson_0.3.7    </span></span>
<span id="cb27-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [37] VIM_7.3.1             colorspace_2.1-4      here_1.0.2           </span></span>
<span id="cb27-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [40] progress_1.2.3        loo_2.10.1            mi_1.3.1             </span></span>
<span id="cb27-41"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [43] Matrix_1.7-6          broom_1.0.13          yardstick_1.4.0      </span></span>
<span id="cb27-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [46] svglite_2.2.2         Cairo_1.7-0           cowplot_1.2.0        </span></span>
<span id="cb27-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [49] mgcv_1.9-4            nlme_3.1-171          xfun_0.61            </span></span>
<span id="cb27-44"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [52] broom.mixed_0.2.9.7   reticulate_1.47.0     kableExtra_1.4.1     </span></span>
<span id="cb27-45"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [55] posterior_1.7.0       checkmate_2.3.4       parallelly_1.48.0    </span></span>
<span id="cb27-46"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [58] miceFast_0.9.1        randomForest_4.7-1.2  missForest_1.6.1     </span></span>
<span id="cb27-47"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [61] miceadds_3.20-10      quantreg_6.1          SparseM_1.84-2       </span></span>
<span id="cb27-48"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [64] MCMCpack_1.7-1        MASS_7.3-66           coda_0.19-4.1        </span></span>
<span id="cb27-49"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [67] latex2exp_0.9.8       rstan_2.32.7          StanHeaders_2.39.1   </span></span>
<span id="cb27-50"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [70] lubridate_1.9.5       forcats_1.0.1         stringr_1.6.0        </span></span>
<span id="cb27-51"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [73] dplyr_1.2.1           purrr_1.2.2           readr_2.2.0          </span></span>
<span id="cb27-52"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [76] tibble_3.3.1          ggplot2_4.0.3         tidyverse_2.0.0      </span></span>
<span id="cb27-53"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [79] ggtext_0.2.0          concurve_3.0.5        showtext_0.9-8       </span></span>
<span id="cb27-54"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [82] showtextdb_3.0        sysfonts_0.8.9        future.apply_1.20.2  </span></span>
<span id="cb27-55"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [85] future_1.76.0         tidyr_1.3.2           magrittr_2.0.5       </span></span>
<span id="cb27-56"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [88] mice_3.19.0           rms_8.1-1             Hmisc_5.3-0          </span></span>
<span id="cb27-57"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb27-58"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; loaded via a namespace (and not attached):</span></span>
<span id="cb27-59"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   [1] fs_2.1.0              matrixStats_1.5.0     bitops_1.1-0         </span></span>
<span id="cb27-60"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   [4] httr_1.4.9            insight_1.5.4         RColorBrewer_1.1-3   </span></span>
<span id="cb27-61"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   [7] tools_4.6.1           doRNG_1.8.6.3         backports_1.5.1      </span></span>
<span id="cb27-62"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [10] R6_2.6.1              ggdist_3.3.3          jomo_2.7-6           </span></span>
<span id="cb27-63"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [13] withr_3.0.3           sp_2.2-3              Brobdingnag_1.3-1    </span></span>
<span id="cb27-64"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [16] prettyunits_1.2.0     gridExtra_2.3.1       textshaping_1.0.5    </span></span>
<span id="cb27-65"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [19] formatR_1.14          sandwich_3.1-3        S7_0.2.2             </span></span>
<span id="cb27-66"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [22] robustbase_0.99-7     polspline_1.1.25      proxy_0.4-29         </span></span>
<span id="cb27-67"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [25] QuickJSR_1.11.0       systemfonts_1.3.2     foreign_0.8-91       </span></span>
<span id="cb27-68"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [28] dichromat_2.0-1       itertools_0.1-3       rstudioapi_0.19.0    </span></span>
<span id="cb27-69"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [31] generics_0.1.4        shape_1.4.6.1         distributional_0.9.0 </span></span>
<span id="cb27-70"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [34] inline_0.3.21         clipr_0.8.1           abind_1.4-8          </span></span>
<span id="cb27-71"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [37] lifecycle_1.0.5       whisker_0.4.1         multcomp_1.4-32      </span></span>
<span id="cb27-72"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [40] yaml_2.3.12           crayon_1.5.3          magick_2.9.1         </span></span>
<span id="cb27-73"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [43] pillar_1.11.1         tcltk_4.6.1           estimability_2.0.0   </span></span>
<span id="cb27-74"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [46] xgboost_3.2.1.1       codetools_0.2-20      pan_2.0              </span></span>
<span id="cb27-75"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [49] glue_1.8.1            rcartocolor_2.1.2     V8_8.2.0             </span></span>
<span id="cb27-76"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [52] data.table_1.18.6.1   vcd_1.4-14            vctrs_0.7.3          </span></span>
<span id="cb27-77"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [55] png_0.1-9             Rdpack_2.6.6          gtable_0.3.6         </span></span>
<span id="cb27-78"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [58] twosamples_2.0.1      rematch2_2.1.2        rbibutils_2.4.1      </span></span>
<span id="cb27-79"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [61] pracma_2.4.6          reformulas_0.4.4      survival_3.8-12      </span></span>
<span id="cb27-80"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [64] TH.data_1.1-5         mcmc_0.9-8            rprojroot_2.1.1      </span></span>
<span id="cb27-81"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [67] tensorA_0.36.2.1      svgPanZoom_0.3.4      otel_0.2.0           </span></span>
<span id="cb27-82"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [70] rpart_4.1.27          DBI_1.3.0             nnet_7.3-21          </span></span>
<span id="cb27-83"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [73] processx_3.9.0        tidyselect_1.2.1      emmeans_2.0.4        </span></span>
<span id="cb27-84"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [76] compiler_4.6.1        curl_8.0.0            glmnet_5.1           </span></span>
<span id="cb27-85"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [79] htmlTable_2.5.0       arrayhelpers_1.1-2    xml2_1.6.0           </span></span>
<span id="cb27-86"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [82] desc_1.4.3            scales_1.4.0          caTools_1.18.4       </span></span>
<span id="cb27-87"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [85] DEoptimR_1.2-2        lmtest_0.9-40         callr_3.8.0          </span></span>
<span id="cb27-88"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [88] digest_0.6.39         minqa_1.2.8           pkgconfig_2.0.3      </span></span>
<span id="cb27-89"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [91] base64enc_0.1-6       lme4_2.0-6            fastmap_1.2.0        </span></span>
<span id="cb27-90"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [94] rlang_1.3.0           htmlwidgets_1.6.4     farver_2.1.2         </span></span>
<span id="cb27-91"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [97] svUnit_1.0.8          zoo_1.9-1             jsonlite_2.0.0       </span></span>
<span id="cb27-92"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [100] rapportools_1.2       Formula_1.2-6         furrr_0.4.0          </span></span>
<span id="cb27-93"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [103] stringi_1.8.9         plyr_1.8.9            pkgbuild_1.4.8       </span></span>
<span id="cb27-94"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [106] listenv_1.1.0         details_0.4.0         pander_0.6.6         </span></span>
<span id="cb27-95"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [109] gridtext_0.1.6        hms_1.1.4             qqconf_1.3.2         </span></span>
<span id="cb27-96"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [112] ranger_0.18.0         opdisDownsampling_1.7 rngtools_1.5.2       </span></span>
<span id="cb27-97"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [115] rstantools_2.7.1      evaluate_1.0.5        mitools_2.7          </span></span>
<span id="cb27-98"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [118] RcppParallel_6.2.1    laeken_0.5.3          nloptr_2.2.1         </span></span>
<span id="cb27-99"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [121] tzdb_0.5.0            MatrixModels_0.5-4    extremevalues_2.4.1  </span></span>
<span id="cb27-100"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [124] xtable_1.8-8          e1071_1.7-17          viridisLite_0.4.3    </span></span>
<span id="cb27-101"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [127] class_7.3-24          arm_1.15-3            cluster_2.1.8.3      </span></span>
<span id="cb27-102"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [130] timechange_0.4.0      globals_0.19.1        bridgesampling_1.2-1</span></span></code></pre></div></div>
</div>


<!-- -->

</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{rafi2024,
  author = {Rafi, Zad and Panda, Sir},
  title = {Using {Stata:} {Producing} {Consonance} {Functions}},
  date = {2024-01-01},
  url = {https://lesslikely.com/statistics/stata},
  langid = {en-US},
  abstract = {A simple guide on how to produce consonance functions in
    Stata.}
}
</code></pre></div></section></div> ]]></description>
  <category>statistics</category>
  <guid>https://lesslikely.com/statistics/stata.html</guid>
  <pubDate>Mon, 01 Jan 2024 05:00:00 GMT</pubDate>
  <media:content url="https://raw.githubusercontent.com/stan-dev/logos/master/logo.png" medium="image" type="image/png"/>
</item>
<item>
  <title>Simulation of a Two-Group Parallel-Arm RCT with Interim Analyses</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/statistics/interim_analyses.html</link>
  <description><![CDATA[ 





<hr>
<p>Recently <a href="https://twitter.com/ADAlthousePhD">Andrew Althouse</a> informed me that he was going to simulate a two-group parallel-arm randomized trial with interim analyses using the <a href="https://CRAN.R-project.org/package=rpact"><code>rpact</code></a> <code>R</code> package, so I offered to also help in constructing the <code>R</code> code to do so. He already has a number of <code>R</code> scripts on his GitHub repo for doing similar simulations, which can be <a href="https://github.com/aalthous/RCT-Simulation-v1">viewed here</a> and a number of tweets explaining these simulations. For this example, his goal was to simulate a trial where the outcome was binary and the probability of death for each group could be tuned in addition to:</p>
<hr>
<ul>
<li>the total number of participants</li>
</ul>
<hr>
<ul>
<li>the number of interim analyses</li>
</ul>
<hr>
<ul>
<li>the schedule of the interim analyses</li>
</ul>
<hr>
<ul>
<li>the group-sequential design used</li>
</ul>
<hr>
<p>along with the usual trial analysis parameters such as:</p>
<hr>
<ul>
<li>the <img src="https://latex.codecogs.com/png.latex?%5Calpha">-level</li>
</ul>
<hr>
<ul>
<li>the type of test (1-sided vs.&nbsp;2-sided).</li>
</ul>
<hr>
<p>The goal was to be able to produce a table of various statistics such as:</p>
<hr>
<ul>
<li>the odds ratio</li>
</ul>
<hr>
<ul>
<li>the confidence limits</li>
</ul>
<hr>
<ul>
<li>the <img src="https://latex.codecogs.com/png.latex?P">-value</li>
</ul>
<hr>
<ul>
<li>the number of successes</li>
</ul>
<hr>
<p>for each of the interim analyses specified.</p>
<hr>
<p>The function below is a reflection of our efforts to do so, and also returns several plots from the <a href="https://CRAN.R-project.org/package=rpact"><code>rpact</code></a> package for the design that is chosen along with a plot comparing the design to other designs. In order to get similar results, you will need to load the <code>R</code> function first, and then simply enter the proper inputs. While there may be more efficient ways to write the code, for example using <code>lapply()</code> instead of for loops, we have chosen not to do so, and we have also tried to minimize the number of <code>R</code> packages necessary for the function to work but the following will be required:</p>
<hr>
<ul>
<li><a href="https://CRAN.R-project.org/package=rpact"><code>rpact</code></a></li>
</ul>
<hr>
<ul>
<li><a href="https://CRAN.R-project.org/package=stringr"><code>stringr</code></a></li>
</ul>
<hr>
<p>You can quickly install and load both using:</p>
<hr>
<hr>
<section id="setting-up-the-function" class="level2">
<h2 class="anchored" data-anchor-id="setting-up-the-function">Setting up the Function</h2>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">#' @title Simulation of a Two-Group Parallel-Arm Trial With Interim Analyses</span></span>
<span id="cb1-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @docType Custom function for simulation from the rpact package</span></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @author Andrew Althouse with edits by Zad Rafi</span></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' </span><span class="al" style="color: #AD0000;
background-color: null;
font-style: inherit;">NOTE</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">: If you want to confirm "type 1 error" under different stopping rules,</span></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' make death = in the two treatment arms (e.g. no treatment effect)</span></span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' </span><span class="al" style="color: #AD0000;
background-color: null;
font-style: inherit;">NOTE</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">: I have set this one up to test the power for a treatment that would reduce mortality</span></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' from 40% in control group (1) to 30% in treatment group (2)</span></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' </span><span class="al" style="color: #AD0000;
background-color: null;
font-style: inherit;">NOTE</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">: Trial Design Parameters - Part 1</span></span>
<span id="cb1-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' Here we will specify the basics: total N patients to enroll, and death rate for each treatment arm</span></span>
<span id="cb1-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' </span><span class="al" style="color: #AD0000;
background-color: null;
font-style: inherit;">NOTE</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">: Trial Design Parameters - Part 2</span></span>
<span id="cb1-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' Here we will define the interim analysis strategy and stopping rules</span></span>
<span id="cb1-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' For this trial we will include provisions for efficacy stopping only (no pre-specified futility stopping)</span></span>
<span id="cb1-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' We will use the rpact package to compute the stopping/success thresholds at the interim and final analysis</span></span>
<span id="cb1-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' </span><span class="al" style="color: #AD0000;
background-color: null;
font-style: inherit;">NOTE</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">: Required packages: rpact and stringr</span></span>
<span id="cb1-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param nSims # The number of simulations, the default is 1000</span></span>
<span id="cb1-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param nPatients # here is where you specify the planned max number of patients you want included in each RCT</span></span>
<span id="cb1-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param death1 # here is where you specify the event rate for patients receiving 'treatment 1' in these trial</span></span>
<span id="cb1-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param death2 # here is where you specify the event rate for patients receiving 'treatment 2' in these trials</span></span>
<span id="cb1-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param nLooks # here is where you put the number of looks that will take place (INCLUDING the final analysis)</span></span>
<span id="cb1-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param analyses_scheduled # schedule of interim analyses</span></span>
<span id="cb1-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param sided # Whether the test is 1-sided or 2-sided</span></span>
<span id="cb1-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param alpha # Specified alpha level, the default is 0.05</span></span>
<span id="cb1-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param informationRates #</span></span>
<span id="cb1-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param trials # The total number of trials you wish to load in the table results.</span></span>
<span id="cb1-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param typeOfDesign # The type of design.</span></span>
<span id="cb1-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param seed # Argument to set the seed for the simulations</span></span>
<span id="cb1-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @return list of dataframes and plots</span></span>
<span id="cb1-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @example See below this code block</span></span>
<span id="cb1-29">interim_sim <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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nPatients =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">death1 =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">death2 =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,</span>
<span id="cb1-30">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nLooks =</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;">analyses_scheduled =</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.25</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.50</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb1-31">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sided =</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;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>,</span>
<span id="cb1-32">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">informationRates =</span> analyses_scheduled,</span>
<span id="cb1-33">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">typeOfDesign =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"asOF"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nSims =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trials =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span id="cb1-34">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>) {</span>
<span id="cb1-35"></span>
<span id="cb1-36">efficacy_thresholds <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>(nLooks)</span>
<span id="cb1-37">design <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;">getDesignGroupSequential</span>(</span>
<span id="cb1-38">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sided =</span> sided, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> alpha,</span>
<span id="cb1-39">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">informationRates =</span> analyses_scheduled,</span>
<span id="cb1-40">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">typeOfDesign =</span> typeOfDesign)</span>
<span id="cb1-41">design_2 <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;">getDesignGroupSequential</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">typeOfDesign =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Pocock</span></span>
<span id="cb1-42">design_3 <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;">getDesignGroupSequential</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">typeOfDesign =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"asP"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Alpha-spending Pocock</span></span>
<span id="cb1-43">design_4 <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;">getDesignGroupSequential</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">typeOfDesign =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OF"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># O'Brien-Fleming</span></span>
<span id="cb1-44">designSet <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;">getDesignSet</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">designs =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(design, design_2,</span>
<span id="cb1-45">                                      design_3, design_4),</span>
<span id="cb1-46">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variedParameters =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"typeOfDesign"</span>)</span>
<span id="cb1-47"></span>
<span id="cb1-48"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">RNGkind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"L'Ecuyer-CMRG"</span>)</span>
<span id="cb1-49"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(seed)</span>
<span id="cb1-50"><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>nLooks) {</span>
<span id="cb1-51">  efficacy_thresholds[j] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> design<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>stageLevels[j]</span>
<span id="cb1-52">}</span>
<span id="cb1-53"></span>
<span id="cb1-54">analyses_nPatients <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> analyses_scheduled <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> nPatients</span>
<span id="cb1-55">efficacy_thresholds</span>
<span id="cb1-56">pb <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;">txtProgressBar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min =</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;">max =</span> nSims, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">initial =</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;">style =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb1-57">trialnum <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>(nSims)</span>
<span id="cb1-58">or <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 class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> nLooks, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> nSims))</span>
<span id="cb1-59">lcl <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 class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> nLooks, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> nSims))</span>
<span id="cb1-60">ucl <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 class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> nLooks, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> nSims))</span>
<span id="cb1-61">pval <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 class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> nLooks, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> nSims))</span>
<span id="cb1-62">success <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 class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> nLooks, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> nSims))</span>
<span id="cb1-63"></span>
<span id="cb1-64">strings <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OR_%d"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"LCL_%d"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"UCL_%d"</span>,</span>
<span id="cb1-65">             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Pval_%d"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Success_%d"</span>)</span>
<span id="cb1-66"></span>
<span id="cb1-67"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(or) <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;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OR_%d"</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>nLooks))</span>
<span id="cb1-68"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(lcl) <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;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"LCL_%d"</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>nLooks))</span>
<span id="cb1-69"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(ucl) <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;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"UCL_%d"</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>nLooks))</span>
<span id="cb1-70"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(pval) <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;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Pval_%d"</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>nLooks))</span>
<span id="cb1-71"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(success) <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;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Success_%d"</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>nLooks))</span>
<span id="cb1-72">overall_success <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>(nSims)</span>
<span id="cb1-73">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>(trialnum, or, lcl, ucl,</span>
<span id="cb1-74">                 pval, success, overall_success)</span>
<span id="cb1-75"></span>
<span id="cb1-76"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">RNGkind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"L'Ecuyer-CMRG"</span>)</span>
<span id="cb1-77"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(seed)</span>
<span id="cb1-78">time <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;">system.time</span>(</span>
<span id="cb1-79"><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>nSims) {</span>
<span id="cb1-80">  trialnum[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> i</span>
<span id="cb1-81">  pid <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;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, nPatients, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-82">  treatment <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;">rep</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;">2</span>, nPatients <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>
<span id="cb1-83">  deathprob <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>(nPatients)</span>
<span id="cb1-84">  deathprob[treatment <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="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> death1</span>
<span id="cb1-85">  deathprob[treatment <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="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> death2</span>
<span id="cb1-86">  death <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;">rbinom</span>(nPatients, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, deathprob)</span>
<span id="cb1-87">  trialdata <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 class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(pid, treatment, death))</span>
<span id="cb1-88"></span>
<span id="cb1-89">  <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>nLooks) {</span>
<span id="cb1-90">    analysisdata <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;">subset</span>(trialdata, pid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> analyses_nPatients[j])</span>
<span id="cb1-91">    model <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;">glm</span>(death <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> treatment,</span>
<span id="cb1-92">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">binomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>),</span>
<span id="cb1-93">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> analysisdata)</span>
<span id="cb1-94">    or[i, j] <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;">exp</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb1-95">    lcl[i, j] <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;">exp</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">confint.default</span>((model))[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb1-96">    ucl[i, j] <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;">exp</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">confint.default</span>((model))[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb1-97">    pval[i, j] <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;">summary</span>(model)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>]</span>
<span id="cb1-98">    success[i, j] <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>(or[i, j] <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;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> pval[i, j] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> efficacy_thresholds[j], <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;">0</span>)</span>
<span id="cb1-99">  }</span>
<span id="cb1-100">  overall_success[i] <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;">0</span></span>
<span id="cb1-101">  <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>nLooks) {</span>
<span id="cb1-102">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (success[i, j] <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>
<span id="cb1-103">      overall_success[i] <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-104">    }</span>
<span id="cb1-105">  }</span>
<span id="cb1-106">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setTxtProgressBar</span>(pb, i)</span>
<span id="cb1-107">})</span>
<span id="cb1-108"></span>
<span id="cb1-109">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>(trialnum, or, lcl, ucl, pval,</span>
<span id="cb1-110">                 success, overall_success)</span>
<span id="cb1-111">simulation_results <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 class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(),</span>
<span id="cb1-112">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> nPatients, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(df))))</span>
<span id="cb1-113"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(simulation_results) <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"trialnum"</span>, (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">do.call</span>(</span>
<span id="cb1-114">  rbind,</span>
<span id="cb1-115">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</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>(strings),</span>
<span id="cb1-116">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FUN =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(j) {</span>
<span id="cb1-117">      (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">do.call</span>(rbind, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</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>nLooks,</span>
<span id="cb1-118">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FUN =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(i) ((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(strings, i)))</span>
<span id="cb1-119">      )[]))[, j]</span>
<span id="cb1-120">    }</span>
<span id="cb1-121">  )</span>
<span id="cb1-122">)), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"overall_success"</span>)</span>
<span id="cb1-123">simulation_results[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">intersect</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(df), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(simulation_results))] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (df[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">intersect</span>(</span>
<span id="cb1-124">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(df),</span>
<span id="cb1-125">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(simulation_results)</span>
<span id="cb1-126">)])</span>
<span id="cb1-127">simulation_results <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.data.frame</span>(simulation_results)</span>
<span id="cb1-128"></span>
<span id="cb1-129">outputs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> simulation_results[, <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><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>(simulation_results))]</span>
<span id="cb1-130"></span>
<span id="cb1-131">cols <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.character</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>nLooks)</span>
<span id="cb1-132">rows <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.character</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>(strings))</span>
<span id="cb1-133">interim <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;">matrix</span>(</span>
<span id="cb1-134">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(strings), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> nLooks,</span>
<span id="cb1-135">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimnames =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>((rows), (cols)),</span>
<span id="cb1-136">  <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;">rep</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;">length</span>(strings) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> nLooks)))</span>
<span id="cb1-137"></span>
<span id="cb1-138"><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> cols) {</span>
<span id="cb1-139">  interim[, 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;">str_subset</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(outputs), i)</span>
<span id="cb1-140">}</span>
<span id="cb1-141"></span>
<span id="cb1-142"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(interim) <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;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Interim_Look_%d"</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>nLooks))</span>
<span id="cb1-143"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(simulation_results)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TrialNum"</span>)</span>
<span id="cb1-144"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(simulation_results)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(simulation_results)] <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Overall_Success"</span>)</span>
<span id="cb1-145">simulation_results_trials <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;">head</span>(simulation_results, trials)</span>
<span id="cb1-146">results <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;">list</span>(</span>
<span id="cb1-147">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(design),</span>
<span id="cb1-148">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(time),</span>
<span id="cb1-149">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(design, <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-150">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_light</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-151">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(</span>
<span id="cb1-152">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">14</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>),</span>
<span id="cb1-153">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>)</span>
<span id="cb1-154">    ),</span>
<span id="cb1-155">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(designSet, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</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-156">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_light</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-157">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(</span>
<span id="cb1-158">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">14</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>),</span>
<span id="cb1-159">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">face =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>)</span>
<span id="cb1-160">    ),</span>
<span id="cb1-161">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(overall_success),</span>
<span id="cb1-162">  simulation_results_trials)</span>
<span id="cb1-163"></span>
<span id="cb1-164"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(results) <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>
<span id="cb1-165">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Design Summary"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Time to complete simulation"</span>,</span>
<span id="cb1-166">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main Design Plot"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Plot of Various Designs"</span>,</span>
<span id="cb1-167">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Table of Overall Success"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Simulation Results"</span>)</span>
<span id="cb1-168"></span>
<span id="cb1-169"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(results)</span>
<span id="cb1-170">}</span></code></pre></div></div>
</div>
<hr>
</section>
<section id="a-simulated-example" class="level2">
<h2 class="anchored" data-anchor-id="a-simulated-example">A Simulated Example</h2>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">results <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;">interim_sim</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nPatients =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">death1 =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">death2 =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,</span>
<span id="cb2-2">                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nLooks =</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;">analyses_scheduled =</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.25</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.50</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb2-3">                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sided =</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;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">typeOfDesign =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"asOF"</span>,</span>
<span id="cb2-4">                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">informationRates =</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.25</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.50</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb2-5">                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nSims =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trials =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>)</span></code></pre></div></div>
</div>
<hr>
<hr>
</section>
<section id="examining-the-results" class="level2">
<h2 class="anchored" data-anchor-id="examining-the-results">Examining the Results</h2>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">results[<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;">5</span>]</span>
<span id="cb3-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; $`Design Summary`</span></span>
<span id="cb3-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb3-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; $`Time to complete simulation`</span></span>
<span id="cb3-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    user  system elapsed </span></span>
<span id="cb3-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    6.57    1.47    7.45 </span></span>
<span id="cb3-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb3-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; $`Main Design Plot`</span></span>
<span id="cb3-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; NULL</span></span>
<span id="cb3-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb3-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; $`Plot of Various Designs`</span></span>
<span id="cb3-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; NULL</span></span>
<span id="cb3-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb3-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; $`Table of Overall Success`</span></span>
<span id="cb3-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; overall_success</span></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   0   1 </span></span>
<span id="cb3-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 134 866</span></span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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>
<span id="cb4-2">table_results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> results[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>]]</span>
<span id="cb4-3"></span>
<span id="cb4-4">table_results[ , <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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>] <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;">round</span>((table_results[ , <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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>]), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb4-5"></span>
<span id="cb4-6">table_results<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>TrialNum <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;">row.names</span>(table_results)</span>
<span id="cb4-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row.names</span>(table_results) <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>
<span id="cb4-8"></span>
<span id="cb4-9"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(table_results)){</span>
<span id="cb4-10">  table_results[,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;">cell_spec</span>(table_results[,i], <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;">"#777"</span>)</span>
<span id="cb4-11">}</span>
<span id="cb4-12"></span>
<span id="cb4-13">table_results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> table_results[<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;">colnames</span>(table_results))]</span></code></pre></div></div>
</div>
<hr>
<p>To examine the results, I used the kableExtra package, though this is not necessary, and simply using the following script will suffice</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">table_results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> results[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>]]</span>
<span id="cb5-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">View</span>(table_results)</span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="lightable-classic caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
<col style="width: 4%">
</colgroup>
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: center; empty-cells: hide;"></th>
<th colspan="5" data-quarto-table-cell-role="th" style="text-align: center; padding-bottom: 0; padding-left: 3px; padding-right: 3px; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><div style="border-bottom: 1px solid #111111; margin-bottom: -1px; ">
Interim_Look_1
</div></th>
<th colspan="5" data-quarto-table-cell-role="th" style="text-align: center; padding-bottom: 0; padding-left: 3px; padding-right: 3px; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><div style="border-bottom: 1px solid #111111; margin-bottom: -1px; ">
Interim_Look_2
</div></th>
<th colspan="5" data-quarto-table-cell-role="th" style="text-align: center; padding-bottom: 0; padding-left: 3px; padding-right: 3px; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><div style="border-bottom: 1px solid #111111; margin-bottom: -1px; ">
Interim_Look_3
</div></th>
<th colspan="5" data-quarto-table-cell-role="th" style="text-align: center; padding-bottom: 0; padding-left: 3px; padding-right: 3px; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><div style="border-bottom: 1px solid #111111; margin-bottom: -1px; ">
Interim_Look_4
</div></th>
<th data-quarto-table-cell-role="th" style="text-align: center; empty-cells: hide;"></th>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">TrialNum</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">OR_1</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">LCL_1</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">UCL_1</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">Pval_1</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">Success_1</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">OR_2</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">LCL_2</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">UCL_2</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">Pval_2</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">Success_2</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">OR_3</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">LCL_3</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">UCL_3</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">Pval_3</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">Success_3</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">OR_4</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">LCL_4</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">UCL_4</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">Pval_4</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">Success_4</th>
<th data-quarto-table-cell-role="th" style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;">Overall_Success</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.936</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.565</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.55</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.797</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.868</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.601</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.255</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.453</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.036</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.767</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.398</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.818</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.891</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.687</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.157</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.387</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
</tr>
<tr class="even">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">2</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.87</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.519</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.459</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.598</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.757</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.525</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.092</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.136</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.745</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.551</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.007</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.056</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.721</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.555</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.936</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.014</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="odd">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">3</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.59</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.35</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.996</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.048</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.555</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.382</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.806</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.002</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.676</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.5</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.916</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.011</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.686</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.529</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.89</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.005</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="even">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">4</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.652</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.385</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.103</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.111</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.671</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.461</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.976</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.037</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.725</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.533</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.988</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.042</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.75</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.576</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.976</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.032</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
</tr>
<tr class="odd">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">5</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.674</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.398</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.142</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.143</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.763</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.526</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.108</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.155</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.835</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.617</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.132</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.246</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.764</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.587</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.994</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.045</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
</tr>
<tr class="even">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">6</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.525</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.309</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.892</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.017</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.622</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.427</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.907</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.014</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.668</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.491</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.909</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.01</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.625</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.479</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.815</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.001</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="odd">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">7</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.742</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.433</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.269</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.275</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.769</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.525</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.125</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.175</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.76</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.558</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.037</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.083</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.719</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.551</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.938</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.015</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="even">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">8</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.661</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.394</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.108</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.116</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.437</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.301</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.632</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.535</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.397</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.721</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.551</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.425</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.714</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="odd">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">9</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.288</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.76</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">2.183</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.348</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.113</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.769</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.612</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.571</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.87</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.645</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.173</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.361</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.771</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.596</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.999</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.049</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
</tr>
<tr class="even">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">10</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.783</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.466</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.316</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.356</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.701</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.484</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.015</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.06</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.655</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.482</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.89</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.007</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.614</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.472</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.798</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="odd">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">11</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.577</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.344</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.968</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.037</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.639</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.444</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.921</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.016</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.56</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.415</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.754</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.577</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.446</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.748</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="even">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">12</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.538</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.315</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.919</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.023</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.629</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.434</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.913</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.015</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.576</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.426</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.78</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.561</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.431</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.731</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="odd">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">13</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.79</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.474</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.315</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.364</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.763</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.531</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.095</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.142</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.789</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.588</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.06</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.115</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.791</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.611</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.025</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.076</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
</tr>
<tr class="even">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">14</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.535</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.318</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.902</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.019</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.69</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.477</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.999</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.049</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.583</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.43</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.792</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.001</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.621</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.477</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.809</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="odd">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">15</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.695</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.419</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.152</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.158</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.744</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.516</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.073</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.114</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.73</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.541</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.985</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.04</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.64</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.493</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.83</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.001</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="even">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">16</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.116</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.657</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.896</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.685</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.763</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.526</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.108</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.155</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.69</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.509</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.935</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.017</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.69</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.532</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.896</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.005</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="odd">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">17</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.533</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.32</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.886</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.015</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.585</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.407</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.839</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.004</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.679</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.504</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.913</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.011</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.622</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.48</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.806</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="even">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">18</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.613</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.364</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.033</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.066</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.692</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.478</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.05</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.78</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.577</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.055</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.107</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.705</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.543</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.914</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.008</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="odd">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">19</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.841</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.502</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.409</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.511</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.768</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.531</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1.11</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.16</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.685</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.506</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.927</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.014</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.665</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.511</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.864</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.002</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
<tr class="even">
<td style="text-align: center; font-weight: bold; color: rgba(102, 102, 102, 1) !important;"><span style="color: rgba(119, 119, 119, 1) !important;">20</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.275</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.159</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.476</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.449</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.31</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.651</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.498</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.369</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.672</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.498</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.384</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0.646</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">0</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
<td style="text-align: center;"><span style="color: rgba(119, 119, 119, 1) !important;">1</span></td>
</tr>
</tbody><tfoot>
<tr class="odd">
<td style="text-align: center; padding: 0;"><span style="text-decoration: underline;">Abbreviations: </span></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
</tr>
<tr class="even">
<td style="text-align: center; padding: 0;"><sup></sup> TrialNum: Trial Number | OR: Odds Ratio | LCL: Lower Confidence Level | UCL: Upper Confidence Level | Pval: P-value</td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
<td style="text-align: center;"></td>
</tr>
</tfoot>

</table>
</div>
</div>
</div>
<hr>
</section>
<section id="statistical-environment" class="level2">
<h2 class="anchored" data-anchor-id="statistical-environment">Statistical Environment</h2>
<hr>
<p>The analyses were run on:</p>
<hr>
<div class="cell" data-layout-align="center">
<pre><code>#&gt; ─ Session info ───────────────────────────────────────────────────────────────
#&gt;  setting  value
#&gt;  version  R version 4.6.1 (2026-06-24)
#&gt;  os       macOS Golden Gate 27.0
#&gt;  system   aarch64, darwin25.4.0
#&gt;  ui       unknown
#&gt;  language (EN)
#&gt;  collate  en_US
#&gt;  ctype    C.UTF-8
#&gt;  tz       America/New_York
#&gt;  date     2026-09-13
#&gt;  pandoc   3.11 @ /opt/homebrew/bin/ (via rmarkdown)
#&gt;  quarto   1.10.18 @ /usr/local/bin/quarto
#&gt; 
#&gt; ─ Packages ───────────────────────────────────────────────────────────────────
#&gt;  package           * version  date (UTC) lib source
#&gt;  abind               1.4-8    2024-09-12 [1] CRAN (R 4.6.1)
#&gt;  Amelia            * 1.8.3    2024-11-08 [1] CRAN (R 4.6.1)
#&gt;  arm                 1.15-3   2026-04-15 [1] CRAN (R 4.6.1)
#&gt;  arrayhelpers        1.1-2    2026-07-24 [1] CRAN (R 4.6.1)
#&gt;  backports           1.5.1    2026-04-03 [1] CRAN (R 4.6.1)
#&gt;  base              * 4.6.1    2026-06-24 [2] local
#&gt;  base64enc           0.1-6    2026-02-02 [1] CRAN (R 4.6.1)
#&gt;  bayesplot         * 1.16.0   2026-08-25 [1] CRAN (R 4.6.1)
#&gt;  bitops              1.1-0    2026-07-30 [1] CRAN (R 4.6.1)
#&gt;  blogdown          * 1.24     2026-06-19 [1] CRAN (R 4.6.1)
#&gt;  boot              * 1.3-32   2025-08-29 [1] CRAN (R 4.6.1)
#&gt;  bootImpute        * 1.3.0    2025-12-15 [1] CRAN (R 4.6.1)
#&gt;  bridgesampling      1.2-1    2025-11-19 [1] CRAN (R 4.6.1)
#&gt;  brms              * 2.23.0   2025-09-09 [1] CRAN (R 4.6.1)
#&gt;  Brobdingnag         1.2-9    2022-10-19 [1] CRAN (R 4.6.1)
#&gt;  broom             * 1.0.13   2026-05-14 [1] CRAN (R 4.6.1)
#&gt;  broom.mixed       * 0.2.9.7  2026-02-17 [1] CRAN (R 4.6.1)
#&gt;  Cairo             * 1.7-0    2025-10-29 [1] CRAN (R 4.6.1)
#&gt;  car               * 3.1-5    2026-02-03 [1] CRAN (R 4.6.1)
#&gt;  carData           * 3.0-6    2026-01-30 [1] CRAN (R 4.6.1)
#&gt;  caTools             1.18.4   2026-07-20 [1] CRAN (R 4.6.1)
#&gt;  checkmate         * 2.3.4    2026-02-03 [1] CRAN (R 4.6.1)
#&gt;  class               7.3-24   2026-08-03 [1] CRAN (R 4.6.1)
#&gt;  cli               * 3.6.6    2026-04-09 [1] CRAN (R 4.6.1)
#&gt;  clipr               0.8.1    2026-05-25 [1] CRAN (R 4.6.1)
#&gt;  cluster             2.1.8.3  2026-07-30 [1] CRAN (R 4.6.1)
#&gt;  coda              * 0.19-4.1 2024-01-31 [1] CRAN (R 4.6.1)
#&gt;  codetools           0.2-20   2024-03-31 [1] CRAN (R 4.6.0)
#&gt;  colorspace        * 2.1-3    2026-07-12 [1] CRAN (R 4.6.1)
#&gt;  compiler            4.6.1    2026-06-24 [2] local
#&gt;  concurve          * 3.0.5    2026-09-13 [1] local
#&gt;  cowplot           * 1.2.0    2025-07-07 [1] CRAN (R 4.6.1)
#&gt;  crayon              1.5.3    2024-06-20 [1] CRAN (R 4.6.1)
#&gt;  curl                8.0.0    2026-08-25 [1] CRAN (R 4.6.1)
#&gt;  data.table          1.18.6.1 2026-08-24 [1] CRAN (R 4.6.1)
#&gt;  datasets          * 4.6.1    2026-06-24 [2] local
#&gt;  DBI                 1.3.0    2026-02-25 [1] CRAN (R 4.6.1)
#&gt;  DEoptimR            1.2-1    2026-08-20 [1] CRAN (R 4.6.1)
#&gt;  desc                1.4.3    2023-12-10 [1] CRAN (R 4.6.1)
#&gt;  details             0.4.0    2025-02-09 [1] CRAN (R 4.6.0)
#&gt;  dichromat           2.0-1    2026-07-22 [1] CRAN (R 4.6.1)
#&gt;  digest              0.6.39   2025-11-19 [1] CRAN (R 4.6.1)
#&gt;  distributional      0.9.0    2026-09-08 [1] CRAN (R 4.6.1)
#&gt;  doParallel        * 1.0.17   2022-02-07 [1] CRAN (R 4.6.1)
#&gt;  doRNG               1.8.6.3  2026-02-05 [1] CRAN (R 4.6.1)
#&gt;  dplyr             * 1.2.1    2026-04-03 [1] CRAN (R 4.6.1)
#&gt;  e1071               1.7-17   2025-12-18 [1] CRAN (R 4.6.1)
#&gt;  emmeans             2.0.4    2026-07-15 [1] CRAN (R 4.6.1)
#&gt;  estimability        2.0.0    2026-06-26 [1] CRAN (R 4.6.1)
#&gt;  evaluate            1.0.5    2025-08-27 [1] CRAN (R 4.6.1)
#&gt;  extremevalues       2.4.1    2024-12-17 [1] CRAN (R 4.6.1)
#&gt;  farver              2.1.2    2024-05-13 [1] CRAN (R 4.6.1)
#&gt;  fastmap             1.2.0    2024-05-15 [1] CRAN (R 4.6.1)
#&gt;  forcats           * 1.0.1    2025-09-25 [1] CRAN (R 4.6.1)
#&gt;  foreach           * 1.5.2    2022-02-02 [1] CRAN (R 4.6.1)
#&gt;  foreign             0.8-91   2026-01-29 [1] CRAN (R 4.6.1)
#&gt;  Formula             1.2-6    2026-08-03 [1] CRAN (R 4.6.1)
#&gt;  fs                  2.1.0    2026-04-18 [1] CRAN (R 4.6.1)
#&gt;  furrr               0.4.0    2026-03-31 [1] CRAN (R 4.6.1)
#&gt;  future            * 1.75.0   2026-07-20 [1] CRAN (R 4.6.1)
#&gt;  future.apply      * 1.20.2   2026-02-20 [1] CRAN (R 4.6.1)
#&gt;  gamlss            * 5.5-0    2025-08-19 [1] CRAN (R 4.6.1)
#&gt;  gamlss.data       * 6.0-7    2025-09-04 [1] CRAN (R 4.6.1)
#&gt;  gamlss.dist       * 6.1-11   2026-09-10 [1] CRAN (R 4.6.1)
#&gt;  generics            0.1.4    2025-05-09 [1] CRAN (R 4.6.1)
#&gt;  ggcorrplot        * 0.3.0    2026-07-24 [1] CRAN (R 4.6.1)
#&gt;  ggdist              3.3.3    2025-04-23 [1] CRAN (R 4.6.1)
#&gt;  ggplot2           * 4.0.3    2026-04-22 [1] CRAN (R 4.6.1)
#&gt;  ggtext            * 0.2.0    2026-08-28 [1] CRAN (R 4.6.1)
#&gt;  glmnet              5.0      2026-05-04 [1] CRAN (R 4.6.1)
#&gt;  globals             0.19.1   2026-03-13 [1] CRAN (R 4.6.1)
#&gt;  glue                1.8.1    2026-04-17 [1] CRAN (R 4.6.1)
#&gt;  graphics          * 4.6.1    2026-06-24 [2] local
#&gt;  grDevices         * 4.6.1    2026-06-24 [2] local
#&gt;  grid              * 4.6.1    2026-06-24 [2] local
#&gt;  gridExtra           2.3.1    2026-06-25 [1] CRAN (R 4.6.1)
#&gt;  gridtext            0.1.6    2026-02-19 [1] CRAN (R 4.6.0)
#&gt;  gtable              0.3.6    2024-10-25 [1] CRAN (R 4.6.1)
#&gt;  gtsummary         * 2.6.1    2026-09-04 [1] CRAN (R 4.6.1)
#&gt;  here              * 1.0.2    2025-09-15 [1] CRAN (R 4.6.1)
#&gt;  Hmisc             * 5.3-0    2026-09-06 [1] CRAN (R 4.6.1)
#&gt;  hms                 1.1.4    2025-10-17 [1] CRAN (R 4.6.1)
#&gt;  htmlTable           2.5.0    2026-04-22 [1] CRAN (R 4.6.1)
#&gt;  htmltools         * 0.5.9    2025-12-04 [1] CRAN (R 4.6.1)
#&gt;  htmlwidgets         1.6.4    2023-12-06 [1] CRAN (R 4.6.1)
#&gt;  httr                1.4.9    2026-09-01 [1] CRAN (R 4.6.1)
#&gt;  ImputeRobust      * 1.3-1    2018-11-30 [1] CRAN (R 4.6.1)
#&gt;  inline              0.3.21   2025-01-09 [1] CRAN (R 4.6.1)
#&gt;  insight             1.5.4    2026-09-05 [1] CRAN (R 4.6.1)
#&gt;  iterators         * 1.0.14   2022-02-05 [1] CRAN (R 4.6.1)
#&gt;  itertools           0.1-3    2014-03-12 [1] CRAN (R 4.6.1)
#&gt;  jomo                2.7-6    2023-04-15 [1] CRAN (R 4.6.1)
#&gt;  jsonlite            2.0.0    2025-03-27 [1] CRAN (R 4.6.1)
#&gt;  kableExtra        * 1.4.1    2026-07-08 [1] CRAN (R 4.6.1)
#&gt;  knitr             * 1.52     2026-09-06 [1] CRAN (R 4.6.1)
#&gt;  labeling            0.4.3    2023-08-29 [1] CRAN (R 4.6.1)
#&gt;  laeken              0.5.3    2024-01-25 [1] CRAN (R 4.6.1)
#&gt;  latex2exp         * 0.9.8    2026-01-09 [1] CRAN (R 4.6.1)
#&gt;  lattice           * 0.23-1   2026-08-12 [1] CRAN (R 4.6.1)
#&gt;  lifecycle           1.0.5    2026-01-08 [1] CRAN (R 4.6.1)
#&gt;  listenv             1.0.0    2026-06-22 [1] CRAN (R 4.6.1)
#&gt;  lme4                2.0-6    2026-07-16 [1] CRAN (R 4.6.1)
#&gt;  lmtest              0.9-40   2022-03-21 [1] CRAN (R 4.6.1)
#&gt;  loo               * 2.10.1   2026-07-24 [1] CRAN (R 4.6.1)
#&gt;  lubridate         * 1.9.5    2026-02-04 [1] CRAN (R 4.6.1)
#&gt;  magick              2.9.1    2026-02-28 [1] CRAN (R 4.6.1)
#&gt;  magrittr          * 2.0.5    2026-04-04 [1] CRAN (R 4.6.1)
#&gt;  MASS              * 7.3-66   2026-07-15 [1] CRAN (R 4.6.1)
#&gt;  Matrix            * 1.7-6    2026-07-25 [1] CRAN (R 4.6.1)
#&gt;  MatrixModels        0.5-4    2025-03-26 [1] CRAN (R 4.6.1)
#&gt;  matrixStats         1.5.0    2025-01-07 [1] CRAN (R 4.6.1)
#&gt;  mcmc                0.9-8    2023-11-16 [1] CRAN (R 4.6.1)
#&gt;  MCMCpack          * 1.7-1    2024-08-27 [1] CRAN (R 4.6.1)
#&gt;  methods           * 4.6.1    2026-06-24 [2] local
#&gt;  mgcv              * 1.9-4    2025-11-07 [1] CRAN (R 4.6.0)
#&gt;  mi                * 1.3.1    2026-07-28 [1] CRAN (R 4.6.1)
#&gt;  mice              * 3.19.0   2025-12-10 [1] CRAN (R 4.6.1)
#&gt;  miceadds          * 3.20-10  2026-05-28 [1] CRAN (R 4.6.1)
#&gt;  miceFast          * 0.9.1    2026-02-26 [1] CRAN (R 4.6.1)
#&gt;  minqa               1.2.8    2024-08-17 [1] CRAN (R 4.6.1)
#&gt;  missForest        * 1.6.1    2025-10-26 [1] CRAN (R 4.6.1)
#&gt;  mitml             * 0.4-5    2023-03-08 [1] CRAN (R 4.6.1)
#&gt;  mitools             2.7      2026-08-31 [1] CRAN (R 4.6.1)
#&gt;  multcomp            1.4-32   2026-08-21 [1] CRAN (R 4.6.1)
#&gt;  mvtnorm           * 1.4-2    2026-07-12 [1] CRAN (R 4.6.1)
#&gt;  nlme              * 3.1-171  2026-09-01 [1] CRAN (R 4.6.1)
#&gt;  nloptr              2.2.1    2025-03-17 [1] CRAN (R 4.6.1)
#&gt;  nnet                7.3-21   2026-08-03 [1] CRAN (R 4.6.1)
#&gt;  opdisDownsampling   1.7      2026-09-04 [1] CRAN (R 4.6.1)
#&gt;  otel                0.2.0    2025-08-29 [1] CRAN (R 4.6.1)
#&gt;  pan                 2.0      2026-06-30 [1] CRAN (R 4.6.1)
#&gt;  pander              0.6.6    2025-03-01 [1] CRAN (R 4.6.1)
#&gt;  parallel          * 4.6.1    2026-06-24 [2] local
#&gt;  parallelly        * 1.48.0   2026-06-29 [1] CRAN (R 4.6.1)
#&gt;  pbmcapply         * 1.5.1    2022-04-28 [1] CRAN (R 4.6.1)
#&gt;  performance       * 0.18.2   2026-09-10 [1] CRAN (R 4.6.1)
#&gt;  pillar              1.11.1   2025-09-17 [1] CRAN (R 4.6.1)
#&gt;  pkgbuild            1.4.8    2025-05-26 [1] CRAN (R 4.6.1)
#&gt;  pkgconfig           2.0.3    2019-09-22 [1] CRAN (R 4.6.1)
#&gt;  plyr                1.8.9    2023-10-02 [1] CRAN (R 4.6.1)
#&gt;  png                 0.1-9    2026-03-15 [1] CRAN (R 4.6.0)
#&gt;  polspline           1.1.25   2024-05-10 [1] CRAN (R 4.6.1)
#&gt;  posterior         * 1.7.0    2026-04-01 [1] CRAN (R 4.6.1)
#&gt;  pracma              2.4.6    2025-10-22 [1] CRAN (R 4.6.1)
#&gt;  prettyunits         1.2.0    2023-09-24 [1] CRAN (R 4.6.1)
#&gt;  ProfileLikelihood * 1.3      2023-08-25 [1] CRAN (R 4.6.1)
#&gt;  progress          * 1.2.3    2023-12-06 [1] CRAN (R 4.6.1)
#&gt;  proxy               0.4-29   2025-12-29 [1] CRAN (R 4.6.1)
#&gt;  purrr             * 1.2.2    2026-04-10 [1] CRAN (R 4.6.1)
#&gt;  qqconf              1.3.2    2023-04-14 [1] CRAN (R 4.6.1)
#&gt;  qqplotr           * 0.0.7    2025-09-05 [1] CRAN (R 4.6.1)
#&gt;  quantreg          * 6.1      2025-03-10 [1] CRAN (R 4.6.1)
#&gt;  QuickJSR            1.11.0   2026-08-21 [1] CRAN (R 4.6.1)
#&gt;  R6                  2.6.1    2025-02-15 [1] CRAN (R 4.6.1)
#&gt;  randomForest      * 4.7-1.2  2024-09-22 [1] CRAN (R 4.6.1)
#&gt;  ranger              0.18.0   2026-01-16 [1] CRAN (R 4.6.1)
#&gt;  rappdirs            0.3.4    2026-01-17 [1] CRAN (R 4.6.1)
#&gt;  rapportools         1.2      2025-02-28 [1] CRAN (R 4.6.1)
#&gt;  rbibutils           2.4.1    2026-01-21 [1] CRAN (R 4.6.1)
#&gt;  RColorBrewer        1.1-3    2022-04-03 [1] CRAN (R 4.6.1)
#&gt;  Rcpp              * 1.1.2    2026-07-05 [1] CRAN (R 4.6.1)
#&gt;  RcppParallel        6.2.1    2026-08-27 [1] CRAN (R 4.6.1)
#&gt;  Rdpack              2.6.6    2026-02-08 [1] CRAN (R 4.6.1)
#&gt;  readr             * 2.2.0    2026-02-19 [1] CRAN (R 4.6.1)
#&gt;  reformulas          0.4.4    2026-02-02 [1] CRAN (R 4.6.1)
#&gt;  rematch2            2.1.2    2020-05-01 [1] CRAN (R 4.6.1)
#&gt;  reshape2          * 1.4.5    2025-11-12 [1] CRAN (R 4.6.1)
#&gt;  reticulate        * 1.47.0   2026-09-03 [1] CRAN (R 4.6.1)
#&gt;  rlang               1.3.0    2026-07-05 [1] CRAN (R 4.6.1)
#&gt;  rmarkdown         * 2.32     2026-09-01 [1] CRAN (R 4.6.1)
#&gt;  rms               * 8.1-1    2026-02-18 [1] CRAN (R 4.6.1)
#&gt;  rngtools            1.5.2    2021-09-20 [1] CRAN (R 4.6.1)
#&gt;  robustbase          0.99-7   2026-02-05 [1] CRAN (R 4.6.1)
#&gt;  rpact             * 4.4.0    2026-03-04 [1] CRAN (R 4.6.1)
#&gt;  rpart               4.1.27   2026-03-27 [1] CRAN (R 4.6.0)
#&gt;  rprojroot           2.1.1    2025-08-26 [1] CRAN (R 4.6.1)
#&gt;  rstan             * 2.32.7   2025-03-10 [1] CRAN (R 4.6.1)
#&gt;  rstantools          2.7.1    2026-09-04 [1] Github (stan-dev/rstantools@4d84659)
#&gt;  rstudioapi          0.19.0   2026-06-11 [1] CRAN (R 4.6.1)
#&gt;  S7                  0.2.2    2026-04-22 [1] CRAN (R 4.6.1)
#&gt;  sandwich            3.1-3    2026-08-03 [1] CRAN (R 4.6.1)
#&gt;  scales              1.4.0    2025-04-24 [1] CRAN (R 4.6.1)
#&gt;  sessioninfo         1.2.4    2026-06-04 [1] CRAN (R 4.6.1)
#&gt;  shape               1.4.6.1  2024-02-23 [1] CRAN (R 4.6.1)
#&gt;  showtext          * 0.9-8    2026-03-21 [1] CRAN (R 4.6.1)
#&gt;  showtextdb        * 3.0      2020-06-04 [1] CRAN (R 4.6.1)
#&gt;  sp                  2.2-3    2026-07-19 [1] CRAN (R 4.6.1)
#&gt;  SparseM           * 1.84-2   2024-07-17 [1] CRAN (R 4.6.1)
#&gt;  splines           * 4.6.1    2026-06-24 [2] local
#&gt;  StanHeaders       * 2.39.1   2026-09-02 [1] CRAN (R 4.6.1)
#&gt;  Statamarkdown     * 1.0.0    2026-08-21 [1] CRAN (R 4.6.1)
#&gt;  stats             * 4.6.1    2026-06-24 [2] local
#&gt;  stats4            * 4.6.1    2026-06-24 [2] local
#&gt;  stringi             1.8.9    2026-08-04 [1] CRAN (R 4.6.1)
#&gt;  stringr           * 1.6.0    2025-11-04 [1] CRAN (R 4.6.1)
#&gt;  summarytools      * 1.1.5    2026-06-25 [1] Github (dcomtois/summarytools@2b613cf)
#&gt;  survival            3.8-12   2026-09-09 [1] CRAN (R 4.6.1)
#&gt;  svglite           * 2.2.2    2025-10-21 [1] CRAN (R 4.6.1)
#&gt;  svgPanZoom          0.3.4    2020-02-15 [1] CRAN (R 4.6.1)
#&gt;  svUnit              1.0.8    2025-08-26 [1] CRAN (R 4.6.1)
#&gt;  sysfonts          * 0.8.9    2024-03-02 [1] CRAN (R 4.6.1)
#&gt;  systemfonts         1.3.2    2026-03-05 [1] CRAN (R 4.6.1)
#&gt;  tcltk               4.6.1    2026-06-24 [2] local
#&gt;  tensorA             0.36.2.1 2023-12-13 [1] CRAN (R 4.6.0)
#&gt;  texPreview        * 2.1.0    2024-01-24 [1] CRAN (R 4.6.0)
#&gt;  textshaping         1.0.5    2026-03-06 [1] CRAN (R 4.6.0)
#&gt;  TH.data             1.1-5    2025-11-17 [1] CRAN (R 4.6.0)
#&gt;  tibble            * 3.3.1    2026-01-11 [1] CRAN (R 4.6.1)
#&gt;  tidybayes         * 3.0.7    2024-09-15 [1] CRAN (R 4.6.1)
#&gt;  tidyr             * 1.3.2    2025-12-19 [1] CRAN (R 4.6.1)
#&gt;  tidyselect          1.2.1    2024-03-11 [1] CRAN (R 4.6.1)
#&gt;  tidyverse         * 2.0.0    2023-02-22 [1] CRAN (R 4.6.1)
#&gt;  timechange          0.4.0    2026-01-29 [1] CRAN (R 4.6.1)
#&gt;  tinytex           * 0.60     2026-06-16 [1] CRAN (R 4.6.1)
#&gt;  tools               4.6.1    2026-06-24 [2] local
#&gt;  twosamples          2.0.1    2023-06-23 [1] CRAN (R 4.6.1)
#&gt;  tzdb                0.5.0    2025-03-15 [1] CRAN (R 4.6.1)
#&gt;  utils             * 4.6.1    2026-06-24 [2] local
#&gt;  V8                  8.2.0    2026-04-21 [1] CRAN (R 4.6.0)
#&gt;  vcd                 1.4-14   2026-07-29 [1] CRAN (R 4.6.1)
#&gt;  vctrs               0.7.3    2026-04-11 [1] CRAN (R 4.6.1)
#&gt;  VIM               * 7.3.1    2026-09-11 [1] CRAN (R 4.6.1)
#&gt;  viridisLite         0.4.3    2026-02-04 [1] CRAN (R 4.6.1)
#&gt;  wesanderson       * 0.3.7    2023-10-31 [1] CRAN (R 4.6.1)
#&gt;  whisker             0.4.1    2022-12-05 [1] CRAN (R 4.6.1)
#&gt;  withr               3.0.3    2026-06-19 [1] CRAN (R 4.6.1)
#&gt;  xfun              * 0.60     2026-07-09 [1] CRAN (R 4.6.1)
#&gt;  xgboost             3.2.1.1  2026-03-18 [1] CRAN (R 4.6.1)
#&gt;  xml2                1.6.0    2026-06-22 [1] CRAN (R 4.6.1)
#&gt;  xtable              1.8-8    2026-02-22 [1] CRAN (R 4.6.1)
#&gt;  yaml                2.3.12   2025-12-10 [1] CRAN (R 4.6.1)
#&gt;  yardstick         * 1.4.0    2026-04-07 [1] CRAN (R 4.6.1)
#&gt;  zoo                 1.9-0    2026-07-31 [1] CRAN (R 4.6.1)
#&gt; 
#&gt;  [1] /opt/homebrew/lib/R/4.6/site-library
#&gt;  [2] /opt/homebrew/Cellar/r/4.6.1/lib/R/library
#&gt;  * ── Packages attached to the search path.
#&gt; 
#&gt; ─ External software ──────────────────────────────────────────────────────────
#&gt;  setting        value
#&gt;  cairo          1.18.4
#&gt;  cairoFT        2.14.3/2.18.1
#&gt;  pango
#&gt;  png
#&gt;  jpeg
#&gt;  tiff
#&gt;  tcl            9.0
#&gt;  curl           8.7.1
#&gt;  zlib           1.2.12
#&gt;  bzlib          1.0.8, 13-Jul-2019
#&gt;  xz             5.8.3
#&gt;  deflate
#&gt;  zstd           1.5.7
#&gt;  PCRE           10.48 2026-08-31
#&gt;  ICU            78.1
#&gt;  TRE            TRE 0.8.0 R_fixes (BSD)
#&gt;  iconv          Apple or GNU libiconv 1.11 /usr/lib/libiconv.2.dylib
#&gt;  readline       8.3
#&gt;  BLAS           /opt/homebrew/Cellar/openblas/0.3.34/lib/libopenblasp-r0.3.34.dylib
#&gt;  lapack         /opt/homebrew/Cellar/r/4.6.1/lib/R/lib/libRlapack.dylib
#&gt;  lapack_version 3.12.1
#&gt; 
#&gt; ─ Python configuration ───────────────────────────────────────────────────────
#&gt;  Python is not available
#&gt; 
#&gt; ──────────────────────────────────────────────────────────────────────────────
#&gt; $RNGkind
#&gt; [1] "L'Ecuyer-CMRG" "Inversion"     "Rejection"</code></pre>
</div>
<hr>
</section>
<section id="article-citation" class="level2">
<h2 class="anchored" data-anchor-id="article-citation">Article Citation</h2>
<p><span class="citation" data-cites="wassmer2018"><sup>1</sup></span></p>


<!-- -->


</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><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" data-entry-spacing="2" data-line-spacing="2">
<div id="ref-wassmer2018" class="csl-entry">
1. Wassmer G, Pahlke F. (2018). <span>“Rpact: Confirmatory adaptive clinical trial design and analysis.”</span> doi: <a href="https://doi.org/10.32614/CRAN.package.rpact">10.32614/CRAN.package.rpact</a>. <a href="https://doi.org/10.32614/CRAN.package.rpact">https://doi.org/10.32614/CRAN.package.rpact</a>.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@misc{rafi2021,
  author = {Rafi, Zad and Rafi, Zad},
  title = {Simulation of a {Two-Group} {Parallel-Arm} {RCT} with
    {Interim} {Analyses}},
  date = {2021-02-01},
  url = {https://lesslikely.com/statistics/interim_analyses},
  langid = {en-US},
  abstract = {A simulation of a two-group parallel-arm randomized trial
    with interim analysis using the rpact package.}
}
</code></pre></div></section></div> ]]></description>
  <category>statistics</category>
  <guid>https://lesslikely.com/statistics/interim_analyses.html</guid>
  <pubDate>Mon, 01 Feb 2021 05:00:00 GMT</pubDate>
  <media:content url="https://lesslikely.com/images/norm.svg" medium="image" type="image/svg+xml"/>
</item>
<item>
  <title>Tables, Graphs, and Computations from Rafi &amp; Greenland (2020)</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/statistics/RG2020BMC.html</link>
  <description><![CDATA[ 





<center>
<img src="https://res.cloudinary.com/less-likely/image/upload/v1602038429/Site/confidencecurve.svg" width="100" style="cursor: zoom-in" align="right">
</center>
<hr>
<p>The following post provides <em>some</em> of the code that was used to construct the figures and tables from <a href="https://doi.org/10.1186/s12874-020-01105-9">Rafi &amp; Greenland, 2020</a><span class="citation" data-cites="rafiSemanticCognitiveTools2020"><sup>1</sup></span>. An enhanced PDF version of the paper can be <a href="https://rdcu.be/b789P">found here</a>. For further discussion of the computations, see the appendix of the <a href="https://static-content.springer.com/esm/art%3A10.1186%2Fs12874-020-01105-9/MediaObjects/12874_2020_1105_MOESM1_ESM.pdf">main paper</a>, along with our <a href="https://arxiv.org/pdf/2008.12991.pdf">technical supplement</a>.<span class="citation" data-cites="greenlandTechnicalIssuesInterpretation2020"><sup>2</sup></span></p>
<hr>
<blockquote class="blockquote">
<p><strong>Disclaimer:</strong> I am responsible for all the code and mistakes below, and none of them can be attributed to my coauthors or my fellow package developers.</p>
</blockquote>
<hr>
<p>In order to recreate the functions, I would recommend installing the latest version of <a href="https://data.lesslikely.com/concurve/"><code>concurve</code></a> from <a href="https://cran.r-project.org/package=concurve">CRAN</a>, as it has patched some issues with graphing when the outcome is binary. Use the script below to get the latest version and load the <code>R</code> package. A number of other <code>R</code> packages are also used in this post, which are listed below.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">install.packages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"concurve"</span>)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"concurve"</span>)</span></code></pre></div></div>
</div>
<hr>
<section id="valid-p-values-are-uniform-under-the-null-model" class="level3">
<h3 class="anchored" data-anchor-id="valid-p-values-are-uniform-under-the-null-model">Valid <img src="https://latex.codecogs.com/png.latex?P">-values Are Uniform Under the Null Model</h3>
<hr>
<p>Here we show that valid <img src="https://latex.codecogs.com/png.latex?P">-values have specific properties, when the null model is true. We first generate two variables (<img src="https://latex.codecogs.com/png.latex?Y">, <img src="https://latex.codecogs.com/png.latex?X">) that come from the same normal distribution with a <img src="https://latex.codecogs.com/png.latex?%5Cmu"> of 0 and <img src="https://latex.codecogs.com/png.latex?%5Csigma"> of 1, each with a total of <code>1000</code> observations. We assume that there is no relationship between these two variables. We run a simple t-test between <img src="https://latex.codecogs.com/png.latex?Y"> and <img src="https://latex.codecogs.com/png.latex?X"> and iterate this <code>100000</code> times and compute <code>100000</code> <img src="https://latex.codecogs.com/png.latex?P">-values to see the overall distribution of the <img src="https://latex.codecogs.com/png.latex?P">-values, which we then plot using a histogram./</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">RNGkind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"L'Ecuyer-CMRG"</span>)</span>
<span id="cb2-2">set.seed <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;">1031</span></span>
<span id="cb2-3">n.sim <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;">100</span></span>
<span id="cb2-4">t.sim <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.sim)</span>
<span id="cb2-5">n.samp <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;">1000</span></span>
<span id="cb2-6"></span>
<span id="cb2-7"><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.sim) {</span>
<span id="cb2-8">    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>(n.samp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</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;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb2-9">    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;">rnorm</span>(n.samp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</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;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb2-10">    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, Y)</span>
<span id="cb2-11">    t <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>(X, Y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df)</span>
<span id="cb2-12">    t.sim[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> t[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]]</span>
<span id="cb2-13">}</span>
<span id="cb2-14"></span>
<span id="cb2-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</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> t.sim)) <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;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,</span>
<span id="cb2-16">    <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;">"#99c7c7"</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.25</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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of P-values Under the Null"</span>,</span>
<span id="cb2-17">    <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;">"P-value"</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;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</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.1</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;">theme_bw</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-4-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>This can also be shown using the <a href="https://cran.r-project.org/package=TeachingDemos"><code>TeachingDemos</code></a> <code>R</code> package, which has a function dedicated to showing this phenomenon.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TeachingDemos"</span>)</span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">RNGkind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"L'Ecuyer-CMRG"</span>)</span>
<span id="cb3-3">set.seed <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;">1031</span></span>
<span id="cb3-4">obs_p <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;">Pvalue.norm.sim</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</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;">mu0 =</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;">sigma =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb3-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma0 =</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;">test =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"two.sided"</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.05</span>,</span>
<span id="cb3-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e+05</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-5-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="code-copy-outer-scaffold"><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;">ggplot</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</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> obs_p)) <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;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,</span>
<span id="cb4-2">    <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;">"#99c7c7"</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.25</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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of P-values Under the Null"</span>,</span>
<span id="cb4-3">    <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;">"P-value"</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;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</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.1</span>)) <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;">theme_bw</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-5-2.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>As you can see, when the null model is true, the distribution of <img src="https://latex.codecogs.com/png.latex?P">-values is uniform. Valid <img src="https://latex.codecogs.com/png.latex?P">-values are uniform under the null hypothesis and their corresponding <img src="https://latex.codecogs.com/png.latex?S">-values are exponentially distributed. We run the same simulation as before, but then convert the obtained <img src="https://latex.codecogs.com/png.latex?P">-values into <img src="https://latex.codecogs.com/png.latex?S">-values, to see how they are distributed.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">RNGkind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"L'Ecuyer-CMRG"</span>)</span>
<span id="cb5-2">set.seed <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;">1031</span></span>
<span id="cb5-3">n.sim <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;">100</span></span>
<span id="cb5-4">t.sim <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.sim)</span>
<span id="cb5-5">n.samp <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;">1000</span></span>
<span id="cb5-6"></span>
<span id="cb5-7"><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.sim) {</span>
<span id="cb5-8">    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>(n.samp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</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;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb5-9">    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;">rnorm</span>(n.samp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</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;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb5-10">    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, Y)</span>
<span id="cb5-11">    t <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>(X, Y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df)</span>
<span id="cb5-12">    t.sim[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> t[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]]</span>
<span id="cb5-13">}</span>
<span id="cb5-14"></span>
<span id="cb5-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log2</span>(t.sim))) <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;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>,</span>
<span id="cb5-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</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;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d46c5b"</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 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;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of S-values Under the Null"</span>,</span>
<span id="cb5-17">    <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;">"S-value (Bits of Information)"</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;">theme_bw</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-6-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
</section>
<section id="posterior-predictive-p-values" class="level3">
<h3 class="anchored" data-anchor-id="posterior-predictive-p-values">Posterior Predictive <img src="https://latex.codecogs.com/png.latex?P">-values</h3>
<hr>
<p>Despite the name, posterior predictive <img src="https://latex.codecogs.com/png.latex?P">-values are not considered valid frequentist <img src="https://latex.codecogs.com/png.latex?P">-values because they do not meet the uniformity criterion, instead they are pulled towards the parameter value <code>0.5</code>. For further discussion, see our <a href="https://arxiv.org/pdf/2008.12991.pdf">technical supplement</a> along with <a href="https://doi.org/10.1080/00031305.2018.1529625">Greenland (2019)</a> for comprehensive theoretical discussions.<span class="citation" data-cites="greenlandValidPvaluesBehave2019 greenlandTechnicalIssuesInterpretation2020"><sup>2, 3</sup></span></p>
<p>A quick excerpt from our main paper and the technical supplement explains why this is not the case,</p>
<hr>
<blockquote class="blockquote">
<p>As discussed in the Supplement, in Bayesian settings one may see certain <img src="https://latex.codecogs.com/png.latex?P">-values that are not valid frequentist <img src="https://latex.codecogs.com/png.latex?P">-values, the primary example being the posterior predictive <img src="https://latex.codecogs.com/png.latex?P">-value<span class="citation" data-cites="bayarriValuesCompositeNull2000"><sup>4</sup></span>;<span class="citation" data-cites="robinsAsymptoticDistributionValues2000"><sup>5</sup></span>; unfortunately, the negative logs of such invalid <img src="https://latex.codecogs.com/png.latex?P">-values do not measure surprisal at the statistic given the model, and so are not valid <img src="https://latex.codecogs.com/png.latex?S">-values.</p>
<p>The decision rule “reject <strong>H</strong> if <img src="https://latex.codecogs.com/png.latex?p%5Cleq"> <img src="https://latex.codecogs.com/png.latex?%5Calpha">” will reject <strong>H</strong> 100<img src="https://latex.codecogs.com/png.latex?%5Calpha">% of the time under sampling from a model <strong>M</strong> obeying <strong>H</strong> (i.e., the Type-1 error rate of the test will be <img src="https://latex.codecogs.com/png.latex?%5Calpha">) provided the random variable <img src="https://latex.codecogs.com/png.latex?P"> corresponding to <img src="https://latex.codecogs.com/png.latex?p"> is valid (uniform under the model <strong>M</strong> used to compute it), but not necessarily otherwise<span class="citation" data-cites="kuffnerWhyArePvalues2019"><sup>6</sup></span>. This is one reason why frequentist writers reject invalid <img src="https://latex.codecogs.com/png.latex?P">-values (such as posterior predictive <img src="https://latex.codecogs.com/png.latex?P">-values, which highly concentrate around 0.50) and devote considerable technical coverage to uniform <img src="https://latex.codecogs.com/png.latex?P">-values<span class="citation" data-cites="kuffnerWhyArePvalues2019"><sup>6</sup></span>;<span class="citation" data-cites="robinsAsymptoticDistributionValues2000"><sup>5</sup></span>;<span class="citation" data-cites="bayarriValuesCompositeNull2000"><sup>4</sup></span>. A valid <img src="https://latex.codecogs.com/png.latex?P">-value (“U-value”) translates into an exponentially distributed <img src="https://latex.codecogs.com/png.latex?S">-value with a mean of 1 nat or <img src="https://latex.codecogs.com/png.latex?%5Clog_%7B2%7D(e)=1.443"> bits where <img src="https://latex.codecogs.com/png.latex?e"> is the base of the natural logs.</p>
<p>Uniformity is also central to the “refutational information” interpretation of the <img src="https://latex.codecogs.com/png.latex?S">-value used here, for it is necessary to ensure that the <img src="https://latex.codecogs.com/png.latex?P">-value <img src="https://latex.codecogs.com/png.latex?p"> from which <img src="https://latex.codecogs.com/png.latex?s"> is derived is in fact the percentile of the observed value of the test statistic in the distribution of the statistic under <strong>M</strong>, thus making small <img src="https://latex.codecogs.com/png.latex?p"> surprising under <strong>M</strong> and making <img src="https://latex.codecogs.com/png.latex?s"> the corresponding degree of surprise. Because posterior predictive <img src="https://latex.codecogs.com/png.latex?P">-values do not translate into sampling percentiles of the statistic under the hypothesis (in fact, they are pulled toward 0.5 from the correct percentiles)<span class="citation" data-cites="robinsAsymptoticDistributionValues2000"><sup>5</sup></span>;<span class="citation" data-cites="bayarriValuesCompositeNull2000"><sup>4</sup></span>, the resulting negative log does not measure surprisal at the statistic given <strong>M</strong>, and so is not a valid <img src="https://latex.codecogs.com/png.latex?S">-value in our terms.</p>
</blockquote>
<hr>
<p>And indeed, we can show this phenomenon below with simulations. Here we fit a simple Bayesian regression model with a weakly informative prior <code>normal(0, 10)</code> using <a href="https://mc-stan.org/rstanarm"><code>rstanarm</code></a>, where both the predictor and response variable come from the same distribution and have the same location and scale parameters (<img src="https://latex.codecogs.com/png.latex?%5Cmu%20=%200">, <img src="https://latex.codecogs.com/png.latex?%5Csigma%20=%201">. We then calculate the observed test statistics, along with their distributions, and convert them into posterior predictive <img src="https://latex.codecogs.com/png.latex?P">-values and plot them using <a href="https://mc-stan.org/bayesplot"><code>Bayesplot</code></a> functions. Then, we iterate this <code>1000</code> times to examine the distribution of posterior predictive <img src="https://latex.codecogs.com/png.latex?P">-values and compare them to standard <img src="https://latex.codecogs.com/png.latex?P">-values that are known to be uniform.</p>
<p>But first, we’ll generate the distribution of the test statistic from one model.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">library</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bayesplot"</span>)</span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rstan"</span>)</span>
<span id="cb6-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rstanarm"</span>)</span>
<span id="cb6-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rstan_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auto_write =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb6-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mc.cores =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb6-6">teal <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#99c7c7"</span>)</span>
<span id="cb6-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"teal"</span>)</span>
<span id="cb6-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">RNGkind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"L'Ecuyer-CMRG"</span>)</span>
<span id="cb6-9">n.samp <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;">100</span></span>
<span id="cb6-10">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>(n.samp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</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;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb6-11">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;">rnorm</span>(n.samp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</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;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb6-12">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, Y)</span>
<span id="cb6-13">mod1 <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;">stan_glm</span>(Y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> X, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">chains =</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;">cores =</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;">refresh =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb6-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prior =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>))</span>
<span id="cb6-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Error in `if (!prior_dist_name %in% unlist(ok_dists)) ...`:</span></span>
<span id="cb6-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ! argument is of length zero</span></span>
<span id="cb6-17">yrep <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;">posterior_predict</span>(mod1)</span>
<span id="cb6-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Error:</span></span>
<span id="cb6-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ! object 'mod1' not found</span></span>
<span id="cb6-20"></span>
<span id="cb6-21">h <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;">ppc_stat</span>(Y, yrep, <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;">"median"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">freq =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</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;">+</span></span>
<span id="cb6-22">    <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;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of Posterior Test Statistic"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-23">    <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 class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">yaxis_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">on =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb6-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Error:</span></span>
<span id="cb6-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ! object 'yrep' not found</span></span>
<span id="cb6-26"></span>
<span id="cb6-27">values_all <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> h[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plot_env"</span>]][[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"T_yrep"</span>]]</span>
<span id="cb6-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Error:</span></span>
<span id="cb6-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ! object 'h' not found</span></span>
<span id="cb6-30">prob_to_find <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> h[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plot_env"</span>]][[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"T_y"</span>]]</span>
<span id="cb6-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Error:</span></span>
<span id="cb6-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ! object 'h' not found</span></span>
<span id="cb6-33">quantInv <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>(distr, value) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ecdf</span>(distr)(value)</span>
<span id="cb6-34">posterior_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;">quantInv</span>(values_all, prob_to_find)</span>
<span id="cb6-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Error:</span></span>
<span id="cb6-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ! object 'values_all' not found</span></span>
<span id="cb6-37"></span>
<span id="cb6-38">l <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;">ppc_stat_2d</span>(Y, yrep) <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;">theme_bw</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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of Posterior Test Statistic"</span>)</span>
<span id="cb6-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Error:</span></span>
<span id="cb6-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ! object 'yrep' not found</span></span>
<span id="cb6-41"></span>
<span id="cb6-42"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(h)</span>
<span id="cb6-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Error in `h()`:</span></span>
<span id="cb6-44"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ! error in evaluating the argument 'x' in selecting a method for function 'plot': object 'h' not found</span></span>
<span id="cb6-45"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(l)</span>
<span id="cb6-46"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Error in `h()`:</span></span>
<span id="cb6-47"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ! error in evaluating the argument 'x' in selecting a method for function 'plot': object 'l' not found</span></span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">print</span>(prob_to_find)</span>
<span id="cb7-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Error in `h()`:</span></span>
<span id="cb7-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ! error in evaluating the argument 'x' in selecting a method for function 'print': object 'prob_to_find' not found</span></span></code></pre></div></div>
</div>
<hr>
<p>The above is the posterior predictive test statistic for one model, along with it’s distribution. Now let’s iterate this process, convert them into posterior predictive <img src="https://latex.codecogs.com/png.latex?P">-values, and generate their distribution.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">rstan_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">auto_write =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb8-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mc.cores =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb8-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">RNGkind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"L'Ecuyer-CMRG"</span>)</span>
<span id="cb8-4">set.seed <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;">1031</span></span>
<span id="cb8-5">n.sim <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;">100</span></span>
<span id="cb8-6">ppp <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.sim)</span>
<span id="cb8-7">n.samp <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;">1000</span></span>
<span id="cb8-8"></span>
<span id="cb8-9">quantInv <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>(distr, value) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ecdf</span>(distr)(value)</span>
<span id="cb8-10"></span>
<span id="cb8-11"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(ppp)) {</span>
<span id="cb8-12">    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>(n.samp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</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;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb8-13">    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;">rnorm</span>(n.samp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</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;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb8-14">    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, Y)</span>
<span id="cb8-15">    mod1 <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;">stan_glm</span>(Y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> X, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">chains =</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;">cores =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb8-16">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh =</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;">prior =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>))</span>
<span id="cb8-17">    yrep <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;">posterior_predict</span>(mod1)</span>
<span id="cb8-18">    h <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;">ppc_stat</span>(Y, yrep, <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;">"median"</span>)</span>
<span id="cb8-19">    values_all <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> h[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plot_env"</span>]][[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"T_yrep"</span>]]</span>
<span id="cb8-20">    prob_to_find <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> h[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plot_env"</span>]][[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"T_y"</span>]]</span>
<span id="cb8-21">    posterior_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;">quantInv</span>(values_all, prob_to_find)</span>
<span id="cb8-22">    ppp[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> posterior_p_value</span>
<span id="cb8-23">}</span>
<span id="cb8-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Error in `if (!prior_dist_name %in% unlist(ok_dists)) ...`:</span></span>
<span id="cb8-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ! argument is of length zero</span></span>
<span id="cb8-26"></span>
<span id="cb8-27"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</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> ppp)) <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;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,</span>
<span id="cb8-28">    <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;">"#99c7c7"</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.25</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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of Posterior Predictive P-values"</span>,</span>
<span id="cb8-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"From Simulation of 1000 Simple Linear Regressions"</span>,</span>
<span id="cb8-30">    <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;">"Posterior Predictive P-value"</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;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb8-31">    <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.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;">theme_bw</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-8-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>We can also show this in <code>Stata 16.1</code>, using their new <code>bayesstats ppvalues</code> command which generates posterior predictive <img src="https://latex.codecogs.com/png.latex?P">-values.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb9-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb9-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">seed</span> 1031</span>
<span id="cb9-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span> 100</span>
<span id="cb9-4"></span>
<span id="cb9-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">generate</span> x = rnormal(0, 1)</span>
<span id="cb9-6"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">generate</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</span> = rnormal(0, 1)</span>
<span id="cb9-7"></span>
<span id="cb9-8">* Bayesian linear regression <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">on</span> x, mirroring the rstanarm <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">model</span>.</span>
<span id="cb9-9">* Stata parameterizes the <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span>() prior <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">by</span> VARIANCE, so rstanarm's</span>
<span id="cb9-10">* <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span>(0, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span> = 10) is <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span>(0, 100) here. {<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</span>:} puts the prior <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">on</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">all</span></span>
<span id="cb9-11">* regression coefficients including the intercept -- bayesmh requires a</span>
<span id="cb9-12">* prior <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> every parameter. The <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">variance</span> gets a <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">proper</span> inverse-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">gamma</span></span>
<span id="cb9-13">* prior; a <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span> prior is invalid <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> {<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">var</span>} (its support includes</span>
<span id="cb9-14">* negative <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">values</span>).</span>
<span id="cb9-15">bayesmh <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</span> x, likelihood(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span>({<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">var</span>}))  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb9-16">    prior({<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</span>:}, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span>(0, 100))         <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb9-17">    prior({<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">var</span>}, igamma(0.01, 0.01))    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb9-18">    rseed(1031) mcmcsize(1000)          <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb9-19">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">saving</span>(bmh_sim, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span>)</span>
<span id="cb9-20"></span>
<span id="cb9-21">* Simulate replicated outcomes from the posterior predictive</span>
<span id="cb9-22">* distribution. This must <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">be</span> saved to a DIFFERENT file than the</span>
<span id="cb9-23">* bayesmh simulation dataset above.</span>
<span id="cb9-24">bayespredict {_ysim}, rseed(1031) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">saving</span>(bmh_pred, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span>)</span>
<span id="cb9-25"></span>
<span id="cb9-26">* Posterior predictive <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">p</span>-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">values</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">test</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">statistics</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> the replicated</span>
<span id="cb9-27">* outcome. (The R analog uses the <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">median</span>; @median is <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> a built-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span></span>
<span id="cb9-28">* bayespredict/bayesstats <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>, so we <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">use</span> the <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">mean</span> and <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">variance</span>,</span>
<span id="cb9-29">* matching the worked example <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> [BAYES] bayesstats ppvalues.)</span>
<span id="cb9-30">bayesstats ppvalues (tmean:@mean({_ysim})) (tvar:@variance({_ysim})) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb9-31">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">using</span> bmh_pred</span>
<span id="cb9-32">#&gt; Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> observations (_N) was 0, now 100.</span>
<span id="cb9-33">#&gt; </span>
<span id="cb9-34">#&gt; </span>
<span id="cb9-35">#&gt; </span>
<span id="cb9-36">#&gt; </span>
<span id="cb9-37">#&gt; Burn-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> ...</span>
<span id="cb9-38">#&gt; Simulation ...</span>
<span id="cb9-39">#&gt; </span>
<span id="cb9-40">#&gt; Model summary</span>
<span id="cb9-41">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb9-42">#&gt; Likelihood: </span>
<span id="cb9-43">#&gt;   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</span> ~ <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span>(xb_y,{<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">var</span>})</span>
<span id="cb9-44">#&gt; </span>
<span id="cb9-45">#&gt; Priors: </span>
<span id="cb9-46">#&gt;   {<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</span>:x <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span>} ~ <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span>(0,100)                                              (1)</span>
<span id="cb9-47">#&gt;         {<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">var</span>} ~ igamma(0.01,0.01)</span>
<span id="cb9-48">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb9-49">#&gt; (1) Parameters are elements <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> the linear form xb_y.</span>
<span id="cb9-50">#&gt; </span>
<span id="cb9-51">#&gt; Bayesian <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span> regression                       MCMC iterations  =      3,500</span>
<span id="cb9-52">#&gt; Random-walk Metropolis–Hastings sampling         Burn-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span>          =      2,500</span>
<span id="cb9-53">#&gt;                                                  MCMC <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">sample</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">size</span> =      1,000</span>
<span id="cb9-54">#&gt;                                                  Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span>    =        100</span>
<span id="cb9-55">#&gt;                                                  Acceptance rate  =      .2428</span>
<span id="cb9-56">#&gt;                                                  Efficiency:  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span> =    .001044</span>
<span id="cb9-57">#&gt;                                                               avg =     .04252</span>
<span id="cb9-58">#&gt; Log marginal-likelihood = -153.90987                          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span> =     .08305</span>
<span id="cb9-59">#&gt; </span>
<span id="cb9-60">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb9-61">#&gt;              |                                                Equal-tailed</span>
<span id="cb9-62">#&gt;              |      Mean   Std. <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">dev</span>.     MCSE     Median  [95% cred. interval]</span>
<span id="cb9-63">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb9-64">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</span>            |</span>
<span id="cb9-65">#&gt;            x |  .0115139   .1551555   .017026   .0145751  -.2995666   .3470796</span>
<span id="cb9-66">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |  .1022613    .137549   .020865   .1348998  -.2513679   .3455865</span>
<span id="cb9-67">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb9-68">#&gt;          <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">var</span> |  .9643251   .1503727    .14715   .9896135   .7582507   1.360154</span>
<span id="cb9-69">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb9-70">#&gt; </span>
<span id="cb9-71">#&gt; file bmh_sim.dta saved.</span>
<span id="cb9-72">#&gt; </span>
<span id="cb9-73">#&gt; </span>
<span id="cb9-74">#&gt; Computing predictions ...</span>
<span id="cb9-75">#&gt; </span>
<span id="cb9-76">#&gt; file bmh_pred.dta saved.</span>
<span id="cb9-77">#&gt; file bmh_pred.ster saved.</span>
<span id="cb9-78">#&gt; </span>
<span id="cb9-79">#&gt; </span>
<span id="cb9-80">#&gt; Posterior predictive summary   MCMC <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">sample</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">size</span> =     1,000</span>
<span id="cb9-81">#&gt; </span>
<span id="cb9-82">#&gt; -----------------------------------------------------------</span>
<span id="cb9-83">#&gt;            T |      Mean   Std. <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">dev</span>.  E(T_obs)  P(T&gt;=T_obs)</span>
<span id="cb9-84">#&gt; -------------+---------------------------------------------</span>
<span id="cb9-85">#&gt;        tmean |  .0550687   .1146021   .0206952         .632</span>
<span id="cb9-86">#&gt;         tvar |  .9896307   .2164376   .9710317         .484</span>
<span id="cb9-87">#&gt; -----------------------------------------------------------</span>
<span id="cb9-88">#&gt; Note: P(T&gt;=T_obs) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">close</span> to 0 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">or</span> 1 indicates lack <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">fit</span>.</span>
<span id="cb9-89">#&gt; </span>
<span id="cb9-90">#&gt; OMP: Warning #96: Cannot form a team with 2 threads, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">using</span> 1 instead.</span>
<span id="cb9-91">#&gt; OMP: Hint Consider unsetting KMP_DEVICE_THREAD_LIMIT (KMP_ALL_THREADS), KMP_TEAMS_THREAD_LIMIT, and OMP_THREAD_LIMIT (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> any are <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span>).</span></code></pre></div></div>
</div>
<hr>
<p>As we can see from the <code>R</code> plot above, the test statistics are are generally concentrated around <code>0.5</code> and the distribution (as shown above via the <code>R</code> code) hardly resembles the uniform distribution of <img src="https://latex.codecogs.com/png.latex?P">-value under the null model. Further, the base-2 log transformation of posterior predictive <img src="https://latex.codecogs.com/png.latex?P">-values is not exponentially distributed, making them invalid <img src="https://latex.codecogs.com/png.latex?S">-values in our terms.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log2</span>(ppp)))) <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;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>,</span>
<span id="cb10-2">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</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;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d46c5b"</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.25</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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of -log2(Posterior Predictive P-values)"</span>,</span>
<span id="cb10-3">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S-values Produced From Posterior Predictive P-values"</span>,</span>
<span id="cb10-4">    <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;">"-log2(Posterior Predictive P-value)"</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;">theme_bw</span>()</span>
<span id="cb10-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Error in `geom_histogram()`:</span></span>
<span id="cb10-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ! Problem while computing stat.</span></span>
<span id="cb10-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ℹ Error occurred in the 1st layer.</span></span>
<span id="cb10-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Caused by error in `seq_len()`:</span></span>
<span id="cb10-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ! argument must be coercible to non-negative integer</span></span></code></pre></div></div>
</div>
<hr>
</section>
<section id="table-1-some-p-values-s-values-maximum-likelihood-ratios-and-likelihood-ratio-statistics" class="level3">
<h3 class="anchored" data-anchor-id="table-1-some-p-values-s-values-maximum-likelihood-ratios-and-likelihood-ratio-statistics">Table 1: Some <img src="https://latex.codecogs.com/png.latex?P">-values, <img src="https://latex.codecogs.com/png.latex?S">-values, Maximum Likelihood Ratios, and Likelihood Ratio Statistics</h3>
<hr>
<p>Here, we look at some common <img src="https://latex.codecogs.com/png.latex?P">-values, and how they correspond to other information statistics and likelihood measures.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">pvalue <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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.99</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</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;">0.05</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.005</span>,</span>
<span id="cb11-2">    <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-04</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5 sigma (~ 2.9 in 10 million)"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1 in 100 million (GWAS)"</span>),</span>
<span id="cb11-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"6 sigma (~ 1 in a billion)"</span>))</span>
<span id="cb11-4"></span>
<span id="cb11-5">svalue <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;">round</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><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log2</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.99</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</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;">0.05</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>,</span>
<span id="cb11-6">    <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.005</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-04</span>)), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">21.7</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">26.6</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">29.9</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb11-7"></span>
<span id="cb11-8">pvalue[<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;">10</span>] <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;">formatC</span>(pvalue[<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;">10</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;">"e"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb11-9"></span>
<span id="cb11-10">mlr <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;">round</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.01</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.26</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.94</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.87</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">12.3</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">27.6</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">51.4</span>,</span>
<span id="cb11-11">    <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1935</span>, (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.2</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;">10</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;">5</span>)), (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.4</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;">10</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;">7</span>)), (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</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;">10</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;">8</span>))), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb11-12"></span>
<span id="cb11-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># likelihood ratio statistic</span></span>
<span id="cb11-14"></span>
<span id="cb11-15">lr <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;">round</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.00016</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.016</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.45</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.32</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.71</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.84</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.02</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.63</span>,</span>
<span id="cb11-16">    <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">7.88</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">15.1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">26.3</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">32.8</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">37.4</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb11-17"></span>
<span id="cb11-18">table1 <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>(pvalue, svalue, mlr, lr)</span>
<span id="cb11-19"></span>
<span id="cb11-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(table1) <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P-value (compatibility)"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S-value (bits)"</span>,</span>
<span id="cb11-21">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Maximum Likelihood Ratio"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Deviance Statistic 2ln(MLR)"</span>)</span>
<span id="cb11-22"></span>
<span id="cb11-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kbl</span>(table1, <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;">"html"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">padding =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">longtable =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb11-24">    <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;">"#777"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-25">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row_spec</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row =</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;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#777"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bold =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-26">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">column_spec</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">column =</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;">4</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;">"#777"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bold =</span> F) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-27">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable_classic</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">full_width =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">html_font =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cambria"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lightable_options =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"basic"</span>,</span>
<span id="cb11-28">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fixed_thead =</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;">enabled =</span> F)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-29">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">footnote</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">general_title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Abbreviations: "</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title_format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"underline"</span>,</span>
<span id="cb11-30">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">general =</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;">"Table 1 $P$-values                  and binary $S$-values, with corresponding maximum-likelihood ratios (MLR) and deviance (likelihood-ratio) statistics for a simple test hypothesis H under background assumptions A"</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<table class="lightable-classic caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">P-value (compatibility)</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">S-value (bits)</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Maximum Likelihood Ratio</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Deviance Statistic 2ln(MLR)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">0.99</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.00e+00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.00</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">0.9</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.15</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.01e+00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.02</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">0.5</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.26e+00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.45</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">0.25</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.94e+00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.32</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">0.1</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">3.32</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">3.87e+00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.71</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">0.05</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">4.32</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">6.83e+00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">3.84</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">0.025</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">5.32</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.23e+01</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">5.02</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">6.64</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.76e+01</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">6.63</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">0.005</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">7.64</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">5.14e+01</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">7.88</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">1e-04</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">13.29</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.94e+03</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">15.10</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">5 sigma (~ 2.9 in 10 million)</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">21.70</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">5.20e+05</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">26.30</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">1 in 100 million (GWAS)</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">26.60</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.40e+07</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">32.80</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">6 sigma (~ 1 in a billion)</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">29.90</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.30e+08</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">37.40</td>
</tr>
</tbody><tfoot>
<tr class="odd">
<td style="text-align: left; padding: 0;"><span style="text-decoration: underline;">Abbreviations: </span></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
<tr class="even">
<td style="text-align: left; padding: 0;"><sup></sup> Table 1 $P$-values and binary $S$-values, with corresponding maximum-likelihood ratios (MLR) and deviance (likelihood-ratio) statistics for a simple test hypothesis H under background assumptions A</td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
</tfoot>

</table>
</div>
</div>
<hr>
<p>For further discussion of 5 and 6 sigma cutoffs, see<span class="citation" data-cites="cousinsJeffreysLindleyParadox2017"><sup>7</sup></span>.</p>
<hr>
</section>
<section id="frequentist-interval-estimate-percentiles" class="level3">
<h3 class="anchored" data-anchor-id="frequentist-interval-estimate-percentiles">Frequentist Interval Estimate Percentiles</h3>
</section>
<section id="refer-to-long-run-coverage" class="level3">
<h3 class="anchored" data-anchor-id="refer-to-long-run-coverage">Refer to Long-Run Coverage</h3>
<hr>
<p>Here we simulate a study where one group with 100 participants has an <img src="https://latex.codecogs.com/png.latex?%5Cmu"> of <code>100</code> with a <img src="https://latex.codecogs.com/png.latex?%5Csigma"> of <code>20</code> and the second group has the same number of participants but an average of <code>80</code> and a standard deviation of <code>20.</code> We compare them using a Welch’s <img src="https://latex.codecogs.com/png.latex?t">-test and generate 95% compatibility intervals several times, specifically <code>100</code> times, and then plot them. Since we know the mean difference is <code>20</code>, we wish to see how often the interval estimates cover this true parameter value.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-12-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="1056"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>This shows that the intervals tend to vary simply as a result of randomness, and that the proper interpretation of the attached percentile is about long run coverage of the true parameter. However, this does not preclude interpretation of a single interval estimate from a study.<span class="citation" data-cites="coxChapterIntervalEstimation1974"><sup>8</sup></span> As we write in the <em>Replace unrealistic “confidence” claims with compatibility measures</em> section of our paper.<span class="citation" data-cites="rafiSemanticCognitiveTools2020"><sup>1</sup></span></p>
<hr>
<blockquote class="blockquote">
<p>The fact that “confidence” refers to the procedure behavior, not the reported interval, seems to be lost on most researchers. Remarking on this subtlety, when Jerzy Neyman discussed his confidence concept in 1934 at a meeting of the Royal Statistical Society, Arthur Bowley replied, “I am not at all sure that the ‘confidence’ is not a confidence trick.”<span class="citation" data-cites="bowleyDiscussionDrNeyman1934"><sup>9</sup></span>. And indeed, 40 years later, Cox and Hinkley warned, “interval estimates cannot be taken as probability statements about parameters, and foremost is the interpretation ‘such and such parameter values are consistent with the data.’”<span class="citation" data-cites="coxChapterIntervalEstimation1974"><sup>8</sup></span>. Unfortunately, the word “consistency” is used for several other concepts in statistics, while in logic it refers to an absolute condition (of noncontradiction); thus, its use in place of “confidence” would risk further confusion.</p>
<p>To address the problems above, we exploit the fact that a 95% CI summarizes the results of varying the test hypothesis H over a range of parameter values, displaying all values for which <img src="https://latex.codecogs.com/png.latex?p"> &gt; 0.05<span class="citation" data-cites="coxPrinciplesStatisticalInference2006"><sup>10</sup></span> and hence <img src="https://latex.codecogs.com/png.latex?s"> &lt; 4.32 bits<span class="citation" data-cites="greenlandValidPvaluesBehave2019"><sup>3</sup></span>;<span class="citation" data-cites="amrheinInferentialStatisticsDescriptive2019"><sup>11</sup></span>. Thus the CI contains a range of parameter values that are more compatible with the data than are values outside the interval, under the background assumptions<span class="citation" data-cites="greenlandValidPvaluesBehave2019"><sup>3</sup></span>;<span class="citation" data-cites="greenlandStatisticalTestsValues2016"><sup>12</sup></span>. Unconditionally (and thus even if the background assumptions are uncertain), the interval shows the values of the parameter which, when combined with the background assumptions, produce a test model that is “highly compatible” with the data in the sense of having less than 4.32 bits of information against it. We thus refer to CI as compatibility intervals rather than confidence intervals<span class="citation" data-cites="greenlandAreConfidenceIntervals2019"><sup>13</sup></span>;<span class="citation" data-cites="greenlandValidPvaluesBehave2019"><sup>3</sup></span>;<span class="citation" data-cites="amrheinInferentialStatisticsDescriptive2019"><sup>11</sup></span>; their abbreviation remains “CI.” We reject calling these intervals “uncertainty intervals,” because they do not capture uncertainty about background assumptions<span class="citation" data-cites="greenlandAreConfidenceIntervals2019"><sup>13</sup></span>.</p>
</blockquote>
<hr>
<p>Indeed, this also has to do with our paper on deemphasizing the model assumptions that are often behind common statistical outputs, and why it is necessary to treat them as uncertain, rather than given.<span class="citation" data-cites="greenlandAidScientificInference2020"><sup>14</sup></span> For example, a 95% interval estimate is assumed to be free of bias in its construction, however, it’s coverage claims are no longer so, once there are systematic errors in play. Many of these common, classical statistical procedures are designed to deal with random variation, and less so with bias (a relatively new field, with shiny new methods).</p>
<hr>
</section>
<section id="brown-et-al.-2017-reanalysis" class="level2">
<h2 class="anchored" data-anchor-id="brown-et-al.-2017-reanalysis">Brown et al.&nbsp;(2017) Reanalysis</h2>
<hr>
<p>Taken from the <a href="https://doi.org/10.1001/jama.2017.3415">Brown et al.&nbsp;data.</a><span class="citation" data-cites="brownAssociationSerotonergicAntidepressant2017 brownAssociationAntenatalExposure2017"><sup>15, 16</sup></span></p>
<p>Here we take the reported statistics from the Brown et al.&nbsp;studies in order to run statistical tests of different alternative test hypotheses and use those results to construct various functions.</p>
<p>We calculate the standard errors from the point estimate and the confidence (compatibility) limits.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">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;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</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.997</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.92</span></span>
<span id="cb12-2"></span>
<span id="cb12-3">logUL <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;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</span>)</span>
<span id="cb12-4">logLL <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;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.997</span>)</span>
<span id="cb12-5"></span>
<span id="cb12-6">logpoint <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;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</span>)</span>
<span id="cb12-7"></span>
<span id="cb12-8">logpoint <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.96</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> se)</span>
<span id="cb12-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [1] 0.954</span></span>
<span id="cb12-10">logpoint <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.96</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> se)</span>
<span id="cb12-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [1] -0.0011</span></span></code></pre></div></div>
</div>
<hr>
<section id="table-2-p-values-s-values-and-likelihoods-for-targeted-hypotheses-about-hazard-ratios-for-brown-et-al." class="level3">
<h3 class="anchored" data-anchor-id="table-2-p-values-s-values-and-likelihoods-for-targeted-hypotheses-about-hazard-ratios-for-brown-et-al.">Table 2: <img src="https://latex.codecogs.com/png.latex?P">-values, <img src="https://latex.codecogs.com/png.latex?S">-values, and Likelihoods for Targeted Hypotheses About Hazard Ratios for <a href="https://doi.org/10.1001/jama.2017.3415">Brown et al.</a></h3>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">testhypothesis <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Halving of hazard"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No effect (null)"</span>,</span>
<span id="cb13-2">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Point estimate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Doubling of hazard"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tripling of hazard"</span>,</span>
<span id="cb13-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Quintupling of hazard"</span>)</span>
<span id="cb13-4"></span>
<span id="cb13-5">hazardratios <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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</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.61</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb13-6">pvals <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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.6e-06</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</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.37</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.2e-06</span>)</span>
<span id="cb13-7">svals <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;">round</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;">log2</span>(pvals), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb13-8">mlr2 <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;">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;">10</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;">5</span>), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.77</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.49</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">26.2</span>, (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</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;">10</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;">4</span>))</span>
<span id="cb13-9">lr <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;">round</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;">exp</span>((((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</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.61</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="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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>((((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</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.61</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="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>
<span id="cb13-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>((((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</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.61</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="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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>((((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</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="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>
<span id="cb13-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>((((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</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="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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>((((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">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.61</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="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>
<span id="cb13-12">    <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb13-13"></span>
<span id="cb13-14">LR <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;">formatC</span>(lr, <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;">"e"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb13-15"></span>
<span id="cb13-16">table2 <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>(testhypothesis, hazardratios, pvals, svals,</span>
<span id="cb13-17">    mlr2, LR)</span>
<span id="cb13-18"></span>
<span id="cb13-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(table2) <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Test Hypothesis"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"HR"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P-values"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S-values"</span>,</span>
<span id="cb13-20">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MLR"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"LR"</span>)</span>
<span id="cb13-21"></span>
<span id="cb13-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kbl</span>(table2, <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;">"html"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">padding =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">longtable =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb13-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;">"#777"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb13-24">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row_spec</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row =</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;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#777"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bold =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb13-25">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">column_spec</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">column =</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;">6</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;">"#777"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bold =</span> F) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb13-26">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable_classic</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">full_width =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">html_font =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cambria"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lightable_options =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"basic"</span>,</span>
<span id="cb13-27">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fixed_thead =</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;">enabled =</span> F))</span></code></pre></div></div>
<div class="cell-output-display">
<table class="lightable-classic caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Test Hypothesis</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">HR</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">P-values</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">S-values</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">MLR</th>
<th data-quarto-table-cell-role="th" style="text-align: left; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">LR</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Halving of hazard</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.50</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">19.25</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.00e+05</td>
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">1.02e+05</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">No effect (null)</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.05</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">4.32</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">6.77e+00</td>
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">6.77e+00</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Point estimate</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.61</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.00e+00</td>
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">1.00e+00</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Doubling of hazard</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.37</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.43</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.49e+00</td>
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">1.49e+00</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Tripling of hazard</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">3.00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">6.64</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.62e+01</td>
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">2.62e+01</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Quintupling of hazard</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">5.00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">18.25</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">5.00e+04</td>
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">5.03e+04</td>
</tr>
</tbody>
</table>
</div>
</div>
<hr>
</section>
<section id="plot-the-point-estimate-and-95-compatibility-interval" class="level3">
<h3 class="anchored" data-anchor-id="plot-the-point-estimate-and-95-compatibility-interval">Plot the point estimate and 95% compatibility interval</h3>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">label <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Brown et al. (2017)</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"> JAMA"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Brown et al. (2017)</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"> J Clin Psychiatry"</span>)</span>
<span id="cb14-2"></span>
<span id="cb14-3">point <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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.7</span>)</span>
<span id="cb14-4">lower <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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.997</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>)</span>
<span id="cb14-5">upper <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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.6</span>)</span>
<span id="cb14-6"></span>
<span id="cb14-7">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>(label, point, lower, upper)</span></code></pre></div></div>
</div>
<hr>
<p>Here we plot the 95% compatibility interval estimate reported from the high-dimensional propensity score analysis.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mapping =</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> label, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> point, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> lower,</span>
<span id="cb15-2">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> upper, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> label)) <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;">geom_pointrange</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;">"#007C7C"</span>,</span>
<span id="cb15-3">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</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;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</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;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</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;">lty =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,</span>
<span id="cb15-4">    <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;">"#d46c5b"</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 class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_flip</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;">scale_y_log10</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</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;">pretty_breaks</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>),</span>
<span id="cb15-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</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.8</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 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;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Association Between Serotonergic Antidepressant Exposure</span></span>
<span id="cb15-6"><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;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">During Pregnancy and Child Autism Spectrum Disorder"</span>,</span>
<span id="cb15-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reported 95% Compatibility Intervals From Primary Results"</span>,</span>
<span id="cb15-8">    <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;">"Study"</span>, <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;">"Hazard Ratio (JAMA) +</span></span>
<span id="cb15-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">            Adjusted Pooled Odds Ratio (J Clin Psychiatry)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geom =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</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.5</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;">size =</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;">"Null parameter value of 1"</span>,</span>
<span id="cb15-11">        <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;">"#d46c5b"</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.75</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;">annotate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geom =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>,</span>
<span id="cb15-12">    <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;">2.2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.8</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;">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;">"Point Estimate = 1.61,</span></span>
<span id="cb15-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">           Lower Limit = 0.997, Upper Limit = 2.59"</span>,</span>
<span id="cb15-14">    <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;">"#000000"</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.75</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;">annotate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geom =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>,</span>
<span id="cb15-15">    <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.2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.8</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;">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;">"Point Estimate = 1.7,</span></span>
<span id="cb15-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">           Lower Limit = 1.1, Upper Limit = 2.6"</span>,</span>
<span id="cb15-17">    <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;">"#000000"</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.75</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;">theme_light</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;">theme</span>(<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_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">angle =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span>,</span>
<span id="cb15-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</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;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">13</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;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">13</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb15-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;">title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">13</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-16-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>Once again, the authors reported that<span class="citation" data-cites="brownAssociationSerotonergicAntidepressant2017"><sup>15</sup></span></p>
<blockquote class="blockquote">
<p>In the 2837 pregnancies (7.9%) exposed to antidepressants, 2.0% (95% CI, 1.6%-2.6%) of children were diagnosed with autism spectrum disorder. Risk of autism spectrum disorder was significantly higher with serotonergic antidepressant exposure (4.51 exposed vs 2.03 unexposed per 1000 person-years; between-group difference, 2.48 95% CI, 2.33-2.62 per 1000 person-years) in crude (HR, 2.16 95% CI, 1.64-2.86) and multivariable-adjusted analyses (HR, 1.59 95% CI, 1.17-2.17) (Table 2). After inverse probability of treatment weighting based on the HDPS, the association was not significant (HR, 1.61 95% CI, 0.997-2.59) (Table 2).</p>
</blockquote>
<p>and concluded with</p>
<blockquote class="blockquote">
<p>In children born to mothers receiving public drug coverage in Ontario, Canada, in utero serotonergic antidepressant exposure compared with no exposure was not associated with autism spectrum disorder in the child. Although a causal relationship cannot be ruled out, the previously observed association may be explained by other factors.</p>
</blockquote>
<p>We will show using the graphical and tabular summaries below, why a more nuanced summary such as,</p>
<blockquote class="blockquote">
<p>“After HDPS adjustment for confounding, a 61% hazard elevation remained; however, under the same model, every hypothesis from no elevation up to a 160% hazard increase had <img src="https://latex.codecogs.com/png.latex?p"> &gt; 0.05; Thus, while quite imprecise, these results are consistent with previous observations of a positive association between serotonergic antidepressant prescriptions and subsequent ASD. Because the association may be partially or wholly due to uncontrolled biases, further evidence will be needed for evaluating what, if any, proportion of it can be attributed to causal effects of prenatal serotonergic antidepressant use on ASD incidence.”</p>
</blockquote>
<p>would have been far more appropriate, as we discuss in our paper.<span class="citation" data-cites="rafiSemanticCognitiveTools2020"><sup>1</sup></span></p>
<hr>
</section>
<section id="p-value-and-s-value-functions" class="level3">
<h3 class="anchored" data-anchor-id="p-value-and-s-value-functions"><img src="https://latex.codecogs.com/png.latex?P">-value and <img src="https://latex.codecogs.com/png.latex?S">-value Functions</h3>
<hr>
<p>In order to use this information to construct a <img src="https://latex.codecogs.com/png.latex?P">-value function, we can use the <a href="https://data.lesslikely.com/concurve/"><code>concurve</code></a> functions.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"concurve"</span>)</span></code></pre></div></div>
</div>
<hr>
<p>We enter the reported point estimates and compatibility limits and produce all possible intervals + <img src="https://latex.codecogs.com/png.latex?P">-values + <img src="https://latex.codecogs.com/png.latex?S">-values. This is calculated assuming normal approximations with the <a href="https://data.lesslikely.com/concurve/reference/curve_rev.html"><code>curve_rev()</code></a> function.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">curve1 <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;">curve_rev</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">point =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">LL =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.997</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">UL =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">measure =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ratio"</span>)</span></code></pre></div></div>
</div>
<hr>
<p>It is stored in the object <code>curve1</code>.</p>
<p>We can generate a table of the relevant statistics from this reanalysis, similar to the table from above, but this time using the <a href="https://data.lesslikely.com/concurve/index.html"><code>concurve</code></a> function, <a href="https://data.lesslikely.com/concurve/reference/curve_table.html"><code>curve_table()</code></a>, but this time it will give us interval estimates of various percentiles (<img src="https://latex.codecogs.com/png.latex?25">%, <img src="https://latex.codecogs.com/png.latex?50">%, <img src="https://latex.codecogs.com/png.latex?75">%, <img src="https://latex.codecogs.com/png.latex?95">%, etc.). These are in turn used to construct the entire confidence (compatibility) distribution or <img src="https://latex.codecogs.com/png.latex?P">-value function.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kbl</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">curve_table</span>(curve1[[<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;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"html"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">padding =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">45</span>,</span>
<span id="cb18-2">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">longtable =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</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;">"#777"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> F, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">curve_table</span>(curve1[[<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-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row_spec</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row =</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;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#777"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bold =</span> T) <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;">column_spec</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">column =</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;">7</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;">"#777"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bold =</span> F) <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;">kable_classic</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">full_width =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">html_font =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cambria"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lightable_options =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"basic"</span>,</span>
<span id="cb18-6">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fixed_thead =</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;">enabled =</span> F)) <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;">footnote</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">general_title =</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;">"Table of Statistics for Various Interval Estimate Percentiles"</span>),</span>
<span id="cb18-8">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">general =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<table class="lightable-classic caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Lower Limit</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Upper Limit</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Interval Width</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Interval Level (%)</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">CDF</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">P-value</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">S-value (bits)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.490</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.74</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.250</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">25.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.625</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.750</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.415</td>
</tr>
<tr class="even">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.366</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.90</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.531</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">50.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.750</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.500</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.000</td>
</tr>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.217</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.13</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.914</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">75.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.875</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.250</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.000</td>
</tr>
<tr class="even">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.178</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.20</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.021</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">80.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.900</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.200</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.322</td>
</tr>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.134</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.29</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.152</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">85.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.925</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.150</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.737</td>
</tr>
<tr class="even">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.079</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.40</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.325</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">90.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.950</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.100</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">3.322</td>
</tr>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.999</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.60</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.596</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">95.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.975</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.050</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">4.322</td>
</tr>
<tr class="even">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.933</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.78</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.846</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">97.5</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.988</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.025</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">5.322</td>
</tr>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.860</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">3.02</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.155</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">99.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.995</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.010</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">6.644</td>
</tr>
</tbody><tfoot>
<tr class="odd">
<td style="text-align: right; padding: 0;"><span style="font-style: italic;">Table of Statistics for Various Interval Estimate Percentiles</span></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
<tr class="even">
<td style="text-align: right; padding: 0;"><sup></sup></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
</tfoot>

</table>
</div>
</div>
<hr>
</section>
<section id="figure-3-p-value-compatibility-function" class="level3">
<h3 class="anchored" data-anchor-id="figure-3-p-value-compatibility-function">Figure 3: <img src="https://latex.codecogs.com/png.latex?P">-value (Compatibility) Function</h3>
<hr>
<p>Plot the <img src="https://latex.codecogs.com/png.latex?P">-value (Compatibility) function of the <a href="https://doi.org/10.1001/jama.2017.3415">Brown et al.</a> data</p>
<p>Now we plot the <img src="https://latex.codecogs.com/png.latex?P">-value function from the data stored in <code>curve1</code> using the <a href="https://data.lesslikely.com/concurve/reference/ggcurve.html"><code>ggcurve()</code></a> function from <a href="https://data.lesslikely.com/concurve/"><code>concurve</code></a>.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggcurve</span>(curve1[[<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;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">measure =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ratio"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nullvalue =</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>
<span id="cb19-2">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</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.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">italic</span>(P),</span>
<span id="cb19-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-value (Compatibility) Function"</span>)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">italic</span>(P),</span>
<span id="cb19-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-values for a range of hazard ratios (HR)"</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;">"Hazard Ratio (HR)"</span>,</span>
<span id="cb19-5">    <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;">expression</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">italic</span>(P), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-value"</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;">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.61</span>,</span>
<span id="cb19-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</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.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;">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;">2.59</span>,</span>
<span id="cb19-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</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.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;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>),</span>
<span id="cb19-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>),</span>
<span id="cb19-9">    <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_text</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;">12</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-20-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>It is practically the same as the published version from <a href="https://doi.org/10.1186/s12874-020-01105-9">Rafi &amp; Greenland, 2020</a><span class="citation" data-cites="rafiSemanticCognitiveTools2020"><sup>1</sup></span>.</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/v1602038429/Site/confidencecurve.svg" width="750"></p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">curve1 <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;">curve_rev</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">point =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">LL =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.997</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">UL =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">measure =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ratio"</span>)</span>
<span id="cb20-2"></span>
<span id="cb20-3">curve2 <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;">curve_rev</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">point =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.7</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">LL =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">UL =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.6</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">measure =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ratio"</span>)</span></code></pre></div></div>
</div>
<hr>
</section>
<section id="cumulative-confidence-compatibility-distribution" class="level3">
<h3 class="anchored" data-anchor-id="cumulative-confidence-compatibility-distribution">Cumulative Confidence (Compatibility Distribution)</h3>
<hr>
<p>Although we do not cover this figure in our paper, it is easy to construct using <a href="https://data.lesslikely.com/concurve/index.html"><code>concurve's</code></a> <a href="https://data.lesslikely.com/concurve/reference/ggcurve.html"><code>ggcurve()</code></a> function by specifying <code>type</code> as “<code>cdf</code>” to see the median estimate within the confidence distribution. The horizontal line that meets at the curve, is approximately the same as the maximum at the <img src="https://latex.codecogs.com/png.latex?P">-value function/confidence (compatibility) curve.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggcurve</span>(curve1[[<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;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cdf"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">measure =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ratio"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nullvalue =</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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-2">    <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;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P-values for a range of hazard ratios (HR)"</span>,</span>
<span id="cb21-3">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Association Between Serotonergic Antidepressant Exposure</span></span>
<span id="cb21-4"><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;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">During Pregnancy and Child Autism Spectrum Disorder"</span>,</span>
<span id="cb21-5">        <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;">"Hazard Ratio (HR)"</span>, <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;">"Cumulative Compatibility"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-6">    <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;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>),</span>
<span id="cb21-7">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>), <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_text</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;">12</span>),</span>
<span id="cb21-8">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-22-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>We will also calculate the likelihoods so that we can generate the corresponding likelihood functions.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">lik2 <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;">curve_rev</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">point =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.7</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">LL =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">UL =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.6</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;">"l"</span>,</span>
<span id="cb22-2">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">measure =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ratio"</span>)</span>
<span id="cb22-3"></span>
<span id="cb22-4">lik1 <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;">curve_rev</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">point =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.61</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">LL =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.997</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">UL =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</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;">"l"</span>,</span>
<span id="cb22-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">measure =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ratio"</span>)</span></code></pre></div></div>
</div>
<hr>
<p>We can also see how consistent these results are with previous studies conducted by the same research group, given the overlap of the functions, which can be compared using the <a href="https://data.lesslikely.com/concurve/reference/plot_compare.html"><code>plot_compare()</code></a> function. Let’s compare the relative likelihood functions from both studies from this research group to see how consistent the results are.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_compare</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data1 =</span> lik1[[<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;">data2 =</span> lik2[[<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;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"l1"</span>,</span>
<span id="cb23-2">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">measure =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ratio"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nullvalue =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Brown et al. 2017. J Clin Psychiatry. vs.</span></span>
<span id="cb23-3"><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;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Brown et al. 2017. JAMA."</span>,</span>
<span id="cb23-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"J Clin Psychiatry: OR = 1.7, 1/6.83 LI: LL = 1.1, UL = 2.6</span></span>
<span id="cb23-5"><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;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">JAMA: HR = 1.61, 1/6.83 LI: LL = 0.997, UL = 2.59"</span>,</span>
<span id="cb23-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xaxis =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hazard Ratio / Odds Ratio"</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;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>),</span>
<span id="cb23-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>),</span>
<span id="cb23-8">    <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_text</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;">12</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-24-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>and the <img src="https://latex.codecogs.com/png.latex?P">-value functions.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_compare</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data1 =</span> curve1[[<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;">data2 =</span> curve2[[<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;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>,</span>
<span id="cb24-2">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">measure =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ratio"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nullvalue =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Brown et al. 2017. J Clin Psychiatry. vs.</span></span>
<span id="cb24-3"><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;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Brown et al. 2017. JAMA."</span>,</span>
<span id="cb24-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"J Clin Psychiatry: OR = 1.7, 1/6.83 LI: LL = 1.1, UL = 2.6</span></span>
<span id="cb24-5"><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;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">JAMA: HR = 1.61, 1/6.83 LI: LL = 0.997, UL = 2.59"</span>,</span>
<span id="cb24-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xaxis =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hazard Ratio / Odds Ratio"</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;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>),</span>
<span id="cb24-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>),</span>
<span id="cb24-8">    <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_text</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;">12</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-25-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
</section>
<section id="figure-4-s-value-suprisal-function" class="level3">
<h3 class="anchored" data-anchor-id="figure-4-s-value-suprisal-function">Figure 4: <img src="https://latex.codecogs.com/png.latex?S">-value (Suprisal) Function</h3>
<hr>
<p>Plot the <img src="https://latex.codecogs.com/png.latex?S">-value (Surprisal) function of the <a href="https://doi.org/10.1001/jama.2017.3415">Brown et al.</a> data with <a href="https://data.lesslikely.com/concurve/reference/ggcurve.html"><code>ggcurve()</code></a></p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggcurve</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> curve1[[<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;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"s"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">measure =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ratio"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nullvalue =</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>
<span id="cb25-2">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S-value (Surprisal) Function"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S-Values (surprisals) for a range of hazard ratios (HR)"</span>,</span>
<span id="cb25-3">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xaxis =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hazard Ratio"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yaxis1 =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S-value (bits of information)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb25-4">    <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;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>),</span>
<span id="cb25-5">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>), <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_text</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;">12</span>),</span>
<span id="cb25-6">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-26-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="576"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>which is quite close to the figure from our paper.</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/v1602200052/Site/surprisalcurve.png" width="750"></p>
<hr>
</section>
<section id="likelihood-support-functions" class="level3">
<h3 class="anchored" data-anchor-id="likelihood-support-functions">Likelihood (Support) Functions</h3>
<hr>
<p>Here we provide the code to show how we constructed the likelihood functions from our paper, which are the supplementary figures found <a href="https://static-content.springer.com/esm/art%3A10.1186%2Fs12874-020-01105-9/MediaObjects/12874_2020_1105_MOESM3_ESM.pdf">here (S1)</a> and <a href="https://static-content.springer.com/esm/art%3A10.1186%2Fs12874-020-01105-9/MediaObjects/12874_2020_1105_MOESM4_ESM.pdf">here (S2)</a>.</p>
<hr>
<p>Calculate and Plot Likelihood (Support) Intervals.</p>
<p>Here we use the reported estimates to construct the <img src="https://latex.codecogs.com/png.latex?Z">-scores and standard errors, which are in turn used to compute the likelihoods.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">hrvalues <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;">seq</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">from =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.65</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">to =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.98</span>, <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.01</span>)</span>
<span id="cb26-2"></span>
<span id="cb26-3">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;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.59</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.997</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.92</span></span>
<span id="cb26-4"></span>
<span id="cb26-5">zscore <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;">sapply</span>(hrvalues, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(i) (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(i<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.61</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>se))</span></code></pre></div></div>
</div>
<hr>
</section>
<section id="figure-s1-relative-likelihood-function" class="level3">
<h3 class="anchored" data-anchor-id="figure-s1-relative-likelihood-function">Figure S1: Relative Likelihood Function</h3>
<hr>
<p>We then standardize all the likelihoods by their maximum at the likelihood function,<span class="citation" data-cites="jewellStatisticsEpidemiology2003"><sup>17</sup></span> to produce relative likelihoods, likelihood intervals, and their corresponding relative likelihood function.<span class="citation" data-cites="royallStatisticalEvidenceLikelihood1997"><sup>18</sup></span></p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1">support <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;">exp</span>((<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>zscore<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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb27-2"></span>
<span id="cb27-3">likfunction <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>(hrvalues, zscore, support)</span>
<span id="cb27-4"></span>
<span id="cb27-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> likfunction, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mapping =</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> hrvalues, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> support)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</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;">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;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</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;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d46c5b"</span>,</span>
<span id="cb27-7">    <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.75</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;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</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;">6.83</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb27-8">    <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;">"#333333"</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.05</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;">geom_ribbon</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> hrvalues,</span>
<span id="cb27-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(support), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> support), <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;">"#d46c5b"</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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-10">    <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;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative Likelihood Function"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative likelihoods for a range of hazard ratios"</span>,</span>
<span id="cb27-11">        <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;">"Hazard Ratio (HR)"</span>, <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;">"Relative Likelihood </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">1/MLR"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-12">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geom =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</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.65</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.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/6.83 LI = 0.997, 2.59"</span>,</span>
<span id="cb27-13">        <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="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#000000"</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;">theme_bw</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;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>),</span>
<span id="cb27-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>),</span>
<span id="cb27-15">    <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_text</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;">12</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-16">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_log10</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</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;">pretty_breaks</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</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 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;">mult =</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.01</span>,</span>
<span id="cb27-17">    <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0125</span>)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</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.1</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-28-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>The <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B6.83%7D"> likelihood interval corresponds to the 95% compatibility interval, as shown by the figure from our paper.</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/v1602200052/Site/relativelikelihood.png" width="750"></p>
<hr>
<p>Below we use the calculated <img src="https://latex.codecogs.com/png.latex?Z">-scores to construct the log-likelihood function which is the upward-concave parabola <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7BZ%5E%7B2%7D%7D%7B2%7D"> = <img src="https://latex.codecogs.com/png.latex?-ln(MLR)"></p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">support <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (zscore<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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb28-2"></span>
<span id="cb28-3">likfunction <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>(hrvalues, zscore, support)</span>
<span id="cb28-4"></span>
<span id="cb28-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> likfunction, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mapping =</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> hrvalues, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> support)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb28-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</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;">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;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</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;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d46c5b"</span>,</span>
<span id="cb28-7">    <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.75</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;">geom_ribbon</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> hrvalues, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> support,</span>
<span id="cb28-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(support)), <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;">"#d46c5b"</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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <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;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log-Likelihood Function"</span>,</span>
<span id="cb28-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Log-likelihoods for a range of hazard ratios"</span>,</span>
<span id="cb28-10">    <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;">"Hazard Ratio (HR)"</span>, <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;">"ln(MLR)"</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;">theme_bw</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;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">13</span>),</span>
<span id="cb28-11">    <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_text</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;">13</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;">scale_x_log10</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</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;">pretty_breaks</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</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="cb28-12">    <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;">mult =</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.01</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0125</span>)),</span>
<span id="cb28-13">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</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;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">15</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb28-14">    <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;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-29-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
</section>
<section id="figure-s2-deviance-function-2lnmlr" class="level3">
<h3 class="anchored" data-anchor-id="figure-s2-deviance-function-2lnmlr">Figure S2: Deviance Function <img src="https://latex.codecogs.com/png.latex?2ln(MLR)"></h3>
<hr>
<p>Known as the deviance function, it is twice the log-likelihood, which maps to the <img src="https://latex.codecogs.com/png.latex?S">-value function.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1">support <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (zscore<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>
<span id="cb29-2"></span>
<span id="cb29-3">likfunction <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>(hrvalues, zscore, support)</span>
<span id="cb29-4"></span>
<span id="cb29-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> likfunction, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mapping =</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> hrvalues, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> support)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</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;">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;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</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;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d46c5b"</span>,</span>
<span id="cb29-7">    <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.75</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;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.84</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#333333"</span>,</span>
<span id="cb29-8">    <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.05</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;">geom_ribbon</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> hrvalues, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> support,</span>
<span id="cb29-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(support)), <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;">"#d46c5b"</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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geom =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>,</span>
<span id="cb29-10">    <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.65</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.4</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/6.83 LI = 0.997, 2.59"</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>
<span id="cb29-11">    <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;">"#000000"</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;">theme_bw</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;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>),</span>
<span id="cb29-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.title.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">12</span>),</span>
<span id="cb29-13">    <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_text</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;">12</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</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;">11</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-14">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_log10</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</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;">pretty_breaks</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</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 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;">mult =</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.01</span>,</span>
<span id="cb29-15">    <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0125</span>)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Deviance Function"</span>,</span>
<span id="cb29-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Deviance statistics for a range of hazard ratios"</span>,</span>
<span id="cb29-17">    <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;">"Hazard Ratio (HR)"</span>, <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;">" Deviance Statistic </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">2ln(MLR)"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/RG2020BMC_files/figure-html/unnamed-chunk-30-1.svg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>And the version from our paper can be found <a href="https://static-content.springer.com/esm/art%3A10.1186%2Fs12874-020-01105-9/MediaObjects/12874_2020_1105_MOESM4_ESM.pdf">here</a>.</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/v1602200052/Site/deviancefunction.png" width="750"></p>
<hr>
<p>It is important to note that although we have calculated these likelihood functions manually here, they can also be generated easily using the <a href="https://data.lesslikely.com/concurve/reference/curve_lik.html"><code>curve_lik()</code></a> function which takes inputs from the <a href="https://cran.r-project.org/package=ProfileLikelihood"><code>ProfileLikelihood</code></a> <code>R</code> package. To see a further discussion, please see the <a href="https://data.lesslikely.com/concurve/articles/likelihood.html">following article</a>, which gives several examples for a wide variety of models.</p>
<p>Further, we urge some caution. Although we endorse the construction and presentation of likelihood functions along with <img src="https://latex.codecogs.com/png.latex?P">-value and <img src="https://latex.codecogs.com/png.latex?S">-value functions, along with the tabulations, the use of pure likelihood methods has been highly controversial among some statisticians, with some going as far as to say that <em>likelihood is blind</em> although not all statisticians believe this, and have responded to such criticisms in kind, see discussants.<span class="citation" data-cites="daviesApproximatingDataDiscussion2008"><sup>19</sup></span> Thus, we support providing both <img src="https://latex.codecogs.com/png.latex?P">-value/<img src="https://latex.codecogs.com/png.latex?S">-value and likelihood-based functions for a complete picture.</p>
<p>Indeed, we can see how they all easily map to one another when plotted side by side, with the following script.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cowplot"</span>)</span>
<span id="cb30-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_grid</span>(confcurve, surprisalcurve, relsupportfunction, deviancefunction,</span>
<span id="cb30-3">    <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;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
</div>
<hr>
<p>A clearer plot comparing the four functions is seen below (click on the image to view in full).</p>
<hr>
<p><img src="https://res.cloudinary.com/less-likely/image/upload/v1581988661/Site/Comparisons.png" width="1000" style="cursor: zoom-in"></p>
<hr>
<p>Additional adjustments that were made to the figures from <a href="https://doi.org/10.1186/s12874-020-01105-9">Rafi &amp; Greenland, 2020</a><span class="citation" data-cites="rafiSemanticCognitiveTools2020"><sup>1</sup></span> were done using Adobe Illustrator and Photoshop.</p>
<p>All errors are ours, and we welcome critical feedback and reporting of errors. To report possible errors in our analyses, please post it as a comment below or as a bug <a href="https://github.com/zadrafi/concurve/issues">here</a>. We will compile them onto a public errata, if any errors or flaws are reported to us.</p>
<hr>
</section>
</section>
<section id="statistical-package-citations" class="level2">
<h2 class="anchored" data-anchor-id="statistical-package-citations">Statistical Package Citations</h2>
<hr>
<p>Please remember to cite the <code>R</code> packages if you use any of the <code>R</code> scripts from above. The citation for our<span class="citation" data-cites="rafiSemanticCognitiveTools2020"><sup>1</sup></span> can be found below in the References section or it can be <a href="https://bmcmedresmethodol.biomedcentral.com/articles/10.1186/s12874-020-01105-9.ris">downloaded here</a> for a reference manager.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"concurve"</span>)</span>
<span id="cb31-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TeachingDemos"</span>)</span>
<span id="cb31-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ProfileLikelihood"</span>)</span>
<span id="cb31-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rstan"</span>)</span>
<span id="cb31-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rstanarm"</span>)</span>
<span id="cb31-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bayesplot"</span>)</span>
<span id="cb31-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"knitr"</span>)</span>
<span id="cb31-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kableExtra"</span>)</span>
<span id="cb31-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggplot2"</span>)</span>
<span id="cb31-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cowplot"</span>)</span>
<span id="cb31-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">citation</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Statamarkdown"</span>)</span></code></pre></div></div>
</div>
<hr>
</section>
<section id="environment" class="level2">
<h2 class="anchored" data-anchor-id="environment">Environment</h2>
<hr>
<p>The analyses were run on:</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">si <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;">sessionInfo</span>()</span>
<span id="cb32-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(si, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">RNG =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">locale =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb32-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; R version 4.6.1 (2026-06-24)</span></span>
<span id="cb32-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Platform: aarch64-apple-darwin25.4.0</span></span>
<span id="cb32-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Running under: macOS Golden Gate 27.0.1</span></span>
<span id="cb32-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb32-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Matrix products: default</span></span>
<span id="cb32-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; BLAS:   /opt/homebrew/Cellar/openblas/0.3.34/lib/libopenblasp-r0.3.34.dylib </span></span>
<span id="cb32-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; LAPACK: /opt/homebrew/Cellar/r/4.6.1/lib/R/lib/libRlapack.dylib;  LAPACK version 3.12.1</span></span>
<span id="cb32-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb32-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Random number generation:</span></span>
<span id="cb32-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  RNG:     L'Ecuyer-CMRG </span></span>
<span id="cb32-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Normal:  Inversion </span></span>
<span id="cb32-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Sample:  Rejection </span></span>
<span id="cb32-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  </span></span>
<span id="cb32-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; locale:</span></span>
<span id="cb32-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [1] C.UTF-8/C.UTF-8/C.UTF-8/C/C.UTF-8/C.UTF-8</span></span>
<span id="cb32-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb32-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; time zone: America/New_York</span></span>
<span id="cb32-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; tzcode source: internal</span></span>
<span id="cb32-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb32-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; attached base packages:</span></span>
<span id="cb32-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [1] splines   grid      stats4    parallel  stats     graphics  grDevices</span></span>
<span id="cb32-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [8] utils     datasets  methods   base     </span></span>
<span id="cb32-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb32-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; other attached packages:</span></span>
<span id="cb32-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   [1] plotly_4.12.1         TSstudio_0.1.7        tfautograph_0.3.2    </span></span>
<span id="cb32-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   [4] tfdatasets_2.18.0     keras_2.16.1          tensorflow_2.20.0    </span></span>
<span id="cb32-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   [7] timetk_2.9.1          modeltime_1.3.5       workflowsets_1.1.1   </span></span>
<span id="cb32-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [10] workflows_1.3.0       tune_2.1.0            tailor_0.1.0         </span></span>
<span id="cb32-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [13] rsample_1.3.2         recipes_1.4.0         parsnip_1.6.1        </span></span>
<span id="cb32-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [16] modeldata_1.6.0       infer_1.1.0           dials_1.4.4          </span></span>
<span id="cb32-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [19] scales_1.4.0          tidymodels_1.5.0      xgboost_3.2.1.1      </span></span>
<span id="cb32-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [22] prophet_1.1.7         rlang_1.3.0           astsa_2.5            </span></span>
<span id="cb32-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [25] bayesforecast_1.0.5   smooth_4.5.2          greybox_2.0.9        </span></span>
<span id="cb32-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [28] glmnet_5.1            forecast_9.0.2        fable_0.5.0          </span></span>
<span id="cb32-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [31] fabletools_0.8.0      tsibbledata_0.4.1     tsibble_1.2.0        </span></span>
<span id="cb32-38"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [34] rstanarm_2.32.2       texPreview_2.1.0      tinytex_0.61         </span></span>
<span id="cb32-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [37] rmarkdown_2.32        brms_2.23.0           bootImpute_1.3.0     </span></span>
<span id="cb32-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [40] knitr_1.52            boot_1.3-32           JuliaCall_0.17.6     </span></span>
<span id="cb32-41"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [43] reshape2_1.4.5        ProfileLikelihood_1.3 ImputeRobust_1.3-1   </span></span>
<span id="cb32-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [46] gamlss_5.5-5          gamlss.dist_6.1-11    gamlss.data_6.0-7    </span></span>
<span id="cb32-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [49] mvtnorm_1.4-2         performance_0.18.2    summarytools_1.1.5   </span></span>
<span id="cb32-44"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [52] tidybayes_3.0.7       htmltools_0.5.9       Statamarkdown_1.1.0  </span></span>
<span id="cb32-45"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [55] car_3.1-5             carData_3.0-6         qqplotr_0.0.7        </span></span>
<span id="cb32-46"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [58] ggcorrplot_0.3.0      mitml_0.4-5           pbmcapply_1.5.1      </span></span>
<span id="cb32-47"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [61] Amelia_1.8.3          Rcpp_1.1.2            blogdown_1.24        </span></span>
<span id="cb32-48"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [64] doParallel_1.0.17     iterators_1.0.14      foreach_1.5.2        </span></span>
<span id="cb32-49"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [67] lattice_0.23-1        bayesplot_1.16.0      wesanderson_0.3.7    </span></span>
<span id="cb32-50"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [70] VIM_7.3.1             colorspace_2.1-4      here_1.0.2           </span></span>
<span id="cb32-51"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [73] progress_1.2.3        loo_2.10.1            mi_1.3.1             </span></span>
<span id="cb32-52"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [76] Matrix_1.7-6          broom_1.0.13          yardstick_1.4.0      </span></span>
<span id="cb32-53"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [79] svglite_2.2.2         Cairo_1.7-0           cowplot_1.2.0        </span></span>
<span id="cb32-54"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [82] mgcv_1.9-4            nlme_3.1-171          xfun_0.61            </span></span>
<span id="cb32-55"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [85] broom.mixed_0.2.9.7   reticulate_1.47.0     kableExtra_1.4.1     </span></span>
<span id="cb32-56"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [88] posterior_1.7.0       checkmate_2.3.4       parallelly_1.48.0    </span></span>
<span id="cb32-57"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [91] miceFast_0.9.1        randomForest_4.7-1.2  missForest_1.6.1     </span></span>
<span id="cb32-58"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [94] miceadds_3.20-10      quantreg_6.1          SparseM_1.84-2       </span></span>
<span id="cb32-59"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [97] MCMCpack_1.7-1        MASS_7.3-66           coda_0.19-4.1        </span></span>
<span id="cb32-60"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [100] latex2exp_0.9.8       rstan_2.32.7          StanHeaders_2.39.1   </span></span>
<span id="cb32-61"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [103] lubridate_1.9.5       forcats_1.0.1         stringr_1.6.0        </span></span>
<span id="cb32-62"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [106] dplyr_1.2.1           purrr_1.2.2           readr_2.2.0          </span></span>
<span id="cb32-63"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [109] tibble_3.3.1          ggplot2_4.0.3         tidyverse_2.0.0      </span></span>
<span id="cb32-64"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [112] ggtext_0.2.0          concurve_3.0.5        showtext_0.9-8       </span></span>
<span id="cb32-65"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [115] showtextdb_3.0        sysfonts_0.8.9        future.apply_1.20.2  </span></span>
<span id="cb32-66"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [118] future_1.76.0         tidyr_1.3.2           magrittr_2.0.5       </span></span>
<span id="cb32-67"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [121] mice_3.19.0           rms_8.1-1             Hmisc_5.3-0          </span></span>
<span id="cb32-68"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb32-69"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; loaded via a namespace (and not attached):</span></span>
<span id="cb32-70"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   [1] igraph_2.3.4          Formula_1.2-6         rematch2_2.1.2       </span></span>
<span id="cb32-71"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   [4] tidyselect_1.2.1      bridgesampling_1.2-1  rngtools_1.5.2       </span></span>
<span id="cb32-72"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   [7] dichromat_2.0-1       png_0.1-9             cli_3.6.6            </span></span>
<span id="cb32-73"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [10] arrayhelpers_1.1-2    textshaping_1.0.5     curl_8.0.0           </span></span>
<span id="cb32-74"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [13] mime_0.13             evaluate_1.0.5        V8_8.2.0             </span></span>
<span id="cb32-75"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [16] stringi_1.8.9         backports_1.5.1       desc_1.4.3           </span></span>
<span id="cb32-76"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [19] qqconf_1.3.2          httpuv_1.6.17         rappdirs_0.3.4       </span></span>
<span id="cb32-77"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [22] details_0.4.0         prodlim_2026.03.11    doRNG_1.8.6.3        </span></span>
<span id="cb32-78"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [25] DT_0.34.0             DBI_1.3.0             withr_3.0.3          </span></span>
<span id="cb32-79"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [28] reformulas_0.4.4      class_7.3-24          systemfonts_1.3.2    </span></span>
<span id="cb32-80"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [31] tfruns_1.5.4          rprojroot_2.1.1       lmtest_0.9-40        </span></span>
<span id="cb32-81"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [34] formatR_1.14          colourpicker_1.3.0    htmlwidgets_1.6.4    </span></span>
<span id="cb32-82"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [37] fs_2.1.0              labeling_0.4.3        ranger_0.18.0        </span></span>
<span id="cb32-83"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [40] DEoptimR_1.2-2        zoo_1.9-1             itertools_0.1-3      </span></span>
<span id="cb32-84"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [43] svUnit_1.0.8          timechange_0.4.0      caTools_1.18.4       </span></span>
<span id="cb32-85"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [46] extremevalues_2.4.1   data.table_1.18.6.1   timeDate_4052.112    </span></span>
<span id="cb32-86"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [49] pan_2.0               clipr_0.8.1           yaml_2.3.12          </span></span>
<span id="cb32-87"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [52] survival_3.8-12       crayon_1.5.3          tensorA_0.36.2.1     </span></span>
<span id="cb32-88"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [55] RColorBrewer_1.1-3    later_1.4.8           codetools_0.2-20     </span></span>
<span id="cb32-89"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [58] base64enc_0.1-6       shape_1.4.6.1         estimability_2.0.0   </span></span>
<span id="cb32-90"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [61] foreign_0.8-91        DiceDesign_1.10       pkgconfig_2.0.3      </span></span>
<span id="cb32-91"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [64] xml2_1.6.0            viridisLite_0.4.3     xtable_1.8-8         </span></span>
<span id="cb32-92"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [67] plyr_1.8.9            httr_1.4.9            rbibutils_2.4.1      </span></span>
<span id="cb32-93"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [70] tools_4.6.1           globals_0.19.1        hardhat_1.4.3        </span></span>
<span id="cb32-94"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [73] pkgbuild_1.4.8        htmlTable_2.5.0       shinyjs_2.1.1        </span></span>
<span id="cb32-95"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [76] crosstalk_1.2.2       twosamples_2.0.1      MatrixModels_0.5-4   </span></span>
<span id="cb32-96"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [79] lme4_2.0-6            digest_0.6.39         furrr_0.4.0          </span></span>
<span id="cb32-97"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [82] farver_2.1.2          tzdb_0.5.0            rapportools_1.2      </span></span>
<span id="cb32-98"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [85] rpart_4.1.27          glue_1.8.1            mixtime_0.3.0        </span></span>
<span id="cb32-99"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [88] fracdiff_1.5-4        generics_0.1.4        ggtime_1.0.0         </span></span>
<span id="cb32-100"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [91] opdisDownsampling_1.7 statmod_1.5.2         arm_1.15-3           </span></span>
<span id="cb32-101"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [94] minqa_1.2.8           mcmc_0.9-8            tcltk_4.6.1          </span></span>
<span id="cb32-102"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [97] texreg_1.40           gower_1.0.2           mitools_2.7          </span></span>
<span id="cb32-103"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [100] gtools_3.9.5          gridExtra_2.3.1       shiny_1.14.0         </span></span>
<span id="cb32-104"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [103] lava_1.9.3            pander_0.6.6          threejs_0.3.4        </span></span>
<span id="cb32-105"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [106] rstudioapi_0.19.0     cluster_2.1.8.3       QuickJSR_1.11.0      </span></span>
<span id="cb32-106"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [109] whisker_0.4.1         rstantools_2.7.1      hms_1.1.4            </span></span>
<span id="cb32-107"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [112] anytime_0.3.13        jomo_2.7-6            xts_0.14.3           </span></span>
<span id="cb32-108"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [115] shinythemes_1.2.0     ipred_0.9-16          laeken_0.5.3         </span></span>
<span id="cb32-109"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [118] e1071_1.7-17          urca_1.3-4            TH.data_1.1-5        </span></span>
<span id="cb32-110"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [121] matrixStats_1.5.0     emmeans_2.0.4         abind_1.4-8          </span></span>
<span id="cb32-111"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [124] bitops_1.1-0          Rdpack_2.6.6          promises_1.5.0       </span></span>
<span id="cb32-112"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [127] inline_0.3.21         sandwich_3.1-3        proxy_0.4-29         </span></span>
<span id="cb32-113"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [130] compiler_4.6.1        prettyunits_1.2.0     distributional_0.9.0 </span></span>
<span id="cb32-114"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [133] listenv_1.1.0         insight_1.5.4         gridtext_0.1.6       </span></span>
<span id="cb32-115"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [136] R6_2.6.1              fastmap_1.2.0         multcomp_1.4-32      </span></span>
<span id="cb32-116"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [139] vecvec_1.3.0          vcd_1.4-14            ggdist_3.3.3         </span></span>
<span id="cb32-117"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [142] nnet_7.3-21           gtable_0.3.6          shinystan_2.7.0      </span></span>
<span id="cb32-118"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [145] miniUI_0.1.2          RcppParallel_6.2.1    polspline_1.1.25     </span></span>
<span id="cb32-119"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [148] lifecycle_1.0.5       S7_0.2.2              Brobdingnag_1.3-1    </span></span>
<span id="cb32-120"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [151] nloptr_2.2.1          dygraphs_1.1.1.6      vctrs_0.7.3          </span></span>
<span id="cb32-121"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [154] zeallot_0.2.0         robustbase_0.99-7     sp_2.2-3             </span></span>
<span id="cb32-122"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [157] pracma_2.4.6          pillar_1.11.1         magick_2.9.1         </span></span>
<span id="cb32-123"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [160] otel_0.2.0            jsonlite_2.0.0        svgPanZoom_0.3.4     </span></span>
<span id="cb32-124"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [163] markdown_2.0</span></span></code></pre></div></div>
</div>
<hr>
</section>
<section id="stata" class="level2">
<h2 class="anchored" data-anchor-id="stata">Stata</h2>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb33-1">about</span>
<span id="cb33-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">version</span></span>
<span id="cb33-3">#&gt; StataNow/MP 19.5 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> Mac (Apple Silicon)</span>
<span id="cb33-4">#&gt; Revision 12 Aug 2026</span>
<span id="cb33-5">#&gt; Copyright 1985-2025 StataCorp LLC</span>
<span id="cb33-6">#&gt; </span>
<span id="cb33-7">#&gt; Total physical <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">memory</span>: 48.01 GB</span>
<span id="cb33-8">#&gt; </span>
<span id="cb33-9">#&gt; Stata license: Single-user 2-core , expiring  6 Feb 2027</span>
<span id="cb33-10">#&gt; Serial number: 501909358563</span>
<span id="cb33-11">#&gt;   Licensed to: Zad Rafi</span>
<span id="cb33-12">#&gt;                </span>
<span id="cb33-13">#&gt; </span>
<span id="cb33-14">#&gt; <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">version</span> 19.5</span></code></pre></div></div>
</div>
<hr>
<p><strong>See also:</strong> <a href="../statistics/sensitivity.html"><em>What Makes a Sensitivity Analysis?</em></a> — the hub piece tying this material to the broader cluster on assumptions, robustness, and what happens when models bend.</p>
<hr>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<hr>


<!-- -->


</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><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" data-entry-spacing="2" data-line-spacing="2">
<div id="ref-rafiSemanticCognitiveTools2020" class="csl-entry">
1. Rafi Z, Greenland S. (2020). <span>“Semantic and cognitive tools to aid statistical science: Replace confidence and significance by compatibility and surprise.”</span> <em>BMC Medical Research Methodology</em>. <strong>20</strong>:244. doi: <a href="https://doi.org/10.1186/s12874-020-01105-9">10.1186/s12874-020-01105-9</a>.
</div>
<div id="ref-greenlandTechnicalIssuesInterpretation2020" class="csl-entry">
2. Greenland S, Rafi Z. (2020). <span>“Technical <span>Issues</span> in the <span>Interpretation</span> of <span>S</span>-values and <span>Their Relation</span> to <span>Other Information Measures</span>.”</span> <em>arXiv:200812991 [statME]</em>. <a href="https://arxiv.org/abs/2008.12991">https://arxiv.org/abs/2008.12991</a>.
</div>
<div id="ref-greenlandValidPvaluesBehave2019" class="csl-entry">
3. Greenland S. (2019). <span>“Valid <span>P</span>-values behave exactly as they should: <span>Some</span> misleading criticisms of <span>P</span>-values and their resolution with <span>S</span>-values.”</span> <em>The American Statistician</em>. <strong>73</strong>:106–114. doi: <a href="https://doi.org/10.1080/00031305.2018.1529625">10.1080/00031305.2018.1529625</a>.
</div>
<div id="ref-bayarriValuesCompositeNull2000" class="csl-entry">
4. Bayarri MJ, Berger JO. (2000). <span>“P <span>Values</span> for <span>Composite Null Models</span>.”</span> <em>Journal of the American Statistical Association</em>. <strong>95</strong>:1127–1142. doi: <a href="https://doi.org/10/dpvq8c">10/dpvq8c</a>.
</div>
<div id="ref-robinsAsymptoticDistributionValues2000" class="csl-entry">
5. <span class="nocase">Robins JM, van der Vaart A, Ventura V</span>. (2000). <span>“Asymptotic <span>Distribution</span> of <span>P Values</span> in <span>Composite Null Models</span>.”</span> <em>Journal of the American Statistical Association</em>. <strong>95</strong>:1143–1156. doi: <a href="https://doi.org/10/gg7krv">10/gg7krv</a>.
</div>
<div id="ref-kuffnerWhyArePvalues2019" class="csl-entry">
6. Kuffner TA, Walker SG. (2019). <span>“Why are <span>P</span>-values controversial?”</span> <em>The American Statistician</em>. <strong>73</strong>:1–3. doi: <a href="https://doi.org/10.1080/00031305.2016.1277161">10.1080/00031305.2016.1277161</a>.
</div>
<div id="ref-cousinsJeffreysLindleyParadox2017" class="csl-entry">
7. Cousins RD. (2017). <span>“The <span>Jeffreys</span> paradox and discovery criteria in high energy physics.”</span> <em>Synthese</em>. <strong>194</strong>:395–432. doi: <a href="https://doi.org/10.1007/s11229-014-0525-z">10.1007/s11229-014-0525-z</a>.
</div>
<div id="ref-coxChapterIntervalEstimation1974" class="csl-entry">
8. Cox DR, Hinkley DV. (1974). <span>“Chapter 7, <span>Interval</span> estimation.”</span> In: Theoretical <span>Statistics</span>. <span>Chapman and Hall/CRC</span>. p. 207–249. doi: <a href="https://doi.org/10.1201/b14832">10.1201/b14832</a>.
</div>
<div id="ref-bowleyDiscussionDrNeyman1934" class="csl-entry">
9. Bowley AL. (1934). <span>“Discussion on <span>Dr</span>. <span>Neyman</span>’s <span>Paper</span>. <span>P</span>. 607 in: <span>Neyman J</span>. <span>On</span> the two different aspects of the representative method: <span>The</span> method of stratified sampling and the method of purposive selection (with discussion).”</span> <em>Journal of the Royal Statistical Society</em>. <strong>4</strong>:558–625. doi: <a href="https://doi.org/10.2307/2342192">10.2307/2342192</a>.
</div>
<div id="ref-coxPrinciplesStatisticalInference2006" class="csl-entry">
10. Cox DR. (2006). <span>“Principles of <span>Statistical Inference</span>.”</span> <span>Cambridge University Press</span>.
</div>
<div id="ref-amrheinInferentialStatisticsDescriptive2019" class="csl-entry">
11. Amrhein V, Trafimow D, Greenland S. (2019). <span>“Inferential statistics as descriptive statistics: <span>There</span> is no replication crisis if we don’t expect replication.”</span> <em>The American Statistician</em>. <strong>73</strong>:262–270. doi: <a href="https://doi.org/10.1080/00031305.2018.1543137">10.1080/00031305.2018.1543137</a>.
</div>
<div id="ref-greenlandStatisticalTestsValues2016" class="csl-entry">
12. Greenland S, Senn SJ, Rothman KJ, Carlin JB, Poole C, Goodman SN, et al. (2016). <span>“Statistical tests, <span>P</span> values, confidence intervals, and power: <span>A</span> guide to misinterpretations.”</span> <em>European Journal of Epidemiology</em>. <strong>31</strong>:337–350. doi: <a href="https://doi.org/10.1007/s10654-016-0149-3">10.1007/s10654-016-0149-3</a>.
</div>
<div id="ref-greenlandAreConfidenceIntervals2019" class="csl-entry">
13. Greenland S. (2019). <span>“Are confidence intervals better termed <span>‘uncertainty intervals’</span>? <span>No</span>: <span>Call</span> them compatibility intervals.”</span> <em>BMJ</em>. <strong>366</strong>. doi: <a href="https://doi.org/10.1136/bmj.l5381">10.1136/bmj.l5381</a>.
</div>
<div id="ref-greenlandAidScientificInference2020" class="csl-entry">
14. Greenland S, Rafi Z. (2020). <span>“To <span>Aid Scientific Inference</span>, <span>Emphasize Unconditional Descriptions</span> of <span>Statistics</span>.”</span> <em>arXiv:190908583 [statME]</em>. <a href="https://arxiv.org/abs/1909.08583">https://arxiv.org/abs/1909.08583</a>.
</div>
<div id="ref-brownAssociationSerotonergicAntidepressant2017" class="csl-entry">
15. Brown HK, Ray JG, Wilton AS, Lunsky Y, Gomes T, Vigod SN. (2017). <span>“Association between serotonergic antidepressant use during pregnancy and autism spectrum disorder in children.”</span> <em>Journal of the American Medical Association</em>. <strong>317</strong>:1544–1552. doi: <a href="https://doi.org/10.1001/jama.2017.3415">10.1001/jama.2017.3415</a>.
</div>
<div id="ref-brownAssociationAntenatalExposure2017" class="csl-entry">
16. Brown HK, Hussain-Shamsy N, Lunsky Y, Dennis C-LE, Vigod SN. (2017). <span>“The association between antenatal exposure to selective serotonin reuptake inhibitors and autism: <span>A</span> systematic review and meta-analysis.”</span> <em>The Journal of Clinical Psychiatry</em>. <strong>78</strong>:e48–e58. doi: <a href="https://doi.org/10.4088/JCP.15r10194">10.4088/JCP.15r10194</a>.
</div>
<div id="ref-jewellStatisticsEpidemiology2003" class="csl-entry">
17. Jewell NP. (2003). <span>“Statistics for <span>Epidemiology</span>.”</span> <span>CRC Press</span>.
</div>
<div id="ref-royallStatisticalEvidenceLikelihood1997" class="csl-entry">
18. Royall R. (1997). <span>“Statistical <span>Evidence</span>: <span>A Likelihood Paradigm</span>.”</span> <span>CRC Press</span>.
</div>
<div id="ref-daviesApproximatingDataDiscussion2008" class="csl-entry">
19. Davies PL. (2008). <span>“Approximating data [with discussion and a rejoinder].”</span> <em>Journal of the Korean Statistical Society</em>. <strong>37</strong>:191–211. doi: <a href="https://doi.org/10/bn8cgk">10/bn8cgk</a>.
</div>
</div></section></div> ]]></description>
  <guid>https://lesslikely.com/statistics/RG2020BMC.html</guid>
  <pubDate>Sat, 12 Dec 2020 05:00:00 GMT</pubDate>
  <media:content url="https://res.cloudinary.com/less-likely/image/upload/v1602038429/Site/confidencecurve.svg" medium="image" type="image/svg+xml"/>
</item>
<item>
  <title>What Makes a Sensitivity Analysis?</title>
  <dc:creator>Zad Rafi</dc:creator>
  <dc:creator>Sir Panda</dc:creator>
  <link>https://lesslikely.com/statistics/sensitivity.html</link>
  <description><![CDATA[ 





<hr>
<section id="cargo-cult-uncertainty" class="level2">
<h2 class="anchored" data-anchor-id="cargo-cult-uncertainty">Cargo-Cult Uncertainty</h2>
<hr>
<p>Sensitivity analyses are an important part of statistical science and many other disciplines when conducted in a principle and systematic manner. However, in the published sensitivity analyses literature, there are many inconsistencies, misconceptions, and highly misleading findings from these analyses. A giant obstacle that prevents these issues from recurring is that they (sensitivity analysis techniques) are quite difficult to learn and often advanced statistical methods that even many statisticians have difficulty with.</p>
<p>Yet, the appearance of difficulty does not dissuade certain researchers away from adopting them for their own work, (so that they may give their colleagues and their stakeholders that they report to, the impression of rigor and methodological expertise), and when this is done mindlessly, researchers will often skip over learning the details and theory, and like many statistical procedures, they will rely on default settings built in the statistical software.</p>
<p>While there are many suites/commands/functions/libraries available to conduct such analyses, much of these procedures masquerade as meticulous sensitivity analyses and to the users, are often a formality to appease stakeholders and give researchers a false sense of confidence about what they are doing. And yet, their users have little to no idea what they’re actually doing. Thus, like many statistical procedures new and old, they too will inevitably be abused as they become more popular and as they are required in research reports.</p>
<hr>
<p>As Stark &amp; Saltelli<span class="citation" data-cites="Stark2018-eo"><sup>1</sup></span>, along with many others such as Gigerenzer<span class="citation" data-cites="gigerenzerStatisticalRitualsReplication2018"><sup>2</sup></span> and Greenland<span class="citation" data-cites="Greenland2017-es"><sup>3</sup></span> have written in the past. Below is an excerpt where Stark describes that much of statistics is simply people masquerading as data analysts and being rewarded as experts despite not having a single clue what they’re doing.</p>
<hr>
<blockquote class="blockquote">
<p>In our experience, many applications of statistics are cargo-cult statistics: practitioners go through the motions of fitting models, computing p-values or confidence intervals, or simulating posterior distributions. They invoke statistical terms and procedures as incantations, with scant understanding of the assumptions or relevance of the calculations, or even the meaning of the terminology. This demotes statistics from a way of thinking about evidence and avoiding self-deception to a formal “blessing” of claims. The effectiveness of cargo-cult statistics is predictably uneven. But it is effective at getting weak work published - and is even required by some journals…</p>
</blockquote>
<hr>
<p>Here, Stark takes on the issue of widely accessible statistical software for academics, students, and analysts.</p>
<hr>
<blockquote class="blockquote">
<p>Statistical software does not help you know what to compute, nor how to interpret the result. It does not offer to explain the assumptions behind methods, nor does it flag delicate or dubious assumptions. It does not warn you about multiplicity or p-hacking. It does not check whether you picked the hypothesis or analysis after looking at the data, nor track the number of analyses you tried before arriving at the one you sought to publish - another form of multiplicity. The more “powerful” and “user-friendly” the software is, the more it invites cargo-cult statistics.<span class="citation" data-cites="Stark2018-eo"><sup>1</sup></span></p>
</blockquote>
<hr>
<p>Greenland<span class="citation" data-cites="Greenland2017-es"><sup>3</sup></span> focuses on how traditional statistical education is inadequate to deal with the messy and chaotic nature of the world and the missing data that is produced by it. Greenland writes that traditional statistical practice opens the room for several cognitive biases, making many reports and conclusions highly misleading. He provides some hope however, by pointing to the utility of sensitivity analyses for modeling bias and uncertainty.</p>
<hr>
<blockquote class="blockquote">
<p>I argue that current training in statistics and analytical methods is inadequate for addressing major sources of inference distortion, and that it should be expanded to cover the biased perceptual and thinking processes (cognitive biases) that plague research reports. As commonly misused, null-hypothesis significance testing (NHST) combines several cognitive problems to create highly distorted interpretations of study results. Interval estimation has proven highly vulnerable to the same problems. Sensitivity and bias analyses address model uncertainties by varying and relaxing assumptions, but (like Bayesian analyses) they are difficult to perform with proper accounting for prior information and are easily manipulated because they depend on specification of many models and parameters.</p>
</blockquote>
<hr>
<p>However, he then follows up to discuss how difficult sensitivity and bias analyses can be due to the plethora of decisions that the analyst must make when specifying parameters in the analysis. These judgements will differ from researcher to researcher, even in the same group, and such analyses have not been studied as widely as conventional statistical practice.</p>
<hr>
<blockquote class="blockquote">
<p>Even with realistic choices, the sensitivity of sensitivity and bias analyses must be evaluated (51). The plausibility of an estimated bias function is determined by intuitions, prejudices, and understanding of the applied context; those can vary dramatically across researchers, in turn leading to very different specifications and inferences even if they are anchored to the same conventional analysis. Adding to this problem, sensitivity and bias analyses are more difficult to perform correctly and more easily massaged toward preferred conclusions, because they require specification of many more equations and their parameters.</p>
<p>And unlike NHST, abuse of sensitivity and bias analysis is as yet barely studied because the pool of such analyses remains small and highly selective. It thus seems implausible that these analyses will increase replicability of inferences, although they can reveal how assumptions affect those inferences. (Here “replicability” is used according to recommendations of the American Statistical Association (52) to denote independent checks of reported results with new data; “reproducibility” then denotes checks of reported results using the original data and computer code.)</p>
</blockquote>
<hr>
<p>Indeed, this is one drawback of (relatively) newly adopted methods/procedures, they have not been studied long enough as say somethng such as a P-value, which has been studied for centuries. Even something as useful as exploring assumptions and uncertainty such as a principled sensitivity analysis is not free from this.</p>
<p>it seems Greenland’s predictions were accurate; in a large systematic review of published sensitivity analyses led by the mathematician Andrea Saltelli and his group, they found that highly cited papers in top impact factor journals rarely contained sensitivity analyses, and that many of these were poorly done and one-dimensional, in the sense of only varying one parameter at a time, which is hardly informative as a multi-dimensional analysis in which multiple parameters are varied at the same time.</p>
<hr>
<p>Here, we will explore one example of how mindless sensitivity analyses are conducted within the context of clinical trials, although we will not explore multi-dimensional sensitivity analyses here. I make this distinction because the environment to conduct sensitivity/bias analyses differs substantially in trials where regulators are involved versus the environment in which many observational studies are analyzed and presented.</p>
<hr>
<p>In medicine, sensitivity analyses (<strong>SA</strong>) are often conducted in trials and observational studies, but again, little thought is given to what they <em>should</em> entail.<span class="citation" data-cites="Stark2018-eo"><sup>1</sup></span> None of this is surprising given that they are not usually taught in traditional settings, although they have been discussed extensively within the statistical and epidemiological literature<span class="citation" data-cites="greenlandMultipleBiasModelling2005 greenlandBiasAnalysis2008 lashApplyingQuantitativeBias2009 lashGoodPracticesQuantitative2014 lashBiasAnalysisGone2021 gustafsonInvitedCommentaryBetter2021 greenlandDealingInevitableDeficiencies2021"><sup>4–10</sup></span> Yet, the other barrier that remains is that they are incredibly technical and will require the assistance of an analyst familiar with both the theory and the applications. It also does not help that the topic is vast and there are multiple new statistical methods being published every day.</p>
<p>Indeed, the <a href="https://www.taylorfrancis.com/books/mono/10.1201/b17622/handbook-missing-data-methodology-geert-molenberghs-garrett-fitzmaurice-michael-kenward-anastasios-tsiatis"><strong>Handbook of Missing Data Methodology</strong></a>,<span class="citation" data-cites="molenberghsHandbookMissingData2014"><sup>11</sup></span> one of the most authoritative and comprehensive books to date on statistical methods to handle missing data in clinical trials, has nearly <em>six chapters</em> devoted to the topic of sensitivity analyses and different approaches to use. Unfortunately, at the rate that this field is advancing, this book may already be outdated, despite only coming out six years ago.</p>
<p>This article will focus on what a sensitivity analysis is often assumed to be based on practices in the literature, some differing points of view regarding sensitivity analyses (with an example of a highly promoted measure for conducting sensitivity analyses that has been very controversial, and a practical example of conducting <em>principled</em>(by principled, I mean non ad-hoc techniques, as James Carpenter would say) sensitivity analyses in the context of missing data in a randomized clinical trial.</p>
<hr>
<section id="everything-is-sensitive" class="level3">
<h3 class="anchored" data-anchor-id="everything-is-sensitive">Everything is Sensitive</h3>
<hr>
<p>Before we move forward, we must consider what a sensitivity analysis actually entails. The first word of the phrase is an obvious tell, it suggests an analysis that examines how sensitive or robust a result is. But a natural question is, sensitive specifically to what? What sort of perturbations and how relevant are they? Can I vary anything in the analysis to test the sensitivity of the result or assumption? For example, if I obtained an odds ratio of <strong>1.7</strong> from the primary analysis in my experiment and I conducted an extra analysis to see whether the odds ratio would change by a resampling method, is that a sensitivity analysis?</p>
<p>What if I did a completely different type of analysis, for example, suppose the primary analysis was a classical statistical test with an adjustment for multiple comparisons and I decided to run a hierarchical Bayesian regression with a spiked prior on the null, would that be a sensitivity analysis, given they are different frameworks and procedures (although being used for similar goals)? The possibilities of what can be varied are endless when a loose definition of sensitivity analysis is assumed. This is unique to every discipline and their culture. In epidemiology, sensitivity analyses and bias analyses which attempt to extensively explore assumptions and the robustness of the result are used synonymously, yet in the clinical trial world, this is not the case.</p>
<hr>
</section>
<section id="frequent-misconceptions" class="level3">
<h3 class="anchored" data-anchor-id="frequent-misconceptions">Frequent Misconceptions</h3>
<hr>
<p>Take for example in clinical trials and observational studies, in particular, it is common to see primary analyses often being intent-to-treat (<strong>ITT</strong>) analyses and sensitivity analyses being per-protocol analyses (<strong>PP</strong>).</p>
<hr>
<blockquote class="blockquote">
<p>I will not define these terms here and would encourage readers to consult other sources.</p>
</blockquote>
<hr>
<p>The following is a similar example from a high-profile trial published in the <em>The Lancet</em> in 2002,<span class="citation" data-cites="scottMulticentreAneurysmScreening2002"><sup>12</sup></span></p>
<hr>
<blockquote class="blockquote">
<p>The Multicentre Aneurysm Screening Study group randomised 67,800 men to receive an invitation to an abdominal ultrasound scan or not [6]. Of those invited to receive an abdominal scan, 20% did not accept. The primary analysis was by intention to treat, thus estimating the effect of being randomised to abdominal ultrasound. Another analysis investigated the complier average causal effect, which considers what the (average) effect of treatment was in patients who would have adhered to protocol however they were randomised [7].</p>
</blockquote>
<hr>
<p>To many, this may seem perfectly fine, even great. The authors used the question they were primarily interested in as the main analysis, and then conducted an additional analysis to see if these results are consistent. Unfortunately, this is highly problematic as <a href="https://doi.org/10.1186/1471-2288-14-11">Morris et al.&nbsp;(2014)</a><span class="citation" data-cites="morrisChoosingSensitivityAnalyses2014"><sup>13</sup></span> describes</p>
<hr>
<blockquote class="blockquote">
<p>These questions are different, and observing different results should not shake our confidence in either. The CACE analysis was a secondary analysis, not a sensitivity analysis.</p>
<p>It is common for authors to compare the results of intention-to-treat with per-protocol analysis; see for example [8, 9]. While it is hard to pin down the precise question of per-protocol analysis [10], this is clearly different to the question intention-to-treat addresses. Per-protocol analysis should not therefore be considered as a sensitivity analysis for intention-to-treat but as a secondary analysis, if at all.</p>
</blockquote>
<hr>
</section>
<section id="randomness-uncertainty" class="level3">
<h3 class="anchored" data-anchor-id="randomness-uncertainty">Randomness &amp; Uncertainty</h3>
<hr>
</section>
<section id="portable-sensitivity-analyses" class="level3">
<h3 class="anchored" data-anchor-id="portable-sensitivity-analyses">Portable Sensitivity Analyses</h3>
<hr>
<p>These sorts of misunderstandings are so common and so prevalent throughout the literature, so it should come as no surprise that sensitivity analyses are rarely done, or they are done incorrectly. Although not in clinical trials, one particular controversial example has been the promotion and use of the <img src="https://latex.codecogs.com/png.latex?E">-value (the ‘E’ apparently stands for ‘evidence’, but I am not sure.) within epidemiology to assess the amount of confounding necessary within an observational study result to practically reduce the effect estimate to something that is practically null.</p>
<p>The method and value has been adopted with open arms by many epidemiologists and health researchers given that it has simplified a task that is often arduous and requires extensive and careful thought in comparison to the traditional classical analysis. Yet, others have also been highly critical of it for a number of reasons, and although they see the value in promoting sensitivity analyses to more researchers around the world, many are concerned that this measure will also eventually go down the road of P-values, but for observational research.</p>
<hr>
</section>
<section id="regulators-sensitivity-analyses" class="level3">
<h3 class="anchored" data-anchor-id="regulators-sensitivity-analyses">Regulators &amp; Sensitivity Analyses</h3>
<hr>
<p>As mentioned above, there are many possible ways to conduct a sensitivity analysis, especially if the phrase is used in a loose/vague way. Whether or not these are valid and principled approaches to conducting sensitivity analyses is another question. Luckily, many of us do not have to ponder day and night about the semantics about this because both The Handbook of Missing Data Methodology and the <strong>International Council for Harmonisation of Technical Requirements for Pharmaceuticals for Human Use</strong> (<strong>ICH</strong>) have given this topic much thought, and for the latter it is reflected by the fact that they recently created an entire new addition to their E9 guidance document (<a href="https://www.fda.gov/regulatory-information/search-fda-guidance-documents/e9-statistical-principles-clinical-trials"><em>Statistical Principles for Clinical Trials</em></a>) which has served as a reference for clinical trial statisticians for decades. In the addendum, titled <a href="https://database.ich.org/sites/default/files/E9-R1_Step4_Guideline_2019_1203.pdf"><em>Addendum on Estimands and Sensitivity Analysis In Clinical Trials</em></a>, which has now been legally adopted by regulatory agencies around the world including the FDA and EMA, they elaborate on the concept of estimands and the role sensitivity analyses play.</p>
<p>To be clear, estimands are not new and have been discussed in the statistical literature since Tukey<span class="citation" data-cites="mostellerDataAnalysisIncluding1987"><sup>14</sup></span> but the ICH working group’s addendum formalized its adoption in the clinical trial world and the importance of sensitivity analyses.<span class="citation" data-cites="akachaEstimandsTheirRole2017 permuttCovariatesChangeEstimand2020 mitroiuNarrativeReviewEstimands2020"><sup>15–17</sup></span></p>
<hr>
</section>
<section id="estimands-sensitivity" class="level3">
<h3 class="anchored" data-anchor-id="estimands-sensitivity">Estimands &amp; Sensitivity</h3>
<hr>
<blockquote class="blockquote">
<p><strong>A.5.2.1. Role of Sensitivity Analysis</strong></p>
<p>Inferences based on a particular estimand should be robust to limitations in the data and deviations from the assumptions used in the statisticral model for the main estimator. This robustness is evaluated through a sensitivity analysis. Sensitivity analysis should be planned for the main estimators of all estimands that will be important for regulatory decision making and labelling in the product information. This can be a topic for discussion and agreement between sponsor and regulator.</p>
<p>The statistical assumptions that underpin the main estimator should be documented. One or more analyses, focused on the same estimand, should then be pre-specified to investigate these assumptions with the objective of verifying whether or not the estimate derived from the main estimator is robust to departures from its assumptions. This might be characterised as the extent of departures from assumptions that change the interpretation of the results in terms of their statistical or clinical significance (e.g.&nbsp;tipping point analysis).</p>
<p>Distinct from sensitivity analysis, where investigations are conducted with the intent of exploring robustness of departures from assumptions, other analyses that are conducted in order to more fully investigate and understand the trial data can be termed “supplementary analysis” (see Glossary; A.5.3.). Where the primary estimand(s) of interest is agreed between sponsor and regulator, the main estimator is pre-specified unambiguously, and the sensitivity analysis verifies that the estimate derived is reliable for interpretation, supplementary analyses should generally be given lower priority in assessment.</p>
<p><strong>A.5.2.2. Choice of Sensitivity Analysis</strong></p>
<p>When planning and conducting a sensitivity analysis, altering multiple aspects of the main analysis simultaneously can make it challenging to identify which assumptions, if any, are responsible for any potential differences seen. It is therefore desirable to adopt a structured approach, specifying the changes in assumptions that underlie the alternative analyses, rather than simply comparing the results of different analyses based on different sets of assumptions. The need for analyses varying multiple assumptions simultaneously should then be considered on a case by case basis. A distinction between testable and untestable assumptions may be useful when assessing the interpretation and relevance of different analyses.</p>
<p><strong>ICH E9 (R1) Guideline</strong></p>
<p>The need for sensitivity analysis in respect of missing data is established and retains its importance in this framework. Missing data should be defined and considered in respect of a particular estimand (see A.4.). The distinction between data that are missing in respect of a specific estimand and data that are not directly relevant to a specific estimand gives rise to separate sets of assumptions to be examined in sensitivity analysis.</p>
</blockquote>
<hr>
<p>they explicitly define a sensitivity analysis as being an analysis which:</p>
<hr>
<ul>
<li>realistically varies the assumptions from the primary analysis</li>
</ul>
<hr>
<ul>
<li>still targets the same estimand</li>
</ul>
<hr>
<ul>
<li>examines the robustness of the results to</li>
</ul>
<hr>
<ul>
<li>assumption violations or departures</li>
</ul>
<hr>
<ul>
<li>can possibly change the results/conclusions drawn</li>
</ul>
<hr>
<p>They contrast this with more extensive analyses that investigate these violations/departures of assumptions, and characterize those analyse as being supplementary rather than sensitivity. The latter is typically what is seen in rigorous epidemiological studies that employ quantitative bias analyses (a more specialized form of sensitivity analysis).</p>
<p>The ICH E9 addendum contains similar views that are echoed by the National Research Council’s advice on clinical trials (National Research Council 2010)<span class="citation" data-cites="littlePreventionTreatmentMissing2012"><sup>18</sup></span> regarding estimands and sensitivity</p>
<hr>
<blockquote class="blockquote">
<p><strong>Recommendation 15</strong>: Sensitivity analysis should be part of the primary reporting of findings from clinical trials. <strong>Examining sensitivity to the assumptions about the missing data mechanism should be a mandatory component of reporting.</strong></p>
</blockquote>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="grViz html-widget html-fill-item" id="htmlwidget-fa974c54d7c477ecf659" style="width:100%;height:480px;"></div>
<script type="application/json" data-for="htmlwidget-fa974c54d7c477ecf659">{"x":{"diagram":"digraph {\n  graph [layout = dot, rankdir = TB,\n         compound = true, bgcolor = \"transparent\",\n         nodesep = .5, ranksep = .25]\n  node [shape = circle,\n      fixedsize = true,\n      fontsize = 9,\n      fontname = Helvetica,\n      fontcolor = \"#000000\",\n      width = .99,\n      height = .99,\n      style = filled,\n      color = \"#91A3B0\",\n      label = \"\"]\n  edge [color = \"#888888\", arrowhead = normal, arrowtail = inv]\n  rec1 [label = \"Study \nObjective\", fillcolor = \"#D0EAEE\"]\n  rec2 [label = \"Estimand\", fillcolor = \"#abd9ca\"]\n  rec3 [label =  \"Primary \nEstimator\", fillcolor = \"#7aa864\"]\n  rec4 [label = \"Primary \nEstimate\", fillcolor = \"#7aa864\"]\n  rec5 [label = \"Sensitivity \nEstimator \n1\", fillcolor = \"#E69F00\"]\n  rec6 [label = \"Sensitivity \nEstimate \n1\", fillcolor = \"#E69F00\"]\n  rec7 [label = \"Sensitivity \nEstimator \n2\", fillcolor = \"#e7998c\"]\n  rec8 [label = \"Sensitivity \nEstimate \n2\", fillcolor = \"#e7998c\"]\n  # edge definitions with the node IDs\n  rec1 -> rec2\n  rec2 -> rec3 ->rec4\n  rec2 -> rec5 ->rec6\n  rec2 -> rec7 ->rec8}","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<hr>
<p>Now, back to the <em>NEJM</em> paper. The reason why an <strong>ITT</strong> analysis and a <strong>PP</strong> analysis cannot serve as primary and sensitivity analyses, respectively, is because they are targeting entirely <em>different estimands</em>.<span class="citation" data-cites="morrisChoosingSensitivityAnalyses2014"><sup>13</sup></span> Thus, because they are answering completely different questions, they’re just two different analyses. And the additional <strong>PP</strong> analysis, although important to certain stakeholders, can be classified as a supplementary analysis or a non-sensitivity analysis.</p>
<p>Indeed, the following flowchart from <a href="https://doi.org/10.1186/1471-2288-14-11">Morris et al.&nbsp;(2014)</a><span class="citation" data-cites="morrisChoosingSensitivityAnalyses2014"><sup>13</sup></span> is particularly useful as a guide to differentiate sensitivity analyses from non-sensitivity analyses.</p>
<hr>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://res.cloudinary.com/less-likely/image/upload/q_auto:best/v1618886541/Site/sensitivitytree.png" class="img-fluid figure-img"></p>
<figcaption>Adapted sensitivity-analysis flowchart.</figcaption>
</figure>
</div>
<p>Adapted flowchart from <a href="https://doi.org/10.1186/1471-2288-14-11">Morris et al.&nbsp;(2014)</a>.</p>
<hr>
</section>
<section id="utility-of-subject-matter-experts" class="level3">
<h3 class="anchored" data-anchor-id="utility-of-subject-matter-experts">Utility of Subject-Matter Experts</h3>
<hr>
<p>So what does a sensitivity analysis actually look like within the context of a clinical trial or experiment? Below, I walk through the analysis of a trial to give some examples.</p>
<hr>
</section>
</section>
<section id="sensitivity-in-clinical-trials" class="level2">
<h2 class="anchored" data-anchor-id="sensitivity-in-clinical-trials">Sensitivity in Clinical Trials</h2>
<hr>
<p>I’ll use a sample clinical trial dataset, which is described here:<span class="citation" data-cites="chenClinicalTrialData2017"><sup>19</sup></span></p>
<hr>
<blockquote class="blockquote">
<p>“This dataset is typical of diastolic blood pressure data measured in small clinical trials in hypertension from the mid-to-late 1960s and for approximately a decade thereafter.</p>
<p><strong>During this time, hypertension was more severe, the number of effective treatments was relatively small, and the definition (DBP &gt; 95 mmHg) of essential hypertension was not as stringent as it is now (DBP &gt; 80 mmHg)</strong> - as seen in the 1967 report from the Veterans Administration Cooperative Study Group on Antihypertensive Agents VA Study Group (1967).</p>
<p>In Table 3.1, diastolic blood pressure (DBP) was measured (mmHg) in the supine position at baseline (i.e., DBP) before randomization… Patients’ age and sex were recorded at baseline and represent potential covariates. <strong>The primary objective in this chapter in the analysis of this dataset is to test whether treatment A (new drug) may be effective in lowering DBP as compared to B (placebo) and to describe changes in DBP across the times at which it was measured.</strong>”</p>
</blockquote>
<hr>
<p>So to recap, the primary investigators of this trial were interested to see whether treatment A was more effective in lowering DBP when compared to placebo.</p>
<hr>
<blockquote class="blockquote">
<p>Although we will not be using some of the scripts and project setup that I discussed in my <a href="https://lesslikely.com/statistics/statistics-quality-control/#setting-up-the-error-catching-script">statistical workflow post</a> for the sake of efficiency and ease, I would urge and recommend others do so that it remains easy to catch errors. In particular, I would especially recommend using the following packages:</p>
</blockquote>
<hr>
<ul>
<li><a href="https://cran.r-project.org/web/packages/here/index.html"><code>here</code></a></li>
</ul>
<hr>
<ul>
<li><a href="https://cran.r-project.org/web/packages/futile.logger/index.html"><code>futile.logger</code></a></li>
</ul>
<hr>
<ul>
<li><a href="https://cran.r-project.org/web/packages/tryCatchLog/index.html"><code>tryCatchLog</code></a></li>
</ul>
<hr>
<p>For the analyses in this post, see the R packages in the session info section at the <a href="../statistics/sensitivity/#statistical-software">end of this post</a>, these will need to be loaded in order for the scripts below to work.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">req_packs <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rms"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mice"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"magrittr"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidyr"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"future"</span>,</span>
<span id="cb1-2">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"showtext"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"concurve"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggtext"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidyverse"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggplot2"</span>,</span>
<span id="cb1-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"parallel"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kableExtra"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cowplot"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cairo"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"svglite"</span>,</span>
<span id="cb1-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"yardstick"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"broom"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mi"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hmisc"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"here"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"VIM"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"wesanderson"</span>,</span>
<span id="cb1-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bayesplot"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lattice"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"doParallel"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blogdown"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Amelia"</span>,</span>
<span id="cb1-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bootImpute"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"brms"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rmarkdown"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tinytex"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"texPreview"</span>,</span>
<span id="cb1-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggcorrplot"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qqplotr"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"car"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Statamarkdown"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rstan"</span>,</span>
<span id="cb1-8">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"missForest"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"htmltools"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidybayes"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"performance"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mvtnorm"</span>,</span>
<span id="cb1-9">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ImputeRobust"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gamlss"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ProfileLikelihood"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reshape2"</span>,</span>
<span id="cb1-10">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"boot"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"knitr"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MASS"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"miceMNAR"</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Load all packages at once</span></span>
<span id="cb1-13"></span>
<span id="cb1-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(req_packs, library, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">character.only =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
</div>
<hr>
<p>I will now simulate some of the data from this clinical trial.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;"># Simulate Trial Data</span></span>
<span id="cb2-2"></span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>,</span>
<span id="cb2-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"L'Ecuyer-CMRG"</span>,</span>
<span id="cb2-5">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">normal.kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Inversion"</span>,</span>
<span id="cb2-6">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sample.kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rejection"</span>)</span>
<span id="cb2-7"></span>
<span id="cb2-8">BaselineDBP <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;">500</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">117</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb2-9">Group <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;">rbinom</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</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-10">Age <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;">500</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>)</span>
<span id="cb2-11">R1 <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;">500</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb2-12">R2 <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;">500</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-13"></span>
<span id="cb2-14">errors <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mvtnorm<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;">rmvnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>,</span>
<span id="cb2-15">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</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;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb2-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb2-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</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;">byrow =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb2-18">  )</span>
<span id="cb2-19">)</span>
<span id="cb2-20"></span>
<span id="cb2-21">PostDBP <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (Age <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.33</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-22">  (Group <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;">9.7</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> errors[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span></code></pre></div></div>
</div>
<hr>
<p>I have made some minor adjustments to this dataset and also generated a new variable (<code>Z</code>) based on the existing ones in the dataset that is strongly correlated with the outcome of interest (<code>PostDBP</code>).</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-8-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;"># Explore Data</span></span>
<span id="cb3-2"></span>
<span id="cb3-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str</span>(BP_full)</span>
<span id="cb3-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 'data.frame':    500 obs. of  7 variables:</span></span>
<span id="cb3-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ PostDBP    : num  142 140 129 148 135 ...</span></span>
<span id="cb3-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ BaselineDBP: num  119 116 115 119 119 ...</span></span>
<span id="cb3-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ Group      : Factor w/ 2 levels "Drug X","Drug Y": 1 1 2 1 2 2 1 2 1 1 ...</span></span>
<span id="cb3-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ Age        : num  41.8 44.4 41.1 56.6 50.2 ...</span></span>
<span id="cb3-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ Z          : num  0.0141 -0.0629 -0.1101 0.0313 0.0495 ...</span></span>
<span id="cb3-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ R1         : num  0.523 1.021 -0.839 0.413 -0.175 ...</span></span>
<span id="cb3-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ R2         : num  0.451 0.35 0.897 1.227 1.166 ...</span></span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div id="lviazvgdqd" style="padding-left:0px;padding-right:0px;padding-top:10px;padding-bottom:10px;overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
<style>#lviazvgdqd table {
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#lviazvgdqd thead, #lviazvgdqd tbody, #lviazvgdqd tfoot, #lviazvgdqd tr, #lviazvgdqd td, #lviazvgdqd th {
  border-style: none;
}

#lviazvgdqd p {
  margin: 0;
  padding: 0;
}

#lviazvgdqd .gt_table {
  display: table;
  border-collapse: collapse;
  line-height: normal;
  margin-left: auto;
  margin-right: auto;
  color: #333333;
  font-size: 16px;
  font-weight: normal;
  font-style: normal;
  background-color: #FFFFFF;
  width: auto;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #A8A8A8;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #A8A8A8;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
}

#lviazvgdqd .gt_caption {
  padding-top: 4px;
  padding-bottom: 4px;
}

#lviazvgdqd .gt_title {
  color: #333333;
  font-size: 125%;
  font-weight: initial;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-color: #FFFFFF;
  border-bottom-width: 0;
}

#lviazvgdqd .gt_subtitle {
  color: #333333;
  font-size: 85%;
  font-weight: initial;
  padding-top: 3px;
  padding-bottom: 5px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-color: #FFFFFF;
  border-top-width: 0;
}

#lviazvgdqd .gt_heading {
  background-color: #FFFFFF;
  text-align: center;
  border-bottom-color: #FFFFFF;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#lviazvgdqd .gt_bottom_border {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#lviazvgdqd .gt_col_headings {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
}

#lviazvgdqd .gt_col_heading {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 6px;
  padding-left: 5px;
  padding-right: 5px;
  overflow-x: hidden;
}

#lviazvgdqd .gt_column_spanner_outer {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: normal;
  text-transform: inherit;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 4px;
  padding-right: 4px;
}

#lviazvgdqd .gt_column_spanner_outer:first-child {
  padding-left: 0;
}

#lviazvgdqd .gt_column_spanner_outer:last-child {
  padding-right: 0;
}

#lviazvgdqd .gt_column_spanner {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: bottom;
  padding-top: 5px;
  padding-bottom: 5px;
  overflow-x: hidden;
  display: inline-block;
  width: 100%;
}

#lviazvgdqd .gt_spanner_row {
  border-bottom-style: hidden;
}

#lviazvgdqd .gt_group_heading {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  text-align: left;
}

#lviazvgdqd .gt_empty_group_heading {
  padding: 0.5px;
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  vertical-align: middle;
}

#lviazvgdqd .gt_from_md > :first-child {
  margin-top: 0;
}

#lviazvgdqd .gt_from_md > :last-child {
  margin-bottom: 0;
}

#lviazvgdqd .gt_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  margin: 10px;
  border-top-style: solid;
  border-top-width: 1px;
  border-top-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 1px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 1px;
  border-right-color: #D3D3D3;
  vertical-align: middle;
  overflow-x: hidden;
}

#lviazvgdqd .gt_stub {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
}

#lviazvgdqd .gt_stub_row_group {
  color: #333333;
  background-color: #FFFFFF;
  font-size: 100%;
  font-weight: initial;
  text-transform: inherit;
  border-right-style: solid;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
  padding-left: 5px;
  padding-right: 5px;
  vertical-align: top;
}

#lviazvgdqd .gt_row_group_first td {
  border-top-width: 2px;
}

#lviazvgdqd .gt_row_group_first th {
  border-top-width: 2px;
}

#lviazvgdqd .gt_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#lviazvgdqd .gt_first_summary_row {
  border-top-style: solid;
  border-top-color: #D3D3D3;
}

#lviazvgdqd .gt_first_summary_row.thick {
  border-top-width: 2px;
}

#lviazvgdqd .gt_last_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#lviazvgdqd .gt_grand_summary_row {
  color: #333333;
  background-color: #FFFFFF;
  text-transform: inherit;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
}

#lviazvgdqd .gt_first_grand_summary_row {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-top-style: double;
  border-top-width: 6px;
  border-top-color: #D3D3D3;
}

#lviazvgdqd .gt_last_grand_summary_row_top {
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 5px;
  padding-right: 5px;
  border-bottom-style: double;
  border-bottom-width: 6px;
  border-bottom-color: #D3D3D3;
}

#lviazvgdqd .gt_striped {
  background-color: rgba(128, 128, 128, 0.05);
}

#lviazvgdqd .gt_table_body {
  border-top-style: solid;
  border-top-width: 2px;
  border-top-color: #D3D3D3;
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
}

#lviazvgdqd .gt_footnotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#lviazvgdqd .gt_footnote {
  margin: 0px;
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#lviazvgdqd .gt_sourcenotes {
  color: #333333;
  background-color: #FFFFFF;
  border-bottom-style: none;
  border-bottom-width: 2px;
  border-bottom-color: #D3D3D3;
  border-left-style: none;
  border-left-width: 2px;
  border-left-color: #D3D3D3;
  border-right-style: none;
  border-right-width: 2px;
  border-right-color: #D3D3D3;
}

#lviazvgdqd .gt_sourcenote {
  font-size: 90%;
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 5px;
  padding-right: 5px;
}

#lviazvgdqd .gt_left {
  text-align: left;
}

#lviazvgdqd .gt_center {
  text-align: center;
}

#lviazvgdqd .gt_right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#lviazvgdqd .gt_font_normal {
  font-weight: normal;
}

#lviazvgdqd .gt_font_bold {
  font-weight: bold;
}

#lviazvgdqd .gt_font_italic {
  font-style: italic;
}

#lviazvgdqd .gt_super {
  font-size: 65%;
}

#lviazvgdqd .gt_footnote_marks {
  font-size: 75%;
  vertical-align: 0.4em;
  position: initial;
}

#lviazvgdqd .gt_asterisk {
  font-size: 100%;
  vertical-align: 0;
}

#lviazvgdqd .gt_indent_1 {
  text-indent: 5px;
}

#lviazvgdqd .gt_indent_2 {
  text-indent: 10px;
}

#lviazvgdqd .gt_indent_3 {
  text-indent: 15px;
}

#lviazvgdqd .gt_indent_4 {
  text-indent: 20px;
}

#lviazvgdqd .gt_indent_5 {
  text-indent: 25px;
}

#lviazvgdqd .katex-display {
  display: inline-flex !important;
  margin-bottom: 0.75em !important;
}

#lviazvgdqd div.Reactable > div.rt-table > div.rt-thead > div.rt-tr.rt-tr-group-header > div.rt-th-group:after {
  height: 0px !important;
}
</style>

<table class="gt_table caption-top table table-sm table-striped small" data-quarto-bootstrap="false">
<caption><strong>Patient Characteristics</strong></caption>
<colgroup>
<col style="width: 20%">
<col style="width: 20%">
<col style="width: 20%">
<col style="width: 20%">
<col style="width: 20%">
</colgroup>
<thead>
<tr class="gt_col_headings header">
<th id="label" class="gt_col_heading gt_columns_bottom_border gt_left" data-quarto-table-cell-role="th" scope="col"><strong>Variable</strong></th>
<th id="n" class="gt_col_heading gt_columns_bottom_border gt_center" data-quarto-table-cell-role="th" scope="col"><strong>N</strong></th>
<th id="stat_0" class="gt_col_heading gt_columns_bottom_border gt_center" data-quarto-table-cell-role="th" scope="col"><strong>Overall</strong><br>
N = 500<span class="gt_footnote_marks" style="white-space:nowrap;font-style:italic;font-weight:normal;line-height:0;"><sup>1</sup></span></th>
<th id="stat_1" class="gt_col_heading gt_columns_bottom_border gt_center" data-quarto-table-cell-role="th" scope="col"><strong>Drug X</strong><br>
N = 258<span class="gt_footnote_marks" style="white-space:nowrap;font-style:italic;font-weight:normal;line-height:0;"><sup>1</sup></span></th>
<th id="stat_2" class="gt_col_heading gt_columns_bottom_border gt_center" data-quarto-table-cell-role="th" scope="col"><strong>Drug Y</strong><br>
N = 242<span class="gt_footnote_marks" style="white-space:nowrap;font-style:italic;font-weight:normal;line-height:0;"><sup>1</sup></span></th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr class="odd">
<td class="gt_row gt_left" headers="label" style="font-weight: bold">PostDBP</td>
<td class="gt_row gt_center" headers="n">500</td>
<td class="gt_row gt_center" headers="stat_0">138.5 (133.4, 142.8)</td>
<td class="gt_row gt_center" headers="stat_1">142.5 (140.5, 144.6)</td>
<td class="gt_row gt_center" headers="stat_2">133.4 (131.3, 135.3)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label" style="font-weight: bold">BaselineDBP</td>
<td class="gt_row gt_center" headers="n">500</td>
<td class="gt_row gt_center" headers="stat_0">116.88 (115.56, 118.22)</td>
<td class="gt_row gt_center" headers="stat_1">116.90 (115.53, 118.21)</td>
<td class="gt_row gt_center" headers="stat_2">116.81 (115.59, 118.23)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label" style="font-weight: bold">Age</td>
<td class="gt_row gt_center" headers="n">500</td>
<td class="gt_row gt_center" headers="stat_0">49 (45, 55)</td>
<td class="gt_row gt_center" headers="stat_1">49 (45, 55)</td>
<td class="gt_row gt_center" headers="stat_2">50 (46, 55)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label" style="font-weight: bold">Z</td>
<td class="gt_row gt_center" headers="n">500</td>
<td class="gt_row gt_center" headers="stat_0">0.00 (-0.04, 0.05)</td>
<td class="gt_row gt_center" headers="stat_1">0.00 (-0.04, 0.04)</td>
<td class="gt_row gt_center" headers="stat_2">0.00 (-0.05, 0.05)</td>
</tr>
<tr class="odd">
<td class="gt_row gt_left" headers="label" style="font-weight: bold">R1</td>
<td class="gt_row gt_center" headers="n">500</td>
<td class="gt_row gt_center" headers="stat_0">0.00 (-0.73, 0.56)</td>
<td class="gt_row gt_center" headers="stat_1">0.05 (-0.73, 0.60)</td>
<td class="gt_row gt_center" headers="stat_2">-0.10 (-0.74, 0.52)</td>
</tr>
<tr class="even">
<td class="gt_row gt_left" headers="label" style="font-weight: bold">R2</td>
<td class="gt_row gt_center" headers="n">500</td>
<td class="gt_row gt_center" headers="stat_0">0.96 (0.64, 1.28)</td>
<td class="gt_row gt_center" headers="stat_1">0.96 (0.59, 1.30)</td>
<td class="gt_row gt_center" headers="stat_2">0.97 (0.67, 1.28)</td>
</tr>
</tbody><tfoot>
<tr class="gt_footnotes odd">
<td colspan="5" class="gt_footnote"><span class="gt_footnote_marks" style="white-space:nowrap;font-style:italic;font-weight:normal;line-height:0;"><sup>1</sup></span> Median (Q1, Q3)</td>
</tr>
</tfoot>

</table>

</div>
</div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">summary</span>(BP_full)</span>
<span id="cb4-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     PostDBP     BaselineDBP     Group          Age             Z                   R1                  R2        </span></span>
<span id="cb4-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Min.   :124   Min.   :110   Drug X:258   Min.   :27.7   Min.   :-1.85e-01   Min.   :-3.205036   Min.   :-0.646  </span></span>
<span id="cb4-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  1st Qu.:133   1st Qu.:116   Drug Y:242   1st Qu.:45.3   1st Qu.:-4.44e-02   1st Qu.:-0.732386   1st Qu.: 0.645  </span></span>
<span id="cb4-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Median :138   Median :117                Median :49.4   Median : 9.45e-05   Median :-0.000058   Median : 0.960  </span></span>
<span id="cb4-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Mean   :138   Mean   :117                Mean   :49.7   Mean   : 0.00e+00   Mean   :-0.042800   Mean   : 0.962  </span></span>
<span id="cb4-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  3rd Qu.:143   3rd Qu.:118                3rd Qu.:54.7   3rd Qu.: 4.56e-02   3rd Qu.: 0.552206   3rd Qu.: 1.283  </span></span>
<span id="cb4-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Max.   :151   Max.   :123                Max.   :68.4   Max.   : 2.02e-01   Max.   : 3.377526   Max.   : 2.480</span></span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">PostDBP</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Group</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Age</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Z</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R1</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R2</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">142</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">119</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Drug X</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">41.8</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.52</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.45</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">140</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">116</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Drug X</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">44.4</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.06</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.35</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">129</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">115</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Drug Y</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">41.1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.11</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.84</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.90</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">148</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">119</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Drug X</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">56.6</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.03</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.41</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.23</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">135</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">119</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Drug Y</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">50.2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.05</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.17</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.17</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">135</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">118</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Drug Y</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">55.3</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.89</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.77</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">143</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">117</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Drug X</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">54.3</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.07</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.34</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">133</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">116</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Drug Y</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">55.8</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.05</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-1.91</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.96</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">144</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">118</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Drug X</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">46.9</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.03</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.75</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">150</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">119</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Drug X</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">62.0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.94</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.48</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-13-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>Now, we can quickly explore the other characteristics of the dataset, and first we look at the rank correlations between the predictors and the response variable.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;"># Data Attributes</span></span>
<span id="cb5-2"></span>
<span id="cb5-3">study_formula <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.formula</span>(PostDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> .)</span>
<span id="cb5-4"></span>
<span id="cb5-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">spearman2</span>(study_formula, BP_full),</span>
<span id="cb5-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cex =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb5-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</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;">"darkred"</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>)</span>
<span id="cb5-8">)</span>
<span id="cb5-9"></span>
<span id="cb5-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v =</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;">col =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alpha</span>(zred, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lty =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-14-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>Along with a correlation matrix between the variables of interest.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-15-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>We will not be looking at the estimates from a fitted model yet. We are mainly looking at a few characteristics of this dataset before we move on to the next step.</p>
<hr>
<section id="the-threat-of-missing-data" class="level3">
<h3 class="anchored" data-anchor-id="the-threat-of-missing-data">The Threat of Missing Data</h3>
<hr>
<p>Now that we have familiarized ourselves with this dataset, we suddenly “notice” that there are missing data (which I actually generated below using a custom function) and suppose we didn’t actually know how the missing data were generated, we might suspect or start with the assumption that the data are missing at random (<strong>MAR</strong>).</p>
<p>We will explore a number of different methods used to handle missing data, including multiple imputation, selection models, and a number of ad-hoc methods commonly used by researchers handle missing data. However, before we move on to discussing some of these methods, we will quickly review concepts and terms regarding missing data mechanisms.</p>
<hr>
<blockquote class="blockquote">
<p>In the figure below, the three missing data mechanisms (MCAR, MAR, and MNAR) and ignorability (whether we need to model the mechanism of missing data) in relation to observed data (Y obs), missing data (Y mis), the missingness matrix (R), and their relationships (q; parameters that explain missingness, i.e., mechanism). The solid arrows, dotted arrows, and arrows with crosses represent “connection,” “possible connection,” and “no connection,” respectively.</p>
<p>The lines connecting ignorability and missingness group the three mechanisms into the two ignorability categories. Also no pure forms of MCAR, MAR, and MNAR exist, and all missingness can be considered as a form of MAR missingness; this is represented by the shaded continuum bar on the left. - Modified from Nakagawa and Freckleton (2011)</p>
</blockquote>
<hr>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/images/missing-mech.png" class="img-fluid figure-img" width="800"></p>
<figcaption>Missing-data mechanism flowchart.</figcaption>
</figure>
</div>
<p>Flowchart from <a href="http://www.i-deel.org/uploads/5/2/4/1/52416001/chapter_4.pdf">Ecological Statistics: Contemporary Theory and Applications</a>.</p>
<hr>
<p>Of course, here, we do have an idea of what the missing data mechanism is, but we shall assume the role of a data analyst who has just been given a dataset with missing values in the outcome from their clinical colleague.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate Missing Data</span></span>
<span id="cb6-2"></span>
<span id="cb6-3"><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;">1031</span>,</span>
<span id="cb6-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"L'Ecuyer-CMRG"</span>,</span>
<span id="cb6-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">normal.kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Inversion"</span>,</span>
<span id="cb6-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sample.kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rejection"</span></span>
<span id="cb6-7">)</span>
<span id="cb6-8">Ry <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>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lesslikely</span>() <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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb6-9">PostDBP[Ry <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;">0</span>] <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;">NA</span></span>
<span id="cb6-10">BP_miss <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="cb6-11">  PostDBP, BaselineDBP,</span>
<span id="cb6-12">  Group, Age, Z, R1, R2</span>
<span id="cb6-13">)</span>
<span id="cb6-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str</span>(BP_miss)</span>
<span id="cb6-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 'data.frame':    500 obs. of  7 variables:</span></span>
<span id="cb6-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ PostDBP    : num  142 140 129 148 135 ...</span></span>
<span id="cb6-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ BaselineDBP: num  119 116 115 119 119 ...</span></span>
<span id="cb6-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ Group      : Factor w/ 2 levels "Drug X","Drug Y": 1 1 2 1 2 2 1 2 1 1 ...</span></span>
<span id="cb6-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ Age        : num  41.8 44.4 41.1 56.6 50.2 ...</span></span>
<span id="cb6-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ Z          : num  0.0141 -0.0629 -0.1101 0.0313 0.0495 ...</span></span>
<span id="cb6-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ R1         : num  0.523 1.021 -0.839 0.413 -0.175 ...</span></span>
<span id="cb6-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  $ R2         : num  0.451 0.35 0.897 1.227 1.166 ...</span></span>
<span id="cb6-23"></span>
<span id="cb6-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(BP_miss))</span>
<span id="cb6-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [1] 245</span></span>
<span id="cb6-26"></span>
<span id="cb6-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Export data for Stata chunks: Group must be numeric and NAs must be blank,</span></span>
<span id="cb6-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># otherwise `import delimited` reads those columns as strings. Code Drug Y as 1</span></span>
<span id="cb6-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># so Stata's `i.group` matches R's factor contrast (base = Drug X).</span></span>
<span id="cb6-30"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.create</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"static/datasets"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">recursive =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">showWarnings =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb6-31">BP_stata <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> BP_miss</span>
<span id="cb6-32">BP_stata<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Group <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.integer</span>(BP_stata<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;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Drug Y"</span>)</span>
<span id="cb6-33"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write.csv</span>(BP_stata, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"static/datasets/temp.csv"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span></code></pre></div></div>
</div>
<hr>
<p>We will now attempt to visualize our dataset and examine what proportion of these data are missing.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">missing_col <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>(zblue, zred)</span>
<span id="cb7-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aggr</span>(BP_miss,</span>
<span id="cb7-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alpha</span>(missing_col, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.60</span>),</span>
<span id="cb7-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prop =</span> F, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">numbers =</span> T</span>
<span id="cb7-5">)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-18-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-19-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="864"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>So now, we must examine this missing dataset and its characteristics and look for any systematic differences. We also examine the proportion of missingness and the influx and outflux patterns. This is important to assess how well connectected the missing data are to the observed data, explained by <a href="https://stefvanbuuren.name/fimd/missing-data-pattern.html">van Buuren here</a></p>
<hr>
<blockquote class="blockquote">
<p>The influx of a variable quantifies how well its missing data connect to the observed data on other variables. The outflux of a variable quantifies how well its observed data connect to the missing data on other variables. In general, higher influx and outflux values are preferred…</p>
<p>Influx and outflux are summaries of the missing data pattern intended to aid in the construction of imputation models. Keeping everything else constant, variables with high influx and outflux are preferred. Realize that outflux indicates the potential (and not actual) contribution to impute other variables. A variable with high <img src="https://latex.codecogs.com/png.latex?O_%7Bj%7D"> may turn out to be useless for imputation if it is unrelated to the incomplete variables. On the other hand, the usefulness of a highly predictive variable is severely limited by a low <img src="https://latex.codecogs.com/png.latex?O_%7Bj%7D">.</p>
<p>More refined measures of usefulness are conceivable, e.g., multiplying <img src="https://latex.codecogs.com/png.latex?O_%7Bj%7D"> by the average proportion of explained variance. Also, we could specialize to one or a few key variables to impute. Alternatively, analogous measures for <img src="https://latex.codecogs.com/png.latex?I_%7Bj%7D"> could be useful. The further development of diagnostic summaries for the missing data pattern is a promising area for further investigation.</p>
</blockquote>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;"># Examine Flux Patterns</span></span>
<span id="cb8-2"></span>
<span id="cb8-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fico</span>(BP_miss), <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;">2</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;">6</span>]</span>
<span id="cb8-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; BaselineDBP       Group         Age           Z          R1 </span></span>
<span id="cb8-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;         0.5         0.5         0.5         0.5         0.5</span></span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; color: rgba(119, 119, 119, 1) !important;"></th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">POBS</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Influx</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Outflux</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">AINB</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">AOUT</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">FICO</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">PostDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.51</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.45</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.49</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Group</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.49</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Age</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.49</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Z</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.49</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">R1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.49</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">R2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.49</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<p>Next, We start off doing some preliminary analyses to eyeball differences between the observed data and the missing data.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-23-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="864"></p>
</figure>
</div>
</div>
<pre><code>#&gt; [1] 245</code></pre>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; color: rgba(119, 119, 119, 1) !important;"></th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">pobs</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">influx</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">outflux</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">ainb</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">aout</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">fico</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">PostDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.51</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.45</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.49</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Group</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.49</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Age</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.49</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Z</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.49</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">R1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.49</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">R2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.49</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<p>Having explored these data, we fit a preliminary model quickly to these missing data using the <a href="https://rdrr.io/pkg/MASS/man/rlm.html"><code>rlm()</code></a> function from the <a href="https://rdrr.io/pkg/MASS/"><code>MASS</code></a> package and glance at what our estimates look like.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;"># Exploratory Model Estimates</span></span>
<span id="cb10-2"></span>
<span id="cb10-3">eda_1 <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;">rlm</span>(</span>
<span id="cb10-4">  PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-5">    Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2,</span>
<span id="cb10-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> BP_miss,</span>
<span id="cb10-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MM"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">psi =</span> psi.huber</span>
<span id="cb10-8">)</span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; color: rgba(119, 119, 119, 1) !important;"></th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Value</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Std. Error</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">t value</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">(Intercept)</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">11.68</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">5.77</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.02</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">factor(Group)Drug Y</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.58</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.13</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-71.57</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.98</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.05</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">19.86</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Age</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.34</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">34.33</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Z</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.93</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.48</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.62</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">R1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.03</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.07</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.43</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">R2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.13</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.13</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.94</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">AIC</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">AICc</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">BIC</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">RMSE</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Sigma</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">749</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">750</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">778</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.03</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-28-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-28-2.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>Because the <a href="https://rdrr.io/pkg/MASS/man/rlm.html"><code>MASS::rlm()</code></a> function will automatically delete missing observations and do a complete-case analysis, we can gauge what our estimates would look like if we assume that the data are missing completely at random (<strong>MCAR</strong>), which is almost always unrealistic.</p>
<p>It is almost always more realistic to assume that the data are missing at random (<strong>MAR</strong>), <img src="https://latex.codecogs.com/png.latex?%5Coperatorname%7BPr%7D%5Cleft(R=0%20%5Cmid%20Y_%7B%5Cmathrm%7Bobs%7D%7D,%20Y_%7B%5Cmathrm%7Bmis%7D%7D,%20%5Cpsi%5Cright)=%5Coperatorname%7BPr%7D%5Cleft(R=0%20%5Cmid%20Y_%7B%5Cmathrm%7Bobs%7D%7D,%20%5Cpsi%5Cright)">. This can often be a reasonable assumption to start off with for the primary analysis.<span class="citation" data-cites="buurenFlexibleImputationMissing2018"><sup>20</sup></span></p>
<hr>
</section>
<section id="multiple-imputation-workflow" class="level3">
<h3 class="anchored" data-anchor-id="multiple-imputation-workflow">Multiple Imputation Workflow</h3>
<hr>
<p>For our main analysis, we will build an imputation model to essentially ‘predict’ the missing values in our dataset. This is because multiple imputation is a well-studied set of algorithms that are efficient and robust to deviances from normality.</p>
<hr>
<blockquote class="blockquote">
<p>Modern missing data methodologies include maximum-likelihood estimation (MLE) methods such as expectation–maximisation (EM) and multiple imputation (MI), both recommended for data which is MAR [3]. MI has been shown to be robust under departures from normality, in cases of low sample size, and when the proportion of missing data is high [2]. With complete outcome variables, MI is typically less computationally expensive than MLE, and MLE tends to be problem-specific with a different model being required for each analysis [8].</p>
<ul>
<li>Plumpton CO, Morris T, Hughes DA, White IR. Multiple imputation of multiple multi-item scales when a full imputation model is infeasible. BMC Res Notes. 2016 Jan 26;9:45. doi: 10.1186/s13104-016-1853-5.</li>
</ul>
</blockquote>
<hr>
<p>How exactly does multiple imputation work?</p>
<hr>
<blockquote class="blockquote">
<p>The standard multiple imputation procedure (Rubin, 1987; Schafer, 1997) replaces missing covariate data with values drawn from a set of specified imputation models based on the observed relationships between the covariates and outcome, typically under a missing at random (MAR) assumption (Little and Rubin, 1987). A key feature of the procedure is that it outputs a number, say M, of imputed datasets. A prediction model is then fitted to each imputed dataset to produce imputation-specific regression coefficients, which can be averaged using “Rubin’s rules” (Rubin, 1987) to provide pooled regression coefficients.</p>
<p>To extract predictions from such a prediction model and multiply imputed data, either the sets of imputation-specific regression coefficients or the pooled regression coefficients could be used, and we must decide how to handle individuals with multiply imputed covariates. Thus there are numerous combinations for constructing a set of predictions, including imputation-specific predictions (M predictions for each individual) and pooled predictions (an averaged prediction over imputed datasets for each individual). The differences between them and their advantages and drawbacks are unclear.</p>
</blockquote>
<hr>
<blockquote class="blockquote">
<p>Wood, A.M., Royston, P. and White, I.R. (2015), The estimation and use of predictions for the assessment of model performance using large samples with multiply imputed data. Biom. J., 57: 614-632. <a href="https://doi.org/10.1002/bimj.201400004" class="uri">https://doi.org/10.1002/bimj.201400004</a></p>
</blockquote>
<hr>
<p>We include all possible information in our imputation model, for example, that might mean entail specifying all the variables in our dataset as covariates, and impute the missing data using a set of reliable and well-studied imputation algorithms, and then analyze each dataset and pool the results. Our basic workflow will look like this:</p>
<hr>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/images/missingness.png" class="img-fluid figure-img" width="800"></p>
<figcaption>Missingness workflow flowchart.</figcaption>
</figure>
</div>
<p>Flowchart from <a href="http://www.i-deel.org/uploads/5/2/4/1/52416001/chapter_4.pdf">Ecological Statistics: Contemporary Theory and Applications</a>.</p>
<hr>
</section>
<section id="concepts-in-multiple-imputation" class="level3">
<h3 class="anchored" data-anchor-id="concepts-in-multiple-imputation">Concepts in Multiple Imputation</h3>
<hr>
<p>It can also be written using the following notation, which will be explained below.</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cbar%7Bb%7D%20&amp;=%5Cfrac%7B1%7D%7Bm%7D%20%5Csum_%7Bi=1%7D%5Em%20b_i%20%5C%5C%0Av_W%20&amp;=%5Cfrac%7B1%7D%7Bm%7D%20%5Csum_%7Bi=1%7D%5Em%20s_%7B.%7D%20e_%7B%5Ccdot%7D%5E2%20%5C%5C%0Av_B%20&amp;=%5Cfrac%7B1%7D%7Bm-1%7D%20%5Csum_%7Bi=1%7D%5Em%5Cleft(b_i-%5Cbar%7Bb%7D%5Cright)%5E2%20%5C%5C%0Av_T%20&amp;=v_W+v_B+%5Cfrac%7Bv_B%7D%7Bm%7D%0A%5Cend%7Baligned%7D%0A"></p>
<hr>
<p><a href="http://www.i-deel.org/uploads/5/2/4/1/52416001/chapter_4.pdf">Nagakawa writes</a>:</p>
<hr>
<blockquote class="blockquote">
<p>There are three main steps in MI: imputation, analysis, and pooling (figure 4.5C). In the imputation step, you create <img src="https://latex.codecogs.com/png.latex?m"> copies of completed data set by using data imputation methods such as the EM/EMB algorithms or the MCMC procedure. In the analysis step, you run separate statistical analyses on each of <img src="https://latex.codecogs.com/png.latex?m"> data sets. Finally, in the pooling step, you aggregate <img src="https://latex.codecogs.com/png.latex?m"> sets of results to produce unbiased parameter and uncertainty estimates.</p>
<p>This aggregation process is done by the following equations (which are automatically calculated in <em>R</em>): where <img src="https://latex.codecogs.com/png.latex?%5Cbar%7Bb%7D"> is the mean of <img src="https://latex.codecogs.com/png.latex?b_%7Bi%7D"> (e.g., regression coefficients), which is a parameter estimated from the ith data set (<img src="https://latex.codecogs.com/png.latex?m">), <img src="https://latex.codecogs.com/png.latex?v_W"> is the within-imputation variance calculated from the standard error associated with <img src="https://latex.codecogs.com/png.latex?b_%7Bi%7D">, <img src="https://latex.codecogs.com/png.latex?v_B"> is the between-imputation variance estimates, and <img src="https://latex.codecogs.com/png.latex?v_T"> is the total variance (<img src="https://latex.codecogs.com/png.latex?%E2%88%9Av_T"> is the overall standard error for <img src="https://latex.codecogs.com/png.latex?%5Cbar%7Bb%7D">).</p>
<p>This set of equations for combining estimates from <img src="https://latex.codecogs.com/png.latex?m"> sets of results is often referred to as Rubin’s rules, as it was developed by Rubin (1987). Statistical significance and confidence intervals (CIs) of pooled parameters are obtained by, where <img src="https://latex.codecogs.com/png.latex?df"> is the number of degrees of freedom used for t-tests or to obtain <img src="https://latex.codecogs.com/png.latex?t"> values and CI calculations, and <img src="https://latex.codecogs.com/png.latex?%CE%B1"> is the significance level (e.g., 95% CI, <img src="https://latex.codecogs.com/png.latex?%CE%B1"> = 0.05).:</p>
</blockquote>
<hr>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0Ad%20f%20&amp;=(m-1)%5Cleft(1+%5Cfrac%7Bm%20v_W%7D%7B(m+1)%20v_B%7D%5Cright)%5E2,%20%5C%5C%0At_%7Bd%20f%7D%20&amp;=%5Cfrac%7B%5Cbar%7Bb%7D%7D%7B%5Csqrt%7Bv_T%7D%7D,%20%5C%5C%0A100(1-%5Calpha)%20%5C%25%20%5Cmathrm%7BCI%7D%20&amp;=%5Cbar%7Bb%7D%20%5Cpm%20t_%7Bd%20f,(1-%5Calpha%20/%202)%20%5Csqrt%7Bv_T%7D%7D%0A%5Cend%7Baligned%7D%0A"></p>
<hr>
<p><a href="http://www.i-deel.org/uploads/5/2/4/1/52416001/chapter_4.pdf">Nagakawa then</a> discusses the similarities between imputation algorithms and MCMC methods,</p>
<hr>
<blockquote class="blockquote">
<p>MCMC procedures (and also Gibbs sampling) are often called Bayesian methods (chapter 1) because their goal is to create the posterior distributions of parameters, but methods using MCMC have much wider applications than Bayesian statistics). The MCMC procedure, is akin to the EM algorithm (Schafer 1997) in that it uses a two-step iterative algorithm to find <img src="https://latex.codecogs.com/png.latex?%5Cbf%7B%5Chat%7Bm%7D%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Cbf%7B%5Chat%7BV%7D%7D">.</p>
<p>The imputation step (I-step) uses stochastic regression with observed data. Next, the posterior step (P-step) uses this filled-in data set to construct the posterior distributions of <img src="https://latex.codecogs.com/png.latex?%5Cbf%7B%5Chat%7Bm%7D%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Cbf%7B%5Chat%7BV%7D%7D">. Then, it uses a Monte Carlo method to sample a new set of <img src="https://latex.codecogs.com/png.latex?%5Cbf%7B%5Chat%7Bm%7D%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Cbf%7B%5Chat%7BV%7D%7D"> from these distributions. These new parameter estimates are used for the subsequent I-step. Iterations of the two steps create the Markov chain, which even actually converges into fully fledged posterior distributions of <img src="https://latex.codecogs.com/png.latex?%5Cbf%7B%5Chat%7Bm%7D%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Cbf%7B%5Chat%7BV%7D%7D"> (figure 4.6B). These distributions are, in turn, used for multiple imputation.</p>
</blockquote>
<hr>
<p>Now that we’ve quickly reviewed some of the concepts of multipe imputation and missing data, we can now begin to build our imputation model. This is generally done by building a model with all relevant covariates, however, this should be compared a reduced model with just the treatment group. This is because we want both the adjusted and unadjusted estimates. We will then compare these models using the <a href="https://github.com/amices/mice/blob/master/R/D3.R">likelihood-ratio test</a><span class="citation" data-cites="mengPerformingLikelihoodRatio1992"><sup>21</sup></span> to see whether there are any substantial differences between the fully-adjusted and reduced model.</p>
<p>The imputation model for a particular parameter will generally resemble the estimation model being used.</p>
<hr>
<blockquote class="blockquote">
<p>When developing your imputation model, it is important to assess if your imputation model is “congenial” or consistent with your analytic model. Consistency means that your imputation model includes (at the very least) the same variables that are in your analytic or estimation model. This includes any transformations to variables that will be needed to assess your hypothesis of interest. This can include log transformations, interaction terms, or recodes of a continuous variable into a categorical form, if that is how it will be used in later analysis. The reason for this relates back to the earlier comments about the purpose of multiple imputation.</p>
<p>Since we are trying to reproduce the proper variance/covariance matrix for estimation, all relationships between our analytic variables should be represented and estimated simultaneously. Otherwise, you are imputing values assuming they have a correlation of zero with the variables you did not include in your imputation model. This would result in underestimating the association between parameters of interest in your analysis and a loss of power to detect properties of your data that may be of interest such as non-linearities and statistical interactions. - <a href="https://stats.oarc.ucla.edu/stata/seminars/mi_in_stata_pt1_new/">From the UCLA Statistical Consulting Website</a></p>
</blockquote>
<hr>
</section>
<section id="monte-carlo-error-analysis" class="level3">
<h3 class="anchored" data-anchor-id="monte-carlo-error-analysis">Monte Carlo Error Analysis</h3>
<hr>
<p>However, before we begin to build the model, we must also have an idea of how many imputations we need to compute. To many, this may seem like a trivial and even nonsensical task when any individual can impute a large number of datasets. Indeed, it may seem that more imputations would give a more reliable and precise estimate, however, nothing in life is free, and running a imputation algorithm that is computationally demanding (and which can potentially take hours or days) is not feasible for everyone, hence the reason for “sample-size” calculations for imputation algorithms.</p>
<hr>
<blockquote class="blockquote">
<p>Multiple imputation is a stochastic procedure. Each time we reimpute our data, we get different sets of imputations because of the randomness of the imputation step, and therefore we get different multiple-imputation estimates. However, we want to be able to reproduce MI results. Of course, we can always set the random-number seed to ensure reproducibility by obtaining the same imputed values. However, what if we use a different seed? Would we not want our results to be similar regardless of what seed we use? This leads us to a notion we call statistical reproducibility—we want results to be similar across repeated uses of the same imputation procedure; that is, we want to minimize the simulation error associated with our results.</p>
<p>To assess the level of simulation error, White, Royston, and Wood (2011) propose to use a Monte Carlo error of the MI results, defined as the standard deviation of the results across repeated runs of the same imputation procedure using the same data. The authors suggest evaluating Monte Carlo error estimates not only for parameter estimates but also for other statistics, including p-values and confidence intervals, as well as MI statistics including RVI and FMI.</p>
</blockquote>
<hr>
<p>The issue with this is that without giving careful thought to how many imputations may be needed for a particular study, one may run the risk of imputing too few datasets and losing information, or they may waste resources imputing a nonsensical amount that may not be necessary. Indeed, the latter seems especially trivial, however, it may often yield no advantages whatsoever, and only incur costs as many authors have argued.</p>
<hr>
<blockquote class="blockquote">
<p>The argument is that “the additional resources that would be required to create and store more than a few imputations would not be well spent” (Schafer 1997, 107), and “in most situations there is simply little advantage to producing and analyzing more than a few imputed datasets” (Schafer and Olsen 1998, 549).</p>
</blockquote>
<hr>
<p>Therefore, we will examine certain characteristics of our dataset with missing values and use them in an analysis to determine how many datasets we should impute to efficiently achieve our goals. We will base this off a number of characteristics such as the fraction of missing information, the proportion of missing observations, and the losses that we are willing to incur.</p>
<p>We first start by running a “dry” or naive imputation of our data to quickly examine some of these characteristics. This imputed dataset will not be used for our primary analysis, it is simply serving to guide us in our main imputation model. This is also why we have set the number of iterations to 0.</p>
<p>Once again, we will include all the variables in our dataset, and use the predictive mean matching method with approximately 5 donors.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;"># Dry Imputation</span></span>
<span id="cb11-2"></span>
<span id="cb11-3">form <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;">list</span>(PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2)</span>
<span id="cb11-4">pred <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;">make.predictorMatrix</span>(BP_miss)</span>
<span id="cb11-5"></span>
<span id="cb11-6">init_imp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mice<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;">mice</span>(</span>
<span id="cb11-7">  BP_miss,</span>
<span id="cb11-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pmm"</span>,</span>
<span id="cb11-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">predictorMatrix =</span> pred,</span>
<span id="cb11-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>,</span>
<span id="cb11-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxit =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb11-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>,</span>
<span id="cb11-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formulas =</span> form,</span>
<span id="cb11-14">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">donors =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb11-15">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remove.collinear =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb11-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remove.constant =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb11-17">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">printFlag =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb11-18">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">visitSequence =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"monotone"</span></span>
<span id="cb11-19">)</span>
<span id="cb11-20"></span>
<span id="cb11-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(init_imp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>loggedEvents, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb11-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; NULL</span></span></code></pre></div></div>
</div>
<hr>
<p>Now that we have imputed our dataset, we may examine it for any issues before moving onto the next step of analyzing it.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-30-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-31-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>Although it is only a dry run, there seems to be no issues with it. We now pool our estimates using Rubin’s rules.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">init_res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mice<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;">pool</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">with</span>(</span>
<span id="cb12-2">  init_imp,</span>
<span id="cb12-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rlm</span>(</span>
<span id="cb12-4">    PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-5">      BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-6">      Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2,</span>
<span id="cb12-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MM"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">psi =</span> psi.huber</span>
<span id="cb12-8">  )</span>
<span id="cb12-9">))</span>
<span id="cb12-10"></span>
<span id="cb12-11">init_res_sum <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;">summary</span>(init_res)</span>
<span id="cb12-12"></span>
<span id="cb12-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(init_res_sum) <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>
<span id="cb12-14">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Term"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SE"</span>,</span>
<span id="cb12-15">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Statistic"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"df"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P-val"</span></span>
<span id="cb12-16">)</span>
<span id="cb12-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ztable</span>(init_res_sum)</span></code></pre></div></div>
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Term</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Estimate</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">SE</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Statistic</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">df</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">P-val</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">(Intercept)</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">41.77</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">17.18</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.43</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">factor(Group)Drug Y</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-8.22</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.43</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-19.26</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.74</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.15</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">5.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Age</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.28</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.03</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">10.23</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Z</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.57</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">4.20</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.37</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.03</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.23</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.14</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.36</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.21</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<p>Now that we have our vector, we can quickly examine certain characteristics such as the fraction of missing information (FIMO), the between-imputation variance and the within-imputation variance. The reason that we focus on these particular attributes is because they are crucial for several tasks in any statistical analysis plan, such as having enough power/precision, minimum long-run coverage, etc.</p>
<p>We use the FIMO from the dry imputation and a number of other criteria to determine how many imputations we need:</p>
<hr>
<ul>
<li>Some have suggested taking the FIMO and multiplying by 100 to obtain the number of imputed datasets needed</li>
</ul>
<hr>
<p><img src="https://latex.codecogs.com/png.latex?m%20%5Capprox%20100%20%5Clambda"></p>
<hr>
<ul>
<li>For our goals, we wish to ensure that the monte-carlo standard error from the imputations are less than 10% of the between-imputation standard error</li>
</ul>
<hr>
<p><img src="https://latex.codecogs.com/png.latex?mcse%20%3C%20B%5E%7B%5Chat%7B-%7D%7D_%7BSE%7D%20*%200.10"></p>
<hr>
<ul>
<li>We wish to minimize the monte-carlo error that is derived from dividing the chosen number of datasets to impute from the fraction of missing information so that the monte-carlo standard error is less than 0.01</li>
</ul>
<hr>
<p><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7BFMI%7D%7Bm%7D%20%E2%89%88%200.01"></p>
<hr>
<ul>
<li>We also wish to minimize the total variance so that the square-root of it is no greater than the ideal variance and the corresponding confidence interval width.</li>
</ul>
<hr>
<p><img src="https://latex.codecogs.com/png.latex?T_%7Bm%7D=%5Cleft(1+%5Cfrac%7B%5Cgamma_%7B0%7D%7D%7Bm%7D%5Cright)%20T_%7B%5Cinfty%7D"></p>
<hr>
<ul>
<li>Furthermore, it is commonly advocated by missing data experts to impute the same or similar number of datasets as fractions of missing observations <img src="https://latex.codecogs.com/png.latex?%5Cgamma_%7B0%7D*100"></li>
</ul>
<hr>
<p>We start by extracting the FMIs from our dry imputation and calculating all these numbers.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Calculate Fraction of Missing Information</span></span>
<span id="cb13-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># `mice::pool()`/`summary.mipo()` have changed their returned columns across</span></span>
<span id="cb13-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># versions. Prefer the explicit `fmi` column when present; otherwise fall back</span></span>
<span id="cb13-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># to `lambda`, and finally compute it from Rubin's variance components.</span></span>
<span id="cb13-5">extract_fmi <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>(model) {</span>
<span id="cb13-6">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is</span>(model, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mira"</span>)) {</span>
<span id="cb13-7">    model <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mice<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;">pool</span>(model)</span>
<span id="cb13-8">  }</span>
<span id="cb13-9">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</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;">is</span>(model, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mipo"</span>)) {</span>
<span id="cb13-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stop</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Model must be multiply imputed."</span>)</span>
<span id="cb13-11">  }</span>
<span id="cb13-12"></span>
<span id="cb13-13">  pooled <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> model<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pooled</span>
<span id="cb13-14">  finite_max <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>(x) {</span>
<span id="cb13-15">    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;">suppressWarnings</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(x))</span>
<span id="cb13-16">    x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> x[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.finite</span>(x)]</span>
<span id="cb13-17">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(x)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(x) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA_real_</span></span>
<span id="cb13-18">  }</span>
<span id="cb13-19"></span>
<span id="cb13-20">  fmi_value <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;">if</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fmi"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(pooled)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">finite_max</span>(pooled<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>fmi) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA_real_</span></span>
<span id="cb13-21">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</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;">is.na</span>(fmi_value)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(fmi_value, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.999</span>))</span>
<span id="cb13-22"></span>
<span id="cb13-23">  lambda_value <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;">if</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lambda"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(pooled)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">finite_max</span>(pooled<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>lambda) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA_real_</span></span>
<span id="cb13-24">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</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;">is.na</span>(lambda_value)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(lambda_value, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.999</span>))</span>
<span id="cb13-25"></span>
<span id="cb13-26">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all</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;">"b"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ubar"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(pooled))) {</span>
<span id="cb13-27">    m_count <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;">if</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;">is.null</span>(model<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>m)) model<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>m <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">finite_max</span>(pooled<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>m)</span>
<span id="cb13-28">    riv <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="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> m_count) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> pooled<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>b <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> pooled<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ubar</span>
<span id="cb13-29">    lambda <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> riv <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> riv)</span>
<span id="cb13-30">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"df"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(pooled)) {</span>
<span id="cb13-31">      fmi_calc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> lambda <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> (pooled<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>df <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>
<span id="cb13-32">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb13-33">      fmi_calc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> lambda</span>
<span id="cb13-34">    }</span>
<span id="cb13-35">    fmi_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;">finite_max</span>(fmi_calc)</span>
<span id="cb13-36">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</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;">is.na</span>(fmi_value)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(fmi_value, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.999</span>))</span>
<span id="cb13-37">  }</span>
<span id="cb13-38"></span>
<span id="cb13-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stop</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Could not extract or compute fraction of missing information from pooled model."</span>)</span>
<span id="cb13-40">}</span>
<span id="cb13-41"></span>
<span id="cb13-42">fmi <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;">extract_fmi</span>(init_res)</span>
<span id="cb13-43"></span>
<span id="cb13-44">m <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> fmi <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.01</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># FMI Imputations</span></span>
<span id="cb13-45"></span>
<span id="cb13-46">mcse <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>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(init_res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pooled<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>b, <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> m) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># MCSE</span></span>
<span id="cb13-47"></span>
<span id="cb13-48">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;">max</span>((init_res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pooled<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ubar) <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;">500</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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># SE</span></span></code></pre></div></div>
</div>
<hr>
<p>What we find is that the fraction of missing information is nearly 50% which is very high and that in order to get a monte-carlo error of less than 0.01, we would need a minimum of at least 50 imputed datasets. We also calculate both the monte-carlo standard error and the standard error from the dry run and find that they are practically equivalent.</p>
<p>However, we must also explore other possibilities in terms of number of imputed datasets to reduce the monte-carlo errors so we run a quick function to do that, checking the effects of a number of imputed datasets on the width of the confidence interval, which is directly tied to the monte-carlo error.</p>
<p>Indeed, Von Hippel (2018) proposed a relationship between the fraction of missing information and the number of imputations needed to achieve a targeted CI length or monte-carlo error using a quadratic formula,</p>
<hr>
<p><img src="https://latex.codecogs.com/png.latex?m=1+%5Cfrac%7B1%7D%7B2%7D%5Cleft(%5Cfrac%7B%5Cgamma_%7B0%7D%7D%7B%5Coperatorname%7BSD%7D%5Cleft(%5Csqrt%7BU_%7B%5Cell%7D%7D%5Cright)%20%5Cmathrm%7BE%7D%5Cleft(%5Csqrt%7BU_%7B%5Cell%7D%7D%5Cright)%7D%5Cright)%5E%7B2%7D"></p>
<hr>
<p>where <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BE%7D%5Cleft(%5Csqrt%7BU_%7B%5Cell%7D%7D%5Cright)"> and <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BSD%7D%5Cleft(%5Csqrt%7BU_%7B%5Cell%7D%7D%5Cright)"> are the coefficient of variation (CV), summarizing the imputation variation in the SE estimates. We can graphically construct a function to depict this relationship and calculate how many imputations we will need based on some desired error and further display the distribution of this relationship by varying these parameters.</p>
<p>In the function below, adopted from von Hippel, and van Buuren,<span class="citation" data-cites="buurenFlexibleImputationMissing2018"><sup>20</sup></span> I vary both the coefficient of variation and the <img src="https://latex.codecogs.com/png.latex?%5Calpha">-level.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;">#' @title How Many Imputations?</span></span>
<span id="cb14-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @description Implements two-stage "how_many_imputations" from von Hippel (2018)</span></span>
<span id="cb14-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param model Either a `mira` object (created by running a model on a data set which was imputed via "mice")</span></span>
<span id="cb14-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' or a `mipo` object (creating by runing `pool()` on a `mira` object).</span></span>
<span id="cb14-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param cv Desired precision of standard errors. Default to .05. (I.e., if the data were re-imputed, the</span></span>
<span id="cb14-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' estimated standard errors would differ by no more than this amount.)</span></span>
<span id="cb14-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @param alpha Significance level for choice of "conservative" FMI.</span></span>
<span id="cb14-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @return The number of required imputations to obtain the `cv` level of precision.</span></span>
<span id="cb14-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @export</span></span>
<span id="cb14-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @importFrom methods is</span></span>
<span id="cb14-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @importFrom stats plogis qlogis qnorm</span></span>
<span id="cb14-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @importFrom mice pool</span></span>
<span id="cb14-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' @references von Hippel, Paul T. (2018)</span></span>
<span id="cb14-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' \sQuote{How Many Imputations Do You Need? A Two-stage Calculation Using a Quadratic Rule.},</span></span>
<span id="cb14-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' \emph{Sociological Methods &amp; Research} p.0049124117747303.</span></span>
<span id="cb14-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#'</span></span>
<span id="cb14-17">powerimp <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>(model, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cv =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>) {</span>
<span id="cb14-18">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is</span>(model, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mira"</span>)) {</span>
<span id="cb14-19">    model <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mice<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;">pool</span>(model)</span>
<span id="cb14-20">  }</span>
<span id="cb14-21">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</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;">is</span>(model, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mipo"</span>)) {</span>
<span id="cb14-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stop</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Model must be multiply imputed."</span>)</span>
<span id="cb14-23">  }</span>
<span id="cb14-24">  fmi <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;">extract_fmi</span>(model)</span>
<span id="cb14-25">  z <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;">qnorm</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> alpha <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>
<span id="cb14-26">  fmiu <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;">plogis</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qlogis</span>(fmi) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> z <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> model<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>m))</span>
<span id="cb14-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ceiling</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;">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;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (fmiu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> cv)<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>
<span id="cb14-28">}</span>
<span id="cb14-29"></span>
<span id="cb14-30">ci_width <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="cb14-31">  cv_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;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.20</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>)</span>
<span id="cb14-32">  results1 <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;">lapply</span>(</span>
<span id="cb14-33">    (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(cv_i) <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;">100</span>),</span>
<span id="cb14-34">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(i) {</span>
<span id="cb14-35">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">powerimp</span>(</span>
<span id="cb14-36">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">model =</span> init_res,</span>
<span id="cb14-37">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cv =</span> i, <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.01</span></span>
<span id="cb14-38">      )</span>
<span id="cb14-39">    }</span>
<span id="cb14-40">  )</span>
<span id="cb14-41">  results2 <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;">lapply</span>(</span>
<span id="cb14-42">    (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(cv_i) <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;">100</span>),</span>
<span id="cb14-43">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(i) {</span>
<span id="cb14-44">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">powerimp</span>(</span>
<span id="cb14-45">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">model =</span> init_res,</span>
<span id="cb14-46">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cv =</span> i, <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.05</span></span>
<span id="cb14-47">      )</span>
<span id="cb14-48">    }</span>
<span id="cb14-49">  )</span>
<span id="cb14-50">  results3 <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;">lapply</span>(</span>
<span id="cb14-51">    (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(cv_i) <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;">100</span>),</span>
<span id="cb14-52">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(i) {</span>
<span id="cb14-53">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">powerimp</span>(</span>
<span id="cb14-54">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">model =</span> init_res,</span>
<span id="cb14-55">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cv =</span> i, <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>
<span id="cb14-56">      )</span>
<span id="cb14-57">    }</span>
<span id="cb14-58">  )</span>
<span id="cb14-59">  a_0<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.01</span> <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;">do.call</span>(rbind, results1)</span>
<span id="cb14-60">  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>(cv_i, a_0<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.01</span>)</span>
<span id="cb14-61">  df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>a_0<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.05</span> <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;">do.call</span>(rbind, results2)</span>
<span id="cb14-62">  df<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>a_0<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">.1</span> <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;">do.call</span>(rbind, results3)</span>
<span id="cb14-63">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(df)</span>
<span id="cb14-64">}</span>
<span id="cb14-65"></span>
<span id="cb14-66">some <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;">ci_width</span>()</span></code></pre></div></div>
</div>
<hr>
<p>With this function, we can now graphically examine the effects of different parameter values on the monte-carlo errors from the imputations.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-35-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>We can see above that as we aim for smaller monte-carlo errors, we need many more imputations to achieve our desired target.</p>
<p>Now that I have constructed and graphed three differing relationships between monte-carlo errors and number of imputations needed to achieve those errors, and varied the <img src="https://latex.codecogs.com/png.latex?%5Calpha">-levels, we can now move onto choosing a specific number of imputations to construct.</p>
<p>If I choose an <img src="https://latex.codecogs.com/png.latex?%5Calpha"> level of 5%, which the maximum tolerable type-I error rate, and a coefficient of variation of 5%</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;"># Estimate Number of Imputations</span></span>
<span id="cb15-2"></span>
<span id="cb15-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">powerimp</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">model =</span> init_res, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cv =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</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.05</span>)</span>
<span id="cb15-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [1] 24</span></span>
<span id="cb15-5"></span>
<span id="cb15-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">powerimp</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">model =</span> init_res, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cv =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</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.05</span>)</span>
<span id="cb15-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [1] 92</span></span>
<span id="cb15-8"></span>
<span id="cb15-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">powerimp</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">model =</span> init_res, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cv =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</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.05</span>)</span>
<span id="cb15-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [1] 2257</span></span></code></pre></div></div>
</div>
<hr>
<p>I need to construct approximately 124 imputations to achieve this coefficient of variation, which is what I will use for all the analyses from here on, and it is clear that it is far more reasonable than trying to impute 3000 datasets to achieve a tiny standard error.</p>
<hr>
<p>However, I want to verify my calculations by running a similar estimation command that Stata provides. The documentation says the following regarding RVI and FMI:</p>
<hr>
<blockquote class="blockquote">
<p>Returning to the output, average RVI reports the average relative increase (averaged over all coefficients) in variance of the estimates because of the missing bmi values. A relative variance increase is an increase in the variance of the estimate because of the loss of information about the parameter due to nonresponse relative to the variance of the estimate with no information lost. The closer this number is to zero, the less effect missing data have on the variance of the estimate. Note that the reported RVI will be zero if you use mi estimate with the complete data or with missing data that have not been imputed. In our case, average RVI is small: 0.0312.</p>
<p>Largest FMI reports the largest of all the FMI about coefficient estimates due to nonresponse. This number can be used to get an idea of whether the specified number of imputations is sufficient for the analysis. A rule of thumb is that M ≥ 100 × FMI provides an adequate level of reproducibility of MI analysis. In our example, the largest FMI is 0.14 and the number of imputations, 20, exceeds the required number of imputations: 14</p>
</blockquote>
<hr>
<p>Although I cannot get the number of imputations directly from a command, I can run the <a href="https://www.stata.com/manuals/mimiestimate.pdf"><code>mi estimate</code></a> command, and look at the overall fraction of missing information as the number of imputations increases. If my previous calculations are consistent, I should look to increase the number of imputations until I achieve an FMI of 1.24 or less: 124/100</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb16-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">linesize</span> 255</span>
<span id="cb16-2"></span>
<span id="cb16-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">all</span></span>
<span id="cb16-4"></span>
<span id="cb16-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">seed</span> 1031</span>
<span id="cb16-6"></span>
<span id="cb16-7"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">quietly</span> import delimited <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"static/datasets/temp.csv"</span>, numericcols(2 3 5 6 7 8)</span>
<span id="cb16-8"></span>
<span id="cb16-9"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">quietly</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mi</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span> mlong</span>
<span id="cb16-10"></span>
<span id="cb16-11"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">quietly</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mi</span> register imputed baselinedbp postdbp age z <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> r1 r2</span>
<span id="cb16-12"></span>
<span id="cb16-13"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">quietly</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mi</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">impute</span> chained (pmm, knn(5)) postdbp = baselinedbp age z r1 r2 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span>, burnin(5) add(120) rseed (1031) nomonotone</span>
<span id="cb16-14"></span>
<span id="cb16-15"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">quietly</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mi</span> estimate, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">saving</span>(miest, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span>): <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">rreg</span> postdbp i.<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> baselinedbp age z r1 r2</span>
<span id="cb16-16"></span>
<span id="cb16-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mi</span> estimate <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">using</span> miest, mcerror <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">level</span>(95)</span>
<span id="cb16-18"></span>
<span id="cb16-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mi</span> estimate, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">saving</span>(miest, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span>) vartable mcerror <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">level</span>(95) nocitable: <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">rreg</span> postdbp i.<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> baselinedbp age z r1 r2</span>
<span id="cb16-20"></span>
<span id="cb16-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mi</span> estimate <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">using</span> miest, mcerror <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">level</span>(95)</span>
<span id="cb16-22">#&gt; file ()<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">print</span>() <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> found</span>
<span id="cb16-23">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(601);</span>
<span id="cb16-24">#&gt; </span>
<span id="cb16-25">#&gt; </span>
<span id="cb16-26">#&gt; </span>
<span id="cb16-27">#&gt; </span>
<span id="cb16-28">#&gt; </span>
<span id="cb16-29">#&gt; </span>
<span id="cb16-30">#&gt; </span>
<span id="cb16-31">#&gt; </span>
<span id="cb16-32">#&gt; </span>
<span id="cb16-33">#&gt; </span>
<span id="cb16-34">#&gt; </span>
<span id="cb16-35">#&gt; Multiple-imputation <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span>                   Imputations       =        120</span>
<span id="cb16-36">#&gt; Robust regression                               Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span>     =        500</span>
<span id="cb16-37">#&gt;                                                 Average RVI       =     0.7202</span>
<span id="cb16-38">#&gt;                                                 Largest FMI       =     0.4949</span>
<span id="cb16-39">#&gt;                                                 Complete DF       =        493</span>
<span id="cb16-40">#&gt; DF adjustment:   Small <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">sample</span>                   DF:     <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>       =     165.96</span>
<span id="cb16-41">#&gt;                                                         avg       =     202.37</span>
<span id="cb16-42">#&gt;                                                         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>       =     274.66</span>
<span id="cb16-43">#&gt; Model <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">F</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">test</span>:       Equal FMI                   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">F</span>(   6,  431.4)   =    1183.09</span>
<span id="cb16-44">#&gt;                                                 Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">F</span>          =     0.0000</span>
<span id="cb16-45">#&gt; </span>
<span id="cb16-46">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb16-47">#&gt;      postdbp | Coefficient  Std. err.      t    P&gt;|t|     [95% conf. interval]</span>
<span id="cb16-48">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb16-49">#&gt;      1.<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> |  -9.523045   .1168215   -81.52   0.000    -9.753025   -9.293066</span>
<span id="cb16-50">#&gt;              |   .0057905   .0025234     1.76   0.000     .0084985    .0067603</span>
<span id="cb16-51">#&gt;              |</span>
<span id="cb16-52">#&gt;  baselinedbp |    .980327   .0453156    21.63   0.000       .89096    1.069694</span>
<span id="cb16-53">#&gt;              |   .0026919   .0011629     0.57   0.000     .0038643    .0032359</span>
<span id="cb16-54">#&gt;              |</span>
<span id="cb16-55">#&gt;          age |   .3297468   .0088947    37.07   0.000      .312222    .3472716</span>
<span id="cb16-56">#&gt;              |   .0004879   .0002219     0.92   0.000     .0006042    .0007118</span>
<span id="cb16-57">#&gt;              |</span>
<span id="cb16-58">#&gt;            z |  -1.062159   1.509542    -0.70   0.483    -4.041587    1.917269</span>
<span id="cb16-59">#&gt;              |   .0945004   .0410673     0.07   0.041     .1227202    .1282877</span>
<span id="cb16-60">#&gt;              |</span>
<span id="cb16-61">#&gt;           r1 |   -.018845   .0725934    -0.26   0.795    -.1621706    .1244805</span>
<span id="cb16-62">#&gt;              |   .0046239   .0026182     0.06   0.049     .0075822    .0063906</span>
<span id="cb16-63">#&gt;              |</span>
<span id="cb16-64">#&gt;           r2 |  -.1529839   .1325282    -1.15   0.250    -.4145243    .1085565</span>
<span id="cb16-65">#&gt;              |   .0082342   .0037686     0.07   0.027     .0120192    .0102984</span>
<span id="cb16-66">#&gt;              |</span>
<span id="cb16-67">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |    11.6797   5.307458     2.20   0.029     1.213107     22.1463</span>
<span id="cb16-68">#&gt;              |   .3147167   .1363694     0.07   0.005     .3681237    .4611054</span>
<span id="cb16-69">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb16-70">#&gt; Note: Values displayed beneath <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span> are Monte Carlo <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">error</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span>.</span>
<span id="cb16-71">#&gt; </span>
<span id="cb16-72">#&gt; </span>
<span id="cb16-73">#&gt; Multiple-imputation <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span>                   Imputations       =        120</span>
<span id="cb16-74">#&gt; Robust regression</span>
<span id="cb16-75">#&gt; </span>
<span id="cb16-76">#&gt; Variance information</span>
<span id="cb16-77">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb16-78">#&gt;              |        Imputation <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">variance</span>                             Relative</span>
<span id="cb16-79">#&gt;              |    Within   Between     Total       RVI       FMI    efficiency</span>
<span id="cb16-80">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb16-81">#&gt;      1.<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> |    .00959   .004024   .013647   .423052   .299522        .99751</span>
<span id="cb16-82">#&gt;              |   .000042   .000576   .000588   .060302   .030372       .000254</span>
<span id="cb16-83">#&gt;              |                                                  </span>
<span id="cb16-84">#&gt;  baselinedbp |   .001177    .00087   .002054   .745092   .430409       .996426</span>
<span id="cb16-85">#&gt;              |   5.1e-06   .000104   .000105   .088822   .029698       .000248</span>
<span id="cb16-86">#&gt;              |                                                  </span>
<span id="cb16-87">#&gt;          age |    .00005   .000029   .000079   .572671   .367007       .996951</span>
<span id="cb16-88">#&gt;              |   2.2e-07   3.9e-06   3.9e-06   .077358   .031978       .000267</span>
<span id="cb16-89">#&gt;              |                                                  </span>
<span id="cb16-90">#&gt;            z |   1.19815   1.07164   2.27872   .901867   .478054       .996032</span>
<span id="cb16-91">#&gt;              |   .005198   .122213   .123705   .102669   .028885       .000241</span>
<span id="cb16-92">#&gt;              |                                                  </span>
<span id="cb16-93">#&gt;           r1 |   .002683   .002566    .00527     .9643   .494902       .995893</span>
<span id="cb16-94">#&gt;              |   .000012   .000373   .000379   .139641   .037113       .000309</span>
<span id="cb16-95">#&gt;              |                                                  </span>
<span id="cb16-96">#&gt;           r2 |    .00936   .008136   .017564   .876541   .470898       .996091</span>
<span id="cb16-97">#&gt;              |   .000041    .00098   .000996    .10503   .030376       .000253</span>
<span id="cb16-98">#&gt;              |                                                  </span>
<span id="cb16-99">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   16.1845   11.8856   28.1691   .740502   .428884       .996439</span>
<span id="cb16-100">#&gt;              |   .070211   1.42688    1.4443   .088798   .029842       .000249</span>
<span id="cb16-101">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb16-102">#&gt; Note: Values displayed beneath <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span> are Monte Carlo <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">error</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span>.</span>
<span id="cb16-103">#&gt; </span>
<span id="cb16-104">#&gt; </span>
<span id="cb16-105">#&gt; </span>
<span id="cb16-106">#&gt; Multiple-imputation <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span>                   Imputations       =        120</span>
<span id="cb16-107">#&gt; Robust regression                               Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span>     =        500</span>
<span id="cb16-108">#&gt;                                                 Average RVI       =     0.7202</span>
<span id="cb16-109">#&gt;                                                 Largest FMI       =     0.4949</span>
<span id="cb16-110">#&gt;                                                 Complete DF       =        493</span>
<span id="cb16-111">#&gt; DF adjustment:   Small <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">sample</span>                   DF:     <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>       =     165.96</span>
<span id="cb16-112">#&gt;                                                         avg       =     202.37</span>
<span id="cb16-113">#&gt;                                                         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>       =     274.66</span>
<span id="cb16-114">#&gt; Model <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">F</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">test</span>:       Equal FMI                   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">F</span>(   6,  431.4)   =    1183.09</span>
<span id="cb16-115">#&gt;                                                 Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">F</span>          =     0.0000</span>
<span id="cb16-116">#&gt; </span>
<span id="cb16-117">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb16-118">#&gt;      postdbp | Coefficient  Std. err.      t    P&gt;|t|     [95% conf. interval]</span>
<span id="cb16-119">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb16-120">#&gt;      1.<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> |  -9.523045   .1168215   -81.52   0.000    -9.753025   -9.293066</span>
<span id="cb16-121">#&gt;              |   .0057905   .0025234     1.76   0.000     .0084985    .0067603</span>
<span id="cb16-122">#&gt;              |</span>
<span id="cb16-123">#&gt;  baselinedbp |    .980327   .0453156    21.63   0.000       .89096    1.069694</span>
<span id="cb16-124">#&gt;              |   .0026919   .0011629     0.57   0.000     .0038643    .0032359</span>
<span id="cb16-125">#&gt;              |</span>
<span id="cb16-126">#&gt;          age |   .3297468   .0088947    37.07   0.000      .312222    .3472716</span>
<span id="cb16-127">#&gt;              |   .0004879   .0002219     0.92   0.000     .0006042    .0007118</span>
<span id="cb16-128">#&gt;              |</span>
<span id="cb16-129">#&gt;            z |  -1.062159   1.509542    -0.70   0.483    -4.041587    1.917269</span>
<span id="cb16-130">#&gt;              |   .0945004   .0410673     0.07   0.041     .1227202    .1282877</span>
<span id="cb16-131">#&gt;              |</span>
<span id="cb16-132">#&gt;           r1 |   -.018845   .0725934    -0.26   0.795    -.1621706    .1244805</span>
<span id="cb16-133">#&gt;              |   .0046239   .0026182     0.06   0.049     .0075822    .0063906</span>
<span id="cb16-134">#&gt;              |</span>
<span id="cb16-135">#&gt;           r2 |  -.1529839   .1325282    -1.15   0.250    -.4145243    .1085565</span>
<span id="cb16-136">#&gt;              |   .0082342   .0037686     0.07   0.027     .0120192    .0102984</span>
<span id="cb16-137">#&gt;              |</span>
<span id="cb16-138">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |    11.6797   5.307458     2.20   0.029     1.213107     22.1463</span>
<span id="cb16-139">#&gt;              |   .3147167   .1363694     0.07   0.005     .3681237    .4611054</span>
<span id="cb16-140">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb16-141">#&gt; Note: Values displayed beneath <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span> are Monte Carlo <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">error</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span>.</span></code></pre></div></div>
</div>
<hr>
</section>
<section id="the-primary-analysis" class="level3">
<h3 class="anchored" data-anchor-id="the-primary-analysis">The Primary Analysis</h3>
<hr>
<p>For the primary analysis, I will use the predictive-mean matching method and specify 5 donors (based on a number of simulation studies that have examined the effect of various donors specified)<span class="citation" data-cites="schenkerPartiallyParametricTechniques1996"><sup>22</sup></span>, and fit a robust regression that includes all the variables within the dataset. Our imputation model will be</p>
<hr>
<p><img src="https://latex.codecogs.com/png.latex?Y%5E%7B%5Coperatorname%7BPost%7D%7D%20=%20%5Cbeta_%7B0%7D%20+%20%5Cbeta_%7B1%7D%5E%7B%5Coperatorname%7BGroup%7D%7D%20+%20%5Cbeta_%7B2%7D%5E%7B%5Coperatorname%7BBase%7D%7D%20+%20%5Cbeta_%7B3%7D%5E%7B%5Coperatorname%7BAge%7D%7D%20+%20%5Cbeta_%7B4%7D%5E%7B%5Coperatorname%7BZ%7D%7D%20+%20%5Cbeta_%7B5%7D%5E%7B%5Coperatorname%7BR1%7D%7D%20+%20%5Cbeta_%7B6%7D%5E%7B%5Coperatorname%7BR2%7D%7D%20+%20%5Cepsilon"></p>
<hr>
<p>So we will now impute our datasets.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;"># Impute Missing Data</span></span>
<span id="cb17-2"></span>
<span id="cb17-3">form <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;">list</span>(PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2)</span>
<span id="cb17-4">pred <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;">make.predictorMatrix</span>(BP_miss)</span>
<span id="cb17-5"></span>
<span id="cb17-6">imp1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mice<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;">mice</span>(</span>
<span id="cb17-7">  BP_miss,</span>
<span id="cb17-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pmm"</span>,</span>
<span id="cb17-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">predictorMatrix =</span> pred,</span>
<span id="cb17-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">120</span>,</span>
<span id="cb17-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxit =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb17-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>,</span>
<span id="cb17-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formulas =</span> form,</span>
<span id="cb17-14">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ridge =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb17-15">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">donors =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb17-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remove.collinear =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb17-17">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remove.constant =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">allow.na =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb17-18">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">printFlag =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">visitSequence =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"monotone"</span></span>
<span id="cb17-19">)</span>
<span id="cb17-20"></span>
<span id="cb17-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(imp1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>loggedEvents, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb17-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; NULL</span></span></code></pre></div></div>
</div>
<hr>
<p>Now that we have imputed our datasets, we may examine them for any issues before moving onto the next step of analyzing it.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-39-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-39-2.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>Our imputed datasets seem to look fine so far. We now fit our models to each of these datasets and combine them using Rubin’s rules.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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;"># Primary Analysis</span></span>
<span id="cb18-2"></span>
<span id="cb18-3">analysis1 <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;">with</span>(imp1, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rlm</span>(</span>
<span id="cb18-4">  PostDBP <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;">+</span></span>
<span id="cb18-5">    BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2,</span>
<span id="cb18-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MM"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">psi =</span> psi.huber</span>
<span id="cb18-7">))</span>
<span id="cb18-8">analysis2 <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;">with</span>(imp1, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rlm</span>(PostDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> (Group),</span>
<span id="cb18-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MM"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">psi =</span> psi.huber</span>
<span id="cb18-10">))</span>
<span id="cb18-11"></span>
<span id="cb18-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">anova</span>(analysis1, analysis2,</span>
<span id="cb18-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D3"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"LR"</span></span>
<span id="cb18-14">)</span>
<span id="cb18-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    test statistic df1 df2 dfcom p.value riv</span></span>
<span id="cb18-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  1 ~~ 2         0   5 600    NA       1 217</span></span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1">result1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mice<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;">pool</span>(analysis1)</span>
<span id="cb19-2"></span>
<span id="cb19-3">results1_sum <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;">summary</span>(result1)</span>
<span id="cb19-4"></span>
<span id="cb19-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(results1_sum) <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>
<span id="cb19-6">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Term"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SE"</span>,</span>
<span id="cb19-7">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Statistic"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"df"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P-val"</span></span>
<span id="cb19-8">)</span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Term</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Estimate</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">SE</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Statistic</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">df</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">P-val</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">(Intercept)</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">11.25</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">5.29</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.13</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">GroupDrug Y</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.51</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.13</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-75.89</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.98</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.05</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">21.82</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Age</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.33</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">34.81</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Z</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-1.33</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.41</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.94</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.07</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.32</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.14</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.13</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-1.09</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<p>While we have our primary analysis estimates, we also continue to examine our imputations for any anomalies.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-43-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>We’ve done our primary analysis, in which we imputed the missing data under the assumption of <strong>MAR</strong>, which is often a reasonable assumption to start with. Unfortunately, we cannot verify whether or not this assumption is true, but we can vary this missing data assumption and assume that the data are missing not at random (<strong>MNAR</strong>) <img src="https://latex.codecogs.com/png.latex?%5Coperatorname%7BPr%7D%5Cleft(R=0%20%5Cmid%20Y_%7B%5Cmathrm%7Bobs%7D%7D,%20Y_%7B%5Cmathrm%7Bmis%7D%7D,%20%5Cpsi%5Cright)">, and that in the individuals with missing data, we can assume different numbers than those with complete data. Our likelihood-ratio test also suggests that there’s very little difference between the full model and the reduced model, so we generally will go with the full model.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="grViz html-widget html-fill-item" id="htmlwidget-427372e5bd567451d12b" style="width:100%;height:480px;"></div>
<script type="application/json" data-for="htmlwidget-427372e5bd567451d12b">{"x":{"diagram":"digraph {\n  graph [layout = dot, rankdir = TB,\n         compound = true, bgcolor = \"transparent\",\n         nodesep = .5, ranksep = .25]\n  node [shape = circle,\n      fixedsize = true,\n      fontsize = 9,\n      fontname = Helvetica,\n      fontcolor = \"#000000\",\n      width = .99,\n      height = .99,\n      style = filled,\n      color = \"#91A3B0\",\n      label = \"\"]\n  edge [color = \"#999\", arrowhead = normal, arrowtail = inv]\n  rec1 [label = \"Study \nObjective\", fillcolor = \"#D0EAEE\"]\n  rec2 [label = \"Estimand\", fillcolor = \"#abd9ca\"]\n  rec3 [label =  \"Primary \nEstimator\", fillcolor = \"#7aa864\"]\n  rec4 [label = \"Primary \nEstimate\", fillcolor = \"#7aa864\"]\n\n  # edge definitions with the node IDs\n  rec1 -> rec2\n  rec2 -> rec3 ->rec4}","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<hr>
</section>
<section id="sa-i-controlled-imputations" class="level3">
<h3 class="anchored" data-anchor-id="sa-i-controlled-imputations">SA I: Controlled Imputations</h3>
<hr>
<p>Now suppose we wish to handle these missing data under the assumption of <strong>MNAR</strong>, we would now be conducting a sensitivity analysis because we are still targeting the same estimand, but only varying the assumptions. The question / target remain the same. To handle missing data that we assume are <strong>MNAR</strong>, there are a number of different and complex approaches.</p>
<p>We start off with the <img src="https://latex.codecogs.com/png.latex?%5Cdelta">-adjustment, controlled multiple imputation method,<span class="citation" data-cites="permuttSensitivityAnalysisMissing2016"><sup>23</sup></span> in which we assume that the group with missing observations differs systematically from the group with complete observations by a certain quantity. We produce a range of these quantities and add or subtract them from the imputed values and then conduct our analysis on this adjusted, imputed dataset. Here I will make the assumption that the average <code>PostDBP</code> estimate from the missing value group differs from at least 0 mmHg to at most 20 mmHg from the group with no missing observations.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Controlled MI</span></span>
<span id="cb20-2"></span>
<span id="cb20-3">ini <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;">mice</span>(BP_miss,</span>
<span id="cb20-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pmm"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxit =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb20-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">predictorMatrix =</span> pred</span>
<span id="cb20-6">)</span>
<span id="cb20-7"></span>
<span id="cb20-8">ini<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>method[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BaselineDBP"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span></span>
<span id="cb20-9">ini<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>method[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PostDBP"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pmm"</span></span>
<span id="cb20-10">ini<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>method[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span></span>
<span id="cb20-11">ini<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>method[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R1"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span></span>
<span id="cb20-12">ini<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>method[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Group"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span></span>
<span id="cb20-13">ini<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>method[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R2"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span></span>
<span id="cb20-14">ini<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>method[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span></span>
<span id="cb20-15">meth <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> ini<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>method</span>
<span id="cb20-16"></span>
<span id="cb20-17">delta <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;">seq</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;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb20-18"></span>
<span id="cb20-19">imp.all <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;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"list"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(delta))</span>
<span id="cb20-20">post <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> ini<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>post</span>
<span id="cb20-21"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(delta)) {</span>
<span id="cb20-22">  d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> delta[i]</span>
<span id="cb20-23">  cmd <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;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"imp[[j]][, i] &lt;- imp[[j]][, i] +"</span>, d)</span>
<span id="cb20-24">  post[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PostDBP"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cmd</span>
<span id="cb20-25">  imp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mice<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;">mice</span>(</span>
<span id="cb20-26">    BP_miss,</span>
<span id="cb20-27">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> meth,</span>
<span id="cb20-28">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">predictorMatrix =</span> pred,</span>
<span id="cb20-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb20-30">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxit =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb20-31">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">donors =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb20-32">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ridge =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb20-33">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formulas =</span> form,</span>
<span id="cb20-34">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remove.collinear =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb20-35">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remove.constant =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb20-36">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">allow.na =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">post =</span> post,</span>
<span id="cb20-37">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">printFlag =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb20-38">  )</span>
<span id="cb20-39">  imp.all[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> imp</span>
<span id="cb20-40">}</span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(delta)) {</span>
<span id="cb21-2">  imp.all[[i]][[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>]][[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Group"</span>]] <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.factor</span>(imp.all[[i]][[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>]][[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Group"</span>]])</span>
<span id="cb21-3">}</span></code></pre></div></div>
</div>
<p>Now that we have our imputed datasets that are modified by <img src="https://latex.codecogs.com/png.latex?%5Cdelta">-adjustments, we can fit our models to each imputed dataset and combine the estimates using Rubin’s rules.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Sensitivity Analysis 1</span></span>
<span id="cb22-2"></span>
<span id="cb22-3">output <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;">sapply</span>(imp.all,</span>
<span id="cb22-4">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) {</span>
<span id="cb22-5">    mice<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;">pool</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">with</span>(</span>
<span id="cb22-6">      x,</span>
<span id="cb22-7">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rlm</span>(</span>
<span id="cb22-8">        PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-9">          BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2,</span>
<span id="cb22-10">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MM"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">psi =</span> psi.huber</span>
<span id="cb22-11">      )</span>
<span id="cb22-12">    ))</span>
<span id="cb22-13">  },</span>
<span id="cb22-14">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simplify =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"array"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">USE.NAMES =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb22-15">)</span>
<span id="cb22-16"></span>
<span id="cb22-17">a <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.data.frame</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(output)))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pooled</span>
<span id="cb22-18">r <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;">array</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(delta) <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;">7</span>),</span>
<span id="cb22-19">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dim =</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;">length</span>(delta), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>),</span>
<span id="cb22-20">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dimnames =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb22-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(delta),</span>
<span id="cb22-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb22-23">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Intercept"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Group"</span>,</span>
<span id="cb22-24">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BaselineDBP"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age"</span>,</span>
<span id="cb22-25">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R2"</span></span>
<span id="cb22-26">    )</span>
<span id="cb22-27">  )</span>
<span id="cb22-28">)</span>
<span id="cb22-29"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(delta)) {</span>
<span id="cb22-30">  r[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;">cbind</span>(a[[i]][[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"estimate"</span>]])</span>
<span id="cb22-31">}</span>
<span id="cb22-32"></span>
<span id="cb22-33">r <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.data.frame</span>(r)</span>
<span id="cb22-34">r <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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Delta =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row.names</span>(r), r, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)</span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Delta</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Intercept</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Group</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Age</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Z</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R1</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R2</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-20</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-112.03</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-11.90</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.99</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.30</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-3.18</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.09</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-1.19</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-15</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-49.65</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-10.64</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.46</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.31</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-2.10</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.06</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.60</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-10</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-25.15</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-10.18</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.26</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.32</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-1.17</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.06</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.41</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-5</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-2.75</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.80</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.09</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.32</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.93</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.25</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">13.07</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.54</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.97</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.33</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.59</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.13</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">5</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">32.79</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.18</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.82</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.33</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.07</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.04</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">10</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">51.86</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-8.84</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.67</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.33</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.18</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.09</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.05</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">15</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">80.67</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-8.37</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.44</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.34</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.75</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.11</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.18</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">20</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">138.66</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-7.17</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.05</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.35</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.19</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.78</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<p>The table above gives the various <img src="https://latex.codecogs.com/png.latex?%5Cdelta">’s (the first column with values ranging from -30 - 30 in increments of 5) that were added to the multiply imputed datasets, and the corresponding estimates from the models fit to those datasets. So now we’ve conducted our first sensitivity analysis using the <img src="https://latex.codecogs.com/png.latex?%5Cdelta">-adjustment, controlled multiple imputation method. This form of sensitivity analysis is also typically what is used and preferred by regulators.<span class="citation" data-cites="permuttSensitivityAnalysisMissing2016"><sup>23</sup></span></p>
<hr>
<blockquote class="blockquote">
<p>Regulators prefer simple methods that impute the missing outcomes under MAR, and then add an adjustment δ to the imputes, while varying δ over a plausible range and independently for each treatment group (Permutt 2016).</p>
<p>The most interesting scenarios will be those where the difference between the δ’s correspond to the size of the treatment effect in the completers. Contours of the p-values may be plotted on a graph as a function of the δ’s to assist in a tipping-point analysis (Liublinska and Rubin 2014).</p>
</blockquote>
<hr>
<p>And as expected, lower <img src="https://latex.codecogs.com/png.latex?%5Cdelta"> values gave us results that were consistent with the primary analysis, while the upper end of the extreme <img src="https://latex.codecogs.com/png.latex?%5Cdelta"> values gave us estimates that were substantially off the mark.</p>
<hr>
<p>Next, we quickly examine the state of a random sample of these imputations to make sure they’re reliable.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-49-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>Now we move onto our next and final sensitivity analysis.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="grViz html-widget html-fill-item" id="htmlwidget-b73b795bdd6d7777caac" style="width:100%;height:480px;"></div>
<script type="application/json" data-for="htmlwidget-b73b795bdd6d7777caac">{"x":{"diagram":"digraph {\n  graph [layout = dot, rankdir = TB,\n         compound = true,bgcolor = \"transparent\",\n         nodesep = .5, ranksep = .25]\n  node [shape = circle,\n      fixedsize = true,\n      fontsize = 9,\n      fontname = Helvetica,\n      fontcolor = \"#000000\",\n      width = .99,\n      height = .99,\n      style = filled,\n      color = \"#91A3B0\",\n      label = \"\"]\n  edge [color = black, arrowhead = normal, arrowtail = inv]\n  rec1 [label = \"Study \nObjective\", fillcolor = \"#D0EAEE\"]\n  rec2 [label = \"Estimand\", fillcolor = \"#abd9ca\"]\n  rec3 [label =  \"Sensitivity \nEstimator \n1\", fillcolor = \"#E69F00\"]\n  rec4 [label = \"Sensitivity \nEstimate \n1\", fillcolor = \"#E69F00\"]\n\n  # edge definitions with the node IDs\n  rec1 -> rec2\n  rec2 -> rec3 ->rec4}","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<hr>
</section>
<section id="sa-ii-selection-models" class="level3">
<h3 class="anchored" data-anchor-id="sa-ii-selection-models">SA II: Selection Models</h3>
<hr>
<p>To further explore the <strong>MNAR</strong> assumption, we could also use a Heckman selection model <img src="https://latex.codecogs.com/png.latex?P(Y,R)=P(Y)P(R%7CY)">, as described by van Buuren here<span class="citation" data-cites="buurenFlexibleImputationMissing2018"><sup>20</sup></span></p>
<hr>
<blockquote class="blockquote">
<p>The selection model multiplies the marginal distribution <img src="https://latex.codecogs.com/png.latex?P(Y)"> in the population with the response weights <img src="https://latex.codecogs.com/png.latex?P(R%7CY)">. Both <img src="https://latex.codecogs.com/png.latex?P(Y)"> and <img src="https://latex.codecogs.com/png.latex?P(R%7CY)"> are unknown, and must be specified by the user. The model where <img src="https://latex.codecogs.com/png.latex?P(Y)"> is normal and where <img src="https://latex.codecogs.com/png.latex?P(R%7CY)"> is a probit model is known as the Heckman model. This model is widely used in economics to correct for selection bias.</p>
</blockquote>
<hr>
<p>We can implement this in <code>R</code> using the <a href="https://cran.r-project.org/package=miceMNAR"><code>miceMNAR</code></a> package, which is an extension to the <a href="https://cran.r-project.org/package=mice"><code>mice</code></a> <code>R</code> package.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Selection Models</span></span>
<span id="cb23-2">has_miceMNAR <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;">requireNamespace</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"miceMNAR"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quietly =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb23-3">has_mnar_api <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;">FALSE</span></span>
<span id="cb23-4"></span>
<span id="cb23-5"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (has_miceMNAR) {</span>
<span id="cb23-6">  miceMNAR_exports <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;">getNamespaceExports</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"miceMNAR"</span>)</span>
<span id="cb23-7">  has_mnar_api <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;">all</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;">"generate_JointModelEq"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MNARargument"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> miceMNAR_exports)</span>
<span id="cb23-8">}</span>
<span id="cb23-9"></span>
<span id="cb23-10"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>has_mnar_api) {</span>
<span id="cb23-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">message</span>(</span>
<span id="cb23-12">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Skipping SA II (selection model): 'miceMNAR' with generate_JointModelEq/MNARargument is unavailable in this environment."</span></span>
<span id="cb23-13">  )</span>
<span id="cb23-14">  imp2 <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>
<span id="cb23-15">} <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb23-16">  JointModelEq <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> miceMNAR<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;">generate_JointModelEq</span>(</span>
<span id="cb23-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> BP_miss,</span>
<span id="cb23-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">varMNAR =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PostDBP"</span></span>
<span id="cb23-19">  )</span>
<span id="cb23-20"></span>
<span id="cb23-21">  JointModelEq[, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PostDBP_var_sel"</span>] <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;">0</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;">1</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;">1</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;">1</span>)</span>
<span id="cb23-22">  JointModelEq[, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PostDBP_var_out"</span>] <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;">0</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;">1</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;">0</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;">1</span>)</span>
<span id="cb23-23"></span>
<span id="cb23-24">  arg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> miceMNAR<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;">MNARargument</span>(</span>
<span id="cb23-25">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> BP_miss,</span>
<span id="cb23-26">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">varMNAR =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"PostDBP"</span>,</span>
<span id="cb23-27">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">JointModelEq =</span> JointModelEq</span>
<span id="cb23-28">  )</span>
<span id="cb23-29"></span>
<span id="cb23-30">  imp2 <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;">mice</span>(</span>
<span id="cb23-31">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> arg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>data_mod,</span>
<span id="cb23-32">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pmm"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>,</span>
<span id="cb23-33">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">predictorMatrix =</span> arg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>predictorMatrix,</span>
<span id="cb23-34">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">JointModelEq =</span> arg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>JointModelEq,</span>
<span id="cb23-35">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">control =</span> arg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>control,</span>
<span id="cb23-36">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remove.collinear =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb23-37">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remove.constant =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">allow.na =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb23-38">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">printFlag =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">visitSequence =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"monotone"</span></span>
<span id="cb23-39">  )</span>
<span id="cb23-40"></span>
<span id="cb23-41">  imp2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Group <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.factor</span>(imp2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Group)</span>
<span id="cb23-42">}</span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-52-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>Now we fit our models to these new datasets and pool them using Rubin’s rules.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Sensitivity Analysis 2</span></span>
<span id="cb24-2"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(imp2)) {</span>
<span id="cb24-3">  analysis3 <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>
<span id="cb24-4">  result3 <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>
<span id="cb24-5">  results3_sum <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="cb24-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Term =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">character</span>(),</span>
<span id="cb24-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Estimate =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(),</span>
<span id="cb24-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(),</span>
<span id="cb24-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Statistic =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(),</span>
<span id="cb24-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(),</span>
<span id="cb24-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;">P-val</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>()</span>
<span id="cb24-12">  )</span>
<span id="cb24-13">} <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb24-14">  analysis3 <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;">with</span>(imp2, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rlm</span>(</span>
<span id="cb24-15">    PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb24-16">      BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2,</span>
<span id="cb24-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MM"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">psi =</span> psi.huber</span>
<span id="cb24-18">  ))</span>
<span id="cb24-19">  result3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mice<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;">pool</span>(analysis3)</span>
<span id="cb24-20"></span>
<span id="cb24-21">  results3_sum <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;">summary</span>(result3)</span>
<span id="cb24-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(results3_sum) <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>
<span id="cb24-23">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Term"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SE"</span>,</span>
<span id="cb24-24">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Statistic"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"df"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P-val"</span></span>
<span id="cb24-25">  )</span>
<span id="cb24-26">}</span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Term</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Estimate</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">SE</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Statistic</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">df</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">P-val</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">(Intercept)</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">10.12</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">6.14</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.65</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">factor(Group)Drug Y</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.50</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.20</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-47.69</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.99</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.06</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">18.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Age</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.33</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">27.99</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Z</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-1.09</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.85</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.59</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.08</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.30</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.15</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.16</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.96</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<p>Now we examine our imputed values.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-55-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>so now we have completed our second sensitivity analysis.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="grViz html-widget html-fill-item" id="htmlwidget-ee11049c1234a332d58a" style="width:100%;height:480px;"></div>
<script type="application/json" data-for="htmlwidget-ee11049c1234a332d58a">{"x":{"diagram":"digraph {\n  graph [layout = dot, rankdir = TB,\n         compound = true, bgcolor = \"transparent\",\n         nodesep = .5, ranksep = .25]\n  node [shape = circle,\n      fixedsize = true,\n      fontsize = 9,\n      fontname = Helvetica,\n      fontcolor = \"#000000\",\n      width = .99,\n      height = .99,\n      style = filled,\n      color = \"#91A3B0\",\n      label = \"\"]\n  edge [color = \"#999\", arrowhead = normal, arrowtail = inv]\n  rec1 [label = \"Study \nObjective\", fillcolor = \"#D0EAEE\"]\n  rec2 [label = \"Estimand\", fillcolor = \"#abd9ca\"]\n  rec3 [label =  \"Sensitivity \nEstimator \n2\", fillcolor = \"#e7998c\"]\n  rec4 [label = \"Sensitivity \nEstimate \n2\", fillcolor = \"#e7998c\"]\n\n  # edge definitions with the node IDs\n  rec1 -> rec2\n  rec2 -> rec3 ->rec4}","config":{"engine":"dot","options":null}},"evals":[],"jsHooks":[]}</script>
</div>
</div>
<hr>
<p>The results from both the primary analysis, the first sensitivity analysis, and the second seem somewhat consistent. However, with the first sensitivity analysis where we applied <img src="https://latex.codecogs.com/png.latex?%5Cdelta">-adjustments, as the adjustments became larger, the coefficients changed drastically. However, such large <img src="https://latex.codecogs.com/png.latex?%5Cdelta">-adjustments are not realistic and those that were smaller led to coefficients that were closer to the other two analyses.</p>
<hr>
</section>
<section id="supplementary-analyses" class="level3">
<h3 class="anchored" data-anchor-id="supplementary-analyses">Supplementary Analyses</h3>
<hr>
<p>The following analyses are what I mostly consider to be supplementary analyses that may further investigate some violations of assumptions but often go far beyond what would be necessary for a principled sensitivity analysis that would typically accompany a primary analysis.</p>
<hr>
<p>First, I like to check that the results from my analyses are consistent across different statistical software So I may check to see that the results from my primary analysis from <code>R</code> are also similar to the results from another statistical software suite like <code>Stata</code>.</p>
<p>So in <code>Stata</code>, I would likely run something similar to the following in order to mimic the primary analysis in <code>R</code>.</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb25-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">linesize</span> 255</span>
<span id="cb25-2"></span>
<span id="cb25-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">all</span></span>
<span id="cb25-4"></span>
<span id="cb25-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">seed</span> 1031</span>
<span id="cb25-6"></span>
<span id="cb25-7">import delimited <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"static/datasets/temp.csv"</span>, numericcols(2 3 5 6 7 8)</span>
<span id="cb25-8"></span>
<span id="cb25-9"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">summarize</span></span>
<span id="cb25-10"></span>
<span id="cb25-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mi</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span> mlong</span>
<span id="cb25-12"></span>
<span id="cb25-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mi</span> register imputed baselinedbp postdbp age z <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> r1 r2</span>
<span id="cb25-14"></span>
<span id="cb25-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mi</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">impute</span> chained (pmm, knn(5)) postdbp = baselinedbp age z r1 r2 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span>, burnin(20) add(100) rseed (1031) savetrace(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">static</span>/datasets/trace1, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span>) nomonotone</span>
<span id="cb25-16"></span>
<span id="cb25-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mi</span> estimate, mcerror: <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">rreg</span> postdbp i.<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> baselinedbp age z r1 r2</span>
<span id="cb25-18"></span>
<span id="cb25-19"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">quietly</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mi</span> passive: <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">generate</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">byte</span> imputed = _mi_miss</span>
<span id="cb25-20">#&gt; file ()<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">print</span>() <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> found</span>
<span id="cb25-21">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(601);</span>
<span id="cb25-22">#&gt; </span>
<span id="cb25-23">#&gt; </span>
<span id="cb25-24">#&gt; </span>
<span id="cb25-25">#&gt; </span>
<span id="cb25-26">#&gt; </span>
<span id="cb25-27">#&gt; (encoding automatically selected: ISO-8859-2)</span>
<span id="cb25-28">#&gt; (7 vars, 500 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span>)</span>
<span id="cb25-29">#&gt; </span>
<span id="cb25-30">#&gt; </span>
<span id="cb25-31">#&gt;     Variable |        Obs        Mean    Std. <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">dev</span>.       Min        Max</span>
<span id="cb25-32">#&gt; -------------+---------------------------------------------------------</span>
<span id="cb25-33">#&gt;      postdbp |        255    138.3033    5.413468   123.8279   150.0574</span>
<span id="cb25-34">#&gt;  baselinedbp |        500    116.8569    1.997616   109.8634   123.0737</span>
<span id="cb25-35">#&gt;        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> |        500        .484    .5002444          0          1</span>
<span id="cb25-36">#&gt;          age |        500    49.73008    6.938333   27.65241    68.4464</span>
<span id="cb25-37">#&gt;            z |        500    2.78e-13    .0626851  -.1845036   .2024892</span>
<span id="cb25-38">#&gt; -------------+---------------------------------------------------------</span>
<span id="cb25-39">#&gt;           r1 |        500   -.0428001    .9472443  -3.205036   3.377526</span>
<span id="cb25-40">#&gt;           r2 |        500    .9620217    .5061543  -.6455948   2.480457</span>
<span id="cb25-41">#&gt; </span>
<span id="cb25-42">#&gt; </span>
<span id="cb25-43">#&gt; (245 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>=0 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span> now marked <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> incomplete)</span>
<span id="cb25-44">#&gt; </span>
<span id="cb25-45">#&gt; <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">note</span>: <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">missing</span>-<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">value</span> pattern is monotone.</span>
<span id="cb25-46">#&gt; </span>
<span id="cb25-47">#&gt; Conditional models:</span>
<span id="cb25-48">#&gt;            postdbp: pmm postdbp baselinedbp age z r1 r2 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> , knn(5)</span>
<span id="cb25-49">#&gt; </span>
<span id="cb25-50">#&gt; Performing chained iterations ...</span>
<span id="cb25-51">#&gt; </span>
<span id="cb25-52">#&gt; Multivariate imputation                     Imputations =      100</span>
<span id="cb25-53">#&gt; Chained equations                                 added =      100</span>
<span id="cb25-54">#&gt; Imputed: <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>=1 through <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>=100                      updated =        0</span>
<span id="cb25-55">#&gt; </span>
<span id="cb25-56">#&gt; Initialization: monotone                     Iterations =     2000</span>
<span id="cb25-57">#&gt;                                                 burn-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> =       20</span>
<span id="cb25-58">#&gt; </span>
<span id="cb25-59">#&gt;            postdbp: predictive <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">mean</span> matching</span>
<span id="cb25-60">#&gt; </span>
<span id="cb25-61">#&gt; ------------------------------------------------------------------</span>
<span id="cb25-62">#&gt;                    |               Observations per <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>             </span>
<span id="cb25-63">#&gt;                    |----------------------------------------------</span>
<span id="cb25-64">#&gt;           Variable |   Complete   Incomplete   Imputed |     Total</span>
<span id="cb25-65">#&gt; -------------------+-----------------------------------+----------</span>
<span id="cb25-66">#&gt;            postdbp |        255          245       245 |       500</span>
<span id="cb25-67">#&gt; ------------------------------------------------------------------</span>
<span id="cb25-68">#&gt; (Complete + Incomplete = Total; Imputed is the minimum across <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span></span>
<span id="cb25-69">#&gt;  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> the number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> filled-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> observations.)</span>
<span id="cb25-70">#&gt; </span>
<span id="cb25-71">#&gt; </span>
<span id="cb25-72">#&gt; Multiple-imputation <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span>                   Imputations       =        100</span>
<span id="cb25-73">#&gt; Robust regression                               Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span>     =        500</span>
<span id="cb25-74">#&gt;                                                 Average RVI       =     0.7136</span>
<span id="cb25-75">#&gt;                                                 Largest FMI       =     0.5035</span>
<span id="cb25-76">#&gt;                                                 Complete DF       =        493</span>
<span id="cb25-77">#&gt; DF adjustment:   Small <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">sample</span>                   DF:     <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>       =     151.95</span>
<span id="cb25-78">#&gt;                                                         avg       =     188.67</span>
<span id="cb25-79">#&gt;                                                         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>       =     233.67</span>
<span id="cb25-80">#&gt; Model <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">F</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">test</span>:       Equal FMI                   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">F</span>(   6,  421.4)   =    1181.06</span>
<span id="cb25-81">#&gt;                                                 Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">F</span>          =     0.0000</span>
<span id="cb25-82">#&gt; </span>
<span id="cb25-83">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb25-84">#&gt;      postdbp | Coefficient  Std. err.      t    P&gt;|t|     [95% conf. interval]</span>
<span id="cb25-85">#&gt; -------------+----------------------------------------------------------------</span>
<span id="cb25-86">#&gt;      1.<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> |  -9.520968   .1207769   -78.83   0.000    -9.758918   -9.283017</span>
<span id="cb25-87">#&gt;              |   .0070306   .0035352     2.31   0.000     .0118962    .0076126</span>
<span id="cb25-88">#&gt;              |</span>
<span id="cb25-89">#&gt;  baselinedbp |   .9811365   .0448784    21.86   0.000     .8926164    1.069657</span>
<span id="cb25-90">#&gt;              |   .0028784   .0010755     0.54   0.000     .0037961    .0033965</span>
<span id="cb25-91">#&gt;              |</span>
<span id="cb25-92">#&gt;          age |    .328745   .0089894    36.57   0.000     .3110251    .3464649</span>
<span id="cb25-93">#&gt;              |   .0005493   .0002679     1.12   0.000      .000839    .0006919</span>
<span id="cb25-94">#&gt;              |</span>
<span id="cb25-95">#&gt;            z |  -1.017329   1.500306    -0.68   0.499    -3.979496    1.944838</span>
<span id="cb25-96">#&gt;              |   .1020678    .050788     0.06   0.041     .1658641    .1196211</span>
<span id="cb25-97">#&gt;              |</span>
<span id="cb25-98">#&gt;           r1 |  -.0169674   .0731975    -0.23   0.817    -.1615836    .1276488</span>
<span id="cb25-99">#&gt;              |   .0051452   .0023361     0.07   0.056     .0063651    .0075475</span>
<span id="cb25-100">#&gt;              |</span>
<span id="cb25-101">#&gt;           r2 |  -.1393538   .1309672    -1.06   0.289    -.3978634    .1191559</span>
<span id="cb25-102">#&gt;              |   .0087814   .0046722     0.07   0.032     .0138722    .0117957</span>
<span id="cb25-103">#&gt;              |</span>
<span id="cb25-104">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |   11.61969   5.244316     2.22   0.028     1.276334    21.96305</span>
<span id="cb25-105">#&gt;              |   .3346446   .1264252     0.08   0.005     .3897239    .4489929</span>
<span id="cb25-106">#&gt; ------------------------------------------------------------------------------</span>
<span id="cb25-107">#&gt; Note: Values displayed beneath <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span> are Monte Carlo <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">error</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">estimates</span>.</span></code></pre></div></div>
</div>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<pre><code>#&gt; file ()print() not found
#&gt; r(601);
#&gt; 
#&gt; 
#&gt; 
#&gt; (Summaries of imputed values from -mi impute chained-)
#&gt; 
#&gt; 
#&gt; Contains data from static/datasets/trace1.dta
#&gt;  Observations:         2,100                  Summaries of imputed values from -mi impute chained-
#&gt;     Variables:             4                  16 Sep 2026 12:35
#&gt; ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#&gt; Variable      Storage   Display    Value
#&gt;     name         type    format    label      Variable label
#&gt; ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#&gt; iter            byte    %12.0g                Iteration numbers
#&gt; m               byte    %12.0g                Imputation numbers
#&gt; postdbp_mean    float   %9.0g                 Mean of postdbp
#&gt; postdbp_sd      float   %9.0g                 Std. dev. of postdbp
#&gt; ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#&gt; Sorted by: 
#&gt; 
#&gt; 
#&gt; 
#&gt; reshaping m=0 data ...
#&gt; (j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 8
#&gt; &gt; 7 88 89 90 91 92 93 94 95 96 97 98 99 100)
#&gt; 
#&gt; Data                               Long   -&gt;   Wide
#&gt; -----------------------------------------------------------------------------
#&gt; Number of observations            2,100   -&gt;   21          
#&gt; Number of variables                   4   -&gt;   201         
#&gt; j variable (100 values)               m   -&gt;   (dropped)
#&gt; xij variables:
#&gt;                            postdbp_mean   -&gt;   postdbp_mean1 postdbp_mean2 ... postdbp_mean100
#&gt;                              postdbp_sd   -&gt;   postdbp_sd1 postdbp_sd2 ... postdbp_sd100
#&gt; -----------------------------------------------------------------------------
#&gt; 
#&gt; assembling results ...
#&gt; 
#&gt; 
#&gt; Time variable: iter, 0 to 20
#&gt;         Delta: 1 unit
#&gt; 
#&gt; 
#&gt; 
#&gt; file ()print() not found
#&gt; r(601);
#&gt; 
#&gt; r(601);</code></pre>
</div>
<hr>
<p>As you can see from above, I imported the missing data I generated in <code>R</code> into <code>Stata</code>, and then used it to multiply impute the datasets using the predictive mean matching method with 5 donors. I chose the exact same number of variables to include in the imputation model as I did with the primary and sensitivity analyses. Just like the primary analysis, I also used robust regression, <a href="https://www.stata.com/manuals/rrreg.pdf"><code>rreg</code></a> in <code>Stata</code>, to analyze the datasets. The numbers seem to be fairly consistent with those from the primary analysis and the some of the results from the sensitivity analyses.</p>
<p>I will now conduct another supplementary analysis, in which I fit a Bayesian regression model using a <em>t</em>-distribution so that it is analogous to the other robust regression models I have utilized so far, and I will specify a weakly informative prior. I will fit one model using the <code>brm_multiple()</code> function which will fit the model to each of the imputed datasets from before, while I fit another Bayesian model which will impute values during the model fitting process and compare the results.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Quantile Regression  --------------------------</span></span>
<span id="cb27-2"></span>
<span id="cb27-3">implist <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mitml<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;">mids2mitml.list</span>(imp1)</span>
<span id="cb27-4"></span>
<span id="cb27-5">vcov.rq <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>(object, ...) {</span>
<span id="cb27-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(object,</span>
<span id="cb27-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"nid"</span>,</span>
<span id="cb27-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">covariance =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb27-9">  )<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>cov</span>
<span id="cb27-10">}</span>
<span id="cb27-11"></span>
<span id="cb27-12">fit1 <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;">with</span>(implist, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rq</span>(PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-13">  Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tau =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>))</span>
<span id="cb27-14">mitml<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;">testEstimates</span>(fit1)</span>
<span id="cb27-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb27-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Call:</span></span>
<span id="cb27-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb27-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; mitml::testEstimates(model = fit1)</span></span>
<span id="cb27-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb27-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Final parameter estimates and inferences obtained from 120 imputed data sets.</span></span>
<span id="cb27-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb27-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                      Estimate Std.Error   t.value        df   P(&gt;|t|)       RIV       FMI </span></span>
<span id="cb27-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; (Intercept)            10.092     6.610     1.527   519.639     0.127     0.918     0.481 </span></span>
<span id="cb27-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; factor(Group)Drug Y    -9.433     0.157   -59.956   622.364     0.000     0.777     0.439 </span></span>
<span id="cb27-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; BaselineDBP             0.991     0.056    17.617   522.900     0.000     0.912     0.479 </span></span>
<span id="cb27-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Age                     0.336     0.011    31.319   690.038     0.000     0.710     0.417 </span></span>
<span id="cb27-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Z                      -1.397     1.755    -0.796   594.157     0.426     0.810     0.449 </span></span>
<span id="cb27-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; R1                     -0.054     0.091    -0.600   403.495     0.549     1.189     0.545 </span></span>
<span id="cb27-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; R2                     -0.137     0.160    -0.859   451.123     0.391     1.056     0.516 </span></span>
<span id="cb27-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb27-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Unadjusted hypothesis test as appropriate in larger samples.</span></span>
<span id="cb27-32"></span>
<span id="cb27-33"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">confint</span>(mitml<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;">testEstimates</span>(fit1))</span>
<span id="cb27-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                      2.5 % 97.5 %</span></span>
<span id="cb27-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; (Intercept)         -2.894 23.078</span></span>
<span id="cb27-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; factor(Group)Drug Y -9.742 -9.124</span></span>
<span id="cb27-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; BaselineDBP          0.880  1.101</span></span>
<span id="cb27-38"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Age                  0.315  0.357</span></span>
<span id="cb27-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Z                   -4.843  2.049</span></span>
<span id="cb27-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; R1                  -0.233  0.124</span></span>
<span id="cb27-41"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; R2                  -0.452  0.177</span></span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Bayesian Regression  --------------------------</span></span>
<span id="cb28-2"></span>
<span id="cb28-3">BP_miss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Group <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.factor</span>(BP_miss<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Group)</span>
<span id="cb28-4"></span>
<span id="cb28-5">brm_form2 <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;">bf</span>(</span>
<span id="cb28-6">  PostDBP <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;">mi</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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb28-7">    Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quantile =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.50</span></span>
<span id="cb28-8">)</span>
<span id="cb28-9"></span>
<span id="cb28-10">prior1 <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;">get_prior</span>(brm_form2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> BP_miss, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">knots =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb28-11">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">asym_laplace</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'identity'</span>))</span>
<span id="cb28-12"></span>
<span id="cb28-13">b_2 <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;">brm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> brm_form2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> BP_miss, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prior =</span> prior1,</span>
<span id="cb28-14">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">asym_laplace</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'identity'</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sample_prior =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'yes'</span>,</span>
<span id="cb28-15">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">control =</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;">max_treedepth =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">adapt_delta =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.80</span>),</span>
<span id="cb28-16">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh =</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;">backend =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rstan"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">chains =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb28-17">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">algorithm =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sampling"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">knots =</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;">future =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cores =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>L,</span>
<span id="cb28-18">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warmup =</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;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>)</span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># `post` is already the mice post-processing vector above, so use a distinct name</span></span>
<span id="cb29-2">bayes_post <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;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exists</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b_2"</span>)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(b_2) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb29-3"></span>
<span id="cb29-4"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(bayes_post)) {</span>
<span id="cb29-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bayesian model summary skipped: `b_2` was not fitted in this environment.</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb29-6">} <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb29-7">  bayes_post</span>
<span id="cb29-8">}</span>
<span id="cb29-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Bayesian model summary skipped: `b_2` was not fitted in this environment.</span></span></code></pre></div></div>
</div>
<hr>
<p>We can also compare the results we get from <code>brms</code>/<code>Stan</code> with <code>MCMCpack.</code></p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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">posterior_95 <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;">MCMCquantreg</span>(</span>
<span id="cb30-2">  PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb30-3">    Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2,</span>
<span id="cb30-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> BP_miss,</span>
<span id="cb30-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tau =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mcmc =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">chains =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb30-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">thin =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span></span>
<span id="cb30-7">)</span>
<span id="cb30-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(posterior_95)</span>
<span id="cb30-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb30-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Iterations = 1001:5991</span></span>
<span id="cb30-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Thinning interval = 10 </span></span>
<span id="cb30-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Number of chains = 1 </span></span>
<span id="cb30-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Sample size per chain = 500 </span></span>
<span id="cb30-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb30-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 1. Empirical mean and standard deviation for each variable,</span></span>
<span id="cb30-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    plus standard error of the mean:</span></span>
<span id="cb30-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb30-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                        Mean      SD Naive SE Time-series SE</span></span>
<span id="cb30-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; (Intercept)         10.2441 19.8021  0.88558        1.00205</span></span>
<span id="cb30-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; factor(Group)Drug Y -9.6451  0.4329  0.01936        0.02600</span></span>
<span id="cb30-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; BaselineDBP          1.0197  0.1688  0.00755        0.00855</span></span>
<span id="cb30-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Age                  0.3108  0.0324  0.00145        0.00156</span></span>
<span id="cb30-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Z                   -3.0856  5.6527  0.25279        0.27623</span></span>
<span id="cb30-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; R1                  -0.0277  0.2696  0.01206        0.01383</span></span>
<span id="cb30-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; R2                  -0.4040  0.3937  0.01761        0.01950</span></span>
<span id="cb30-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb30-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 2. Quantiles for each variable:</span></span>
<span id="cb30-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb30-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                        2.5%    25%     50%    75%  97.5%</span></span>
<span id="cb30-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; (Intercept)         -27.035 -2.560  9.2822 22.020 49.797</span></span>
<span id="cb30-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; factor(Group)Drug Y -10.572 -9.916 -9.6297 -9.350 -8.846</span></span>
<span id="cb30-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; BaselineDBP           0.679  0.918  1.0263  1.130  1.338</span></span>
<span id="cb30-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Age                   0.253  0.290  0.3094  0.332  0.375</span></span>
<span id="cb30-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Z                   -14.438 -6.933 -3.3466  1.069  7.636</span></span>
<span id="cb30-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; R1                   -0.550 -0.214 -0.0152  0.146  0.507</span></span>
<span id="cb30-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; R2                   -1.189 -0.646 -0.3728 -0.158  0.312</span></span></code></pre></div></div>
</div>
<hr>
<hr>
<p>Next, we examine the results from the Bayesian model in which values were imputed during model fitting.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">posterior_summary</span>(b_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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>]</span>
<span id="cb31-2">(post <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;">posterior_samples</span>(b_2))</span></code></pre></div></div>
</div>
<hr>
<p>They seem to be similar to the results we’ve been seeing so far.</p>
<hr>
<p>Indeed, it is no surprise that the Bayesian model with a weakly dispersed prior would give similar results to the base <a href="https://rdrr.io/pkg/MASS/man/rlm.html"><code>rlm()</code></a> function. We now look at robust methods and resampling and the results they give.</p>
<hr>
<p>Although this is currently under the supplementary analysis section, I would very much consider these next two analyses to be sensitivity analyses. The first method utilized here is known as the <em>random indicator method</em>, and it is an experimental method that essentially combines a selection model and a pattern-mixture model and is designed to handle data that are missing not at random. As van Buuren writes<span class="citation" data-cites="buurenFlexibleImputationMissing2018"><sup>20</sup></span></p>
<hr>
<blockquote class="blockquote">
<p>The random indicator method (Jolani 2012)<span class="citation" data-cites="jolaniDualImputationStrategies2012"><sup>24</sup></span> is an experimental iterative method that redraws the missing data indicator under a selection model, and imputes the missing data under a pattern-mixture model, with the objective of estimating δ from the data under relaxed assumptions. Initial simulation results look promising. The algorithm is available as the <code>ri</code> method in <a href="https://cran.r-project.org/web/packages/mice/index.html"><code>mice</code></a>.</p>
</blockquote>
<hr>
<p>The script below utilizes this method (random indicator), but bootstraps the missing dataset before the imputation procedure, and then after multiply imputing the datasets, obtains estimates using maximum likelihood multiple (<strong>MLMI</strong>) imputation, an alternative and more efficient method to the more popular posterior draw multiple imputation (<strong>PDMI</strong>). More about <strong>MLMI</strong> can be found here.<span class="citation" data-cites="vonhippelMaximumLikelihoodMultiple2019"><sup>25</sup></span></p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Bootstrap Inference</span></span>
<span id="cb32-2"></span>
<span id="cb32-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootMice</span>(BP_miss, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ri"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxit =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb32-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">predictorMatrix =</span> pred, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nBoot =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">96</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nImp =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb32-5">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formulas =</span> form, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nCores =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>L,</span>
<span id="cb32-6">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ridge =</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;">remove.collinear =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb32-7">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remove.constant =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">allow.na =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb32-8">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">printFlag =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">visitSequence =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"monotone"</span>) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-&gt;</span> imps</span>
<span id="cb32-9"></span>
<span id="cb32-10">analyseImp <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>(inputData) {</span>
<span id="cb32-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</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;">rlm</span>(PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2,</span>
<span id="cb32-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> inputData, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MM"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">psi =</span> psi.huber</span>
<span id="cb32-13">  )))</span>
<span id="cb32-14">}</span>
<span id="cb32-15"></span>
<span id="cb32-16">analyseImp1 <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>(inputData) {</span>
<span id="cb32-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</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;">glm</span>(PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2,</span>
<span id="cb32-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> inputData, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gaussian</span>()</span>
<span id="cb32-19">  )))</span>
<span id="cb32-20">}</span>
<span id="cb32-21"></span>
<span id="cb32-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;">bootImputeAnalyse</span>(imps, analyseImp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quiet =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb32-23">ests1 <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;">bootImputeAnalyse</span>(imps, analyseImp1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quiet =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb32-24"></span>
<span id="cb32-25">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;">as.data.frame</span>(ests)</span>
<span id="cb32-26"></span>
<span id="cb32-27"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(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;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Var"</span>,</span>
<span id="cb32-28">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CI.ll"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CI.ul"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"df"</span>)</span>
<span id="cb32-29"></span>
<span id="cb32-30"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rownames</span>(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;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Intercept"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Group"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BaselineDBP"</span>,</span>
<span id="cb32-31">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R2"</span>)</span>
<span id="cb32-32">ests1 <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.data.frame</span>(ests1)</span>
<span id="cb32-33"></span>
<span id="cb32-34"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(ests1) <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Var"</span>,</span>
<span id="cb32-35">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CI.ll"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CI.ul"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"df"</span>)</span>
<span id="cb32-36"></span>
<span id="cb32-37"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rownames</span>(ests1) <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Intercept"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Group"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BaselineDBP"</span>,</span>
<span id="cb32-38">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Age"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R2"</span>)</span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; color: rgba(119, 119, 119, 1) !important;"></th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Estimate</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Var</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">CI.ll</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">CI.ul</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">df</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Intercept</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">10.72</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">16.51</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.19</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">19.25</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">18.3</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Group</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.62</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.89</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.34</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">48.0</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.99</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.91</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.06</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">19.6</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Age</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.34</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.32</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.36</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">55.4</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Z</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.32</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-4.06</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.05</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">51.2</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">R1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.19</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.15</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">64.3</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">R2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.14</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.39</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.11</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">44.8</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; color: rgba(119, 119, 119, 1) !important;"></th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Estimate</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Var</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">CI.ll</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">CI.ul</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">df</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Intercept</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">10.37</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">16.67</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.84</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">18.89</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">19.7</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Group</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.63</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.89</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.36</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">47.5</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.99</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.92</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.06</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">20.7</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Age</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.33</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.31</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.35</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">57.3</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Z</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-1.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.21</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-4.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.96</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">50.1</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">R1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.18</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.15</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">62.6</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">R2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.15</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.39</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.09</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">43.3</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<p>For our second supplementary analysis, We will utilize the <code>GAMLSS</code> method, which is an extension of the generalized linear model and the generalized additive model. For the vast majority of the imputations we have conducted, we have drawn values from an assumed normal distribution. Thus, <code>GAMLSS</code> allows us to be far more flexible with our assumptions. However, it is also worth noting that general normal imputations are robust against violations of the assumption of normality</p>
<hr>
<blockquote class="blockquote">
<p>In general, normal imputations appear to be robust against violations of normality. Demirtas, Freels, and Yucel (2008) found that flatness of the density, heavy tails, non-zero peakedness, skewness and multimodality do not appear to hamper the good performance of multiple imputation for the mean structure in samples n &gt; 400, even for high percentages (75%) of missing data in one variable. The variance parameter is more critical though, and could be off-target in smaller samples.</p>
</blockquote>
<hr>
<p>Regardless, we will be using the <code>GAMLSS</code> method and also imputing from a <em>t</em>-distribution, which is much more robust to outliers.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1">gamt <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;">mice</span>(BP_miss, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gamlssTF"</span>,</span>
<span id="cb33-2">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">predictorMatrix =</span> pred,</span>
<span id="cb33-3">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m =</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;">maxit =</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;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>,</span>
<span id="cb33-4">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cores =</span> cores, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formulas =</span> form, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ridge =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb33-5">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remove.collinear =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remove.constant =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb33-6">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">allow.na =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">printFlag =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb33-7"></span>
<span id="cb33-8">gt1 <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;">with</span>(gamt, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rlm</span>(PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-9">  BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-10">  Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2))</span>
<span id="cb33-11"></span>
<span id="cb33-12">resultsgt <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mice<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;">pool</span>(gt1)</span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ztable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(resultsgt))</span></code></pre></div></div>
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">term</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">estimate</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">std.error</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">statistic</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">df</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">p.value</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">(Intercept)</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">13.23</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">4.95</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.67</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">factor(Group)Drug Y</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.52</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.13</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-76.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.97</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.04</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">23.48</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Age</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.32</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">35.44</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Z</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.62</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.39</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.44</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.07</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.34</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.14</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.10</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-1.35</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<p>Having done that, I shall try one more supplementary analysis which piqued my curiosity. I recently came across a few papers that concluded that random forests outperformed other imputation algorithms in recovering the true parameter values.</p>
<p>Generally, imputation algorithms are evaluated based on a general simulation design which often resembles the following:</p>
<hr>
<hr>
<ol type="1">
<li>Sampling mechanism only. The basic simulation steps are: choose <img src="https://latex.codecogs.com/png.latex?Q">, take samples <img src="https://latex.codecogs.com/png.latex?Y%5E%7B(s)%7D">, fit the complete-data model, estimate <img src="https://latex.codecogs.com/png.latex?%5Chat%7BQ%7D%5E%7B(s)%7D"> and <img src="https://latex.codecogs.com/png.latex?U%5E%7B(s)%7D"> and calculate the outcomes aggregated over <img src="https://latex.codecogs.com/png.latex?s">.</li>
</ol>
<hr>
<ol start="2" type="1">
<li>Sampling and missing data mechanisms combined. The basic simulation steps are: choose <img src="https://latex.codecogs.com/png.latex?Q">, take samples <img src="https://latex.codecogs.com/png.latex?Y%5E%7B(s)%7D">, generate incomplete data <img src="https://latex.codecogs.com/png.latex?Y_%7B%5Cmathrm%7Bobs%7D%7D%5E%7B(s,%20t)%7D">, impute, estimate <img src="https://latex.codecogs.com/png.latex?%5Chat%7BQ%7D%5E%7B(s,%20t)%7D"> and <img src="https://latex.codecogs.com/png.latex?T%5E%7B(s,%20t)%7D"> and calculate outcomes aggregated over <img src="https://latex.codecogs.com/png.latex?s"> and <img src="https://latex.codecogs.com/png.latex?t">.</li>
</ol>
<hr>
<ol start="3" type="1">
<li>Missing data mechanism only. The basic simulation steps are: choose <img src="https://latex.codecogs.com/png.latex?(%5Chat%7BQ%7D,%20U)">, generate incomplete data <img src="https://latex.codecogs.com/png.latex?Y_%7Bo%20b%20s%7D%5E%7B(t)%7D">, impute, estimate <img src="https://latex.codecogs.com/png.latex?(Q,%20U)%5E%7B(t)%7D"> and <img src="https://latex.codecogs.com/png.latex?B%5E%7B(t)%7D"> and calculate outcomes aggregated over <img src="https://latex.codecogs.com/png.latex?t">.</li>
</ol>
<hr>
<p>These designs generally lead to evaluating a number of metrics which include the following:</p>
<hr>
<ul>
<li>Raw Bias: where <img src="https://latex.codecogs.com/png.latex?RB"> is bias and <img src="https://latex.codecogs.com/png.latex?Q"> is the difference between the estimate and the truth <img src="https://latex.codecogs.com/png.latex?RB=E(Q)-Q">, which may also be expressed as a percent <img src="https://latex.codecogs.com/png.latex?100*%5Cfrac%7BRB=E(Q)-Q%7D%7BQ%7D"></li>
</ul>
<hr>
<ul>
<li>Coverage Rate: which is simply the proportion of times the intervals actually contain the true parameter value</li>
</ul>
<hr>
<ul>
<li>Average Width: the width of the interval estimates, with longer widths indicating less information</li>
</ul>
<hr>
<ul>
<li>Root mean squared error (RMSE) <img src="https://latex.codecogs.com/png.latex?%5Coperatorname%7BRMSE%7D=%5Csqrt%7B%5Cfrac%7B1%7D%7Bn_%7B%5Ctext%20%7Bmis%20%7D%7D%7D%20%5Csum_%7Bi=1%7D%5E%7Bn_%7B%5Ctext%20%7Bmits%20%7D%7D%7D%5Cleft(y_%7Bi%7D%5E%7B%5Ctext%20%7Bmis%20%7D%7D-%5Cdot%7By%7D_%7Bi%7D%5Cright)%5E%7B2%7D%7D"></li>
</ul>
<hr>
<p>The authors primarily based their conclusions on the root mean squared error (RMSE). However, this is problematic for a number of reasons; imputation is not the same as prediction, and so the same loss functions are not as useful; indeed, the RMSE is highly misleading as a measure of performance.</p>
<p>van Buuren explains here:</p>
<hr>
<blockquote class="blockquote">
<p>It is well known that the minimum RMSE is attained by predicting the missing <img src="https://latex.codecogs.com/png.latex?%5Cdot%7B%7By%7D%7D_%7Bi%7D"> by the linear model with the regression weights set to their least squares estimates. According to this reasoning the “best” method replaces each missing value by its most likely value under the model. However, this will find the same values over and over, and is single imputation.</p>
<p>This method ignores the inherent uncertainty of the missing values (and acts as if they were known after all), resulting in biased estimates and invalid statistical inferences. Hence, the method yielding the lowest RMSE is bad for imputation. More generally, measures based on similarity between the true and imputed values do not separate valid from invalid imputation methods.</p>
</blockquote>
<hr>
<p>Having set up our simulation design, we can now test the performances between regression imputation <em>norm.predict</em> and and regular regression imputation <em>norm</em> and we will be examining the metrics above to evaluate performance. Regression imputation generally gives very biased results given that it uses its predictions to impute the missing values. Thus, I will show here how RMSE is highly misleading as a metric to evaluate the performance of imputation algorithms.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Evaluate MI Algorithms</span></span>
<span id="cb35-2"></span>
<span id="cb35-3">create.data <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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta =</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;">sigma2 =</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;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>,</span>
<span id="cb35-4">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">run =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) {</span>
<span id="cb35-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> run)</span>
<span id="cb35-6">  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>(n)</span>
<span id="cb35-7">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> beta <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x <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;">rnorm</span>(n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(sigma2))</span>
<span id="cb35-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</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> y)</span>
<span id="cb35-9">}</span>
<span id="cb35-10"></span>
<span id="cb35-11">make.missing <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>(data, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) {</span>
<span id="cb35-12">  rx <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;">rbinom</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(data), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, p)</span>
<span id="cb35-13">  data[rx <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;">0</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>] <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;">NA</span></span>
<span id="cb35-14">  data</span>
<span id="cb35-15">}</span>
<span id="cb35-16"></span>
<span id="cb35-17">test.impute <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>(data, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m =</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;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"norm"</span>, ...) {</span>
<span id="cb35-18">  imp <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;">mice</span>(data,</span>
<span id="cb35-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> method, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m =</span> m,</span>
<span id="cb35-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">print =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cores =</span> cores, ...</span>
<span id="cb35-21">  )</span>
<span id="cb35-22">  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;">with</span>(imp, <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> x))</span>
<span id="cb35-23">  tab <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;">summary</span>(mice<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;">pool</span>(fit), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">conf.int =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb35-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(tab[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</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;">"estimate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2.5 %"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"97.5 %"</span>)])</span>
<span id="cb35-25">}</span>
<span id="cb35-26"></span>
<span id="cb35-27">rmse <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>(truedata, imp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>) {</span>
<span id="cb35-28">  mx <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;">is.na</span>(mice<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;">complete</span>(imp, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))[, v]</span>
<span id="cb35-29">  mse <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;">rep</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, imp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>m)</span>
<span id="cb35-30">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (k <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(imp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>m)) {</span>
<span id="cb35-31">    filled <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mice<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;">complete</span>(imp, k)[mx, v]</span>
<span id="cb35-32">    true <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> truedata[mx, v]</span>
<span id="cb35-33">    mse[k] <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>((filled <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> true)<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>
<span id="cb35-34">  }</span>
<span id="cb35-35">  <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;">mean</span>(mse))</span>
<span id="cb35-36">}</span>
<span id="cb35-37"></span>
<span id="cb35-38">mae <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>(truedata, imp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>) {</span>
<span id="cb35-39">  mx <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;">is.na</span>(mice<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;">complete</span>(imp, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))[, v]</span>
<span id="cb35-40">  mse <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;">rep</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, imp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>m)</span>
<span id="cb35-41">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (k <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(imp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>m)) {</span>
<span id="cb35-42">    filled <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mice<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;">complete</span>(imp, k)[mx, v]</span>
<span id="cb35-43">    true <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> truedata[mx, v]</span>
<span id="cb35-44">    mse[k] <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>((filled <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> true))</span>
<span id="cb35-45">  }</span>
<span id="cb35-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(mse))</span>
<span id="cb35-47">}</span>
<span id="cb35-48"></span>
<span id="cb35-49">simulate1 <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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">runs =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>) {</span>
<span id="cb35-50">  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;">array</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dim =</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;">2</span>, runs, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb35-51">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dimnames</span>(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;">list</span>(</span>
<span id="cb35-52">    <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;">"norm.predict"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"norm"</span>),</span>
<span id="cb35-53">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</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>runs),</span>
<span id="cb35-54">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MAE"</span></span>
<span id="cb35-55">  )</span>
<span id="cb35-56">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (run <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>runs) {</span>
<span id="cb35-57">    truedata <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;">create.data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">run =</span> run)</span>
<span id="cb35-58">    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;">make.missing</span>(truedata)</span>
<span id="cb35-59">    imp <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;">mice</span>(data,</span>
<span id="cb35-60">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"norm.predict"</span>,</span>
<span id="cb35-61">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m =</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;">cores =</span> cores,</span>
<span id="cb35-62">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">print =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb35-63">    )</span>
<span id="cb35-64">    res[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, run, ] <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;">mae</span>(truedata, imp)</span>
<span id="cb35-65">    imp <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;">mice</span>(data, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"norm"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">print =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb35-66">    res[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, run, ] <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;">mae</span>(truedata, imp)</span>
<span id="cb35-67">  }</span>
<span id="cb35-68">  res</span>
<span id="cb35-69">}</span>
<span id="cb35-70"></span>
<span id="cb35-71">simulate2 <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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">runs =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>) {</span>
<span id="cb35-72">  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;">array</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dim =</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;">2</span>, runs, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb35-73">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dimnames</span>(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;">list</span>(</span>
<span id="cb35-74">    <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;">"norm.predict"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"norm"</span>),</span>
<span id="cb35-75">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</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>runs),</span>
<span id="cb35-76">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"RMSE"</span></span>
<span id="cb35-77">  )</span>
<span id="cb35-78">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (run <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>runs) {</span>
<span id="cb35-79">    truedata <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;">create.data</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">run =</span> run)</span>
<span id="cb35-80">    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;">make.missing</span>(truedata)</span>
<span id="cb35-81">    imp <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;">mice</span>(data,</span>
<span id="cb35-82">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"norm.predict"</span>,</span>
<span id="cb35-83">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m =</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;">cores =</span> cores,</span>
<span id="cb35-84">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">print =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb35-85">    )</span>
<span id="cb35-86">    res[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, run, ] <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;">rmse</span>(truedata, imp)</span>
<span id="cb35-87">    imp <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;">mice</span>(data, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"norm"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">print =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb35-88">    res[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, run, ] <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;">rmse</span>(truedata, imp)</span>
<span id="cb35-89">  }</span>
<span id="cb35-90">  res</span>
<span id="cb35-91">}</span></code></pre></div></div>
</div>
<hr>
<p>Our simulation above will generate a dataset, delete values from the dataset and then impute the missing values for that dataset using regression imputation and stochastic regression imputation. We will use two metrics to evaluate the performance of these two algorithms, RMSE and MAE. Once again, it is worth keeping in mind that regression imputation generally performs very poorly when it comes to imputation and that stochastic regression imputation performs better.</p>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><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="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;">1031</span>,</span>
<span id="cb36-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"L'Ecuyer-CMRG"</span>,</span>
<span id="cb36-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">normal.kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Inversion"</span>,</span>
<span id="cb36-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sample.kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rejection"</span></span>
<span id="cb36-5">)</span>
<span id="cb36-6">res1 <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;">simulate1</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)</span>
<span id="cb36-7">res_1 <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;">apply</span>(res1, <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;">3</span>),</span>
<span id="cb36-8">  mean,</span>
<span id="cb36-9">  <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>
<span id="cb36-10">)</span>
<span id="cb36-11">res2 <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;">simulate2</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)</span>
<span id="cb36-12">res_2 <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;">apply</span>(res2, <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;">3</span>),</span>
<span id="cb36-13">  mean,</span>
<span id="cb36-14">  <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>
<span id="cb36-15">)</span>
<span id="cb36-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ztable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(res_1, res_2))</span></code></pre></div></div>
</div>
<hr>
<p>What this simulation clearly shows is that despite regression imputation norm.predict giving highly biased results as usual relative to the truth, it still has a much lower RMSE than stochastic regression imputation, which both had a higher RMSE and a closer distance to the correct parameter values. Once again, this is not surprising given that imputation is not the same thing as prediction and therefore the loss functions cannot be used synonymously. However, when it came to raw bias and mean absolute error, stochastic regression imputation outperformed regression imputation which had a much larger mean absolute error and raw bias.</p>
<p>This is why the most informative metrics to focus on when evaluating an imputation algorithm include information/width, sufficient long-run coverage, and less misleading metrics such as mean absolute error and mean absolute percentage error.</p>
<hr>
<p>The authors specifically used the <code>missForest</code> package. I tried using the package, but encountered too many difficulties so I simply specified the <code>rf</code> method in <code>mice</code>, and worked from there.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># MI Using Random Forest</span></span>
<span id="cb37-2"></span>
<span id="cb37-3">form <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;">list</span>(PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2)</span>
<span id="cb37-4"></span>
<span id="cb37-5">rf <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mice<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;">mice</span>(</span>
<span id="cb37-6">  BP_miss,</span>
<span id="cb37-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rf"</span>,</span>
<span id="cb37-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ntree =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>,</span>
<span id="cb37-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">predictorMatrix =</span> pred,</span>
<span id="cb37-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span id="cb37-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxit =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb37-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>,</span>
<span id="cb37-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formulas =</span> form,</span>
<span id="cb37-14">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ridge =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb37-15">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remove.collinear =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb37-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remove.constant =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb37-17">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">allow.na =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb37-18">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">printFlag =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb37-19">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">visitSequence =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"monotone"</span></span>
<span id="cb37-20">)</span>
<span id="cb37-21"></span>
<span id="cb37-22">rf1 <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;">with</span>(rf, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rlm</span>(PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb37-23">  BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb37-24">  Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2,</span>
<span id="cb37-25">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MM"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">psi =</span> psi.huber</span>
<span id="cb37-26">))</span>
<span id="cb37-27"></span>
<span id="cb37-28">results5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mice<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;">pool</span>(rf1)</span>
<span id="cb37-29"></span>
<span id="cb37-30">results5_sum <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;">summary</span>(results5)</span>
<span id="cb37-31"></span>
<span id="cb37-32"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(results5_sum) <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>
<span id="cb37-33">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Term"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SE"</span>,</span>
<span id="cb37-34">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Statistic"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"df"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P-val"</span></span>
<span id="cb37-35">)</span>
<span id="cb37-36"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ztable</span>(results5_sum)</span></code></pre></div></div>
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Term</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Estimate</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">SE</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Statistic</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">df</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">P-val</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">(Intercept)</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">33.94</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">9.94</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">3.42</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">factor(Group)Drug Y</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.45</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.18</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-53.97</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.80</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.09</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">9.38</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Age</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.29</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">17.77</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Z</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.58</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.09</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.22</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.18</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.10</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">NA</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
</section>
<section id="full-analysis-set" class="level3">
<h3 class="anchored" data-anchor-id="full-analysis-set">Full Analysis Set</h3>
<hr>
<p>After we run all those analyses, we can finally check our numbers from the full dataset with no missing observations to see how our approaches to handle the missing data have performed. We first look at the fully adjusted model fit with <a href="https://rdrr.io/pkg/MASS/man/rlm.html"><code>rlm()</code></a>.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Full Analysis Set</span></span>
<span id="cb38-2"></span>
<span id="cb38-3">final_full_mod <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;">rlm</span>(</span>
<span id="cb38-4">  PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb38-5">    Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2,</span>
<span id="cb38-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> BP_full,</span>
<span id="cb38-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MM"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">psi =</span> psi.huber</span>
<span id="cb38-8">)</span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; color: rgba(119, 119, 119, 1) !important;"></th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Value</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Std. Error</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">t value</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">(Intercept)</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">9.19</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">3.72</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.47</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">factor(Group)Drug Y</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.66</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.09</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-106.85</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.03</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">31.68</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Age</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.33</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">50.17</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">Z</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-2.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-2.00</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">R1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.05</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.21</td>
</tr>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">R2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.09</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-0.09</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Term</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">VIF</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">VIF_CI_low</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">VIF_CI_high</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">SE_factor</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Tolerance</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Tolerance_CI_low</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Tolerance_CI_high</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">factor(Group)</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">489.74</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.99</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">BaselineDBP</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.97</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.75</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.26</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.40</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.51</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.44</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.57</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Age</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.02</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">4.09</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.98</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.24</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Z</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.98</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.75</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2.27</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.41</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.51</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.44</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.57</td>
</tr>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">33.65</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.99</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.03</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">R2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.01</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1603.17</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.99</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.00</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1.00</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<p>We can also graphically inspect our assumptions.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-76-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-76-2.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p>Then we look at the unadjusted model, where the difference is the group that the participants were randomized to.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Unadjusted Model</span></span>
<span id="cb39-2"></span>
<span id="cb39-3">final_reduced_mod <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;">rlm</span>(PostDBP <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;">factor</span>(Group),</span>
<span id="cb39-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> BP_full,</span>
<span id="cb39-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MM"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">psi =</span> psi.huber</span>
<span id="cb39-6">)</span>
<span id="cb39-7"></span>
<span id="cb39-8">final_reduced_mod_sum <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;">summary</span>(final_reduced_mod)[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coefficients"</span>]]</span>
<span id="cb39-9"></span>
<span id="cb39-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(final_reduced_mod_sum) <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>
<span id="cb39-11">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Value"</span>,</span>
<span id="cb39-12">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Std. Error"</span>,</span>
<span id="cb39-13">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t-value"</span></span>
<span id="cb39-14">)</span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; color: rgba(119, 119, 119, 1) !important;"></th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Value</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Std. Error</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">t-value</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">(Intercept)</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">142.6</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.20</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">728.8</td>
</tr>
<tr class="even">
<td style="text-align: left; color: rgba(119, 119, 119, 1) !important;">factor(Group)Drug Y</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-9.2</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.28</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">-32.7</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<p>We can also compare the two to see if there are any substantial differences.</p>
<hr>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; ">
<table class="table-striped lightable-classic caption-top table table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Name</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Model</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">AIC</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">AIC_wt</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">AICc</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">AICc_wt</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">BIC</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">BIC_wt</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">RMSE</th>
<th data-quarto-table-cell-role="th" style="text-align: center; color: rgba(119, 119, 119, 1) !important;">Sigma</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">final_full_mod</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">rlm</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1420</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1420</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1453</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">1</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.98</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0.99</td>
</tr>
<tr class="even">
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">final_reduced_mod</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">rlm</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2556</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2557</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">2569</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">0</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">3.10</td>
<td style="text-align: center; color: rgba(119, 119, 119, 1) !important;">3.11</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<p>While the results have mostly been consistent, I also wanted to run a few additional analyses of my own to see whether these effect estimates were consistent I first started by constructing the confidence distribution using the [<code>concurve</code>] package to see the range of parameter values consistent with the data given the background model assumptions.<span class="citation" data-cites="rafiSemanticCognitiveTools2020 greenlandAidScientificInference2020"><sup>26, 27</sup></span></p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Compatibility of Values</span></span>
<span id="cb40-2"></span>
<span id="cb40-3">fit1 <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;">glm</span>(</span>
<span id="cb40-4">  PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb40-5">    Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2,</span>
<span id="cb40-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> BP_full, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gaussian</span>()</span>
<span id="cb40-7">)</span>
<span id="cb40-8"></span>
<span id="cb40-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(fit1)</span>
<span id="cb40-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb40-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Call:</span></span>
<span id="cb40-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; glm(formula = PostDBP ~ factor(Group) + BaselineDBP + Age + Z + </span></span>
<span id="cb40-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     R1 + R2, family = gaussian(), data = BP_full)</span></span>
<span id="cb40-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb40-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Coefficients:</span></span>
<span id="cb40-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                     Estimate Std. Error t value Pr(&gt;|t|)    </span></span>
<span id="cb40-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; (Intercept)          9.02736    3.65879    2.47    0.014 *  </span></span>
<span id="cb40-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; factor(Group)Drug Y -9.64556    0.08906 -108.30   &lt;2e-16 ***</span></span>
<span id="cb40-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; BaselineDBP          1.00567    0.03120   32.23   &lt;2e-16 ***</span></span>
<span id="cb40-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Age                  0.32696    0.00645   50.69   &lt;2e-16 ***</span></span>
<span id="cb40-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Z                   -1.97391    0.99551   -1.98    0.048 *  </span></span>
<span id="cb40-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; R1                   0.01071    0.04711    0.23    0.820    </span></span>
<span id="cb40-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; R2                  -0.02493    0.08799   -0.28    0.777    </span></span>
<span id="cb40-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ---</span></span>
<span id="cb40-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1</span></span>
<span id="cb40-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb40-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; (Dispersion parameter for gaussian family taken to be 0.983)</span></span>
<span id="cb40-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb40-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     Null deviance: 15519.32  on 499  degrees of freedom</span></span>
<span id="cb40-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Residual deviance:   484.49  on 493  degrees of freedom</span></span>
<span id="cb40-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; AIC: 1419</span></span>
<span id="cb40-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb40-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Number of Fisher Scoring iterations: 2</span></span>
<span id="cb40-34"></span>
<span id="cb40-35">fit2 <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;">glm</span>(PostDBP <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;">factor</span>(Group),</span>
<span id="cb40-36">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> BP_full, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gaussian</span>()</span>
<span id="cb40-37">)</span>
<span id="cb40-38"></span>
<span id="cb40-39"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(fit2)</span>
<span id="cb40-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb40-41"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Call:</span></span>
<span id="cb40-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; glm(formula = PostDBP ~ factor(Group), family = gaussian(), data = BP_full)</span></span>
<span id="cb40-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb40-44"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Coefficients:</span></span>
<span id="cb40-45"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                     Estimate Std. Error t value Pr(&gt;|t|)    </span></span>
<span id="cb40-46"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; (Intercept)          142.596      0.193   737.3   &lt;2e-16 ***</span></span>
<span id="cb40-47"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; factor(Group)Drug Y   -9.263      0.278   -33.3   &lt;2e-16 ***</span></span>
<span id="cb40-48"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ---</span></span>
<span id="cb40-49"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1</span></span>
<span id="cb40-50"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb40-51"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; (Dispersion parameter for gaussian family taken to be 9.65)</span></span>
<span id="cb40-52"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb40-53"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;     Null deviance: 15519.3  on 499  degrees of freedom</span></span>
<span id="cb40-54"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Residual deviance:  4805.8  on 498  degrees of freedom</span></span>
<span id="cb40-55"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; AIC: 2556</span></span>
<span id="cb40-56"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb40-57"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Number of Fisher Scoring iterations: 2</span></span>
<span id="cb40-58"></span>
<span id="cb40-59">curve1 <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;">curve_gen</span>(fit1,</span>
<span id="cb40-60">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"factor(Group)Drug Y"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>,</span>
<span id="cb40-61">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">log =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">table =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb40-62">)</span></code></pre></div></div>
</div>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-82-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<table class="lightable-classic caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Lower Limit</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Upper Limit</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Interval Width</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Interval Level (%)</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">CDF</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">P-value</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">S-value (bits)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.67</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.62</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.057</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">25.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.625</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.750</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.415</td>
</tr>
<tr class="even">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.71</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.59</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.120</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">50.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.750</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.500</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.000</td>
</tr>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.75</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.54</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.205</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">75.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.875</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.250</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.000</td>
</tr>
<tr class="even">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.76</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.53</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.228</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">80.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.900</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.200</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.322</td>
</tr>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.77</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.52</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.256</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">85.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.925</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.150</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.737</td>
</tr>
<tr class="even">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.79</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.50</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.293</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">90.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.950</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.100</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">3.322</td>
</tr>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.82</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.47</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.349</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">95.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.975</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.050</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">4.322</td>
</tr>
<tr class="even">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.85</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.45</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.399</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">97.5</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.988</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.025</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">5.322</td>
</tr>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.88</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.42</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.459</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">99.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.995</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.010</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">6.644</td>
</tr>
</tbody><tfoot>
<tr class="odd">
<td style="text-align: right; padding: 0;"><span style="font-style: italic;">Table of Statistics for Various Interval Estimate Percentiles</span></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
<tr class="even">
<td style="text-align: right; padding: 0;"><sup></sup></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
</tfoot>

</table>
</div>
</div>
<hr>
<p>Indeed, our confidence distribution ends up being very similar to our Bayesian posterior distribution for the treatment effect. Under certain situations, the maximum likelihood estimate ends up also being equivalent to the median unbiased estimate. In this case, it happens to be very similar to the maximum a posteriori estimate.</p>
<hr>
<p><img src="https://latex.codecogs.com/png.latex?C%20V_%7Bn%7D(%5Ctheta)=1-2%5Cleft%7CH_%7Bn%7D(%5Ctheta)-0.5%5Cright%7C=2%20%5Cmin%20%5Cleft%5C%7BH_%7Bn%7D(%5Ctheta),%201-H_%7Bn%7D(%5Ctheta)%5Cright%5C%7D"></p>
<hr>
<div class="cell" data-layout-align="center">
<pre><code>#&gt; Posterior density plot skipped: `b_2` was not fitted in this environment.</code></pre>
</div>
<hr>
<p>We can also check to see that our confidence distribution and posterior distribution are consistent with the profile-likelihood function, which is free of nuisance parameters. The advantage of profiling is allowing us to recover more accurate parameter estimates when there are several nuisance parameters or messy data. Below are implementations in both <code>R</code> and <code>Stata</code>, except this time we do not specify errors from the <em>t</em>-distribution.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb42" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1">analyseImp3 <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>(inputData, i) {</span>
<span id="cb42-2">  dt <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> inputData[i, ]</span>
<span id="cb42-3">  (<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;">glm</span>(PostDBP <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;">factor</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> BaselineDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Age <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> R2,</span>
<span id="cb42-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dt, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gaussian</span>()</span>
<span id="cb42-5">  ))[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb42-6">}</span>
<span id="cb42-7"></span>
<span id="cb42-8">bootdist <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> boot<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;">boot</span>(</span>
<span id="cb42-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> BP_full, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistic =</span> analyseImp3,</span>
<span id="cb42-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sim =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ordinary"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"i"</span>,</span>
<span id="cb42-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parallel =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"multicore"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncpus =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span></span>
<span id="cb42-12">)</span>
<span id="cb42-13"></span>
<span id="cb42-14">sd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> boot<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;">boot.ci</span>(bootdist, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">conf =</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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</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;">100</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;">"bca"</span>)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>]</span>
<span id="cb42-15"></span>
<span id="cb42-16">A <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> sd<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bca</span>
<span id="cb42-17"></span>
<span id="cb42-18"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qplot</span>((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(A[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>], A[, <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;">geom =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"density"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">I</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#3f8f9b44"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb42-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_less</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb42-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb42-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bCA Bootstrap Density Plot"</span>,</span>
<span id="cb42-22">    <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;">"'Group' Parameter Value (Treatment Effect mmHg)"</span>,</span>
<span id="cb42-23">    <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="cb42-24">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-84-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<p><img src="https://latex.codecogs.com/png.latex?L_%7Bt_%7Bn%7D%7D(%5Ctheta)=f_%7Bn%7D%5Cleft(F_%7Bn%7D%5E%7B-1%7D%5Cleft(H_%7Bp%20i%20v%7D(%5Ctheta)%5Cright)%5Cright)%5Cleft%7C%5Cfrac%7B%5Cpartial%7D%7B%5Cpartial%20t%7D%20%5Cpsi%5Cleft(t_%7Bn%7D,%20%5Ctheta%5Cright)%5Cright%7C=h_%7Bp%20i%20v%7D(%5Ctheta)%5Cleft%7C%5Cfrac%7B%5Cpartial%7D%7B%5Cpartial%20t%7D%20%5Cpsi(t,%20%5Ctheta)%5Cright%7C%20/%5Cleft.%5Cleft%7C%5Cfrac%7B%5Cpartial%7D%7B%5Cpartial%20%5Ctheta%7D%20%5Cpsi(t,%20%5Ctheta)%5Cright%7C%5Cright%7C_%7Bt=t_%7Bn%7D%7D"></p>
<hr>
<hr>
<p>We now focus on profiling on the treatment effect and calculating the profile deviance function. We then multiply our deviance by -0.5 to obtain the profile log-likelihood function.</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb43" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb43-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Profile Likelihood</span></span>
<span id="cb43-2"></span>
<span id="cb43-3">prof <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;">profile</span>(fit1)</span>
<span id="cb43-4">disp <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;">attr</span>(prof, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"summary"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>dispersion</span>
<span id="cb43-5">mindev <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;">attr</span>(prof, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"original.fit"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>deviance</span>
<span id="cb43-6"></span>
<span id="cb43-7">dev1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> prof[[<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>tau<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>
<span id="cb43-8">dev2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dev1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> disp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> mindev</span>
<span id="cb43-9"></span>
<span id="cb43-10">tmpf <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>(x, n) {</span>
<span id="cb43-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb43-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">par =</span> n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tau =</span> x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>tau,</span>
<span id="cb43-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">deviance =</span> x<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="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> disp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> mindev,</span>
<span id="cb43-14">    x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par.vals, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">check.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb43-15">  )</span>
<span id="cb43-16">}</span>
<span id="cb43-17"></span>
<span id="cb43-18">pp <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;">do.call</span>(rbind, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mapply</span>(tmpf, prof, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(prof),</span>
<span id="cb43-19">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SIMPLIFY =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb43-20">))</span>
<span id="cb43-21"></span>
<span id="cb43-22">pp2 <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;">melt</span>(pp, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id.var =</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;">3</span>)</span>
<span id="cb43-23">pp3 <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;">subset</span>(pp2, par <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> variable, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">select =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>variable)</span>
<span id="cb43-24">pp4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pp3[<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;">c</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;">13</span>), ]</span>
<span id="cb43-25"></span>
<span id="cb43-26">pp4<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>loglik <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pp4<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>deviance <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</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></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://lesslikely.com/statistics/sensitivity_files/figure-html/unnamed-chunk-87-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb44" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb44-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">linesize</span> 255</span>
<span id="cb44-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">all</span></span>
<span id="cb44-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">seed</span> 1031</span>
<span id="cb44-4">import delimited <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"static/datasets/temp.csv"</span>, numericcols(2 3 5 6 7 8)</span>
<span id="cb44-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">capture</span> which pllf</span>
<span id="cb44-6"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_rc</span> == 0 {</span>
<span id="cb44-7"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">foreach</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">var</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">varlist</span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> baselinedbp age z r1 r2 {</span>
<span id="cb44-8">grstyle init</span>
<span id="cb44-9">grstyle <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">color</span> <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">background</span> <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">white</span>, opacity(.1)</span>
<span id="cb44-10"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">quietly</span> pllf <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">glm</span> postdbp <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> baselinedbp age z r1 r2, profile(<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`var'</span>)</span>
<span id="cb44-11"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">graph</span> copy Graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`var'</span></span>
<span id="cb44-12">}</span>
<span id="cb44-13"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">graph</span> <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">combine</span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group</span> baselinedbp age z r1 r2</span>
<span id="cb44-14"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">graph</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">export</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loglikfunction.svg"</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span></span>
<span id="cb44-15">}</span>
<span id="cb44-16"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb44-17"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">display</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Skipping profile-likelihood plots: the -pllf- command is not installed."</span></span>
<span id="cb44-18">}</span>
<span id="cb44-19">#&gt; file ()<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">print</span>() <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> found</span>
<span id="cb44-20">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(601);</span>
<span id="cb44-21">#&gt; </span>
<span id="cb44-22">#&gt; </span>
<span id="cb44-23">#&gt; </span>
<span id="cb44-24">#&gt; </span>
<span id="cb44-25">#&gt; </span>
<span id="cb44-26">#&gt; (encoding automatically selected: ISO-8859-2)</span>
<span id="cb44-27">#&gt; (7 vars, 500 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">obs</span>)</span>
<span id="cb44-28">#&gt; </span>
<span id="cb44-29">#&gt; </span>
<span id="cb44-30">#&gt; </span>
<span id="cb44-31">#&gt; Skipping profile-likelihood plots: the -pllf- command is <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> installed.</span></code></pre></div></div>
</div>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<table class="lightable-classic caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Lower Limit</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Upper Limit</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">CI Width</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">Level (%)</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">CDF</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">P-value</th>
<th data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold; color: rgba(119, 119, 119, 1) !important;">S-value</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.67</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.62</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.057</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">25.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.625</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.750</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.415</td>
</tr>
<tr class="even">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.71</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.59</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.120</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">50.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.750</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.500</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">1.000</td>
</tr>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.75</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.54</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.205</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">75.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.875</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.250</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.000</td>
</tr>
<tr class="even">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.76</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.53</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.228</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">80.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.900</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.200</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.322</td>
</tr>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.77</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.52</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.256</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">85.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.925</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.150</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">2.737</td>
</tr>
<tr class="even">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.79</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.50</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.293</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">90.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.950</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.100</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">3.322</td>
</tr>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.82</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.47</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.349</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">95.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.975</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.050</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">4.322</td>
</tr>
<tr class="even">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.85</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.45</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.399</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">97.5</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.988</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.025</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">5.322</td>
</tr>
<tr class="odd">
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.88</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">-9.42</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.459</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">99.0</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.995</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">0.010</td>
<td style="text-align: right; color: rgba(119, 119, 119, 1) !important;">6.644</td>
</tr>
</tbody><tfoot>
<tr class="odd">
<td style="text-align: right; padding: 0;"><span style="font-style: italic;">Table of Statistics for Various Interval Estimate Percentiles</span></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
<tr class="even">
<td style="text-align: right; padding: 0;"><sup></sup></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
<td style="text-align: right;"></td>
</tr>
</tfoot>

</table>
</div>
</div>
<hr>
<p>I then compared the results of the full analysis set to the results from the primary analysis and sensitivity analyses.</p>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<pre><code>#&gt; file ()print() not found
#&gt; r(601);
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 11.359786 -9.5274391 .98342353 .32837421 -1.3210281 -.02229379 -.12617403</code></pre>
</div>
<hr>
<p>[<code>concurve</code>]: <code>R</code>: #R <code>Stata</code>: #stata</p>
</section>
<section id="examining-the-analyses" class="level3">
<h3 class="anchored" data-anchor-id="examining-the-analyses">Examining the Analyses</h3>
<hr>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 5px; overflow-x: scroll; width:100%; "><table class=" lightable-classic" style="font-size: 12px; font-family: PT Serif; margin-left: auto; margin-right: auto;border-bottom: 0;border-bottom: 0;">
<caption style="font-size: initial !important;">Evaluation of Imputation Algorithms</caption>
 <thead>
  <tr>
   <th style="text-align:left;color: rgba(136, 136, 136, 1) !important;">   </th>
   <th style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> PMM </th>
   <th style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> Heckman </th>
   <th style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> Stata </th>
   <th style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> Bayes </th>
   <th style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> GAMLSS </th>
   <th style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> RI </th>
   <th style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> RF </th>
   <th style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> True </th>
  </tr>
 </thead>
<tbody>
  <tr>
   <td style="text-align:left;"> (Intercept) </td>
   <td style="text-align:right;"> 11.25 </td>
   <td style="text-align:right;"> 10.12 </td>
   <td style="text-align:right;"> 11.36 </td>
   <td style="text-align:right;"> NA </td>
   <td style="text-align:right;"> 13.23 </td>
   <td style="text-align:right;"> 10.37 </td>
   <td style="text-align:right;"> 33.94 </td>
   <td style="text-align:right;"> 9.19 </td>
  </tr>
  <tr>
   <td style="text-align:left;"> factor(Group)Drug Y </td>
   <td style="text-align:right;"> -9.51 </td>
   <td style="text-align:right;"> -9.50 </td>
   <td style="text-align:right;"> -9.53 </td>
   <td style="text-align:right;"> NA </td>
   <td style="text-align:right;"> -9.52 </td>
   <td style="text-align:right;"> -9.63 </td>
   <td style="text-align:right;"> -9.45 </td>
   <td style="text-align:right;"> -9.66 </td>
  </tr>
  <tr>
   <td style="text-align:left;"> BaselineDBP </td>
   <td style="text-align:right;"> 0.98 </td>
   <td style="text-align:right;"> 0.99 </td>
   <td style="text-align:right;"> 0.98 </td>
   <td style="text-align:right;"> NA </td>
   <td style="text-align:right;"> 0.97 </td>
   <td style="text-align:right;"> 0.99 </td>
   <td style="text-align:right;"> 0.80 </td>
   <td style="text-align:right;"> 1.00 </td>
  </tr>
  <tr>
   <td style="text-align:left;"> Age </td>
   <td style="text-align:right;"> 0.33 </td>
   <td style="text-align:right;"> 0.33 </td>
   <td style="text-align:right;"> 0.33 </td>
   <td style="text-align:right;"> NA </td>
   <td style="text-align:right;"> 0.32 </td>
   <td style="text-align:right;"> 0.33 </td>
   <td style="text-align:right;"> 0.29 </td>
   <td style="text-align:right;"> 0.33 </td>
  </tr>
  <tr>
   <td style="text-align:left;"> Z </td>
   <td style="text-align:right;"> -1.33 </td>
   <td style="text-align:right;"> -1.09 </td>
   <td style="text-align:right;"> -1.32 </td>
   <td style="text-align:right;"> NA </td>
   <td style="text-align:right;"> -0.62 </td>
   <td style="text-align:right;"> -1.02 </td>
   <td style="text-align:right;"> 0.02 </td>
   <td style="text-align:right;"> -2.02 </td>
  </tr>
  <tr>
   <td style="text-align:left;"> R1 </td>
   <td style="text-align:right;"> -0.02 </td>
   <td style="text-align:right;"> -0.02 </td>
   <td style="text-align:right;"> -0.02 </td>
   <td style="text-align:right;"> NA </td>
   <td style="text-align:right;"> -0.02 </td>
   <td style="text-align:right;"> -0.02 </td>
   <td style="text-align:right;"> 0.02 </td>
   <td style="text-align:right;"> 0.01 </td>
  </tr>
  <tr>
   <td style="text-align:left;"> R2 </td>
   <td style="text-align:right;"> -0.14 </td>
   <td style="text-align:right;"> -0.15 </td>
   <td style="text-align:right;"> -0.13 </td>
   <td style="text-align:right;"> NA </td>
   <td style="text-align:right;"> -0.14 </td>
   <td style="text-align:right;"> -0.15 </td>
   <td style="text-align:right;"> -0.02 </td>
   <td style="text-align:right;"> -0.01 </td>
  </tr>
  <tr>
   <td style="text-align:left;color: rgba(136, 136, 136, 1) !important;"> MPE </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> -203.93 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> -214.28 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> -171.96 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> NA </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> -194.38 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> -224.45 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> -53.76 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.00 </td>
  </tr>
  <tr>
   <td style="text-align:left;color: rgba(136, 136, 136, 1) !important;"> Huber Loss </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.26 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.13 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.28 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> NA </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.64 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.17 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 3.69 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.00 </td>
  </tr>
  <tr>
   <td style="text-align:left;color: rgba(136, 136, 136, 1) !important;"> MAE </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.44 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.32 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.45 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> NA </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.83 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.34 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 3.89 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.00 </td>
  </tr>
  <tr>
   <td style="text-align:left;color: rgba(136, 136, 136, 1) !important;"> MSD </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> -0.39 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> -0.26 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> -0.41 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> NA </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> -0.77 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> -0.29 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> -3.82 </td>
   <td style="text-align:right;color: rgba(136, 136, 136, 1) !important;"> 0.00 </td>
  </tr>
</tbody>
<tfoot>
<tr><td style="padding: 0; " colspan="100%"><span style="text-decoration: underline;">Metric Abbreviations: </span></td></tr>
<tr><td style="padding: 0; " colspan="100%">
<sup></sup> MPE = Mean Percentage Error; MAE = Mean Absolute Error; MSD = Mean Signed Deviation</td></tr>
</tfoot>
<tfoot>
<tr><td style="padding: 0; " colspan="100%"><span style="text-decoration: underline;">MI Abbreviations: </span></td></tr>
<tr><td style="padding: 0; " colspan="100%">
<sup></sup> PMM = Predictive Mean Matching; Heckman = Heckman Selection Model;
 RI = Random Indicator; RF = Random Forest; Bayes = Imputation During Model Fitting</td></tr>
</tfoot>
</table></div>
</div>
</div>
<hr>
<p>We can see that that the overall treatment effect is approximately 9.7-9.9, and for most of the principled methods we used to handle the missing data, we did not obtain similar estimates. For example, both the primary analysis and the controlled multiple imputation methods did not yield the correct treatment effect estimate in the adjusted model.</p>
<p>In fact, nearly all of the methods used except for the Heckman selection model, yielded overestimates of the treatment effect. Even though such analyses can be substantially improved with more specification and more information, the reality is that data that are assumed to be <strong>MNAR</strong> are difficult to handle and that no method can guarantee the correct answer. Indeed, we knew the missing data model / mechanism, via our custom function</p>
<hr>
<div class="cell" data-layout-align="center">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb46" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Missing Data Mechanism</span></span>
<span id="cb46-2"></span>
<span id="cb46-3">lesslikely <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="cb46-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1031</span>,</span>
<span id="cb46-5">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"L'Ecuyer-CMRG"</span>,</span>
<span id="cb46-6">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">normal.kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Inversion"</span>,</span>
<span id="cb46-7">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sample.kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rejection"</span></span>
<span id="cb46-8">  )</span>
<span id="cb46-9">  logistic <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>(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(x) <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;">exp</span>(x))</span>
<span id="cb46-10">  <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;">rbinom</span>(n, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">logistic</span>(errors[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]))</span>
<span id="cb46-11">}</span>
<span id="cb46-12"></span>
<span id="cb46-13">Ry <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>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lesslikely</span>() <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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb46-14">PostDBP[Ry <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;">0</span>] <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;">NA</span></span></code></pre></div></div>
</div>
<hr>
<p><img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Bequation%7D%0A%5CPr(R_1=0)=%5Cpsi_0+%5Cfrac%7Be%5E%7BY_1%7D%7D%7B1+e%5E%7BY_1%7D%7D%5Cpsi_1%0A%5Cend%7Bequation%7D"></p>
<hr>
<p>for <strong>MNAR</strong> we set <img src="https://latex.codecogs.com/png.latex?%5Cpsi_%5Cmathrm%7BMNAR%7D=(0,1)"></p>
<hr>
<p>Thus, we obtain the following model:</p>
<hr>
<p><img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign%7D%0A%20%20%5Cmathrm%7BMNAR%7D&amp;:%5Cmathrm%7Blogit%7D(%5CPr(R_1=0))%20=%20Y_1%20%5C%0A%5Cend%7Balign%7D"></p>
<hr>
<p>Even the random indicator method, which has shown much promise in simulation studies<span class="citation" data-cites="jolaniDualImputationStrategies2012"><sup>24</sup></span> and offers the advantage of not having to specify a pattern-mixture or selection model could not recover the correct treatment effect estimate either, showing the difficulty of handling missing data and the limitations of automated approaches.</p>
<hr>
<p>I hope it is clear from the examples above that it is quite easy to do any analyses with missing data and use a variety of ad-hoc approaches or even principled approaches to explore whether or not the results you’ve obtained are trustworthy or at least even give that impression, but doing a careful and principled one is quite difficult and requires much thought that will take into account real departures from assumptions and whether or not those will lead to substantial changes in results and conclusions/decisions.</p>
<hr>
</section>
</section>
<section id="related-from-less-likely" class="level2">
<h2 class="anchored" data-anchor-id="related-from-less-likely">Related from Less Likely</h2>
<hr>
<p>Sensitivity analysis is the connective tissue running through much of what’s published here. The pieces below sit naturally adjacent to this one — each either depends on, extends, or stress-tests an assumption that a sensitivity analysis would interrogate:</p>
<ul>
<li><a href="../statistics/assumptions.html">Your Models Are Neither Useful Nor Approximate</a> — the assumption layer that sensitivity analysis exists to probe.</li>
<li><a href="../statistics/bootstrap.html">Confidence, Posteriors, and the Bootstrap</a> — uncertainty quantification via resampling; a workhorse for sensitivity to distributional assumptions.</li>
<li><a href="../statistics/evidence-of-absence.html">When Can We Say That Something Doesn’t Work?</a> — null-result claims rest on sensitivity to model choice and design.</li>
<li><a href="../statistics/problems-with-nnt.html">Problems with the Number Needed to Treat</a> — NNT is notoriously non-robust to baseline-risk specification.</li>
<li><a href="../statistics/meta-analysis-models.html">Meta-Analysis: Choose Your Model Wisely</a> — the choice between fixed- and random-effects models is itself a sensitivity decision.</li>
<li><a href="../statistics/bayesian-vitamin-e.html">Vitamin E, Mortality, and the Bayesian Gloss</a> — a worked case study in prior sensitivity gone unexamined.</li>
<li><a href="../statistics/statistical-quality-control.html">Quality Control in Statistical Analyses</a> — the kind of sensitivity check that catches the error before it ships.</li>
<li><a href="../statistics/RG2020BMC.html">Tables, Graphs, and Computations from Rafi &amp; Greenland (2020)</a> — the consonance-function machinery underlying much of this post.</li>
</ul>
<hr>
</section>
<section id="acknowledgements" class="level2">
<h2 class="anchored" data-anchor-id="acknowledgements">Acknowledgements</h2>
<hr>
<blockquote class="blockquote">
<p>I’d like to thank <a href="https://twitter.com/tmorris_mrc"><strong>Dr.&nbsp;Tim Morris</strong></a> and <a href="https://twitter.com/ADAlthousePhD"><strong>Dr.&nbsp;Andrew Althouse</strong></a> for helpful comments on an earlier version of this piece. My <strong>acknowledgment</strong> of their help does <strong>not</strong> imply endorsement of my views by these colleagues or vice versa, and I remain <strong>solely</strong> responsible for the views expressed herein. All errors are my own. To point out such errors, please leave a comment below or use the <a href="../contact">contact form</a> to get in touch.</p>
</blockquote>
<hr>
</section>
<section id="statistical-environments" class="level2">
<h2 class="anchored" data-anchor-id="statistical-environments">Statistical Environments</h2>
<hr>
<section id="r-environment" class="level5">
<h5 class="anchored" data-anchor-id="r-environment">R Environment</h5>
<hr>
<div class="cell" data-layout-align="center">
<pre><code>#&gt; ─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#&gt;  setting  value
#&gt;  version  R version 4.6.1 (2026-06-24)
#&gt;  os       macOS Golden Gate 27.0
#&gt;  system   aarch64, darwin25.4.0
#&gt;  ui       unknown
#&gt;  language (EN)
#&gt;  collate  C.UTF-8
#&gt;  ctype    C.UTF-8
#&gt;  tz       America/New_York
#&gt;  date     2026-09-16
#&gt;  pandoc   3.8 @ /opt/anaconda3/bin/ (via rmarkdown)
#&gt;  quarto   1.10.18 @ /usr/local/bin/quarto
#&gt; 
#&gt; ─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#&gt;  package           * version  date (UTC) lib source
#&gt;  Amelia            * 1.8.3    2024-11-08 [1] CRAN (R 4.6.1)
#&gt;  bayesplot         * 1.16.0   2026-08-25 [1] CRAN (R 4.6.1)
#&gt;  blogdown          * 1.24     2026-06-19 [1] CRAN (R 4.6.1)
#&gt;  boot              * 1.3-32   2025-08-29 [1] CRAN (R 4.6.1)
#&gt;  bootImpute        * 1.3.0    2025-12-15 [1] CRAN (R 4.6.1)
#&gt;  brms              * 2.23.0   2025-09-09 [1] CRAN (R 4.6.1)
#&gt;  broom             * 1.0.13   2026-05-14 [1] CRAN (R 4.6.1)
#&gt;  broom.mixed       * 0.2.9.7  2026-02-17 [1] CRAN (R 4.6.1)
#&gt;  Cairo             * 1.7-0    2025-10-29 [1] CRAN (R 4.6.1)
#&gt;  car               * 3.1-5    2026-02-03 [1] CRAN (R 4.6.1)
#&gt;  carData           * 3.0-6    2026-01-30 [1] CRAN (R 4.6.1)
#&gt;  checkmate         * 2.3.4    2026-02-03 [1] CRAN (R 4.6.1)
#&gt;  cli               * 3.6.6    2026-04-09 [1] CRAN (R 4.6.1)
#&gt;  coda              * 0.19-4.1 2024-01-31 [1] CRAN (R 4.6.1)
#&gt;  colorspace        * 2.1-3    2026-07-12 [1] CRAN (R 4.6.1)
#&gt;  concurve          * 3.0.5    2026-09-13 [1] local
#&gt;  cowplot           * 1.2.0    2025-07-07 [1] CRAN (R 4.6.1)
#&gt;  doParallel        * 1.0.17   2022-02-07 [1] CRAN (R 4.6.1)
#&gt;  dplyr             * 1.2.1    2026-04-03 [1] CRAN (R 4.6.1)
#&gt;  forcats           * 1.0.1    2025-09-25 [1] CRAN (R 4.6.1)
#&gt;  foreach           * 1.5.2    2022-02-02 [1] CRAN (R 4.6.1)
#&gt;  futile.logger     * 1.4.9    2025-12-29 [1] CRAN (R 4.6.0)
#&gt;  future            * 1.75.0   2026-07-20 [1] CRAN (R 4.6.1)
#&gt;  future.apply      * 1.20.2   2026-02-20 [1] CRAN (R 4.6.1)
#&gt;  gamlss            * 5.5-0    2025-08-19 [1] CRAN (R 4.6.1)
#&gt;  gamlss.data       * 6.0-7    2025-09-04 [1] CRAN (R 4.6.1)
#&gt;  gamlss.dist       * 6.1-11   2026-09-10 [1] CRAN (R 4.6.1)
#&gt;  ggcorrplot        * 0.3.0    2026-07-24 [1] CRAN (R 4.6.1)
#&gt;  ggplot2           * 4.0.3    2026-04-22 [1] CRAN (R 4.6.1)
#&gt;  ggtext            * 0.2.0    2026-08-28 [1] CRAN (R 4.6.1)
#&gt;  gtsummary         * 2.6.1    2026-09-04 [1] CRAN (R 4.6.1)
#&gt;  here              * 1.0.2    2025-09-15 [1] CRAN (R 4.6.1)
#&gt;  Hmisc             * 5.3-0    2026-09-06 [1] CRAN (R 4.6.1)
#&gt;  htmltools         * 0.5.9    2025-12-04 [1] CRAN (R 4.6.1)
#&gt;  ImputeRobust      * 1.3-1    2018-11-30 [1] CRAN (R 4.6.1)
#&gt;  iterators         * 1.0.14   2022-02-05 [1] CRAN (R 4.6.1)
#&gt;  kableExtra        * 1.4.1    2026-07-08 [1] CRAN (R 4.6.1)
#&gt;  knitr             * 1.52     2026-09-06 [1] CRAN (R 4.6.1)
#&gt;  latex2exp         * 0.9.8    2026-01-09 [1] CRAN (R 4.6.1)
#&gt;  lattice           * 0.23-1   2026-08-12 [1] CRAN (R 4.6.1)
#&gt;  loo               * 2.10.1   2026-07-24 [1] CRAN (R 4.6.1)
#&gt;  lubridate         * 1.9.5    2026-02-04 [1] CRAN (R 4.6.1)
#&gt;  magrittr          * 2.0.5    2026-04-04 [1] CRAN (R 4.6.1)
#&gt;  MASS              * 7.3-66   2026-07-15 [1] CRAN (R 4.6.1)
#&gt;  Matrix            * 1.7-6    2026-07-25 [1] CRAN (R 4.6.1)
#&gt;  MCMCpack          * 1.7-1    2024-08-27 [1] CRAN (R 4.6.1)
#&gt;  mgcv              * 1.9-4    2025-11-07 [1] CRAN (R 4.6.0)
#&gt;  mi                * 1.3.1    2026-07-28 [1] CRAN (R 4.6.1)
#&gt;  mice              * 3.19.0   2025-12-10 [1] CRAN (R 4.6.1)
#&gt;  miceadds          * 3.20-10  2026-05-28 [1] CRAN (R 4.6.1)
#&gt;  miceFast          * 0.9.1    2026-02-26 [1] CRAN (R 4.6.1)
#&gt;  missForest        * 1.6.1    2025-10-26 [1] CRAN (R 4.6.1)
#&gt;  mitml             * 0.4-5    2023-03-08 [1] CRAN (R 4.6.1)
#&gt;  mvtnorm           * 1.4-2    2026-07-12 [1] CRAN (R 4.6.1)
#&gt;  nlme              * 3.1-171  2026-09-01 [1] CRAN (R 4.6.1)
#&gt;  parallelly        * 1.48.0   2026-06-29 [1] CRAN (R 4.6.1)
#&gt;  pbmcapply         * 1.5.1    2022-04-28 [1] CRAN (R 4.6.1)
#&gt;  performance       * 0.18.2   2026-09-10 [1] CRAN (R 4.6.1)
#&gt;  posterior         * 1.7.0    2026-04-01 [1] CRAN (R 4.6.1)
#&gt;  ProfileLikelihood * 1.3      2023-08-25 [1] CRAN (R 4.6.1)
#&gt;  progress          * 1.2.3    2023-12-06 [1] CRAN (R 4.6.1)
#&gt;  purrr             * 1.2.2    2026-04-10 [1] CRAN (R 4.6.1)
#&gt;  qqplotr           * 0.0.7    2025-09-05 [1] CRAN (R 4.6.1)
#&gt;  quantreg          * 6.1      2025-03-10 [1] CRAN (R 4.6.1)
#&gt;  randomForest      * 4.7-1.2  2024-09-22 [1] CRAN (R 4.6.1)
#&gt;  Rcpp              * 1.1.2    2026-07-05 [1] CRAN (R 4.6.1)
#&gt;  readr             * 2.2.0    2026-02-19 [1] CRAN (R 4.6.1)
#&gt;  reshape2          * 1.4.5    2025-11-12 [1] CRAN (R 4.6.1)
#&gt;  reticulate        * 1.47.0   2026-09-03 [1] CRAN (R 4.6.1)
#&gt;  rmarkdown         * 2.32     2026-09-01 [1] CRAN (R 4.6.1)
#&gt;  rms               * 8.1-1    2026-02-18 [1] CRAN (R 4.6.1)
#&gt;  rstan             * 2.32.7   2025-03-10 [1] CRAN (R 4.6.1)
#&gt;  showtext          * 0.9-8    2026-03-21 [1] CRAN (R 4.6.1)
#&gt;  showtextdb        * 3.0      2020-06-04 [1] CRAN (R 4.6.1)
#&gt;  SparseM           * 1.84-2   2024-07-17 [1] CRAN (R 4.6.1)
#&gt;  StanHeaders       * 2.39.1   2026-09-02 [1] CRAN (R 4.6.1)
#&gt;  Statamarkdown     * 1.0.0    2026-08-21 [1] CRAN (R 4.6.1)
#&gt;  stringr           * 1.6.0    2025-11-04 [1] CRAN (R 4.6.1)
#&gt;  svglite           * 2.2.2    2025-10-21 [1] CRAN (R 4.6.1)
#&gt;  sysfonts          * 0.8.9    2024-03-02 [1] CRAN (R 4.6.1)
#&gt;  texPreview        * 2.1.0    2024-01-24 [1] CRAN (R 4.6.0)
#&gt;  tibble            * 3.3.1    2026-01-11 [1] CRAN (R 4.6.1)
#&gt;  tidybayes         * 3.0.7    2024-09-15 [1] CRAN (R 4.6.1)
#&gt;  tidyr             * 1.3.2    2025-12-19 [1] CRAN (R 4.6.1)
#&gt;  tidyverse         * 2.0.0    2023-02-22 [1] CRAN (R 4.6.1)
#&gt;  tinytex           * 0.60     2026-06-16 [1] CRAN (R 4.6.1)
#&gt;  tryCatchLog       * 1.3.3    2025-12-04 [1] CRAN (R 4.6.0)
#&gt;  VIM               * 7.3.1    2026-09-11 [1] CRAN (R 4.6.1)
#&gt;  wesanderson       * 0.3.7    2023-10-31 [1] CRAN (R 4.6.1)
#&gt;  xfun              * 0.60     2026-07-09 [1] CRAN (R 4.6.1)
#&gt;  xtable            * 1.8-8    2026-02-22 [1] CRAN (R 4.6.1)
#&gt;  yardstick         * 1.4.0    2026-04-07 [1] CRAN (R 4.6.1)
#&gt; 
#&gt;  [1] /opt/homebrew/lib/R/4.6/site-library
#&gt;  [2] /opt/homebrew/Cellar/r/4.6.1/lib/R/library
#&gt;  * ── Packages attached to the search path.
#&gt; 
#&gt; ─ External software ────────────────────────────────────────────────────────────────────────────────────────────────────────────
#&gt;  setting        value
#&gt;  cairo          1.18.4
#&gt;  cairoFT        2.14.3/2.18.1
#&gt;  pango
#&gt;  png
#&gt;  jpeg
#&gt;  tiff
#&gt;  tcl            9.0
#&gt;  curl           8.7.1
#&gt;  zlib           1.2.12
#&gt;  bzlib          1.0.8, 13-Jul-2019
#&gt;  xz             5.8.3
#&gt;  deflate
#&gt;  zstd           1.5.7
#&gt;  PCRE           10.48 2026-08-31
#&gt;  ICU            78.1
#&gt;  TRE            TRE 0.8.0 R_fixes (BSD)
#&gt;  iconv          Apple or GNU libiconv 1.11 /usr/lib/libiconv.2.dylib
#&gt;  readline       8.3
#&gt;  BLAS           /opt/homebrew/Cellar/openblas/0.3.34/lib/libopenblasp-r0.3.34.dylib
#&gt;  lapack         /opt/homebrew/Cellar/r/4.6.1/lib/R/lib/libRlapack.dylib
#&gt;  lapack_version 3.12.1
#&gt; 
#&gt; ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#&gt; Quarto: 1.10.18
#&gt; pandoc: 3.8
#&gt; knitr engines: awk, bash, coffee, gawk, groovy, haskell, lein, mysql, node, octave, perl, php, psql, Rscript, ruby, sas, scala, sed, sh, stata, zsh, asis, asy, block, block2, bslib, c, cat, cc, comment, css, ditaa, dot, embed, eviews, exec, fortran, fortran95, go, highlight, js, julia, python, R, Rcpp, sass, scss, sql, stan, targets, tikz, verbatim, ojs, mermaid, glue, glue_sql, gluesql, details, texpreview</code></pre>
</div>
<hr>
</section>
<section id="stata" class="level5">
<h5 class="anchored" data-anchor-id="stata">Stata Environment</h5>
<hr>
<div class="cell" data-layout-align="center" data-collectcode="true" data-statapath="/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb48" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb48-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">linesize</span> 255</span>
<span id="cb48-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">display</span> %tcMonth_dd,CCYY_hh:MM_am now()</span>
<span id="cb48-3">about</span>
<span id="cb48-4">ado <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">dir</span></span>
<span id="cb48-5">#&gt; file ()<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">print</span>() <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> found</span>
<span id="cb48-6">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(601);</span>
<span id="cb48-7">#&gt; </span>
<span id="cb48-8">#&gt; </span>
<span id="cb48-9">#&gt; </span>
<span id="cb48-10">#&gt; September 16,2026 12:37 pm</span>
<span id="cb48-11">#&gt; </span>
<span id="cb48-12">#&gt; </span>
<span id="cb48-13">#&gt; StataNow/MP 19.5 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> Mac (Apple Silicon)</span>
<span id="cb48-14">#&gt; Revision 12 Aug 2026</span>
<span id="cb48-15">#&gt; Copyright 1985-2025 StataCorp LLC</span>
<span id="cb48-16">#&gt; </span>
<span id="cb48-17">#&gt; Total physical <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">memory</span>: 48.01 GB</span>
<span id="cb48-18">#&gt; </span>
<span id="cb48-19">#&gt; Stata license: Single-user 2-core , expiring  6 Feb 2027</span>
<span id="cb48-20">#&gt; Serial number: 501909358563</span>
<span id="cb48-21">#&gt;   Licensed to: Zad Rafi</span>
<span id="cb48-22">#&gt;                </span>
<span id="cb48-23">#&gt; </span>
<span id="cb48-24">#&gt; </span>
<span id="cb48-25">#&gt; [1] package parallel from http:<span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//fmwww.bc.edu/repec/bocode/p</span></span>
<span id="cb48-26">#&gt;       'PARALLEL': module <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> Parallel Computing</span>
<span id="cb48-27">#&gt; </span>
<span id="cb48-28">#&gt; [2] package svalue from http:<span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//fmwww.bc.edu/RePEc/bocode/s</span></span>
<span id="cb48-29">#&gt;       'SVALUE': module <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> computing and graphically displaying S-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">values</span> against their respective P-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">values</span></span>
<span id="cb48-30">#&gt; </span>
<span id="cb48-31">#&gt; [3] package cifunction from http:<span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//fmwww.bc.edu/RePEc/bocode/c</span></span>
<span id="cb48-32">#&gt;       'CIFUNCTION': module <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> computing and graphically displaying <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">all</span> possible confidence intervals around a point estimate</span>
<span id="cb48-33">#&gt; </span>
<span id="cb48-34">#&gt; [4] package getregstats from http:<span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//fmwww.bc.edu/RePEc/bocode/g</span></span>
<span id="cb48-35">#&gt;       'GETREGSTATS': module <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> computing <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">all</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">values</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> a regression <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">table</span> when only the coefficient and one other statistic is available</span>
<span id="cb48-36">#&gt; </span>
<span id="cb48-37">#&gt; [5] package gr0072_2 from http:<span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//www.stata-journal.com/software/sj25-4</span></span>
<span id="cb48-38">#&gt;       SJ25-4 gr0072_2. Update: Nice axis labels <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> ...</span>
<span id="cb48-39">#&gt; </span>
<span id="cb48-40">#&gt; [6] package grstyle from http:<span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//fmwww.bc.edu/repec/bocode/g</span></span>
<span id="cb48-41">#&gt;       'GRSTYLE': module to customize the overall look <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> graphs</span>
<span id="cb48-42">#&gt; </span>
<span id="cb48-43">#&gt; [7] package palettes from http:<span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//fmwww.bc.edu/repec/bocode/p</span></span>
<span id="cb48-44">#&gt;       'PALETTES': module to provide <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">color</span> palettes, symbol palettes, and <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">line</span> pattern palettes</span></code></pre></div></div>
</div>
<hr>
</section>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<hr>


<!-- -->


</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><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" data-entry-spacing="2" data-line-spacing="2">
<div id="ref-Stark2018-eo" class="csl-entry">
1. Stark PB, Saltelli A. (2018). <span>“Cargo-cult statistics and scientific crisis.”</span> <em>Significance</em>. <strong>15</strong>:40–43. doi: <a href="https://doi.org/10.1111/j.1740-9713.2018.01174.x">10.1111/j.1740-9713.2018.01174.x</a>.
</div>
<div id="ref-gigerenzerStatisticalRitualsReplication2018" class="csl-entry">
2. Gigerenzer G. (2018). <span>“Statistical <span>Rituals</span>: <span>The Replication Delusion</span> and <span>How We Got There</span>.”</span> <em>Advances in Methods and Practices in Psychological Science</em>. <strong>1</strong>:198–218. doi: <a href="https://doi.org/10.1177/2515245918771329">10.1177/2515245918771329</a>.
</div>
<div id="ref-Greenland2017-es" class="csl-entry">
3. Greenland S. (2017). <span>“Invited commentary: <span>The</span> need for cognitive science in methodology.”</span> <em>American Journal of Epidemiology</em>. <strong>186</strong>:639–645. doi: <a href="https://doi.org/10.1093/aje/kwx259">10.1093/aje/kwx259</a>.
</div>
<div id="ref-greenlandMultipleBiasModelling2005" class="csl-entry">
4. Greenland S. (2005). <span>“Multiple-bias modelling for analysis of observational data.”</span> <em>Journal of the Royal Statistical Society Series A (Statistics in Society)</em>. <strong>168</strong>:267–306. doi: <a href="https://doi.org/10.1111/j.1467-985X.2004.00349.x">10.1111/j.1467-985X.2004.00349.x</a>.
</div>
<div id="ref-greenlandBiasAnalysis2008" class="csl-entry">
5. Greenland S, Lash TL. (2008). <span>“Bias analysis.”</span> In: Rothman KJ, Greenland S, Lash TL, editors. Modern <span>Epidemiology</span>. 3rd edition. <span>Lippincott Williams &amp; Wilkins</span>. p. 345–380.
</div>
<div id="ref-lashApplyingQuantitativeBias2009" class="csl-entry">
6. Lash TL, Fox MP, Fink AK. (2009). <span>“Applying <span>Quantitative Bias Analysis</span> to <span>Epidemiologic Data</span>.”</span> <span>Springer New York</span>.
</div>
<div id="ref-lashGoodPracticesQuantitative2014" class="csl-entry">
7. Lash TL, Fox MP, MacLehose RF, Maldonado G, McCandless LC, Greenland S. (2014). <span>“Good practices for quantitative bias analysis.”</span> <em>International Journal of Epidemiology</em>. <strong>43</strong>:1969–1985. doi: <a href="https://doi.org/10.1093/ije/dyu149">10.1093/ije/dyu149</a>.
</div>
<div id="ref-lashBiasAnalysisGone2021" class="csl-entry">
8. Lash TL, Ahern TP, Collin LJ, Fox MP, MacLehose RF. (2021). <span>“Bias <span>Analysis Gone Bad</span>.”</span> <em>American Journal of Epidemiology</em>. doi: <a href="https://doi.org/10.1093/aje/kwab072">10.1093/aje/kwab072</a>.
</div>
<div id="ref-gustafsonInvitedCommentaryBetter2021" class="csl-entry">
9. Gustafson P. (2021). <span>“Invited <span>Commentary</span>: <span>Toward Better Bias Analysis</span>.”</span> <em>American Journal of Epidemiology</em>. doi: <a href="https://doi.org/10.1093/aje/kwab068">10.1093/aje/kwab068</a>.
</div>
<div id="ref-greenlandDealingInevitableDeficiencies2021" class="csl-entry">
10. Greenland S. (2021). <span>“Dealing with the <span>Inevitable Deficiencies</span> of <span>Bias Analysis</span> and <span>All Analyses</span>.”</span> <em>American Journal of Epidemiology</em>. doi: <a href="https://doi.org/10.1093/aje/kwab069">10.1093/aje/kwab069</a>.
</div>
<div id="ref-molenberghsHandbookMissingData2014" class="csl-entry">
11. Molenberghs G, Fitzmaurice G, Kenward MG, Tsiatis A, Verbeke G. (2014). <span>“Handbook of <span>Missing Data Methodology</span>.”</span> <span>CRC Press</span>.
</div>
<div id="ref-scottMulticentreAneurysmScreening2002" class="csl-entry">
12. Scott RaP. (2002). <span>“The <span>Multicentre Aneurysm Screening Study</span> (<span>MASS</span>) into the effect of abdominal aortic aneurysm screening on mortality in men: A randomised controlled trial.”</span> <em>The Lancet</em>. <strong>360</strong>:1531–1539. doi: <a href="https://doi.org/10.1016/S0140-6736(02)11522-4">10.1016/S0140-6736(02)11522-4</a>.
</div>
<div id="ref-morrisChoosingSensitivityAnalyses2014" class="csl-entry">
13. Morris TP, Kahan BC, White IR. (2014). <span>“Choosing sensitivity analyses for randomised trials: principles.”</span> <em>BMC Medical Research Methodology</em>. <strong>14</strong>:11. doi: <a href="https://doi.org/10.1186/1471-2288-14-11">10.1186/1471-2288-14-11</a>.
</div>
<div id="ref-mostellerDataAnalysisIncluding1987" class="csl-entry">
14. Mosteller F, Tukey JW. (1987). <span>“Data analysis including statistics.”</span> In: The <span>Collected Works</span> of <span>John W</span>. <span>Tukey</span>: <span>Philosophy</span> and <span>Principles</span> of <span>Data Analysis</span> 1965-1986. <span>CRC Press</span>.
</div>
<div id="ref-akachaEstimandsTheirRole2017" class="csl-entry">
15. Akacha M, Bretz F, Ohlssen D, Rosenkranz G, Schmidli H. (2017). <span>“Estimands and <span>Their Role</span> in <span>Clinical Trials</span>.”</span> <em>Statistics in Biopharmaceutical Research</em>. <strong>9</strong>:268–271. doi: <a href="https://doi.org/10.1080/19466315.2017.1302358">10.1080/19466315.2017.1302358</a>.
</div>
<div id="ref-permuttCovariatesChangeEstimand2020" class="csl-entry">
16. Permutt T. (2020). <span>“Do <span>Covariates Change</span> the <span>Estimand</span>?”</span> <em>Statistics in Biopharmaceutical Research</em>. <strong>12</strong>:45–53. doi: <a href="https://doi.org/10.1080/19466315.2019.1647874">10.1080/19466315.2019.1647874</a>.
</div>
<div id="ref-mitroiuNarrativeReviewEstimands2020" class="csl-entry">
17. Mitroiu M, Oude Rengerink K, Teerenstra S, Pétavy F, Roes KCB. (2020). <span>“A narrative review of estimands in drug development and regulatory evaluation: Old wine in new barrels?”</span> <em>Trials</em>. <strong>21</strong>:671. doi: <a href="https://doi.org/10.1186/s13063-020-04546-1">10.1186/s13063-020-04546-1</a>.
</div>
<div id="ref-littlePreventionTreatmentMissing2012" class="csl-entry">
18. Little RJ, D’Agostino R, Cohen ML, Dickersin K, Emerson SS, Farrar JT, et al. (2012). <span>“The <span>Prevention</span> and <span>Treatment</span> of <span>Missing Data</span> in <span>Clinical Trials</span>.”</span> <em>New England Journal of Medicine</em>. <strong>367</strong>:1355–1360. doi: <a href="https://doi.org/10.1056/NEJMsr1203730">10.1056/NEJMsr1203730</a>.
</div>
<div id="ref-chenClinicalTrialData2017" class="csl-entry">
19. Chen D-G(Din), Peace KE, Zhang P. (2017). <span>“Clinical trial data analysis using r and SAS.”</span> 2nd edition. Chapman; Hall/CRC. doi: <a href="https://doi.org/10.1201/9781315155104">10.1201/9781315155104</a>.
</div>
<div id="ref-buurenFlexibleImputationMissing2018" class="csl-entry">
20. Buuren S van. (2018). <span>“Flexible <span>Imputation</span> of <span>Missing Data</span>, <span>Second Edition</span>.”</span> <span>CRC Press</span>.
</div>
<div id="ref-mengPerformingLikelihoodRatio1992" class="csl-entry">
21. Meng X-L, Rubin DB. (1992). <span>“Performing <span>Likelihood Ratio Tests</span> with <span>Multiply</span>-<span>Imputed Data Sets</span>.”</span> <em>Biometrika</em>. <strong>79</strong>:103–111. doi: <a href="https://doi.org/10.2307/2337151">10.2307/2337151</a>.
</div>
<div id="ref-schenkerPartiallyParametricTechniques1996" class="csl-entry">
22. Schenker N, Taylor J. (1996). <span>“Partially parametric techniques for multiple imputation.”</span> <em>Computational Statistics &amp; Data Analysis</em>. <strong>22</strong>:425–446. doi: <a href="https://doi.org/10.1016/0167-9473(95)00057-7">10.1016/0167-9473(95)00057-7</a>.
</div>
<div id="ref-permuttSensitivityAnalysisMissing2016" class="csl-entry">
23. Permutt T. (2016). <span>“Sensitivity analysis for missing data in regulatory submissions.”</span> <em>Statistics in Medicine</em>. <strong>35</strong>:2876–2879. doi: <a href="https://doi.org/10.1002/sim.6753">10.1002/sim.6753</a>.
</div>
<div id="ref-jolaniDualImputationStrategies2012" class="csl-entry">
24. Jolani S. (2012). <span>“Dual <span>Imputation Strategies</span> for <span>Analyzing Incomplete Data</span>.”</span>
</div>
<div id="ref-vonhippelMaximumLikelihoodMultiple2019" class="csl-entry">
25. <span class="nocase">von Hippel PT, Bartlett J</span>. (2019). <span>“Maximum likelihood multiple imputation: <span>Faster</span> imputations and consistent standard errors without posterior draws.”</span> <em>arXiv:12100870 [stat]</em>. <a href="https://arxiv.org/abs/1210.0870">https://arxiv.org/abs/1210.0870</a>.
</div>
<div id="ref-rafiSemanticCognitiveTools2020" class="csl-entry">
26. Rafi Z, Greenland S. (2020). <span>“Semantic and cognitive tools to aid statistical science: Replace confidence and significance by compatibility and surprise.”</span> <em>BMC Medical Research Methodology</em>. <strong>20</strong>:244. doi: <a href="https://doi.org/10.1186/s12874-020-01105-9">10.1186/s12874-020-01105-9</a>.
</div>
<div id="ref-greenlandAidScientificInference2020" class="csl-entry">
27. Greenland S, Rafi Z. (2020). <span>“To <span>Aid Scientific Inference</span>, <span>Emphasize Unconditional Descriptions</span> of <span>Statistics</span>.”</span> <em>arXiv:190908583 [statME]</em>. <a href="https://arxiv.org/abs/1909.08583">https://arxiv.org/abs/1909.08583</a>.
</div>
</div></section><section class="quarto-appendix-contents" id="quarto-citation"><h2 class="anchored quarto-appendix-heading">Citation</h2><div><div class="quarto-appendix-secondary-label">BibTeX citation:</div><pre class="sourceCode code-with-copy quarto-appendix-bibtex"><code class="sourceCode bibtex">@online{rafi2020,
  author = {Rafi, Zad and Panda, Sir},
  title = {What {Makes} a {Sensitivity} {Analysis?}},
  date = {2020-12-12},
  url = {https://lesslikely.com/statistics/sensitivity.html},
  langid = {en-US}
}
</code></pre></div></section></div> ]]></description>
  <category>statistics</category>
  <guid>https://lesslikely.com/statistics/sensitivity.html</guid>
  <pubDate>Sat, 12 Dec 2020 05:00:00 GMT</pubDate>
  <media:content url="https://lesslikely.com/images/sensitivity.png" medium="image" type="image/png" height="122" width="144"/>
</item>
</channel>
</rss>
