<?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>Statistical science, applied to medicine and nutrition — the quiet arithmetic of being wrong less often.</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>Wed, 16 Sep 2026 04:00:00 GMT</lastBuildDate>
<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 P-value reports one number about one hypothesis. The <em>P-value function</em> reports the same test statistic applied to <strong>every</strong> candidate parameter value at once — and it contains every compatibility interval at every level as horizontal slices.<sup>1</sup> Nothing below is new mathematics. It is the same normal approximation you already use, drawn in full instead of evaluated at one point.</p>
<div class="no-row-height column-margin column-container"><div id="fn1"><p><sup>1</sup>&nbsp;Slice the curve at height <img src="https://latex.codecogs.com/png.latex?p%20=%200.05"> and read off the x-coordinates: those are the 95% limits. Slice at <img src="https://latex.codecogs.com/png.latex?p%20=%200.01"> and you have the 99% limits. The interval was never a separate calculation.</p></div></div><p>The display is 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. What has changed is that it now costs nothing to render, and that we have a better vocabulary for the vertical axis: <strong>compatibility</strong> rather than confidence, and <strong>surprisal</strong> rather than 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 — a horizontal slice through the curve, not a separate object.</p>
</div>
</div>
<section id="the-explorer" class="level2">
<h2 class="anchored" data-anchor-id="the-explorer">The explorer</h2>
<p>Move the sliders. Everything recomputes in the browser — no server, no round trip.</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>The S-value exists because “P = 0.05” carries no intuition and “significant” carries the wrong one. Bits do carry intuition, because everyone has a physical model of coin flipping. Drag μ above and watch the coins.</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 surprise <em>at the whole model</em>, not at <img src="https://latex.codecogs.com/png.latex?%5Cmu"> alone. Every bit is also a bit against the assumed absence of uncontrolled confounding, selection effects, measurement error, and model form. A large S-value says the data are hard to reconcile with the conjunction of <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and everything else you assumed; it does not tell you which conjunct to abandon. 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>Look at the point estimates before you look at anything else.</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. What actually changed between them is not the estimate — it is the width of the interval, which grows from a ratio of 1.9 to 5.4 across the three adjusted analyses as each trades precision for stronger confounding control. The verdicts flip; the estimate does not move.</p>
<p>The published conclusion was that exposure “was not associated with” autism. That sentence is doing work the arithmetic will not support: 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>Uncheck the crude analysis and the remaining three curves are near-concentric: same peak, different width. That is the shape of a precision problem, not a disagreement about effect size. Now 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>Set the slider to 1.5 and all four analyses agree: <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. The analysis that was “not significant” and the analysis that was “significant” are, against this hypothesis, 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. Reporting only that test, and only its dichotomised outcome, discards the answer to every other question the same data address — including 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: 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 parameter value are separate things that a single P-value fuses into one number. Hold the IPT-weighted estimate fixed and vary only the 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 is the study as published. Push <img src="https://latex.codecogs.com/png.latex?k"> to 4 and the null falls well outside the 95% interval without the estimate having moved a hair. Pull <img src="https://latex.codecogs.com/png.latex?k"> down to 0.3 and the same estimate becomes compatible with almost everything between 0.7 and 3.9.</p>
<p>This is worth sitting with, because it is the mechanism behind most “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 number 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 models <em>random</em> error only. Multiplying the sample size by 16 does nothing to confounding, selection, or measurement error — 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. A very narrow curve centred in the wrong place is the most confident way to be wrong. If you want that quantified rather than assumed away, the tool is bias analysis, not more subjects.</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>“Study A was significant, study B was not, so they disagree” is a comparison of two verdicts, not of two estimates. The comparison that answers the question is a curve in its own right: 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. 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 (<img src="https://latex.codecogs.com/png.latex?P%20=%200.051">) and B at 1.05 (<img src="https://latex.codecogs.com/png.latex?P%20=%200.684">) — the two studies land on opposite sides of the conventional threshold. Their ratio of ratios is 1.53, 95% interval 0.90 to 2.61, and the difference carries 3.1 bits of information: fewer than the 4.3 bits the 0.05 convention itself demands, and fewer than four coin flips. Two verdicts that disagree, one comparison that does not.</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. Use this widget for genuinely independent studies. For nested analyses of one data set, the honest summary is the overlay itself: 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. It is still 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 precisely where the S-value is most informative. Two stacked panels sharing an x-axis cost one extra inch of page and 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 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 because that is the conventional test value, not because it is 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 is the binding constraint.</li>
<li><strong>No normality diagnostics.</strong> Every curve here assumes the log estimate is approximately normal with the reported standard error. That is the same assumption the published interval already made; the curve does not add it, it only makes it 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>The same idea applied to tabular results — searchable and sortable by clicking 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 a hypothesis you 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>Nothing above requires a new statistic, a new threshold, or a new software stack. It requires four sentences you can paste into a results section:</p>
<ol type="1">
<li>Report the estimate and interval <strong>without</strong> the word “significant” — “HR 1.61, 95% compatibility interval 0.997 to 2.59”.</li>
<li>Report the P-value <strong>as a number</strong>, not as an inequality against 0.05, and say what 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, that is the finding.</li>
<li>Say that the interval and P-value are conditional on the <strong>entire</strong> model, not just on the parameter.</li>
</ol>
<p>If a reviewer asks for the significance verdict back, the curve is the reply: it contains their verdict as one horizontal slice, plus 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>Three things people associate with Gwern’s pages are Quarto defaults and 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;The convention that 0.05 marks a boundary is worth pricing in bits: it is 4.32 bits of information against the tested hypothesis, or roughly the surprise of four consecutive heads. Few people 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>Wed, 16 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>Three constructions, six languages, one inferential object. The likelihood function, its deviance transform, the <em>P</em>-value (compatibility) function, and the <em>S</em>-value function are coordinate views of the same thing; a script that can build one can build them all. 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>A silent run means 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 variations of likelihood which, of which one we touch on. To see a clear expalanation of the differences between these various likelihood, see<span class="citation" data-cites="cole2013 coxPrinciplesStatisticalInference2006"><sup>1, 2</sup></span></p>
<section id="maximum-likelihood-from-scratch" class="level1">
<h1>Maximum likelihood from scratch</h1>
<p>Fit a normal linear model and a logistic regression by writing the log-likelihood yourself and maximizing it, then check against the built-in estimator. The one trick used everywhere: parameterize with <img src="https://latex.codecogs.com/png.latex?%5Cln%5Csigma"> so 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: <code>optim</code> on a hand-written negative log-likelihood, checked 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; file ()print() not found
#&gt; r(601);
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&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 =    200
#&gt;                                                         Wald chi2(1)  =  72.77
#&gt; Log likelihood = -342.99235                             Prob &gt; chi2   = 0.0000
#&gt; 
#&gt; ------------------------------------------------------------------------------
#&gt;            y | Coefficient  Std. err.      z    P&gt;|z|     [95% conf. interval]
#&gt; -------------+----------------------------------------------------------------
#&gt; mu           |
#&gt;            x |   .8119551   .0951852     8.53   0.000     .6253954    .9985147
#&gt;        _cons |   1.868002   .0954381    19.57   0.000     1.680947    2.055057
#&gt; -------------+----------------------------------------------------------------
#&gt; lnsigma      |
#&gt;        _cons |   .2960232        .05     5.92   0.000      .198025    .3940214
#&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 =    300
#&gt;                                                         Wald chi2(1)  =  28.32
#&gt; Log likelihood = -187.34499                             Prob &gt; chi2   = 0.0000
#&gt; 
#&gt; ------------------------------------------------------------------------------
#&gt;            y | Coefficient  Std. err.      z    P&gt;|z|     [95% conf. interval]
#&gt; -------------+----------------------------------------------------------------
#&gt;            x |   .7507449   .1410829     5.32   0.000     .4742275    1.027262
#&gt;        _cons |  -.3434135    .124075    -2.77   0.006     -.586596    -.100231
#&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>Note: current Optim.jl rejects the old <code>autodiff = :forward</code> symbol (it now wants an <code>ADTypes</code> object); the default finite-difference gradient is version-robust and plenty here. The trailing semicolons are load-bearing for the <em>output</em>, not 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. Three kinds of line are deliberately left unsuppressed, because what they echo is worth reading – 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>; with no toolbox, <code>fminsearch</code> (Nelder–Mead, base MATLAB) reaches the same optimum more slowly. 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>
<span id="cb5-43">#<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">Part</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">A</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">validation</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">PASSED</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;">MLE</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">reproduces</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">backslash</span></span>
<span id="cb5-44">#<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">Part</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;">validation</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">PASSED</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;">MLE</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">reproduces</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">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 <em>are</em> the ML estimates – <code>REGR_SLOPE</code> and <code>REGR_INTERCEPT</code> – and grid search plays the role of the optimizer. The chunks below <strong>execute at render time</strong> against an in-process DuckDB seeded in the setup chunk, so every number on this page is query output rather than a transcription. The dialect is ANSI where it counts; the Snowflake originals differ only in how 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>The estimates are real query output. Pulling the same rows into R confirms SQL is computing the maximum likelihood fit and not something adjacent to 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="level1">
<h1>Likelihood function from summary statistics</h1>
<p>A point estimate and a 95% interval on the ratio scale are enough to reconstruct the whole function: recover the standard error from the interval width, lay down a grid, and 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="">Julia</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="">MATLAB</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="">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><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-7-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><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"></a></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; file ()print() not found
#&gt; r(601);
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&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 =    200
#&gt;                                                         Wald chi2(1)  =  72.77
#&gt; Log likelihood = -342.99235                             Prob &gt; chi2   = 0.0000
#&gt; 
#&gt; ------------------------------------------------------------------------------
#&gt;            y | Coefficient  Std. err.      z    P&gt;|z|     [95% conf. interval]
#&gt; -------------+----------------------------------------------------------------
#&gt; mu           |
#&gt;            x |   .8119551   .0951852     8.53   0.000     .6253954    .9985147
#&gt;        _cons |   1.868002   .0954381    19.57   0.000     1.680947    2.055057
#&gt; -------------+----------------------------------------------------------------
#&gt; lnsigma      |
#&gt;        _cons |   .2960232        .05     5.92   0.000      .198025    .3940214
#&gt; ------------------------------------------------------------------------------
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; check: ML slope  =  0.811955  OLS slope  =  0.811955
#&gt; 
#&gt; check: ML sigma  =  1.344501  OLS sigma (n-scaled) =  1.344501
#&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 =    300
#&gt;                                                         Wald chi2(1)  =  28.32
#&gt; Log likelihood = -187.34499                             Prob &gt; chi2   = 0.0000
#&gt; 
#&gt; ------------------------------------------------------------------------------
#&gt;            y | Coefficient  Std. err.      z    P&gt;|z|     [95% conf. interval]
#&gt; -------------+----------------------------------------------------------------
#&gt;            x |   .7507449   .1410829     5.32   0.000     .4742275    1.027262
#&gt;        _cons |  -.3434135    .124075    -2.77   0.006     -.586596    -.100231
#&gt; ------------------------------------------------------------------------------
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; check: ml slope =  0.750745  logit slope =  0.750745
#&gt; 
#&gt; check: ml ll    =  -187.344987  logit ll    =  -187.344987
#&gt; 
#&gt; 
#&gt; 
#&gt; Part B validation PASSED: ml reproduces logit
#&gt; 
#&gt; 
#&gt; All maximum likelihood constructions validated.</code></pre>
</div>
<section id="the-inverse-route-sweeping-levels-instead-of-parameters-with-cifunction" class="level1">
<h1>The inverse route: sweeping levels instead of parameters with <code>cifunction</code></h1>
<p>Everything above builds the curve by sweeping the <strong>parameter</strong> axis: 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. There is a second route to the same object that works from the other side: sweep the <strong>confidence level</strong> from 0 to 99.99% and compute the interval limits at each level. Plotting the limits against the levels traces exactly the same curve – 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 simultaneously. Ariel Linden’s <a href="https://lesslikely.com/statistics/cifunction/"><code>cifunction</code></a> Stata module implements the level-sweeping construction directly; the R equivalent is <a href="https://github.com/zadrafi/concurve">concurve</a>. Install once from SSC:</p>
<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 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;">ssc</span> install cifunction</span>
<span id="cb10-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>One convention to respect: 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 back-transforms. Same Brown et al.&nbsp;example as above, with the saved output asserted against both the reported interval and the manual z-grid construction: ## Python</p>
<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 python code-with-copy"><code class="sourceCode python"><span id="cb11-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="cb11-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="cb11-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="cb11-4"></span>
<span id="cb11-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="cb11-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="cb11-7"></span>
<span id="cb11-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="cb11-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="cb11-10"></span>
<span id="cb11-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="cb11-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="cb11-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="cb11-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="cb11-15"></span>
<span id="cb11-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="cb11-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="cb11-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="cb11-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="cb11-20"></span>
<span id="cb11-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="cb11-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="cb11-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="cb11-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="cb11-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="cb11-26">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative Likelihood Function"</span>)</span>
<span id="cb11-27">plt.show()</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-10-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-2"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-10-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</section>
</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="cb12" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb12-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="cb12-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gr</span>();</span>
<span id="cb12-3"></span>
<span id="cb12-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="cb12-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="cb12-6"></span>
<span id="cb12-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="cb12-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="cb12-9"></span>
<span id="cb12-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="cb12-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="cb12-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="cb12-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="cb12-14"></span>
<span id="cb12-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="cb12-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="cb12-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="cb12-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="cb12-19"></span>
<span id="cb12-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="cb12-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="cb12-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="cb12-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="cb12-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="cb12-25">p</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-11-J1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-3"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-11-J1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="300"></a></p>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-2-4" class="tab-pane" aria-labelledby="tabset-2-4-tab">
<p><code>normcdf</code> needs the Statistics Toolbox; 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="cb13" style="background: #f1f3f5;"><pre class="sourceCode matlab code-with-copy"><code class="sourceCode matlab"><span id="cb13-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="cb13-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="cb13-3"></span>
<span id="cb13-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="cb13-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="cb13-6"></span>
<span id="cb13-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="cb13-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="cb13-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="cb13-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="cb13-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="cb13-12"></span>
<span id="cb13-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="cb13-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="cb13-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="cb13-16"></span>
<span id="cb13-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="cb13-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="cb13-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="cb13-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="cb13-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="cb13-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="cb13-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>
<span id="cb13-24">#<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">validation</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">PASSED</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6.83</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">LI</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;">95</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% CI</span></span></code></pre></div></div>
<p><a href="likelihood-polyglot_files/figure-html/matlab-summary-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-4"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/matlab-summary-1.png" class="img-fluid"></a></p>
</div>
</div>
<div id="tabset-2-5" class="tab-pane" aria-labelledby="tabset-2-5-tab">
<p>Neither Snowflake nor DuckDB ships <code>erf()</code>, so <img src="https://latex.codecogs.com/png.latex?%5CPhi"> uses 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; it returns a table, and something else draws 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="cb14" style="background: #f1f3f5;"><pre class="sourceCode sql code-with-copy"><code class="sourceCode sql"><span id="cb14-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="cb14-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="cb14-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="cb14-4">),</span>
<span id="cb14-5">grid <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb14-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="cb14-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="cb14-8">),</span>
<span id="cb14-9">lik <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb14-10">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> g.hr,</span>
<span id="cb14-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="cb14-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="cb14-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="cb14-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="cb14-15">),</span>
<span id="cb14-16">pv <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb14-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="cb14-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="cb14-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="cb14-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="cb14-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="cb14-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="cb14-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="cb14-24">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">FROM</span> lik</span>
<span id="cb14-25">)</span>
<span id="cb14-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="cb14-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 it returns is <img src="https://latex.codecogs.com/png.latex?%5B1.0025,%202.5918%5D"> against 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="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">          FROM grid g CROSS JOIN params p),</span></span>
<span id="cb15-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  pv AS (SELECT hr, z, support, deviance,</span></span>
<span id="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">         FROM lik)</span></span>
<span id="cb15-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="cb15-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  FROM pv ORDER BY hr;"</span>)</span>
<span id="cb15-18"></span>
<span id="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-32"></span>
<span id="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-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="cb15-40">}</span>
<span id="cb15-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="cb15-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="cb15-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="cb15-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><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-13-4.png" class="lightbox" data-gallery="quarto-lightbox-gallery-5"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-13-4.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></a></p>
</figure>
</div>
</div>
<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;">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">. Reading the bottom-right panel: the S-value there is 4.27 bits – about as much evidence against the null as five straight heads, which is not much.</p>
</div>
</div>
</div>
</section>
<section id="profile-likelihood-for-a-regression-coefficient" class="level1">
<h1>Profile likelihood for a regression coefficient</h1>
<p>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">, 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 – that is what makes it a <em>profile</em> likelihood rather than 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="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-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="cb17-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="cb17-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="cb17-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="cb17-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="cb17-6"></span>
<span id="cb17-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="cb17-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="cb17-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="cb17-10"></span>
<span id="cb17-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="cb17-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="cb17-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="cb17-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="cb17-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="cb17-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="cb17-17"></span>
<span id="cb17-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="cb17-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="cb17-20"></span>
<span id="cb17-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="cb17-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="cb17-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="cb17-24"></span>
<span id="cb17-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="cb17-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="cb17-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="cb17-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="cb17-29"></span>
<span id="cb17-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="cb17-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="cb17-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="cb17-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="cb17-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="cb17-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><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-14-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-6"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-14-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></a></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; file ()print() not found
#&gt; r(601);
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; Number of observations (_N) was 0, now 300.
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; 
#&gt; (file /tmp/S_70849.000001 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><a href="profile_likelihood_logit.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-7"><img src="https://lesslikely.com/statistics/profile_likelihood_logit.svg" class="img-fluid"></a></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="cb19" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb19-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="cb19-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="cb19-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="cb19-4"></span>
<span id="cb19-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="cb19-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="cb19-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="cb19-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="cb19-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="cb19-10"></span>
<span id="cb19-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="cb19-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="cb19-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="cb19-14">X_nuis <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sm.add_constant(w)</span>
<span id="cb19-15"></span>
<span id="cb19-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="cb19-17">ll <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.array([</span>
<span id="cb19-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="cb19-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="cb19-20">])</span>
<span id="cb19-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="cb19-22"></span>
<span id="cb19-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="cb19-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="cb19-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="cb19-26"></span>
<span id="cb19-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="cb19-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="cb19-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="cb19-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="cb19-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="cb19-32">ax.set_ylabel(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative likelihood"</span>)</span>
<span id="cb19-33">ax.set_title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Profile Likelihood Function"</span>)</span>
<span id="cb19-34">plt.show()</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-16-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-8"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-16-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></a></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="cb20" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb20-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="cb20-2"></span>
<span id="cb20-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="cb20-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="cb20-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="cb20-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="cb20-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="cb20-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="cb20-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 300×3 DataFrame</span></span>
<span id="cb20-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Row │ y        x            w</span></span>
<span id="cb20-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;      │ Float64  Float64      Float64</span></span>
<span id="cb20-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ─────┼──────────────────────────────────</span></span>
<span id="cb20-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="cb20-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="cb20-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="cb20-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="cb20-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="cb20-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="cb20-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="cb20-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="cb20-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   ⋮  │    ⋮          ⋮           ⋮</span></span>
<span id="cb20-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="cb20-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="cb20-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="cb20-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="cb20-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="cb20-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="cb20-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="cb20-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                         285 rows omitted</span></span>
<span id="cb20-30"></span>
<span id="cb20-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="cb20-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="cb20-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb20-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; y ~ 1 + x + w</span></span>
<span id="cb20-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb20-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Coefficients:</span></span>
<span id="cb20-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ─────────────────────────────────────────────────────────────────────────</span></span>
<span id="cb20-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="cb20-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ─────────────────────────────────────────────────────────────────────────</span></span>
<span id="cb20-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="cb20-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="cb20-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="cb20-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ─────────────────────────────────────────────────────────────────────────</span></span>
<span id="cb20-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="cb20-45"></span>
<span id="cb20-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="cb20-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="cb20-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="cb20-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="cb20-50"></span>
<span id="cb20-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="cb20-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="cb20-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="cb20-54"></span>
<span id="cb20-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="cb20-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="cb20-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="cb20-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="cb20-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="cb20-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="cb20-61">p</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-17-J1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-9"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-17-J1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="300"></a></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: 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 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="cb21" style="background: #f1f3f5;"><pre class="sourceCode matlab code-with-copy"><code class="sourceCode matlab"><span id="cb21-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="cb21-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="cb21-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="cb21-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="cb21-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="cb21-6"></span>
<span id="cb21-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="cb21-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="cb21-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="cb21-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="cb21-11"></span>
<span id="cb21-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="cb21-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="cb21-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="cb21-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="cb21-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="cb21-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="cb21-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="cb21-19"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb21-20"></span>
<span id="cb21-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="cb21-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="cb21-23"></span>
<span id="cb21-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="cb21-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="cb21-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="cb21-27"></span>
<span id="cb21-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="cb21-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="cb21-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="cb21-31"></span>
<span id="cb21-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="cb21-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="cb21-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="cb21-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="cb21-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="cb21-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="cb21-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>
<span id="cb21-39">#<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">validation</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">PASSED</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;">profile</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">peak</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;">full</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;">model</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">MLE</span></span>
<span id="cb21-40">#<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="va" style="color: #111111;
background-color: null;
font-style: inherit;">support</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">interval</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.4246</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.9635</span>]   <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">Wald</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">95</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% CI: [0.4116, 0.9579]</span></span></code></pre></div></div>
<p><a href="likelihood-polyglot_files/figure-html/matlab-profile-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-10"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/matlab-profile-1.png" class="img-fluid"></a></p>
</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, so it cancels in <code>ll - max(ll)</code> – which is all 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 (no IRLS), so a logistic profile is out of scope. But 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, so profiling collapses to one <code>AVG</code> per candidate slope – a <code>GROUP BY</code>, not a refit loop. The profile-grid MLE matches <code>REGR_SLOPE</code> exactly here – the peak and the closed form agree to the last printed digit, since both are computed from the same rows. (Dialect landmine: Snowflake rejects correlated scalar subqueries here; the <code>CROSS JOIN</code> + <code>GROUP BY</code> below is the working idiom.)</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 sql code-with-copy"><code class="sourceCode sql"><span id="cb22-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="cb22-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="cb22-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-- closed-form. No refit loop, no IRLS.</span></span>
<span id="cb22-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="cb22-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="cb22-6">),</span>
<span id="cb22-7">m <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb22-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="cb22-9">),</span>
<span id="cb22-10">grid <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb22-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="cb22-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="cb22-13">),</span>
<span id="cb22-14">prof <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">AS</span> (</span>
<span id="cb22-15">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> g.b_cand,</span>
<span id="cb22-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="cb22-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="cb22-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="cb22-19">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">FROM</span> grid g</span>
<span id="cb22-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="cb22-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="cb22-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="cb22-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="cb22-24">)</span>
<span id="cb22-25"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">SELECT</span> b_cand,</span>
<span id="cb22-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="cb22-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 hand the result set to whatever draws your charts – here, R:</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 r code-with-copy"><code class="sourceCode r"><span id="cb23-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="cb23-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="cb23-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="cb23-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="cb23-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="cb23-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  prof AS (</span></span>
<span id="cb23-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    SELECT g.b_cand,</span></span>
<span id="cb23-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="cb23-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="cb23-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="cb23-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    GROUP BY g.b_cand, c.n)</span></span>
<span id="cb23-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="cb23-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  FROM prof ORDER BY b_cand;"</span>)</span>
<span id="cb23-14"></span>
<span id="cb23-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="cb23-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="cb23-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="cb23-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="cb23-19"></span>
<span id="cb23-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="cb23-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="cb23-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="cb23-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="cb23-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="cb23-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="cb23-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="cb23-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="cb23-28"></span>
<span id="cb23-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="cb23-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="cb23-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="cb23-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="cb23-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="cb23-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="cb23-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="cb23-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="cb23-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><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-19-4.png" class="lightbox" data-gallery="quarto-lightbox-gallery-11"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-19-4.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></a></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, which is the same identity the R, Python, and Julia sections check – here with every number produced by a <code>GROUP BY</code>.</p>
</div>
</div>
</div>
</section>
<section id="existing-r-tools-as-alternatives" class="level1">
<h1>Existing R tools as alternatives</h1>
<p>Everything above builds the likelihood by hand. In R you usually do not have to: several packages will do the maximizing and profiling for you, and their output reshapes into the same five-column object <code>concurve</code> plots. The one helper below is all the glue needed. 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> for the longer treatment.</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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(concurve)</span>
<span id="cb24-2"></span>
<span id="cb24-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="cb24-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="cb24-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="cb24-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="cb24-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="cb24-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values        =</span> values,</span>
<span id="cb24-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">likelihood    =</span> support,</span>
<span id="cb24-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">loglikelihood =</span> loglik_rel,</span>
<span id="cb24-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">support       =</span> support,</span>
<span id="cb24-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="cb24-13">  )</span>
<span id="cb24-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="cb24-15">  df</span>
<span id="cb24-16">}</span>
<span id="cb24-17"></span>
<span id="cb24-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="cb24-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="cb24-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="cb24-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; mean   sd </span></span>
<span id="cb24-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>Base R, no dependencies. <code>optim</code> finds the MLE and the Hessian gives Wald standard errors. To <em>profile</em> <img src="https://latex.codecogs.com/png.latex?%5Cmu">, substitute the conditional MLE of <img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2"> at each grid point rather than 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="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-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="cb25-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="cb25-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="cb25-4">}</span>
<span id="cb25-5"></span>
<span id="cb25-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="cb25-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="cb25-8">fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>par</span>
<span id="cb25-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    mu sigma </span></span>
<span id="cb25-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  9.41  2.93</span></span>
<span id="cb25-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="cb25-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;    mu sigma </span></span>
<span id="cb25-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 0.415 0.293</span></span>
<span id="cb25-14"></span>
<span id="cb25-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="cb25-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="cb25-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="cb25-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="cb25-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="cb25-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="cb25-21"></span>
<span id="cb25-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="cb25-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="cb25-24"></span>
<span id="cb25-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="cb25-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="cb25-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><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-21-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-12"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-21-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></a></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="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(maxLik)</span>
<span id="cb26-2"></span>
<span id="cb26-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="cb26-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="cb26-5">}</span>
<span id="cb26-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="cb26-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(theta_mle)</span>
<span id="cb26-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; --------------------------------------------</span></span>
<span id="cb26-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Maximum Likelihood estimation</span></span>
<span id="cb26-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Newton-Raphson maximisation, 7 iterations</span></span>
<span id="cb26-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="cb26-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Log-Likelihood: -125 </span></span>
<span id="cb26-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 2  free parameters</span></span>
<span id="cb26-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Estimates:</span></span>
<span id="cb26-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="cb26-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="cb26-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="cb26-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ---</span></span>
<span id="cb26-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="cb26-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; --------------------------------------------</span></span>
<span id="cb26-21"></span>
<span id="cb26-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="cb26-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="cb26-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="cb26-25"></span>
<span id="cb26-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="cb26-27"></span>
<span id="cb26-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="cb26-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="cb26-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="cb26-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><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-22-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-13"><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"></a></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 profiles for you. <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="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>(bbmle)</span>
<span id="cb27-2"></span>
<span id="cb27-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="cb27-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="cb27-5"></span>
<span id="cb27-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="cb27-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="cb27-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="cb27-9"></span>
<span id="cb27-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="cb27-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="cb27-12"></span>
<span id="cb27-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="cb27-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="cb27-15"></span>
<span id="cb27-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="cb27-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="cb27-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><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-23-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-14"><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"></a></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 carrying many nuisance parameters, <code>cond</code> gives <em>exact conditional</em> likelihood inference: it conditions the nuisance parameters out instead of profiling them.</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>(cond)</span>
<span id="cb28-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(babies)</span>
<span id="cb28-3"></span>
<span id="cb28-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="cb28-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="cb28-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="cb28-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(cond_fit)</span>
<span id="cb28-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb28-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="cb28-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Family:  binomial</span></span>
<span id="cb28-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Offset:  lullyes</span></span>
<span id="cb28-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb28-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;           Estimate   Std. Error </span></span>
<span id="cb28-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; uncond.        1.43        0.734</span></span>
<span id="cb28-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; cond.          1.27        0.689</span></span>
<span id="cb28-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb28-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Confidence intervals</span></span>
<span id="cb28-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; --------------------</span></span>
<span id="cb28-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  level = 95 %</span></span>
<span id="cb28-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                                            lower two-sided upper</span></span>
<span id="cb28-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Wald pivot                              -0.00651            2.87</span></span>
<span id="cb28-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="cb28-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Likelihood root                          0.12300            3.09</span></span>
<span id="cb28-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="cb28-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="cb28-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb28-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; Diagnostics:</span></span>
<span id="cb28-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; ----------- </span></span>
<span id="cb28-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   INF    NP </span></span>
<span id="cb28-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; 0.076 0.289 </span></span>
<span id="cb28-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb28-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  Approximation based on 20 points</span></span>
<span id="cb28-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><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-24-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-15"><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"></a></p>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
<section id="the-pitfall-slicing-is-not-profiling" class="level2">
<h2 class="anchored" data-anchor-id="the-pitfall-slicing-is-not-profiling">The pitfall: slicing is not profiling</h2>
<p>Fixing a nuisance parameter instead of re-maximizing it is the most common way to get this wrong. Holding <img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2%20=%201"> here yields a likelihood far too narrow, because the real <img src="https://latex.codecogs.com/png.latex?%5Csigma"> is about 3.2 — the interval it implies is roughly a third of the honest width:</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">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="cb29-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="cb29-3"></span>
<span id="cb29-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="cb29-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="cb29-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="cb29-7">}</span>
<span id="cb29-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="cb29-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   slice_width profile_width </span></span>
<span id="cb29-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;         0.554         1.658</span></span>
<span id="cb29-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="cb29-12"></span>
<span id="cb29-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="cb29-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="cb29-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="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;">"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><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-25-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-16"><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"></a></p>
</figure>
</div>
</div>
</div>
</section>
<section id="profile-likelihood-from-profilelikelihood" class="level2">
<h2 class="anchored" data-anchor-id="profile-likelihood-from-profilelikelihood">Profile likelihood from <code>ProfileLikelihood</code></h2>
<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 all four coordinate views from the top of this post off a single fit. The 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="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>(ProfileLikelihood)</span>
<span id="cb30-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(dataglm)</span>
<span id="cb30-3"></span>
<span id="cb30-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="cb30-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="cb30-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="cb30-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="cb30-8"></span>
<span id="cb30-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="cb30-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="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"></span>
<span id="cb31-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="cb31-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="cb31-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="cb31-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="cb31-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="cb31-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>The same object, 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="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-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><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-27-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-17"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-27-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></a></p>
</figure>
</div>
</div>
<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;">"l2"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-27-2.png" class="lightbox" data-gallery="quarto-lightbox-gallery-18"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-27-2.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></a></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;">"l3"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-27-3.png" class="lightbox" data-gallery="quarto-lightbox-gallery-19"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-27-3.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></a></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;">"d"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-27-4.png" class="lightbox" data-gallery="quarto-lightbox-gallery-20"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-27-4.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</section>
<section id="profile-versus-wald-and-where-the-16.83-interval-lands" class="level2">
<h2 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</h2>
<p><code>curve_lik_glm</code> profiles a coefficient directly. Comparing it against the Wald normal approximation on the same grid shows the skew the Wald interval discards — and 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="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-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="cb36-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="cb36-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="cb36-4"></span>
<span id="cb36-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="cb36-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="cb36-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="cb36-8"></span>
<span id="cb36-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="cb36-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="cb36-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="cb36-12"></span>
<span id="cb36-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="cb36-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="cb36-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="cb36-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="cb36-17">)</span>
<span id="cb36-18">out</span>
<span id="cb36-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;                        lower.limit upper.limit</span></span>
<span id="cb36-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="cb36-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="cb36-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="cb36-23"></span>
<span id="cb36-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="cb36-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="cb36-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="cb36-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>The profile curve leans right of the symmetric Wald curve, and that lean is precisely what 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="cb37" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-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="cb37-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><a href="likelihood-polyglot_files/figure-html/unnamed-chunk-29-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-21"><img src="https://lesslikely.com/statistics/likelihood-polyglot_files/figure-html/unnamed-chunk-29-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
</section>
</section>
<section id="profile-likelihood-for-a-regression-coefficient-1" class="level1">
<h1>Profile likelihood for a regression coefficient</h1>
<p>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">, 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 – that is what makes it a <em>profile</em> likelihood rather than 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-5-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-5-1" aria-controls="tabset-5-1" aria-selected="true" href="">Stata</a></li></ul>
<div class="tab-content">
<div id="tabset-5-1" class="tab-pane active" aria-labelledby="tabset-5-1-tab">
<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 stata code-with-copy"><code class="sourceCode stata"><span id="cb38-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">version</span> 16</span>
<span id="cb38-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="cb38-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="cb38-4"></span>
<span id="cb38-5"><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> 300</span>
<span id="cb38-6"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">generate</span> x = rnormal(0, 1)</span>
<span id="cb38-7"><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;">w</span> = rnormal(0, 1)                       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// nuisance covariate</span></span>
<span id="cb38-8"><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> = runiform() &lt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">invlogit</span>(-0.3 + 0.8*x + 0.4*<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span>)</span>
<span id="cb38-9"></span>
<span id="cb38-10">* full <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">fit</span>: the MLE and Wald <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;">define</span> the <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span></span>
<span id="cb38-11"><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;">logit</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</span> x <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">w</span></span>
<span id="cb38-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scalar</span> bhat  = _b[x]</span>
<span id="cb38-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scalar</span> sehat = _se[x]</span>
<span id="cb38-14"></span>
<span id="cb38-15">* <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span>: MLE +/- 4 SEs, 121 points (each point costs one -<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">logit</span>- refit)</span>
<span id="cb38-16"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">local</span> npts  = 121</span>
<span id="cb38-17"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">local</span> blo   = bhat - 4*sehat</span>
<span id="cb38-18"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">local</span> bstep = 8*sehat / (<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`npts'</span> - 1)</span>
<span id="cb38-19"></span>
<span id="cb38-20"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">tempname</span> results</span>
<span id="cb38-21"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">tempfile</span> profile</span>
<span id="cb38-22"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">postfile</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`results'</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">double</span>(beta ll) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">using</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"`profile'"</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span></span>
<span id="cb38-23"></span>
<span id="cb38-24"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">forvalues</span> i = 1/<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`npts'</span> {</span>
<span id="cb38-25">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">local</span> b = <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`blo'</span> + (<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;">`bstep'</span></span>
<span id="cb38-26">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">capture</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">drop</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">off</span></span>
<span id="cb38-27">    <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;">generate</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">double</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">off</span> = <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`b'</span>*x</span>
<span id="cb38-28">    <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;">logit</span> <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;">w</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">offset</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">off</span>)</span>
<span id="cb38-29">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">post</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`results'</span> (<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`b'</span>) (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">e</span>(ll))</span>
<span id="cb38-30">}</span>
<span id="cb38-31"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">postclose</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`results'</span></span>
<span id="cb38-32"></span>
<span id="cb38-33"><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;">"`profile'"</span>, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb38-34"></span>
<span id="cb38-35">* normalize into support / deviance</span>
<span id="cb38-36"><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> ll</span>
<span id="cb38-37"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">generate</span> support  = <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(ll - <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>))</span>
<span id="cb38-38"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">generate</span> deviance = -2*(ll - <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>))</span>
<span id="cb38-39"></span>
<span id="cb38-40">* --- validation 1: profile peak sits <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">at</span> the full-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">model</span> MLE ---</span>
<span id="cb38-41"><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> beta <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> support == 1</span>
<span id="cb38-42"><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="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_n</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"profile peak = "</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> result %9.6f <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 class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-43">    <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;">"   full-model MLE = "</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> result %9.6f bhat</span>
<span id="cb38-44"><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>(<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>) - bhat) &lt; <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`bstep'</span>   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// within one grid step</span></span>
<span id="cb38-45"></span>
<span id="cb38-46">* --- validation 2: 1/6.83 support interval ~ Wald 95% CI ---</span>
<span id="cb38-47"><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> beta <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> support &gt;= 1/6.83</span>
<span id="cb38-48"><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;">"1/6.83 support interval: ["</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> result %6.4f <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-49">    <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;">", "</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> result %6.4f <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</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;">"]"</span>                    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-50">    <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;">"   Wald 95% CI: ["</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> result %6.4f bhat - 1.96*sehat      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-51">    <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;">", "</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> result %6.4f bhat + 1.96*sehat <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;">"]"</span></span>
<span id="cb38-52">* profile and Wald agree closely here (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">smooth</span> likelihood, moderate n);</span>
<span id="cb38-53">* they diverge exactly <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> much <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">as</span> the likelihood is skewed</span>
<span id="cb38-54"><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>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>) - (bhat - 1.96*sehat)) &lt; 3*<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`bstep'</span></span>
<span id="cb38-55"><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>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>) - (bhat + 1.96*sehat)) &lt; 3*<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`bstep'</span></span>
<span id="cb38-56"><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: profile peak and support interval check out"</span></span>
<span id="cb38-57"></span>
<span id="cb38-58">* --- plots ---</span>
<span id="cb38-59"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">twoway</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">line</span> support beta),                                            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-60">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xline</span>(<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`=bhat'</span>, lpattern(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">dash</span>) lcolor(gs10))                        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-61">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xline</span>(0, lpattern(<span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">dot</span>) lcolor(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">red</span>))                                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-62">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">yline</span>(0.1464, lcolor(gs12))                                        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-63">    <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;">"Profile Likelihood Function for a Logistic Coefficient"</span>)    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-64">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">subtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Nuisance parameters re-maximized at each grid point"</span>)    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-65">    <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;">"Coefficient of x (log-odds scale)"</span>)                        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-66">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">ytitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative Likelihood"</span>) <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span>(prof_lik, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span>)</span>
<span id="cb38-67"></span>
<span id="cb38-68"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">twoway</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">line</span> deviance beta),                                           <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-69">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">xline</span>(<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">`=bhat'</span>, lpattern(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">dash</span>) lcolor(gs10))                        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-70">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">yline</span>(3.84, lcolor(gs12))                                          <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-71">    <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;">"Profile Deviance Function"</span>)                                 <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-72">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">subtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Horizontal line at 3.84; crossings = 95% profile CI"</span>)    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-73">    <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;">"Coefficient of x (log-odds scale)"</span>)                        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">///</span></span>
<span id="cb38-74">    <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">ytitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Profile Deviance"</span>) <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span>(prof_dev, <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">replace</span>)</span>
<span id="cb38-75"></span>
<span id="cb38-76"><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> prof_lik prof_dev, <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">cols</span>(2)</span>
<span id="cb38-77">#&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="cb38-78">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(601);</span>
<span id="cb38-79">#&gt; </span>
<span id="cb38-80">#&gt; </span>
<span id="cb38-81">#&gt; </span>
<span id="cb38-82">#&gt; </span>
<span id="cb38-83">#&gt; </span>
<span id="cb38-84">#&gt; Number <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">of</span> observations (_N) was 0, now 300.</span>
<span id="cb38-85">#&gt; </span>
<span id="cb38-86">#&gt; </span>
<span id="cb38-87">#&gt; </span>
<span id="cb38-88">#&gt; </span>
<span id="cb38-89">#&gt; </span>
<span id="cb38-90">#&gt; </span>
<span id="cb38-91">#&gt; </span>
<span id="cb38-92">#&gt; </span>
<span id="cb38-93">#&gt; </span>
<span id="cb38-94">#&gt; </span>
<span id="cb38-95">#&gt; </span>
<span id="cb38-96">#&gt; </span>
<span id="cb38-97">#&gt; (file /tmp/S_76071.000001 <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> found)</span>
<span id="cb38-98">#&gt; </span>
<span id="cb38-99">#&gt; </span>
<span id="cb38-100">#&gt; </span>
<span id="cb38-101">#&gt; </span>
<span id="cb38-102">#&gt; </span>
<span id="cb38-103">#&gt; </span>
<span id="cb38-104">#&gt; </span>
<span id="cb38-105">#&gt; </span>
<span id="cb38-106">#&gt; </span>
<span id="cb38-107">#&gt; profile peak =  0.748198   full-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">model</span> MLE =  0.748198</span>
<span id="cb38-108">#&gt; </span>
<span id="cb38-109">#&gt; </span>
<span id="cb38-110">#&gt; </span>
<span id="cb38-111">#&gt; 1/6.83 support interval: [0.4730, 1.0430]   Wald 95% CI: [0.4593, 1.0371]</span>
<span id="cb38-112">#&gt; </span>
<span id="cb38-113">#&gt; </span>
<span id="cb38-114">#&gt; </span>
<span id="cb38-115">#&gt; validation PASSED: profile peak and support interval check out</span></code></pre></div></div>
</div>
<section id="validation-status" class="level1">
<h1>Validation status</h1>
<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="level1">
<h1>Package Citations</h1>
<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.0.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.0.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="level1">
<h1>Statistical Environments</h1>
<hr>
<section id="r-environment" class="level4">
<h4 class="anchored" data-anchor-id="r-environment">R Environment</h4>
<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
#&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;  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.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;  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-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;  duckdb              1.5.5      2026-07-25 [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;  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.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;  maxLik            * 1.5-2.2    2025-12-29 [1] CRAN (R 4.6.0)
#&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.0.0      2026-08-21 [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.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; ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#&gt; $RNGkind
#&gt; [1] "Mersenne-Twister" "Inversion"        "Rejection"</code></pre>
</div>
<hr>
</section>
<section id="stata-environment" class="level4">
<h4 class="anchored" data-anchor-id="stata-environment">Stata Environment</h4>
<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; 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="cb41-5">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(601);</span>
<span id="cb41-6">#&gt; </span>
<span id="cb41-7">#&gt; </span>
<span id="cb41-8">#&gt; </span>
<span id="cb41-9">#&gt;  September 13,2026 5:39 am</span>
<span id="cb41-10">#&gt; </span>
<span id="cb41-11">#&gt; </span>
<span id="cb41-12">#&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-13">#&gt; Revision 12 Aug 2026</span>
<span id="cb41-14">#&gt; Copyright 1985-2025 StataCorp LLC</span>
<span id="cb41-15">#&gt; </span>
<span id="cb41-16">#&gt; Total physical <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">memory</span>: 48.01 GB</span>
<span id="cb41-17">#&gt; </span>
<span id="cb41-18">#&gt; Stata license: Single-user 2-core , expiring  6 Feb 2027</span>
<span id="cb41-19">#&gt; Serial number: 501909358563</span>
<span id="cb41-20">#&gt;   Licensed to: Zad Rafi</span>
<span id="cb41-21">#&gt; </span></code></pre></div></div>
</div>
<hr>
</section>
</section>
<section id="references" class="level1">
<h1>References</h1>
</section>
</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-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-16},
  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>Wed, 16 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 failed projects are not failures due to technical matters, but failures of a good collaboration. They fail earlier, in the part nobody writes up: a question that was never pinned down, a column whose meaning changed in 2023, a “quick pull” that quietly became the number in the board deck. The statistician gets blamed for the estimate and the data engineer gets blamed for the pipeline, but 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>consulting the statistician after the experiment is finished is often merely asking him to perform 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>This is a piece about the habits that keep the patient alive. It is deliberately two-sided. Collaborators owe analysts specific things; analysts owe collaborators specific things back, and “the data wasn’t clean” is not 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>The intuition that a well-specified question has one obvious analysis is wrong, and it is wrong by a measurable amount.</p>
