<?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>Trial Notes</title>
<link>https://trialnotes.org/posts.html</link>
<atom:link href="https://trialnotes.org/posts.xml" rel="self" type="application/rss+xml"/>
<description>Notes on trial design and analysis</description>
<generator>quarto-1.5.57</generator>
<lastBuildDate>Sat, 04 Apr 2026 04:00:00 GMT</lastBuildDate>
<item>
  <title>Moving Beyond Percent Change from Baseline: Longitudinal Negative Binomial Models in Single-Arm Studies</title>
  <dc:creator>Fei Zuo</dc:creator>
  <link>https://trialnotes.org/posts/one_arm/</link>
  <description><![CDATA[ 




<p><strong>🎧 1-minute summary</strong></p>
<p><em>Narration generated using OpenAI.fm.</em></p>
<audio controls="" preload="none" style="width:320px; margin-bottom:14px;">
<source src="../../audio/single_arm.mp3" type="audio/mpeg">
</audio>
<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">
Disclaimer
</div>
</div>
<div class="callout-body-container callout-body">
<p>This post uses simulated data for illustration and does not reflect any specific study, program, or proprietary design.</p>
</div>
</div>
<p>In single-arm or open-label seizure studies, efficacy is often summarized using <strong>percent change from baseline (PCFB)</strong>. Tables of <strong>mean</strong> or <strong>median PCFB</strong>, and sometimes <strong>responder rates</strong>, are used to describe how patients appear to improve after starting treatment.</p>
<p>While familiar, these summaries come with important limitations:</p>
<ul>
<li><p>discard rich longitudinal data into a single derived value</p></li>
<li><p>behave asymmetrically and nonlinearly</p></li>
<li><p>obscure how outcomes evolve over time</p></li>
<li><p>do not directly estimate a seizure reduction (see discussion <a href="https://trialnotes.org/posts/estimand/">here</a>)</p></li>
</ul>
<p>An alternative is to analyze the <strong>observed seizure counts directly over time</strong> using a <strong>longitudinal negative binomial (NB) model</strong>. Rather than reducing the data to baseline-to-post-baseline summaries, this approach uses all repeated measurements and models how seizure rates evolve after treatment initiation.</p>
<p>In single-arm settings, this naturally leads to using <strong>time as a proxy for treatment exposure</strong>.</p>
<section id="model-setup" class="level2">
<h2 class="anchored" data-anchor-id="model-setup">Model setup</h2>
<p>In the absence of a control arm, we observe seizure counts repeatedly after treatment begins. A longitudinal NB model can be written as:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Clog%5Cbig(E%5BY_%7Bit%7D%5D%5Cbig)%20=%20%5Cbeta_0%20+%20f(%5Ctext%7Btime%7D_%7Bit%7D)%20+%20%5Cgamma%20%5Ccdot%20%5Ctext%7Bbaseline%7D_i%20+%20b_i%20+%20%5Clog(%5Ctext%7Bexposure%7D_%7Bit%7D)%0A"></p>
<p>where:</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?Y_%7Bit%7D">: seizure count for patient <img src="https://latex.codecogs.com/png.latex?i"> at time <img src="https://latex.codecogs.com/png.latex?t"><br>
</li>
<li><img src="https://latex.codecogs.com/png.latex?f(%5Ctext%7Btime%7D)">: effect of follow-up time<br>
</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Ctext%7Bbaseline%7D_i">: baseline seizure frequency<br>
</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Cgamma">: coefficient for baseline<br>
</li>
<li><img src="https://latex.codecogs.com/png.latex?b_i">: subject-specific random effect<br>
</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Clog(%5Ctext%7Bexposure%7D_%7Bit%7D)">: offset accounting for observation duration (applicable when follow-up duration differs across subjects)</li>
</ul>
<p>Here, <strong>time captures how seizure rates change after treatment initiation</strong>, while <strong>baseline explains between-patient differences</strong>.</p>
</section>
<section id="how-this-is-different-from-pcfb" class="level2">
<h2 class="anchored" data-anchor-id="how-this-is-different-from-pcfb">How this is different from PCFB</h2>
<p>PCFB asks:</p>
<blockquote class="blockquote">
<p>How much did the outcome change from baseline to a single follow-up time?</p>
</blockquote>
<p>A longitudinal NB model asks:</p>
<blockquote class="blockquote">
<p>What is the trajectory of seizure rates over time after treatment starts?</p>
</blockquote>
<p>Key differences:</p>
<ul>
<li><p>PCFB discards the original count data → NB uses count data from all visits</p></li>
<li><p>PCFB embeds baseline in the outcome, introducing extra noise and variability → NB allows baseline to be modelled separately as a predictor</p></li>
<li><p>PCFB distorts scale because it’s asymmetric and nonlinear → NB models counts on a natural rate scale</p></li>
<li><p>trials reporting on PCFB summaries typically ignore within-subject correlation by collapsing repeated measures into a single summary → NB explicitly models repeated measures</p></li>
</ul>
</section>
<section id="baseline-covariate-vs-reference-point" class="level2">
<h2 class="anchored" data-anchor-id="baseline-covariate-vs-reference-point">Baseline: covariate vs reference point</h2>
<p>A common practice in single-arm analyses is to:</p>
<blockquote class="blockquote">
<p>compare each post-baseline visit to baseline, rather than adjusting for baseline as a covariate</p>
</blockquote>
<p>While intuitive, this approach has a key flaw.</p>
<p>Baseline seizure frequency is <strong>highly prognostic</strong> of future counts. It is not just a reference point—it is a major source of variability across patients.</p>
<p>When you anchor everything to baseline:</p>
<ul>
<li><p>baseline becomes part of the outcome (as in PCFB)</p></li>
<li><p>its prognostic information is no longer used to explain variability</p></li>
<li><p>additional noise is introduced because the outcome depends on both baseline and post-baseline measurements</p></li>
<li><p>and time effects can become confounded with baseline-dependent dynamics (including regression to the mean)</p></li>
</ul>
<p>In contrast, including baseline as a covariate:</p>
<ul>
<li><p>separates <strong>between-patient heterogeneity</strong> from <strong>within-patient change over time</strong></p></li>
<li><p>improves efficiency</p></li>
<li><p>and yields a cleaner interpretation of the post-treatment trajectory</p></li>
</ul>
<p><strong>In single-arm settings,</strong> <strong>apparent improvements measured as changes from baseline (including PCFB and responder rates derived from PCFB) do not identify a treatment effect</strong>. This is because the outcome is defined relative to baseline, so any observed changes, whether due to natural fluctuations, regression to the mean, or other time effects, are carried directly into the endpoint. Without a control group, these changes are indistinguishable from what would have happened in the absence of treatment. As a result, descriptive summaries such as PCFB or responder rates should not be interpreted as evidence of efficacy.</p>
<p>A longitudinal negative binomial model provides a more principled way to evaluate post-baseline trajectory by accounting for baseline differences and within-subject variability. Importantly, baseline is treated as a covariate rather than embedded in the outcome, so the model does not rely on baseline as a reference point for comparison.</p>
</section>
<section id="interpreting-the-time-effect-in-a-negative-binomial-model" class="level2">
<h2 class="anchored" data-anchor-id="interpreting-the-time-effect-in-a-negative-binomial-model">Interpreting the time effect in a negative binomial model</h2>
<p>If time is modelled linearly:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Af(%5Ctext%7Btime%7D)%20=%20%5Cbeta_1%20%5Ccdot%20%5Ctext%7Btime%7D%0A"></p>
<p>then:</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?%5Cexp(%5Cbeta_1)"> is the rate ratio per visit<br>
</li>
<li>e.g., <img src="https://latex.codecogs.com/png.latex?%5Cexp(%5Cbeta_1)%20=%200.90"> implies a 10% reduction in seizure rate per visit</li>
</ul>
<p>This provides a simple summary of longitudinal change but it assumes the effect is constant over time.</p>
</section>
<section id="allowing-the-time-effect-to-vary" class="level2">
<h2 class="anchored" data-anchor-id="allowing-the-time-effect-to-vary">Allowing the time effect to vary</h2>
<p>In practice, treatment-associated trajectories are rarely perfectly linear. You may see:</p>
<ul>
<li><p>rapid early improvement</p></li>
<li><p>delayed onset</p></li>
<li><p>plateauing</p></li>
<li><p>or rebound</p></li>
</ul>
<p>These patterns can be explored by modelling time more flexibly.</p>
<section id="time-as-a-categorical-variable" class="level3">
<h3 class="anchored" data-anchor-id="time-as-a-categorical-variable">Time as a categorical variable</h3>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">count <span 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>(visit) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> log_baseline <span 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> id)</span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>count ~ factor(visit) + log_baseline + (1 | id)</code></pre>
</div>
</div>
<ul>
<li><p>no shape assumption</p></li>
<li><p>each visit has its own estimate</p></li>
<li><p>a useful first diagnostic, but can introduce many parameters and is often not suitable as a final model where there are many visits</p></li>
<li><p>Baseline is included on the log scale to stabilize its relationship with the outcome, since seizure counts are typically skewed and vary over a wide range, and proportional differences are more meaningful than absolute differences. More flexible approaches to modelling baseline (e.g., splines) could also be considered, and this is an area we will explore in a separate post.</p></li>
</ul>
</section>
<section id="polynomial-time-quadratic" class="level3">
<h3 class="anchored" data-anchor-id="polynomial-time-quadratic">Polynomial time (quadratic)</h3>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">count <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> visit <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">I</span>(visit<span 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> log_baseline <span 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> id)</span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>count ~ visit + I(visit^2) + log_baseline + (1 | id)</code></pre>
</div>
</div>
<ul>
<li><p>allows curvature</p></li>
<li><p>simple extension of the linear model</p></li>
<li><p>still assumes a functional form for time, which may be restrictive</p></li>
<li><p>can behave poorly at the boundaries (i.e., at early and late visits)</p></li>
<li><p>interpretation becomes less intuitive as higher-order terms are added</p></li>
</ul>
</section>
<section id="splines-flexible-smooth-trajectories" class="level3">
<h3 class="anchored" data-anchor-id="splines-flexible-smooth-trajectories">Splines (flexible smooth trajectories)</h3>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(splines)</span>
<span id="cb5-2"></span>
<span id="cb5-3">count <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ns</span>(visit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</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> log_baseline <span 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> id)</span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>count ~ ns(visit, df = 3) + log_baseline + (1 | id)</code></pre>
</div>
</div>
<ul>
<li><p>allows flexible, smooth nonlinear trajectories over time</p></li>
<li><p>avoids imposing a rigid functional form for time</p></li>
<li><p>more stable than high-degree polynomials</p></li>
<li><p>coefficients are not directly interpretable</p></li>
<li><p>requires choosing degrees of freedom (i.e., number and placement of knots), though default choices are often adequate in practice since the goal is to capture overall shape without overfitting</p></li>
</ul>
</section>
</section>
<section id="interpreting-flexible-time-models" class="level2">
<h2 class="anchored" data-anchor-id="interpreting-flexible-time-models">Interpreting flexible time models</h2>
<p>Once time is modelled flexibly via splines or higher-order polynomials, coefficients are no longer directly interpretable.</p>
<p>Instead, interpretation should focus on:</p>
<section id="the-fitted-trajectory-primary" class="level3">
<h3 class="anchored" data-anchor-id="the-fitted-trajectory-primary">1. The fitted trajectory (primary)</h3>
<ul>
<li><p>plot predicted seizure rates over time</p></li>
<li><p>assess shape (early drop, plateau, etc.)</p></li>
</ul>
</section>
<section id="comparisons-between-time-points" class="level3">
<h3 class="anchored" data-anchor-id="comparisons-between-time-points">2. Comparisons between time points</h3>
<ul>
<li><p>visit 2 vs visit 1</p></li>
<li><p>visit 3 vs visit 1</p></li>
<li><p>visit 4 vs visit 2</p></li>
<li><p>visit 5 vs visit 3</p></li>
</ul>
<p>These give <strong>interval-specific rate ratios</strong>, which are often more meaningful than a single slope.</p>
<p>Conceptually:</p>
<ul>
<li><p>linear time → <strong>one number (constant effect)</strong></p></li>
<li><p>flexible time → <strong>a curve (time-varying effect)</strong></p></li>
</ul>
</section>
</section>
<section id="a-simulated-study-for-illustration" class="level2">
<h2 class="anchored" data-anchor-id="a-simulated-study-for-illustration">A simulated study for illustration</h2>
<p>A single-arm longitudinal seizure study was simulated with repeated counts over six post-baseline visits, incorporating a baseline covariate, subject-level variability, and a nonlinear time effect reflecting delayed and evolving improvement. Counts were generated from a negative binomial distribution with varying observation durations. A linear time model was compared with a flexible spline model to illustrate how different assumptions about time affect the estimated trajectory. Details of the simulation are provided in the annotated code.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ============================================================</span></span>
<span id="cb7-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simulate one single-arm longitudinal seizure study</span></span>
<span id="cb7-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># with NONLINEAR (visit-specific) time effects</span></span>
<span id="cb7-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#</span></span>
<span id="cb7-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Goal:</span></span>
<span id="cb7-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># - illustrate a setting where the time effect is NOT constant</span></span>
<span id="cb7-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># - demonstrate when flexible time modelling (e.g., natural splines) is useful</span></span>
<span id="cb7-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ============================================================</span></span>
<span id="cb7-9"></span>
<span id="cb7-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 1. Load packages</span></span>
<span id="cb7-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(glmmTMB)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># negative binomial mixed models</span></span>
<span id="cb7-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(dplyr)     <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># data manipulation</span></span>
<span id="cb7-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plotting</span></span>
<span id="cb7-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(splines)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># natural spline basis for time</span></span>
<span id="cb7-17"></span>
<span id="cb7-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set seed for reproducibility</span></span>
<span id="cb7-19"><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;">1234</span>)</span>
<span id="cb7-20"></span>
<span id="cb7-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 2. Define study design</span></span>
<span id="cb7-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-24">n_patients <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;">80</span>                 <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># number of subjects</span></span>
<span id="cb7-25">n_visits <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>                    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># visits: 1, 2, 3, 4, 5, 6</span></span>
<span id="cb7-26">visit_times <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>n_visits        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># post-baseline visits only</span></span>
<span id="cb7-27"></span>
<span id="cb7-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Note:</span></span>
<span id="cb7-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Here I simulate only post-baseline repeated counts.</span></span>
<span id="cb7-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Baseline seizure count is included as a subject-level covariate, not as one of the longitudinal count outcomes.</span></span>
<span id="cb7-31"></span>
<span id="cb7-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 3. Define true data-generating parameters</span></span>
<span id="cb7-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-35"></span>
<span id="cb7-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Baseline mean seizure level (on log scale)</span></span>
<span id="cb7-37">beta_0 <span class="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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>)</span>
<span id="cb7-38"></span>
<span id="cb7-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Effect of baseline seizure count (log scale)</span></span>
<span id="cb7-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We use log(28-day seizure count at baseline + 1) as the baseline covariate  </span></span>
<span id="cb7-41"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># A value of 1 is added to avoid log(0)</span></span>
<span id="cb7-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># In practice, this is often not an issue if the study has a minimum entry criterion (e.g., ≥5 seizures during the baseline period).</span></span>
<span id="cb7-43">beta_baseline <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.35</span></span>
<span id="cb7-44"></span>
<span id="cb7-45"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Subject-specific heterogeneity (random intercept SD - i.e., between-subject variability)</span></span>
<span id="cb7-46">sd_subject <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span></span>
<span id="cb7-47"></span>
<span id="cb7-48"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Negative binomial size parameter</span></span>
<span id="cb7-49"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Smaller values = more overdispersion</span></span>
<span id="cb7-50">theta_nb <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;">4</span></span>
<span id="cb7-51"></span>
<span id="cb7-52"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-53"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 4. Define NONLINEAR time effects</span></span>
<span id="cb7-54"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-55"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># These are visit-specific log-rate effects (relative to visit 1)</span></span>
<span id="cb7-56"></span>
<span id="cb7-57">true_time_effect <span class="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="cb7-58">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># visit 1: no effect (reference)</span></span>
<span id="cb7-59">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2"</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;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>),        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 5% reduction relative to visit 1</span></span>
<span id="cb7-60">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"3"</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;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.90</span>),        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 10% reduction relative to visit 1</span></span>
<span id="cb7-61">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4"</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;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>),        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 25% reduction relative to visit 1</span></span>
<span id="cb7-62">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5"</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;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>),        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plateau - maintaining a 12% reduction relative to visit 1</span></span>
<span id="cb7-63">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"6"</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;">log</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>)          <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 40% reduction relative to visit 1</span></span>
<span id="cb7-64">)</span>
<span id="cb7-65"></span>
<span id="cb7-66"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Interpretation:</span></span>
<span id="cb7-67"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># - delayed onset of seizure reduction</span></span>
<span id="cb7-68"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># - increasing seizure reduction over time</span></span>
<span id="cb7-69"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># - partial plateau</span></span>
<span id="cb7-70"></span>
<span id="cb7-71"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-72"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 5. Simulate subject-level baseline information</span></span>
<span id="cb7-73"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-74">subject_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="cb7-75">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>n_patients,</span>
<span id="cb7-76"></span>
<span id="cb7-77">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simulate baseline 28-day seizure count for each patient</span></span>
<span id="cb7-78">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This is a covariate, not part of the repeated outcome series</span></span>
<span id="cb7-79">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Mu set to 8 as a chosen average baseline seizure rate that approximately gives about 8 seizures per 28 days</span></span>
<span id="cb7-80">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Size parameter set to 2.5 to allow for more baseline variability </span></span>
<span id="cb7-81">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Note: if baseline is collected over a longer period (e.g., 84 days),</span></span>
<span id="cb7-82">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># a 28-day seizure frequency is often derived as:</span></span>
<span id="cb7-83">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   28 * (total seizures in period / number of evaluable days in period)</span></span>
<span id="cb7-84">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">baseline28 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnbinom</span>(n_patients, <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;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>),</span>
<span id="cb7-85"></span>
<span id="cb7-86">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Random intercept to induce within-subject correlation</span></span>
<span id="cb7-87">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">b_i =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n_patients, <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> sd_subject)</span>
<span id="cb7-88">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-89">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb7-90">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Log-transform baseline count for use as a covariate</span></span>
<span id="cb7-91">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># +1 avoids taking log(0)</span></span>
<span id="cb7-92">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># In practice, this is often not an issue if the study has a minimum entry criterion (e.g., ≥5 seizures during the baseline period).</span></span>
<span id="cb7-93">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">log_baseline =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(baseline28 <span 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="cb7-94">  )</span>
<span id="cb7-95"></span>
<span id="cb7-96"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-97"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 6. Expand to one row per patient per visit (i.e., longitudinal data)</span></span>
<span id="cb7-98"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-99">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand.grid</span>(</span>
<span id="cb7-100">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>n_patients,</span>
<span id="cb7-101">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">visit =</span> visit_times</span>
<span id="cb7-102">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-103">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(id, visit) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-104">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(subject_df, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"id"</span>)</span>
<span id="cb7-105"></span>
<span id="cb7-106"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-107"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 7. Simulate observation duration</span></span>
<span id="cb7-108"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-109"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Allow varying observation periods to justify offset</span></span>
<span id="cb7-110"></span>
<span id="cb7-111">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-112">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb7-113">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">exposure_days =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</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;">28</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb7-114">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prob =</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.15</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.70</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span>)),</span>
<span id="cb7-115">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Offset adjusts for differing observation durations.</span></span>
<span id="cb7-116">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Dividing by 28 expresses the model on a 28-day rate scale,</span></span>
<span id="cb7-117">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># which aligns with typical reporting in epilepsy trials.</span></span>
<span id="cb7-118">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This does not affect exponentiated covariate effects (rate ratios), only the intercept.</span></span>
<span id="cb7-119">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">offset_log =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(exposure_days <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">28</span>)</span>
<span id="cb7-120">  )</span>
<span id="cb7-121"></span>
<span id="cb7-122"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-123"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 8. Generate mean seizure counts</span></span>
<span id="cb7-124"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-125"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># True linear predictor:</span></span>
<span id="cb7-126"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># log(E[count]) =</span></span>
<span id="cb7-127"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#   intercept</span></span>
<span id="cb7-128"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># + time effect</span></span>
<span id="cb7-129"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># + baseline prognostic effect</span></span>
<span id="cb7-130"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># + subject random intercept</span></span>
<span id="cb7-131"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># + offset for observation duration</span></span>
<span id="cb7-132"></span>
<span id="cb7-133">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-134">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb7-135">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">eta =</span> beta_0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-136">      true_time_effect[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(visit)] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># nonlinear time effect</span></span>
<span id="cb7-137">      beta_baseline <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> log_baseline <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-138">      b_i <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-139">      offset_log,</span>
<span id="cb7-140"></span>
<span id="cb7-141">    <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;">exp</span>(eta) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># expected seizure count; this can be non-integer.</span></span>
<span id="cb7-142">                  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Observed counts are integers drawn from a negative binomial distribution centered at mu.</span></span>
<span id="cb7-143">  )</span>
<span id="cb7-144"></span>
<span id="cb7-145"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-146"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 9. Simulate observed seizure counts</span></span>
<span id="cb7-147"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-148">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-149">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb7-150">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnbinom</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> theta_nb)</span>
<span id="cb7-151">  )</span>
<span id="cb7-152"></span>
<span id="cb7-153"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-154"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 10. Fit a linear-time NB mixed model (misspecified under this DGP)</span></span>
<span id="cb7-155"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-156"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This assumes a constant log-rate change per visit.</span></span>
<span id="cb7-157">fit_linear <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glmmTMB</span>(</span>
<span id="cb7-158">  count <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> visit <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> log_baseline <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">offset</span>(offset_log) <span 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> id),</span>
<span id="cb7-159">  <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;">nbinom2</span>(),</span>
<span id="cb7-160">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat</span>
<span id="cb7-161">)</span>
<span id="cb7-162"></span>
<span id="cb7-163"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(fit_linear)</span>
<span id="cb7-164"></span>
<span id="cb7-165"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-166"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 11. Interpret the linear time effect</span></span>
<span id="cb7-167"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-168">beta_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;">fixef</span>(fit_linear)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>cond[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"visit"</span>]</span>
<span id="cb7-169">rr_per_visit <span class="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>(beta_hat)</span>
<span id="cb7-170"></span>
<span id="cb7-171"><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;">Linear time model:</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-172"><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;">"Estimated log-rate ratio per visit:"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(beta_hat, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</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-173"><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;">"Estimated rate ratio per visit:"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(rr_per_visit, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</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-174"><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;">"Estimated percent change per visit:"</span>,</span>
<span id="cb7-175">    <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="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> rr_per_visit) <span 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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</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="cb7-176"></span>
<span id="cb7-177"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-178"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 12. Fit a spline-time NB mixed model</span></span>
<span id="cb7-179"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-180"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This allows the time trend to be nonlinear and more flexible.</span></span>
<span id="cb7-181">fit_spline <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glmmTMB</span>(</span>
<span id="cb7-182">  count <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ns</span>(visit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</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> log_baseline <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">offset</span>(offset_log) <span 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> id),</span>
<span id="cb7-183">  <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;">nbinom2</span>(),</span>
<span id="cb7-184">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat</span>
<span id="cb7-185">)</span>
<span id="cb7-186"></span>
<span id="cb7-187"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(fit_spline)</span>
<span id="cb7-188"></span>
<span id="cb7-189"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Important:</span></span>
<span id="cb7-190"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># The spline coefficients themselves are not directly interpretable.</span></span>
<span id="cb7-191"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Interpretation should focus on predicted means / fitted trajectory</span></span>
<span id="cb7-192"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># or contrasts between selected post-baseline visits.</span></span>
<span id="cb7-193"></span>
<span id="cb7-194"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-195"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 13. Obtain model-based predictions over time</span></span>
<span id="cb7-196"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-197"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Predict at the average baseline level and a standard 28-day period</span></span>
<span id="cb7-198">newdat <span class="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="cb7-199">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">visit =</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>, <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;">by =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),</span>
<span id="cb7-200">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">log_baseline =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>log_baseline),</span>
<span id="cb7-201">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">offset_log =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,     <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ie, exposure_days=28, corresponding to a standard 28-day period</span></span>
<span id="cb7-202">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span></span>
<span id="cb7-203">)</span>
<span id="cb7-204"></span>
<span id="cb7-205">newdat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pred_linear <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">predict</span>(</span>
<span id="cb7-206">  fit_linear,</span>
<span id="cb7-207">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">newdata =</span> newdat,</span>
<span id="cb7-208">  <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;">"response"</span>,</span>
<span id="cb7-209">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">re.form =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># marginal prediction: no subject-specific random effect</span></span>
<span id="cb7-210">)</span>
<span id="cb7-211"></span>
<span id="cb7-212">newdat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pred_spline <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">predict</span>(</span>
<span id="cb7-213">  fit_spline,</span>
<span id="cb7-214">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">newdata =</span> newdat,</span>
<span id="cb7-215">  <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;">"response"</span>,</span>
<span id="cb7-216">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">re.form =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span></span>
<span id="cb7-217">)</span>
<span id="cb7-218"></span>
<span id="cb7-219"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-220"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 14. Summarize observed mean counts by visit</span></span>
<span id="cb7-221"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb7-222">obs_summary <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-223">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(visit) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-224">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb7-225">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_count =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(count),</span>
<span id="cb7-226">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">median_count =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(count),</span>
<span id="cb7-227">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span></span>
<span id="cb7-228">  )</span>
<span id="cb7-229"></span>
<span id="cb7-230"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(obs_summary)</span></code></pre></div>
</details>
</div>
<p><strong>True time effects used in the simulation (relative to visit 1):</strong></p>
<ul>
<li><p>visit 1: reference (no change)</p></li>
<li><p>visit 2: 5% reduction</p></li>
<li><p>visit 3: 10% reduction</p></li>
<li><p>visit 4: 25% reduction</p></li>
<li><p>visit 5: plateau (same as visit 4)</p></li>
<li><p>visit 6: 40% reduction</p></li>
</ul>
<p><strong>Below is a snippet of the simulated longitudinal dataset for the first subject:</strong></p>
<div class="cell">
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 3%">
<col style="width: 6%">
<col style="width: 11%">
<col style="width: 11%">
<col style="width: 13%">
<col style="width: 14%">
<col style="width: 11%">
<col style="width: 9%">
<col style="width: 10%">
<col style="width: 6%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: center;">id</th>
<th style="text-align: center;">visit</th>
<th style="text-align: center;">baseline28</th>
<th style="text-align: center;">b_i</th>
<th style="text-align: center;">log_baseline</th>
<th style="text-align: center;">exposure_days</th>
<th style="text-align: center;">offset_log</th>
<th style="text-align: center;">eta</th>
<th style="text-align: center;">mu</th>
<th style="text-align: center;">count</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;">1</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-0.0732203</td>
<td style="text-align: center;">1.098612</td>
<td style="text-align: center;">35</td>
<td style="text-align: center;">0.2231436</td>
<td style="text-align: center;">2.326197</td>
<td style="text-align: center;">10.238929</td>
<td style="text-align: center;">11</td>
</tr>
<tr class="even">
<td style="text-align: center;">1</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-0.0732203</td>
<td style="text-align: center;">1.098612</td>
<td style="text-align: center;">35</td>
<td style="text-align: center;">0.2231436</td>
<td style="text-align: center;">2.274904</td>
<td style="text-align: center;">9.726982</td>
<td style="text-align: center;">41</td>
</tr>
<tr class="odd">
<td style="text-align: center;">1</td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-0.0732203</td>
<td style="text-align: center;">1.098612</td>
<td style="text-align: center;">35</td>
<td style="text-align: center;">0.2231436</td>
<td style="text-align: center;">2.220836</td>
<td style="text-align: center;">9.215036</td>
<td style="text-align: center;">7</td>
</tr>
<tr class="even">
<td style="text-align: center;">1</td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-0.0732203</td>
<td style="text-align: center;">1.098612</td>
<td style="text-align: center;">28</td>
<td style="text-align: center;">0.0000000</td>
<td style="text-align: center;">1.815371</td>
<td style="text-align: center;">6.143357</td>
<td style="text-align: center;">11</td>
</tr>
<tr class="odd">
<td style="text-align: center;">1</td>
<td style="text-align: center;">5</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-0.0732203</td>
<td style="text-align: center;">1.098612</td>
<td style="text-align: center;">28</td>
<td style="text-align: center;">0.0000000</td>
<td style="text-align: center;">1.815371</td>
<td style="text-align: center;">6.143357</td>
<td style="text-align: center;">2</td>
</tr>
<tr class="even">
<td style="text-align: center;">1</td>
<td style="text-align: center;">6</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-0.0732203</td>
<td style="text-align: center;">1.098612</td>
<td style="text-align: center;">35</td>
<td style="text-align: center;">0.2231436</td>
<td style="text-align: center;">1.815371</td>
<td style="text-align: center;">6.143357</td>
<td style="text-align: center;">7</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>Each row corresponds to a visit for a given subject. The dataset includes visit, baseline seizure count (baseline28), subject-specific random effects (<img src="https://latex.codecogs.com/png.latex?b_i">), the log-transformed baseline seizure count (log_baseline = <img src="https://latex.codecogs.com/png.latex?%5Clog(%5Ctext%7Bbaseline28%7D%20+%201)">), observation duration (exposure_days), its log-transformed value used as an offset (offset_log), the linear predictor (<img src="https://latex.codecogs.com/png.latex?%5Ceta">, representing the log of the expected count), the expected count (<img src="https://latex.codecogs.com/png.latex?%5Cmu">), and the observed seizure count.</p>
<p><strong>Interpretation of plot:</strong></p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<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;"># -----------------------------</span></span>
<span id="cb8-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 15. Plot observed means and fitted trajectories</span></span>
<span id="cb8-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb8-4"></span>
<span id="cb8-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Model predictions in long format</span></span>
<span id="cb8-6">plot_pred <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> newdat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(visit, pred_linear, pred_spline) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-8">  tidyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(</span>
<span id="cb8-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cols =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(pred_linear, pred_spline),</span>
<span id="cb8-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"series"</span>,</span>
<span id="cb8-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value"</span></span>
<span id="cb8-12">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb8-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">series =</span> dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(</span>
<span id="cb8-15">      series,</span>
<span id="cb8-16">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pred_linear =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Linear model"</span>,</span>
<span id="cb8-17">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pred_spline =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spline model"</span></span>
<span id="cb8-18">    )</span>
<span id="cb8-19">  )</span>
<span id="cb8-20"></span>
<span id="cb8-21"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Observed means</span></span>
<span id="cb8-22">plot_obs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> obs_summary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb8-24">    visit,</span>
<span id="cb8-25">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> mean_count,</span>
<span id="cb8-26">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">series =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Observed"</span></span>
<span id="cb8-27">  )</span>
<span id="cb8-28"></span>
<span id="cb8-29"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Combine all series</span></span>
<span id="cb8-30">plot_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;">bind_rows</span>(plot_obs, plot_pred)</span>
<span id="cb8-31"></span>
<span id="cb8-32">plot_all<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>series <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(</span>
<span id="cb8-33">  plot_all<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>series,</span>
<span id="cb8-34">  <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Observed"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Linear model"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spline model"</span>)</span>
<span id="cb8-35">)</span>
<span id="cb8-36"></span>
<span id="cb8-37"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(plot_all, <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> visit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> value,</span>
<span id="cb8-38">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> series,</span>
<span id="cb8-39">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape =</span> series,</span>
<span id="cb8-40">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> series)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="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="cb8-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(</span>
<span id="cb8-44">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb8-45">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Observed"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>,</span>
<span id="cb8-46">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Linear model"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>,</span>
<span id="cb8-47">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spline model"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span></span>
<span id="cb8-48">    )</span>
<span id="cb8-49">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_shape_manual</span>(</span>
<span id="cb8-51">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb8-52">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Observed"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>,       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># circle</span></span>
<span id="cb8-53">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Linear model"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span>,   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># triangle</span></span>
<span id="cb8-54">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spline model"</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;">NA</span></span>
<span id="cb8-55">    )</span>
<span id="cb8-56">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-57">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_linetype_manual</span>(</span>
<span id="cb8-58">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb8-59">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Observed"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"solid"</span>,</span>
<span id="cb8-60">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Linear model"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"solid"</span>,</span>
<span id="cb8-61">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Spline model"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"solid"</span></span>
<span id="cb8-62">    )</span>
<span id="cb8-63">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-64">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(</span>
<span id="cb8-65">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(</span>
<span id="cb8-66">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">override.aes =</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;">shape =</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;">16</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">17</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>))</span>
<span id="cb8-67">    )</span>
<span id="cb8-68">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-69">  <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;">color =</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;">shape =</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;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-70">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>()</span></code></pre></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://trialnotes.org/posts/one_arm/index_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<ul>
<li><p>black line with circles = observed mean count at each visit</p></li>
<li><p>blue line with triangles = linear-time NB model</p></li>
<li><p>red line = spline-time NB model</p></li>
</ul>
<p>The model-based predictions are slightly lower than the observed means because they represent the expected outcome for a typical subject (with average covariates and no subject-specific random effect), whereas the observed means average over heterogeneous subjects. As a result, differences between model-based predictions and raw means are expected and do not indicate poor model fit; the key comparison here is the trajectory over time rather than matching the raw means exactly.</p>
<p><strong>Interpreting time effects across models:</strong></p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<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;"># -----------------------------</span></span>
<span id="cb9-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 16. Example contrasts between post-baseline visits</span></span>
<span id="cb9-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb9-4"></span>
<span id="cb9-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># For the spline model, compare predicted rates at selected visits.</span></span>
<span id="cb9-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># These are model-based comparisons across time points,</span></span>
<span id="cb9-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># conditional on baseline covariate being held fixed.</span></span>
<span id="cb9-8"></span>
<span id="cb9-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create dataset for selected visits</span></span>
<span id="cb9-10">contrast_dat <span class="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="cb9-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">visit =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">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 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;">6</span>),   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># &lt;-- include all visits if you want all contrasts</span></span>
<span id="cb9-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">log_baseline =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>log_baseline),</span>
<span id="cb9-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">offset_log =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb9-14">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span></span>
<span id="cb9-15">)</span>
<span id="cb9-16"></span>
<span id="cb9-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Get linear predictors (log scale)</span></span>
<span id="cb9-18">lp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">predict</span>(</span>
<span id="cb9-19">  fit_spline,</span>
<span id="cb9-20">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">newdata =</span> contrast_dat,</span>
<span id="cb9-21">  <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;">"link"</span>,</span>
<span id="cb9-22">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">re.form =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span></span>
<span id="cb9-23">)</span>
<span id="cb9-24"></span>
<span id="cb9-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Compute rate ratios</span></span>
<span id="cb9-26">rr_2_vs_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;">exp</span>(lp[<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> lp[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb9-27">rr_3_vs_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;">exp</span>(lp[<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> lp[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb9-28">rr_4_vs_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;">exp</span>(lp[<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> lp[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb9-29">rr_5_vs_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;">exp</span>(lp[<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> lp[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb9-30">rr_6_vs_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;">exp</span>(lp[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> lp[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb9-31"></span>
<span id="cb9-32">rr_4_vs_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;">exp</span>(lp[<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> lp[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb9-33">rr_6_vs_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;">exp</span>(lp[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> lp[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>])</span>
<span id="cb9-34"></span>
<span id="cb9-35"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cat("\nSpline model contrasts:\n")</span></span>
<span id="cb9-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cat("Visit 2 vs Visit 1 rate ratio:", round(rr_2_vs_1, 3), "\n")</span></span>
<span id="cb9-37"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cat("Visit 3 vs Visit 1 rate ratio:", round(rr_3_vs_1, 3), "\n")</span></span>
<span id="cb9-38"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cat("Visit 4 vs Visit 1 rate ratio:", round(rr_4_vs_1, 3), "\n")</span></span>
<span id="cb9-39"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cat("Visit 5 vs Visit 1 rate ratio:", round(rr_5_vs_1, 3), "\n")</span></span>
<span id="cb9-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cat("Visit 6 vs Visit 1 rate ratio:", round(rr_6_vs_1, 3), "\n")</span></span>
<span id="cb9-41"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># </span></span>
<span id="cb9-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cat("Visit 4 vs Visit 2 rate ratio:", round(rr_4_vs_2, 3), "\n")</span></span>
<span id="cb9-43"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cat("Visit 6 vs Visit 4 rate ratio:", round(rr_6_vs_4, 3), "\n")</span></span>
<span id="cb9-44"></span>
<span id="cb9-45"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># These contrasts illustrate how the implied time effect can vary</span></span>
<span id="cb9-46"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># across different parts of follow-up when time is modeled flexibly.</span></span>
<span id="cb9-47"></span>
<span id="cb9-48"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb9-49"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 17. Summarize true vs estimated effects</span></span>
<span id="cb9-50"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -----------------------------</span></span>
<span id="cb9-51"></span>
<span id="cb9-52"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># --- 1. True effects (relative to visit 1) ---</span></span>
<span id="cb9-53">true_rr <span class="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>(true_time_effect)</span>
<span id="cb9-54"></span>
<span id="cb9-55">true_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="cb9-56">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">visit =</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;">names</span>(true_rr)),</span>
<span id="cb9-57">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_rr_vs_v1 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(true_rr)</span>
<span id="cb9-58">)</span>
<span id="cb9-59"></span>
<span id="cb9-60"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># --- 2. Linear model estimate ---</span></span>
<span id="cb9-61">beta_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;">fixef</span>(fit_linear)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>cond[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"visit"</span>]</span>
<span id="cb9-62">rr_linear <span class="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>(beta_hat)</span>
<span id="cb9-63"></span>
<span id="cb9-64"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Linear model implies cumulative effect per visit relative to visit 1</span></span>
<span id="cb9-65">linear_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="cb9-66">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">visit =</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>
<span id="cb9-67">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linear_rr_vs_v1 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(beta_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 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="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="cb9-68">)</span>
<span id="cb9-69"></span>
<span id="cb9-70"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># --- 3. Spline model estimates ---</span></span>
<span id="cb9-71">contrast_dat <span class="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="cb9-72">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">visit =</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>
<span id="cb9-73">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">log_baseline =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>log_baseline),</span>
<span id="cb9-74">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">offset_log =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb9-75">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span></span>
<span id="cb9-76">)</span>
<span id="cb9-77"></span>
<span id="cb9-78">lp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">predict</span>(</span>
<span id="cb9-79">  fit_spline,</span>
<span id="cb9-80">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">newdata =</span> contrast_dat,</span>
<span id="cb9-81">  <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;">"link"</span>,</span>
<span id="cb9-82">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">re.form =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span></span>
<span id="cb9-83">)</span>
<span id="cb9-84"></span>
<span id="cb9-85">spline_rr <span class="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>(lp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> lp[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb9-86"></span>
<span id="cb9-87">spline_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="cb9-88">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">visit =</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>
<span id="cb9-89">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spline_rr_vs_v1 =</span> spline_rr</span>
<span id="cb9-90">)</span>
<span id="cb9-91"></span>
<span id="cb9-92"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># --- Combine all ---</span></span>
<span id="cb9-93">summary_table <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> true_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-94">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(linear_df, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"visit"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-95">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(spline_df, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"visit"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-96">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb9-97">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_rr =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(true_rr_vs_v1, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb9-98">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linear_rr =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(linear_rr_vs_v1, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb9-99">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spline_rr =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(spline_rr_vs_v1, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb9-100"></span>
<span id="cb9-101">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_pct =</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="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> true_rr) <span 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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb9-102">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linear_pct =</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="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> linear_rr) <span 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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb9-103">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spline_pct =</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="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> spline_rr) <span 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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb9-104"></span>
<span id="cb9-105">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">True RR (% reduction)</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;">paste0</span>(true_rr, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" ("</span>, true_pct, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%)"</span>),</span>
<span id="cb9-106">    <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;">Linear model RR (% reduction)</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;">paste0</span>(linear_rr, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" ("</span>, linear_pct, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%)"</span>),</span>
<span id="cb9-107">    <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;">Spline model RR (% reduction)</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;">paste0</span>(spline_rr, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" ("</span>, spline_pct, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%)"</span>)</span>
<span id="cb9-108">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-109">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(</span>
<span id="cb9-110">    <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;">Visit</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> visit,</span>
<span id="cb9-111">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">True RR (% reduction)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb9-112">    <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;">Linear model RR (% reduction)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,</span>
<span id="cb9-113">    <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;">Spline model RR (% reduction)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb9-114">  )</span>
<span id="cb9-115"></span>
<span id="cb9-116">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(summary_table, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">align =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"c"</span>)</span></code></pre></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 7%">
<col style="width: 25%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: center;">Visit</th>
<th style="text-align: center;">True RR (% reduction)</th>
<th style="text-align: center;">Linear model RR (% reduction)</th>
<th style="text-align: center;">Spline model RR (% reduction)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;">1</td>
<td style="text-align: center;">1 (0%)</td>
<td style="text-align: center;">1 (0%)</td>
<td style="text-align: center;">1 (0%)</td>
</tr>
<tr class="even">
<td style="text-align: center;">2</td>
<td style="text-align: center;">0.95 (-5%)</td>
<td style="text-align: center;">0.899 (-10.1%)</td>
<td style="text-align: center;">0.981 (-1.9%)</td>
</tr>
<tr class="odd">
<td style="text-align: center;">3</td>
<td style="text-align: center;">0.9 (-10%)</td>
<td style="text-align: center;">0.809 (-19.1%)</td>
<td style="text-align: center;">0.863 (-13.7%)</td>
</tr>
<tr class="even">
<td style="text-align: center;">4</td>
<td style="text-align: center;">0.75 (-25%)</td>
<td style="text-align: center;">0.728 (-27.2%)</td>
<td style="text-align: center;">0.753 (-24.7%)</td>
</tr>
<tr class="odd">
<td style="text-align: center;">5</td>
<td style="text-align: center;">0.75 (-25%)</td>
<td style="text-align: center;">0.655 (-34.5%)</td>
<td style="text-align: center;">0.682 (-31.8%)</td>
</tr>
<tr class="even">
<td style="text-align: center;">6</td>
<td style="text-align: center;">0.6 (-40%)</td>
<td style="text-align: center;">0.589 (-41.1%)</td>
<td style="text-align: center;">0.608 (-39.2%)</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The above table shows the <strong>rate ratio (% reduction)</strong> for each post-baseline visit relative to the first post-baseline visit. The linear time model assumes a constant rate ratio per visit (i.e., a constant multiplicative change between <strong>consecutive</strong> visits). However, when comparing each visit to the first post-baseline visit, these effects accumulate over time, resulting in different rate ratios at later visits (i.e., RR for visit 3 relative to visit 1 is <img src="https://latex.codecogs.com/png.latex?0.8994%5E%7B2%7D%20%5Capprox%200.728">). Thus, while the per-visit effect is constant, the cumulative effect relative to visit 1 is not.</p>
<p>Because this is a single simulated dataset, the estimated effects are not expected to recover the true visit-specific effects exactly. The purpose here is to illustrate how different model specifications capture the longitudinal trajectory.</p>
<p>The two models capture the trajectory differently. The linear time model imposes a constant multiplicative change per visit, which accumulates over time and leads to increasingly large reductions at later visits. As a result, it <strong>overestimates % reduction when the true effect plateaus</strong> (e.g., visits 4–5).</p>
<p>In contrast, the spline model allows the trajectory to vary over time and better reflects the <strong>nonlinear pattern</strong> in the data, including smaller reductions at earlier visits and a subsequent plateau. While it does not recover the true visit-specific rate ratios exactly in this single simulated dataset, it provides a more flexible and realistic representation of the underlying trajectory.</p>
</section>
<section id="what-this-approach-estimates" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="what-this-approach-estimates">What this approach estimates</h2>
<p>This framework provides a more principled way to evaluate longitudinal seizure rate trajectory in single-arm studies:</p>

<div class="no-row-height column-margin column-container"><div class="">
<p><strong>What is a causal effect?</strong></p>
<p>A causal effect is defined as the contrast between two potential outcomes for the same individual:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AY(1)%20-%20Y(0)%0A"></p>
<p>where:</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?Y(1)"> is the outcome under treatment<br>
</li>
<li><img src="https://latex.codecogs.com/png.latex?Y(0)"> is the outcome under control</li>
</ul>
<p>Because both potential outcomes cannot be observed for the same individual, causal effects cannot be directly measured. In a randomized trial, randomization allows unbiased estimation of the <strong>average causal effect</strong> by comparing outcomes between groups:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AE%5BY(1)%20-%20Y(0)%5D%0A"></p>
<p>Apparent improvement measured as changes from baseline within a single arm may reflect natural fluctuations, regression to the mean, or other time effects, and does not identify a causal effect because it does not compare observed outcomes to the unobserved counterfactual.</p>
</div></div><ul>
<li><p>uses all available data</p></li>
<li><p>respects the count nature of the outcome</p></li>
<li><p>incorporates baseline appropriately</p></li>
<li><p>allows flexible modelling of time</p></li>
</ul>
<p>The model estimates how seizure rates evolve over time after treatment initiation.</p>
<p>However, it does not estimate a causal treatment effect defined as the contrast between two potential outcomes (see margin notes). In certain settings, such as rare diseases or areas of high unmet need, regulatory decisions may still rely on single-arm studies as supportive of efficacy when interpreted in the context of external evidence (e.g., natural history or historical controls). In these cases, the observed trajectory is used as part of a broader evidentiary framework rather than as a standalone estimate of causal effect.</p>
</section>
<section id="takeaway" class="level2">
<h2 class="anchored" data-anchor-id="takeaway">Takeaway</h2>
<p>In single-arm settings, changes from baseline (including PCFB and responder rates which are derived from PCFB) do not identify a treatment effect, as they conflate natural fluctuations, regression to the mean, or other time effects with treatment.</p>
<p>A longitudinal negative binomial model provides a more principled way to evaluate post-baseline trajectories by using all available data and accounting for baseline differences and within-subject variability. Importantly, how time is modelled matters. A linear time effect imposes a constant multiplicative change per visit, which can be overly restrictive and may misrepresent the underlying trajectory. Flexible approaches, such as splines, allow the data to inform how the post-baseline trajectory evolves over time. These models should be viewed as tools for describing longitudinal patterns, using time as a proxy for treatment exposure rather than establishing a causal treatment effect.</p>
</section>
<section id="references-1" class="level2">
<h2 class="anchored" data-anchor-id="references-1">References</h2>
<p>Hernán, M. A., &amp; Robins, J. M. (2020). <em>Causal inference: What if.</em> Chapman &amp; Hall/CRC.</p>
<p>Holland, P. W. (1986). Statistics and causal inference. <em>Journal of the American Statistical Association, 81</em>(396), 945–960. <a href="https://doi.org/10.1080/01621459.1986.10478354" class="uri">https://doi.org/10.1080/01621459.1986.10478354</a></p>
<p>Rubin, D. B. (1974). Estimating causal effects of treatments in randomized and nonrandomized studies. <em>Journal of Educational Psychology, 66</em>(5), 688–701. <a href="https://doi.org/10.1037/h0037350" class="uri">https://doi.org/10.1037/h0037350</a></p>
<p>U.S. Food and Drug Administration. (2023). <em>Considerations for the design and conduct of externally controlled trials for drug and biological products (Draft Guidance).</em> <a href="https://www.fda.gov/media/164960/download" class="uri">https://www.fda.gov/media/164960/download</a></p>
<p>U.S. Food and Drug Administration. (2019). <em>Demonstrating substantial evidence of effectiveness for human drug and biological products (Draft Guidance).</em> <a href="https://www.fda.gov/media/133660/download" class="uri">https://www.fda.gov/media/133660/download</a></p>
<p>U.S. Food and Drug Administration. (2019). <em>Rare diseases: Natural history studies for drug development (Guidance for industry).</em> <a href="https://www.fda.gov/media/122425/download" class="uri">https://www.fda.gov/media/122425/download</a></p>


</section>

 ]]></description>
  <category>methodology</category>
  <category>modelling</category>
  <category>regression</category>
  <category>simulation</category>
  <category>trial design</category>
  <guid>https://trialnotes.org/posts/one_arm/</guid>
  <pubDate>Sat, 04 Apr 2026 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Power, Estimands, and Endpoint Choice in Seizure Trials</title>
  <dc:creator>Fei Zuo</dc:creator>
  <link>https://trialnotes.org/posts/estimand/</link>
  <description><![CDATA[ 




<p><strong>🎧 1-minute summary</strong></p>
<p><em>Narration generated using OpenAI.fm.</em></p>
<audio controls="" preload="none" style="width:320px; margin-bottom:14px;">
<source src="../../audio/estimand_small.mp3" type="audio/mpeg">
</audio>
<p>In many epilepsy clinical trials evaluating seizure frequency, the primary analysis is based on subject-level outcome measures such as:</p>

<div class="no-row-height column-margin column-container"><div class="">
<p><strong>What is an estimand</strong></p>
<p>An estimand precisely defines the treatment effect a clinical trial seeks to estimate. According to ICH E9(R1) (2019), an estimand includes:</p>
<ul>
<li>The target population<br>
</li>
<li>The treatment condition<br>
</li>
<li>The outcome variable<br>
</li>
<li>The handling of intercurrent events<br>
</li>
<li>The population-level summary measure (e.g., mean difference, rate ratio)</li>
</ul>
<p>It clarifies the scientific question before analysis begins.</p>
</div></div><ul>
<li><p>Percent change from baseline (PCFB), or</p></li>
<li><p>Responder status derived from achieving a ≥50% reduction in PCFB.</p></li>
</ul>
<p>Correspondingly, the sample size calculation is often derived from detecting:</p>
<ul>
<li><p>A <strong>difference in mean PCFB</strong> under normal-theory assumptions, or or a <strong>shift in the distribution of PCFB</strong> using a rank-based nonparametric test (e.g., the Wilcoxon rank-sum test).</p>
<ul>
<li>The latter is frequently described as powering for a “median difference,” although the Wilcoxon test does not, in general, test equality of medians — a distinction we will revisit.</li>
</ul></li>
<li><p>A <strong>difference in responder proportions</strong> (using binomial assumptions).</p></li>
</ul>
<p>The above looks standard but they are conceptually disconnected from the estimand the trial is supposed to target.</p>
<section id="what-is-the-underlying-outcome" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="what-is-the-underlying-outcome">What is the underlying outcome?</h2>
<p>In epilepsy trials, what we observe are <strong>seizure counts</strong> reported over specified time intervals:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AY_i%5E%7B%5Ctext%7Bbase%7D%7D,%20%5Cquad%20Y_i%5E%7B%5Ctext%7Bpost%7D%7D%0A"></p>
<p>Seizures are:</p>
<ul>
<li><p>Nonnegative integers</p></li>
<li><p>Heterogeneous across patients</p></li>
<li><p>Overdispersed</p></li>
<li><p>Often approximately negative binomial</p></li>
</ul>
<p>In a parallel-group randomized trial, the natural causal estimand is defined on the count scale, typically as a <strong>rate ratio</strong> representing a <em>multiplicative</em> change in seizure frequency.</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BRate%20ratio%7D%0A=%0A%5Cfrac%7BE%5C!%5Cleft%5BY%5E%7B%5Ctext%7Bpost%7D%7D(1)%5Cright%5D%7D%0A%20%20%20%20%20%7BE%5C!%5Cleft%5BY%5E%7B%5Ctext%7Bpost%7D%7D(0)%5Cright%5D%7D%0A"></p>

<div class="no-row-height column-margin column-container"><div class="">
<p><strong>Estimand (ICH E9(R1))</strong></p>
<p>In ICH E9(R1) terms, this specifies the treatment effect through the <strong>outcome</strong> (post-treatment seizure counts) and the <strong>summary measure</strong> (a rate ratio), producing a <strong>population-level causal contrast</strong> on the count scale.</p>
</div></div><p>This answers:</p>
<blockquote class="blockquote">
<p><strong>How does seizure frequency compare between treatment and control?</strong></p>
</blockquote>
<p>Modeling treatment as acting on the event rate reflects both the biological mechanism and the stochastic structure of the data.</p>

<div class="no-row-height column-margin column-container"><div class="">
<p><strong>Stochastic structure</strong></p>
<p>“Stochastic” refers to the probabilistic pattern of variability in the data.<br>
Seizure counts are discrete events whose variability depends on the underlying event rate and differs across patients. Count models respect this mean–variance relationship; transformed endpoints such as percent change or responder status do not.</p>
</div></div><p>So what happens when we change the outcome scale?</p>
<p>Instead of modeling counts directly, many trials analyze transformations of these counts.</p>
<p><strong>The moment we change the outcome scale, we change the estimand even if the raw data are the same.</strong></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">
Why a rate ratio?
</div>
</div>
<div class="callout-body-container callout-body">
<p>Seizures are recurrent events occurring over time. Treatment plausibly acts by modifying the underlying event rate, leading to proportional (multiplicative) changes rather than fixed absolute shifts.</p>
<p>Clinically, seizure studies are already described this way (e.g., a 30% reduction, a 50% reduction). A rate ratio formalizes that proportional interpretation directly on the count scale.</p>
</div>
</div>
</section>
<section id="powering-on-percent-change-from-baseline-pcfb" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="powering-on-percent-change-from-baseline-pcfb">Powering on percent change from baseline (PCFB)</h2>
<p>PCFB is defined as:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7BY%5E%7B%5Ctext%7Bpost%7D%7D%20-%20Y%5E%7B%5Ctext%7Bbase%7D%7D%7D%0A%20%20%20%20%20%7BY%5E%7B%5Ctext%7Bbase%7D%7D%7D%0A"></p>
<p>This is:</p>
<ul>
<li><p>A nonlinear transformation</p></li>
<li><p>A ratio of two random variables</p></li>
<li><p>Baseline-dependent</p></li>
<li><p>Highly heteroskedastic</p></li>
<li><p>Asymmetric</p></li>
</ul>

<div class="no-row-height column-margin column-container"><div class="">
<p><strong>Heteroskedasticity (linear regression)</strong></p>
<p>The classical linear model assumes homoskedasticity (i.e., constant error variance): <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BVar%7D(%5Cvarepsilon_i%20%5Cmid%20X_i)=%5Csigma%5E2">.</p>
<p>Heteroskedasticity means the variance depends on <img src="https://latex.codecogs.com/png.latex?X">: <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BVar%7D(%5Cvarepsilon_i%20%5Cmid%20X_i)=%5Csigma_i%5E2">.</p>
<p>Estimated coefficients remain unbiased (if the mean model is correct), but standard errors can be wrong, leading to invalid confidence intervals and p-values.</p>
</div><div class="">
<p><strong>PCFB and heteroskedasticity</strong></p>
<p>PCFB is a ratio with baseline in the denominator.<br>
When baseline is small, small absolute changes produce large percent changes.</p>
<p>The resulting variability depends on baseline level.<br>
Power calculations that assume a constant variance on the percent-change scale therefore misrepresent the true variability of the endpoint.</p>
</div></div>
<p>Yet sample size calculations typically assume:</p>
<ul>
<li><p>Approximate normality (or large-sample symmetry)</p></li>
<li><p>Homoskedasticity</p></li>
<li><p>Additive effects on the percent-change scale</p></li>
<li><p>A well-defined mean percent change (i.e., not dominated by baseline-dependent instability, extreme values, or denominator sensitivity)</p></li>
</ul>
<p>None of these assumptions are satisfied for the PCFB endpoint.</p>
<section id="the-estimand-under-pcfb" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="the-estimand-under-pcfb">The estimand under PCFB</h3>
<p>When PCFB is analyzed, the estimand becomes:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5CDelta_%7B%5Ctext%7BPCFB%7D%7D%0A=%0AE%5C!%5Cleft%5B%0A%5Cfrac%7BY_i%5E%7B%5Ctext%7Bpost%7D%7D%20-%20Y_i%5E%7B%5Ctext%7Bbase%7D%7D%7D%0A%20%20%20%20%20%7BY_i%5E%7B%5Ctext%7Bbase%7D%7D%7D%0A%5C;%5Cmiddle%7C%5C;%20A_i%20=%201%0A%5Cright%5D%0A-%0AE%5C!%5Cleft%5B%0A%5Cfrac%7BY_i%5E%7B%5Ctext%7Bpost%7D%7D%20-%20Y_i%5E%7B%5Ctext%7Bbase%7D%7D%7D%0A%20%20%20%20%20%7BY_i%5E%7B%5Ctext%7Bbase%7D%7D%7D%0A%5C;%5Cmiddle%7C%5C;%20A_i%20=%200%0A%5Cright%5D%0A"></p>

<div class="no-row-height column-margin column-container"><div class="">
<p><strong>Treatment indicator</strong></p>
<p>(A_i = 1) denotes assignment to treatment and (A_i = 0) denotes control.</p>
</div></div><p>This answers:</p>
<blockquote class="blockquote">
<p><strong>Did average percent change differ between groups?</strong></p>
</blockquote>
<p>That is a different question from:</p>
<blockquote class="blockquote">
<p><strong>By what proportion did treatment change seizure frequency relative to control?</strong></p>
</blockquote>
<p>The former targets the mean of a ratio-based transformation. The latter targets the seizure process itself.</p>
<p>Once PCFB is chosen as the outcome scale, the trial <strong>no longer estimates a treatment effect on seizure counts or seizure frequency</strong>. It estimates a difference in average percent change, a quantity that:</p>
<ul>
<li><p>Depends heavily on baseline values</p></li>
<li><p>Is unstable at low baseline values</p></li>
<li><p>Embeds regression to the mean</p></li>
<li><p>Distorts variability due to asymmetric bounds</p></li>
<li><p>Discards information on the absolute scale by equating biologically distinct count reductions</p></li>
</ul>
<p>For example:</p>
<ul>
<li><p>Going from 200 → 100 seizures</p></li>
<li><p>Going from 10 → 5 seizures</p></li>
</ul>
<p>Both yield:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%7B%5Ctext%7Bpost%7D%7D%20-%20%7B%5Ctext%7Bbaseline%7D%7D%7D%0A%20%20%20%20%20%7B%7B%5Ctext%7Bbaseline%7D%7D%7D%20=%20-50%5C%25%0A"></p>
<p>But the clinical burden is clearly different.</p>
<p>The PCFB transformation collapses distinct biological realities into identical summary values.</p>
</section>
<section id="the-asymmetry-problem" class="level3">
<h3 class="anchored" data-anchor-id="the-asymmetry-problem">The asymmetry problem</h3>
<p>Percent decrease is bounded:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A-100%5C%25%20%5Cle%20%5Ctext%7BPCFB%7D%20%3C%20%5Cinfty%0A"></p>
<p>You cannot reduce seizures by more than 100%, but increases are unbounded. The scale is inherently asymmetric:</p>
<ul>
<li><p>50 → 5 = -90%</p></li>
<li><p>5 → 50 = +900%</p></li>
<li><p>100 → 5 = −95%</p></li>
<li><p>5 → 100 = +1900%</p></li>
</ul>
<p>This means:</p>
<ul>
<li><p>Large increases can dominate averages.</p></li>
<li><p>Variance behaves very differently in the increasing direction.</p></li>
<li><p>The scale does not reflect biological symmetry.</p></li>
<li><p>The PCFB value depends heavily on baseline level but baseline can no longer be meaningfully adjusted for in a regression model. This will be demonstrated in a subsequent simulation post.</p></li>
</ul>
<p>The asymmetry arises from the transformation, not from seizure biology.</p>
<p><strong>Converting counts to PCFB distorts the variance structure and discards information contained in the original data.</strong></p>
<div class="callout callout-style-default callout-note callout-titled" title="Subject-level percent change ≠ proportional rate reduction">
<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">
Subject-level percent change ≠ proportional rate reduction
</div>
</div>
<div class="callout-body-container callout-body">
<p>A treatment contrast defined on percent change from baseline is not equivalent to a proportional change in the group-level event rate.</p>
<p>A rate ratio compares mean seizure frequencies between groups. PCFB averages subject-specific ratios, which weight patients differently depending on baseline and do not, in general, recover the proportional (multiplicative) effect on the underlying event rate.</p>
</div>
</div>
</section>
</section>
<section id="does-analyzing-the-median-rescue-pcfb" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="does-analyzing-the-median-rescue-pcfb">Does analyzing the median rescue PCFB?</h2>
<p>A common response is:</p>
<blockquote class="blockquote">
<p><strong>“Then analyze the median percent change instead.”</strong></p>
</blockquote>
<p>This does not resolve the fundamental issues.</p>
<p>Even when focusing on the median, the estimand remains defined on the PCFB scale. The question simply becomes:</p>
<blockquote class="blockquote">
<p><strong>Did the median percent change differ between groups?</strong></p>
</blockquote>
<p>This is still:</p>
<ul>
<li><p>A nonlinear ratio</p></li>
<li><p>Baseline-dependent</p></li>
<li><p>Asymmetric</p></li>
<li><p>Heteroskedastic</p></li>
</ul>
<p>Switching from mean to median does not repair the scale distortion.</p>
<p><strong>The estimand remains disconnected from the underlying seizure count process.</strong></p>
<section id="wilcoxon-does-not-test-equality-of-medians" class="level3">
<h3 class="anchored" data-anchor-id="wilcoxon-does-not-test-equality-of-medians">Wilcoxon does not test equality of medians</h3>
<p>In practice, “median PCFB analysis” often uses the Wilcoxon rank-sum test.</p>
<p>But the Wilcoxon test does not, in general, test equality of medians. It tests a shift in distributions — more precisely, it evaluates the probability that a randomly selected patient from the treatment group has a better outcome than a randomly selected patient from the control group:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AP(Z_1%20%3E%20Z_0)%0A+%0A%5Cfrac%7B1%7D%7B2%7D%20P(Z_1%20=%20Z_0)%0A=%0A%5Cfrac%7B1%7D%7B2%7D%0A"></p>
<p>Only under strong conditions (e.g., identical shapes with pure location shift) does this correspond to a median difference.</p>
<p>Those conditions are unlikely to hold for PCFB because:</p>
<ul>
<li><p>PCFB is skewed</p></li>
<li><p>It is bounded below at −100%</p></li>
<li><p>It is unbounded above</p></li>
<li><p>Its variance depends on baseline</p></li>
</ul>
<p>So describing a Wilcoxon-powered trial as being powered for a “median difference” is generally incorrect.</p>
</section>
<section id="hodgeslehmann-is-not-a-median-difference-either" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="hodgeslehmann-is-not-a-median-difference-either">Hodges–Lehmann is not a median difference either</h3>
<p>The Hodges–Lehmann estimator is often described as estimating a “median difference.”</p>

<div class="no-row-height column-margin column-container"><div class="">
<p><strong>Notation</strong></p>
<p>(Z_{1i}), (Z_{0j}): individual outcomes for subjects in the treatment and control groups.</p>
<p>(Z_1), (Z_0): the corresponding group-level outcome distributions (random variables).</p>
<p>The difference in medians subtracts the 50th percentile of each group’s distribution, whereas the Hodges–Lehmann estimator takes the median of all cross-group pairwise differences.</p>
</div></div><p>In fact, it estimates the <strong>median of all pairwise differences</strong>:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Coperatorname%7BMedian%7D_%7Bi,j%7D%5Cbigl(Z_%7B1i%7D%20-%20Z_%7B0j%7D%5Cbigr)%0A"> That is <strong>not</strong> the same as <strong>the difference in marginal medians</strong>:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Coperatorname%7BMedian%7D(Z_1)%20-%20%5Coperatorname%7BMedian%7D(Z_0)%0A"></p>
<p>These are only equal under special symmetry conditions.</p>
<p>Again, PCFB generally does not satisfy those conditions.</p>
</section>
<section id="what-about-ranked-ancova" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="what-about-ranked-ancova">What about ranked ANCOVA?</h3>
<p>Ranked ANCOVA replaces PCFB with its overall ranks and fits a standard linear model.</p>
<p>Under the null, it tests whether treatment shifts the <strong>adjusted rank distribution</strong> of PCFB. This may appear attractive as it allows baseline adjustment and avoids normality assumptions. But it does not fix the core issue.</p>
<p>The resulting estimand targets a shift in the ranked percent changes, not an effect on seizure counts. It answers:</p>
<blockquote class="blockquote">
<p><strong>Does treatment change the mean ranks of percent changes?</strong></p>
</blockquote>

<div class="no-row-height column-margin column-container"><div class="">
<p><strong>Ranked ANCOVA</strong></p>
<p>Often described as “nonparametric,” ranked ANCOVA avoids distributional assumptions about the outcome but still fits a linear ANCOVA model after ranking.</p>
<p>Thus it retains the usual linear model structure, including additive covariate effects and common slopes unless interactions are included. It is distribution-free for the outcome, but not model-free.</p>
</div></div><p>In practice, ranked ANCOVA provides <strong>only a p-value</strong> for a treatment effect on the rank scale. It does <strong>not</strong> directly estimate a clinically interpretable treatment effect (e.g., a mean or median difference in PCFB), <strong>nor</strong> does it provide a corresponding measure of precision.</p>
<p>What often happens in epilepsy trials is that the p-value from ranked ANCOVA is reported alongside descriptive median PCFB values for each treatment group. This implicitly suggests that the test pertains to a difference in medians, which is generally not true. The p-value corresponds to a shift in adjusted ranks, not to a formally estimated median difference.</p>
<p>Again, ranking does not repair the distortion introduced by PCFB itself. It simply applies a different statistical test to the same transformed endpoint.</p>
</section>
<section id="what-about-quantile-regression" class="level3">
<h3 class="anchored" data-anchor-id="what-about-quantile-regression">What about quantile regression?</h3>
<p>If the goal is to estimate a median difference in percent change, the appropriate tool is quantile regression.</p>
<p>For the median, the estimand is:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AQ_%7B0.5%7D(Z%20%5Cmid%20A%20=%201)%0A-%0AQ_%7B0.5%7D(Z%20%5Cmid%20A%20=%200)%0A"></p>
<p>where <img src="https://latex.codecogs.com/png.latex?Z"> denotes percent change from baseline.</p>
<p>This answers:</p>
<blockquote class="blockquote">
<p><strong>What is the difference in median percent change between groups?</strong></p>
</blockquote>
<p>This directly estimates a <strong>difference in medians</strong> with confidence intervals, unlike Wilcoxon, Hodges–Lehmann, or ranked ANCOVA.</p>
<p>But the estimand remains a contrast in percent change, not a treatment effect on seizure frequency.</p>
<p><strong>The statistical method can be correct, while the estimand is misaligned with the data-generating mechanism.</strong></p>
</section>
</section>
<section id="powering-on-responder-status" class="level2">
<h2 class="anchored" data-anchor-id="powering-on-responder-status">Powering on responder status</h2>
<p>Responder status is typically derived as:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AR_i%20=%20%5Cmathbf%7B1%7D%5C!%5Cleft%5C%7B%0A%5Cfrac%7BY_i%5E%7B%5Ctext%7Bpost%7D%7D%20-%20Y_i%5E%7B%5Ctext%7Bbase%7D%7D%7D%7BY_i%5E%7B%5Ctext%7Bbase%7D%7D%7D%0A%5Cle%20-0.5%0A%5Cright%5C%7D%0A"></p>
<section id="the-estimand-under-responder-analysis" class="level3">
<h3 class="anchored" data-anchor-id="the-estimand-under-responder-analysis">The estimand under responder analysis</h3>
<p>When responder status is analyzed, the estimand becomes:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5CDelta_%7B%5Ctext%7BResp%7D%7D%0A=%0AP%5Cbigl(R(1)=1%5Cbigr)%0A-%0AP%5Cbigl(R(0)=1%5Cbigr)%0A"></p>
<p>This answers:</p>
<blockquote class="blockquote">
<p><strong>Did the probability of achieving at least a 50% reduction differ between groups?</strong></p>
</blockquote>
<p>The responder estimand targets a <strong>tail probability of a thresholded transformation of a ratio of counts</strong> — several layers removed from the underlying seizure process.</p>
<p><strong>Because responder status is derived from PCFB, it inherits the structural distortions of that transformation and further reduces the data to a binary indicator.</strong></p>
<p>This approach implicitly assumes:</p>
<ul>
<li><p>The outcome is inherently binary</p></li>
<li><p>Treatment is acting directly on the probability of response</p></li>
<li><p>There is no underlying count structure beneath the response indicator</p></li>
</ul>
<p>Under this view, “responder status” is treated as if it were the primary stochastic outcome following a Bernoulli data-generating process. But in reality, it is not generated by a Bernoulli mechanism and instead constructed from noisy, overdispersed count data.</p>
</section>
<section id="consequences-for-power-and-sample-size" class="level3">
<h3 class="anchored" data-anchor-id="consequences-for-power-and-sample-size">Consequences for power and sample size</h3>
<p>Power may be overstated based on a responder analysis because it:</p>
<ul>
<li><p>Discards magnitude beyond the 50% threshold</p></li>
<li><p>Changes discontinuously near the cutoff</p></li>
<li><p>Is highly sensitive to baseline seizure distribution</p></li>
<li><p>Ignores count overdispersion and heterogeneity in variance calculations</p></li>
<li><p>Ignores follow-up duration or exposure time in variance calculations</p></li>
</ul>
</section>
</section>
<section id="why-this-matters" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="why-this-matters">Why this matters</h2>
<p>When the outcome scale changes, the estimand changes. And when the estimand changes, the scientific question changes.</p>
<div class="tbl-cap" data-location="top">
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Analysis</th>
<th style="text-align: left;">Estimand</th>
<th style="text-align: left;">Scientific Question</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Count model</td>
<td style="text-align: left;">Rate ratio</td>
<td style="text-align: left;">By what proportion does treatment change seizure frequency relative to control?</td>
</tr>
<tr class="even">
<td style="text-align: left;">PCFB</td>
<td style="text-align: left;">Difference in percent change (mean or median)</td>
<td style="text-align: left;">Did percent change differ between treatment and control?</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Responder</td>
<td style="text-align: left;">Difference in response probability</td>
<td style="text-align: left;">Did the probability of achieving at least a 50% reduction differ between treatment and control?</td>
</tr>
</tbody>
</table>
</div>

<div class="no-row-height column-margin column-container"><div class="">
<p><strong>Why</strong> <strong>proportional</strong> (<strong>multiplicative) effects align with seizure-generating processes</strong></p>
<p>Seizures are recurrent events generated by an underlying patient-specific event rate.<br>
If treatment reduces that rate by, say, 30% compared to placebo, this implies:</p>
<p>[ E[Y(1)] = 0.70 E[Y(0)] ]</p>
<p>This proportional (multiplicative) structure:</p>
<p>• Reflects how risk-reduction therapies typically operate<br>
• Preserves the count scale<br>
• Avoids baseline-dependent distortion introduced by dividing by individual baseline values</p>
<p>In contrast, percent change and responder status are transformations of observed counts. They introduce nonlinear distortion, heteroskedasticity, and arbitrary thresholds that are not inherent to seizure biology</p>
</div></div><p>Powering under PCFB or responder frameworks is <strong>disconnected</strong> from the <strong>true data-generating process</strong> and have the following implications:</p>
<ul>
<li><p>Type I error can drift because variance is mischaracterized</p></li>
<li><p>Power is misestimated</p></li>
<li><p>Larger sample sizes are often required</p></li>
<li><p>The trial is designed to detect the wrong quantity</p></li>
</ul>
<p>You may believe that you are powering the trial to detect for seizure reduction, but you are actually powering it to detect:</p>
<ul>
<li><p>A mean difference or a distribution shift in a transformed ratio, or</p></li>
<li><p>A proportion difference in a threshold-crossing probability</p></li>
</ul>
<p>The design, the estimand, and the biology are no longer aligned. Once that misalignment is built into the sample size calculation, it propagates through the entire trial.</p>
</section>
<section id="what-should-be-done-instead" class="level2">
<h2 class="anchored" data-anchor-id="what-should-be-done-instead">What should be done instead?</h2>
<p>For seizure endpoints:</p>
<ol type="1">
<li><p>Specify the estimand on the count scale using an appropriate treatment contrast (e.g., a rate ratio) and convert the result to a clinically interpretable quantity (e.g., a rate ratio of 0.7 translates to a 30% reduction in seizure frequency for active compared to placebo)</p></li>
<li><p>Specify a realistic data-generating process (e.g., negative binomial with overdispersion)</p></li>
<li><p>Simulate trials under that model</p></li>
<li><p>Fit the intended analysis model</p></li>
<li><p>Estimate empirical power</p></li>
</ol>
<p>This ensures:</p>
<ul>
<li><p>Estimand coherence</p></li>
<li><p>Proper variance representation</p></li>
<li><p>Honest operating characteristics</p></li>
</ul>
</section>
<section id="what-comes-next" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="what-comes-next">What comes next</h2>
<p>The remaining issue is <strong>operating characteristics</strong> — measures of how a design performs across repeated trials under a given data-generating process.</p>

<div class="no-row-height column-margin column-container"><div class="">
<p><strong>Analytical vs Empirical Power</strong></p>
<p><em>Analytical power</em> is calculated from a closed-form formula under assumed model conditions (e.g., normality, binomial variance).</p>
<p><em>Empirical power</em> is estimated by simulation: generate many datasets under a specified data-generating process, analyze each one, and compute the proportion rejecting (H_0).</p>
<p>When model assumptions are incorrect, analytical power may be miscalibrated.<br>
Empirical power reflects operating characteristics under the assumed data-generating process.</p>
</div></div><p>In a subsequent post, we will compare the analysis of seizure counts or frequency, PCFB, and responder endpoints under realistic seizure-generating processes, to examine:</p>
<ul>
<li><p>Type I error</p></li>
<li><p>Empirical power</p></li>
<li><p>Bias</p></li>
<li><p>Mean squared error (MSE)</p></li>
<li><p>Confidence interval coverage</p></li>
</ul>
</section>
<section id="takeaway" class="level2">
<h2 class="anchored" data-anchor-id="takeaway">Takeaway</h2>
<p>Seizures are counts. Replacing counts with percent change or responder status changes the estimand and therefore the scientific question.</p>
<p>PCFB and responder analyses do not estimate a treatment effect on seizure frequency. They estimate contrasts in transformed or thresholded quantities whose statistical properties and interpretation are disconnected from the underlying count process.</p>
<p>When the estimand is misaligned with the seizure-generating process, power is computed for the wrong quantity and the trial answers a different question than intended.</p>
</section>
<section id="section" class="level2">
<h2 class="anchored" data-anchor-id="section"></h2>


</section>

 ]]></description>
  <category>methodology</category>
  <category>superiority trials</category>
  <category>trial design</category>
  <guid>https://trialnotes.org/posts/estimand/</guid>
  <pubDate>Sun, 04 Jan 2026 05:00:00 GMT</pubDate>
</item>
<item>
  <title>Rethinking Placebo Response</title>
  <dc:creator>Fei Zuo</dc:creator>
  <link>https://trialnotes.org/posts/placebo_resp/</link>
  <description><![CDATA[ 




<p><strong>🎧 1-minute summary</strong></p>
<p><em>Narration generated using OpenAI.fm.</em></p>
<audio controls="" preload="none" style="width:320px; margin-bottom:14px;">
<source src="../../audio/placebo-resp_small.mp3" type="audio/mpeg">
</audio>
<p>In randomized clinical trials, especially in neurology and psychiatry, we often hear phrases like:</p>
<ul>
<li><p>“The placebo response was high.”</p></li>
<li><p>“This indication has a large placebo effect.”</p></li>
<li><p>“The drug failed because of placebo response.”</p></li>
</ul>
<p>These statements are often misleading. In this post, I’ll explain why placebo response is frequently misunderstood, why it cannot be interpreted as evidence of a causal improvement, and why misunderstanding it leads to flawed trial design and reasoning. The discussion here focuses on superiority trials.</p>
<section id="what-is-placebo-response" class="level2">
<h2 class="anchored" data-anchor-id="what-is-placebo-response">What is placebo response?</h2>
<p>Placebo response refers to the overall change observed in participants assigned to placebo between baseline and follow-up. This term does not refer solely to a psychobiological “placebo effect.” In methodological literature, placebo response encompasses all sources of change occurring in the placebo arm, including natural disease course and statistical artifacts, not just expectation-driven effects.</p>
<p>Placebo response is therefore a <strong>composite</strong> quantity.</p>
</section>
<section id="the-decomposition-problem" class="level2">
<h2 class="anchored" data-anchor-id="the-decomposition-problem">The decomposition problem</h2>
<p>In practice, observed change in the placebo arm reflects multiple distinct components:</p>
<ol type="1">
<li><p><strong>Natural history</strong> (disease fluctuation, spontaneous remission, cyclical patterns)</p></li>
<li><p><strong>Regression to the mean</strong> (especially when enrollment requires elevated baseline severity)</p></li>
<li><p><strong>Measurement error</strong> (random variation in outcome assessment)</p></li>
<li><p><strong>Study effect</strong> (being observed, monitored, structured follow-up, adherence reinforcement, behavioral change)</p></li>
<li><p><strong>True placebo effect</strong> (expectation-driven psychobiologic response attributable to belief in treatment)</p></li>
</ol>
<p>All of these are bundled together under the label “placebo response.”</p>
<p>And here is the problem:</p>
<div class="callout callout-style-simple callout-note no-icon">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-body-container">
<ul>
<li><p>These components <strong>cannot be separated</strong> in a standard parallel-group randomized trial. The design does not allow identification of which portion of within-arm change is attributable to which mechanism.</p></li>
<li><p>Placebo response is a <strong>within-arm change-from-baseline quantity</strong>. It is <strong>not</strong> <strong>a causal effect</strong>.</p></li>
</ul>
</div>
</div>
</div>
</section>
<section id="within-arm-change-is-not-a-causal-estimand" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="within-arm-change-is-not-a-causal-estimand">Within-arm change is not a causal estimand</h2>
<p>When we calculate placebo response, we are computing:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPlacebo%20response%7D%0A=%0A%5Cmathbb%7BE%7D%5Cleft(%20Y_%7B%5Ctext%7Bpost%7D%7D%20-%20Y_%7B%5Ctext%7Bbaseline%7D%7D%20%5Cmid%20%5Ctext%7BPlacebo%7D%20%5Cright)%0A"></p>
<p>That is a <strong>descriptive</strong> statistic.</p>
<p>But the treatment effect in a randomized trial is:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BTreatment%20effect%7D%0A=%0A%5Cmathbb%7BE%7D%5Cleft(%20Y_%7B%5Ctext%7Bpost%7D%7D%20%5Cmid%20%5Ctext%7BDrug%7D%20%5Cright)%0A-%0A%5Cmathbb%7BE%7D%5Cleft(%20Y_%7B%5Ctext%7Bpost%7D%7D%20%5Cmid%20%5Ctext%7BPlacebo%7D%20%5Cright)%0A"></p>
<p>That is a <strong>between-arm contrast</strong>.</p>
<p>Randomization protects and justifies the treatment contrast, not the within-arm summaries.</p>
<p>So when people say: “Patients improved on placebo.”</p>
<p>The statement sounds causal but it is ambiguous. Improvement always <strong>implies a comparison</strong>.</p>
<p>The question is:</p>
<p><strong>Improved relative to what?</strong></p>
<ul>
<li><p><strong>Relative to baseline?</strong></p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BE%7D%5Cleft(%20Y_%7B%5Ctext%7Bpost%7D%7D%20-%20Y_%7B%5Ctext%7Bbaseline%7D%7D%20%5Cmid%20%5Ctext%7BPlacebo%7D%20%5Cright)%0A"></p>
<p>That is simply change over time that bundles together everything that happens between baseline and follow-up, including regression to the mean, measurement error, natural fluctuation in disease severity, study participation effects, and any expectation-driven placebo effects. But it remains a before-after comparison within a single arm and does not isolate any specific component. More importantly, <strong>without a “no-placebo” counterfactual</strong> (i.e., a control arm in which participants receive no placebo intervention), there is no basis for concluding that placebo itself caused the observed effect. Regression to the mean, measurement error, natural fluctuation, and study participation effects can all produce change over time <em>even if no placebo were given</em>.</p>
</li>
<li><p><strong>Relative to no study participation?</strong></p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BE%7D%5Cleft(%20Y_%7B%5Ctext%7Bpost%7D%7D%20%5Cmid%20%5Ctext%7BPlacebo%7D%20%5Cright)%0A-%0A%5Cmathbb%7BE%7D%5Cleft(%20Y_%7B%5Ctext%7Bpost%7D%7D%20%5Cmid%20%5Ctext%7BNo%20Study%7D%20%5Cright)%0A"></p>
<p>Enrollment in a clinical trial changes behavior. Patients are monitored more closely, seen at scheduled visits, encouraged to adhere to treatment, and given structured clinical attention. These factors can influence outcomes even without active therapy — a so-called <em>study effect</em>. If “improvement on placebo” refers to improvement relative to what would have happened outside the trial entirely, then it incorporates these participation effects. That is a different counterfactual from baseline change and it is not directly observed in a standard parallel-group randomized trial.</p></li>
<li><p><strong>Relative to the natural disease trajectory?</strong></p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BE%7D%5Cleft(%20Y_%7B%5Ctext%7Bpost%7D%7D%20%5Cmid%20%5Ctext%7BPlacebo%7D%20%5Cright)%0A-%0A%5Cmathbb%7BE%7D%5Cleft(%20Y_%7B%5Ctext%7Bpost%7D%7D%20%5Cmid%20%5Ctext%7BNatural%20History%7D%20%5Cright)%0A"></p>
<p>Many conditions fluctuate over time. Some improve spontaneously, some remit partially, and some follow cyclical patterns. If “improvement on placebo” refers to improvement relative to what would have happened under the untreated natural disease trajectory without study participation, then it invokes a different counterfactual altogether. That counterfactual is not identifiable in a standard parallel-group randomized trial.</p></li>
<li><p><strong>Relative to drug?</strong></p>
<p>This is the only comparison randomization is designed to answer. The causal estimand in a superiority trial is:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BTreatment%20effect%7D%0A=%0A%5Cmathbb%7BE%7D%5Cleft(%20Y_%7B%5Ctext%7Bpost%7D%7D%20%5Cmid%20%5Ctext%7BDrug%7D%20%5Cright)%0A-%0A%5Cmathbb%7BE%7D%5Cleft(%20Y_%7B%5Ctext%7Bpost%7D%7D%20%5Cmid%20%5Ctext%7BPlacebo%7D%20%5Cright)%0A"></p></li>
</ul>
<div class="no-row-height column-margin column-container"><div class="">
<p><strong>What is a causal effect?</strong></p>
<p>A causal effect is defined as the contrast between two potential outcomes for the same individual:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AY(1)%20-%20Y(0)%0A"></p>
<p>where:</p>
<ul>
<li>Y(1) is the outcome under treatment</li>
<li>Y(0) is the outcome under control</li>
</ul>
<p>Because both potential outcomes cannot be observed for the same individual, causal effects cannot be directly measured. In a randomized trial, randomization allows unbiased estimation of the <strong>average causal effect</strong> by comparing outcomes between groups:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AE%5C!%5Cleft%5BY(1)%20-%20Y(0)%5Cright%5D%0A"></p>
<p>Apparent improvement within the placebo arm alone does not identify a causal effect, because it does not compare observed outcomes to the unobserved counterfactual.</p>
</div></div><div class="callout callout-style-simple callout-note no-icon">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-body-container">
<p>Without clarifying the counterfactual, “improvement on placebo” collapses multiple distinct estimands into a single phrase, and only one of them (drug vs placebo) is relevant to causal treatment effect estimation.</p>
</div>
</div>
</div>
</section>
<section id="what-randomization-actually-protects" class="level2">
<h2 class="anchored" data-anchor-id="what-randomization-actually-protects">What randomization actually protects</h2>
<p>Randomization ensures that everything happening in the placebo arm is also happening in the treatment arm in expectation.</p>
<p>That includes:</p>
<ul>
<li><p>Regression to the mean</p></li>
<li><p>Natural history</p></li>
<li><p>Measurement noise</p></li>
<li><p>Study participation effects</p></li>
<li><p>Expectation effects (if blinding holds)</p></li>
</ul>
<p>Because the estimand is the <strong>difference between groups</strong>, all shared componensts <strong>cancel in expectation and therefore in the contrast</strong>.</p>
<p>This is the key insight:</p>
<div class="callout callout-style-simple callout-note no-icon">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-body-container">
<ul>
<li><p>Placebo response is <strong>shared variability</strong>.</p></li>
<li><p>Shared variability does <strong>not</strong> bias the treatment effect.</p></li>
<li><p>Randomization renders placebo response <strong>irrelevant</strong> to the treatment contrast.</p></li>
</ul>
</div>
</div>
</div>
</section>
<section id="the-logical-mistake" class="level2">
<h2 class="anchored" data-anchor-id="the-logical-mistake">The logical mistake</h2>
<p>The reasoning often goes like this:</p>
<ol type="1">
<li><p>The placebo arm “improved” a lot.</p></li>
<li><p>Therefore, placebo is “competing” with the drug.</p></li>
<li><p>Therefore, we must reduce placebo response.</p></li>
</ol>
<p>But this logic confuses <strong>within-arm change</strong> with the <strong>between-arm contrast</strong> that defines treatment effect.</p>
<p>The treatment effect is the difference between randomized groups, not the magnitude of change within one arm.</p>
<p>To see this clearly, consider a simple simulation.</p>
</section>
<section id="a-simulation-demonstration" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="a-simulation-demonstration">A simulation demonstration</h2>
<p>We simulate a fluctuating disease across many trials where:</p>
<ul>
<li><p>Patients enroll during a symptomatic period (as is common in practice due to eligibility criteria).</p></li>
<li><p>Outcomes are noisy.</p></li>
<li><p>There is regression to the mean.</p></li>
<li><p>The drug has a modest true effect of −2 units.</p></li>
<li><p>The placebo has no causal effect, but outcomes naturally fluctuate.</p></li>
</ul>

<div class="no-row-height column-margin column-container"><div class="margin-aside">
<p><strong>Regression to the mean</strong></p>
<p>Because enrollment is based on a high observed baseline, some patients qualify as a result of random positive noise fluctuation rather than consistently high underlying severity.</p>
<p>When re-measured at follow-up, that noise component does not systematically repeat. As a result, the group will tend to show apparent improvement on average even in the absence of any active treatment.</p>
<p>This is precisely why change from baseline is not informative about causal effect. The observed improvement reflects statistical artifact and natural variability, not evidence that placebo caused benefit.</p>
</div></div><div class="hidden">
<p><img src="https://latex.codecogs.com/png.latex?%0ASE_%7B%5Ctext%7BWelch%7D%7D%0A=%0A%5Csqrt%7B%5Cfrac%7Bs_1%5E2%7D%7Bn_1%7D+%5Cfrac%7Bs_0%5E2%7D%7Bn_0%7D%7D%0A"></p>
<p><img src="https://latex.codecogs.com/png.latex?%0Adf_%7B%5Ctext%7BWelch%7D%7D%0A=%0A%5Cfrac%7B%5Cleft(%5Cfrac%7Bs_1%5E2%7D%7Bn_1%7D+%5Cfrac%7Bs_0%5E2%7D%7Bn_0%7D%5Cright)%5E2%7D%0A%7B%5Cfrac%7B%5Cleft(%5Cfrac%7Bs_1%5E2%7D%7Bn_1%7D%5Cright)%5E2%7D%7Bn_1-1%7D+%5Cfrac%7B%5Cleft(%5Cfrac%7Bs_0%5E2%7D%7Bn_0%7D%5Cright)%5E2%7D%7Bn_0-1%7D%7D%0A"></p>
<p><img src="https://latex.codecogs.com/png.latex?%0ACI_%7B0.95%7D%0A=%0A%5Chat%7B%5CDelta%7D%0A%5Cpm%0At_%7B0.975,%5C;df_%7B%5Ctext%7BWelch%7D%7D%7D%5C,SE_%7B%5Ctext%7BWelch%7D%7D%0A"></p>
</div>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="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;">1</span>)</span>
<span id="cb1-2"></span>
<span id="cb1-3">one_trial <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;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>, </span>
<span id="cb1-4">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_drug_effect =</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="cb1-5">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma_person =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,<span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#between-subject heterogeneity in disease severity</span></span>
<span id="cb1-6">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma_noise =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#measurement noise/day-to-day symptom variability</span></span>
<span id="cb1-7">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enroll_threshold =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">55</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#only people with a baseline measurement ≥ 55 meet eligible criteria</span></span>
<span id="cb1-8">                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">return_data =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#for inspection only when set to TRUE</span></span>
<span id="cb1-9">  {</span>
<span id="cb1-10"></span>
<span id="cb1-11">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># keep generating candidates until we can enroll n</span></span>
<span id="cb1-12">  keep_idx <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">integer</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#indices of candidates whose observed baseline meets eligibility</span></span>
<span id="cb1-13">  mu_pool <span class="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>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#each candidate’s latent (unobserved) “true” severity</span></span>
<span id="cb1-14">  y0_pool <span class="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>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#their observed baseline measurement (true severity + noise)</span></span>
<span id="cb1-15"></span>
<span id="cb1-16">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(keep_idx) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> n) {</span>
<span id="cb1-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#This loop will keep generating candidates until we have at least n eligible participants.    </span></span>
<span id="cb1-18">    mu_new <span class="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;">5</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n, <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;">50</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> sigma_person) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Generate candidates' latent severities</span></span>
<span id="cb1-19">    y0_new <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mu_new <span 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>(<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>n, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, sigma_noise) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Generate candidates' baseline observed score</span></span>
<span id="cb1-20">    keep_new <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(y0_new <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> enroll_threshold) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#only enroll candidates whose observed baseline is high enough (≥ 55). </span></span>
<span id="cb1-21">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Note eligibility is based on measured baseline severity, not latent severity.</span></span>
<span id="cb1-22"></span>
<span id="cb1-23">    mu_pool <span class="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>(mu_pool, mu_new)</span>
<span id="cb1-24">    y0_pool <span class="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>(y0_pool, y0_new)</span>
<span id="cb1-25">    keep_idx <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(y0_pool <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> enroll_threshold)</span>
<span id="cb1-26">  }</span>
<span id="cb1-27"></span>
<span id="cb1-28">  idx <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(keep_idx, n) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Randomly select exactly n enrolled patients</span></span>
<span id="cb1-29">  mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mu_pool[idx]</span>
<span id="cb1-30">  y0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> y0_pool[idx]</span>
<span id="cb1-31"></span>
<span id="cb1-32">  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;">rbinom</span>(n, <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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># 1=drug, 0=placebo</span></span>
<span id="cb1-33">  y1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mu <span 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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, sigma_noise) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> A <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> true_drug_effect</span>
<span id="cb1-34"></span>
<span id="cb1-35">  placebo_change <span class="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>(y1[A <span 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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> y0[A <span 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>
<span id="cb1-36">  te_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;">mean</span>(y1[A <span 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;">mean</span>(y1[A <span 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>
<span id="cb1-37"></span>
<span id="cb1-38">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># -- Precision: Welch-style SE, CI, one-sided test for power----------------</span></span>
<span id="cb1-39">  n1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(A <span 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-40">  n0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(A <span 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>
<span id="cb1-41">  s1_sq <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(y1[A <span 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-42">  s0_sq <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">var</span>(y1[A <span 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>
<span id="cb1-43">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Standard error for difference in means (Welch formulation).</span></span>
<span id="cb1-44">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We estimate the variance from the data, so the sampling distribution</span></span>
<span id="cb1-45">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># of the test statistic follows a t distribution rather than a normal.</span></span>
<span id="cb1-46">  se_te <span class="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>(s1_sq <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> n1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> s0_sq <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> n0)</span>
<span id="cb1-47">  </span>
<span id="cb1-48">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Welch–Satterthwaite df</span></span>
<span id="cb1-49">  df_welch <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (s1_sq<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> s0_sq<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n0)<span 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>
<span id="cb1-50">    ((s1_sq<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n1)<span 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>(n1 <span 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> (s0_sq<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n0)<span 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>(n0 <span 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-51">  </span>
<span id="cb1-52">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Two-sided 95% CI using t critical value</span></span>
<span id="cb1-53">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># If the population variances were known, a normal (z) critical value</span></span>
<span id="cb1-54">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># could be used. Here they are estimated, so t is appropriate.</span></span>
<span id="cb1-55">  t_crit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qt</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> df_welch)</span>
<span id="cb1-56">  ci_lo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> te_post <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> t_crit <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> se_te</span>
<span id="cb1-57">  ci_hi <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> te_post <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> t_crit <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> se_te</span>
<span id="cb1-58">  </span>
<span id="cb1-59">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># One-sided p-value for benefit (H1: treatment effect &lt; 0)</span></span>
<span id="cb1-60">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># The test statistic follows a t distribution with df_welch.</span></span>
<span id="cb1-61">  t_stat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> te_post <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> se_te</span>
<span id="cb1-62">  p_one_sided <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pt</span>(t_stat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> df_welch)</span>
<span id="cb1-63">  </span>
<span id="cb1-64">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># "Power" indicator = conclude benefit at alpha=0.025 (one-sided)</span></span>
<span id="cb1-65">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># equivalent to checking whether the upper bound of a two-sided 95% confidence interval</span></span>
<span id="cb1-66">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># is below zero, since both use the same critical value.</span></span>
<span id="cb1-67">  sig_025 <span class="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>(p_one_sided <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.025</span>) </span>
<span id="cb1-68">  sig_benefit_025 <span class="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>(ci_hi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#an alternative check</span></span>
<span id="cb1-69"></span>
<span id="cb1-70">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># --------------------------------------------------------------</span></span>
<span id="cb1-71">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (return_data) { <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#for inspection only</span></span>
<span id="cb1-72">    <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;">list</span>(</span>
<span id="cb1-73">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">screened =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb1-74">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_severity =</span> mu_pool,</span>
<span id="cb1-75">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">baseline_observed =</span> y0_pool,</span>
<span id="cb1-76">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">eligible =</span> y0_pool <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> enroll_threshold</span>
<span id="cb1-77">      ),</span>
<span id="cb1-78">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enrolled =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb1-79">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_severity =</span> mu,</span>
<span id="cb1-80">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">baseline_observed =</span> y0,</span>
<span id="cb1-81">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">treatment =</span> A,</span>
<span id="cb1-82">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">followup =</span> y1</span>
<span id="cb1-83">      ),</span>
<span id="cb1-84">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">summaries =</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;">placebo_change =</span> placebo_change,</span>
<span id="cb1-85">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">treatment_effect =</span> te_post,</span>
<span id="cb1-86">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df_welch =</span> df_welch,</span>
<span id="cb1-87">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t_crit =</span> t_crit,</span>
<span id="cb1-88">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se_te =</span> se_te,</span>
<span id="cb1-89">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_lo =</span> ci_lo,</span>
<span id="cb1-90">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_hi =</span> ci_hi,</span>
<span id="cb1-91">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sig_025 =</span> sig_025,</span>
<span id="cb1-92">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sig_benefit_025 =</span> sig_benefit_025,</span>
<span id="cb1-93">                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p_one_sided =</span> p_one_sided)</span>
<span id="cb1-94">    ))</span>
<span id="cb1-95">  }</span>
<span id="cb1-96">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># --------------------------------------------------------------</span></span>
<span id="cb1-97">  <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;">placebo_change =</span> placebo_change,</span>
<span id="cb1-98">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">treatment_effect =</span> te_post,</span>
<span id="cb1-99">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df_welch =</span> df_welch,</span>
<span id="cb1-100">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t_crit =</span> t_crit,</span>
<span id="cb1-101">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se_te =</span> se_te,</span>
<span id="cb1-102">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_lo =</span> ci_lo,</span>
<span id="cb1-103">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_hi =</span> ci_hi,</span>
<span id="cb1-104">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sig_025 =</span> sig_025,</span>
<span id="cb1-105">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sig_benefit_025 =</span> sig_benefit_025, </span>
<span id="cb1-106">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p_one_sided =</span> p_one_sided)</span>
<span id="cb1-107">}</span>
<span id="cb1-108"></span>
<span id="cb1-109"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Repeat across 2000 simulations</span></span>
<span id="cb1-110">B <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;">2000</span></span>
<span id="cb1-111">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;">do.call</span>(rbind, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(B), <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;">one_trial</span>())) </span>
<span id="cb1-112"></span>
<span id="cb1-113"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Summarize the simulation results</span></span>
<span id="cb1-114">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;">list</span>(</span>
<span id="cb1-115">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_placebo_change =</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;">mean</span>(res[, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"placebo_change"</span>]), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb1-116">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_estimated_treatment_effect =</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;">mean</span>(res[, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"treatment_effect"</span>]), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb1-117">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_se =</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;">mean</span>(res[, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"se_te"</span>]), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb1-118">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_ci_width =</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;">mean</span>(res[, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ci_hi"</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> res[, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ci_lo"</span>]), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb1-119">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">approx_power =</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;">mean</span>(res[, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sig_025"</span>]), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb1-120">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#approx_power = round(mean(res[, "sig_benefit_025"]), 2), #an alternative check</span></span>
<span id="cb1-121">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_trials_used =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(res)</span>
<span id="cb1-122">) </span>
<span id="cb1-123"></span>
<span id="cb1-124"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(out)</span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>$mean_placebo_change
[1] -7.31

$mean_estimated_treatment_effect
[1] -2.05

$mean_se
[1] 1.35

$mean_ci_width
[1] 5.32

$approx_power
[1] 0.33

$n_trials_used
[1] 2000</code></pre>
</div>
</div>
<p>Across 2000 simulated trials, you will typically observe that:</p>
<ul>
<li><p>The placebo arm shows substantial “improvement” from baseline — a large “placebo response.”</p></li>
<li><p>The estimated treatment effect is very close to −2, the true drug effect.</p></li>
</ul>
<p>The placebo arm shows an apparent improvement not because placebo is effective, but because regression to the mean and variability generate change over time. Those same forces operate in the treatment arm.</p>
<p>Randomization ensures that these shared forces <strong>cancel in expectation</strong> when we compute:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BE%7D%5Cbig(Y_%7B%5Ctext%7Bpost%7D%7D%20%5Cmid%20%5Ctext%7BDrug%7D%5Cbig)%0A%5C;-%5C;%0A%5Cmathbb%7BE%7D%5Cbig(Y_%7B%5Ctext%7Bpost%7D%7D%20%5Cmid%20%5Ctext%7BPlacebo%7D%5Cbig)%0A"></p>
<p>A large placebo response (i.e., within-placebo change) is usually a symptom of <strong>high outcome variability</strong>. It is this variability, <strong>not</strong> the apparent improvement itself, that increases standard errors, widens confidence intervals, and reduces statistical power.</p>
<p>That is a <strong>precision</strong> issue, not a validity issue.</p>
<div class="callout callout-style-simple callout-note no-icon">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-body-container">
<p>A high placebo response does not invalidate the comparison. It reflects that clinical outcomes are dynamic and randomized trials are designed precisely so that such dynamics do not bias the treatment contrast.</p>
</div>
</div>
</div>
</section>
<section id="why-strategies-to-reduce-placebo-response-are-misguided" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="why-strategies-to-reduce-placebo-response-are-misguided">Why strategies to reduce placebo response are misguided</h2>
<p>Many placebo-response reduction strategies aim to improve signal detection by reducing observed within-placebo change.</p>

<div class="no-row-height column-margin column-container"><div class="margin-aside">
<p><strong>Placebo run-in periods</strong></p>
<p>As Stephen Senn has noted in discussions of placebo run-in designs, excluding “placebo responders” during a run-in does not necessarily remove placebo response from a trial; it may simply exclude patients who happened to improve at that particular time.</p>
</div><div class="margin-aside">
<p><strong>Risk of overcorrection</strong></p>
<p>Efforts to reduce placebo response can introduce new problems:</p>
<ul>
<li>Selection effects that distort the target population</li>
<li>Reduced generalizability</li>
<li>Inflated apparent effect sizes</li>
<li>Fragile, non-replicable results</li>
</ul>
<p>If the treatment only appears effective after aggressively filtering out natural variability, that raises deeper questions about clinical relevance.</p>
</div></div>
<p>Common approaches include:</p>
<ul>
<li><p>Placebo run-in periods</p></li>
<li><p>Excluding early “improvers”</p></li>
<li><p>Enrichment designs</p></li>
<li><p>Highly restrictive eligibility criteria</p></li>
</ul>
<p>When strategies aim to “reduce placebo response”, they are often attempting to suppress natural variability and heterogeneity in the outcome measure through design restrictions. Variability itself is not the problem — it is a property of the disease and the measurement process; the problem is <strong>inefficient analysis</strong>. The principled approach is to account for variability appropriately in the statistical model, not to alter the population or trial context in ways that may compromise generalizability, clinical applicability, and robustness.</p>
<p>Although regulatory guidance recognizes enrichment strategies including those aimed at reducing variability, the notion of a “placebo responder” warrants caution. In fluctuating conditions, short-term improvement during a run-in period often reflects regression to the mean or random temporal variation rather than a stable biological subtype. A patient labelled a “placebo responder” at one time point may not meet that definition if re-measured later. Excluding such individuals therefore selects on <strong>transient fluctuation</strong> rather than on a reproducible causal mechanism, and may do little to achieve its intended goal.</p>
</section>
<section id="if-the-goal-is-better-signal-detection-focus-on-efficient-modeling" class="level2">
<h2 class="anchored" data-anchor-id="if-the-goal-is-better-signal-detection-focus-on-efficient-modeling">If the goal Is better signal detection, focus on efficient modeling</h2>
<p>If variability makes treatment effects harder to detect, the principled solution is to improve statistical efficiency.</p>
<section id="use-appropriate-endpoints-and-efficient-modelling" class="level3">
<h3 class="anchored" data-anchor-id="use-appropriate-endpoints-and-efficient-modelling"><strong>Use appropriate endpoints and efficient modelling</strong></h3>
<p>For clinical outcomes, whether continuous, count, or ordinal, analyze the outcome directly and adjust for baseline and other prognostic baseline covariates using an appropriate regression model for the outcome type.</p>
<p>This approach:</p>
<ul>
<li><p>Accounts for baseline differences</p></li>
<li><p>Reduces unexplained variability</p></li>
<li><p>Improves statistical power</p></li>
<li><p>Uses all available information when repeated measurements are present</p></li>
<li><p>Avoids unnecessary data reduction (e.g., dichotomization or percent change from baseline)</p></li>
</ul>
</section>
<section id="other-principled-ways-to-improve-precision" class="level3">
<h3 class="anchored" data-anchor-id="other-principled-ways-to-improve-precision">Other principled ways to improve precision</h3>
<ul>
<li><p>Increase sample size</p></li>
<li><p>Improve measurement reliability (better instruments, rater training, repeated measurements)</p></li>
<li><p>Reduce measurement noise, not biological variability</p></li>
</ul>
</section>
</section>
<section id="takeaway" class="level2">
<h2 class="anchored" data-anchor-id="takeaway">Takeaway</h2>
<p>Precision should be achieved through robust endpoints and efficient modeling that adjusts for prognostic baseline covariates.</p>
<p>“Placebo response” is a descriptive summary of within-arm change. It conflates regression to the mean, measurement error, natural fluctuation, study effects, and expectation effects into a single number. These components are not separately identifiable in a parallel-group randomized trial.</p>
<p>Apparent within-arm improvement is not evidence of a causal effect. Change from baseline, by itself, does not justify an improvement claim without an explicit comparison arm. In a randomized superiority trial, the only causal estimand the design justifies is the treatment contrast.</p>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<p>Hernán, M. A., &amp; Robins, J. M. (2020). <em>Causal inference: What if.</em> Chapman &amp; Hall/CRC.</p>
<p>Holland, P. W. (1986). Statistics and causal inference. <em>Journal of the American Statistical Association, 81</em>(396), 945–960. <a href="https://doi.org/10.1080/01621459.1986.10478354" class="uri">https://doi.org/10.1080/01621459.1986.10478354</a></p>
<p>International Council for Harmonisation of Technical Requirements for Pharmaceuticals for Human Use (ICH). (2019). <em>ICH E9(R1) addendum on estimands and sensitivity analysis in clinical trials.</em></p>
<p>Murray, E. J. (2021). Editorial: Demystifying the placebo effect. <em>American Journal of Epidemiology, 190</em>(1), 2–9.<br>
<a href="https://doi.org/10.1093/aje/kwaa162">doi:10.1093/aje/kwaa162</a></p>
<p>Rubin, D. B. (1974). Estimating causal effects of treatments in randomized and nonrandomized studies. <em>Journal of Educational Psychology, 66</em>(5), 688–701. <a href="https://doi.org/10.1037/h0037350" class="uri">https://doi.org/10.1037/h0037350</a></p>
<p>Senn, S. (2021). <em>Statistical issues in drug development</em> (3rd ed.). Wiley.</p>
<p>U.S. Food and Drug Administration. (2019). <em>Enrichment strategies for clinical trials to support determination of effectiveness of human drugs and biological products: Guidance for industry.</em></p>


</section>

 ]]></description>
  <category>methodology</category>
  <category>randomization</category>
  <category>simulation</category>
  <category>superiority trials</category>
  <category>trial design</category>
  <guid>https://trialnotes.org/posts/placebo_resp/</guid>
  <pubDate>Sun, 14 Dec 2025 05:00:00 GMT</pubDate>
</item>
<item>
  <title>Why Block Size Should Not Appear in the Protocol or SAP</title>
  <dc:creator>Fei Zuo</dc:creator>
  <link>https://trialnotes.org/posts/block/</link>
  <description><![CDATA[ 




<p><strong>🎧 1-minute summary</strong></p>
<p><em>Narration generated using OpenAI.fm.</em></p>
<audio controls="" preload="none" style="width:320px; margin-bottom:14px;">
<source src="../../audio/block_small.mp3" type="audio/mpeg">
</audio>
<p>In randomized clinical trials, we talk a lot about blinding. But an equally important and subtly different concept is allocation concealment.</p>
<p>They are not the same thing.</p>
<ul>
<li><p><strong>Blinding</strong> protects against bias <em>after</em> treatment is assigned (e.g., preventing biased outcome assessment).</p></li>
<li><p><strong>Allocation concealment</strong> protects against bias at the moment of enrollment <em>before</em> treatment is assigned (e.g., preventing foreknowledge of upcoming treatment assignment).</p></li>
</ul>
<p>Because allocation concealment depends on unpredictability at the time of enrollment, certain operational details such as <strong>block size</strong> can weaken that protection if widely disclosed.</p>
<section id="regulatory-and-reporting-standards-emphasize-concealment-not-disclosure-of-block-size" class="level2">
<h2 class="anchored" data-anchor-id="regulatory-and-reporting-standards-emphasize-concealment-not-disclosure-of-block-size">Regulatory and Reporting Standards Emphasize Concealment, Not Disclosure of Block Size</h2>
<p>Major regulatory and reporting guidance documents are clear about the importance of allocation concealment. Notably, they do not require disclosure of block size in protocols or SAPs.</p>
<p><strong>ICH E9 (Statistical Principles for Clinical Trials)</strong></p>
<blockquote class="blockquote">
<p><strong>ICH E9 emphasizes that randomization protects against selection bias and provides a valid basis for statistical inference. This protection depends on the allocation sequence remaining unpredictable at the time of enrollment.</strong></p>
</blockquote>
<p>Unpredictability is the core principle. If the block size is known to investigators, predictability can arise — directly conflicting with this requirement.</p>
<p><strong>ICH E6 (Good Clinical Practice)</strong></p>
<p>ICH E6 emphasizes safeguarding the randomization process:</p>
<blockquote class="blockquote">
<p><strong>“The investigator should follow the trial’s randomization procedures, if any, and should ensure that the code is broken only in accordance with the protocol.”</strong></p>
</blockquote>
<p>Maintaining control of the randomization schedule including operational details like block size is part of preserving its integrity.</p>
<p><strong>CONSORT 2010 Statement</strong></p>
<p>CONSORT distinguishes clearly between:</p>
<ul>
<li><p><strong>Sequence generation</strong></p></li>
<li><p><strong>Allocation concealment mechanism</strong></p></li>
</ul>
<p>Item 9 of the CONSORT 2010 checklist requires:</p>
<blockquote class="blockquote">
<p><strong>“Mechanism used to implement the random allocation sequence (such as sequentially numbered containers), describing any steps taken to conceal the sequence until interventions were assigned.”</strong></p>
</blockquote>
<p>CONSORT focuses on <em>how concealment was ensured</em>, not on revealing details that would undermine it.</p>
</section>
<section id="the-purpose-of-block-randomization" class="level2">
<h2 class="anchored" data-anchor-id="the-purpose-of-block-randomization">The Purpose of Block Randomization</h2>
<p>Block randomization is used to maintain approximate treatment balance throughout enrollment.</p>
<p>For example, in a 1:1 trial with block size 4, each block contains:</p>
<ul>
<li><p>2 assignments to Treatment A</p></li>
<li><p>2 assignments to Treatment B</p></li>
</ul>
<p>The order of assignments within each block is randomly permuted. Since each block contains equal numbers of assignments for each treatment, treatment counts remain balanced throughout enrollment, reducing the risk of large imbalances if the trial stops early.</p>
</section>
<section id="the-problem-predictability" class="level2">
<h2 class="anchored" data-anchor-id="the-problem-predictability">The Problem: Predictability</h2>
<p>If investigators know the block size, allocation can become <strong>predictable</strong>.</p>
<p>Imagine:</p>
<ul>
<li><p>1:1 randomization</p></li>
<li><p>Block size = 4</p></li>
<li><p>Three patients in a block have already been assigned: A, B, A</p></li>
</ul>
<p>What is the fourth assignment?</p>
<p>It must be B.</p>
<p>At that point, allocation is no longer random in practice. It is deducible.</p>
<p>The mere ability to anticipate the next assignment can influence enrollment decisions in small but systematic ways:</p>
<ul>
<li><p>Delaying enrollment of a “difficult” patient</p></li>
<li><p>Accelerating enrollment of a “good prognosis” patient</p></li>
<li><p>Selectively enrolling borderline-eligible patients</p></li>
</ul>
<p>This introduces <strong>selection bias</strong>, even in a formally randomized trial. That is a failure of allocation concealment.</p>
</section>
<section id="allocation-concealment-blinding" class="level2">
<h2 class="anchored" data-anchor-id="allocation-concealment-blinding">Allocation Concealment ≠ Blinding</h2>
<p>Even in an open-label trial (no blinding), allocation concealment must still be protected.</p>
<p><strong>Blinding protects:</strong></p>
<ul>
<li><p>Outcome assessment</p></li>
<li><p>Patient behavior</p></li>
<li><p>Investigator expectations</p></li>
</ul>
<p><strong>Allocation concealment protects:</strong></p>
<ul>
<li>The integrity of who gets assigned what</li>
</ul>
<p><strong>You can have:</strong></p>
<ul>
<li><p>A blinded trial with broken allocation concealment</p></li>
<li><p>An open-label trial with perfect allocation concealment</p></li>
</ul>
<p>They are conceptually distinct safeguards.</p>
</section>
<section id="why-block-size-does-not-belong-in-the-protocol-or-sap" class="level2">
<h2 class="anchored" data-anchor-id="why-block-size-does-not-belong-in-the-protocol-or-sap">Why Block Size Does Not Belong in the Protocol or SAP</h2>
<p>The protocol and SAP are often widely distributed:</p>
<ul>
<li><p>Investigators</p></li>
<li><p>Coordinators</p></li>
<li><p>Sponsors</p></li>
<li><p>Regulators</p></li>
<li><p>Data monitoring committees</p></li>
</ul>
<p>If the block size is written there, it is no longer protected.</p>
<p>Best practice is:</p>
<ul>
<li><p>The protocol states that blocked randomization will be used.</p></li>
<li><p>The SAP describes the randomization method in general terms.</p></li>
<li><p>The actual block size (and any random variation in block size) is known only to:</p>
<ul>
<li><p>The unblinded statistician</p></li>
<li><p>The randomization unit/vendor/system</p></li>
</ul></li>
</ul>
<p>This protects allocation concealment while still maintaining transparency about the design.</p>
</section>
<section id="fixed-block-sizes" class="level2">
<h2 class="anchored" data-anchor-id="fixed-block-sizes">Fixed Block Sizes</h2>
<p>Using a fixed block size makes predictability easier.</p>
<p>A better approach is:</p>
<ul>
<li><strong>Randomly varying</strong> block sizes (e.g., 2, 4, and 6)</li>
</ul>
<p>This dramatically <strong>reduces predictability</strong>. But even then, disclosing the possible block sizes weakens protection.</p>
<div class="callout callout-style-simple callout-note no-icon callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Randomization terminology
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<p><strong>Simple randomization</strong><br>
Each subject is assigned independently (e.g., coin flip) using a chance mechanism. Balance is achieved on average, but temporary imbalances can occur.</p>
<p><strong>Permuted block randomization — fixed block size</strong><br>
Assignments are balanced within blocks of a constant size (e.g., all blocks size 4), and the order within each block is randomly permuted.</p>
<p><strong>Permuted block randomization — varying block sizes</strong><br>
The block size itself is randomly selected from a prespecified set (e.g., 2, 4 and 6). Each block remains internally permuted. This reduces predictability compared with fixed small blocks.</p>
<p><strong>Do:</strong><br>
- Use permuted blocks to maintain balance during enrollment.<br>
- Prefer varying block sizes to protect allocation concealment.<br>
- Ensure block size is a multiple of the allocation ratio (e.g., multiple of 2 for 1:1 allocation).<br>
- Restrict knowledge of block sizes to the unblinded randomization statistician/system.</p>
<p><strong>Do not:</strong><br>
- Use small fixed block sizes when assignments could be inferred.<br>
- Disclose block size in widely distributed protocol or SAP documents.<br>
- Confuse allocation concealment with blinding.</p>
</div>
</div>
</div>
</section>
<section id="the-statistical-consequences-of-broken-allocation-concealment" class="level2">
<h2 class="anchored" data-anchor-id="the-statistical-consequences-of-broken-allocation-concealment">The Statistical Consequences of Broken Allocation Concealment</h2>
<p>Empirical evidence shows that trials with inadequate allocation concealment:</p>
<ul>
<li><p>Systematically overestimate treatment effects</p></li>
<li><p>Are more likely to report statistically significant results</p></li>
<li><p>Introduce selection bias at enrollment</p></li>
</ul>
</section>
<section id="what-the-protocol-should-say" class="level2">
<h2 class="anchored" data-anchor-id="what-the-protocol-should-say">What the Protocol Should Say</h2>
<p>Instead of specifying block size, a protocol can say:</p>
<blockquote class="blockquote">
<p><strong>Participants will be randomized in a 1:1 ratio using a centralized, computer-generated permuted block randomization schedule. Details of the randomization sequence will be maintained by the unblinded statistician to ensure allocation concealment.</strong></p>
</blockquote>
<p>That is sufficient. Regulators do not require disclosure of block size in public-facing documents.</p>
</section>
<section id="takeaway" class="level2">
<h2 class="anchored" data-anchor-id="takeaway">Takeaway</h2>
<ul>
<li><p>Block size is an operational detail. Its disclosure does not improve reproducibility, transparency, or statistical validity. But it can undermine allocation concealment.</p></li>
<li><p>And once allocation concealment is compromised, the trial is vulnerable to selection bias even if it remains fully blinded.</p></li>
<li><p>Protecting allocation concealment is protecting the integrity of randomization itself.</p></li>
<li><p>Block size should be known only to the unblinded randomization statistician or system.</p></li>
<li><p>Regulators do not require disclosure of block size in public-facing documents.</p></li>
</ul>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<p>International Council for Harmonisation of Technical Requirements for Pharmaceuticals for Human Use. (1998). <em>ICH E9: Statistical principles for clinical trials</em>.</p>
<p>International Council for Harmonisation of Technical Requirements for Pharmaceuticals for Human Use. (2019). <em>ICH E9(R1) addendum on estimands and sensitivity analysis in clinical trials</em>.</p>
<p>International Council for Harmonisation of Technical Requirements for Pharmaceuticals for Human Use. (2016). <em>ICH E6(R2): Guideline for good clinical practice</em>.</p>
<p>Schulz, K. F., Altman, D. G., &amp; Moher, D., for the CONSORT Group. (2010). CONSORT 2010 statement: Updated guidelines for reporting parallel group randomized trials. <em>BMJ, 340</em>, c332. <a href="https://doi.org/10.1136/bmj.c332" class="uri">https://doi.org/10.1136/bmj.c332</a></p>
<p>Schulz, K. F., Chalmers, I., Hayes, R. J., &amp; Altman, D. G. (1995). Empirical evidence of bias: Dimensions of methodological quality associated with estimates of treatment effects in controlled trials. <em>JAMA, 273</em>(5), 408–412. <a href="https://jamanetwork.com/journals/jama/article-abstract/386770">https://doi.org/10.1001/jama.1995.03520290060030</a></p>
<p>Schulz, K. F., &amp; Grimes, D. A. (2002). Allocation concealment in randomised trials: Defending against deciphering. <em>The Lancet, 359</em>(9306), 614–618. <a href="https://www.thelancet.com/journals/lancet/article/PIIS0140-6736(02)07750-4/abstract">https://doi.org/10.1016/S0140-6736(02)07750-4</a></p>
<p>Moher, D., Pham, B., Jones, A., Cook, D. J., Jadad, A. R., Moher, M., Tugwell, P., &amp; Klassen, T. P. (1998). Does quality of reports of randomised trials affect estimates of intervention efficacy reported in meta-analyses? <em>The Lancet, 352</em>(9128), 609–613. <a href="https://www.thelancet.com/journals/lancet/article/PIIS0140-6736(98)01085-X/abstract">https://doi.org/10.1016/S0140-6736(98)01085-X</a></p>
<p>Savović, J., Jones, H. E., Altman, D. G., Harris, R. J., Jüni, P., Pildal, J., Als-Nielsen, B., Balk, E. M., Gluud, C., Gluud, L. L., Ioannidis, J. P. A., Schulz, K. F., Beynon, R., Welton, N. J., Wood, L., &amp; Sterne, J. A. C. (2012). Influence of reported study design characteristics on intervention effect estimates from randomized, controlled trials: Combined analysis of meta-epidemiological studies. <em>Annals of Internal Medicine, 157</em>(6), 429–438. <a href="https://www.acpjournals.org/doi/10.7326/0003-4819-157-6-201209180-00537" class="uri">https://www.acpjournals.org/doi/10.7326/0003-4819-157-6-201209180-00537</a></p>


</section>

 ]]></description>
  <category>randomization</category>
  <category>trial design</category>
  <guid>https://trialnotes.org/posts/block/</guid>
  <pubDate>Sun, 30 Nov 2025 05:00:00 GMT</pubDate>
</item>
<item>
  <title>Why Dichotomizing Continuous Variables Is a Mistake</title>
  <dc:creator>Fei Zuo</dc:creator>
  <link>https://trialnotes.org/posts/dichotomize/</link>
  <description><![CDATA[ 




<p><strong>🎧 1-minute summary</strong></p>
<p><em>Narration generated using OpenAI.fm.</em></p>
<audio controls="" preload="none" style="width:320px; margin-bottom:14px;">
<source src="../../audio/dicho_small.mp3" type="audio/mpeg">
</audio>
<p>Many clinical trial analyses still dichotomize continuous predictors. This feels simple. It is not harmless.</p>
<p>Let’s simulate a clean linear relationship and see what happens.</p>
<section id="simulation-setup" class="level2">
<h2 class="anchored" data-anchor-id="simulation-setup">Simulation setup</h2>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="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;">1</span>)</span>
<span id="cb1-2"></span>
<span id="cb1-3">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;">500</span></span>
<span id="cb1-4">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-5">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>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>
<span id="cb1-6"></span>
<span id="cb1-7">d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(x, y)</span></code></pre></div>
</details>
</div>
<p>Here, the outcome <img src="https://latex.codecogs.com/png.latex?y"> depends linearly on the predictor <img src="https://latex.codecogs.com/png.latex?x">.</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Ay%20=%202x%20+%20%5Cepsilon,%20%5Cquad%20%5Cepsilon%20%5Csim%20N(0,1)%0A"></p>
</section>
<section id="model-using-a-continuous-predictor" class="level2">
<h2 class="anchored" data-anchor-id="model-using-a-continuous-predictor">Model using a continuous predictor</h2>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">fit_cont <span class="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="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(fit_cont)</span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
Call:
lm(formula = y ~ x, data = d)

Residuals:
     Min       1Q   Median       3Q      Max 
-2.94113 -0.74507  0.01663  0.72882  3.11131 

Coefficients:
            Estimate Std. Error t value Pr(&gt;|t|)    
(Intercept) -0.04496    0.04730  -0.951    0.342    
x            1.95692    0.04678  41.832   &lt;2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.057 on 498 degrees of freedom
Multiple R-squared:  0.7785,    Adjusted R-squared:  0.778 
F-statistic:  1750 on 1 and 498 DF,  p-value: &lt; 2.2e-16</code></pre>
</div>
</div>
<p>This model uses the full information contained in the predictor <img src="https://latex.codecogs.com/png.latex?x">.</p>
<p>The estimated coefficient represents the expected change in <img src="https://latex.codecogs.com/png.latex?y"> for a one-unit increase in <img src="https://latex.codecogs.com/png.latex?x">.</p>
</section>
<section id="model-using-a-dichotomized-predictor" class="level2">
<h2 class="anchored" data-anchor-id="model-using-a-dichotomized-predictor">Model using a dichotomized predictor</h2>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>x_cat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>x), <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="cb4-2">fit_cat <span class="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_cat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d)</span>
<span id="cb4-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(fit_cat)</span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
Call:
lm(formula = y ~ x_cat, data = d)

Residuals:
    Min      1Q  Median      3Q     Max 
-4.6942 -1.1305 -0.0022  1.0593  6.1757 

Coefficients:
            Estimate Std. Error t value Pr(&gt;|t|)    
(Intercept)  -1.5672     0.1017  -15.42   &lt;2e-16 ***
x_cat         3.1330     0.1438   21.79   &lt;2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.607 on 498 degrees of freedom
Multiple R-squared:  0.4881,    Adjusted R-squared:  0.4871 
F-statistic: 474.9 on 1 and 498 DF,  p-value: &lt; 2.2e-16</code></pre>
</div>
</div>
<p>This replaces the continuous predictor with a binary variable indicating whether the value of <img src="https://latex.codecogs.com/png.latex?x"> is at or above the median versus below the median.</p>
<p>Instead of estimating a slope, the model now estimates the <strong>difference in mean outcome between the two groups</strong>.</p>
</section>
<section id="comparing-r-squared" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="comparing-r-squared">Comparing R-squared</h2>

<div class="no-row-height column-margin column-container"><section id="about-r²" class="level3">
<h3 class="anchored" data-anchor-id="about-r²">About R²</h3>
<p>R² (coefficient of determination) is the proportion of variability in the outcome explained by the predictors in the model:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AR%5E2%20=%201%20-%20%5Cfrac%7B%5Ctext%7BRSS%7D%7D%7B%5Ctext%7BTSS%7D%7D%0A"></p>
<p>Where:</p>
<ul>
<li><p><strong>RSS</strong> = Residual Sum of Squares</p></li>
<li><p><strong>TSS</strong> = Total Sum of Squares</p></li>
</ul>
<p>Interpretation:</p>
<ul>
<li><strong>R² = 0</strong> means the model explains none of the variability.</li>
<li><strong>R² = 0.40</strong> means 40% of the variability in the outcome is explained by the predictors.</li>
<li><strong>R² = 1</strong> means perfect fit (rare outside of overfitting).</li>
</ul>
<p>Cautions:</p>
<ul>
<li>R² is not a causal measure.</li>
<li>A high value does not imply a correct mode.</li>
<li>R² always increases when more predictors are added, even if they are irrelevant.</li>
<li>For non-linear models (e.g., logistic regression), pseudo-R² measures do not have the same interpretation.</li>
</ul>
</section></div><div class="cell">
<details class="code-fold">
<summary>Code</summary>
<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;">summary</span>(fit_cont)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r.squared </span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.7784605</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<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;">summary</span>(fit_cat)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r.squared</span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.4881285</code></pre>
</div>
</div>
<p>In this simulation, comparing R² between models shows how dichotomizing a predictor discards information — the explanatory power decreases even though the underlying relationship is unchanged.</p>
<p>The model using a dichotomized predictor throws away information. The estimated relationship becomes less precise and less powerful.</p>
</section>
<section id="why-information-is-lost" class="level2">
<h2 class="anchored" data-anchor-id="why-information-is-lost">Why information is lost</h2>
<p>The continuous model uses the full range of variation in the predictor. The dichotomized model only uses whether the value falls above or below a threshold. Observations with very different values of <img src="https://latex.codecogs.com/png.latex?x"> are treated as identical if they fall in the same category.</p>
<p>For example, values of <img src="https://latex.codecogs.com/png.latex?x=0.1"> and <img src="https://latex.codecogs.com/png.latex?x=3.0"> would both be coded as <strong>1</strong> if they fall at or above the median, even though they carry very different information about the outcome.</p>
<p>This loss of information reduces the model’s ability to explain variability in the outcome and weakens its ability to detect real relationships.</p>
</section>
<section id="takeaway" class="level2">
<h2 class="anchored" data-anchor-id="takeaway">Takeaway</h2>
<p>Categorizing a continuous predictor throws away information and reduces statistical efficiency. Unless there is a compelling clinical reason, predictors should generally be analyzed on their original continuous scale.</p>


</section>

 ]]></description>
  <category>modelling</category>
  <category>regression</category>
  <category>simulation</category>
  <guid>https://trialnotes.org/posts/dichotomize/</guid>
  <pubDate>Sun, 26 Oct 2025 04:00:00 GMT</pubDate>
</item>
</channel>
</rss>