<p>In the best-known demonstration, 29 teams comprising 61 analysts were given the same dataset and the same question — whether soccer referees give more red cards to dark-skin-toned players. The 29 analyses used 21 unique combinations of covariates. Estimated effects ranged from an odds ratio of 0.89 to 2.93, median 1.31; 20 teams (69%) reported a statistically significant positive effect and 9 (31%) did not. Neither 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. <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>The lesson is not that analysis is arbitrary. It is that <strong>the analysis is underdetermined by the question</strong>, and 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 your 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 your contribution as a collaborator — supplying context that narrows the defensible choice set — is not a courtesy. It is part of the estimate.</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 design, not at submission.</strong> The single highest-leverage change is temporal. 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, precisely 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 consulted at design can change the sample size. A statistician consulted at submission can only change the adjectives.</p>
<p><strong>State the estimand before the method.</strong> Not “can you run a regression,” but: what quantity, in what population, under what contrast, with what handling of intercurrent events. If you cannot say it in a sentence, that is the finding, and it is worth knowing before you collect data.</p>
<p><strong>Disclose everything you already looked at.</strong> Selective reporting is not a moral failing you have to confess; it is a fact about the data-generating process that changes what the numbers mean. An analyst who learns on submission day that you already ran eleven subgroup comparisons has been handed a different problem than 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 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 being paid by the hour.</p>
<p><strong>Accept that the honest answer may be “this design can’t answer that.”</strong> The most valuable thing a statistician does is sometimes to tell you your study is not powered to detect what you care about. Treating this as obstruction rather than information is how you 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, not 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 lets the analyst tell you the first request would have misled you — because, say, the comp-store definition excludes the exact stores you’re evaluating.<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 are two correct calculations of two different things. 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 feeding a pricing change deserve different levels of scrutiny, and analysts cannot calibrate effort they cannot see. Tell them the blast radius.</p>
<p><strong>Give real deadlines and real slack.</strong> “EOD” for a request that requires joining three source systems is not a deadline; it is a request for an unvalidated guess with your name on it.</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 your business logic is inconsistent, usually at 2 a.m. Treat their constraints as physics, not preferences.</p>
<p><strong>Send the reproduction, not the vibe.</strong> “The dashboard looks off” costs an engineer hours. “Row for store 412, 2026-07-14, shows fuel gallons of 0 but the POS extract shows 8,431 — here’s the query” costs minutes.</p>
<p><strong>A defect report has four parts, and “something is wrong” is none of them.</strong> Telling an engineer or statistician that a number is wrong 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 collaborators most often skip, because it feels like doing the engineer’s job. It is the opposite: you are the only person who <em>knows</em> the rule. The engineer can translate a rule into SQL in an afternoon; they cannot conjure the rule itself, and if forced to guess, you have just delegated your business logic to the person with the least context for it — which is how the definition-drift problem below gets minted 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 — every one of these breaks something downstream. The cost of a two-line heads-up is roughly zero. The cost of discovering it via a silently wrong report is not.</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 people have already quoted externally.</p>
<p><strong>Stop building shadow pipelines.</strong> The spreadsheet you maintain because the official table was inconvenient will eventually be cited in a meeting as a source of truth, and someone will have to reconcile it. If the official table is wrong, file that as a defect rather than routing around it.</p>
<p><strong>Treat data quality as a shared problem, not a service-desk ticket.</strong> In dbt Labs’ 2025 practitioner survey (459 respondents, collected October–December 2024 — a self-selected industry sample, not 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, which means it is mostly not within the data team’s control, which means it will not be fixed by escalating to the data team.</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 both directions, and this is where the genre usually goes soft.</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 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 technical correctness delivered incomprehensibly has an effect size of zero.</p>
<p><strong>Report uncertainty as uncertainty.</strong> Give the interval and the assumptions it rests on. Treating a P-value as a binary verdict rather than as continuous evidence throws away most of what the analysis produced — the case for <a href="../statistics/s-values">S-values</a> and the full <a href="../statistics/cifunction">compatibility/consonance function</a> rather than a single dichotomized interval.</p>
<p><strong>Say what would change your mind.</strong> Before running the analysis, state which results would be surprising and what you would do about them. This is the analyst-side equivalent of pre-registration and it is free.</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>, an analysis whose choices aren’t recorded is not a result — it’s an anecdote with decimal places. Code in version control, the query saved next to the number, 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 privately resents it for six weeks has chosen the worst available option.</p>
<p><strong>Explain the constraint, not just 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 a business partner can act on. “That’s not possible” is not.</p>
<hr>
</section>
<section id="everything-runs-on-assumptions-ledger-them-dont-launder-them" class="level2">
<h2 class="anchored" data-anchor-id="everything-runs-on-assumptions-ledger-them-dont-launder-them">Everything Runs on Assumptions — Ledger Them, Don’t Launder Them</h2>
<p>Every model is a bundle of <a href="../statistics/assumptions">assumptions</a>: linearity, exchangeability, missingness mechanisms, the proposition that the measurement instrument measures the thing. But so is everything else in the collaboration. You assume the chair holds, the laptop boots, the warehouse job ran last night, the engineer understood the ticket, the stakeholder meant what the ticket says. There is no assumption-free work — there is only work whose assumptions are written down and work whose assumptions are discovered later, at a worse time, by someone angrier.</p>
<p>The failure mode is not <em>making</em> assumptions. It is <em>laundering</em> them — letting them pass silently into the result so 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 precisely this: dozens of defensible assumption sets, each invisible in its own write-up, visible only when laid side by side.</p>
<p>So the practice, for both sides of the table, is a two-column discipline. For each assumption, 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> — which conclusions survive, which die, and what you’d check first.</li>
</ol>
<p>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 happen when you do this. First, most of the second column turns out to be checkable in minutes — the ledger converts vague dread into a short verification queue. Second, disagreements relocate to where they belong: not “your number is wrong” but “I don’t accept row three,” which is a conversation two professionals can actually finish. An assumption stated with its failure consequence is a hypothesis; an assumption left implicit is a landmine with your name on the deed.</p>
</section>
<section id="an-intake-template" class="level2">
<h2 class="anchored" data-anchor-id="an-intake-template">An Intake Template</h2>
<p>Put this at the top of every request. If it cannot be filled in, the work 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> Design is locked, data are collected, and the ask is to find something. See Fisher, above.</p>
<p><strong>The definition drift.</strong> Two teams, two correct numbers, one metric name. 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 becomes load-bearing; nobody remembers the filters six months later.</p>
<p><strong>The silent constraint.</strong> The analyst knows the design cannot support the claim, says so once, softly, in a meeting, and is not heard. Write it down. Writing it down is the whole technique.</p>
<p>None of this is sophisticated. That is rather the point: the returns to being a good collaborator come almost entirely from unglamorous, cheap, early habits, and almost not 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, warn about upstream changes — and, 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. Jones won by first-round submission. It was not particularly close.</p>
<p>Now imagine you had never seen Jones fight. You watched exactly one round of that contest and were asked: <em>what is the probability Jones wins this match?</em></p>
<p>If you’re a frequentist, you have 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. You cannot take a limit over one data point. So strictly speaking, the frequentist cannot assign a probability to this specific contest.</p>
<p>This is not a minor inconvenience. It is one of the oldest and most discussed objections in the philosophy of probability: the <em>single-case problem</em>, treated at length by Hájek (2009) and Gillies (2000).</p>
<p>But here is the thing: most people watching that fight thought Jones was a heavy favorite, and they were right. And they were right <em>in a way that a frequentist framework, properly applied, can actually explain</em> — just not in the way the objection implies.</p>
<p>The standard critique goes like this: frequentism requires repeatable experiments. A unique event — <em>this</em> fight, <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 not wrong as far as it goes. But it conflates two things: 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 is not claiming something about a unique unrepeatable event. It is claiming something 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. The probability is a statement about the <em>reference class</em>, not the individual.</p>
<p>This is exactly von Mises’s original framing: probability is always about collectives, not single instances. What we need is the right collective — and 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>
<p><callout type="note"> The numbers in this section come from market data, not controlled experiments. They describe the aggregate accuracy of odds-setters and bettors, not the underlying probability of any single fight. </callout></p>
<p>Across all UFC fights, favorites win somewhere in the range of 60 to 65 percent of the time — meaning underdogs pull off upsets in more than a third of all fights. That 35-to-40 percent upset rate is notably higher than 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 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>The market, in other words, <em>does</em> predict fight outcomes with meaningful accuracy when there is a genuine skill gap. It fails — or at least flattens — when the gap is small.</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 is the central claim, stated plainly: <strong>a fighter being more skilled than their opponent does not mean they win every fight.</strong> It means their <em>probability</em> of winning a single fight is greater than 0.5, perhaps substantially so. But a 70% win probability is also a 30% loss probability.</p>
<p>This is not a trivial point. It is, in miniature, the same confusion that afflicts applied researchers who treat a statistically meaningful estimate as proof that the effect always occurs. The estimate is about the distribution. The distribution is not the single draw.</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. But 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. A scramble on the mat can convert a dominant position into a finished fight in one second.</p>
<p>If you ran that version of GSP against a solid but beatable opponent ten times, you’d expect him to win eight or nine. In one fight, you’d expect him to win — but “expect” means something probabilistic, not certain.</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 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 rather than simply predicting a binary outcome. This matters because the outcome of a fight is not 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 you model it that way — as they did, comparing favorably to bookmaker odds — you are treating the fight as a sequence of probabilistic events from a well-defined class. The frequentist framework is doing real work. It is just applied at the level of <em>techniques and positions</em> rather than <em>whole fights</em>.</p>
<p>That is a defensible and scientifically useful construction. It is also, notably, the same move statisticians make in clinical medicine: you cannot run a randomized trial on a specific patient, but you can estimate their probability of response from a well-defined reference population and then apply 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 most analysts — and most fans — make is binary: the favorite “should” win, the underdog “shouldn’t,” and an upset is a surprise requiring explanation.</p>
<p>The better frame: a fight between a 70% favorite and a 30% underdog is <em>not</em> a fight with a predetermined outcome. It is a draw from a distribution with that shape. Three out of ten times, the underdog wins. That is not an upset requiring special explanation. That is the distribution working correctly.</p>
<p>An upset <em>does</em> warrant explanation if it happens at a rate <em>higher</em> than the odds imply — i.e., if the market is miscalibrated. The Fightful analysis of heavy favorites suggests the market is reasonably calibrated at the extremes, noisier in the middle.</p>
<p>The key methodological point: <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; fighters with fight-ending power but defensive liabilities have wide distributions. The outcome of one draw tells you something, but not 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.” One draw is 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 evidence, and end up with a posterior. For singular events, this is the most coherent framework — a posterior probability genuinely represents a degree of belief about <em>this specific contest</em>, not a reference class.</p>
<p>But the Bayesian approach faces its own problem in combat sports: you 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, the most useful approach is not doctrinal but instrumental: build the best reference class you 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 frequentism in practice — not a claim that probabilities don’t apply to single fights, but a demand that you 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 is genuinely less predictable than most sports. The upset rate is substantially higher than in major team sports, and the mechanisms are clear: it is a sport defined by rapid phase transitions (standup, clinch, ground), each carrying its own variance.</p>
<p>That unpredictability is not a bug in the analysis. It is a feature of the process. A skilled fighter’s edge is real and measurable in the aggregate — the betting market shows this plainly at heavy price differentials — but 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 researchers make when they treat a significant p-value as proof that the effect always occurs.</p>
<p>One fight is one trial. The distribution is real. The single draw tells you much less than you think.</p>
<hr>
<p><em>See also:</em> - <a href="../statistics/s-values.html"><em>Semantic and Cognitive Tools to Aid Statistical Science</em></a> — the case for replacing “significant” with “compatible” and describing what the data are more and less consistent with - <em>[TODO: link to another relevant post on inference under uncertainty]</em></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>This post demonstrates how to include Stata, Julia, and pseudocode in your 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>Stata code can be included for syntax highlighting:</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>Julia code for statistical computing:</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>
<div class="pseudocode-container quarto-float" data-line-number-punc=":" data-indent-lines="false" data-indent-size="1.2em" data-comment-delimiter="//" data-line-number="true" data-caption-prefix="Algorithm" data-pseudocode-number="1" data-no-end="false">
<div class="pseudocode">
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 β
</div>
</div>
</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 analysis looks across languages:</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="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-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="cb5-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="cb5-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="cb6" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-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="cb6-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="cb6-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="cb6-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="cb7" style="background: #f1f3f5;"><pre class="sourceCode stata code-with-copy"><code class="sourceCode stata"><span id="cb7-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">clear</span></span>
<span id="cb7-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="cb7-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="cb7-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="cb8" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-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="cb8-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="cb8-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="cb8-4">mean_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.mean(data)</span>
<span id="cb8-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="cb8-6">                      loc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>mean_val,</span>
<span id="cb8-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 just need to see the code</li>
<li><strong>Execute code sparingly</strong> - Only execute when output is essential</li>
<li><strong>Document your setup</strong> - Note required packages and versions</li>
<li><strong>Test before publishing</strong> - Ensure code runs without errors</li>
<li><strong>Provide context</strong> - Explain what the code does and why</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 multiple languages, you can now share statistical methods and algorithms in the language that best suits your analysis and audience.</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-dont-hold">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="level1">
<h1>The Power of the Bootstrap</h1>
<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="level2">
<h2 class="anchored" data-anchor-id="properties-of-confidence-distributions">Properties of Confidence Distributions</h2>
<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="level1">
<h1>The Nonparametric Bootstrap</h1>
<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><a href="bootstrap_files/figure-html/unnamed-chunk-5-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><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"></a></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><a href="bootstrap_files/figure-html/unnamed-chunk-5-2.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-2"><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"></a></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><a href="bootstrap_files/figure-html/unnamed-chunk-7-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-3"><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"></a></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><a href="bootstrap_files/figure-html/unnamed-chunk-7-2.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-4"><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"></a></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><a href="bootstrap_files/figure-html/unnamed-chunk-9-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-5"><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"></a></p>
</figure>
</div>
</div>
</div>
<hr>
</section>
<section id="the-parametric-bootstrap" class="level1">
<h1>The Parametric Bootstrap</h1>
<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><a href="bootstrap_files/figure-html/unnamed-chunk-12-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-6"><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"></a></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="level1">
<h1>References</h1>
<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>Traditional confidence intervals present a single level of uncertainty (typically 95%), but this dichotomous approach discards valuable information about the data. The <strong>confidence interval function</strong> (CI-function) provides a more complete picture by displaying all possible confidence intervals simultaneously.</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 been described in the literature under various names:</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>Install <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>A CI-function graphically represents the relationship between confidence levels and confidence intervals:</p>
<ul>
<li><strong>Peak of curve</strong>: Indicates the point estimate</li>
<li><strong>Concentration around peak</strong>: Reflects precision of estimate</li>
<li><strong>Narrow curve</strong>: High precision (large sample size)</li>
<li><strong>Broad curve</strong>: Low precision (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>: Shows compatibility of all values with data</li>
<li><strong>Precision visualization</strong>: Curve width directly shows estimate precision</li>
<li><strong>Multiple comparisons</strong>: Reveals whether data provide reassurance about null effects</li>
<li><strong>Nuanced interpretation</strong>: Moves beyond 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 the statistical model is correct). The curve explicitly shows the gradual nature of statistical evidence rather than suggesting arbitrary cutoffs.</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>Reproducing 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">## 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="cb2-9">## <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(601);</span>
<span id="cb2-10">## </span>
<span id="cb2-11">## </span>
<span id="cb2-12">## </span>
<span id="cb2-13">## </span>
<span id="cb2-14">## ------------------------------------------------------------------------------</span>
<span id="cb2-15">##              | Risk Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Interval]</span>
<span id="cb2-16">## -------------+----------------------------------------------------------------</span>
<span id="cb2-17">##    Estimates |          2    .707306    -1.96   0.050            1           4</span>
<span id="cb2-18">## ------------------------------------------------------------------------------</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>Using 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">## 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="cb3-18">## <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(601);</span>
<span id="cb3-19">## </span>
<span id="cb3-20">## </span>
<span id="cb3-21">## (Doll and Hill (1966))</span>
<span id="cb3-22">## </span>
<span id="cb3-23">## </span>
<span id="cb3-24">## Iteration 0:  Log likelihood = -4.0705386  </span>
<span id="cb3-25">## Iteration 1:  Log likelihood = -3.9613823  </span>
<span id="cb3-26">## Iteration 2:  Log likelihood = -3.9612634  </span>
<span id="cb3-27">## Iteration 3:  Log likelihood = -3.9612634  </span>
<span id="cb3-28">## </span>
<span id="cb3-29">## 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="cb3-30">##                                                         LR <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1)    =   9.73</span>
<span id="cb3-31">##                                                         Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>   = 0.0018</span>
<span id="cb3-32">## Log likelihood = -3.9612634                             Pseudo R2     = 0.5511</span>
<span id="cb3-33">## </span>
<span id="cb3-34">## ------------------------------------------------------------------------------</span>
<span id="cb3-35">##       deaths |        IRR   Std. err.      z    P&gt;|z|     [95% conf. interval]</span>
<span id="cb3-36">## -------------+----------------------------------------------------------------</span>
<span id="cb3-37">##       smokes |   5.736638   4.181258     2.40   0.017     1.374811    23.93712</span>
<span id="cb3-38">##        <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="cb3-39">##   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(pyears) |          1  (exposure)</span>
<span id="cb3-40">## ------------------------------------------------------------------------------</span>
<span id="cb3-41">## 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-42">## </span>
<span id="cb3-43">## Iteration 0:  Log likelihood = -5.4793565  </span>
<span id="cb3-44">## Iteration 1:  Log likelihood = -5.4104407  </span>
<span id="cb3-45">## Iteration 2:  Log likelihood =   -5.41027  </span>
<span id="cb3-46">## Iteration 3:  Log likelihood =   -5.41027  </span>
<span id="cb3-47">## </span>
<span id="cb3-48">## 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="cb3-49">##                                                         LR <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1)    =   7.59</span>
<span id="cb3-50">##                                                         Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>   = 0.0059</span>
<span id="cb3-51">## Log likelihood = -5.41027                               Pseudo R2     = 0.4123</span>
<span id="cb3-52">## </span>
<span id="cb3-53">## ------------------------------------------------------------------------------</span>
<span id="cb3-54">##       deaths |        IRR   Std. err.      z    P&gt;|z|     [95% conf. interval]</span>
<span id="cb3-55">## -------------+----------------------------------------------------------------</span>
<span id="cb3-56">##       smokes |   2.138812   .6520701     2.49   0.013     1.176691    3.887609</span>
<span id="cb3-57">##        <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="cb3-58">##   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(pyears) |          1  (exposure)</span>
<span id="cb3-59">## ------------------------------------------------------------------------------</span>
<span id="cb3-60">## 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-61">## </span>
<span id="cb3-62">## Iteration 0:  Log likelihood = -6.2456963  </span>
<span id="cb3-63">## Iteration 1:  Log likelihood = -6.1713863  </span>
<span id="cb3-64">## Iteration 2:  Log likelihood =  -6.171298  </span>
<span id="cb3-65">## Iteration 3:  Log likelihood =  -6.171298  </span>
<span id="cb3-66">## </span>
<span id="cb3-67">## 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="cb3-68">##                                                         LR <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1)    =   4.01</span>
<span id="cb3-69">##                                                         Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>   = 0.0453</span>
<span id="cb3-70">## Log likelihood = -6.171298                              Pseudo R2     = 0.2450</span>
<span id="cb3-71">## </span>
<span id="cb3-72">## ------------------------------------------------------------------------------</span>
<span id="cb3-73">##       deaths |        IRR   Std. err.      z    P&gt;|z|     [95% conf. interval]</span>
<span id="cb3-74">## -------------+----------------------------------------------------------------</span>
<span id="cb3-75">##       smokes |    1.46824    .295728     1.91   0.057     .9893522     2.17893</span>
<span id="cb3-76">##        <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="cb3-77">##   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(pyears) |          1  (exposure)</span>
<span id="cb3-78">## ------------------------------------------------------------------------------</span>
<span id="cb3-79">## 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-80">## </span>
<span id="cb3-81">## Iteration 0:  Log likelihood = -6.1640322  </span>
<span id="cb3-82">## Iteration 1:  Log likelihood = -6.1203079  </span>
<span id="cb3-83">## Iteration 2:  Log likelihood = -6.1202768  </span>
<span id="cb3-84">## Iteration 3:  Log likelihood = -6.1202768  </span>
<span id="cb3-85">## </span>
<span id="cb3-86">## 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="cb3-87">##                                                         LR <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>(1)    =   2.43</span>
<span id="cb3-88">##                                                         Prob &gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chi2</span>   = 0.1189</span>
<span id="cb3-89">## Log likelihood = -6.1202768                             Pseudo R2     = 0.1658</span>
<span id="cb3-90">## </span>
<span id="cb3-91">## ------------------------------------------------------------------------------</span>
<span id="cb3-92">##       deaths |        IRR   Std. err.      z    P&gt;|z|     [95% conf. interval]</span>
<span id="cb3-93">## -------------+----------------------------------------------------------------</span>
<span id="cb3-94">##       smokes |    1.35606   .2748845     1.50   0.133     .9114509    2.017551</span>
<span id="cb3-95">##        <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="cb3-96">##   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ln</span>(pyears) |          1  (exposure)</span>
<span id="cb3-97">## ------------------------------------------------------------------------------</span>
<span id="cb3-98">## 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>This example demonstrates how CI-functions can reveal patterns across subgroups—in this case, showing 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>Comparing 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">## 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="cb4-15">## <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(601);</span>
<span id="cb4-16">## </span>
<span id="cb4-17">## </span>
<span id="cb4-18">## </span>
<span id="cb4-19">##                                                          Proportion</span>
<span id="cb4-20">##                  |   Exposed   Unexposed  |      Total      exposed</span>
<span id="cb4-21">## -----------------+------------------------+------------------------</span>
<span id="cb4-22">##            Cases |        10          36  |         46       0.2174</span>
<span id="cb4-23">##         Controls |         5          40  |         45       0.1111</span>
<span id="cb4-24">## -----------------+------------------------+------------------------</span>
<span id="cb4-25">##            Total |        15          76  |         91       0.1648</span>
<span id="cb4-26">##                  |                        |</span>
<span id="cb4-27">##                  |      Point estimate    |    [95% conf. interval]</span>
<span id="cb4-28">##                  |------------------------+------------------------</span>
<span id="cb4-29">##       Odds <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">ratio</span> |         2.222222       |      .69377    7.118025 (Woolf)</span>
<span id="cb4-30">##  Attr. frac. ex. |              .55       |      -.4414    .8595116 (Woolf)</span>
<span id="cb4-31">##  Attr. frac. pop |         .1195652       |</span>
<span id="cb4-32">##                  +-------------------------------------------------</span>
<span id="cb4-33">##                                <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-34">## </span>
<span id="cb4-35">## </span>
<span id="cb4-36">##                                                          Proportion</span>
<span id="cb4-37">##                  |   Exposed   Unexposed  |      Total      exposed</span>
<span id="cb4-38">## -----------------+------------------------+------------------------</span>
<span id="cb4-39">##            Cases |        18          78  |         96       0.1875</span>
<span id="cb4-40">##         Controls |         7          86  |         93       0.0753</span>
<span id="cb4-41">## -----------------+------------------------+------------------------</span>
<span id="cb4-42">##            Total |        25         164  |        189       0.1323</span>
<span id="cb4-43">##                  |                        |</span>
<span id="cb4-44">##                  |      Point estimate    |    [95% conf. interval]</span>
<span id="cb4-45">##                  |------------------------+------------------------</span>
<span id="cb4-46">##       Odds <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">ratio</span> |         2.835165       |    1.123936    7.151794 (Woolf)</span>
<span id="cb4-47">##  Attr. frac. ex. |         .6472868       |    .1102698    .8601749 (Woolf)</span>
<span id="cb4-48">##  Attr. frac. pop |         .1213663       |</span>
<span id="cb4-49">##                  +-------------------------------------------------</span>
<span id="cb4-50">##                                <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-51">## </span>
<span id="cb4-52">## </span>
<span id="cb4-53">## </span>
<span id="cb4-54">## ------------------------------------------------------------------------------</span>
<span id="cb4-55">##              | Odds Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Interval]</span>
<span id="cb4-56">## -------------+----------------------------------------------------------------</span>
<span id="cb4-57">##    Estimates |   2.835165   1.338429     2.21   0.027     1.123936    7.151794</span>
<span id="cb4-58">## ------------------------------------------------------------------------------</span>
<span id="cb4-59">## </span>
<span id="cb4-60">## </span>
<span id="cb4-61">## </span>
<span id="cb4-62">## ------------------------------------------------------------------------------</span>
<span id="cb4-63">##              | Odds Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Interval]</span>
<span id="cb4-64">## -------------+----------------------------------------------------------------</span>
<span id="cb4-65">##    Estimates |   2.222222   1.319891     1.34   0.179     .6937698    7.118025</span>
<span id="cb4-66">## ------------------------------------------------------------------------------</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>Comparing 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">## 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="cb5-15">## <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(601);</span>
<span id="cb5-16">## </span>
<span id="cb5-17">## </span>
<span id="cb5-18">## </span>
<span id="cb5-19">## </span>
<span id="cb5-20">## ------------------------------------------------------------------------------</span>
<span id="cb5-21">##              | Risk Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Interval]</span>
<span id="cb5-22">## -------------+----------------------------------------------------------------</span>
<span id="cb5-23">##    Estimates |         .7   .4474236    -0.56   0.577           .2        2.45</span>
<span id="cb5-24">## ------------------------------------------------------------------------------</span>
<span id="cb5-25">## </span>
<span id="cb5-26">## </span>
<span id="cb5-27">## </span>
<span id="cb5-28">## ------------------------------------------------------------------------------</span>
<span id="cb5-29">##              | Risk Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Interval]</span>
<span id="cb5-30">## -------------+----------------------------------------------------------------</span>
<span id="cb5-31">##    Estimates |        1.2   .2482485     0.88   0.378           .8         1.8</span>
<span id="cb5-32">## ------------------------------------------------------------------------------</span>
<span id="cb5-33">## </span>
<span id="cb5-34">## </span>
<span id="cb5-35">## </span>
<span id="cb5-36">## ------------------------------------------------------------------------------</span>
<span id="cb5-37">##              | Risk Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Interval]</span>
<span id="cb5-38">## -------------+----------------------------------------------------------------</span>
<span id="cb5-39">##    Estimates |        1.3   .6337692     0.54   0.590           .5        3.38</span>
<span id="cb5-40">## ------------------------------------------------------------------------------</span>
<span id="cb5-41">## </span>
<span id="cb5-42">## </span>
<span id="cb5-43">## </span>
<span id="cb5-44">## ------------------------------------------------------------------------------</span>
<span id="cb5-45">##              | Risk Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Interval]</span>
<span id="cb5-46">## -------------+----------------------------------------------------------------</span>
<span id="cb5-47">##    Estimates |        3.6   1.870876     2.46   0.014          1.3    9.969231</span>
<span id="cb5-48">## ------------------------------------------------------------------------------</span></code></pre></div></div>
</div>
<p>This visualization makes it immediately apparent 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>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">## 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="cb6-12">## <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(601);</span>
<span id="cb6-13">## </span>
<span id="cb6-14">## </span>
<span id="cb6-15">## </span>
<span id="cb6-16">## </span>
<span id="cb6-17">## ------------------------------------------------------------------------------</span>
<span id="cb6-18">##              | Odds Ratio   Std. Err.      z    P&gt;|z|     [95% Conf. Interval]</span>
<span id="cb6-19">## -------------+----------------------------------------------------------------</span>
<span id="cb6-20">##    Estimates |        .87   .0965065    -1.26   0.209           .7    1.081286</span>
<span id="cb6-21">## ------------------------------------------------------------------------------</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 using <code>saving()</code>, cifunction stores these 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 represent the information content against a null hypothesis, measured 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 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>Always use log scale</strong> for ratio measures (OR, RR, HR, IRR)</li>
<li><strong>Label curves clearly</strong> when plotting multiple estimates</li>
<li><strong>Save output data</strong> for further analysis or custom plotting</li>
<li><strong>Consider degrees of freedom</strong> when using regression-based estimates</li>
<li><strong>Interpret curves holistically</strong> rather than focusing on single cutoffs</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 principle that statistical evidence is continuous rather than dichotomous. 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>The approach aligns with modern calls for moving beyond p-value thresholds<span class="citation" data-cites="wasserstein2019moving"><sup>7</sup></span> by presenting 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>
<ul>
<li>Assumes the statistical model is correctly specified</li>
<li>Does not account for unmeasured confounding or bias</li>
<li>Cannot compensate for poor study design or execution</li>
<li>Interpretation requires 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 valid only to the extent that the underlying statistical model and 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. 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>This ensures symmetric intervals on the log scale and proper geometric interpretation.</p>
<hr>
<p><strong>Last updated:</strong> 2026-09-13 <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 graphically
    displays all possible confidence intervals around a point estimate,
    creating what’s known as a confidence interval function, confidence
    curve, p-value function, or consonance interval. This approach
    conveys more information than traditional single-level confidence
    intervals by showing the full range of values compatible with the
    data at all confidence levels.}
}
</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="level1">
<h1>Statistical Models as Approximations</h1>
<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><a href="../images/approximation.png" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><img src="https://lesslikely.com/images/approximation.png" class="img-fluid"></a></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="level1">
<h1>What Goes into a Model?</h1>
<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="level1">
<h1>Violation of Assumptions</h1>
<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><a href="assumptions_files/figure-html/unnamed-chunk-5-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-2"><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"></a></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><a href="assumptions_files/figure-html/unnamed-chunk-7-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-3"><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"></a></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><a href="scatter.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-1" title="scatter"><img src="https://lesslikely.com/statistics/scatter.svg" style="width:150.0%;height:150.0%" alt="scatter" class="figure-img"></a></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><a href="mfp.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-2" title="fractional polynomial model"><img src="https://lesslikely.com/statistics/mfp.svg" style="width:150.0%;height:150.0%" alt="fractional polynomial model" class="figure-img"></a></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><a href="../images/matrix.png" class="lightbox" data-gallery="quarto-lightbox-gallery-3"><img src="https://lesslikely.com/images/matrix.png" style="width:150.0%;height:150.0%"></a></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><a href="RG2020BMC_files/figure-html/unnamed-chunk-20-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-4"><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"></a></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><a href="../images/confidence.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-5"><img src="https://lesslikely.com/images/confidence.svg" class="img-fluid"></a></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><a href="https://stat.lesslikely.com/concurve/articles/surprisal.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-6" title="Surprisal Function"><img src="https://stat.lesslikely.com/concurve/articles/surprisal.svg" style="width:150.0%;height:150.0%" alt="Surprisal Function" class="figure-img"></a></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="level2">
<h2 class="anchored" data-anchor-id="using-the-cifunction-command-for-confidence-interval-functions">Using the <code>cifunction</code> Command for Confidence Interval Functions</h2>
<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="level3">
<h3 class="anchored" data-anchor-id="syntax">Syntax</h3>
<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="level3">
<h3 class="anchored" data-anchor-id="options">Options</h3>
<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="level3">
<h3 class="anchored" data-anchor-id="example-1-simple-risk-ratio">Example 1: Simple Risk Ratio</h3>
<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="level3">
<h3 class="anchored" data-anchor-id="example-2-multiple-rate-ratios-by-age-group">Example 2: Multiple Rate Ratios by Age Group</h3>
<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="level3">
<h3 class="anchored" data-anchor-id="example-3-comparing-crude-and-pooled-estimates">Example 3: Comparing Crude and Pooled Estimates</h3>
<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="level3">
<h3 class="anchored" data-anchor-id="output-from-cifunction">Output from <code>cifunction</code></h3>
<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="level3">
<h3 class="anchored" data-anchor-id="references-for-cifunction">References for <code>cifunction</code></h3>
<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="level1">
<h1>Cite R Packages</h1>
<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="level1">
<h1>Session info</h1>
<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</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 utils     datasets  methods   base     </span></span>
<span id="cb27-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb27-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; other attached packages:</span></span>
<span id="cb27-26"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [1] cli_3.6.6             texPreview_2.1.0      tinytex_0.60          rmarkdown_2.31        brms_2.23.0          </span></span>
<span id="cb27-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [6] bootImpute_1.3.0      knitr_1.51            boot_1.3-32           gtsummary_2.5.1       reshape2_1.4.5       </span></span>
<span id="cb27-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [11] ProfileLikelihood_1.3 ImputeRobust_1.3-1    gamlss_5.5-0          gamlss.dist_6.1-1     gamlss.data_6.0-7    </span></span>
<span id="cb27-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [16] mvtnorm_1.4-2         performance_0.17.1    summarytools_1.1.5    tidybayes_3.0.7       htmltools_0.5.9      </span></span>
<span id="cb27-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [21] Statamarkdown_0.9.7   car_3.1-5             carData_3.0-6         qqplotr_0.0.7         ggcorrplot_0.3.0     </span></span>
<span id="cb27-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [26] mitml_0.4-5           pbmcapply_1.5.1       Amelia_1.8.3          Rcpp_1.1.2            blogdown_1.24        </span></span>
<span id="cb27-32"><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         lattice_0.23-1        bayesplot_1.15.0     </span></span>
<span id="cb27-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [36] wesanderson_0.3.7     VIM_7.0.0             colorspace_2.1-3      here_1.0.2            progress_1.2.3       </span></span>
<span id="cb27-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [41] loo_2.10.1            mi_1.3.1              Matrix_1.7-6          broom_1.0.13          yardstick_1.4.0      </span></span>
<span id="cb27-35"><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         mgcv_1.9-4            nlme_3.1-170         </span></span>
<span id="cb27-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [51] xfun_0.60             broom.mixed_0.2.9.7   reticulate_1.46.0     kableExtra_1.4.1      posterior_1.7.0      </span></span>
<span id="cb27-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [56] checkmate_2.3.4       parallelly_1.48.0     miceFast_0.9.1        randomForest_4.7-1.2  missForest_1.6.1     </span></span>
<span id="cb27-38"><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        MCMCpack_1.7-1        MASS_7.3-66          </span></span>
<span id="cb27-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [66] coda_0.19-4.1         latex2exp_0.9.8       rstan_2.32.7          StanHeaders_2.32.10   lubridate_1.9.5      </span></span>
<span id="cb27-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [71] forcats_1.0.1         stringr_1.6.0         dplyr_1.2.1           purrr_1.2.2           readr_2.2.0          </span></span>
<span id="cb27-41"><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       ggtext_0.1.2          concurve_3.0.0       </span></span>
<span id="cb27-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [81] showtext_0.9-8        showtextdb_3.0        sysfonts_0.8.9        future.apply_1.20.2   future_1.75.0        </span></span>
<span id="cb27-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; [86] tidyr_1.3.2           magrittr_2.0.5        mice_3.19.0           rms_8.1-1             Hmisc_5.2-6          </span></span>
<span id="cb27-44"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt; </span></span>
<span id="cb27-45"><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-46"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   [1] dichromat_2.0-1       nnet_7.3-21           TH.data_1.1-5         vctrs_0.7.3           digest_0.6.39        </span></span>
<span id="cb27-47"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;   [6] png_0.1-9             shape_1.4.6.1         proxy_0.4-29          magick_2.9.1          withr_3.0.3          </span></span>
<span id="cb27-48"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [11] survival_3.8-9        doRNG_1.8.6.3         MatrixModels_0.5-4    emmeans_2.0.4         systemfonts_1.3.2    </span></span>
<span id="cb27-49"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [16] zoo_1.9-0             V8_8.2.0              ggdist_3.3.3          DEoptimR_1.2-0        Formula_1.2-6        </span></span>
<span id="cb27-50"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [21] prettyunits_1.2.0     rematch2_2.1.2        httr_1.4.8            otel_0.2.0            globals_0.19.1       </span></span>
<span id="cb27-51"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [26] rstudioapi_0.19.0     extremevalues_2.4.1   pan_2.0               generics_0.1.4        processx_3.9.0       </span></span>
<span id="cb27-52"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [31] base64enc_0.1-6       curl_7.1.0            mitools_2.4           lgr_0.5.2             xtable_1.8-8         </span></span>
<span id="cb27-53"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [36] svUnit_1.0.8          desc_1.4.3            pracma_2.4.6          evaluate_1.0.5        hms_1.1.4            </span></span>
<span id="cb27-54"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [41] glmnet_5.0            rcartocolor_2.1.2     lmtest_0.9-40         palmerpenguins_0.1.1  robustbase_0.99-7    </span></span>
<span id="cb27-55"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [46] matrixStats_1.5.0     svgPanZoom_0.3.4      class_7.3-24          pillar_1.11.1         caTools_1.18.4       </span></span>
<span id="cb27-56"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [51] compiler_4.6.1        stringi_1.8.9         paradox_1.0.1         jomo_2.7-6            minqa_1.2.8          </span></span>
<span id="cb27-57"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [56] plyr_1.8.9            crayon_1.5.3          abind_1.4-8           sp_2.2-3              rapportools_1.2      </span></span>
<span id="cb27-58"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [61] twosamples_2.0.1      sandwich_3.1-3        whisker_0.4.1         codetools_0.2-20      multcomp_1.4-31      </span></span>
<span id="cb27-59"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [66] textshaping_1.0.5     QuickJSR_1.10.0       e1071_1.7-17          gridtext_0.1.6        lme4_2.0-6           </span></span>
<span id="cb27-60"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [71] fs_2.1.0              itertools_0.1-3       listenv_1.0.0         Rdpack_2.6.6          pkgbuild_1.4.8       </span></span>
<span id="cb27-61"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [76] estimability_2.0.0    callr_3.8.0           tzdb_0.5.0            pkgconfig_2.0.3       tools_4.6.1          </span></span>
<span id="cb27-62"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [81] rbibutils_2.4.1       viridisLite_0.4.3     DBI_1.3.0             fastmap_1.2.0         scales_1.4.0         </span></span>
<span id="cb27-63"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [86] opdisDownsampling_1.6 insight_1.5.2         rpart_4.1.27          farver_2.1.2          moocore_0.3.2        </span></span>
<span id="cb27-64"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [91] reformulas_0.4.4      yaml_2.3.12           foreign_0.8-91        lifecycle_1.0.5       bbotk_1.12.0         </span></span>
<span id="cb27-65"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [96] backports_1.5.1       mlr3tuning_1.6.1      Brobdingnag_1.2-9     timechange_0.4.0      gtable_0.3.6         </span></span>
<span id="cb27-66"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [ reached 'max' / getOption("max.print") -- omitted 42 entries ]</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="level1">
<h1>Setting up the Function</h1>
<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="level1">
<h1>A Simulated Example</h1>
<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="level1">
<h1>Examining the Results</h1>
<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="level1">
<h1>Statistical Environment</h1>
<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="level1">
<h1>Article Citation</h1>
<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="level2">
<h2 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</h2>
<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><a href="RG2020BMC_files/figure-html/unnamed-chunk-4-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><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"></a></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><a href="RG2020BMC_files/figure-html/unnamed-chunk-5-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-2"><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"></a></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><a href="RG2020BMC_files/figure-html/unnamed-chunk-5-2.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-3"><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"></a></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><a href="RG2020BMC_files/figure-html/unnamed-chunk-6-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-4"><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"></a></p>
</figure>
</div>
</div>
</div>
<hr>
</section>
<section id="posterior-predictive-p-values" class="level2">
<h2 class="anchored" data-anchor-id="posterior-predictive-p-values">Posterior Predictive <img src="https://latex.codecogs.com/png.latex?P">-values</h2>
<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><a href="RG2020BMC_files/figure-html/unnamed-chunk-8-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-5"><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"></a></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; could <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> find feasible <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">values</span></span>
<span id="cb9-33">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(491);</span>
<span id="cb9-34">#&gt; </span>
<span id="cb9-35">#&gt; </span>
<span id="cb9-36">#&gt; </span>
<span id="cb9-37">#&gt; </span>
<span id="cb9-38">#&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-39">#&gt; </span>
<span id="cb9-40">#&gt; </span>
<span id="cb9-41">#&gt; </span>
<span id="cb9-42">#&gt; </span>
<span id="cb9-43">#&gt; Burn-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> ...</span>
<span id="cb9-44">#&gt; Simulation ...</span>
<span id="cb9-45">#&gt; </span>
<span id="cb9-46">#&gt; Model summary</span>
<span id="cb9-47">#&gt; -------------------------------------------------------------------------</span>
<span id="cb9-48">#&gt; &gt; -----</span>
<span id="cb9-49">#&gt; Likelihood: </span>
<span id="cb9-50">#&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-51">#&gt; </span>
<span id="cb9-52">#&gt; Priors: </span>
<span id="cb9-53">#&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>
<span id="cb9-54">#&gt;                 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span>(0,100)                                            </span>
<span id="cb9-55">#&gt;                 &gt;   (1)</span>
<span id="cb9-56">#&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-57">#&gt; -------------------------------------------------------------------------</span>
<span id="cb9-58">#&gt; &gt; -----</span>
<span id="cb9-59">#&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-60">#&gt; </span>
<span id="cb9-61">#&gt; Bayesian <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">normal</span> regression                       MCMC iterations  =      </span>
<span id="cb9-62">#&gt; &gt; 3,500</span>
<span id="cb9-63">#&gt; Random-walk Metropolis–Hastings sampling         Burn-<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span>          =      </span>
<span id="cb9-64">#&gt; &gt; 2,500</span>
<span id="cb9-65">#&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> =      </span>
<span id="cb9-66">#&gt; &gt; 1,000</span>
<span id="cb9-67">#&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>    =      </span>
<span id="cb9-68">#&gt; &gt;   100</span>
<span id="cb9-69">#&gt;                                                  Acceptance rate  =      </span>
<span id="cb9-70">#&gt; &gt; .2428</span>
<span id="cb9-71">#&gt;                                                  Efficiency:  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span> =    .0</span>
<span id="cb9-72">#&gt; &gt; 01044</span>
<span id="cb9-73">#&gt;                                                               avg =     .</span>
<span id="cb9-74">#&gt; &gt; 04252</span>
<span id="cb9-75">#&gt; Log marginal-likelihood = -153.90987                          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span> =     .</span>
<span id="cb9-76">#&gt; &gt; 08305</span>
<span id="cb9-77">#&gt; </span>
<span id="cb9-78">#&gt; -------------------------------------------------------------------------</span>
<span id="cb9-79">#&gt; &gt; -----</span>
<span id="cb9-80">#&gt;              |                                                Equal-taile</span>
<span id="cb9-81">#&gt; &gt; <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">d</span></span>
<span id="cb9-82">#&gt;              |      Mean   Std. <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">dev</span>.     MCSE     Median  [95% cred. inte</span>
<span id="cb9-83">#&gt; &gt; rval]</span>
<span id="cb9-84">#&gt; -------------+-----------------------------------------------------------</span>
<span id="cb9-85">#&gt; &gt; -----</span>
<span id="cb9-86">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">y</span>            |</span>
<span id="cb9-87">#&gt;            x |  .0115139   .1551555   .017026   .0145751  -.2995666   .34</span>
<span id="cb9-88">#&gt; &gt; 70796</span>
<span id="cb9-89">#&gt;        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">_cons</span> |  .1022613    .137549   .020865   .1348998  -.2513679   .34</span>
<span id="cb9-90">#&gt; &gt; 55865</span>
<span id="cb9-91">#&gt; -------------+-----------------------------------------------------------</span>
<span id="cb9-92">#&gt; &gt; -----</span>
<span id="cb9-93">#&gt;          <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">var</span> |  .9643251   .1503727    .14715   .9896135   .7582507   1.3</span>
<span id="cb9-94">#&gt; &gt; 60154</span>
<span id="cb9-95">#&gt; -------------------------------------------------------------------------</span>
<span id="cb9-96">#&gt; &gt; -----</span>
<span id="cb9-97">#&gt; </span>
<span id="cb9-98">#&gt; file bmh_sim.dta saved.</span>
<span id="cb9-99">#&gt; </span>
<span id="cb9-100">#&gt; </span>
<span id="cb9-101">#&gt; Computing predictions ...</span>
<span id="cb9-102">#&gt; </span>
<span id="cb9-103">#&gt; file bmh_pred.dta saved.</span>
<span id="cb9-104">#&gt; file bmh_pred.ster saved.</span>
<span id="cb9-105">#&gt; </span>
<span id="cb9-106">#&gt; </span>
<span id="cb9-107">#&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-108">#&gt; </span>
<span id="cb9-109">#&gt; -----------------------------------------------------------</span>
<span id="cb9-110">#&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-111">#&gt; -------------+---------------------------------------------</span>
<span id="cb9-112">#&gt;        tmean |  .0550687   .1146021   .0206952         .632</span>
<span id="cb9-113">#&gt;         tvar |  .9896307   .2164376   .9710317         .484</span>
<span id="cb9-114">#&gt; -----------------------------------------------------------</span>
<span id="cb9-115">#&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-116">#&gt; </span>
<span id="cb9-117">#&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-118">#&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="level2">
<h2 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</h2>
<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="level2">
<h2 class="anchored" data-anchor-id="frequentist-interval-estimate-percentiles">Frequentist Interval Estimate Percentiles</h2>
</section>
<section id="refer-to-long-run-coverage" class="level2">
<h2 class="anchored" data-anchor-id="refer-to-long-run-coverage">Refer to Long-Run Coverage</h2>
<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><a href="RG2020BMC_files/figure-html/unnamed-chunk-12-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-6"><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"></a></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="level1">
<h1>Brown et al.&nbsp;(2017) Reanalysis</h1>
<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="level2">
<h2 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></h2>
<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="level2">
<h2 class="anchored" data-anchor-id="plot-the-point-estimate-and-95-compatibility-interval">Plot the point estimate and 95% compatibility interval</h2>
<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><a href="RG2020BMC_files/figure-html/unnamed-chunk-16-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-7"><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"></a></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="level2">
<h2 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</h2>
<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="level2">
<h2 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</h2>
<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><a href="RG2020BMC_files/figure-html/unnamed-chunk-20-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-8"><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"></a></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="level2">
<h2 class="anchored" data-anchor-id="cumulative-confidence-compatibility-distribution">Cumulative Confidence (Compatibility Distribution)</h2>
<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><a href="RG2020BMC_files/figure-html/unnamed-chunk-22-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-9"><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"></a></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><a href="RG2020BMC_files/figure-html/unnamed-chunk-24-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-10"><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"></a></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><a href="RG2020BMC_files/figure-html/unnamed-chunk-25-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-11"><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"></a></p>
</figure>
</div>
</div>
</div>
<hr>
</section>
<section id="figure-4-s-value-suprisal-function" class="level2">
<h2 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</h2>
<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><a href="RG2020BMC_files/figure-html/unnamed-chunk-26-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-12"><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"></a></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="level2">
<h2 class="anchored" data-anchor-id="likelihood-support-functions">Likelihood (Support) Functions</h2>
<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="level2">
<h2 class="anchored" data-anchor-id="figure-s1-relative-likelihood-function">Figure S1: Relative Likelihood Function</h2>
<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><a href="RG2020BMC_files/figure-html/unnamed-chunk-28-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-13"><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"></a></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><a href="RG2020BMC_files/figure-html/unnamed-chunk-29-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-14"><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"></a></p>
</figure>
</div>
</div>
</div>
<hr>
</section>
<section id="figure-s2-deviance-function-2lnmlr" class="level2">
<h2 class="anchored" data-anchor-id="figure-s2-deviance-function-2lnmlr">Figure S2: Deviance Function <img src="https://latex.codecogs.com/png.latex?2ln(MLR)"></h2>
<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><a href="RG2020BMC_files/figure-html/unnamed-chunk-30-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-15"><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"></a></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="level1">
<h1>Statistical Package Citations</h1>
<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="level1">
<h1>Environment</h1>
<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</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] en_US/C.UTF-8/en_US/C/en_US/en_US</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.0        </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.8        </span></span>
<span id="cb32-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#&gt;  [28] glmnet_5.0            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.60         </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-0          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.0.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-3      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.60            </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.75.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.3          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-1        zoo_1.9-0             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.0.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.2-9    </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="level1">
<h1>Stata</h1>
<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; could <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> find feasible <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">values</span></span>
<span id="cb33-4">#&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r</span>(491);</span>
<span id="cb33-5">#&gt; </span>
<span id="cb33-6">#&gt; </span>
<span id="cb33-7">#&gt; </span>
<span id="cb33-8">#&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-9">#&gt; Revision 12 Aug 2026</span>
<span id="cb33-10">#&gt; Copyright 1985-2025 StataCorp LLC</span>
<span id="cb33-11">#&gt; </span>
<span id="cb33-12">#&gt; Total physical <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">memory</span>: 48.01 GB</span>
<span id="cb33-13">#&gt; </span>
<span id="cb33-14">#&gt; Stata license: Single-user 2-core , expiring  6 Feb 2027</span>
<span id="cb33-15">#&gt; Serial number: 501909358563</span>
<span id="cb33-16">#&gt;   Licensed to: Zad Rafi</span>
<span id="cb33-17">#&gt;                </span>
<span id="cb33-18">#&gt; </span>
<span id="cb33-19">#&gt; <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">version</span> 19.5</span>
<span id="cb33-20">#&gt; </span>
<span id="cb33-21">#&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="cb33-22">#&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><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="level1">
<h1>References</h1>
<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="level1">
<h1>Cargo-Cult Uncertainty</h1>
<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="level2">
<h2 class="anchored" data-anchor-id="everything-is-sensitive">Everything is Sensitive</h2>
<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="level2">
<h2 class="anchored" data-anchor-id="frequent-misconceptions">Frequent Misconceptions</h2>
<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="level2">
<h2 class="anchored" data-anchor-id="randomness-uncertainty">Randomness &amp; Uncertainty</h2>
<hr>
</section>
<section id="portable-sensitivity-analyses" class="level2">
<h2 class="anchored" data-anchor-id="portable-sensitivity-analyses">Portable Sensitivity Analyses</h2>
<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="level2">
<h2 class="anchored" data-anchor-id="regulators-sensitivity-analyses">Regulators &amp; Sensitivity Analyses</h2>
<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="level2">
<h2 class="anchored" data-anchor-id="estimands-sensitivity">Estimands &amp; Sensitivity</h2>
<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-7b6237e72ac11269cf0c" style="width:100%;height:480px;"></div>
<script type="application/json" data-for="htmlwidget-7b6237e72ac11269cf0c">{"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">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="https://res.cloudinary.com/less-likely/image/upload/q_auto:best/v1618886541/Site/sensitivitytree.png" class="lightbox" data-gallery="quarto-lightbox-gallery-1" title="Adapted sensitivity-analysis flowchart."><img src="https://res.cloudinary.com/less-likely/image/upload/q_auto:best/v1618886541/Site/sensitivitytree.png" class="img-fluid quarto-figure quarto-figure-center figure-img" alt="Adapted sensitivity-analysis flowchart."></a></p>
</figure>
</div>
<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="level2">
<h2 class="anchored" data-anchor-id="utility-of-subject-matter-experts">Utility of Subject-Matter Experts</h2>
<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="level1">
<h1>Sensitivity in Clinical Trials</h1>
<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><a href="sensitivity_files/figure-html/unnamed-chunk-8-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-2"><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"></a></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><a href="sensitivity_files/figure-html/unnamed-chunk-13-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-3"><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"></a></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><a href="sensitivity_files/figure-html/unnamed-chunk-14-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-4"><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"></a></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><a href="sensitivity_files/figure-html/unnamed-chunk-15-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-5"><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"></a></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="level2">
<h2 class="anchored" data-anchor-id="the-threat-of-missing-data">The Threat of Missing Data</h2>
<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">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="../images/missing-mech.png" class="lightbox" data-gallery="quarto-lightbox-gallery-6" title="Missing-data mechanism flowchart."><img src="https://lesslikely.com/images/missing-mech.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="800" alt="Missing-data mechanism flowchart."></a></p>
</figure>
</div>
<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><a href="sensitivity_files/figure-html/unnamed-chunk-18-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-7"><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"></a></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><a href="sensitivity_files/figure-html/unnamed-chunk-19-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-8"><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"></a></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><a href="sensitivity_files/figure-html/unnamed-chunk-23-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-9"><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"></a></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><a href="sensitivity_files/figure-html/unnamed-chunk-28-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-10"><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"></a></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="sensitivity_files/figure-html/unnamed-chunk-28-2.png" class="lightbox" data-gallery="quarto-lightbox-gallery-11"><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"></a></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="level2">
<h2 class="anchored" data-anchor-id="multiple-imputation-workflow">Multiple Imputation Workflow</h2>
<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">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="../images/missingness.png" class="lightbox" data-gallery="quarto-lightbox-gallery-12" title="Missingness workflow flowchart."><img src="https://lesslikely.com/images/missingness.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="800" alt="Missingness workflow flowchart."></a></p>
</figure>
</div>
<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="level2">
<h2 class="anchored" data-anchor-id="concepts-in-multiple-imputation">Concepts in Multiple Imputation</h2>
<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="level2">
<h2 class="anchored" data-anchor-id="monte-carlo-error-analysis">Monte Carlo Error Analysis</h2>
<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><a href="sensitivity_files/figure-html/unnamed-chunk-30-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-13"><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"></a></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><a href="sensitivity_files/figure-html/unnamed-chunk-31-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-14"><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"></a></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><a href="sensitivity_files/figure-html/unnamed-chunk-35-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-15"><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"></a></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="level2">
<h2 class="anchored" data-anchor-id="the-primary-analysis">The Primary Analysis</h2>
<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><a href="sensitivity_files/figure-html/unnamed-chunk-39-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-16"><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"></a></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="sensitivity_files/figure-html/unnamed-chunk-39-2.png" class="lightbox" data-gallery="quarto-lightbox-gallery-17"><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"></a></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><a href="sensitivity_files/figure-html/unnamed-chunk-43-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-18"><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"></a></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-9d3b09c2fc2583bc2f9e" style="width:100%;height:480px;"></div>
<script type="application/json" data-for="htmlwidget-9d3b09c2fc2583bc2f9e">{"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="level2">
<h2 class="anchored" data-anchor-id="sa-i-controlled-imputations">SA I: Controlled Imputations</h2>
<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><a href="sensitivity_files/figure-html/unnamed-chunk-49-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-19"><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"></a></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-927269e9737d3df3d632" style="width:100%;height:480px;"></div>
<script type="application/json" data-for="htmlwidget-927269e9737d3df3d632">{"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="level2">
<h2 class="anchored" data-anchor-id="sa-ii-selection-models">SA II: Selection Models</h2>
<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><a href="sensitivity_files/figure-html/unnamed-chunk-52-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-20"><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"></a></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><a href="sensitivity_files/figure-html/unnamed-chunk-55-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-21"><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"></a></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-96bd5cea48d21205852e" style="width:100%;height:480px;"></div>
<script type="application/json" data-for="htmlwidget-96bd5cea48d21205852e">{"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="level2">
<h2 class="anchored" data-anchor-id="supplementary-analyses">Supplementary Analyses</h2>
<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                  13 Sep 2026 04:16
#&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="level2">
<h2 class="anchored" data-anchor-id="full-analysis-set">Full Analysis Set</h2>
<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><a href="sensitivity_files/figure-html/unnamed-chunk-76-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-22"><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"></a></p>
</figure>
</div>
</div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><a href="sensitivity_files/figure-html/unnamed-chunk-76-2.png" class="lightbox" data-gallery="quarto-lightbox-gallery-23"><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"></a></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><a href="sensitivity_files/figure-html/unnamed-chunk-82-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-24"><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"></a></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><a href="sensitivity_files/figure-html/unnamed-chunk-84-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-25"><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"></a></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><a href="sensitivity_files/figure-html/unnamed-chunk-87-1.png" class="lightbox" data-gallery="quarto-lightbox-gallery-26"><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"></a></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="level2">
<h2 class="anchored" data-anchor-id="examining-the-analyses">Examining the Analyses</h2>
<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="level1">
<h1>Related from Less Likely</h1>
<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="level1">
<h1>Acknowledgements</h1>
<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="level1">
<h1>Statistical Environments</h1>
<hr>
<section id="r-environment" class="level4">
<h4 class="anchored" data-anchor-id="r-environment">R Environment</h4>
<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.UTF-8
#&gt;  ctype    en_US.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 @ /Applications/quarto/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.11
#&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="level4">
<h4 class="anchored" data-anchor-id="stata">Stata Environment</h4>
<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 13,2026 4:18 am</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="level1">
<h1>References</h1>
<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>
<item>
  <title>Medicine Is Being Treated with Snake-Oil Statistics</title>
  <dc:creator>Zad Rafi</dc:creator>
  <dc:creator>Andrew Gelman</dc:creator>
  <dc:creator>Aleksi Reito</dc:creator>
  <dc:creator>Sander Greenland</dc:creator>
  <link>https://lesslikely.com/statistics/snakeoilstats.html</link>
  <description><![CDATA[ 





<p><strong>Suggested Running Head:</strong> Snake Oil Statistics</p>
<hr>
<p>Statistics has helped medicine move away from an eminence-based framework, where subject-matter experts decided what worked and what didn’t, towards an evidence-based one. Among the techniques deployed, null-hypothesis statistical testing (NHST) is the most common, where the word “null” is invariably taken by users to mean that the only hypotheses tested are those of “no association” or “no effect” (sometimes labeled “nil hypotheses”). Despite objections to them extending throughout the past century<span class="citation" data-cites="boringMathematicalVsScientific1919"><sup>1</sup></span>, these tests are supposed to serve as a safeguard against researchers fooling themselves and others, as well as serving as a central component of experimental design and analysis.</p>
<p>Unfortunately, these tests are easily subverted into playing the reverse role of providing a badge of approval, allowing researchers to make stronger claims than warranted by valid statistical analyses. Confidence intervals have been extensively promoted to address this problem, but they too have been subverted by being treated as if they are only testing null hypotheses. The consequences for evidence-based medicine have been dire.</p>
<p>There are three commonly stated principles (shown in Figure 1) of evidence-based medicine<span class="citation" data-cites="sackettEvidenceBasedMedicine1996"><sup>2</sup></span>:</p>
<ol type="1">
<li>reliance on statistically significant results (and thus NHST) from randomized controlled trials,</li>
<li>balancing of costs, benefits, and uncertainties in decision making, and</li>
<li>combining clinical expertise with external evidence to tailor treatments for individuals.</li>
</ol>
<p><em>Figure 1</em></p>
<p>Unfortunately, the use of NHST can get in the way of the movement toward an evidence-based framework. This may sound paradoxical, given that one of the foundations of evidence-based medicine is hypothesis testing based on randomized controlled trials, deemed by many to be the most reliable forms of evidence<span class="citation" data-cites="sackettEvidenceBasedMedicine1996"><sup>2</sup></span>. One problem is that reliance on statistical significance (principle 1) may conflict with the other principles: In conflict with balancing costs and benefits under uncertainty (principle 2), statistical significance or non-significance is typically used to replace uncertainty with certainty<span class="citation" data-cites="Greenland2017-es mcshaneAbandonStatisticalSignificance2019"><sup>3, 4</sup></span> — indeed, researchers are encouraged to do this and it is even forced by some journals<span class="citation" data-cites="bauchnerReportingInterpretationRandomized2019"><sup>5</sup></span>.</p>
<p>Reliance on statistical significance can interact badly with expertise and background evidence (principle 3), often leading to incoherent attempts at resolution. For example, researchers may do separate analyses for men and women, often with no biological basis for expecting other than small differences in effects (if any). In doing so they often find that one group (usually the larger one, which is usually men) show a “significant” effect while the other does not. They then misreport this difference in “significance” as if it represented a significant difference in effect between groups when in fact it only reflects a difference in the group sizes, plus random differences in group-specific P-values. Such misinterpretations fool researchers into thinking that the data support targeting treatments at the group showing “significance” and mislead clinicians into tailoring treatment plans for individuals based on nothing more than random variation.</p>
<p>The unfortunate reality is that estimating effects for individuals or population subsets requires far more sophistication than basic testing procedures<span class="citation" data-cites="sennStatisticalPitfallsPersonalized2018"><sup>6</sup></span>. It can take several times more patients to estimate variation in effects (“interactions”) than average effects<span class="citation" data-cites="greenlandTestsInteractionEpidemiologic1983"><sup>7</sup></span>. Given that few studies are large enough to estimate main effects of interest, it will typically be impossible to obtain reliable estimates of effect variation even if the study is otherwise flawless. That problem should be dealt with under principle (2) by recognizing that subgroups will have very imprecise estimates, leading to enormous uncertainties about who if anyone should be targeted for or excluded from treatment. Unfortunately, the prevalent misunderstandings of classical statistics have trained most researchers, editors, and reviewers to demand statistical significance and certainty as a prerequisite for publication<span class="citation" data-cites="Rosenthal1979-az"><sup>8</sup></span> and decision making. Applying those demands within subgroups all but guarantees that distorted impressions of patient-specific effects will follow.</p>
<p>Through neglect of basic education, the statistics profession is partly responsible for these issues, but there is nothing new about medicine’s desire for certainty. That desire is part of human nature and thus existed long before the adoption of statistical methods. The resulting demands for certainty in reported results have provided ample opportunities for overconfident researchers to rise to prominence. Physicians have long capitalized on several opportunities with their sophisticated knowledge of physiology and anatomy, and used their medical authority to argue what treatments worked, shape public policy, and design clinical guidelines, maintaining a form of medicine characterized as “eminence based.”</p>
<p><em>The landscape changed when advances in quantitative methods eventually reached medicine<span class="citation" data-cites="medicalresearchcouncilStreptomycinTreatmentPulmonary1948"><sup>9</sup></span>, leading to a newfound demand for scientific rigor and making many individuals wary of the claims of subject-matter experts<span class="citation" data-cites="goodmanWhyGettingRid2019"><sup>10</sup></span>. These demands may be some of the biggest contributors to medicine’s adoption of statistical methods and its movement towards an evidence-based framework. Unfortunately, in its pursuit for objectivity, medicine was sold snake oil statistics and as a result, its desire for objectivity and rigor backfired.</em></p>
<center>
<strong>Figure 2: Snake oil statistics.</strong> Methodological interventions that have been oversold by early adopters as cure alls despite no supporting evidence of utility in a particular application.
</center>
<p>To see the reach of these problems, one simply needs to look wherever a new drug has been considered effective only if it has been shown statistically significantly better than a control in one or more randomized clinical trials (a standard that applies to FDA new-drug approvals, though not to medical devices, which can be cleared through other pathways). The largest enforcers of these methods have been regulatory agencies that wish to minimize treatments that do not work (false positives) and minimize adverse events from treatments. One should ask: what specifically convinced these agencies that statistical significance and in particular NHST was the best analysis criterion to achieve these goals?</p>
<p>In a nonexistent ideal world, the regulatory agencies looked at several statistical methods, tested each of them in many settings to see how well they identified true benefits and harms while avoiding false conclusions, and from that determined NHST performed best out of all options – with periodic updates as new methods appeared. Of course, history shows something else entirely, even indicating that adoption of NHST was mainly a result of political desperation<span class="citation" data-cites="Kennedy-Shaffer2017-uw rubergInferenceDecisionMaking2019"><sup>11, 12</sup></span>. To understand the harsh reality, we must go back to the mid-20th century, when pharmaceutical companies submitted new drug applications to the FDA that often lacked any protocols and statistical analysis plans, making the entire drug approval process chaotic. By the end of the 1960s, the FDA had become desperate to standardize the drug-approval process and make it scientifically rigorous, especially with impending pressures from the Drug Amendments of 1962, which demanded rigorous evidence for drug approval.</p>
<p>At the same time, applied researchers were looking for rigorous ways to summarize experiments with numerical quantities. Their search struck gold with the works of the prominent statisticians, Ronald A. Fisher<span class="citation" data-cites="fisherStatisticalMethodsScientific1955 fisherStatisticalMethodsResearch1925 fisherDesignExperiments1935"><sup>13–15</sup></span>, Jerzy Neyman<span class="citation" data-cites="neymanProblemMostEfficient1933"><sup>16</sup></span>, and Egon Pearson<span class="citation" data-cites="pearsonSurveyUsesStatistical1933"><sup>17</sup></span>, who created and popularized powerful statistical tools for researchers that lacked statistical training. Eventually, researchers across many disciplines adopted NHST and the now-infamous 0.05 cutoff. Soon, the FDA followed and incorporated these methods into its regulatory process, without any formal debate about the methods’ utility or evidence<span class="citation" data-cites="rubergInferenceDecisionMaking2019"><sup>12</sup></span>.</p>
<p><strong>Figure 3: Austin Bradford Hill.</strong> The statistician and epidemiologist who conducted the first randomized controlled trial in medicine.</p>
<p>It thus appears that embracement of the NHST paradigm arose from expediently following the ascendant trend in research rather than a critical evaluation of various options emerging in the same period. Since its adoption into the regulatory process, this framework has been rigorously enforced by the FDA as the gold standard in the approval process.</p>
<p>We find it ironic that the gatekeepers of evidence-based medicine — regulatory agencies, journal editors and reviewers, and medical researchers – continue to insist on enforcement of a statistical framework that was never critically examined for its utility in medicine<span class="citation" data-cites="rubergInferenceDecisionMaking2019"><sup>12</sup></span>. This failure makes it understandable why it can be credibly argued that conventional statistical methods have done more harm than good in medical science. These methods, including null-hypothesis tests and so-called “confidence” intervals are a set of decision-making tools designed for tightly controlled randomized experiments in which the treatment effects (if any) can be distinguished from all other causal effects, and can be distinguished from random error (noise) by increasing the study size in an affordable manner. Examples of such scenarios arise in agricultural research where the experimental units are plants or plots, and industrial quality control, where the experimental unit is a part or product. The tools were originally developed for these environments, in which (compared to clinical studies) experimenters have almost godlike control over the selection of units and their subsequent experiences, aided by having a rather short follow-up period and low cost per experimental unit. And then, the decisions to be made are relatively simple and easily monitored, e.g., change a fertilizer formulation or manufacturing tolerance<span class="citation" data-cites="pearsonSurveyUsesStatistical1933"><sup>17</sup></span>. Experimental psychology is similar in terms of control, cost, and even lower cost-benefit consequences.</p>
<p>In clinical environments, however, the cost per experimental unit (the patient) is far higher, creating severe limits on study size and thus noise reduction, and the costs and benefits of decisions can be enormous. At the same time, there is far less control of extraneous selection and confounding effects: Physicians and their patients can and do selectively refuse to participate or cease to adhere to assigned treatment protocols, and may drop out for unknown reasons. Meanwhile, direct physical control of the patient environment is extremely limited or nonexistent, especially when follow-up extends beyond hospital stay. And then, amplifying these limits, the required decisions are often complex and of highly uncertain consequence, yet may be pivotal to the experimental results and clinical decisions, e.g., when to withdraw treatment from patients apparently experiencing side effects or when to switch treatments for nonresponsive patients.</p>
<p>These vast differences haven’t stopped medical researchers from using conventional methods as if they were operating in a tightly controlled environment, treating ambiguous trial results as if they supported decisive conclusions despite obvious uncertainties and potentially devastating consequences. The usual depictions of this problem involves researchers trying to “game” statistical methods so that they show “significant” effects<span class="citation" data-cites="Simmons2011-em wangResearcherRequestsInappropriate2018"><sup>18, 19</sup></span>; while such “significance questing” is a real problem, warnings about it usually ignore or dismiss opposite behavior in which showing “nonsignificance” will facilitate publication in prestigious medical journals, especially where so-called “replication failure” has become a hot topic<span class="citation" data-cites="Greenland2017-es"><sup>3</sup></span>. Adding to these distortions is the publication bias that results when researchers or editors deem results unworthy of submission or acceptance because they are just not interesting because they fail to report a “discovery” or only replicate what is “known.” This desire for novelty or publicity, along with demands for certainty, has distorted the medical literature with dubious, inflated effects<span class="citation" data-cites="dickersinMetaanalysisStateoftheScience1992"><sup>20</sup></span> and misleading claims of replication failure based on fundamentally ambiguous results<span class="citation" data-cites="amrheinScientistsRiseStatistical2019 amrheinInferentialStatisticsDescriptive2019"><sup>21, 22</sup></span>.</p>
<center>
<section id="responses-to-the-problems" class="level2">
<h2 class="anchored" data-anchor-id="responses-to-the-problems">Responses to the problems</h2>
</section></center>
<p><em>In response to the ongoing abuse of statistical testing, the American Statistical Association released a statement in 2016 cautioning against the fixating on P-values and statistical significance<span class="citation" data-cites="wassersteinASAStatementPValues2016"><sup>23</sup></span>. Three years later, the organization published an issue titled “A World Beyond P &lt; 0.05” with 43 commentaries from statistical experts on how to improve statistical inference, with or without P-values<span class="citation" data-cites="wassersteinMovingWorld052019"><sup>24</sup></span>. The issue was accompanied by a highly discussed commentary in Nature titled “Scientists Rise up Against Statistical Significance” that discouraged mindless automation and dichotomization of statistical results<span class="citation" data-cites="amrheinScientistsRiseStatistical2019"><sup>21</sup></span>, and was supported by signatures of some 800 applied researchers.</em></p>
<p>While these calls are impressive and a growing number of journals — including the New England Journal of Medicine and, in modified form, JAMA — have updated their statistical-reporting policies, most regulatory agencies and the bulk of the medical literature continue to fixate on statistical significance<span class="citation" data-cites="bauchnerReportingInterpretationRandomized2019 harringtonNewGuidelinesStatistical2019"><sup>5, 25</sup></span>. Correspondingly, we can expect medical researchers to keep cutting corners to achieve or remove statistical significance<span class="citation" data-cites="Simmons2011-em wangResearcherRequestsInappropriate2018"><sup>18, 19</sup></span> or misinterpret ambiguous results as if definitive, a practice that is often labeled as “spin”<span class="citation" data-cites="khanLevelPrevalenceSpin2019"><sup>26</sup></span>.</p>
<p>We can interpret the persistence of null hypothesis significance testing (NHST) in two ways. One story is that the value of NHST is recognized by real-world decision makers, despite the carping of ivory-tower critics such as the authors of the present article. The other story is that the counterproductive nature of NHST has been denied by the medical establishment<span class="citation" data-cites="bauchnerReportingInterpretationRandomized2019 harringtonNewGuidelinesStatistical2019"><sup>5, 25</sup></span>, and that better alternatives are available<span class="citation" data-cites="rubergInferenceDecisionMaking2019"><sup>12</sup></span>. There are legitimate practical concerns behind both these perspectives. On one hand, active researchers and regulators have legitimate concerns about working on or approving treatments that do not work. On the other hand, many well-publicized examples have made it clear that NHST can easily lead to overconfidence and erroneous inferences, as seen in discussions that treat statistically significance as demonstrating presence of effects and nonsignificance as demonstrating absence of effects.</p>
<center>

<section id="methodologists-propose-new-methods-to-address-nhst-in-their-field" class="level2">
<h2 class="anchored" data-anchor-id="methodologists-propose-new-methods-to-address-nhst-in-their-field">Methodologists propose new methods to address NHST in their field</h2>
</section></center>
<p>Fear of false positives has dominated most discussions of scientific rigor<span class="citation" data-cites="Benjamin2017-fz Ioannidis2018-ad Simmons2011-em"><sup>18, 27, 28</sup></span>, often relegating false negatives to more technical discussions of power. Although false positives can be costly, so can missing clinically meaningful effects<span class="citation" data-cites="amrheinScientistsRiseStatistical2019"><sup>21</sup></span>. Take postmarketing surveillance for pharmaceuticals; in such situations, serious adverse events from drugs are often underreported and have in some cases been actively suppressed<span class="citation" data-cites="Vandenbroucke2008 Doshi2012"><sup>29, 30</sup></span>, as seen in Cochrane reviews of unpublished trial data, leading to a scarcity of data and resulting in studies that will never be able to show a “significant” effect because of the lack of resources and time. If a study comparing adverse events from those taking an approved drug and some control group is unable to show statistical significance, even when the estimated effect is important and plausible, the results will typically be confused and used for evidence of absence<span class="citation" data-cites="altmanAbsenceEvidenceNot1995 amrheinScientistsRiseStatistical2019"><sup>21, 31</sup></span>, and prescribing is unlikely to be curtailed, leading to continued harm.</p>
<p>The confusion of statistical nonsignificance with evidence of absence will remain a problem in fields where effects are often small and yet studies powered to detect them are infeasible. Most studies in surgical science rarely have more than a dozen participants. Again, this makes it incredibly difficult to achieve statistical significance, even when clinically important effects are likely. In such fields, adopting the NHST framework for analysis all but guarantees failure to detect those effects. As a result, researchers have looked to other methods — including Bayes factors, second-generation P-values, and post-hoc power calculations — to circumvent the bad hand that was dealt to them<span class="citation" data-cites="gigerenzerSurrogateScienceIdol2015 vanravenzwaaijBayesFactorsSuperiority2019 Simonsohn2014-bv"><sup>32–34</sup></span>. Unfortunately, such transitions are not always helpful: while reasonably defensible alternatives such as interval testing and posterior intervals do exist, several of the most-publicized proposals introduce their own errors, and in fact, some may actually result in more errors than before.</p>
<p>For example, a group of surgeons recently published several statistical recommendations on what to do if a surgical study result was nonsignificant<span class="citation" data-cites="bababekovProposalMitigateConsequences2018 bababekovPowerThresholdApplicable2019 bababekovPostHocPower2019"><sup>35–37</sup></span>, providing hope to researchers who have had their inquiries halted by that result. But the recommendations are not only statistically invalid and clinically misleading, and thus have been discouraged by statisticians for nearly two decades<span class="citation" data-cites="Greenland2012-by Hoenig2001-vi"><sup>38, 39</sup></span>. In a similar tale, two sports scientists published a statistical method<span class="citation" data-cites="dankelMethodStopAnalyzing2019"><sup>40</sup></span> which was supposed to improve the classification of individual treatment responses by reducing the influence of random error in small studies. Unfortunately, reducing the influence of random error in a valid manner requires improvement of study design, including increase in study size, so unsurprisingly the proposed method has unacceptably poor statistical properties<span class="citation" data-cites="tenanStatisticalPropertiesDankelLoenneke2019"><sup>41</sup></span>.</p>
<p>The efforts behind new methods and recommendations are a response to an arbitrary dichotomy that has been imposed upon researchers by the medical and scientific establishment: decide whether a result is “positive” or “negative”, with no allowance for what is usually the most reasonable interpretation – ambiguous or indecisive. Unfortunately, conventional statistics has aggravated this problem by offering methods like NHST which produce only dichotomous answers. These methods which swept research sciences in the mid-20th century and are now firmly rooted in tradition, as if that tradition is the best we can do. But it isn’t.</p>
<p>The problem with upending this tradition however is that there is no consensus about what to replace it with, a problem that only grows as alternatives continue to proliferate. A idealistic (and we think naïve) view would simply allow authors to choose alternatives of their liking. The problem with this anarchic approach is that many of the alternatives are themselves misleading and even defective or at best inferior to other methods in demonstrable ways. Yet seeing these problems requires not only sufficient technical expertise to evaluate methods, but also a willingness to see them – a willingness that should not be assumed for originators and adopters of the method. Unfortunately, mere publication of a method in a peer-reviewed journal is a faulty indicator of method validity. That is especially so if publication is not in a statistics journal, for in that case it means only that peer-review was by referees who may have had little of the special technical expertise needed for thorough evaluation.</p>
<center>

<section id="solutions" class="level2">
<h2 class="anchored" data-anchor-id="solutions">Solutions</h2>
</section></center>
<p>There are no simple solutions or universal guidelines that medical researchers can always use to improve scientific rigor within their area of work. We nonetheless offer some recommendations and resources that we believe may be useful to those who recognize problems in their field and wish for some sort of guidance:</p>
<ol type="1">
<li>Collaborate with well-qualified statisticians to design and conduct studies that are rigorous, efficient, and cost effective<span class="citation" data-cites="Gelman2014-qk Rothman2018-tf"><sup>42, 43</sup></span>. Look to these statistical collaborators for guidance about honestly reporting uncertainty, not certainty<span class="citation" data-cites="wangResearcherRequestsInappropriate2018"><sup>19</sup></span>.</li>
<li>If possible, pool resources to run larger studies that are likely to be more precise and informative than individual studies, which may simply waste resources and offer little yield<span class="citation" data-cites="moshontzPsychologicalScienceAccelerator2018"><sup>44</sup></span>. However, more data is not synonymous with more information: Increasing study size may be detrimental if it entails a reduction in data quality<span class="citation" data-cites="coxPrinciplesAppliedStatistics2011"><sup>45</sup></span>.</li>
<li>Aim to be more descriptive and less inferential<span class="citation" data-cites="amrheinInferentialStatisticsDescriptive2019"><sup>22</sup></span>. Accept uncertainty and the anxiety that comes with it<span class="citation" data-cites="mcshaneAbandonStatisticalSignificance2019"><sup>4</sup></span>, along with the idea that no one study warrants conclusions about the true nature of a phenomenon, a delusion that is not even true in particle physics! And if a phenomenon is subtle, even several studies may be insufficient for valid conclusions beyond “more research is needed.”</li>
<li>When making real world decisions, use all information available to you, balancing costs, benefits, and uncertainties<span class="citation" data-cites="parmigianiDecisionTheoryPrinciples2009"><sup>46</sup></span>, rather than basing decisions on whether a single numerical value is above or below an arbitrary cutoff.</li>
<li>Be mindful of cognitive biases that may distort your conclusions throughout the study and the many cognitive biases that will afflict you, your colleagues, and your collaborators<span class="citation" data-cites="gigerenzerMindlessStatistics2004 Greenland2017-es Stark2018-eo"><sup>3, 47, 48</sup></span>.</li>
<li>Use statistical methods that have been reviewed and validated by the statistical community beyond their developers and promoters. That validation is provided not only by publication in statistical journals, but also by applications that can be judged as having reached sound, well-cautioned conclusions in context. Especially, beware of any method that (like NHST) claims to offer firm conclusions based on purely numeric comparisons.</li>
</ol>

<section id="references" class="level1">



<!-- -->


</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-boringMathematicalVsScientific1919" class="csl-entry">
1. Boring EG. (1919). <span>“Mathematical vs. Scientific significance.”</span> <em>Psychological Bulletin</em>. <strong>16</strong>:335–338. doi: <a href="https://doi.org/10.1037/h0074554">10.1037/h0074554</a>.
</div>
<div id="ref-sackettEvidenceBasedMedicine1996" class="csl-entry">
2. Sackett DL, Rosenberg WM, Gray JA, Haynes RB, Richardson WS. (1996). <span>“Evidence based medicine: What it is and what it isn’t.”</span> <em>BMJ (Clinical research ed)</em>. <strong>312</strong>:71–72. doi: <a href="https://doi.org/10.1136/bmj.312.7023.71">10.1136/bmj.312.7023.71</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-mcshaneAbandonStatisticalSignificance2019" class="csl-entry">
4. McShane BB, Gal D, Gelman A, Robert C, Tackett JL. (2019). <span>“Abandon <span>Statistical Significance</span>.”</span> <em>The American Statistician</em>. <strong>73</strong>:235–245. doi: <a href="https://doi.org/10.1080/00031305.2018.1527253">10.1080/00031305.2018.1527253</a>.
</div>
<div id="ref-bauchnerReportingInterpretationRandomized2019" class="csl-entry">
5. Bauchner H, Golub RM, Fontanarosa PB. (2019). <span>“Reporting and <span>Interpretation</span> of <span>Randomized Clinical Trials</span>.”</span> <em>Journal of the American Medical Association</em>. <strong>322</strong>:732–735. doi: <a href="https://doi.org/10.1001/jama.2019.12056">10.1001/jama.2019.12056</a>.
</div>
<div id="ref-sennStatisticalPitfallsPersonalized2018" class="csl-entry">
6. Senn S. (2018). <span>“Statistical pitfalls of personalized medicine.”</span> <em>Nature</em>. <strong>563</strong>:619–621. doi: <a href="https://doi.org/10.1038/d41586-018-07535-2">10.1038/d41586-018-07535-2</a>.
</div>
<div id="ref-greenlandTestsInteractionEpidemiologic1983" class="csl-entry">
7. Greenland S. (1983). <span>“Tests for interaction in epidemiologic studies: <span>A</span> review and a study of power.”</span> <em>Statistics in Medicine</em>. <strong>2</strong>:243–251. doi: <a href="https://doi.org/10.1002/sim.4780020219">10.1002/sim.4780020219</a>.
</div>
<div id="ref-Rosenthal1979-az" class="csl-entry">
8. Rosenthal R. (1979). <span>“The file drawer problem and tolerance for null results.”</span> <em>Psychol Bull</em>. <strong>86</strong>:638. doi: <a href="https://doi.org/10.1037/0033-2909.86.3.638">10.1037/0033-2909.86.3.638</a>.
</div>
<div id="ref-medicalresearchcouncilStreptomycinTreatmentPulmonary1948" class="csl-entry">
9. Council MR. (1948). <span>“<a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2091872">Streptomycin <span>Treatment</span> of <span>Pulmonary Tuberculosis</span></a>.”</span> <em>British Medical Journal</em>. <strong>2</strong>:769–782.
</div>
<div id="ref-goodmanWhyGettingRid2019" class="csl-entry">
10. Goodman SN. (2019). <span>“Why is <span>Getting Rid</span> of <span>P</span>-<span>Values So Hard</span>? <span>Musings</span> on <span>Science</span> and <span>Statistics</span>.”</span> <em>The American Statistician</em>. <strong>73</strong>:26–30. doi: <a href="https://doi.org/10.1080/00031305.2018.1558111">10.1080/00031305.2018.1558111</a>.
</div>
<div id="ref-Kennedy-Shaffer2017-uw" class="csl-entry">
11. Kennedy-Shaffer L. (2017). <span>“<a href="https://www.ncbi.nlm.nih.gov/pubmed/30294197">When the <span>Alpha</span> is the <span>Omega</span>: <span>P</span>-<span>Values</span>, <span>‘<span>Substantial Evidence</span>,’</span> and the 0.05 <span>Standard</span> at <span>FDA</span></a>.”</span> <em>Food Drug Law J</em>. <strong>72</strong>:595–635.
</div>
<div id="ref-rubergInferenceDecisionMaking2019" class="csl-entry">
12. Ruberg SJ, Jr FEH, Gamalo-Siebers M, LaVange L, Lee JJ, Price K, et al. (2019). <span>“Inference and <span>Decision Making</span> for 21st-<span>Century Drug Development</span> and <span>Approval</span>.”</span> <em>The American Statistician</em>. <strong>73</strong>:319–327. doi: <a href="https://doi.org/10.1080/00031305.2019.1566091">10.1080/00031305.2019.1566091</a>.
</div>
<div id="ref-fisherStatisticalMethodsScientific1955" class="csl-entry">
13. Fisher R. (1955). <span>“Statistical <span>Methods</span> and <span>Scientific Induction</span>.”</span> <em>Journal of the Royal Statistical Society Series B (Methodological)</em>. <strong>17</strong>:69–78. doi: <a href="https://doi.org/10.1111/j.2517-6161.1955.tb00180.x">10.1111/j.2517-6161.1955.tb00180.x</a>.
</div>
<div id="ref-fisherStatisticalMethodsResearch1925" class="csl-entry">
14. Fisher RA. (1925). <span>“Statistical <span>Methods</span> for <span>Research Workers</span>.”</span> <span>Oliver and Boyd</span>: <span>Edinburgh</span>.
</div>
<div id="ref-fisherDesignExperiments1935" class="csl-entry">
15. Fisher RA. (1935). <span>“The <span>Design</span> of <span>Experiments</span>.”</span> <span>Oxford, England</span>: <span>Oliver &amp; Boyd</span>.
</div>
<div id="ref-neymanProblemMostEfficient1933" class="csl-entry">
16. Neyman J, Pearson ES. (1933). <span>“On the <span>Problem</span> of the <span>Most Efficient Tests</span> of <span>Statistical Hypotheses</span>.”</span> <em>Philosophical Transactions of the Royal Society of London Series A, Containing Papers of a Mathematical or Physical Character</em>. <strong>231</strong>:289–337. doi: <a href="https://doi.org/10.1098/rsta.1933.0009">10.1098/rsta.1933.0009</a>.
</div>
<div id="ref-pearsonSurveyUsesStatistical1933" class="csl-entry">
17. Pearson ES. (1933). <span>“A <span>Survey</span> of the <span>Uses</span> of <span>Statistical Method</span> in the <span>Control</span> and <span>Standardization</span> of the <span>Quality</span> of <span>Manufactured Products</span>.”</span> <em>Journal of the Royal Statistical Society</em>. <strong>96</strong>:21–75. doi: <a href="https://doi.org/10.2307/2341869">10.2307/2341869</a>.
</div>
<div id="ref-Simmons2011-em" class="csl-entry">
18. Simmons JP, Nelson LD, Simonsohn U. (2011). <span>“False-positive psychology: Undisclosed flexibility in data collection and analysis allows presenting anything as significant.”</span> <em>Psychological Science</em>. <strong>22</strong>:1359–1366. doi: <a href="https://doi.org/10.1177/0956797611417632">10.1177/0956797611417632</a>.
</div>
<div id="ref-wangResearcherRequestsInappropriate2018" class="csl-entry">
19. Wang MQ, Yan AF, Katz RV. (2018). <span>“Researcher requests for inappropriate analysis and reporting: <span>A U</span>.<span>S</span>. Survey of consulting biostatisticians.”</span> <em>Annals of Internal Medicine</em>. <strong>169</strong>:554. doi: <a href="https://doi.org/10.7326/M18-1230">10.7326/M18-1230</a>.
</div>
<div id="ref-dickersinMetaanalysisStateoftheScience1992" class="csl-entry">
20. Dickersin K, Berlin JA. (1992). <span>“Meta-analysis: <span>State</span>-of-the-<span>Science</span>.”</span> <em>Epidemiologic Reviews</em>. <strong>14</strong>:154–176. doi: <a href="https://doi.org/10.1093/oxfordjournals.epirev.a036084">10.1093/oxfordjournals.epirev.a036084</a>.
</div>
<div id="ref-amrheinScientistsRiseStatistical2019" class="csl-entry">
21. Amrhein V, Greenland S, McShane B. (2019). <span>“Scientists rise up against statistical significance.”</span> <em>Nature</em>. <strong>567</strong>:305. doi: <a href="https://doi.org/10.1038/d41586-019-00857-9">10.1038/d41586-019-00857-9</a>.
</div>
<div id="ref-amrheinInferentialStatisticsDescriptive2019" class="csl-entry">
22. 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-wassersteinASAStatementPValues2016" class="csl-entry">
23. Wasserstein RL, Lazar NA. (2016). <span>“The <span>ASA Statement</span> on p-<span>Values</span>: <span>Context</span>, <span>Process</span>, and <span>Purpose</span>.”</span> <em>The American Statistician</em>. <strong>70</strong>:129–133. doi: <a href="https://doi.org/10.1080/00031305.2016.1154108">10.1080/00031305.2016.1154108</a>.
</div>
<div id="ref-wassersteinMovingWorld052019" class="csl-entry">
24. Wasserstein RL, Schirm AL, Lazar NA. (2019). <span>“Moving to a world beyond <span>‘p <span><img src="https://latex.codecogs.com/png.latex?%3C"></span> 0.05’</span>.”</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 id="ref-harringtonNewGuidelinesStatistical2019" class="csl-entry">
25. Harrington D, D’Agostino RB, Gatsonis C, Hogan JW, Hunter DJ, Normand S-LT, et al. (2019). <span>“New guidelines for statistical reporting in the journal.”</span> <em>New England Journal of Medicine</em>. <strong>381</strong>:285–286. doi: <a href="https://doi.org/10.1056/NEJMe1906559">10.1056/NEJMe1906559</a>.
</div>
<div id="ref-khanLevelPrevalenceSpin2019" class="csl-entry">
26. Khan MS, Lateef N, Siddiqi TJ, Rehman KA, Alnaimat S, Khan SU, et al. (2019). <span>“Level and <span>Prevalence</span> of <span>Spin</span> in <span>Published Cardiovascular Randomized Clinical Trial Reports With Statistically Nonsignificant Primary Outcomes</span>: <span>A Systematic Review</span>.”</span> <em>JAMA Network Open</em>. <strong>2</strong>:e192622–e192622. doi: <a href="https://doi.org/10.1001/jamanetworkopen.2019.2622">10.1001/jamanetworkopen.2019.2622</a>.
</div>
<div id="ref-Benjamin2017-fz" class="csl-entry">
27. Benjamin DJ, Berger JO, Johannesson M, Nosek BA, Wagenmakers E, Berk R, et al. (2017). <span>“Redefine statistical significance.”</span> <em>Nature Human Behaviour</em>. <strong>2</strong>:6–10. doi: <a href="https://doi.org/10.1038/s41562-017-0189-z">10.1038/s41562-017-0189-z</a>.
</div>
<div id="ref-Ioannidis2018-ad" class="csl-entry">
28. Ioannidis JPA. (2018). <span>“The <span>Proposal</span> to <span>Lower P Value Thresholds</span> to .005.”</span> <em>JAMA</em>. <strong>319</strong>:1429–1430. doi: <a href="https://doi.org/10.1001/jama.2018.1536">10.1001/jama.2018.1536</a>.
</div>
<div id="ref-Vandenbroucke2008" class="csl-entry">
29. Vandenbroucke JP, Psaty BM. (2008). <span>“Benefits and risks of drug treatments: How to combine the best evidence on benefits with the best data about adverse effects.”</span> <em>JAMA</em>. <strong>300</strong>:2417–2419. doi: <a href="https://doi.org/10.1001/jama.2008.723">10.1001/jama.2008.723</a>. <a href="https://doi.org/10.1001/jama.2008.723">https://doi.org/10.1001/jama.2008.723</a>.
</div>
<div id="ref-Doshi2012" class="csl-entry">
30. Doshi P, Jefferson T, Del Mar C. (2012). <span>“The imperative to share clinical study reports: Recommendations from the <span>Tamiflu</span> experience.”</span> <em>PLoS Medicine</em>. <strong>9</strong>:e1001201. doi: <a href="https://doi.org/10.1371/journal.pmed.1001201">10.1371/journal.pmed.1001201</a>. <a href="https://doi.org/10.1371/journal.pmed.1001201">https://doi.org/10.1371/journal.pmed.1001201</a>.
</div>
<div id="ref-altmanAbsenceEvidenceNot1995" class="csl-entry">
31. Altman DG, Bland JM. (1995). <span>“Absence of evidence is not evidence of absence.”</span> <em>BMJ (Clinical research ed)</em>. <strong>311</strong>:485. doi: <a href="https://doi.org/10.1136/bmj.311.7003.485">10.1136/bmj.311.7003.485</a>.
</div>
<div id="ref-gigerenzerSurrogateScienceIdol2015" class="csl-entry">
32. Gigerenzer G, Marewski JN. (2015). <span>“Surrogate <span>Science</span>: <span>The Idol</span> of a <span>Universal Method</span> for <span>Scientific Inference</span>.”</span> <em>Journal of Management</em>. <strong>41</strong>:421–440. doi: <a href="https://doi.org/10.1177/0149206314547522">10.1177/0149206314547522</a>.
</div>
<div id="ref-vanravenzwaaijBayesFactorsSuperiority2019" class="csl-entry">
33. <span class="nocase">van Ravenzwaaij D, Monden R, Tendeiro JN, Ioannidis JPA</span>. (2019). <span>“Bayes factors for superiority, non-inferiority, and equivalence designs.”</span> <em>BMC Medical Research Methodology</em>. <strong>19</strong>:71. doi: <a href="https://doi.org/10.1186/s12874-019-0699-7">10.1186/s12874-019-0699-7</a>.
</div>
<div id="ref-Simonsohn2014-bv" class="csl-entry">
34. Simonsohn U, Nelson LD, Simmons JP. (2014). <span>“P-<span>Curve</span> and <span>Effect Size</span>: <span>Correcting</span> for <span>Publication Bias Using Only Significant Results</span>.”</span> <em>Perspect Psychol Sci</em>. <strong>9</strong>:666–681. doi: <a href="https://doi.org/10.1177/1745691614553988">10.1177/1745691614553988</a>.
</div>
<div id="ref-bababekovProposalMitigateConsequences2018" class="csl-entry">
35. Bababekov YJ, Stapleton SM, Mueller JL, Fong ZV, Chang DC. (2018). <span>“A <span>Proposal</span> to <span>Mitigate</span> the <span>Consequences</span> of <span>Type</span> 2 <span>Error</span> in <span>Surgical Science</span>.”</span> <em>Annals of Surgery</em>. <strong>267</strong>:621. doi: <a href="https://doi.org/10.1097/SLA.0000000000002547">10.1097/SLA.0000000000002547</a>.
</div>
<div id="ref-bababekovPowerThresholdApplicable2019" class="csl-entry">
36. Bababekov YJ, Hung Y-C, Hsu Y-T, Udelsman BV, Mueller JL, Lin H-Y, et al. (2019). <span>“Is the <span>Power Threshold</span> of 0.8 <span>Applicable</span> to <span>Surgical Science</span>? The <span>Underpowered Study</span>.”</span> <em>Journal of Surgical Research</em>. <strong>241</strong>:235–239. doi: <a href="https://doi.org/10.1016/j.jss.2019.03.062">10.1016/j.jss.2019.03.062</a>.
</div>
<div id="ref-bababekovPostHocPower2019" class="csl-entry">
37. Bababekov YJ, Chang DC. (2019). <span>“Post <span>Hoc Power</span>: <span>A Surgeon</span>’s <span>First Assistant</span> in <span>Interpreting</span> <span>‘<span>Negative</span>’</span> <span>Studies</span>.”</span> <em>Annals of Surgery</em>. doi: <a href="https://doi.org/10.1097/SLA.0000000000002914">10.1097/SLA.0000000000002914</a>.
</div>
<div id="ref-Greenland2012-by" class="csl-entry">
38. Greenland S. (2012). <span>“Nonsignificance plus high power does not imply support for the null over the alternative.”</span> <em>Annals of Epidemiology</em>. <strong>22</strong>:364–368. doi: <a href="https://doi.org/10.1016/j.annepidem.2012.02.007">10.1016/j.annepidem.2012.02.007</a>.
</div>
<div id="ref-Hoenig2001-vi" class="csl-entry">
39. Hoenig JM, Heisey DM. (2001). <span>“The <span>Abuse</span> of <span>Power</span>.”</span> <em>The American Statistician</em>. <strong>55</strong>:19–24. doi: <a href="https://doi.org/10.1198/000313001300339897">10.1198/000313001300339897</a>.
</div>
<div id="ref-dankelMethodStopAnalyzing2019" class="csl-entry">
40. Dankel SJ, Loenneke JP. (2019). <span>“A <span>Method</span> to <span>Stop Analyzing Random Error</span> and <span>Start Analyzing Differential Responders</span> to <span>Exercise</span>.”</span> <em>Sports Medicine</em>. doi: <a href="https://doi.org/10.1007/s40279-019-01147-0">10.1007/s40279-019-01147-0</a>.
</div>
<div id="ref-tenanStatisticalPropertiesDankelLoenneke2019" class="csl-entry">
41. Tenan M, Vigotsky AD, Caldwell AR. (2019). <span>“On the <span>Statistical Properties</span> of the <span>Dankel</span>-<span>Loenneke Method</span>.”</span> <em>SportRxiv</em>. doi: <a href="https://doi.org/10.31236/osf.io/8ndhg">10.31236/osf.io/8ndhg</a>.
</div>
<div id="ref-Gelman2014-qk" class="csl-entry">
42. Gelman A, Carlin J. (2014). <span>“Beyond <span>Power Calculations</span>: <span>Assessing Type S</span> (<span>Sign</span>) and <span>Type M</span> (<span>Magnitude</span>) <span>Errors</span>.”</span> <em>Perspectives on Psychological Science</em>. <strong>9</strong>:641–651. doi: <a href="https://doi.org/10.1177/1745691614551642">10.1177/1745691614551642</a>.
</div>
<div id="ref-Rothman2018-tf" class="csl-entry">
43. Rothman KJ, Greenland S. (2018). <span>“Planning study size based on precision rather than power.”</span> <em>Epidemiology</em>. <strong>29</strong>:599–603. doi: <a href="https://doi.org/10.1097/EDE.0000000000000876">10.1097/EDE.0000000000000876</a>.
</div>
<div id="ref-moshontzPsychologicalScienceAccelerator2018" class="csl-entry">
44. Moshontz H, Campbell L, Ebersole CR, IJzerman H, Urry HL, Forscher PS, et al. (2018). <span>“The <span>Psychological Science Accelerator</span>: <span>Advancing Psychology Through</span> a <span>Distributed Collaborative Network</span>:”</span> <em>Advances in Methods and Practices in Psychological Science</em>. doi: <a href="https://doi.org/10.1177/2515245918797607">10.1177/2515245918797607</a>.
</div>
<div id="ref-coxPrinciplesAppliedStatistics2011" class="csl-entry">
45. Cox DR, Donnelly CA. (2011). <span>“Principles of <span>Applied Statistics</span>.”</span> <span>Cambridge University Press</span>.
</div>
<div id="ref-parmigianiDecisionTheoryPrinciples2009" class="csl-entry">
46. Parmigiani G, Inoue L. (2009). <span>“Decision <span>Theory</span>: <span>Principles</span> and <span>Approaches</span>.”</span> <span>John Wiley &amp; Sons</span>.
</div>
<div id="ref-gigerenzerMindlessStatistics2004" class="csl-entry">
47. Gigerenzer G. (2004). <span>“Mindless statistics.”</span> <em>The Journal of Socio-Economics</em>. <strong>33</strong>:587–606. doi: <a href="https://doi.org/10.1016/j.socec.2004.09.033">10.1016/j.socec.2004.09.033</a>.
</div>
<div id="ref-Stark2018-eo" class="csl-entry">
48. 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></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 Rafi, Zad and Gelman, Andrew and Reito, Aleksi
    and Greenland, Sander},
  title = {Medicine {Is} {Being} {Treated} with {Snake-Oil}
    {Statistics}},
  date = {2020-11-11},
  url = {https://lesslikely.com/statistics/snakeoilstats.html},
  langid = {en-US}
}
</code></pre></div></section></div> ]]></description>
  <category>statistics</category>
  <guid>https://lesslikely.com/statistics/snakeoilstats.html</guid>
  <pubDate>Wed, 11 Nov 2020 05:00:00 GMT</pubDate>
</item>
<item>
  <title>Quality Control in Statistical Analyses</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/statistics/statistical-quality-control.html</link>
  <description><![CDATA[ 





<hr>
<p>Experienced statisticians and data analysts are familiar with stories where a coding error has led to an entire conclusion changing, <a href="https://jamanetwork.com/journals/jama/fullarticle/2752474">or even a retraction</a>.[@aboumatarNoticeRetractionAboumatar2019] It’s the sort of stuff that keeps people up at night. Unfortunately, not many of us think about these sorts of scenarios until we realize it’s very possible that it could happen to any of us.</p>
<p>To me, it seems that many of these issues could be avoided by having a principled data management and statistical workflow, and making it as transparent, open, and reproducible as possible. I’d like to quickly go over a few things that I’ve found helpful over the years, and I’ll first start with data management and data entry and then move onto analysis workflows. I largely consider this to be a living document, and I’m sure many people who will read this will have far better suggestions, so please leave them down below in the comments!</p>
<p>Before I go on, I want to emphasize that backing up your data, scripts, and <a href="https://happygitwithr.com/">using version control</a> is extremely important. There is no debate about this. It’s necessary so that other collaborators/colleagues can inspect your work and catch potential mistakes or see overall progress, but more importantly, it will prevent you from losing your data in a disaster, and it’ll help you catch your own mistakes, since you’ll be the most familiar with the data and scripts.</p>
<hr>
<section id="data-entry-management" class="level1">
<h1>Data Entry &amp; Management</h1>
<hr>
<p>A nice paper that I’d like to review is the one by <a href="https://doi.org/10.1080/00031305.2017.1375989">Broman &amp; Woo, 2018</a> on how to manage your data when working with spreadsheets.[@bromanDataOrganizationSpreadsheets2018] The sad reality is that even though spreadsheets like Microsoft Excel or Google Sheets are available everywhere, and easy to use, there are many risks when working with spreadsheets, just ask any <a href="https://genomebiology.biomedcentral.com/articles/10.1186/s13059-016-1044-7?fbclid=IwAR06eQ5LTg2LX5byJBWfC6rJdAbAGXKvy3PUOhzPsVjUGqb7KqB1V_x36M0">statistician who works in genetics</a> or any bioinformatician.[@ziemannGeneNameErrors2016]</p>
<p>One of the most fatal errors <a href="https://theconversation.com/why-you-should-never-use-microsoft-excel-to-count-coronavirus-cases-147681">occurred recently</a> when a group of researchers lost thousands of documented COVID cases because they entered data for each case as a column instead of a row, and Excel has a limit on how many columns and rows it can handle (<strong>1,048,576 rows</strong> and <strong>16,384 columns</strong>, <a href="https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3">according to Microsoft</a>), as a result, most of these cases were lost, resulting in an enormous waste of resources due to a careless and ignorant mistake, highlighting the dangers of recklessly inputting data and conducting statistical analyses. There is no doubt that reviewing principles of good data management and workflow are essential to any data analyst. I’d like to touch on some of the most important points of <a href="https://doi.org/10.1080/00031305.2017.1375989">Broman &amp; Woo, 2018</a> paper before moving onto some other “principles” I’d like to share:</p>
<hr>
<section id="general-principle-be-consistent-with-everything" class="level2">
<h2 class="anchored" data-anchor-id="general-principle-be-consistent-with-everything">General Principle: Be Consistent With Everything</h2>
<hr>

<ul>
<li>When labeling missing values (<code>NA</code>, <code>N/A</code>, etc.):
<ul>
<li><p>
<span style="color:#7aa864; font-weight: 700;">Good</span>: Choose one method (<code>NA</code>, <code>N/A</code>, etc.) and stick with it.
</p></li>
<li><p>
<span style="color:#CD5C5C; font-weight: 700;">Bad</span>: Leaving cells empty to indicate missingness.
</p></li>
</ul></li>
</ul>
<hr>
<ul>
<li>When labeling response variables:
<ul>
<li><p>
<span style="color:#7aa864; font-weight: 700;">Good</span>: If you label a response variable consistently, for example, <code>fat-free-mass</code> in every instance to refer to the same variable.
</p></li>
<li><p>
<span style="color:#CD5C5C; font-weight: 700;">Bad</span>: If you label a response variable <code>fat-free-mass</code> in one script/sheet, and <code>ffm</code>/<code>fat_free_mass</code> in another.
</p></li>
</ul></li>
</ul>
<hr>
<ul>
<li>When formatting variable predictor names:
<ul>
<li><p>
<span style="color:#7aa864; font-weight: 700;">Good</span>: <code>predictor_1_week12</code>, <code>predictor_2_week12</code>, <code>response_variable_week12</code>. This is consistent, with the order of the names, and dates/weeks, so it is easier to organize, inspect, and clean. Same thing applies to labeling response variables and pretty much all variables.
</p></li>
<li><p>
<span style="color:#CD5C5C; font-weight: 700;">Bad</span>: When you label one variable <code>week12_predictor_1</code>, the next <code>predictor_2_week12</code>, and the last, <code>12_week_response</code>. Just <em>no</em>.
</p></li>
</ul></li>
</ul>
<hr>
<ul>
<li>When formatting dates:
<ul>
<li><p>
<span style="color:#7aa864; font-weight: 700;">Good</span>: Use one format, <code>YYYY-MM-DD</code>, consistently.
</p></li>
<li><p>
<span style="color:#CD5C5C; font-weight: 700;">Bad</span>: Everything else.
</p></li>
</ul></li>
</ul>
<hr>
<ul>
<li>When filling out cells:
<ul>
<li><p>
<span style="color:#7aa864; font-weight: 700;">Good</span>: One cell = one thing. No more, no less.
</p></li>
<li><p>
<span style="color:#CD5C5C; font-weight: 700;">Bad</span>: One cell = multiple entries or no entries at all.
</p></li>
</ul></li>
</ul>
<hr>
<ul>
<li>When keeping track of the data:
<ul>
<li><p>
<span style="color:#7aa864; font-weight: 700;">Good</span>: Create a comprehensive data dictionary so anyone can look at it and understand the spreadsheets/dataframes/variables.
</p></li>
<li><p>
<span style="color:#CD5C5C; font-weight: 700;">Bad</span>: Expecting yourself and others to figure it out based on the variable names that you thought were brilliant.
</p></li>
</ul></li>
</ul>
<hr>
<ul>
<li>When using Excel or Google Sheet’s shiny features:
<ul>
<li><p>
<span style="color:#7aa864; font-weight: 700;">Good</span>: Avoid using any of them, any formulas, highlighting, <em>italicizing</em>, <span style="font-weight:700;">bolding</span>, etc.
</p></li>
<li><p>
<span style="color:#CD5C5C; font-weight: 700;">Bad</span>: If you’re the type of person to create charts in Excel.
</p></li>
</ul></li>
</ul>
<hr>
<ul>
<li>Planning for disasters:
<ul>
<li><p>
<span style="color:#7aa864; font-weight: 700;">Good</span>: Always, always, backup your files, save them in .txt files. Keep backups of those. And most importantly, <a href="https://happygitwithr.com/"><strong>use version control!</strong></a>
</p></li>
<li><p>
<span style="color:#CD5C5C; font-weight: 700;">Bad</span>: You don’t really plan for disasters and go with the flow.
</p></li>
</ul></li>
</ul>

<hr>
<ul>
<li>Last but not least, when entering cases:
<ul>
<li><p>
</p><p><span style="color:#7aa864; font-weight: 700;">Good</span>: Rows are for cases and observations, and columns are for variables and characteristics. Please do not switch these up!</p></li>
<li><p>
</p><p><span style="color:#CD5C5C; font-weight: 700;">Bad</span>: Using them interchangeably.</p></li>
</ul></li>
</ul>
<hr>
</section>
</section>
<section id="setting-up-a-principled-statistical-workflow" class="level1">
<h1>Setting Up a Principled Statistical Workflow</h1>
<hr>
<p>Here’s what I’ve been doing for many years and what seems to work for me (none of these ideas are originally mine, and I actually picked them up over the years from others’ advice, which will be linked below).</p>
<hr>
<section id="setting-up-the-project-folder" class="level2">
<h2 class="anchored" data-anchor-id="setting-up-the-project-folder">Setting up the Project Folder</h2>
<hr>
<p>When setting up a folder specific for a project (if you’re not doing this, you absolutely need to), first, I will create a folder with the title of my project, and usually have an <a href="https://rstudio.com/"><code>RStudio</code></a> project set up in there.</p>
<hr>
<blockquote class="blockquote">
<p>Disclaimer: while much of this advice will be familiar and easy to understand for those who use <code>R</code>, I think the general principles are widely applicable, especially for those who use scripts in their statistical software).</p>
</blockquote>
<hr>
<p>This folder will contain many other folders (more on that below), so the structure will end up being a bit complex.</p>
<hr>
<p><img data-enlargeable="" style="cursor: zoom-in" src="https://res.cloudinary.com/less-likely/image/upload/v1613136545/Site/diagram.png" alt="workflow"></p>
<hr>
<blockquote class="blockquote">
<p>It may be a bit difficult to read the words within the circles, but clicking on the diagram should enlargen it and allow you to zoom in, giving you a sense of how I organize all these scripts and files.</p>
</blockquote>
<hr>
<p>If this ends up confusing you, you can just scroll all the way down to see an image of what the folder structure looks like.</p>
<p>Instead of constantly changing the working directory to each subfolder when I need to do something inside that subfolder for a particular project or analysis, I set the project folder as the working directory only once, and then run the following:</p>
<hr>
<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"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Very seriously consider installing the `here` package</span></span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># https://cran.r-project.org/package=here</span></span>
<span id="cb1-4"></span>
<span id="cb1-5"><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;">"here"</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This and the scripts below take</span></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># the directory used and set it as the top</span></span>
<span id="cb1-9"></span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_here</span>()</span>
<span id="cb1-11"></span>
<span id="cb1-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>()</span></code></pre></div></div>
</div>
<hr>
<p>This not only sets the working directory, but gives you far more control over how you can save your files from any place within the hierarchical folder structure. It will create a file called <code>.here</code> inside the <code>Main Project</code> folder, which will indicate that this is the top level of the hierarchy.</p>
<p>Then, I will usually have created a <code>README.Rmd</code> file in the <code>Main Project</code> folder with updates on what I’ve done and what I still need to work on, so I will remember and so my collaborators can see it too (when it has been pushed to GitHub or other <a href="https://happygitwithr.com/">version control</a> repos).</p>
<p>Next, I’ll set up a <code>Data</code> folder inside the <code>Main Project</code> folder. This is where all my data/spreadsheets/.txt files and data dictionaries will go. The original data files will stay inside this folder, while I create two other subsubfolders inside this <code>Data</code> folder called <code>Transformed</code> and <code>Models</code>. In <code>Transformed</code>, I will typically save <code>.rds</code> files that were a result of cleaning and transforming the data, including imputing missing data. I will touch more on exactly how I do that later below. A <code>Models</code> subfolder will obviously store fitted models and any validation/sensitivity analyses of those models.[@morrisChoosingSensitivityAnalyses2014]</p>
<p>Now, back to the <code>Main Project</code> folder, I’ll set up another folder within it called <code>R</code>. This will be where all of my <code>.R</code> scripts/files live. I will number them sequentially along with a title for a specific purpose, like so</p>
<hr>
<ul>
<li><p><code>main.R</code></p></li>
<li><p><code>01-functions.R</code></p></li>
<li><p><code>02-cleaning.R</code></p></li>
<li><p><code>03-inspection.R</code></p></li>
<li><p><code>04-analysis.R</code></p></li>
<li><p><code>04.5-validation.R</code></p></li>
<li><p><code>05-sensitivity.R</code></p></li>
<li><p><code>06-tables.R</code></p></li>
</ul>
<hr>
</section>
<section id="setting-up-the-functions-script" class="level2">
<h2 class="anchored" data-anchor-id="setting-up-the-functions-script">Setting up the Functions Script</h2>
<hr>
<p>All potential <code>R</code> packages and custom functions that I need will belong in <code>01-functions.R</code>. This <code>.R</code> file will only serve this purpose and nothing else. As you’ve guessed by now, the other <code>.R</code> files will be doing the same, they have very specific purposes and are organized to reflect this.</p>
<p>An example of the first script can be found below.</p>
<hr>
<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"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Necessary Packages ------------------------------------</span></span>
<span id="cb2-2"></span>
<span id="cb2-3">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;">"concurve"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mice"</span>,</span>
<span id="cb2-4">               <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;">"parallel"</span>,</span>
<span id="cb2-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;">"projpred"</span>,</span>
<span id="cb2-6">               <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;">"loo"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rstan"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"here"</span>,</span>
<span id="cb2-7">               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tryCatchLog"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"futile.logger"</span>,</span>
<span id="cb2-8">               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"patchwork"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"corrplot"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"beepr"</span>,</span>
<span id="cb2-9">               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"summarytools"</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;">"wakefield"</span>,</span>
<span id="cb2-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;">"mfp"</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;">"flextable"</span>,</span>
<span id="cb2-11">               <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;">"lme4"</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;">"miceMNAR"</span>)</span>
<span id="cb2-12"></span>
<span id="cb2-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Load all packages at once</span></span>
<span id="cb2-14"></span>
<span id="cb2-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(req_packs, library,</span>
<span id="cb2-16">       <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>
<span id="cb2-17"></span>
<span id="cb2-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Loggings messages</span></span>
<span id="cb2-19"><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;">keep.source =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb2-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">options</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tryCatchLog.write.error.dump.file"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb2-21"></span>
<span id="cb2-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set seed for random number generator</span></span>
<span id="cb2-23"></span>
<span id="cb2-24"><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-25"><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 class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># My birthday</span></span>
<span id="cb2-26"></span>
<span id="cb2-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># RStan Settings  -------------------------------------</span></span>
<span id="cb2-28"></span>
<span id="cb2-29"><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_bw</span>())</span>
<span id="cb2-30"><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;">"red"</span>)</span>
<span id="cb2-31"><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="cb2-32"><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="cb2-33"></span>
<span id="cb2-34"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">has_build_tools</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">debug =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb2-35"></span>
<span id="cb2-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Stan Settings  ---------------------------------------</span></span>
<span id="cb2-37"></span>
<span id="cb2-38">dotR <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.path</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.getenv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"HOME"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".R"</span>)</span>
<span id="cb2-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;">file.exists</span>(dotR)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dir.create</span>(dotR)</span>
<span id="cb2-40">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;">file.path</span>(dotR, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Makevars"</span>)</span>
<span id="cb2-41"><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;">file.exists</span>(M)) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.create</span>(M)</span>
<span id="cb2-42"><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;">"</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;">CXX14FLAGS=-O3 -march=native -mtune=native -fPIC"</span>,</span>
<span id="cb2-43">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CXX14=g++"</span>,</span>
<span id="cb2-44">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">file =</span> M, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">append =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
</div>
<hr>
<p>The script above loads all the necessary <code>R</code> packages each time it is called, along with the specified functions, so most of the other <code>.R</code> files will depend upon this one.</p>
<p>However, I will not be running each of these <code>.R</code> files/scripts individually, line by line, or by selecting all the lines in an <code>.R</code> file and running the script.</p>
<p>Instead, after I’ve created all these files (figuring out what I need to do carefully and writing it down and annotating it), every single <code>.R</code> file except for <code>main.R</code> will have the following script, which I will explain later below (or some iteration of this script to match the name of the file) at the beginning:</p>
<hr>
</section>
<section id="setting-up-the-error-catching-script" class="level2">
<h2 class="anchored" data-anchor-id="setting-up-the-error-catching-script">Setting up the Error Catching Script</h2>
<hr>
<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"><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;">"here"</span>)</span>
<span id="cb3-2"></span>
<span id="cb3-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_here</span>()</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01-functions.R"</span>))</span>
<span id="cb3-6"></span>
<span id="cb3-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(futile.logger)</span>
<span id="cb3-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tryCatchLog)</span>
<span id="cb3-9"></span>
<span id="cb3-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Keeps source code file name and line number tracking</span></span>
<span id="cb3-11"><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;">keep.source =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb3-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">options</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tryCatchLog.write.error.dump.file"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb3-13"></span>
<span id="cb3-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Logs messages into a file</span></span>
<span id="cb3-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flog.appender</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appender.file</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"my_app.log"</span>))</span>
<span id="cb3-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flog.threshold</span>(INFO)</span>
<span id="cb3-17"></span>
<span id="cb3-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Function that catches any messages</span></span>
<span id="cb3-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatchLog</span>(<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;">"script.R"</span>))</span></code></pre></div></div>
</div>
<hr>
<p>You’ll notice several things. First, I’m once again calling the <a href="https://cran.r-project.org/package=here"><code>here</code></a> package and telling it that I’m working within this folder (<code>R</code>), and then I’m calling the <code>01-functions.R</code> file by using the <code>source()</code> function, but also notice how the <code>source()</code> function is followed by a <code>here()</code> function/argument. This <code>here()</code> function allows you to fully control files in a specific folder from anywhere else, without having to actually be in that folder. So, suppose I was in the <code>Main Project</code> -&gt; <code>Data</code> -&gt; <code>Models</code> folder and I was saving my work there (in the <code>Models</code> folder), which is pretty far from the <code>R</code> folder, I can still, using functions like <code>source()</code>, <code>save()</code>, etc., call or manipulate files from a totally different folder by specifying the hierarchy using <code>here()</code>. This can also be done in other ways, but those are far more cumbersome, and not flexible.</p>
<p>This is how I always call the necessary packages and functions I need from every <code>.R</code> script, simply by using the <code>source()</code> function and using <code>here()</code> to direct it to the <code>01-functions.R</code> file in the <code>R</code> folder. Now let’s look at the next few lines.</p>
<hr>
<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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flog.appender</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appender.file</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"script.log"</span>))</span>
<span id="cb4-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flog.threshold</span>(INFO)</span>
<span id="cb4-3"></span>
<span id="cb4-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatchLog</span>(<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;">"script.R"</span>))</span></code></pre></div></div>
</div>
<hr>
<p>This script is designed to catch any warnings that occur inside the <code>.R</code> script and save them to a .log file in another subfolder within the <code>R</code> folder called <code>Errors</code>. So here’s an example of a full script for a mix of data generation and inspection, so that you can see it in action.</p>
<hr>
</section>
<section id="example-of-data-loading-inspection" class="level2">
<h2 class="anchored" data-anchor-id="example-of-data-loading-inspection">Example of Data Loading &amp; Inspection</h2>
<hr>
<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;">library</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"here"</span>)</span>
<span id="cb5-2"></span>
<span id="cb5-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_here</span>()</span>
<span id="cb5-4"></span>
<span id="cb5-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01-functions.R"</span>)) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Loads all R functions</span></span>
<span id="cb5-6"></span>
<span id="cb5-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># First we need some data</span></span>
<span id="cb5-8"></span>
<span id="cb5-9"><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-10"><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 class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># My birthday</span></span>
<span id="cb5-11"></span>
<span id="cb5-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Suppose you wanted to simulate a clinical trial</span></span>
<span id="cb5-13"><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;">"simstudy"</span>)</span>
<span id="cb5-14"></span>
<span id="cb5-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simulating a Clinical Trial --------------------------</span></span>
<span id="cb5-16"></span>
<span id="cb5-17">def <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">defData</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">varname =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"male"</span>, <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;">"binary"</span>,</span>
<span id="cb5-18">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</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;">id=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cid"</span>)</span>
<span id="cb5-19">def <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">defData</span>(def, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">varname =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"over65"</span>,</span>
<span id="cb5-20">               <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;">"binary"</span>,</span>
<span id="cb5-21">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-1.7 + .8 * male"</span>,</span>
<span id="cb5-22">               <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="cb5-23">def <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">defData</span>(def,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">varname =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"baseDBP"</span>,</span>
<span id="cb5-24">               <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;">"normal"</span>,</span>
<span id="cb5-25">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">70</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variance =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>)</span>
<span id="cb5-26">def <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">defData</span>(def, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">varname =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"age"</span>,</span>
<span id="cb5-27">               <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;">"normal"</span>,</span>
<span id="cb5-28">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span id="cb5-29">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variance =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb5-30">def <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">defData</span>(def, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">varname =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"visits"</span>,</span>
<span id="cb5-31">               <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;">"poisson"</span>,</span>
<span id="cb5-32">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1.5 - 0.2 * age + 0.5 * male"</span>,</span>
<span id="cb5-33">    <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;">"log"</span>)</span>
<span id="cb5-34">def <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">defData</span>(def, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">varname =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"weight"</span>,</span>
<span id="cb5-35">               <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;">"normal"</span>,</span>
<span id="cb5-36">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variance =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb5-37">dtstudy <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">genData</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>, def)</span>
<span id="cb5-38">study <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">trtAssign</span>(dtstudy, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nTrt =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb5-39">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">balanced =</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;">grpName =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rxGrp"</span>)</span>
<span id="cb5-40">study <span class="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>(study)</span>
<span id="cb5-41">study<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>iq <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> iq <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> wakefield<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">iq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>)</span>
<span id="cb5-42">study<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>height <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> height <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> wakefield<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">height</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>)</span>
<span id="cb5-43">study<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>income <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> income <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> wakefield<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">income</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>,</span>
<span id="cb5-44">                              <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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Income"</span>)</span>
<span id="cb5-45">study<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SAT_score <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> wakefield<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sat</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;">mean =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1500</span>,</span>
<span id="cb5-46">                 <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;">100</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> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2400</span>,</span>
<span id="cb5-47">                 <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;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SAT"</span>)</span>
<span id="cb5-48">study<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>visits <span class="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>(study<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>visits)</span>
<span id="cb5-49"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add noisy predictors</span></span>
<span id="cb5-50">study[, <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 class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</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;">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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <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>
<span id="cb5-51">                         (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</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="cb5-52">                                <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;">1</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="cb5-53">varname <span class="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;">"x%d"</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 class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>))</span>
<span id="cb5-54"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(study)[<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 class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> varname</span>
<span id="cb5-55"></span>
<span id="cb5-56">study1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">trtAssign</span>(dtstudy, <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;">balanced =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb5-57">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">strata =</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;">"male"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"over65"</span>),</span>
<span id="cb5-58">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">grpName =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rxGrp"</span>)</span>
<span id="cb5-59"></span>
<span id="cb5-60">study1</span>
<span id="cb5-61"></span>
<span id="cb5-62"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inspecting Data  -------------------------------------</span></span>
<span id="cb5-63"></span>
<span id="cb5-64">summarytools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">view</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dfSummary</span>(study))</span>
<span id="cb5-65"></span>
<span id="cb5-66">study<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>over65 <span class="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>(study<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>over65)</span>
<span id="cb5-67">study<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>male <span class="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>(study<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>male)</span>
<span id="cb5-68">study<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>rxGrp <span class="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>(study<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>rxGrp)</span>
<span id="cb5-69"></span>
<span id="cb5-70">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>(baseDBP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> .)</span>
<span id="cb5-71"></span>
<span id="cb5-72"><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, study))</span>
<span id="cb5-73"><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>
<span id="cb5-74"></span>
<span id="cb5-75">x_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;">model.matrix</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> ., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study)[, <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="cb5-76"></span>
<span id="cb5-77"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Initial Data Analysis  ------------------------------</span></span>
<span id="cb5-78"></span>
<span id="cb5-79">(cormatrix <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cor</span>(x_1)))</span>
<span id="cb5-80"></span>
<span id="cb5-81">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;">colorRampPalette</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;">"#BB4444"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#EE9988"</span>,</span>
<span id="cb5-82">                          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#FFFFFF"</span>,</span>
<span id="cb5-83">                          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#77AADD"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#4477AA"</span>))</span>
<span id="cb5-84"></span>
<span id="cb5-85"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">corrplot</span>(cormatrix, <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;">"color"</span>,</span>
<span id="cb5-86">         <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;">col</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>),</span>
<span id="cb5-87">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tl.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;">tl.cex =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.40</span>,</span>
<span id="cb5-88">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">addCoef.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;">number.cex =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>)</span>
<span id="cb5-89"></span>
<span id="cb5-90"></span>
<span id="cb5-91">clus1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varclus</span>(x_1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">similarity =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"h"</span>)</span>
<span id="cb5-92">clus2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varclus</span>(x_1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">similarity =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"s"</span>)</span>
<span id="cb5-93">clus3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varclus</span>(x_1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">similarity =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span>)</span>
<span id="cb5-94"></span>
<span id="cb5-95"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(clus1, <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;">"Hoeffing's D statistic"</span>,</span>
<span id="cb5-96">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</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;">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;">cex =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>)</span>
<span id="cb5-97"><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;">"Hierarchical Cluster Analysis"</span>)</span>
<span id="cb5-98"></span>
<span id="cb5-99"></span>
<span id="cb5-100"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(clus2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</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;">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;">cex =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>)</span>
<span id="cb5-101"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(clus3, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</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;">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;">cex =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>)</span>
<span id="cb5-102"></span>
<span id="cb5-103">Pre <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(study)</span>
<span id="cb5-104">(fmla <span class="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>(<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;">"~"</span>,</span>
<span id="cb5-105">                          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(Pre,</span>
<span id="cb5-106">                                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"+"</span>))))</span>
<span id="cb5-107"></span>
<span id="cb5-108"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Redundancy analysis</span></span>
<span id="cb5-109"></span>
<span id="cb5-110">redun <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">redun</span>(fmla,</span>
<span id="cb5-111">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study,</span>
<span id="cb5-112">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r2 =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.90</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;">"ordinary"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">allcat =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb5-113">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tlinear =</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;">iterms =</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;">pr =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
</div>
<hr>
<p>The above script simulated some fake data for a hypothetical clinical trial (usually we use this first script to load data from a .csv or .txt file) and then we used several functions to inspect the dataframe for the structure and distributions of the variables and missing data, etc. We also attempted to properly code the variables. Now, in order to capture any possible errors, we will have to run this entire script from another <code>R</code> script instead of running it line by line or selecting all the code and running it.</p>
<p>We will do this from a Main source script, which will allow us to use the <code>tryCatchLog()</code> function.</p>
<hr>
</section>
<section id="example-of-the-main-source-script" class="level2">
<h2 class="anchored" data-anchor-id="example-of-the-main-source-script">Example of the Main Source Script</h2>
<hr>
<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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"here"</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;">"tryCatchLog"</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;">"futile.logger"</span>)</span>
<span id="cb6-4"></span>
<span id="cb6-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_here</span>() <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Load and set here</span></span>
<span id="cb6-6"></span>
<span id="cb6-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>() <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Call here</span></span>
<span id="cb6-8"></span>
<span id="cb6-9"><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;">keep.source =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb6-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">options</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tryCatchLog.write.error.dump.file"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb6-11"></span>
<span id="cb6-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Script loads all necessary functions</span></span>
<span id="cb6-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flog.appender</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appender.file</span>(</span>
<span id="cb6-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Errors"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01-functions.log"</span>)))</span>
<span id="cb6-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatchLog</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01-functions.R"</span>)))</span>
<span id="cb6-16"></span>
<span id="cb6-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Line script to clean the data</span></span>
<span id="cb6-18"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flog.appender</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appender.file</span>(</span>
<span id="cb6-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Errors"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"02-cleaning.log"</span>)))</span>
<span id="cb6-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatchLog</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"02-cleaning.R"</span>)))</span>
<span id="cb6-21"></span>
<span id="cb6-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Line script below to inspect the data</span></span>
<span id="cb6-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flog.appender</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appender.file</span>(</span>
<span id="cb6-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Errors"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"03-inspection.log"</span>)))</span>
<span id="cb6-25"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatchLog</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"03-inspection.R"</span>)))</span>
<span id="cb6-26"></span>
<span id="cb6-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Load saved objects from cleanings</span></span>
<span id="cb6-28"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flog.appender</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appender.file</span>(</span>
<span id="cb6-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Errors"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"03.5-load_data.log"</span>)))</span>
<span id="cb6-30"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatchLog</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"03.5-load_data.R"</span>)))</span>
<span id="cb6-31"></span>
<span id="cb6-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Main analysis script</span></span>
<span id="cb6-33"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flog.appender</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appender.file</span>(</span>
<span id="cb6-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Errors"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"04-analysis.log"</span>)))</span>
<span id="cb6-35"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatchLog</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"04-analysis.R"</span>)))</span>
<span id="cb6-36"></span>
<span id="cb6-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Below is the validation of main analysis results</span></span>
<span id="cb6-38"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flog.appender</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appender.file</span>(</span>
<span id="cb6-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Errors"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"04.5-validation.log"</span>)))</span>
<span id="cb6-40"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatchLog</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"04.5-validation.R"</span>)))</span>
<span id="cb6-41"></span>
<span id="cb6-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Test the sensitivity of the results by</span></span>
<span id="cb6-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># varying assumptions/multiple parameters</span></span>
<span id="cb6-44"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flog.appender</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appender.file</span>(</span>
<span id="cb6-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Errors"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"05-sensitivity.log"</span>)))</span>
<span id="cb6-46"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatchLog</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"05-sensitivity.R"</span>)))</span>
<span id="cb6-47"></span>
<span id="cb6-48"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate tables and figures of all your results</span></span>
<span id="cb6-49"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flog.appender</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appender.file</span>(</span>
<span id="cb6-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Errors"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"06-tables.log"</span>)))</span>
<span id="cb6-51"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatchLog</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"06-tables.R"</span>)))</span>
<span id="cb6-52"></span>
<span id="cb6-53"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Export these into actual files that can be</span></span>
<span id="cb6-54"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># inserted into papers, reports, etc.</span></span>
<span id="cb6-55"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flog.appender</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appender.file</span>(</span>
<span id="cb6-56">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Errors"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"07-export.log"</span>)))</span>
<span id="cb6-57"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatchLog</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"07-export.R"</span>)))</span></code></pre></div></div>
</div>
<hr>
<p>If anything went wrong during the simulations and their inspections in the first script from above, it would have been captured by the error-catching scripts that we have set up, which would be placed within a .log file in the <code>Errors</code> folder, which is inside the <code>R</code> folder.</p>
<hr>
</section>
<section id="setting-the-seed" class="level2">
<h2 class="anchored" data-anchor-id="setting-the-seed">Setting the Seed</h2>
<hr>
<blockquote class="blockquote">
<p>Also, note that we have set the seed using a specific random number generator algorithm. This is not that important, however, it is important to correctly set the seed for reproducing any random numbers generated. This requires even more careful thought when running a simulation study, in which the states of the simulation need to be saved for a particular repetition, and so that streams do not overlap.[@morrisUsingSimulationStudies2019]</p>
</blockquote>
<hr>
<p>I will admit that the error script is not <em>perfect</em> at capturing warnings, but for most things, if something wrong occurs when a script is run, the function <code>tryCatchLog()</code> and its .log file usually catches the warning, so I would know that something went wrong and what specifically.</p>
<p>However, some may be skeptical of this approach and ask why I need to catch these errors and save them if I ran the scripts? Why not just scroll up and look at the console to see the errors or warnings?</p>
<p>Many reasons:</p>
<hr>
<ul>
<li>Suppose the analyses take a very long time, and are computationally intensive, and <code>R</code>/<a href="https://rstudio.com/"><code>RStudio</code></a> crashes, you may not be able to figure out what went wrong.</li>
<li>Suppose the analysis completed but because there was so much occurring in the console (for example, sampling from a posterior) that you missed the warnings/errors and got results that you don’t know have issues.</li>
</ul>
<hr>
<p>Thus, having this system set up to catch errors in every script also helps us automate the entire workflow once we’ve carefully set it up. After each <code>.R</code> script has one of these message-catching scripts, we can run our entire analysis from start to finish from <code>main.R</code> with one command. This not only makes your workspace organized, but also makes it easier for others to reproduce your work if you share your files and folders via a repository.</p>
<hr>
<p>So, now the <code>Error</code> folder will contain .txt files with any warning messages or errors.</p>
<p>Typically, when I’m setting up a new project, I will also add a few other folders such as an <code>Outputs</code> folder, where I will save tables and graphs, and a <code>Report</code> folder, where I might be working on a manuscript.</p>
<p>Now that I’ve mentioned my hierarchy and how I catch errors, I can mention some other things that I believe are absolutely heinous practices.</p>
<p>Many people often will run an entire analysis and have several objects/vectors stored in their Global Environment in <code>R</code> and <code>RStudio</code>. Suppose they’re taking a break, finished with the analysis, turning off the computer, or stepping away for whatever reason, what they’ll typically do is click the save button on the top right pane and “Save the workspace image”. Indeed, if they don’t do that themselves, the IDE <code>RStudio</code> will explicitly ask them if they wish to save their workspace image.</p>
<p>This is a horrific practice and you should never do this because it can lead to several problems such as:</p>
<ul>
<li><p>having several saved objects and packages conflict with one another once they’re all loaded together at once</p></li>
<li><p>having giant workspace images, that will probably cause <code>R</code>, and especially <code>RStudio</code> to constantly crash</p></li>
<li><p>not allowing you to load very specific objects that you need at a time while leaving everything else</p></li>
</ul>
<p>I would say that it is a good idea to never save the workspace image, ever. It is also quite easy to turn off. Simply go the <code>RStudio</code> menu and click <em>Preferences</em>, and in the <em>General</em> section, you will see the following options:</p>
<hr>
<p><img data-enlargeable="" width="500" style="cursor: zoom-in" src="https://res.cloudinary.com/less-likely/image/upload/v1604649526/Site/RStudio_Default_Save_Options.png"></p>
<hr>
<p>It is essential to uncheck everything under <em>R Sessions</em>, <em>Workspace</em>, and <em>History</em>, so that you do not set your self up for a future disaster.</p>
<p>Instead of using these convenient but highly problematic options, always use the <code>saveRDS()</code> base <code>R</code> function, where the first argument is the object in your environment that you want to save, and the second argument is the path where you want to save it, which of course should be using the <code>here()</code> function.</p>
<p>Now suppose I decided to use multiple imputation because I had a dataset with many missing values, and suppose I had a grasp of the missing data mechanism, and so I used something like the not-at-random fully conditional specification approach (<strong>NARFCS</strong>)[@tompsettUseNotatrandomFully2018] to attempt to handle data that I believe to be missing not at random (<strong>MNAR</strong>), and I wanted to save the imputed dataset, and only load the imputed dataset next time. This is how I would do it (in the vaguest way possible). First, I’ll start with the dataset that we generated above and generate missing values via different missing data mechanisms using the <code>ampute()</code> function from the <code>mice</code> package.[@buurenMiceMultivariateImputation2011]</p>
<hr>
<blockquote class="blockquote">
<p><strong>Important</strong>: This is all assuming that one has carefully constructed an imputation model, and that multiple imputation is the most appropriate solution. As many others have pointed out, simply running a script like <code>mice(data)</code> in <code>R</code> without careful thought to the imputation model, is a very, very bad idea. Missing data is an extremely complex topic and I recommend everyone carefully read the works[@buurenFlexibleImputationMissing2018] of missing data researchers such as:</p>
</blockquote>
<ul>
<li><p><a href="https://stefvanbuuren.name/fimd/">Stef van Buuren</a></p>
<blockquote class="blockquote">

</blockquote></li>
<li><p><a href="https://twitter.com/tmorris_mrc">Tim Morris</a></p>
<blockquote class="blockquote">

</blockquote></li>
<li><p><a href="https://www.ctu.mrc.ac.uk/about-us/senior-staff/ian-white/">Ian White</a></p>
<blockquote class="blockquote">

</blockquote></li>
<li><p><a href="https://scholar.google.com/citations?user=5q4fhUoAAAAJ&amp;hl=en">Donald Rubin</a></p>
<blockquote class="blockquote">

</blockquote></li>
<li><p><a href="https://thestatsgeek.com/">Jonathan Bartlett</a></p>
<blockquote class="blockquote">

</blockquote></li>
<li><p><a href="https://www.paulgstf.com/">Paul Gustafson</a></p>
<blockquote class="blockquote">

</blockquote></li>
</ul>
<hr>
</section>
<section id="example-of-a-multiple-imputation-script" class="level2">
<h2 class="anchored" data-anchor-id="example-of-a-multiple-imputation-script">Example of a Multiple Imputation Script</h2>
<hr>
<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;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01-functions.R"</span>))</span>
<span id="cb7-2"></span>
<span id="cb7-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;">"beepr"</span>)</span>
<span id="cb7-4"></span>
<span id="cb7-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Package that uses multiple imputation</span></span>
<span id="cb7-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># by chained equations</span></span>
<span id="cb7-7"></span>
<span id="cb7-8"><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;">"mice"</span>)</span>
<span id="cb7-9"></span>
<span id="cb7-10"></span>
<span id="cb7-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate Missing Data  --------------------------------</span></span>
<span id="cb7-12"></span>
<span id="cb7-13">study_mnar <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ampute</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study[, <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>
<span id="cb7-14">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prop =</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;">mech =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MNAR"</span>)</span>
<span id="cb7-15">mnar_patterns <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> study_mnar<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>patterns</span>
<span id="cb7-16">mnar_weight <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> study_mnar<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>weight</span>
<span id="cb7-17">study_mnar_rerun <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ampute</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study[, <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>
<span id="cb7-18">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prop =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb7-19">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mech =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MNAR"</span>,</span>
<span id="cb7-20">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">patterns =</span> mnar_patterns,</span>
<span id="cb7-21">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> mnar_weight)</span>
<span id="cb7-22">study_mar <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ampute</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study[, <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;">4</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prop =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb7-23">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mech =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MAR"</span>)</span>
<span id="cb7-24">mar_patterns <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> study_mar<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>patterns</span>
<span id="cb7-25">mar_weight <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> study_mar<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>weight</span>
<span id="cb7-26">study_mar_rerun <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ampute</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study[, <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;">4</span>],</span>
<span id="cb7-27">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prop =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb7-28">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mech =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"MAR"</span>,</span>
<span id="cb7-29">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">patterns =</span> mar_patterns,</span>
<span id="cb7-30">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> mar_weight)</span>
<span id="cb7-31"></span>
<span id="cb7-32">study_mar_rerun[[<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>over65 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>()</span>
<span id="cb7-34">study_mar_rerun[[<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>male <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>()</span>
<span id="cb7-36">study_mar_rerun[[<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>rxGrp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>()</span>
<span id="cb7-38"></span>
<span id="cb7-39">df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> study_mnar_rerun<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>amp</span>
<span id="cb7-40">df2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> study_mar_rerun<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>amp</span>
<span id="cb7-41"></span>
<span id="cb7-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inspect Data</span></span>
<span id="cb7-43"></span>
<span id="cb7-44"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str</span>(df) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inspect data frame</span></span>
<span id="cb7-45"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(df) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># High level summary of dataframe</span></span>
<span id="cb7-46"><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>(df)) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Look at missing values etc.</span></span>
<span id="cb7-47"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colSums</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(df))</span>
<span id="cb7-48">summarytools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">view</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dfSummary</span>(df))</span>
<span id="cb7-49"></span>
<span id="cb7-50"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str</span>(df2) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inspect data frame</span></span>
<span id="cb7-51"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(df2) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># High level summary of dataframe</span></span>
<span id="cb7-52"><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>(df2)) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Look at missing values etc.</span></span>
<span id="cb7-53"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colSums</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(df2))</span>
<span id="cb7-54">summarytools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">view</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dfSummary</span>(df2))</span>
<span id="cb7-55"></span>
<span id="cb7-56"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Prepare Data for Imputation -------------------------</span></span>
<span id="cb7-57"></span>
<span id="cb7-58">temp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> df</span>
<span id="cb7-59">temp2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> df2</span>
<span id="cb7-60"></span>
<span id="cb7-61"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">missing_plot</span>(temp)</span>
<span id="cb7-62"></span>
<span id="cb7-63"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">missing_plot</span>(temp2)</span>
<span id="cb7-64"></span>
<span id="cb7-65"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set-up predictor matrix</span></span>
<span id="cb7-66"></span>
<span id="cb7-67">predMatrix <span class="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>(temp)</span>
<span id="cb7-68">predMatrix2 <span class="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>(temp2)</span>
<span id="cb7-69"></span>
<span id="cb7-70"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set-up predictor matrix for unidentifiable part:</span></span>
<span id="cb7-71">predSens <span class="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 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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>), <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;">6</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;">6</span>)</span>
<span id="cb7-72"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(predSens) <span class="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;">":"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(temp), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span>
<span id="cb7-73"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rownames</span>(predSens) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(temp)</span>
<span id="cb7-74"></span>
<span id="cb7-75"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set-up list with sensitivity parameter values</span></span>
<span id="cb7-76"></span>
<span id="cb7-77">pSens <span class="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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ncol</span>(temp))</span>
<span id="cb7-78"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(pSens) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(temp)</span>
<span id="cb7-79">pSens[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rxGrp"</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;">list</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="cb7-80">pSens[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"baseDBP"</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;">list</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="cb7-81">pSens[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"male"</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;">list</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="cb7-82">pSens[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"over65"</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;">list</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="cb7-83"></span>
<span id="cb7-84"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># MICE RI Imputation  ----------------------------------</span></span>
<span id="cb7-85"></span>
<span id="cb7-86">z1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">parlmice</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> temp, <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>
<span id="cb7-87">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">predictorMatrix =</span> predMatrix,</span>
<span id="cb7-88">              <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;">8</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>
<span id="cb7-89">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cluster.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;">n.core =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb7-90">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n.imp.core =</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;">cl.type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FORK"</span>,</span>
<span id="cb7-91">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ridge =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-04</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="cb7-92">              <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;">TRUE</span>)</span>
<span id="cb7-93"></span>
<span id="cb7-94">z2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">parlmice</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> temp2, <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="cb7-95">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">predictorMatrix =</span> predMatrix2,</span>
<span id="cb7-96">              <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;">8</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>
<span id="cb7-97">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cluster.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;">n.core =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb7-98">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ridge =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-04</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="cb7-99">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n.imp.core =</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;">cl.type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FORK"</span>)</span>
<span id="cb7-100"></span>
<span id="cb7-101">zfinal <span class="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>(z1, z2)</span>
<span id="cb7-102"></span>
<span id="cb7-103"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Heckman Imputation  ----------------------------------</span></span>
<span id="cb7-104"></span>
<span id="cb7-105">study<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>baseDBP <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> temp<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>baseDBP</span>
<span id="cb7-106">JointModelEq<span class="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_JointModelEq</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>temp,</span>
<span id="cb7-107">                                    <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;">"baseDBP"</span>)</span>
<span id="cb7-108">JointModelEq[,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"baseDBP_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>
<span id="cb7-109">JointModelEq[,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"baseDBP_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;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb7-110"></span>
<span id="cb7-111">arg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">MNARargument</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> temp, <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;">"baseDBP"</span>,</span>
<span id="cb7-112">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">JointModelEq =</span> JointModelEq)</span>
<span id="cb7-113"></span>
<span id="cb7-114">arg<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;">"ri"</span></span>
<span id="cb7-115">arg<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;">"visits"</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;">"ri"</span></span>
<span id="cb7-116">arg<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;">"weight"</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;">"ri"</span></span>
<span id="cb7-117">arg<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;">"iq"</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;">"ri"</span></span>
<span id="cb7-118">arg<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;">"height"</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;">"ri"</span></span>
<span id="cb7-119"></span>
<span id="cb7-120">imp1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">parlmice</span>(<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="cb7-121">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> arg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>method,</span>
<span id="cb7-122">                  <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="cb7-123">                  <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="cb7-124">                  <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="cb7-125">                  <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;">m =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>,</span>
<span id="cb7-126">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cluster.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;">n.core =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb7-127">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n.imp.core =</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;">cl.type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FORK"</span>)</span>
<span id="cb7-128"></span>
<span id="cb7-129">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>(zfinal, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(baseDBP <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> visits <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> weight <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> iq <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> height <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> rxGrp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> male <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> over65))</span>
<span id="cb7-130">result1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pool</span>(analysis1)</span>
<span id="cb7-131"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(result1)</span>
<span id="cb7-132"></span>
<span id="cb7-133">z2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">parlmice</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> temp2, <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="cb7-134">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">predictorMatrix =</span> predMatrix2,</span>
<span id="cb7-135">              <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;">8</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>
<span id="cb7-136">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cluster.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;">n.core =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb7-137">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n.imp.core =</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;">cl.type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FORK"</span>)</span>
<span id="cb7-138"></span>
<span id="cb7-139">heckman <span class="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>(imp1, z2)</span>
<span id="cb7-140"></span>
<span id="cb7-141"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">beep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># I will touch on this function below.</span></span>
<span id="cb7-142"></span>
<span id="cb7-143"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">saveRDS</span>(zfinal, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main Project"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data"</span>,</span>
<span id="cb7-144">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zfinal.rds"</span>))</span></code></pre></div></div>
</div>
<hr>
<p>Here is the workflow truly showing its advantages, <code>saveRDS()</code> is saving a very specific object (<code>zfinal</code>, the imputed dataset) into the <code>Data</code> folder by using the hierarchical structure of the folder which can easily be navigated using <code>here()</code>. Notice how to save something and use <code>here()</code> to specify the location, the first argument is <code>Main Project</code>, followed by <code>Data</code>, and then comes the object name (<code>zfinal.rds</code>).</p>
<p>Now I have saved my imputed dataset as an object called <code>zfinal.rds</code> and it is saved in the <code>Data</code> folder even though I am hypothetically working from the <code>R</code> folder.</p>
<p>Also notice that I use the <code>beep()</code> function from the <a href="https://cran.r-project.org/package=beepr">beepr</a> <code>R</code> package, which can be quite handy in letting you know if a particular script or analysis is done.</p>
<p>Next time, if I cleared my entire global environment and wanted to only load the imputed dataset, I would simply have to just click on the <code>zfinal.rds</code> file in the <code>Data</code> folder and it would load into the environment or I could use the following command,</p>
<hr>
</section>
<section id="saving-and-reading-data-carefully" class="level2">
<h2 class="anchored" data-anchor-id="saving-and-reading-data-carefully">Saving and Reading Data Carefully</h2>
<hr>
<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"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># The function readRDS() and saveRDS()</span></span>
<span id="cb8-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># are possibly the most important base R functions</span></span>
<span id="cb8-3"></span>
<span id="cb8-4">zfinal <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readRDS</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zfinal.rds"</span>,</span>
<span id="cb8-5">             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main Project"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data"</span>,</span>
<span id="cb8-6">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zfinal.rds"</span>))</span></code></pre></div></div>
</div>
<hr>
<p>This gives us full control over the environment, and it’s also why I encourage people to turn off the automatic prompt to save the workspace that <a href="https://rstudio.com/"><code>RStudio</code></a> gives you by default (I am certain even Hadley Wickham has said the same on multiple occasions).</p>
<p>So if I now wanted to include the imputed dataset into one of my <code>.R</code> scripts that I am trying to automate with one command, whether for reproducibility, or speed, etc., I could do it with absolute control.</p>
<p>This is also how I save my models and how I validate them, which is especially handy because running those can also take an excruciatingly long time.</p>
<p>Here’s an example of a script that would be in the <code>04-analysis.R</code> script, I’m leaving out the warning-catching script now to avoid making this too long. I don’t need to load the <a href="https://cran.r-project.org/package=brms"><code>brms</code></a> package because I’m already calling it from the first <code>.R</code> script, <code>01-functions.R</code> (but I’m just showing it for now to avoid confusion), and then I am saving it in the <code>Models</code> folder which is found in the <code>Data</code> folder. And again, the <code>beep()</code> function would let me know when the script is over, and scripts like this can often take very long, due to the computational intensity.</p>
<p>The script below is an analysis script whose results we plan on saving once completed. Due to the arguments I have set (iterations, warmups, chains, and using an imputed dataset), it can often take a long time before it is finished, and if I did happen to do other tasks while I was waiting on that, the output would automatically save to the <code>Models</code> folder via <code>saveRDS()</code>, and I would also receive a notification via the <code>beep()</code> function, preventing me from wasting any time.</p>
<hr>
</section>
<section id="example-modeling-script" class="level2">
<h2 class="anchored" data-anchor-id="example-modeling-script">Example Modeling Script</h2>
<hr>
<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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Calling all packages, please report for duty</span></span>
<span id="cb9-2"></span>
<span id="cb9-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01-functions.R"</span>))</span>
<span id="cb9-4"></span>
<span id="cb9-5"><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;">"brms"</span>)</span>
<span id="cb9-6"></span>
<span id="cb9-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This is a script I used previously</span></span>
<span id="cb9-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># where I used Bayes for regularization</span></span>
<span id="cb9-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Although these are all generic options</span></span>
<span id="cb9-10"></span>
<span id="cb9-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Prior Information  --------------------------------</span></span>
<span id="cb9-12"></span>
<span id="cb9-13">sample_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;">complete</span>(zfinal, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb9-14"></span>
<span id="cb9-15">n_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;">nrow</span>(sample_z) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># of observations</span></span>
<span id="cb9-16"></span>
<span id="cb9-17">k_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;">ncol</span>(sample_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;">1</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># of predictors</span></span>
<span id="cb9-18"></span>
<span id="cb9-19">p0_1 <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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Prior for the number of relevant variables</span></span>
<span id="cb9-20"></span>
<span id="cb9-21">tau0_1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> p0_1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (k_1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> p0_1) <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;">sqrt</span>(n_1) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># tau scale</span></span>
<span id="cb9-22"></span>
<span id="cb9-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Regularized horseshoe prior</span></span>
<span id="cb9-24">hs_prior <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_prior</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"horseshoe(scale_global = tau0_1,</span></span>
<span id="cb9-25"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                      scale_slab = 1)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">class =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"b"</span>)</span>
<span id="cb9-26"></span>
<span id="cb9-27"><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;">"future"</span>)</span>
<span id="cb9-28"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plan</span>(multiprocess)</span>
<span id="cb9-29"></span>
<span id="cb9-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Regularized Bayesian quantile</span></span>
<span id="cb9-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># regression using regularized horseshoe prior</span></span>
<span id="cb9-32">brms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">brm_multiple</span>(</span>
<span id="cb9-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bf</span>(baseDBP <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> visits <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> weight <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> iq <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> height <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> rxGrp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> male <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> over65,</span>
<span id="cb9-34">     <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="cb9-35">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> zfinal, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prior =</span> hs_prior,</span>
<span id="cb9-36">     <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;">sample_prior =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb9-37">     <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;">future =</span> F,</span>
<span id="cb9-38">     <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;">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;">chains =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb9-39">     <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;">thin =</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;">combine =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb9-40">     <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>
<span id="cb9-41">                    <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 class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-&gt;</span> pen_model_1</span>
<span id="cb9-42"></span>
<span id="cb9-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Principled way of saving results</span></span>
<span id="cb9-44"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">saveRDS</span>(pen_model_1,</span>
<span id="cb9-45">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main Project"</span>, <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;">"Models"</span>,</span>
<span id="cb9-46">             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pen_model_1.rds"</span>))</span>
<span id="cb9-47"></span>
<span id="cb9-48"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">beep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
</div>
<hr>
<p>So I’ve saved the full contents of the fitted model (<code>pen_model_1</code>), which are usually several gigabytes large in size, within the <code>Models</code> folder. Once again, notice how the <code>here()</code> function allows you to work from a subfolder like <code>R</code>, which is inside the <code>Main Project</code> folder, and allows you to specify the hierarchy, and where you are within it, and save to whichever folder you wish, in this case <code>Models</code>, which is inside of <code>Data</code>. Now, I will typically conduct model checks and make sure it is performing well, and not misspecified,</p>
<hr>
<div class="cell">
<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;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01-functions.R"</span>))</span>
<span id="cb10-2"></span>
<span id="cb10-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inspect RHat values ---------------------------</span></span>
<span id="cb10-4"></span>
<span id="cb10-5">rhats_1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pen_model_1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>rhats</span>
<span id="cb10-6"></span>
<span id="cb10-7">rhats_1_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (rhats_1 <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;">1.1</span>)</span>
<span id="cb10-8">((<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;">table</span>(rhats_1_df)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span></span>
<span id="cb10-9">    (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(rhats_1_df) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ncol</span>(rhats_1_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;">100</span>))</span>
<span id="cb10-10"></span>
<span id="cb10-11">rhats_1_vec <span class="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;">unlist</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb10-12">  rhats_1[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ncol</span>(rhats_1)])))</span>
<span id="cb10-13"></span>
<span id="cb10-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pdf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outputs"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Figures"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Diagnostics"</span>,</span>
<span id="cb10-15">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OUTCOME_COMP_rhat.pdf"</span>))</span>
<span id="cb10-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mcmc_rhat_hist</span>(rhats_1_vec) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Model 1 Chain Convergence"</span>)</span>
<span id="cb10-18"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dev.off</span>()</span>
<span id="cb10-19"></span>
<span id="cb10-20"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inspect Effective Sample Size ----------------------</span></span>
<span id="cb10-21"></span>
<span id="cb10-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mcmc_neff_hist</span>(rhats_1_vec) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Effective Sample Size"</span>)</span>
<span id="cb10-24"></span>
<span id="cb10-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inspect Divergences ---------------------------</span></span>
<span id="cb10-26"></span>
<span id="cb10-27"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pdf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outputs"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Figures"</span>,</span>
<span id="cb10-28">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Diagnostics"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OUTCOME_1.pdf"</span>))</span>
<span id="cb10-29"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mcmc_nuts_divergence</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nuts_params</span>(pen_model_1),</span>
<span id="cb10-30">                     <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log_posterior</span>(pen_model_1))</span>
<span id="cb10-31"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dev.off</span>()</span>
<span id="cb10-32"></span>
<span id="cb10-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Examine Residual Plots ----------------------------</span></span>
<span id="cb10-34"></span>
<span id="cb10-35">df_resid_stan_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;">data.frame</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fitted</span>(pen_model_1)[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>],</span>
<span id="cb10-36">                              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">residuals</span>(pen_model_1)[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb10-37"></span>
<span id="cb10-38"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pdf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outputs"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Figures"</span>,</span>
<span id="cb10-39">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Diagnostics"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OUTCOME_1.pdf"</span>))</span>
<span id="cb10-40"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(df_resid_stan_1,</span>
<span id="cb10-41">       <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;">sample =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">residuals</span>(pen_model_1)[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_qq</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_qq_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Model 1 Residuals"</span>)</span>
<span id="cb10-45"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dev.off</span>()</span>
<span id="cb10-46"></span>
<span id="cb10-47">(sum1 <span class="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_summary</span>(pen_model_1))[<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;">8</span>, ])</span>
<span id="cb10-48"></span>
<span id="cb10-49"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mcmc_intervals</span>(pen_model_1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">point_est =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"median"</span>,</span>
<span id="cb10-50">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prob =</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;">prob_outer =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb10-51">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pars =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">parnames</span>(pen_model_1)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-52">  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;">scale_y_discrete</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-53">  <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=</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="cb10-54">        <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;">13</span>),</span>
<span id="cb10-55">        <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;">15</span>,</span>
<span id="cb10-56">                                  <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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-57">  <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>
<span id="cb10-58">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</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.05</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</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;">ymin =</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;">ymax =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>,</span>
<span id="cb10-59">    <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;">"darkred"</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.075</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-60">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"segment"</span>,</span>
<span id="cb10-61">    <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="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;">xend =</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.05</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;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yend =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>,</span>
<span id="cb10-62">    <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;">"#990000"</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>
<span id="cb10-63">    <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;">75</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;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-64">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"segment"</span>,</span>
<span id="cb10-65">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xend =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</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;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yend =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>,</span>
<span id="cb10-66">    <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;">"#990000"</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>
<span id="cb10-67">    <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;">75</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;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-68">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Change in Outcome 1"</span>)</span>
<span id="cb10-69"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dev.off</span>()</span>
<span id="cb10-70"></span>
<span id="cb10-71"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pdf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outputs"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Figures"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OUTCOME_1.pdf"</span>))</span>
<span id="cb10-72"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mcmc_hist</span>(pen_model_1)</span>
<span id="cb10-73"></span>
<span id="cb10-74"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Posterior Predictive Checks</span></span>
<span id="cb10-75"></span>
<span id="cb10-76"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pdf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outputs"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Figures"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Diagnostics"</span>,</span>
<span id="cb10-77">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OUTCOME_1check.pdf"</span>))</span>
<span id="cb10-78"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pp_check</span>(pen_model_1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nsamples =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">250</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-79">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Posterior Predictive Check: Model 1"</span>)</span>
<span id="cb10-80"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dev.off</span>()</span>
<span id="cb10-81"></span>
<span id="cb10-82"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Shows dens_overlay plot by default</span></span>
<span id="cb10-83"></span>
<span id="cb10-84">bayes_rsq1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bayes_R2</span>(pen_model_1)</span>
<span id="cb10-85"></span>
<span id="cb10-86">bayes_rsq1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(bayes_rsq1))</span>
<span id="cb10-87"></span>
<span id="cb10-88"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write.csv</span>(sum1, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outputs"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tables"</span>,</span>
<span id="cb10-89">                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OUTCOME_1.csv"</span>))</span></code></pre></div></div>
</div>
<hr>
<p>Once I have fit my model and done some initial checks, I usually conduct some more thorough checks using k-fold cross-validation or nested cross-validation, or bootstrap optimism.</p>
<p>A script of this can be found below.</p>
<hr>
<div class="cell">
<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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01-functions.R"</span>))</span>
<span id="cb11-2"></span>
<span id="cb11-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 10-Fold Cross-Validations -------------------------</span></span>
<span id="cb11-4"></span>
<span id="cb11-5">kfold_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;">kfold</span>(pen_model_1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">K =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span id="cb11-6">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">save_fits =</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;">cores =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb11-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">saveRDS</span>(kfold_1, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<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;">"Models"</span>,</span>
<span id="cb11-8">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Validation"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kfold_1.rds"</span>))</span>
<span id="cb11-9">kfp_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;">kfold_predict</span>(kfold_1)</span>
<span id="cb11-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">saveRDS</span>(kfp_1, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<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;">"Models"</span>,</span>
<span id="cb11-11">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Validation"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kfp_1.rds"</span>))</span>
<span id="cb11-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kfold_rmse</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> kfp_1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>y,</span>
<span id="cb11-13">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yrep =</span> kfp_1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>yrep,</span>
<span id="cb11-14">           <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;">"rmse"</span>,</span>
<span id="cb11-15">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>,</span>
<span id="cb11-16"><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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]][[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span>]]<span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">)</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-&gt;</span> kfold_rmse_1</span>
<span id="cb11-17"></span>
<span id="cb11-18">kfold_rmse_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;">median</span>(kfold_rmse_1)</span>
<span id="cb11-19"></span>
<span id="cb11-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">saveRDS</span>(kfold_rmse_1,</span>
<span id="cb11-21">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<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;">"Models"</span>,</span>
<span id="cb11-22">             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Validation"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kfold_rmse_1.rds"</span>))</span></code></pre></div></div>
</div>
<hr>
<p>Once I’ve written all my analysis and validation scripts, I’ll typically create a subfolder in the <code>Outputs</code> folder called <code>Figures</code> and <code>Tables</code> and save them appropriately with the help <code>here()</code>.</p>
<hr>
</section>
<section id="example-table-script" class="level2">
<h2 class="anchored" data-anchor-id="example-table-script">Example Table Script</h2>
<hr>
<div class="cell">
<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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"01-functions.R"</span>))</span>
<span id="cb12-2"></span>
<span id="cb12-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Read in Validation Objects ------------------------</span></span>
<span id="cb12-4"></span>
<span id="cb12-5">kfold_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;">readRDS</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kfold_1.rds"</span>,</span>
<span id="cb12-6">                   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main Project"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data"</span>,</span>
<span id="cb12-7">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Models"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Validation"</span>,</span>
<span id="cb12-8">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kfold_1.rds"</span>))</span>
<span id="cb12-9">kfold_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;">readRDS</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kfold_1.rds"</span>,</span>
<span id="cb12-10">                   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main Project"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data"</span>,</span>
<span id="cb12-11">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Models"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Validation"</span>,</span>
<span id="cb12-12">                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kfold_2.rds"</span>))</span>
<span id="cb12-13">kfp_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;">readRDS</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kfp_1.rds"</span>,</span>
<span id="cb12-14">                 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main Project"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data"</span>,</span>
<span id="cb12-15">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Models"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Validation"</span>,</span>
<span id="cb12-16">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kfp_1.rds"</span>))</span>
<span id="cb12-17">kfp_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;">readRDS</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kfp_1.rds"</span>,</span>
<span id="cb12-18">                 <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main Project"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data"</span>,</span>
<span id="cb12-19">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Models"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Validation"</span>,</span>
<span id="cb12-20">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"kfp_2.rds"</span>))</span>
<span id="cb12-21"></span>
<span id="cb12-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Extract Estimates from Objects ---------------------</span></span>
<span id="cb12-23"></span>
<span id="cb12-24">KFOLDIC_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;">c</span>(kfold_1[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"estimates"</span>]][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>],</span>
<span id="cb12-25">                     kfold_2[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"estimates"</span>]][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>])</span>
<span id="cb12-26">KFOLDIC_SE_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;">c</span>(kfold_1[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"estimates"</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;">2</span>],</span>
<span id="cb12-27">                        kfold_2[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"estimates"</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;">2</span>])</span>
<span id="cb12-28">BAYES_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;">c</span>(bayes_rsq1, bayes_rsq2), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb12-29">KFOLD_ELPD_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;">c</span>(kfold_1[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"estimates"</span>]][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>],</span>
<span id="cb12-30">                        kfold_2[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"estimates"</span>]][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb12-31">KFOLD_ELPD_SE_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;">c</span>(kfold_1[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"estimates"</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>
<span id="cb12-32">                           kfold_2[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"estimates"</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>
<span id="cb12-33"></span>
<span id="cb12-34">Outcome <span class="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;">"OUTCOME_1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"OUTCOME_2"</span>)</span>
<span id="cb12-35"></span>
<span id="cb12-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Construct Data Frames ------------------------------</span></span>
<span id="cb12-37"></span>
<span id="cb12-38">table4 <span class="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>(Outcome, BAYES_R2, KFOLD_ELPD_1,</span>
<span id="cb12-39">                     KFOLD_ELPD_SE_1, KFOLDIC_1,</span>
<span id="cb12-40">                     KFOLDIC_SE_1)</span>
<span id="cb12-41"></span>
<span id="cb12-42"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(table4) <span class="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;">"Outcome"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bayes R^2"</span>,</span>
<span id="cb12-43">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10-fold CV ELPD"</span>,</span>
<span id="cb12-44">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10-fold CV ELPD SE"</span>,</span>
<span id="cb12-45">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10-fold CV IC"</span>,</span>
<span id="cb12-46">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10-fold CV IC SE"</span>)</span>
<span id="cb12-47"></span>
<span id="cb12-48"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Export as Tables ----------------------------------</span></span>
<span id="cb12-49"></span>
<span id="cb12-50"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write.csv</span>(table4, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main Project"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outputs"</span>,</span>
<span id="cb12-51">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tables"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Table4.csv"</span>))</span>
<span id="cb12-52"></span>
<span id="cb12-53">table5 <span class="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>(Outcome, KFOLD_ELPD_1,</span>
<span id="cb12-54">                     KFOLD_ELPD_SE_1,</span>
<span id="cb12-55">                     KFOLDIC_1, KFOLDIC_SE_1)</span>
<span id="cb12-56"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(table5) <span class="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;">"Outcome"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10-fold CV ELPD"</span>,</span>
<span id="cb12-57">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10-fold CV ELPD SE"</span>,</span>
<span id="cb12-58">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10-fold CV IC"</span>,</span>
<span id="cb12-59">                      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10-fold CV IC SE"</span>)</span>
<span id="cb12-60"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write.csv</span>(table5,</span>
<span id="cb12-61">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main Project"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outputs"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tables"</span>,</span>
<span id="cb12-62">               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Table5.csv"</span>))</span>
<span id="cb12-63"></span>
<span id="cb12-64"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Save Tables From Sensitivity Analyses --------------</span></span>
<span id="cb12-65"></span>
<span id="cb12-66"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write.csv</span>(sens_table_OUTCOME_1,</span>
<span id="cb12-67">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main Project"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outputs"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tables"</span>,</span>
<span id="cb12-68">               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Table7_OUTCOME_1.csv"</span>))</span>
<span id="cb12-69"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write.csv</span>(sens_table_OUTCOME_2,</span>
<span id="cb12-70">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Main Project"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outputs"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Tables"</span>,</span>
<span id="cb12-71">               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Table7_OUTCOME_2.csv"</span>))</span></code></pre></div></div>
</div>
<hr>
<p>Then, I’ll go back to the <code>README.Rmd</code> file, make notes of the hierarchy of the entire folder and subfolders, and what’s been completed, and what still needs to be done.</p>
<p>Now, suppose I deleted all of my saved models, imputed data, graphs, and tables, (which would be a devastating blow!) and only had the original dataset and organized scripts. Anyone could go into my project and simply highlight the entire <code>main.R</code> file and run it, and they would get all the same outputs and models, assuming a seed was set in advance, which is essential. Although, it might take them a long time to get the same outputs (if computationally intensive)… they would likely be able to get all the exact same results.</p>
<hr>
</section>
</section>
<section id="possible-drawbacks-of-this-approach" class="level1">
<h1>Possible Drawbacks of this Approach</h1>
<hr>
<p>Every proposal tends to have drawbacks or limitations, and those who do not explicitly tell you about them are misleading you. In the approach I have outlined above, one major drawback is that it takes a somewhat long time to set up and therefore could deter many statisticians and data analysts. The other drawback is that by loading all your functions and libraries in the first <code>01_functions.R</code> script, there is potential for conflict between functions, therefore you’ll have to be mindful of what packages you need and when. Indeed, I ran into this issue when loading the <code>brms</code> package, which had several functions that conflicted with the base <code>R</code> functions. So please be mindful of this.</p>
<p>Further, and most importantly, I have no evidence that this approach can truly prevent errors, it is simply a belief I have as a result of my own experiences and suggesting them to others, and hearing positive comments. So please, take that into account, although I would be grateful if you were able to share your positive or even negative experiences using this approach below.</p>
<hr>
<p>Please, please annotate your scripts, as I have done so several times above to explain some of the functions. This is not only helpful for others who are trying to go through your code and understand it, but also for yourself. If you end up forgetting what function does what, and what steps you were taking, you will be in for a really frustrating time, and possibly prone to making serious mistakes.</p>
<p>Here’s what my project folders tend to look like (figure below). And here is a <a href="https://github.com/zadrafi/statworkflow">template GitHub repo</a> to show what the structure typically looks like.</p>
<hr>
<p><img data-enlargeable="" width="400" style="cursor: zoom-in" src="https://res.cloudinary.com/less-likely/image/upload/v1592068111/Site/Screen_Shot_2020-06-13_at_11.38.26_AM.png"></p>
<hr>
<p>It should go without saying that sharing your data (if possible) and code will help you and your collaborators catch errors before it’s too late, but also, sharing them with others/the public after a project is done will <em>also</em> help catch possible errors that you/your collaborators/reviewers didn’t catch, which may mislead other researchers and also result in a much more stressful situation for you.</p>
<p>And last but not least, it is also essential to give extensive details on which version of <code>R</code> you used and which packages you used and their versions. This is because many scripts that once worked on previous versions of the software may no longer give the same results or may not even work at all. In order for someone to reproduce your results, they’ll need to know the environment on which you ran your analyses on. You can provide these details easily simply by running the script <code>sessionInfo()</code>, which should be at the end of every <code>R</code> script you run.</p>
<hr>
</section>
<section id="helpful-resources" class="level1">
<h1>Helpful Resources</h1>
<hr>
<ul>
<li><a href="https://stackoverflow.com/questions/1429907/workflow-for-statistical-analysis-and-report-writing">Workflow for Statistical Analysis and Report Writing</a></li>
</ul>
<hr>
<ul>
<li><a href="https://stackoverflow.com/questions/19967478/how-to-save-data-file-into-rdata">How to Save Data File into .RData?</a></li>
</ul>
<hr>
<ul>
<li><a href="https://www.youtube.com/watch?v=Ry2xjTBtNFE">Basic Data Entry Using Excel</a></li>
</ul>
<hr>
<ul>
<li><a href="https://www.kristianbrock.com/post/send-me-data/">Sending Me Data in Excel</a></li>
</ul>
<hr>
<ul>
<li><a href="https://happygitwithr.com/">Happy Git and GitHub for the useR</a></li>
</ul>
<hr>
</section>
<section id="environment" class="level1">
<h1>Environment</h1>
<hr>
<p>The analyses were run on:</p>
<hr>
<div class="cell">
<pre><code>R version 4.6.0 (2026-04-24)
Platform: aarch64-apple-darwin25.4.0
Running under: macOS Tahoe 26.5.1

Matrix products: default
BLAS:   /opt/homebrew/Cellar/openblas/0.3.33/lib/libopenblasp-r0.3.33.dylib 
LAPACK: /opt/homebrew/Cellar/r/4.6.0/lib/R/lib/libRlapack.dylib;  LAPACK version 3.12.1

Random number generation:
 RNG:     Mersenne-Twister 
 Normal:  Inversion 
 Sample:  Rejection 
 
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] htmlwidgets_1.6.4 compiler_4.6.0    fastmap_1.2.0     cli_3.6.6         htmltools_0.5.9   tools_4.6.0       parallel_4.6.0   
 [8] otel_0.2.0        yaml_2.3.12       rmarkdown_2.31    knitr_1.51        data.table_1.18.4 jsonlite_2.0.0    xfun_0.59        
[15] digest_0.6.39     rlang_1.2.0       evaluate_1.0.5</code></pre>
</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="level1">
<h1>References</h1>
<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> ]]></description>
  <category>statistics</category>
  <guid>https://lesslikely.com/statistics/statistical-quality-control.html</guid>
  <pubDate>Sat, 13 Jun 2020 04:00:00 GMT</pubDate>
  <media:content url="https://res.cloudinary.com/less-likely/image/upload/v1613136545/Site/diagram.png" medium="image" type="image/png"/>
</item>
<item>
  <title>Book Review: Regression and Other Stories by Gelman, Hill, and Vehtari</title>
  <dc:creator>Zad Rafi</dc:creator>
  <link>https://lesslikely.com/statistics/regression-stories.html</link>
  <description><![CDATA[ 





<hr>
<p>Over a decade ago, <a href="https://statmodeling.stat.columbia.edu/">Andrew Gelman</a> and <a href="https://steinhardt.nyu.edu/faculty/Jennifer_L_Hill">Jennifer Hill</a> gave applied researchers a comprehensive book <em>(<a href="https://www.amazon.com/Analysis-Regression-Multilevel-Hierarchical-Models/dp/052168689X">Data Analysis Using Regression and Multilevel/Hierarchical Models</a>)</em> on fitting simple and complex statistical models in <code>R</code> both from a classical framework and a Bayesian one. Now they’re back with an updated version and a new author (<a href="https://users.aalto.fi/~ave/">Aki Vehtari</a>).</p>
<p>Much has changed in applied statistics since 2006 (when the book was first released). The primary software used at the time and in the book to fit Bayesian models was <code>BUGS</code> (Bayesian inference Using Gibbs Sampling).</p>
<p>However, both <code>BUGS</code> and some of the <code>R</code> code in the first edition are now outdated. The new edition updates the <code>R</code> code and contains intuitive instructions on how to fit simple and complex models using the probabilistic programming language, <a href="https://mc-stan.org/"><code>Stan</code></a> (also developed by Gelman and <a href="https://mc-stan.org/about/team/">colleagues</a>), which is now used in several fields (even for <a href="https://statmodeling.stat.columbia.edu/2019/04/24/postdoctoral-position-in-vancouver-using-stan-working-on-wine-for-reals/">studying wine!</a>).</p>
<p>Indeed, running a Bayesian regression model in <code>R</code> is now as simple as</p>
<hr>
<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"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># I use the sample PlantGrowth dataset in R</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;">"rstanarm"</span>)</span>
<span id="cb1-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;">"bayesplot"</span>)</span>
<span id="cb1-4">pg <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> PlantGrowth</span>
<span id="cb1-5">model1 <span class="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>(weight <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> group, </span>
<span id="cb1-6">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> pg, <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="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model1)</span>
<span id="cb1-8"></span>
<span id="cb1-9">Model Info<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span></span>
<span id="cb1-10"> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>     stan_glm</span>
<span id="cb1-11"> family<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>       gaussian [identity]</span>
<span id="cb1-12"> formula<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>      weight <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> group</span>
<span id="cb1-13"> algorithm<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>    sampling</span>
<span id="cb1-14"> sample<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;">4000</span> (posterior sample size)</span>
<span id="cb1-15"> priors<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>       see <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">help</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'prior_summary'</span>)</span>
<span id="cb1-16"> observations<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;">30</span></span>
<span id="cb1-17"> predictors<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="cb1-18"></span>
<span id="cb1-19">Estimates<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span></span>
<span id="cb1-20">              mean   sd   <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;">%   50%</span>   <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span>%</span>
<span id="cb1-21">(Intercept)  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.0</span>    <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.8</span>   <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.0</span>   <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.3</span> </span>
<span id="cb1-22">grouptrt1   <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="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.7</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span> </span>
<span id="cb1-23">grouptrt2    <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.3</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.5</span>   <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span> </span>
<span id="cb1-24">sigma        <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</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.5</span>   <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>   <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span> </span>
<span id="cb1-25"></span>
<span id="cb1-26">Fit Diagnostics<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span></span>
<span id="cb1-27">           mean   sd   <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;">%   50%</span>   <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span>%</span>
<span id="cb1-28">mean_PPD <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.1</span>    <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.9</span>   <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.1</span>   <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.3</span>  </span>
<span id="cb1-29"></span>
<span id="cb1-30">The mean_ppd is the sample average posterior predictive distribution of the outcome <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">variable</span> (<span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> details see <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">help</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'summary.stanreg'</span>)).</span>
<span id="cb1-31"></span>
<span id="cb1-32">MCMC diagnostics</span>
<span id="cb1-33">              mcse Rhat n_eff</span>
<span id="cb1-34">(Intercept)   <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0</span>  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2844</span> </span>
<span id="cb1-35">grouptrt1     <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0</span>  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2882</span> </span>
<span id="cb1-36">grouptrt2     <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0</span>  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2642</span> </span>
<span id="cb1-37">sigma         <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0</span>  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3279</span> </span>
<span id="cb1-38">mean_PPD      <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0</span>  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3354</span> </span>
<span id="cb1-39">log<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>posterior <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0</span>  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1645</span> </span>
<span id="cb1-40"></span>
<span id="cb1-41">For each parameter, mcse is Monte Carlo standard error, n_eff is a crude measure of effective sample size, and Rhat is the potential scale reduction factor on split <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">chains</span> (at convergence <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Rhat=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>).</span>
<span id="cb1-42"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(model1)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><a href="regression-stories_files/figure-html/unnamed-chunk-2-1.svg" class="lightbox" data-gallery="quarto-lightbox-gallery-1"><img src="https://lesslikely.com/statistics/regression-stories_files/figure-html/unnamed-chunk-2-1.svg" class="img-fluid figure-img" width="672"></a></p>
</figure>
</div>
</div>
</div>
<hr>
<p>Another key difference between the first edition and the new edition is that the 2006 book attempted to cover several topics at once. It contained instructions on how to fit simple models in a classical framework all the way up to multilevel models in a Bayesian framework. The new edition attempts to reduce this information overload by splitting itself into two volumes.</p>
<p>The first volume <em>(Regression and Other Stories)</em> covers fitting simple and complex models using <code>R</code> and <code>Stan</code>, and is oriented towards the applied researcher or statistician, who wants a smooth introduction to fitting Bayesian models using <code>Stan</code> without diving into much theory or math.</p>
<p>A draft copy of the table of contents in the new edition can be <a href="../uploads/regressiontoc.pdf">found here</a>, though it’s very likely that the published edition will have some changes.</p>
<p>The book does not cover much of multilevel modeling, which is reserved for the second volume, <em>Advanced Regression and Multilevel Models</em> (planned to be released in the next year or two).</p>
<p>Make no mistake, although both of these books are unlikely to touch on a serious amount of theory or math, they are not books that can be read without serious engagement and practice. Every chapter contains enough math for the reader to understand the concepts being discussed with exercises at the end to solidify these concepts.</p>
<p>The chapter exercises are incredibly similar to these exam questions that Gelman created for his Applied Regression class.</p>
<p>Question: <a href="https://statmodeling.stat.columbia.edu/2019/06/01/question-1-of-our-applied-regression-final-exam/">1</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/02/question-2-of-our-applied-regression-final-exam-and-solution-to-question-1/">2</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/03/question-3-of-our-applied-regression-final-exam-and-solution-to-question-2/">3</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/04/question-4-of-our-applied-regression-final-exam-and-solution-to-question-3/">4</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/05/question-5-of-our-applied-regression-final-exam-and-solution-to-question-4/">5</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/06/question-6-of-our-applied-regression-final-exam-and-solution-to-question-5/">6</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/07/question-7-of-our-applied-regression-final-exam-and-solution-to-question-6/">7</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/08/question-8-of-our-applied-regression-final-exam-and-solution-to-question-7/">8</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/09/question-9-of-our-applied-regression-final-exam-and-solution-to-question-8/">9</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/10/question-10-of-our-applied-regression-final-exam-and-solution-to-question-9/">10</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/11/question-11-of-our-applied-regression-final-exam-and-solution-to-question-10/">11</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/12/question-12-of-our-applied-regression-final-exam-and-solution-to-question-11/">12</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/13/question-13-of-our-applied-regression-final-exam-and-solution-to-question-12/">13</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/14/question-14-of-our-applied-regression-final-exam-and-solution-to-question-13/">14</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/15/question-15-of-our-applied-regression-final-exam-and-solution-to-question-14/">15</a>, <a href="https://statmodeling.stat.columbia.edu/2019/06/16/were-done-with-our-applied-regression-final-exam-and-solution-to-question-15/">solution to 15</a>.</p>
<p>I suspect that many of the commenters of the blog who had some difficulty with these questions would have had an easier time had they had the opportunity to read the book.</p>
<p>The new edition also covers several news stories from the past few years (some of which long-time blog readers will be familiar with) and gives readers a set of tools to think critically about these stories and how proper statistical thinking could’ve prevented mishaps. In addition, it incorporates concepts that Gelman and colleagues have developed and solidified over the years, since the first edition was published, such as the concept of <a href="https://doi.org/10.1177%2F1745691614551642">Type-M and Type-S errors</a>.</p>
<p>Overall, the book is quite comprehensive and will leave the reader with a rich set of tools to think critically about statistics and to fit models in the real world. I look forward to grabbing a hard copy once the book is out, which seems to be in the <a href="https://twitter.com/avehtari/status/1251188631487774720">summer to fall of 2020</a>.</p>
<hr>
<blockquote class="blockquote">
<p>Update: Looks like the <a href="https://www.amazon.com/Regression-Stories-Analytical-Methods-Research/dp/110702398X">book is out!</a></p>
</blockquote>


<!-- -->


<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>
  <guid>https://lesslikely.com/statistics/regression-stories.html</guid>
  <pubDate>Tue, 11 Jun 2019 04:00:00 GMT</pubDate>
  <media:content url="https://res.cloudinary.com/less-likely/image/upload/f_auto,q_auto/v1587793393/Site/gelman_raos_2020.jpg" medium="image" type="image/jpeg"/>
</item>
</channel>
</rss>
