<?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>Kaique Alves Blog</title>
<link>https://alvesks.com.br/blog/</link>
<atom:link href="https://alvesks.com.br/blog/index.xml" rel="self" type="application/rss+xml"/>
<description>Technical notes and tutorials in plant disease epidemiology, modeling, and quantitative plant pathology.</description>
<generator>quarto-1.9.37</generator>
<lastBuildDate>Sun, 12 Apr 2026 03:00:00 GMT</lastBuildDate>
<item>
  <title>Simulating epidemics with epifitter: initial inoculum and infection rate</title>
  <dc:creator>Kaique Alves</dc:creator>
  <link>https://alvesks.com.br/blog/posts/epifitter-epidemias/</link>
  <description><![CDATA[ 





<p>Hello everyone!</p>
<p>In plant disease epidemiology, much of the biological interpretation of an epidemic depends on the shape of the disease progress curve. Two epidemics may reach similar final severity levels and still reflect very different processes in terms of initial establishment, growth rate, and the moment at which the system enters a phase of rapid expansion.</p>
<p>Consider, for example, two hypothetical situations. In the first, the epidemic is detected early because the system already starts the season with a relatively large amount of inoculum. In the second, the epidemic begins at a very low level but progresses rapidly because environmental conditions are highly favorable for infection, colonization, and pathogen reproduction. In both cases, an observer may record high disease intensity in late assessments, but the underlying epidemiological explanation is not the same.</p>
<p>This is precisely where simulation becomes useful. By simulating disease progress curves, we can isolate parameters, control assumptions, and examine how specific changes affect epidemic dynamics through time. The <a href="https://alvesks.github.io/epifitter/" target="_blank"><code>epifitter</code></a> package is particularly valuable in this context because it generates synthetic epidemics from classical epidemiological models, allowing theoretical concepts to be translated into clear visual demonstrations.</p>
<p>In this post, I focus on two central parameters of temporal epidemiology:</p>
<ul>
<li><code>y0</code>: the initial inoculum, that is, the initial disease intensity at the beginning of the epidemic</li>
<li><code>r</code>: the apparent infection rate, that is, the parameter controlling the speed of epidemic progress through time</li>
</ul>
<p>The goal here is to provide a more technical and conceptual discussion than a purely operational tutorial, using <code>epifitter</code> to show why these parameters are not interchangeable and why their interpretation requires care.</p>
<section id="what-epifitter-can-simulate" class="level2">
<h2 class="anchored" data-anchor-id="what-epifitter-can-simulate">What <code>epifitter</code> can simulate</h2>
<p>In the official <code>epifitter</code> documentation, the <code>sim_</code> family of functions can be used to generate disease progress curves under several classical epidemiological models, including exponential, monomolecular, logistic, and Gompertz models. In the package simulation article, the main arguments include:</p>
<ul>
<li><code>N</code>: total epidemic duration in time units</li>
<li><code>dt</code>: interval between consecutive assessments</li>
<li><code>y0</code>: initial disease intensity or initial inoculum</li>
<li><code>r</code>: apparent infection rate</li>
<li><code>n</code>: number of replications</li>
<li><code>alpha</code>: magnitude of random noise applied to the replications</li>
</ul>
<p>From a methodological perspective, this makes the package very useful for teaching, scenario exploration, and epidemiological reasoning before moving to formal model fitting with empirical data.</p>
</section>
<section id="loading-the-packages" class="level2">
<h2 class="anchored" data-anchor-id="loading-the-packages">Loading the packages</h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(epifitter)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(dplyr)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cowplot)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggthemes)</span></code></pre></div>
</div>
</section>
<section id="initial-inoculum-as-the-boundary-condition-of-the-epidemic" class="level2">
<h2 class="anchored" data-anchor-id="initial-inoculum-as-the-boundary-condition-of-the-epidemic">Initial inoculum as the boundary condition of the epidemic</h2>
<p>In mathematical and epidemiological terms, <code>y0</code> can be understood as the initial condition of the system. It defines the starting point of the epidemic at time zero. Therefore, when we compare epidemics under the same model and with the same value of <code>r</code>, differences in <code>y0</code> mainly affect the initial position of the curve and, consequently, the moment at which the epidemic becomes detectable or epidemiologically relevant.</p>
<p>Biologically, larger values of <code>y0</code> may reflect:</p>
<ul>
<li>greater inoculum survival between seasons</li>
<li>a larger initial source of infection</li>
<li>earlier presence of infected tissue</li>
<li>a higher probability of detecting the epidemic in the first assessments</li>
</ul>
<p>In the example below, <code>r</code> is held constant while only <code>y0</code> changes.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">epi_y0_baixo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sim_logistic</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;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dt =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.12</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;">1</span>)</span>
<span id="cb2-2">epi_y0_medio <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sim_logistic</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;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dt =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>,  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.12</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;">1</span>)</span>
<span id="cb2-3">epi_y0_alto  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sim_logistic</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;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dt =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>,  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.12</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;">1</span>)</span>
<span id="cb2-4"></span>
<span id="cb2-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb2-6">  epi_y0_baixo <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low y0"</span>),</span>
<span id="cb2-7">  epi_y0_medio <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"medium y0"</span>),</span>
<span id="cb2-8">  epi_y0_alto  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high y0"</span>)</span>
<span id="cb2-9">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(time, y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> scenario)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_colorblind</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_half_open</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb2-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Changing only the initial inoculum"</span>,</span>
<span id="cb2-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Time"</span>,</span>
<span id="cb2-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease intensity"</span>,</span>
<span id="cb2-18">    <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;">"Scenario"</span></span>
<span id="cb2-19">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>()</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/epifitter-epidemias/epifitter-epidemias_files/figure-html/unnamed-chunk-2-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>The epidemiological interpretation of this graph is relatively straightforward:</p>
<ul>
<li>with low <code>y0</code>, the epidemic remains at very low intensity for longer</li>
<li>with high <code>y0</code>, the curve starts from a more advanced level</li>
<li>the main difference lies in the temporal position of the epidemic, not necessarily in the maximum slope of the curve</li>
</ul>
<p>This matters because two fields may display similar final severities while having started the epidemic process at very different moments. From the perspective of monitoring and management, this distinction is crucial.</p>
</section>
<section id="apparent-infection-rate-as-a-velocity-parameter" class="level2">
<h2 class="anchored" data-anchor-id="apparent-infection-rate-as-a-velocity-parameter">Apparent infection rate as a velocity parameter</h2>
<p>If <code>y0</code> defines the initial condition, <code>r</code> controls how quickly the epidemic expands. In disease progress models, <code>r</code> is usually interpreted as an aggregate parameter of epidemic efficiency, reflecting how strongly disease increases through time within the structure of the chosen model.</p>
<p>Larger values of <code>r</code> may be associated with:</p>
<ul>
<li>environmental conditions more favorable for infection</li>
<li>greater efficiency of host colonization</li>
<li>shorter or more intense secondary cycles</li>
<li>greater host susceptibility</li>
</ul>
<p>In the next example, <code>y0</code> is fixed and only <code>r</code> changes.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">epi_r_baixo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sim_logistic</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;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dt =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb3-2">epi_r_medio <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sim_logistic</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;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dt =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.12</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;">1</span>)</span>
<span id="cb3-3">epi_r_alto  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sim_logistic</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;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dt =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.22</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;">1</span>)</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb3-6">  epi_r_baixo <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low r"</span>),</span>
<span id="cb3-7">  epi_r_medio <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"medium r"</span>),</span>
<span id="cb3-8">  epi_r_alto  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high r"</span>)</span>
<span id="cb3-9">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(time, y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> scenario)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_colorblind</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_half_open</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb3-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Changing only the apparent infection rate"</span>,</span>
<span id="cb3-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Time"</span>,</span>
<span id="cb3-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease intensity"</span>,</span>
<span id="cb3-18">    <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;">"Scenario"</span></span>
<span id="cb3-19">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>()</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/epifitter-epidemias/epifitter-epidemias_files/figure-html/unnamed-chunk-3-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>Here, the interpretation is different from the one observed for <code>y0</code>:</p>
<ul>
<li>with low <code>r</code>, the epidemic progresses slowly</li>
<li>with high <code>r</code>, epidemic growth is much faster</li>
<li>the main difference lies in the slope of the curve and the time required to reach high disease levels</li>
</ul>
<p>In practical terms, this means that epidemics with the same starting point may diverge substantially over time if the environment, host, or pathogen changes the efficiency of the infection process.</p>
</section>
<section id="why-y0-and-r-may-confound-interpretation" class="level2">
<h2 class="anchored" data-anchor-id="why-y0-and-r-may-confound-interpretation">Why <code>y0</code> and <code>r</code> may confound interpretation</h2>
<p>One reason simulation is so useful is that, in observational data, it is not always trivial to distinguish the effect of <code>y0</code> from the effect of <code>r</code>. In many situations, an observer may conclude that one epidemic is â€œmore severeâ€ simply because it appears more advanced at a given moment. However, this impression may arise either from a larger initial inoculum or from a higher progression rate.</p>
<p>For example:</p>
<ul>
<li>an epidemic with high <code>y0</code> and moderate <code>r</code> may appear more advanced early on</li>
<li>an epidemic with low <code>y0</code> and high <code>r</code> may quickly overtake another curve after a short time interval</li>
</ul>
<p>In other words, starting earlier is not the same as progressing faster. This distinction is conceptually important when comparing treatments, genotypes, seasons, locations, or management systems.</p>
</section>
<section id="a-simple-factorial-experiment" class="level2">
<h2 class="anchored" data-anchor-id="a-simple-factorial-experiment">A simple factorial experiment</h2>
<p>A useful strategy for visualizing this interaction is to combine different values of <code>y0</code> and <code>r</code> in a grid of scenarios.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">cenarios <span class="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="cb4-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</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.001</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>),</span>
<span id="cb4-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.12</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.22</span>)</span>
<span id="cb4-4">)</span>
<span id="cb4-5"></span>
<span id="cb4-6">simulacoes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_len</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(cenarios)), <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(i) {</span>
<span id="cb4-8">    y0_i <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cenarios<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>y0[i]</span>
<span id="cb4-9">    r_i <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cenarios<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r[i]</span>
<span id="cb4-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sim_logistic</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;">60</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dt =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> y0_i, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> r_i, <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;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-11">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb4-12">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> y0_i,</span>
<span id="cb4-13">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> r_i,</span>
<span id="cb4-14">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y0 = "</span>, y0_i, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" | r = "</span>, r_i)</span>
<span id="cb4-15">      )</span>
<span id="cb4-16">  })</span>
<span id="cb4-17">)</span>
<span id="cb4-18"></span>
<span id="cb4-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(simulacoes, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(time, y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</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;">"#0b6e4f"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> scenario) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_half_open</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb4-25">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Combining different values of y0 and r"</span>,</span>
<span id="cb4-26">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Time"</span>,</span>
<span id="cb4-27">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease intensity"</span></span>
<span id="cb4-28">  )</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/epifitter-epidemias/epifitter-epidemias_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="960"></p>
</figure>
</div>
</div>
</div>
<p>This grid makes three points especially clear:</p>
<ul>
<li><code>y0</code> shifts the epidemic along the time axis</li>
<li><code>r</code> changes the speed of epidemic growth</li>
<li>the combination of both may profoundly alter epidemiological interpretation</li>
</ul>
</section>
<section id="comparing-both-effects-side-by-side" class="level2">
<h2 class="anchored" data-anchor-id="comparing-both-effects-side-by-side">Comparing both effects side by side</h2>
<p>A useful complementary visualization is to contrast, in parallel panels, the isolated effect of <code>y0</code> and the isolated effect of <code>r</code>.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">plot_y0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb5-2">  epi_y0_baixo <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low y0"</span>),</span>
<span id="cb5-3">  epi_y0_medio <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"medium y0"</span>),</span>
<span id="cb5-4">  epi_y0_alto  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high y0"</span>)</span>
<span id="cb5-5">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(time, y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> scenario)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_colorblind</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_half_open</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb5-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Effect of y0"</span>,</span>
<span id="cb5-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Time"</span>,</span>
<span id="cb5-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease intensity"</span>,</span>
<span id="cb5-15">    <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;">"Scenario"</span></span>
<span id="cb5-16">  )</span>
<span id="cb5-17"></span>
<span id="cb5-18">plot_r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb5-19">  epi_r_baixo <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"low r"</span>),</span>
<span id="cb5-20">  epi_r_medio <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"medium r"</span>),</span>
<span id="cb5-21">  epi_r_alto  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high r"</span>)</span>
<span id="cb5-22">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(time, y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> scenario)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_colorblind</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_half_open</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb5-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Effect of r"</span>,</span>
<span id="cb5-30">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Time"</span>,</span>
<span id="cb5-31">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease intensity"</span>,</span>
<span id="cb5-32">    <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;">"Scenario"</span></span>
<span id="cb5-33">  )</span>
<span id="cb5-34"></span>
<span id="cb5-35"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot_grid</span>(plot_y0, plot_r, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</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;">"A"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"B"</span>))</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/epifitter-epidemias/epifitter-epidemias_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="1152"></p>
</figure>
</div>
</div>
</div>
<p>This contrast makes clear that <code>y0</code> and <code>r</code> affect different dimensions of the curve. The first mainly changes the initial condition; the second mainly changes the velocity of epidemic expansion.</p>
</section>
<section id="what-if-i-use-other-models" class="level2">
<h2 class="anchored" data-anchor-id="what-if-i-use-other-models">What if I use other models?</h2>
<p>The same reasoning can be extended to other models available in <code>epifitter</code>, such as:</p>
<ul>
<li><code>sim_exponential()</code></li>
<li><code>sim_monomolecular()</code></li>
<li><code>sim_logistic()</code></li>
<li><code>sim_gompertz()</code></li>
</ul>
<p>The biological role of <code>y0</code> and <code>r</code> remains central, but the way these effects are visually expressed depends on the mathematical structure of the model. For that reason, simulation is not just about producing attractive curves; it is about making explicit the epidemiological assumptions embedded in each equation.</p>
</section>
<section id="conclusion" class="level2">
<h2 class="anchored" data-anchor-id="conclusion">Conclusion</h2>
<p>From an epidemiological perspective:</p>
<ul>
<li><code>y0</code> answers the question: where does the epidemic start?</li>
<li><code>r</code> answers the question: how fast does it advance?</li>
</ul>
<p>These parameters are complementary, but not equivalent. Understanding this distinction is essential for interpreting disease progress curves, comparing epidemics, and discussing biological mechanisms with greater rigor.</p>
<p><code>epifitter</code> provides a very effective way of translating this discussion into clear and reproducible visual demonstrations. For teaching, conceptual exploration, and hypothesis building, this type of simulation is particularly valuable.</p>
<p>In a future post, I can extend this discussion by explicitly comparing the <strong>exponential, monomolecular, logistic, and Gompertz</strong> models, highlighting how the interpretation of <code>y0</code> and <code>r</code> changes with model structure.</p>


</section>

 ]]></description>
  <category>English</category>
  <category>epidemiology</category>
  <category>epifitter</category>
  <category>simulation</category>
  <category>plant pathology</category>
  <guid>https://alvesks.com.br/blog/posts/epifitter-epidemias/</guid>
  <pubDate>Sun, 12 Apr 2026 03:00:00 GMT</pubDate>
</item>
<item>
  <title>Modeling plant disease yield loss: attainable yield, slope, damage coefficient, mixed-effects models, and meta-analysis</title>
  <dc:creator>Kaique Alves</dc:creator>
  <link>https://alvesks.com.br/blog/posts/yield-loss/</link>
  <description><![CDATA[ 





<p>In plant pathology, we often spend a lot of time measuring disease. We estimate severity, count symptomatic plants, follow epidemics through time, and compare treatments, cultivars, or environments. Those measurements are essential, but they are rarely the final question. At some point, the agronomic question becomes much more direct: <strong>how much yield is being lost because of disease?</strong></p>
<p>That question is simple to ask and surprisingly easy to answer poorly. A field with more disease often yields less, but the size of that loss depends on when disease occurred, how it was measured, how much disease contrast the study captured, and what the crop could have produced in the absence of disease. Two studies may show similar final severity and still imply different levels of damage if they differ in cultivar, season, management, weather, or attainable yield.</p>
<p>This is why yield loss modeling is useful. It gives us a way to connect disease intensity with crop performance, rather than stopping at disease intensity alone. In practical terms, this connection helps with crop-loss assessment, breeding decisions, cultivar comparisons, fungicide evaluation, and broader questions about disease risk under different environments.</p>
<p>The goal of this article is to build that logic step by step. I start with the basic idea of a damage function, using severity as the disease measure for clarity. Then I show how the same idea can be extended when the data come from several studies rather than from a single clean experiment. The examples later in the post use mixed-effects models and meta-analysis, but the introduction is not about the software. The main point is to understand what we are trying to estimate, why the data structure matters, and how each modeling choice changes the interpretation.</p>
<p>The tutorial is informed by the broader crop-loss literature in plant pathology and by my recent work on soybean rust damage under climate variability in Brazil. However, the dataset used below is simulated. I use simulated data so the workflow can be shown transparently, with known structure and with a few intentionally problematic studies that make the selection step visible. The numerical results in this post should therefore be read as teaching outputs, not as empirical evidence about soybean rust, ENSO, or any specific pathosystem. For empirical estimates and scientific conclusions, see the corresponding <a href="https://bsppjournals.onlinelibrary.wiley.com/doi/full/10.1111/ppa.70069" target="_blank">Plant Pathology paper</a> and <a href="https://alvesks.github.io/paper_ENSO_SBR_damage/main_damage_coef.html" target="_blank">analysis page</a>.</p>
<p>One practical issue will appear early in the workflow: study selection. In disease-yield analysis, not every study is equally informative for estimating damage. We need enough disease contrast, enough disease pressure, and a plausible basis for estimating yield in the absence of disease. This is not just data cleaning; it defines the evidence used to estimate the relationship between disease and yield.</p>
<section id="why-yield-loss-models-matter" class="level2">
<h2 class="anchored" data-anchor-id="why-yield-loss-models-matter">Why yield loss models matter</h2>
<p>Before writing any code, it is worth slowing down and asking what a yield loss model is supposed to do. The model is not just a convenient way to draw a line through points. It is a way to translate disease measurements into an agronomic consequence.</p>
<p>The biological premise is straightforward: increasing disease burden is generally associated with declining yield. However, the epidemiological interpretation depends strongly on how that relationship is parameterized, how disease was assessed, and on which quantity is treated as the inferential target.</p>
<p>The disease variable in a yield loss model should not be treated as an interchangeable number. Final severity, severity at a specific growth stage, AUDPC, healthy area duration, or another disease metric may each represent a different biological pathway from infection to damage. In this article I use severity as the explanatory variable for clarity, but the same modeling logic only becomes meaningful when the disease metric is aligned with the crop growth period in which yield is actually being determined.</p>
<p>A classical linear damage function may be written as:</p>
<p><img src="https://latex.codecogs.com/png.latex?Y%20=%20b_0%20+%20b_1%20D"></p>
<p>where:</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?Y"> is yield</li>
<li><img src="https://latex.codecogs.com/png.latex?D"> is disease intensity, frequently represented by severity in percentage terms</li>
<li><img src="https://latex.codecogs.com/png.latex?b_0"> is the intercept, commonly interpreted as attainable yield</li>
<li><img src="https://latex.codecogs.com/png.latex?b_1"> is the slope, describing the change in yield per unit increase in disease</li>
</ul>
<p>In most yield loss applications, <img src="https://latex.codecogs.com/png.latex?b_1"> is negative. Consequently, a steeper negative slope indicates greater damage per unit increase in disease intensity.</p>
<p>From this formulation, we often derive the <strong>damage coefficient</strong>, a relative measure that expresses the proportional reduction in yield associated with each 1 percentage-point increase in disease:</p>
<p><img src="https://latex.codecogs.com/png.latex?DC%20=%20-100%20%5Ctimes%20%5Cfrac%7Bb_1%7D%7Bb_0%7D"></p>
<p>This quantity is especially useful because it rescales the slope by the attainable yield. As a consequence, comparisons of disease damage become more interpretable across studies or environments that differ substantially in yield potential.</p>
<p>With that basic relationship in place, the next step is to separate the pieces of the model. This matters because the intercept, slope, and damage coefficient are often discussed together, but they do not answer the same biological question.</p>
</section>
<section id="the-main-parameters" class="level2">
<h2 class="anchored" data-anchor-id="the-main-parameters">The main parameters</h2>
<p>Before discussing model fitting, it is useful to clarify the epidemiological interpretation of the main parameters. This section is intentionally short: the goal is to give the reader a mental map before the tutorial starts using these terms repeatedly.</p>
<section id="attainable-yield" class="level3">
<h3 class="anchored" data-anchor-id="attainable-yield">Attainable yield</h3>
<p>Attainable yield is the expected yield in the absence of disease within the production context under study. In a simple linear damage function, it is approximated by the intercept <img src="https://latex.codecogs.com/png.latex?b_0">. Biologically, it is not a universal constant; rather, it is conditional on cultivar, environment, season, management, and the entire set of factors that define the production system. Statistically, it is most credible when the study includes observations close enough to low disease levels to support that extrapolation.</p>
</section>
<section id="slope" class="level3">
<h3 class="anchored" data-anchor-id="slope">Slope</h3>
<p>The slope <img src="https://latex.codecogs.com/png.latex?b_1"> quantifies the rate at which yield changes as disease intensity increases. If disease severity is measured in percentage points and yield in kg/ha, then the slope is interpreted as kg/ha lost per 1 percentage-point increase in severity. This interpretation is conditional on the observed disease range; slopes estimated from narrow or very low severity gradients are often unstable and should not be extrapolated to high disease pressure.</p>
</section>
<section id="damage-coefficient" class="level3">
<h3 class="anchored" data-anchor-id="damage-coefficient">Damage coefficient</h3>
<p>The damage coefficient is the relative expression of the slope. It addresses a more transportable epidemiological question: what fraction of attainable yield is lost for each unit increase in disease? This is particularly valuable when comparing studies conducted under distinct yield potentials, provided the attainable-yield estimate and the observed disease gradient are both credible.</p>
</section>
</section>
<section id="a-conceptual-example" class="level2">
<h2 class="anchored" data-anchor-id="a-conceptual-example">A conceptual example</h2>
<p>A convenient way to clarify the epidemiological role of these parameters is to vary them one at a time. I therefore use three separate conceptual plots rather than a single composite figure so that the contribution of each parameter remains explicit.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Load packages used throughout the tutorial.</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cowplot)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggthemes)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(lme4)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(lmerTest)</span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(metafor)</span>
<span id="cb1-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(knitr)</span>
<span id="cb1-9"></span>
<span id="cb1-10">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span>opts_chunk<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">message =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warning =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Use one plot theme and one random seed so the examples are reproducible.</span></span>
<span id="cb1-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_set</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_half_open</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>))</span>
<span id="cb1-14"><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;">42</span>)</span>
<span id="cb1-15"></span>
<span id="cb1-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Shared colors for ENSO phases in all figures.</span></span>
<span id="cb1-17">enso_palette <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb1-18">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Neutral"</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;">"#1A1A1A"</span>,</span>
<span id="cb1-19">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</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;">"#D99500"</span>,</span>
<span id="cb1-20">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</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;">"#67B7F7"</span></span>
<span id="cb1-21">)</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Severity grid used by the simple conceptual examples.</span></span>
<span id="cb2-2">severity_grid <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">severity =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">70</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb2-3"></span>
<span id="cb2-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Same slope, different intercepts: isolates attainable yield.</span></span>
<span id="cb2-5">attainable_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;">bind_rows</span>(</span>
<span id="cb2-6">  severity_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yield =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4800</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;">22</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> severity,</span>
<span id="cb2-8">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Higher attainable yield"</span>),</span>
<span id="cb2-9">  severity_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yield =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3900</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;">22</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> severity,</span>
<span id="cb2-11">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lower attainable yield"</span>)</span>
<span id="cb2-12">)</span>
<span id="cb2-13"></span>
<span id="cb2-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Same intercept, different slopes: isolates damage rate.</span></span>
<span id="cb2-15">slope_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;">bind_rows</span>(</span>
<span id="cb2-16">  severity_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-17">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yield =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4300</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;">14</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> severity,</span>
<span id="cb2-18">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lower damage slope"</span>),</span>
<span id="cb2-19">  severity_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yield =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4300</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;">30</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> severity,</span>
<span id="cb2-21">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Higher damage slope"</span>)</span>
<span id="cb2-22">)</span>
<span id="cb2-23"></span>
<span id="cb2-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Different intercepts and slopes: closer to empirical heterogeneity.</span></span>
<span id="cb2-25">combined_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;">bind_rows</span>(</span>
<span id="cb2-26">  severity_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-27">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yield =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4700</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;">14</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> severity,</span>
<span id="cb2-28">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"High yield, low damage"</span>),</span>
<span id="cb2-29">  severity_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-30">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yield =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3900</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;">30</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> severity,</span>
<span id="cb2-31">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenario =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Low yield, high damage"</span>)</span>
<span id="cb2-32">)</span></code></pre></div></div>
</details>
</div>
<section id="changing-only-attainable-yield" class="level3">
<h3 class="anchored" data-anchor-id="changing-only-attainable-yield">1. Changing only attainable yield</h3>
<p>The first plot isolates the effect of attainable yield while holding the slope constant.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">attainable_labels <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> attainable_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(scenario) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_tail</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;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>()</span>
<span id="cb3-5"></span>
<span id="cb3-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(attainable_df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, yield, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> scenario)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(</span>
<span id="cb3-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> attainable_labels,</span>
<span id="cb3-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> scenario),</span>
<span id="cb3-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.08</span>,</span>
<span id="cb3-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb3-13">    <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;">3.7</span>,</span>
<span id="cb3-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb3-15">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb3-17">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Higher attainable yield"</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;">"#0B6E4F"</span>,</span>
<span id="cb3-18">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lower attainable yield"</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;">"#C84C09"</span></span>
<span id="cb3-19">  )) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">82</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clip =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"off"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb3-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Changing only attainable yield"</span>,</span>
<span id="cb3-24">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb3-25">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yield (kg/ha)"</span></span>
<span id="cb3-26">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.margin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">margin</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">85</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>))</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-3-1.png" class="img-fluid figure-img" width="652"></p>
</figure>
</div>
</div>
</div>
<p>In this first case, both lines share the same slope, meaning that disease causes the same absolute yield reduction per unit increase in severity in both scenarios. The only difference lies in the intercept. Epidemiologically, this implies a difference in baseline productivity rather than a difference in the damage process itself.</p>
</section>
<section id="changing-only-slope" class="level3">
<h3 class="anchored" data-anchor-id="changing-only-slope">2. Changing only slope</h3>
<p>The next plot isolates the effect of the damage slope while holding attainable yield constant.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">slope_labels <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> slope_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(scenario) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_tail</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;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>()</span>
<span id="cb4-5"></span>
<span id="cb4-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(slope_df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, yield, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> scenario)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(</span>
<span id="cb4-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> slope_labels,</span>
<span id="cb4-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> scenario),</span>
<span id="cb4-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.08</span>,</span>
<span id="cb4-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb4-13">    <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;">3.7</span>,</span>
<span id="cb4-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb4-15">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb4-17">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lower damage slope"</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;">"#0B6E4F"</span>,</span>
<span id="cb4-18">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Higher damage slope"</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;">"#C84C09"</span></span>
<span id="cb4-19">  )) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">82</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clip =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"off"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb4-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Changing only slope"</span>,</span>
<span id="cb4-24">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb4-25">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yield (kg/ha)"</span></span>
<span id="cb4-26">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.margin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">margin</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">75</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>))</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="652"></p>
</figure>
</div>
</div>
</div>
<p>Here the intercept is identical in both scenarios, so attainable yield is unchanged. What differs is the rate at which yield declines as severity increases. This is the clearest graphical representation of the epidemiological meaning of the damage slope.</p>
</section>
<section id="changing-attainable-yield-and-slope-together" class="level3">
<h3 class="anchored" data-anchor-id="changing-attainable-yield-and-slope-together">3. Changing attainable yield and slope together</h3>
<p>This third plot combines both dimensions simultaneously, which is generally closer to the structure of empirical datasets.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">combined_labels <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> combined_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(scenario) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_tail</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;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>()</span>
<span id="cb5-5"></span>
<span id="cb5-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(combined_df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, yield, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> scenario)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(</span>
<span id="cb5-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> combined_labels,</span>
<span id="cb5-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> scenario),</span>
<span id="cb5-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.08</span>,</span>
<span id="cb5-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb5-13">    <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;">3.7</span>,</span>
<span id="cb5-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb5-15">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb5-17">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"High yield, low damage"</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;">"#0B6E4F"</span>,</span>
<span id="cb5-18">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Low yield, high damage"</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;">"#C84C09"</span></span>
<span id="cb5-19">  )) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">82</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clip =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"off"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb5-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Changing both parameters"</span>,</span>
<span id="cb5-24">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb5-25">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yield (kg/ha)"</span></span>
<span id="cb5-26">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.margin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">margin</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">70</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>))</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="652"></p>
</figure>
</div>
</div>
</div>
<p>This final case is usually the most realistic one in plant pathology. Empirical datasets commonly differ simultaneously in attainable yield and in damage slope. That is precisely why the damage coefficient is so useful: it rescales the slope by attainable yield and therefore improves interpretability across heterogeneous production contexts.</p>
<p>The conceptual example keeps the biology simple on purpose. Real yield loss datasets are rarely this clean. They usually combine several studies, years, disease gradients, and environmental contexts. The next section creates a simulated dataset with that kind of structure so that the modeling workflow has something realistic to work with.</p>
</section>
</section>
<section id="simulating-a-multi-study-dataset" class="level2">
<h2 class="anchored" data-anchor-id="simulating-a-multi-study-dataset">Simulating a multi-study dataset</h2>
<p>To demonstrate the models, I first simulate a candidate dataset that resembles a realistic plant pathology structure: multiple studies nested within years and conducted under different ENSO phases. Each study is allowed to have its own attainable yield and its own severity-yield slope. The point is not to mimic one particular experiment perfectly, but to create a dataset that contains the problems analysts commonly face in practice.</p>
<p>In practice, not every candidate study is equally informative for estimating yield loss. A study with almost no disease gradient, very low maximum severity, or an implausible estimated attainable yield may contribute more noise than information to the damage function. The simulation below therefore creates both informative studies and a small set of intentionally problematic studies, so that the selection step can be demonstrated before any mixed model or meta-analysis is fitted.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># One row per candidate study. The last six studies are deliberately</span></span>
<span id="cb6-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># constructed to fail one of the screening criteria later in the workflow.</span></span>
<span id="cb6-3">study_info <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb6-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">study =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</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;">24</span>),</span>
<span id="cb6-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2013</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;">2020</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)),</span>
<span id="cb6-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">times =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>),</span>
<span id="cb6-7">                <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;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>)),</span>
<span id="cb6-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">screening_scenario =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb6-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(study) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">19</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Limited severity range"</span>,</span>
<span id="cb6-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(study) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">22</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Low maximum severity"</span>,</span>
<span id="cb6-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(study) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">23</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"High intercept outlier"</span>,</span>
<span id="cb6-12">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(study) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Low intercept outlier"</span>,</span>
<span id="cb6-13">    <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Retained candidate"</span></span>
<span id="cb6-14">  )</span>
<span id="cb6-15">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-17">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ENSO phases are allowed to differ in attainable yield.</span></span>
<span id="cb6-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">attainable =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb6-19">      enso <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</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;">rnorm</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;">mean =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4350</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">180</span>),</span>
<span id="cb6-20">      enso <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Neutral"</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;">rnorm</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;">mean =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4200</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">180</span>),</span>
<span id="cb6-21">      enso <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</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;">rnorm</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;">mean =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4050</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">180</span>)</span>
<span id="cb6-22">    ),</span>
<span id="cb6-23">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Two studies receive unrealistic attainable-yield values so the</span></span>
<span id="cb6-24">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># intercept-outlier criterion can be demonstrated.</span></span>
<span id="cb6-25">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">attainable =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb6-26">      screening_scenario <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"High intercept outlier"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> attainable <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1600</span>,</span>
<span id="cb6-27">      screening_scenario <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Low intercept outlier"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> attainable <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1400</span>,</span>
<span id="cb6-28">      <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> attainable</span>
<span id="cb6-29">    ),</span>
<span id="cb6-30">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ENSO phases are also allowed to differ in disease damage slope.</span></span>
<span id="cb6-31">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">slope =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb6-32">      enso <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</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;">rnorm</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;">mean =</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;">30</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.5</span>),</span>
<span id="cb6-33">      enso <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Neutral"</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;">rnorm</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;">mean =</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;">22</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.0</span>),</span>
<span id="cb6-34">      enso <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</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;">rnorm</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;">mean =</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;">17</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.5</span>)</span>
<span id="cb6-35">    )</span>
<span id="cb6-36">  )</span>
<span id="cb6-37"></span>
<span id="cb6-38">candidate_damage_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> study_info <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmap</span>(</span>
<span id="cb6-40">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(attainable, slope, screening_scenario),</span>
<span id="cb6-41">    \(b0, b1, scenario) {</span>
<span id="cb6-42">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Problematic studies receive either a narrow severity range or</span></span>
<span id="cb6-43">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># very low maximum severity; the others span a wider disease gradient.</span></span>
<span id="cb6-44">      severity <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (scenario <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Limited severity range"</span>) {</span>
<span id="cb6-45">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">22</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">26</span>))</span>
<span id="cb6-46">      } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (scenario <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Low maximum severity"</span>) {</span>
<span id="cb6-47">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">9.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length.out =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>)</span>
<span id="cb6-48">      } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb6-49">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">70</span>))</span>
<span id="cb6-50">      }</span>
<span id="cb6-51">      </span>
<span id="cb6-52">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Yield follows a linear damage function plus observation-level noise.</span></span>
<span id="cb6-53">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb6-54">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">severity =</span> severity,</span>
<span id="cb6-55">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yield =</span> b0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> b1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> severity <span 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;">14</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">130</span>)</span>
<span id="cb6-56">      )</span>
<span id="cb6-57">    }</span>
<span id="cb6-58">  )) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-59">  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;">unnest</span>(data) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-60">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-61">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Keep simulated values inside plausible plotting bounds.</span></span>
<span id="cb6-62">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">severity =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(severity, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb6-63">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yield =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmax</span>(yield, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">600</span>)</span>
<span id="cb6-64">  )</span>
<span id="cb6-65"></span>
<span id="cb6-66"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Display only a few rows so the reader can inspect the generated structure.</span></span>
<span id="cb6-67">candidate_damage_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-68">  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;">select</span>(study, year, enso, screening_scenario, severity, yield) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-69">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_head</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;">8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-70">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"First rows of the simulated candidate multi-study dataset"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>First rows of the simulated candidate multi-study dataset</caption>
<thead>
<tr class="header">
<th style="text-align: left;">study</th>
<th style="text-align: left;">year</th>
<th style="text-align: left;">enso</th>
<th style="text-align: left;">screening_scenario</th>
<th style="text-align: right;">severity</th>
<th style="text-align: right;">yield</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">2.08</td>
<td style="text-align: right;">4286.70</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">2.28</td>
<td style="text-align: right;">4635.06</td>
</tr>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">6.28</td>
<td style="text-align: right;">4345.97</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">10.18</td>
<td style="text-align: right;">4221.84</td>
</tr>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">22.07</td>
<td style="text-align: right;">3819.73</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">23.27</td>
<td style="text-align: right;">3949.15</td>
</tr>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">23.76</td>
<td style="text-align: right;">3833.61</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">27.05</td>
<td style="text-align: right;">3784.80</td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
<section id="selecting-studies-for-damage-analysis" class="level2">
<h2 class="anchored" data-anchor-id="selecting-studies-for-damage-analysis">Selecting studies for damage analysis</h2>
<p>Once the candidate dataset exists, the next decision is not which model to fit. The next decision is whether the studies actually contain enough information to support a damage analysis.</p>
<p>At this stage, the workflow shifts from simulating candidate studies to deciding which studies are eligible for damage analysis. The screening is done at the study level, not at the observation level, because the inferential unit being accepted or rejected is the study-specific disease-yield relationship.</p>
<p>Here I use three transparent criteria. First, the within-study severity range must be greater than 5 percentage points. Second, the maximum severity observed within the study must be greater than 10%. Third, the intercept from the study-specific linear regression must not be an outlier according to the 1.5 IQR rule.</p>
<p>These criteria are not meant to prove that the selected studies are perfect. They are practical safeguards against estimating damage from studies with insufficient disease contrast, very low disease pressure, or implausible attainable-yield estimates. In an empirical analysis, the numerical thresholds should be justified before the final model is interpreted and, when possible, checked with sensitivity analyses. I keep this step explicit because reproducing a yield loss analysis requires reproducing both the model specification and the rules used to decide which studies are informative enough to enter the analysis.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Fit a simple study-specific regression only for screening purposes.</span></span>
<span id="cb7-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># These fits help diagnose whether each study has a usable disease-yield signal.</span></span>
<span id="cb7-3">study_screening <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> candidate_damage_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nest</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</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;">c</span>(study, year, enso, screening_scenario)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb7-6">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Criterion 1 and 2: disease contrast and disease pressure.</span></span>
<span id="cb7-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">severity_min =</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(data, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(.x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>severity)),</span>
<span id="cb7-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">severity_max =</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(data, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(.x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>severity)),</span>
<span id="cb7-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">severity_range =</span> severity_max <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> severity_min,</span>
<span id="cb7-10">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Criterion 3: attainable-yield plausibility via the intercept.</span></span>
<span id="cb7-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fit_yield =</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(data, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(yield <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> severity, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> .x)),</span>
<span id="cb7-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">intercept =</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(fit_yield, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(.x)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])),</span>
<span id="cb7-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">slope_yield =</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(fit_yield, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(.x)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]))</span>
<span id="cb7-14">)</span>
<span id="cb7-15"></span>
<span id="cb7-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Intercept outliers are detected across the candidate set using the 1.5 IQR rule.</span></span>
<span id="cb7-17">intercept_limits <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> study_screening <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb7-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q1 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(intercept, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>),</span>
<span id="cb7-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q3 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(intercept, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>),</span>
<span id="cb7-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iqr =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IQR</span>(intercept),</span>
<span id="cb7-22">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower =</span> q1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> iqr,</span>
<span id="cb7-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper =</span> q3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> iqr</span>
<span id="cb7-24">  )</span>
<span id="cb7-25"></span>
<span id="cb7-26">study_screening <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> study_screening <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb7-28">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Apply the three criteria and keep a human-readable reason for exclusion.</span></span>
<span id="cb7-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enough_gradient =</span> severity_range <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb7-30">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enough_maximum_severity =</span> severity_max <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span id="cb7-31">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">intercept_outlier =</span> intercept <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> intercept_limits<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>lower <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span></span>
<span id="cb7-32">      intercept <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> intercept_limits<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>upper,</span>
<span id="cb7-33">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">selected =</span> enough_gradient <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> enough_maximum_severity <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>intercept_outlier,</span>
<span id="cb7-34">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">screening_result =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb7-35">      <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>enough_gradient <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Removed: severity range &lt;= 5 p.p."</span>,</span>
<span id="cb7-36">      <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>enough_maximum_severity <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Removed: maximum severity &lt;= 10%"</span>,</span>
<span id="cb7-37">      intercept_outlier <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Removed: intercept outlier"</span>,</span>
<span id="cb7-38">      <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Selected"</span></span>
<span id="cb7-39">    )</span>
<span id="cb7-40">)</span>
<span id="cb7-41"></span>
<span id="cb7-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Report the screening table before filtering the dataset.</span></span>
<span id="cb7-43">study_screening <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-44">  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;">select</span>(</span>
<span id="cb7-45">    study,</span>
<span id="cb7-46">    year,</span>
<span id="cb7-47">    enso,</span>
<span id="cb7-48">    screening_scenario,</span>
<span id="cb7-49">    severity_range,</span>
<span id="cb7-50">    severity_max,</span>
<span id="cb7-51">    intercept,</span>
<span id="cb7-52">    screening_result</span>
<span id="cb7-53">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-54">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb7-55">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(severity_range, severity_max, intercept), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(.x, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb7-56">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-57">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study-level screening of the simulated candidate dataset"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>Study-level screening of the simulated candidate dataset</caption>
<colgroup>
<col style="width: 5%">
<col style="width: 4%">
<col style="width: 7%">
<col style="width: 20%">
<col style="width: 13%">
<col style="width: 11%">
<col style="width: 8%">
<col style="width: 29%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">study</th>
<th style="text-align: left;">year</th>
<th style="text-align: left;">enso</th>
<th style="text-align: left;">screening_scenario</th>
<th style="text-align: right;">severity_range</th>
<th style="text-align: right;">severity_max</th>
<th style="text-align: right;">intercept</th>
<th style="text-align: left;">screening_result</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">58.63</td>
<td style="text-align: right;">60.71</td>
<td style="text-align: right;">4482.26</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="even">
<td style="text-align: left;">2</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">64.51</td>
<td style="text-align: right;">64.68</td>
<td style="text-align: right;">4189.33</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="odd">
<td style="text-align: left;">3</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">63.78</td>
<td style="text-align: right;">67.65</td>
<td style="text-align: right;">4440.60</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="even">
<td style="text-align: left;">4</td>
<td style="text-align: left;">2014</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">64.34</td>
<td style="text-align: right;">68.54</td>
<td style="text-align: right;">3893.56</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="odd">
<td style="text-align: left;">5</td>
<td style="text-align: left;">2014</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">57.51</td>
<td style="text-align: right;">62.61</td>
<td style="text-align: right;">4333.12</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="even">
<td style="text-align: left;">6</td>
<td style="text-align: left;">2014</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">60.90</td>
<td style="text-align: right;">63.20</td>
<td style="text-align: right;">4325.53</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="odd">
<td style="text-align: left;">7</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">57.67</td>
<td style="text-align: right;">67.29</td>
<td style="text-align: right;">4323.19</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="even">
<td style="text-align: left;">8</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">55.14</td>
<td style="text-align: right;">69.72</td>
<td style="text-align: right;">4104.14</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="odd">
<td style="text-align: left;">9</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">42.93</td>
<td style="text-align: right;">50.49</td>
<td style="text-align: right;">4787.89</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="even">
<td style="text-align: left;">10</td>
<td style="text-align: left;">2016</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">52.91</td>
<td style="text-align: right;">58.70</td>
<td style="text-align: right;">4110.56</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="odd">
<td style="text-align: left;">11</td>
<td style="text-align: left;">2016</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">57.75</td>
<td style="text-align: right;">61.77</td>
<td style="text-align: right;">3434.11</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="even">
<td style="text-align: left;">12</td>
<td style="text-align: left;">2016</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">68.83</td>
<td style="text-align: right;">69.46</td>
<td style="text-align: right;">4825.50</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="odd">
<td style="text-align: left;">13</td>
<td style="text-align: left;">2017</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">62.15</td>
<td style="text-align: right;">63.63</td>
<td style="text-align: right;">4077.57</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="even">
<td style="text-align: left;">14</td>
<td style="text-align: left;">2017</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">65.26</td>
<td style="text-align: right;">65.51</td>
<td style="text-align: right;">4131.78</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="odd">
<td style="text-align: left;">15</td>
<td style="text-align: left;">2017</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">57.94</td>
<td style="text-align: right;">64.77</td>
<td style="text-align: right;">4239.40</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="even">
<td style="text-align: left;">16</td>
<td style="text-align: left;">2018</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">59.96</td>
<td style="text-align: right;">68.74</td>
<td style="text-align: right;">4145.85</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="odd">
<td style="text-align: left;">17</td>
<td style="text-align: left;">2018</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">61.17</td>
<td style="text-align: right;">63.07</td>
<td style="text-align: right;">3862.12</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="even">
<td style="text-align: left;">18</td>
<td style="text-align: left;">2018</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Retained candidate</td>
<td style="text-align: right;">56.90</td>
<td style="text-align: right;">58.46</td>
<td style="text-align: right;">3837.21</td>
<td style="text-align: left;">Selected</td>
</tr>
<tr class="odd">
<td style="text-align: left;">19</td>
<td style="text-align: left;">2019</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Limited severity range</td>
<td style="text-align: right;">3.95</td>
<td style="text-align: right;">26.00</td>
<td style="text-align: right;">3181.89</td>
<td style="text-align: left;">Removed: severity range &lt;= 5 p.p.</td>
</tr>
<tr class="even">
<td style="text-align: left;">20</td>
<td style="text-align: left;">2019</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">Limited severity range</td>
<td style="text-align: right;">3.65</td>
<td style="text-align: right;">25.78</td>
<td style="text-align: right;">3773.90</td>
<td style="text-align: left;">Removed: severity range &lt;= 5 p.p.</td>
</tr>
<tr class="odd">
<td style="text-align: left;">21</td>
<td style="text-align: left;">2019</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Low maximum severity</td>
<td style="text-align: right;">9.50</td>
<td style="text-align: right;">9.50</td>
<td style="text-align: right;">4139.89</td>
<td style="text-align: left;">Removed: maximum severity &lt;= 10%</td>
</tr>
<tr class="even">
<td style="text-align: left;">22</td>
<td style="text-align: left;">2020</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Low maximum severity</td>
<td style="text-align: right;">9.50</td>
<td style="text-align: right;">9.50</td>
<td style="text-align: right;">4240.69</td>
<td style="text-align: left;">Removed: maximum severity &lt;= 10%</td>
</tr>
<tr class="odd">
<td style="text-align: left;">23</td>
<td style="text-align: left;">2020</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">High intercept outlier</td>
<td style="text-align: right;">64.60</td>
<td style="text-align: right;">65.65</td>
<td style="text-align: right;">5520.25</td>
<td style="text-align: left;">Removed: intercept outlier</td>
</tr>
<tr class="even">
<td style="text-align: left;">24</td>
<td style="text-align: left;">2020</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Low intercept outlier</td>
<td style="text-align: right;">58.99</td>
<td style="text-align: right;">60.96</td>
<td style="text-align: right;">3200.17</td>
<td style="text-align: left;">Removed: intercept outlier</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The three plots below show the same screening logic criterion by criterion. In each case, the dashed line or shaded band represents the threshold used to decide whether the study remains eligible for the damage analysis.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create plotting labels once, then reuse them across the three screening plots.</span></span>
<span id="cb8-2">study_screening_plot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> study_screening <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb8-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">study_number =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(study),</span>
<span id="cb8-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">severity_range_status =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(</span>
<span id="cb8-6">      enough_gradient,</span>
<span id="cb8-7">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Passes criterion"</span>,</span>
<span id="cb8-8">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Removed by this criterion"</span></span>
<span id="cb8-9">    ),</span>
<span id="cb8-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maximum_severity_status =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(</span>
<span id="cb8-11">      enough_maximum_severity,</span>
<span id="cb8-12">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Passes criterion"</span>,</span>
<span id="cb8-13">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Removed by this criterion"</span></span>
<span id="cb8-14">    ),</span>
<span id="cb8-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">intercept_status =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(</span>
<span id="cb8-16">      intercept_outlier,</span>
<span id="cb8-17">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Removed by this criterion"</span>,</span>
<span id="cb8-18">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Passes criterion"</span></span>
<span id="cb8-19">    )</span>
<span id="cb8-20">  )</span>
<span id="cb8-21"></span>
<span id="cb8-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Use the same palette for all criterion-specific plots.</span></span>
<span id="cb8-23">criterion_palette <span class="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="cb8-24">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Passes criterion"</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;">"#587C7A"</span>,</span>
<span id="cb8-25">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Removed by this criterion"</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;">"#C84C09"</span></span>
<span id="cb8-26">)</span>
<span id="cb8-27"></span>
<span id="cb8-28"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(</span>
<span id="cb8-29">  study_screening_plot,</span>
<span id="cb8-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(study_number, severity_range, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> severity_range_status)</span>
<span id="cb8-31">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.72</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;">"white"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1A1A1A"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(</span>
<span id="cb8-35">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>,</span>
<span id="cb8-36">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">24.4</span>,</span>
<span id="cb8-37">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb8-38">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5 p.p. threshold"</span>,</span>
<span id="cb8-39">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb8-40">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.45</span>,</span>
<span id="cb8-41">    <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;">3.4</span></span>
<span id="cb8-42">  ) <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_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> criterion_palette) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">27.5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb8-47">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Criterion 1: retain studies with enough disease contrast"</span>,</span>
<span id="cb8-48">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study"</span>,</span>
<span id="cb8-49">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Severity range, max(S) - min(S), p.p."</span>,</span>
<span id="cb8-50">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb8-51">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/screening-severity-range-criterion-1.png" class="img-fluid figure-img" width="825"></p>
</figure>
</div>
</div>
</div>
<p>The first criterion removes studies with too little contrast in disease severity. Without a minimum severity range, the estimated damage slope is weakly identified because the study contains little information about how yield changes across disease intensities.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(</span>
<span id="cb9-2">  study_screening_plot,</span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(study_number, severity_max, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> maximum_severity_status)</span>
<span id="cb9-4">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.72</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;">"white"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1A1A1A"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(</span>
<span id="cb9-8">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>,</span>
<span id="cb9-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">24.4</span>,</span>
<span id="cb9-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span id="cb9-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10% maximum severity threshold"</span>,</span>
<span id="cb9-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb9-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.45</span>,</span>
<span id="cb9-14">    <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;">3.4</span></span>
<span id="cb9-15">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> criterion_palette) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">29</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb9-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Criterion 2: retain studies that reached meaningful disease pressure"</span>,</span>
<span id="cb9-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study"</span>,</span>
<span id="cb9-22">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Maximum severity, max(S) (%)"</span>,</span>
<span id="cb9-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb9-24">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/screening-maximum-severity-criterion-1.png" class="img-fluid figure-img" width="825"></p>
</figure>
</div>
</div>
</div>
<p>The second criterion removes studies in which the epidemic remained too weak to support a damage estimate. A study may have some variation in severity but still never reach disease levels high enough to represent a meaningful yield-loss gradient.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(study_screening_plot, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(study_number, intercept, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> intercept_status)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(</span>
<span id="cb10-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rect"</span>,</span>
<span id="cb10-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmin =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>,</span>
<span id="cb10-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span>,</span>
<span id="cb10-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> intercept_limits<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>lower,</span>
<span id="cb10-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> intercept_limits<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>upper,</span>
<span id="cb10-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#587C7A"</span>,</span>
<span id="cb10-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span></span>
<span id="cb10-10">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(</span>
<span id="cb10-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(intercept_limits<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>lower, intercept_limits<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>upper),</span>
<span id="cb10-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb10-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1A1A1A"</span>,</span>
<span id="cb10-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span></span>
<span id="cb10-16">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(</span>
<span id="cb10-19">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>,</span>
<span id="cb10-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb10-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> intercept_limits<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>upper,</span>
<span id="cb10-22">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1.5 IQR upper limit"</span>,</span>
<span id="cb10-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb10-24">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.45</span>,</span>
<span id="cb10-25">    <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;">3.4</span></span>
<span id="cb10-26">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(</span>
<span id="cb10-28">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>,</span>
<span id="cb10-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb10-30">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> intercept_limits<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>lower,</span>
<span id="cb10-31">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1.5 IQR lower limit"</span>,</span>
<span id="cb10-32">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb10-33">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.25</span>,</span>
<span id="cb10-34">    <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;">3.4</span></span>
<span id="cb10-35">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> criterion_palette) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">24</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb10-40">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Criterion 3: remove studies with outlying attainable-yield estimates"</span>,</span>
<span id="cb10-41">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study"</span>,</span>
<span id="cb10-42">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study-specific intercept, beta[0] (kg/ha)"</span>,</span>
<span id="cb10-43">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb10-44">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/screening-intercept-outlier-criterion-1.png" class="img-fluid figure-img" width="825"></p>
</figure>
</div>
</div>
</div>
<p>The third criterion evaluates the first-regression intercept because that value will later be interpreted as attainable yield and used to compute relative yield loss. An outlying intercept does not automatically mean that a study is biologically impossible, but it is a warning that the fitted disease-free yield estimate may dominate the damage coefficient. In applied work, this kind of flag should lead to inspection of the original study, its yield scale, its disease range, and any design or measurement issues.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Keep only studies that passed all screening criteria.</span></span>
<span id="cb11-2">damage_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> candidate_damage_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">semi_join</span>(</span>
<span id="cb11-4">    study_screening <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-5">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(selected) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-6">      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;">select</span>(study, year, enso),</span>
<span id="cb11-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</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;">"study"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"enso"</span>)</span>
<span id="cb11-8">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb11-10">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Drop unused factor levels so later model summaries and plots are cleaner.</span></span>
<span id="cb11-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">study =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">droplevels</span>(study),</span>
<span id="cb11-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">droplevels</span>(year),</span>
<span id="cb11-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(enso, <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;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>))</span>
<span id="cb11-14">  )</span></code></pre></div></div>
</div>
<p>After screening, it is useful to inspect the selected observations before moving to model fitting. The first diagnostic view compares the marginal distributions of disease severity and yield by ENSO phase. This is not a formal model diagnostic, but it helps verify whether the selected dataset still spans a useful disease gradient and whether the yield distribution differs across the simulated environmental contexts.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Put severity and yield into long format so they can be shown in one faceted plot.</span></span>
<span id="cb12-2">selected_distribution_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> damage_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb12-4">    study,</span>
<span id="cb12-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(enso, <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;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>)),</span>
<span id="cb12-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">severity =</span> severity,</span>
<span id="cb12-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yield =</span> yield</span>
<span id="cb12-8">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(</span>
<span id="cb12-10">    <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>(severity, yield),</span>
<span id="cb12-11">    <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;">"variable"</span>,</span>
<span id="cb12-12">    <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="cb12-13">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb12-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variable =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(</span>
<span id="cb12-16">      variable,</span>
<span id="cb12-17">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">severity =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb12-18">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yield =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yield (kg/ha)"</span></span>
<span id="cb12-19">    )</span>
<span id="cb12-20">  )</span>
<span id="cb12-21"></span>
<span id="cb12-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(selected_distribution_df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(value, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> enso)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_density</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.22</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>variable, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> enso_palette) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> enso_palette) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb12-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of severity and yield in the selected studies"</span>,</span>
<span id="cb12-30">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb12-31">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>,</span>
<span id="cb12-32">    <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;">"ENSO phase"</span>,</span>
<span id="cb12-33">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ENSO phase"</span></span>
<span id="cb12-34">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/selected-severity-yield-distributions-1.png" class="img-fluid figure-img" width="825"></p>
</figure>
</div>
</div>
</div>
<p>The second diagnostic view keeps the response and explanatory variable together. Each line is a study-specific linear fit to the selected observations, with line color indicating the ENSO phase. This view is deliberately shown in a single panel so that between-study heterogeneity in baseline yield and damage slope remains visible before the mixed-effects model is introduced.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Each line is an exploratory within-study fit, not the final model.</span></span>
<span id="cb13-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(</span>
<span id="cb13-3">  damage_df,</span>
<span id="cb13-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(</span>
<span id="cb13-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> severity,</span>
<span id="cb13-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> yield,</span>
<span id="cb13-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> study,</span>
<span id="cb13-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(enso, <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;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>))</span>
<span id="cb13-9">  )</span>
<span id="cb13-10">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-11">  <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;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.22</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;">1.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_smooth</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</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;">se =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> enso_palette) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb13-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study-specific severity-yield relationships in the selected dataset"</span>,</span>
<span id="cb13-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb13-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yield (kg/ha)"</span>,</span>
<span id="cb13-19">    <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;">"ENSO phase"</span></span>
<span id="cb13-20">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/selected-study-severity-yield-smooths-1.png" class="img-fluid figure-img" width="825"></p>
</figure>
</div>
</div>
</div>
<p>The next figure displays the selected simulated dataset on a study-by-study basis. Its main purpose is to make clear why a mixed-effects framework becomes attractive under this type of hierarchical structure.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Faceting by study makes the hierarchical data structure visible.</span></span>
<span id="cb14-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(damage_df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, yield, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> enso)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.65</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="cb14-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_smooth</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">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="cb14-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>study, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> enso_palette) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb14-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Simulated severity-yield relationships across studies"</span>,</span>
<span id="cb14-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb14-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yield (kg/ha)"</span>,</span>
<span id="cb14-12">    <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;">"ENSO phase"</span></span>
<span id="cb14-13">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" width="816"></p>
</figure>
</div>
</div>
</div>
<p>This is the type of structure in which ordinary regression becomes limited. Each selected study has its own baseline productivity and damage slope, while the full dataset also includes between-year and between-phase sources of variation.</p>
<p>Because this is a didactic simulation, the ENSO-specific differences in attainable yield and slope are intentionally cleaner than what is typically observed in empirical datasets. Field data often exhibit substantially greater overlap among groups, weaker moderator signals, noisier study-specific relationships, and additional reasons to examine whether each study is representative enough for a damage analysis.</p>
<p>After this screening step, the analysis has a clearer target: a selected set of studies with enough disease contrast and plausible yield baselines. That is the point at which a mixed-effects model becomes useful, because the selected data still have a hierarchical structure that should not be ignored.</p>
</section>
<section id="modeling-yield-loss-with-mixed-effects-models" class="level2">
<h2 class="anchored" data-anchor-id="modeling-yield-loss-with-mixed-effects-models">Modeling yield loss with mixed-effects models</h2>
<p>Mixed models are useful when observations are not independent because they are clustered within studies, years, locations, or other grouping factors. In yield loss datasets, this is usually the rule rather than the exception. The key benefit is that the model can estimate an average damage function while allowing individual studies to depart from that average in both attainable yield and damage slope. In other words, the model gives us a common summary without pretending that every study behaved identically.</p>
<section id="a-general-damage-coefficient-without-moderators" class="level3">
<h3 class="anchored" data-anchor-id="a-general-damage-coefficient-without-moderators">1. A general damage coefficient without moderators</h3>
<p>The first step is deliberately simple: fit a mixed model with severity as the only fixed-effect predictor. This yields a population-average attainable yield and a population-average slope while still accounting for study-to-study heterogeneity through random effects. The random slope term is important here because it acknowledges that disease damage is not expected to be identical across all field studies.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Fit the overall mixed model directly to the selected observation-level data.</span></span>
<span id="cb15-2">damage_lmer_overall <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lmer</span>(</span>
<span id="cb15-3">  yield <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> severity <span 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> severity <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> study) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> year),</span>
<span id="cb15-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> damage_df,</span>
<span id="cb15-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">REML =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb15-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">control =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lmerControl</span>(</span>
<span id="cb15-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">optimizer =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bobyqa"</span>,</span>
<span id="cb15-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">optCtrl =</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;">maxfun =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2e5</span>)</span>
<span id="cb15-9">  )</span>
<span id="cb15-10">)</span>
<span id="cb15-11"></span>
<span id="cb15-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inspect fixed effects, random effects, and model fit information.</span></span>
<span id="cb15-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(damage_lmer_overall)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: yield ~ severity + (1 + severity | study) + (1 | year)
   Data: damage_df
Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))

REML criterion at convergence: 3266.3

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-2.47399 -0.58857  0.02183  0.61328  2.52533 

Random effects:
 Groups   Name        Variance  Std.Dev. Corr  
 study    (Intercept) 106673.34 326.6          
          severity        28.09   5.3    -0.66 
 year     (Intercept)      0.00   0.0          
 Residual              16934.04 130.1          
Number of obs: 252, groups:  study, 18; year, 6

Fixed effects:
            Estimate Std. Error       df t value Pr(&gt;|t|)    
(Intercept) 4198.537     78.693   16.932   53.35  &lt; 2e-16 ***
severity     -23.137      1.321   17.272  -17.52 1.95e-12 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
         (Intr)
severity -0.666
optimizer (bobyqa) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')</code></pre>
</div>
</div>
<p>For the mixed-model summaries below, I use a parametric bootstrap. This is particularly useful for the damage coefficient because the latter is a nonlinear function of the intercept and slope:</p>
<p><img src="https://latex.codecogs.com/png.latex?DC%20=%20-100%20%5Ctimes%20%5Cfrac%7Bb_1%7D%7Bb_0%7D"></p>
<p>The example uses 250 bootstrap simulations to keep the article render reasonably fast. For a final empirical analysis, I would usually increase this number and report convergence, singular-fit checks, residual diagnostics, and any sensitivity of the damage coefficient to model structure.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Helper for percentile bootstrap intervals from bootMer output.</span></span>
<span id="cb17-2">boot_percentile <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>(boot_obj, terms, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>) {</span>
<span id="cb17-3">  alpha <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> level) <span 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="cb17-4">  lower <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(boot_obj<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, terms, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> alpha, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb17-5">  upper <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(boot_obj<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, terms, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> alpha, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb17-6">  </span>
<span id="cb17-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb17-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">term =</span> terms,</span>
<span id="cb17-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> boot_obj<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t0[terms],</span>
<span id="cb17-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_lb =</span> lower,</span>
<span id="cb17-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_ub =</span> upper</span>
<span id="cb17-12">  )</span>
<span id="cb17-13">}</span>
<span id="cb17-14"></span>
<span id="cb17-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Prediction grid used to draw the population-average damage function.</span></span>
<span id="cb17-16">overall_grid <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">severity =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">70</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb17-17"></span>
<span id="cb17-18">overall_boot_fun <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>(fit) {</span>
<span id="cb17-19">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fixed effects define the population-average damage function</span></span>
<span id="cb17-20">  beta <span class="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)</span>
<span id="cb17-21">  b0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(beta[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(Intercept)"</span>])</span>
<span id="cb17-22">  b1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(beta[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"severity"</span>])</span>
<span id="cb17-23">  </span>
<span id="cb17-24">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># population-average fitted values for the confidence band</span></span>
<span id="cb17-25">  mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">predict</span>(fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">newdata =</span> overall_grid, <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="cb17-26">  </span>
<span id="cb17-27">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># new observations include residual variation for prediction intervals</span></span>
<span id="cb17-28">  y_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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(mu), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sigma</span>(fit))</span>
<span id="cb17-29">  </span>
<span id="cb17-30">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Return scalar summaries and fitted/predicted curves in one vector.</span></span>
<span id="cb17-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb17-32">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">attainable_yield =</span> b0,</span>
<span id="cb17-33">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">slope =</span> b1,</span>
<span id="cb17-34">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">damage_coefficient =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> b1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> b0,</span>
<span id="cb17-35">    stats<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(mu, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fit_"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(mu))),</span>
<span id="cb17-36">    stats<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(y_new, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pred_"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(y_new)))</span>
<span id="cb17-37">  )</span>
<span id="cb17-38">}</span>
<span id="cb17-39"></span>
<span id="cb17-40"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Parametric bootstrap refits the model repeatedly to quantify uncertainty.</span></span>
<span id="cb17-41">overall_boot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootMer</span>(</span>
<span id="cb17-42">  damage_lmer_overall,</span>
<span id="cb17-43">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FUN =</span> overall_boot_fun,</span>
<span id="cb17-44">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nsim =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">250</span>,</span>
<span id="cb17-45">  <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;">"parametric"</span>,</span>
<span id="cb17-46">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use.u =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb17-47">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">123</span></span>
<span id="cb17-48">)</span>
<span id="cb17-49"></span>
<span id="cb17-50"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Extract intervals for the three main epidemiological summaries.</span></span>
<span id="cb17-51">overall_damage <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boot_percentile</span>(</span>
<span id="cb17-52">  overall_boot,</span>
<span id="cb17-53">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">terms =</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;">"attainable_yield"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"damage_coefficient"</span>)</span>
<span id="cb17-54">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb17-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb17-56">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">term =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(</span>
<span id="cb17-57">      term,</span>
<span id="cb17-58">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">attainable_yield =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Attainable yield"</span>,</span>
<span id="cb17-59">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">slope =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Slope"</span>,</span>
<span id="cb17-60">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">damage_coefficient =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Damage coefficient"</span></span>
<span id="cb17-61">    ),</span>
<span id="cb17-62">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(estimate, ci_lb, ci_ub), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(.x, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb17-63">  )</span>
<span id="cb17-64"></span>
<span id="cb17-65">overall_damage <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb17-66">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bootstrap percentile intervals for the overall mixed-model summary"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>Bootstrap percentile intervals for the overall mixed-model summary</caption>
<thead>
<tr class="header">
<th style="text-align: left;">term</th>
<th style="text-align: right;">estimate</th>
<th style="text-align: right;">ci_lb</th>
<th style="text-align: right;">ci_ub</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Attainable yield</td>
<td style="text-align: right;">4198.54</td>
<td style="text-align: right;">4030.14</td>
<td style="text-align: right;">4350.77</td>
</tr>
<tr class="even">
<td style="text-align: left;">Slope</td>
<td style="text-align: right;">-23.14</td>
<td style="text-align: right;">-25.64</td>
<td style="text-align: right;">-20.50</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Damage coefficient</td>
<td style="text-align: right;">0.55</td>
<td style="text-align: right;">0.50</td>
<td style="text-align: right;">0.60</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>Under this formulation:</p>
<ul>
<li>attainable yield is the model-based population-average yield at zero disease</li>
<li>slope is the model-based population-average absolute yield loss per 1 percentage-point increase in severity</li>
<li>damage coefficient is the corresponding relative yield loss per 1 percentage-point increase in severity</li>
<li>the bootstrap confidence intervals summarize the uncertainty around those population-level quantities</li>
</ul>
<p>This summary is useful, but it should not be interpreted as a universal or context-free damage coefficient. It remains a population-level estimate conditional on the adopted mixed-model structure and on the coding of the data.</p>
</section>
<section id="confidence-intervals-versus-prediction-intervals" class="level3">
<h3 class="anchored" data-anchor-id="confidence-intervals-versus-prediction-intervals">Confidence intervals versus prediction intervals</h3>
<p>These two interval types answer different inferential questions:</p>
<ul>
<li>a <strong>confidence interval</strong> around the fitted line quantifies uncertainty in the estimated mean response</li>
<li>a <strong>prediction interval</strong> is wider because it characterizes where a new observation may fall around the model-implied mean</li>
</ul>
<p>So, in practice:</p>
<ul>
<li>confidence intervals are about the uncertainty of the model-implied average relationship</li>
<li>prediction intervals are about the uncertainty of future data points around that relationship</li>
</ul>
<p>In the code below, the prediction interval includes residual variation around the population-average curve. It should therefore be read as an observation-level interval around the fixed-effect mean, not as a full new-study predictive interval. Predicting an entirely new study or year would require adding the relevant random-effect variation as well.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Convert bootstrap draws into confidence and prediction bands.</span></span>
<span id="cb18-2">overall_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">predict</span>(damage_lmer_overall, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">newdata =</span> overall_grid, <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="cb18-3">fit_cols_overall <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^fit_"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(overall_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb18-4">pred_cols_overall <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^pred_"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(overall_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb18-5"></span>
<span id="cb18-6">overall_curve <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> overall_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb18-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fit =</span> overall_fit,</span>
<span id="cb18-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">conf_lb =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(overall_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, fit_cols_overall, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>),</span>
<span id="cb18-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">conf_ub =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(overall_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, fit_cols_overall, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>),</span>
<span id="cb18-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pred_lb =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(overall_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, pred_cols_overall, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>),</span>
<span id="cb18-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pred_ub =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(overall_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, pred_cols_overall, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>)</span>
<span id="cb18-13">  )</span></code></pre></div></div>
</div>
<p>The confidence interval is shown first because it is the narrower quantity and directly reflects uncertainty around the estimated mean response.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(overall_curve, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, fit)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># confidence interval for the mean fitted response</span></span>
<span id="cb19-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_ribbon</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> conf_lb, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> conf_ub), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1f6f78"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.22</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#154d57"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb19-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Overall mixed model: confidence interval for the mean response"</span>,</span>
<span id="cb19-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb19-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yield (kg/ha)"</span></span>
<span id="cb19-10">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-10-1.png" class="img-fluid figure-img" width="681"></p>
</figure>
</div>
</div>
</div>
<p>Next comes the prediction interval, which is wider because it includes the dispersion of future observations around the mean response.</p>
<p>Because these bands are obtained from percentile limits of a finite parametric bootstrap sample, they are not expected to look perfectly smooth or exactly linear, especially when the number of bootstrap refits is modest. Small local irregularities in the ribbon therefore reflect Monte Carlo error in the bootstrap quantiles rather than a biological departure from linearity in the fitted damage function.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(overall_curve, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, fit)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># prediction interval for a new observation</span></span>
<span id="cb20-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_ribbon</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> pred_lb, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> pred_ub), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#6e8fa4"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.24</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#154d57"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb20-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Overall mixed model: prediction interval for new observations"</span>,</span>
<span id="cb20-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb20-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yield (kg/ha)"</span></span>
<span id="cb20-10">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-11-1.png" class="img-fluid figure-img" width="681"></p>
</figure>
</div>
</div>
</div>
<p>Once that distinction is clear, both intervals can be displayed together in a single plot.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(overall_curve, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, fit)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># prediction interval is wider and shown first</span></span>
<span id="cb21-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_ribbon</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> pred_lb, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> pred_ub), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#6e8fa4"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.18</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># confidence interval is narrower and shown on top</span></span>
<span id="cb21-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_ribbon</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> conf_lb, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> conf_ub), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1f6f78"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.24</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</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;">"#154d57"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb21-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Overall mixed model: confidence and prediction intervals together"</span>,</span>
<span id="cb21-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb21-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yield (kg/ha)"</span></span>
<span id="cb21-12">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-12-1.png" class="img-fluid figure-img" width="681"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="extending-the-mixed-effects-model-with-moderators" class="level3">
<h3 class="anchored" data-anchor-id="extending-the-mixed-effects-model-with-moderators">2. Extending the mixed-effects model with moderators</h3>
<p>Once the general relationship has been established, the next question is whether the damage function changes across epidemiological contexts. Here I use ENSO phase as a moderator. In this simulated example, ENSO phase represents a broad environmental context; in an empirical study, it should be interpreted cautiously as a contextual classifier rather than as a direct mechanistic cause unless the design and supporting covariates justify that claim.</p>
<p>The model now includes:</p>
<ul>
<li>a fixed effect of severity</li>
<li>a fixed effect of ENSO phase</li>
<li>a severity by ENSO interaction</li>
<li>a random intercept and random slope for each study</li>
<li>a random intercept for year</li>
</ul>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Fit the moderated model: ENSO changes the intercept and the severity slope.</span></span>
<span id="cb22-2">damage_lmer_enso <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lmer</span>(</span>
<span id="cb22-3">  yield <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> severity <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> enso <span 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> severity <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> study) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> year),</span>
<span id="cb22-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> damage_df,</span>
<span id="cb22-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">REML =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb22-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">control =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lmerControl</span>(</span>
<span id="cb22-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">optimizer =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bobyqa"</span>,</span>
<span id="cb22-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">optCtrl =</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;">maxfun =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2e5</span>)</span>
<span id="cb22-9">  )</span>
<span id="cb22-10">)</span>
<span id="cb22-11"></span>
<span id="cb22-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inspect the interaction terms before translating them into phase-specific summaries.</span></span>
<span id="cb22-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(damage_lmer_enso)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: yield ~ severity * enso + (1 + severity | study) + (1 | year)
   Data: damage_df
Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))

REML criterion at convergence: 3213

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-2.36119 -0.60807  0.03054  0.64302  2.43939 

Random effects:
 Groups   Name        Variance  Std.Dev. Corr  
 study    (Intercept) 88757.722 297.922        
          severity        5.274   2.297  -0.55 
 year     (Intercept)     0.000   0.000        
 Residual             16973.294 130.282        
Number of obs: 252, groups:  study, 18; year, 6

Fixed effects:
                  Estimate Std. Error       df t value Pr(&gt;|t|)    
(Intercept)       4170.151    124.553   14.816  33.481 2.24e-15 ***
severity           -23.135      1.195   14.452 -19.363 9.67e-12 ***
ensoCold          -166.891    176.693   14.997  -0.945  0.35987    
ensoWarm           246.456    176.187   14.829   1.399  0.18243    
severity:ensoCold    5.846      1.693   14.640   3.453  0.00366 ** 
severity:ensoWarm   -5.877      1.679   14.006  -3.500  0.00354 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
            (Intr) sevrty ensCld ensWrm svrt:C
severity    -0.534                            
ensoCold    -0.705  0.377                     
ensoWarm    -0.707  0.378  0.498              
svrty:nsCld  0.377 -0.706 -0.542 -0.267       
svrty:nsWrm  0.380 -0.711 -0.268 -0.536  0.502
optimizer (bobyqa) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')</code></pre>
</div>
</div>
<p>The fixed part of the model now addresses a moderated question: on average, does the severity-yield relationship differ among ENSO phases?</p>
<p>The random part answers a different question: how much do individual studies deviate from the population-average intercept and slope?</p>
</section>
<section id="interpreting-the-moderated-mixed-model" class="level3">
<h3 class="anchored" data-anchor-id="interpreting-the-moderated-mixed-model">Interpreting the moderated mixed model</h3>
<p>Under this formulation:</p>
<ul>
<li>the intercept corresponds to the expected attainable yield for the reference ENSO class when severity is zero</li>
<li>the severity coefficient is the baseline damage slope for the reference class</li>
<li>the interaction terms quantify how the slope changes in the other ENSO phases</li>
<li>the study-level random effects allow each study to have its own attainable yield and its own damage slope</li>
</ul>
<p>This is often a strong modeling strategy when the primary objective is to analyze the full hierarchical dataset directly while testing whether a contextual factor modifies disease damage.</p>
<p>The same bootstrap strategy can be extended here, now allowing the phase-specific summaries to vary across bootstrap refits.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Build a grid with all severity values for each ENSO phase.</span></span>
<span id="cb24-2">enso_grid <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb24-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">severity =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">70</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb24-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</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;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>), <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;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>))</span>
<span id="cb24-5">)</span>
<span id="cb24-6"></span>
<span id="cb24-7">enso_boot_fun <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>(fit) {</span>
<span id="cb24-8">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Extract phase-specific intercepts and slopes from the fixed effects.</span></span>
<span id="cb24-9">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Neutral is the reference phase; Cold and Warm add their coefficients.</span></span>
<span id="cb24-10">  beta <span class="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)</span>
<span id="cb24-11">  b0_neutral <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(beta[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(Intercept)"</span>])</span>
<span id="cb24-12">  b1_neutral <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(beta[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"severity"</span>])</span>
<span id="cb24-13">  b0_cold <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(beta[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(Intercept)"</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> beta[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ensoCold"</span>])</span>
<span id="cb24-14">  b1_cold <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(beta[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"severity"</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> beta[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"severity:ensoCold"</span>])</span>
<span id="cb24-15">  b0_warm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(beta[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(Intercept)"</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> beta[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ensoWarm"</span>])</span>
<span id="cb24-16">  b1_warm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unname</span>(beta[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"severity"</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> beta[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"severity:ensoWarm"</span>])</span>
<span id="cb24-17">  </span>
<span id="cb24-18">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Population-average fitted values and new observation draws.</span></span>
<span id="cb24-19">  mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">predict</span>(fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">newdata =</span> enso_grid, <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="cb24-20">  y_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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(mu), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sigma</span>(fit))</span>
<span id="cb24-21">  </span>
<span id="cb24-22">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Match each grid row to its phase-specific attainable yield.</span></span>
<span id="cb24-23">  attainable_vec <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb24-24">    enso_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>enso <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Neutral"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> b0_neutral,</span>
<span id="cb24-25">    enso_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>enso <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> b0_cold,</span>
<span id="cb24-26">    <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> b0_warm</span>
<span id="cb24-27">  )</span>
<span id="cb24-28">  </span>
<span id="cb24-29">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Convert absolute yield predictions to relative yield loss.</span></span>
<span id="cb24-30">  rel_loss_mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (attainable_vec <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> attainable_vec</span>
<span id="cb24-31">  rel_loss_pred <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (attainable_vec <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> y_new) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> attainable_vec</span>
<span id="cb24-32">  </span>
<span id="cb24-33">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Return phase-specific summaries plus curves for plotting.</span></span>
<span id="cb24-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb24-35">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">neutral_attainable_yield =</span> b0_neutral,</span>
<span id="cb24-36">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">neutral_slope =</span> b1_neutral,</span>
<span id="cb24-37">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">neutral_damage_coefficient =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> b1_neutral <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> b0_neutral,</span>
<span id="cb24-38">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cold_attainable_yield =</span> b0_cold,</span>
<span id="cb24-39">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cold_slope =</span> b1_cold,</span>
<span id="cb24-40">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cold_damage_coefficient =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> b1_cold <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> b0_cold,</span>
<span id="cb24-41">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warm_attainable_yield =</span> b0_warm,</span>
<span id="cb24-42">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warm_slope =</span> b1_warm,</span>
<span id="cb24-43">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warm_damage_coefficient =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> b1_warm <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> b0_warm,</span>
<span id="cb24-44">    stats<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(mu, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fit_"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(mu))),</span>
<span id="cb24-45">    stats<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(y_new, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pred_"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(y_new))),</span>
<span id="cb24-46">    stats<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(rel_loss_mu, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loss_fit_"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(rel_loss_mu))),</span>
<span id="cb24-47">    stats<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setNames</span>(rel_loss_pred, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"loss_pred_"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(rel_loss_pred)))</span>
<span id="cb24-48">  )</span>
<span id="cb24-49">}</span>
<span id="cb24-50"></span>
<span id="cb24-51"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Run the phase-specific parametric bootstrap.</span></span>
<span id="cb24-52">enso_boot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootMer</span>(</span>
<span id="cb24-53">  damage_lmer_enso,</span>
<span id="cb24-54">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FUN =</span> enso_boot_fun,</span>
<span id="cb24-55">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nsim =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">250</span>,</span>
<span id="cb24-56">  <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;">"parametric"</span>,</span>
<span id="cb24-57">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use.u =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb24-58">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">123</span></span>
<span id="cb24-59">)</span>
<span id="cb24-60"></span>
<span id="cb24-61"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Extract intervals for attainable yield, slope, and damage coefficient by phase.</span></span>
<span id="cb24-62">lmer_phase_estimates <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb24-63">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boot_percentile</span>(enso_boot, <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;">"neutral_attainable_yield"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"neutral_slope"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"neutral_damage_coefficient"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb24-64">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Neutral"</span>),</span>
<span id="cb24-65">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boot_percentile</span>(enso_boot, <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;">"cold_attainable_yield"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cold_slope"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cold_damage_coefficient"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb24-66">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>),</span>
<span id="cb24-67">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boot_percentile</span>(enso_boot, <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;">"warm_attainable_yield"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"warm_slope"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"warm_damage_coefficient"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb24-68">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>)</span>
<span id="cb24-69">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb24-70">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb24-71">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parameter =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb24-72">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(term, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"attainable_yield"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Attainable yield"</span>,</span>
<span id="cb24-73">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(term, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"damage_coefficient"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Damage coefficient"</span>,</span>
<span id="cb24-74">      <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Slope"</span></span>
<span id="cb24-75">    ),</span>
<span id="cb24-76">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(enso, <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;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>))</span>
<span id="cb24-77">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb24-78">  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;">select</span>(enso, parameter, estimate, ci_lb, ci_ub) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb24-79">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(estimate, ci_lb, ci_ub), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(.x, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)))</span>
<span id="cb24-80"></span>
<span id="cb24-81">lmer_phase_estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb24-82">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bootstrap percentile intervals for phase-specific summaries from the moderated mixed model"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>Bootstrap percentile intervals for phase-specific summaries from the moderated mixed model</caption>
<thead>
<tr class="header">
<th style="text-align: left;">enso</th>
<th style="text-align: left;">parameter</th>
<th style="text-align: right;">estimate</th>
<th style="text-align: right;">ci_lb</th>
<th style="text-align: right;">ci_ub</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Attainable yield</td>
<td style="text-align: right;">4170.15</td>
<td style="text-align: right;">3911.65</td>
<td style="text-align: right;">4384.65</td>
</tr>
<tr class="even">
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Slope</td>
<td style="text-align: right;">-23.14</td>
<td style="text-align: right;">-25.25</td>
<td style="text-align: right;">-20.98</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Damage coefficient</td>
<td style="text-align: right;">0.55</td>
<td style="text-align: right;">0.51</td>
<td style="text-align: right;">0.60</td>
</tr>
<tr class="even">
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">Attainable yield</td>
<td style="text-align: right;">4003.26</td>
<td style="text-align: right;">3795.51</td>
<td style="text-align: right;">4231.23</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">Slope</td>
<td style="text-align: right;">-17.29</td>
<td style="text-align: right;">-19.59</td>
<td style="text-align: right;">-15.08</td>
</tr>
<tr class="even">
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">Damage coefficient</td>
<td style="text-align: right;">0.43</td>
<td style="text-align: right;">0.38</td>
<td style="text-align: right;">0.48</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Attainable yield</td>
<td style="text-align: right;">4416.61</td>
<td style="text-align: right;">4182.37</td>
<td style="text-align: right;">4653.27</td>
</tr>
<tr class="even">
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Slope</td>
<td style="text-align: right;">-29.01</td>
<td style="text-align: right;">-31.14</td>
<td style="text-align: right;">-26.59</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Damage coefficient</td>
<td style="text-align: right;">0.66</td>
<td style="text-align: right;">0.61</td>
<td style="text-align: right;">0.70</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Recover the bootstrapped columns corresponding to fitted curves,</span></span>
<span id="cb25-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># prediction curves, and relative-loss curves.</span></span>
<span id="cb25-3">enso_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">predict</span>(damage_lmer_enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">newdata =</span> enso_grid, <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="cb25-4">fit_cols_enso <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^fit_"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(enso_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb25-5">pred_cols_enso <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^pred_"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(enso_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb25-6">loss_fit_cols_enso <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^loss_fit_"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(enso_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb25-7">loss_pred_cols_enso <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^loss_pred_"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(enso_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb25-8"></span>
<span id="cb25-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Combine point estimates and bootstrap intervals into one plotting data frame.</span></span>
<span id="cb25-10">enso_curves <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> enso_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb25-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb25-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fit =</span> enso_fit,</span>
<span id="cb25-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">conf_lb =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(enso_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, fit_cols_enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>),</span>
<span id="cb25-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">conf_ub =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(enso_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, fit_cols_enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>),</span>
<span id="cb25-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pred_lb =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(enso_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, pred_cols_enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>),</span>
<span id="cb25-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pred_ub =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(enso_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, pred_cols_enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>),</span>
<span id="cb25-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rel_loss_fit =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(enso_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, loss_fit_cols_enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, median),</span>
<span id="cb25-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rel_loss_conf_lb =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(enso_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, loss_fit_cols_enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>),</span>
<span id="cb25-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rel_loss_conf_ub =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(enso_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, loss_fit_cols_enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>),</span>
<span id="cb25-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rel_loss_pred_lb =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(enso_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, loss_pred_cols_enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>),</span>
<span id="cb25-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rel_loss_pred_ub =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(enso_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[, loss_pred_cols_enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drop =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, quantile, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>)</span>
<span id="cb25-22">  )</span>
<span id="cb25-23"></span>
<span id="cb25-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Labels placed at the end of each phase-specific line.</span></span>
<span id="cb25-25">phase_label_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> lmer_phase_estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb25-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(parameter <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Damage coefficient"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb25-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb25-28">    enso,</span>
<span id="cb25-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(enso, <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;">DC = "</span>, estimate, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%/pp"</span>)</span>
<span id="cb25-30">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb25-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(</span>
<span id="cb25-32">    enso_curves <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;">group_by</span>(enso) <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;">slice_tail</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;">1</span>) <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;">ungroup</span>() <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;">select</span>(enso, fit, rel_loss_fit),</span>
<span id="cb25-33">    <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;">"enso"</span></span>
<span id="cb25-34">  )</span></code></pre></div></div>
</div>
<p>These curves remain population-level summaries derived from the mixed model. The bootstrap simply allows uncertainty to be quantified for both the estimated mean response and the prediction of new observations.</p>
<p>The first faceted figure shows only the confidence interval, so the reader can focus on uncertainty in the mean severity-yield relationship within each ENSO phase.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(enso_curves, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, fit)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb26-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># confidence interval for the mean fitted response in each phase</span></span>
<span id="cb26-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_ribbon</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> conf_lb, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> conf_ub), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1f6f78"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.22</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb26-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#154d57"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb26-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb26-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb26-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb26-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Moderated mixed model: confidence intervals by ENSO phase"</span>,</span>
<span id="cb26-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb26-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yield (kg/ha)"</span></span>
<span id="cb26-11">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-16-1.png" class="img-fluid figure-img" width="806"></p>
</figure>
</div>
</div>
</div>
<p>The second faceted figure shows the prediction interval, which is wider because it reflects the variability of future observations around those phase-specific mean lines.</p>
<p>Again, because these prediction bands are constructed from finite bootstrap percentiles, they may display slight local waviness instead of perfectly straight boundaries. With a relatively small number of bootstrap simulations, that behavior should be interpreted as a numerical feature of the resampling procedure rather than as evidence that the underlying mean relationship is nonlinear.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(enso_curves, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, fit)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># prediction interval for a new observation in each phase</span></span>
<span id="cb27-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_ribbon</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> pred_lb, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> pred_ub), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#6e8fa4"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.24</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#154d57"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb27-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb27-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Moderated mixed model: prediction intervals by ENSO phase"</span>,</span>
<span id="cb27-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb27-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yield (kg/ha)"</span></span>
<span id="cb27-11">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-17-1.png" class="img-fluid figure-img" width="806"></p>
</figure>
</div>
</div>
</div>
<p>Once the distinction is clear, the two types of interval can be merged in a single view.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(enso_curves, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, fit)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb28-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># wider prediction interval</span></span>
<span id="cb28-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_ribbon</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> pred_lb, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> pred_ub), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#6e8fa4"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.18</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb28-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># narrower confidence interval</span></span>
<span id="cb28-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_ribbon</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> conf_lb, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> conf_ub), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1f6f78"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.24</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb28-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#154d57"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.35</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb28-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(</span>
<span id="cb28-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> phase_label_df,</span>
<span id="cb28-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">71</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> label),</span>
<span id="cb28-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb28-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb28-12">    <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;">3.4</span>,</span>
<span id="cb28-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lineheight =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span></span>
<span id="cb28-14">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb28-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb28-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">84</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clip =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"off"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb28-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb28-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb28-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Phase-specific damage functions from the moderated mixed model"</span>,</span>
<span id="cb28-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb28-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yield (kg/ha)"</span></span>
<span id="cb28-22">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb28-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.margin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">margin</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">70</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-18-1.png" class="img-fluid figure-img" width="806"></p>
</figure>
</div>
</div>
</div>
<p>Because disease damage is often easier to interpret on a relative scale, it is also useful to express the same bootstrap results in terms of percentage yield loss.</p>
<p>The next plot follows the same logic, but the y-axis is now expressed as relative yield loss rather than absolute yield.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(enso_curves, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, rel_loss_fit)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># prediction interval on the relative-loss scale</span></span>
<span id="cb29-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_ribbon</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> rel_loss_pred_lb, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> rel_loss_pred_ub), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#6e8fa4"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.18</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># confidence interval on the relative-loss scale</span></span>
<span id="cb29-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_ribbon</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> rel_loss_conf_lb, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> rel_loss_conf_ub), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1f6f78"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.24</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#154d57"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.35</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(</span>
<span id="cb29-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> phase_label_df,</span>
<span id="cb29-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">71</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> rel_loss_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> label),</span>
<span id="cb29-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb29-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,</span>
<span id="cb29-12">    <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;">3.4</span>,</span>
<span id="cb29-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lineheight =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span></span>
<span id="cb29-14">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">84</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clip =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"off"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb29-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative yield loss implied by the moderated mixed model"</span>,</span>
<span id="cb29-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb29-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative yield loss (%)"</span></span>
<span id="cb29-22">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.margin =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">margin</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">70</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5.5</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-19-1.png" class="img-fluid figure-img" width="806"></p>
</figure>
</div>
</div>
</div>
<p>This step preserves interpretation at the mixed-model level. We are still working with the fixed effects from a mixed-effects model fitted with <code>lmer()</code>, but now expressing them in the classical language of attainable yield, slope, and damage coefficient.</p>
<p>The mixed-effects workflow keeps the raw observations in a single model. That is often the most natural route when the analyst has access to the complete dataset. Sometimes, however, the scientific question is framed differently: each study contributes its own damage estimate, and the synthesis happens at the study level. That is the logic of the next workflow.</p>
</section>
</section>
<section id="a-separate-route-study-level-regressions-followed-by-meta-analysis" class="level2">
<h2 class="anchored" data-anchor-id="a-separate-route-study-level-regressions-followed-by-meta-analysis">A separate route: study-level regressions followed by meta-analysis</h2>
<p>The inferential logic of meta-analysis is distinct from that of mixed models and is therefore best presented as a separate workflow. The important shift is that the study, not the individual observation, becomes the main unit of synthesis.</p>
<p>With mixed-effects modeling, we model the raw data directly.</p>
<p>With meta-analysis, the workflow proceeds by fitting a series of regressions, one for each study, and only then synthesizing the resulting study-level damage estimates. In this workflow, the study-specific damage coefficient is obtained through two regression steps, following the logic commonly used in classical yield loss analyses. The earlier selection step matters especially here because weak study-level gradients can produce unstable slopes and misleading sampling variances.</p>
<p>So the sequence is:</p>
<ol type="1">
<li>fit an ordinary regression for each study</li>
<li>extract intercept and slope</li>
<li>compute the study-specific damage coefficient</li>
<li>estimate its sampling variance</li>
<li>meta-analyze those study-level estimates</li>
</ol>
<section id="step-1.-first-regression-yield-on-severity-within-each-study" class="level3">
<h3 class="anchored" data-anchor-id="step-1.-first-regression-yield-on-severity-within-each-study">Step 1. First regression: yield on severity within each study</h3>
<p>The first regression provides the study-specific intercept and slope. The intercept is carried forward as the study-specific estimate of attainable yield, so this step is not just a preliminary calculation; it defines the scale on which relative loss will be computed.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># One row per selected study; each nested dataset is analyzed separately.</span></span>
<span id="cb30-2">study_regression_1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> damage_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb30-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nest</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</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;">c</span>(study, year, enso)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb30-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb30-5">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># First regression: absolute yield as a function of severity.</span></span>
<span id="cb30-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fit_yield =</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(data, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(yield <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> severity, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> .x)),</span>
<span id="cb30-7">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># The intercept is carried forward as study-specific attainable yield.</span></span>
<span id="cb30-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">intercept =</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(fit_yield, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(.x)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]),</span>
<span id="cb30-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">slope_yield =</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(fit_yield, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(.x)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb30-10">  )</span>
<span id="cb30-11"></span>
<span id="cb30-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Show the first-step coefficients before transforming the response.</span></span>
<span id="cb30-13">study_regression_1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb30-14">  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;">select</span>(study, year, enso, intercept, slope_yield) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb30-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_head</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;">8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb30-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb30-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">intercept =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(intercept, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb30-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">slope_yield =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(slope_yield, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb30-19">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb30-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study-specific coefficients from the first regression"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>Study-specific coefficients from the first regression</caption>
<thead>
<tr class="header">
<th style="text-align: left;">study</th>
<th style="text-align: left;">year</th>
<th style="text-align: left;">enso</th>
<th style="text-align: right;">intercept</th>
<th style="text-align: right;">slope_yield</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">4482.26</td>
<td style="text-align: right;">-24.37</td>
</tr>
<tr class="even">
<td style="text-align: left;">2</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: right;">4189.33</td>
<td style="text-align: right;">-21.67</td>
</tr>
<tr class="odd">
<td style="text-align: left;">3</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: right;">4440.60</td>
<td style="text-align: right;">-32.61</td>
</tr>
<tr class="even">
<td style="text-align: left;">4</td>
<td style="text-align: left;">2014</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">3893.56</td>
<td style="text-align: right;">-20.64</td>
</tr>
<tr class="odd">
<td style="text-align: left;">5</td>
<td style="text-align: left;">2014</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: right;">4333.12</td>
<td style="text-align: right;">-15.47</td>
</tr>
<tr class="even">
<td style="text-align: left;">6</td>
<td style="text-align: left;">2014</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: right;">4325.53</td>
<td style="text-align: right;">-29.08</td>
</tr>
<tr class="odd">
<td style="text-align: left;">7</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">4323.19</td>
<td style="text-align: right;">-26.14</td>
</tr>
<tr class="even">
<td style="text-align: left;">8</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: right;">4104.14</td>
<td style="text-align: right;">-22.33</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>Before moving to the relative-loss scale, it is helpful to visualize what the first regression is doing. Each line below represents the fitted severity-yield relationship for a single study, stratified by ENSO phase. This makes explicit that the first step of the meta-analytic workflow is not a single pooled regression, but rather a collection of study-specific linear damage functions from which intercepts and slopes are extracted.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create fitted lines from the first regression for visualization.</span></span>
<span id="cb31-2">study_line_grid <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb31-3">  study_regression_1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</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;">select</span>(study, enso, intercept, slope_yield),</span>
<span id="cb31-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">severity =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb31-5">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb31-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb31-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fitted_yield =</span> intercept <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> slope_yield <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> severity,</span>
<span id="cb31-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(enso, <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;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>))</span>
<span id="cb31-9">  )</span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(study_line_grid, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, fitted_yield, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> study, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> enso)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.55</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> enso_palette) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb32-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study-specific severity-yield regressions from step 1"</span>,</span>
<span id="cb32-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb32-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Yield (kg/ha)"</span></span>
<span id="cb32-10">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-22-1.png" class="img-fluid figure-img" width="825"></p>
</figure>
</div>
</div>
</div>
<p>The next figure summarizes the study-specific coefficients extracted from those first-step regressions. The point clouds represent the individual study estimates, while the larger points and horizontal segments show the phase-specific means and central ranges. This display is useful because it separates variation in attainable yield from variation in absolute damage rate before the transformation to relative loss is introduced.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Put intercepts and slopes into one table for a compact coefficient plot.</span></span>
<span id="cb33-2">study_parameter_plot_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;">bind_rows</span>(</span>
<span id="cb33-3">  study_regression_1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb33-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb33-5">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(enso, <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;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>)),</span>
<span id="cb33-6">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parameter =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Intercept"</span>,</span>
<span id="cb33-7">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> intercept</span>
<span id="cb33-8">    ),</span>
<span id="cb33-9">  study_regression_1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb33-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb33-11">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(enso, <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;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>)),</span>
<span id="cb33-12">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parameter =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Slope"</span>,</span>
<span id="cb33-13">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> slope_yield</span>
<span id="cb33-14">    )</span>
<span id="cb33-15">)</span>
<span id="cb33-16"></span>
<span id="cb33-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Summarize each phase so individual estimates can be compared with group patterns.</span></span>
<span id="cb33-18">study_parameter_summary <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> study_parameter_plot_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb33-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(parameter, enso) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb33-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb33-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_estimate =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(estimate),</span>
<span id="cb33-22">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q25 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(estimate, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>),</span>
<span id="cb33-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q75 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(estimate, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>),</span>
<span id="cb33-24">    <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="cb33-25">  )</span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(study_parameter_plot_df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> estimate, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> enso)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb34-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(</span>
<span id="cb34-3">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_jitter</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.08</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb34-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.45</span>,</span>
<span id="cb34-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.7</span>,</span>
<span id="cb34-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb34-7">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb34-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_segment</span>(</span>
<span id="cb34-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study_parameter_summary,</span>
<span id="cb34-10">    <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> q25, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xend =</span> q75, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yend =</span> enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> enso),</span>
<span id="cb34-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.8</span>,</span>
<span id="cb34-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">inherit.aes =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb34-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb34-14">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb34-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(</span>
<span id="cb34-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study_parameter_summary,</span>
<span id="cb34-17">    <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> mean_estimate, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> enso),</span>
<span id="cb34-18">    <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;">3.2</span>,</span>
<span id="cb34-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">inherit.aes =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb34-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb34-21">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb34-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>parameter, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_x"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb34-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> enso_palette) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb34-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb34-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb34-26">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study-level intercept and slope estimates from step 1"</span>,</span>
<span id="cb34-27">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Parameter estimate"</span>,</span>
<span id="cb34-28">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb34-29">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-24-1.png" class="img-fluid figure-img" width="825"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="step-2.-relative-yield-loss-based-on-the-study-specific-intercept" class="level3">
<h3 class="anchored" data-anchor-id="step-2.-relative-yield-loss-based-on-the-study-specific-intercept">Step 2. Relative yield loss based on the study-specific intercept</h3>
<p>Following the classical logic, yield loss is now expressed relative to the attainable yield of each study. For each observation:</p>
<p><img src="https://latex.codecogs.com/png.latex?L%20=%20100%20%5Ctimes%20%5Cfrac%7Bb_0%20-%20Y%7D%7Bb_0%7D"></p>
<p>where <img src="https://latex.codecogs.com/png.latex?L"> is relative yield loss in percent and <img src="https://latex.codecogs.com/png.latex?b_0"> is the study-specific attainable yield obtained from the first regression.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Join the study-specific attainable yield back to every observation.</span></span>
<span id="cb35-2">relative_loss_df <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> damage_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb35-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(</span>
<span id="cb35-4">    study_regression_1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb35-5">      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;">select</span>(study, year, enso, intercept),</span>
<span id="cb35-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</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;">"study"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"enso"</span>)</span>
<span id="cb35-7">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb35-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb35-9">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Step 2 transformation: absolute yield becomes relative yield loss.</span></span>
<span id="cb35-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">relative_loss =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (intercept <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> yield) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> intercept</span>
<span id="cb35-11">  )</span>
<span id="cb35-12"></span>
<span id="cb35-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Inspect the transformed response before fitting second-step regressions.</span></span>
<span id="cb35-14">relative_loss_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb35-15">  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;">select</span>(study, enso, severity, yield, intercept, relative_loss) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb35-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_head</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;">8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb35-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb35-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(severity, yield, intercept, relative_loss), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(.x, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb35-19">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb35-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative yield loss calculated from the study-specific attainable yield"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>Relative yield loss calculated from the study-specific attainable yield</caption>
<thead>
<tr class="header">
<th style="text-align: left;">study</th>
<th style="text-align: left;">enso</th>
<th style="text-align: right;">severity</th>
<th style="text-align: right;">yield</th>
<th style="text-align: right;">intercept</th>
<th style="text-align: right;">relative_loss</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">2.08</td>
<td style="text-align: right;">4286.70</td>
<td style="text-align: right;">4482.26</td>
<td style="text-align: right;">4.36</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">2.28</td>
<td style="text-align: right;">4635.06</td>
<td style="text-align: right;">4482.26</td>
<td style="text-align: right;">-3.41</td>
</tr>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">6.28</td>
<td style="text-align: right;">4345.97</td>
<td style="text-align: right;">4482.26</td>
<td style="text-align: right;">3.04</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">10.18</td>
<td style="text-align: right;">4221.84</td>
<td style="text-align: right;">4482.26</td>
<td style="text-align: right;">5.81</td>
</tr>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">22.07</td>
<td style="text-align: right;">3819.73</td>
<td style="text-align: right;">4482.26</td>
<td style="text-align: right;">14.78</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">23.27</td>
<td style="text-align: right;">3949.15</td>
<td style="text-align: right;">4482.26</td>
<td style="text-align: right;">11.89</td>
</tr>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">23.76</td>
<td style="text-align: right;">3833.61</td>
<td style="text-align: right;">4482.26</td>
<td style="text-align: right;">14.47</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">27.05</td>
<td style="text-align: right;">3784.80</td>
<td style="text-align: right;">4482.26</td>
<td style="text-align: right;">15.56</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>At this stage, the response variable has changed. The figure below shows the observation-level relative yield loss obtained after scaling each yield value by the study-specific attainable yield from the first regression. This step is critical because it moves the analysis from the absolute scale of yield to the proportional scale on which the damage coefficient is defined. It also means that uncertainty in the first-regression intercept can influence the second-stage effect size.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(relative_loss_df, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, relative_loss, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> enso)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb36-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey40"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb36-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</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;">1.8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb36-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb36-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> enso_palette) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb36-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb36-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb36-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Observation-level relative yield loss after the step-2 transformation"</span>,</span>
<span id="cb36-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb36-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative yield loss (%)"</span></span>
<span id="cb36-11">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-26-1.png" class="img-fluid figure-img" width="825"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="step-3.-second-regression-relative-loss-on-severity-through-the-origin" class="level3">
<h3 class="anchored" data-anchor-id="step-3.-second-regression-relative-loss-on-severity-through-the-origin">Step 3. Second regression: relative loss on severity through the origin</h3>
<p>We then fit a second regression for each study:</p>
<p><img src="https://latex.codecogs.com/png.latex?L%20=%20DC%20%5Ctimes%20S"></p>
<p>That is, relative yield loss is regressed on severity with no intercept, and the slope of this second regression is the study-specific damage coefficient. The through-origin constraint encodes the assumption that zero disease corresponds to zero relative disease loss after scaling by attainable yield. This is reasonable for the didactic example, but in empirical work it should be checked against the design, disease range, and presence of other yield-limiting factors.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Fit the second regression separately for each study.</span></span>
<span id="cb37-2">study_effects <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> relative_loss_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb37-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nest</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</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;">c</span>(study, year, enso, intercept)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb37-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb37-5">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># No intercept: zero disease is assumed to imply zero disease-attributable loss.</span></span>
<span id="cb37-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fit_dc =</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(data, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(relative_loss <span 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> severity, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> .x)),</span>
<span id="cb37-7">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># The slope is the study-level damage coefficient.</span></span>
<span id="cb37-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">damage_coefficient =</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(fit_dc, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(.x)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]),</span>
<span id="cb37-9">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Sampling variance is needed for inverse-variance weighting in meta-analysis.</span></span>
<span id="cb37-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vi_dc =</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(fit_dc, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vcov</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;">1</span>]),</span>
<span id="cb37-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sei_dc =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(vi_dc)</span>
<span id="cb37-12">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb37-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>()</span>
<span id="cb37-14"></span>
<span id="cb37-15">study_effects <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb37-16">  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;">select</span>(study, year, enso, damage_coefficient, sei_dc) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb37-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_head</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;">8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb37-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb37-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">damage_coefficient =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(damage_coefficient, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb37-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sei_dc =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(sei_dc, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb37-21">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb37-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study-level damage coefficients from the second regression"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>Study-level damage coefficients from the second regression</caption>
<thead>
<tr class="header">
<th style="text-align: left;">study</th>
<th style="text-align: left;">year</th>
<th style="text-align: left;">enso</th>
<th style="text-align: right;">damage_coefficient</th>
<th style="text-align: right;">sei_dc</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">0.544</td>
<td style="text-align: right;">0.0192</td>
</tr>
<tr class="even">
<td style="text-align: left;">2</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: right;">0.517</td>
<td style="text-align: right;">0.0214</td>
</tr>
<tr class="odd">
<td style="text-align: left;">3</td>
<td style="text-align: left;">2013</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: right;">0.734</td>
<td style="text-align: right;">0.0248</td>
</tr>
<tr class="even">
<td style="text-align: left;">4</td>
<td style="text-align: left;">2014</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">0.530</td>
<td style="text-align: right;">0.0179</td>
</tr>
<tr class="odd">
<td style="text-align: left;">5</td>
<td style="text-align: left;">2014</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: right;">0.357</td>
<td style="text-align: right;">0.0200</td>
</tr>
<tr class="even">
<td style="text-align: left;">6</td>
<td style="text-align: left;">2014</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: right;">0.672</td>
<td style="text-align: right;">0.0244</td>
</tr>
<tr class="odd">
<td style="text-align: left;">7</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">0.605</td>
<td style="text-align: right;">0.0249</td>
</tr>
<tr class="even">
<td style="text-align: left;">8</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: right;">0.544</td>
<td style="text-align: right;">0.0129</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The second regression is easier to interpret visually when represented as a family of lines constrained to pass through the origin. Each line below is a study-specific estimate of the damage coefficient, obtained from regressing relative yield loss on severity without an intercept. The slope of each line is therefore the study-level damage coefficient used in the subsequent meta-analysis.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create study-specific damage lines for visualization.</span></span>
<span id="cb38-2">dc_line_grid <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb38-3">  study_effects <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</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;">select</span>(study, enso, damage_coefficient),</span>
<span id="cb38-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">severity =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb38-5">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb38-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb38-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">relative_loss =</span> damage_coefficient <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> severity,</span>
<span id="cb38-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(enso, <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;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>))</span>
<span id="cb38-9">  )</span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(dc_line_grid, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(severity, relative_loss, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> study, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> enso)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb39-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.55</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb39-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb39-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> enso_palette) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb39-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb39-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb39-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb39-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Study-specific damage functions from step 3"</span>,</span>
<span id="cb39-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb39-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relative yield loss (%)"</span></span>
<span id="cb39-11">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-29-1.png" class="img-fluid figure-img" width="825"></p>
</figure>
</div>
</div>
</div>
<p>Because the second-step slopes are the quantities ultimately synthesized in the meta-analysis, it is also useful to examine their empirical distribution before fitting the meta-analytic model. The histogram below gives a direct view of how the study-level damage coefficients are distributed within each ENSO phase.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(study_effects, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(damage_coefficient)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb40-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey35"</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;">"white"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb40-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb40-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb40-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb40-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution of study-level damage coefficients before meta-analysis"</span>,</span>
<span id="cb40-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Damage coefficient (% yield loss per 1% severity)"</span>,</span>
<span id="cb40-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Count"</span></span>
<span id="cb40-9">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-30-1.png" class="img-fluid figure-img" width="825"></p>
</figure>
</div>
</div>
</div>
<p>The variance calculation is critical. A meta-analytic model does not only require the effect size estimate (<code>yi</code>); it also requires the corresponding sampling variance (<code>vi</code>) or standard error. Without that information, studies cannot be weighted appropriately. The simple variance used here comes from the second regression and keeps the example transparent; a publication-level analysis may need a delta-method, bootstrap, or joint-model strategy to propagate uncertainty from both regression steps.</p>
</section>
</section>
<section id="fitting-the-meta-analytic-model" class="level2">
<h2 class="anchored" data-anchor-id="fitting-the-meta-analytic-model">Fitting the meta-analytic model</h2>
<p>The study-specific damage coefficients can now be synthesized with a multilevel meta-analytic model. Because studies are clustered within years, I use <code>rma.mv()</code> instead of <code>rma.uni()</code>. This preserves the study-level effect-size logic while recognizing that estimates from the same year may share environmental, management, or assessment conditions.</p>
<p>At this point the data have changed shape. We are no longer modeling each yield observation directly. We are modeling the collection of study-level damage coefficients and their sampling variances.</p>
<section id="a-meta-analytic-estimate-without-moderators" class="level3">
<h3 class="anchored" data-anchor-id="a-meta-analytic-estimate-without-moderators">A meta-analytic estimate without moderators</h3>
<p>The first meta-analytic step mirrors the general mixed-effects summary: a single pooled damage coefficient across all studies, without moderators.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb41" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb41-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Overall synthesis of study-level damage coefficients.</span></span>
<span id="cb41-2">meta_damage_overall <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rma.mv</span>(</span>
<span id="cb41-3">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># yi is the study-level effect size; V is its sampling variance.</span></span>
<span id="cb41-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yi =</span> damage_coefficient,</span>
<span id="cb41-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">V =</span> vi_dc,</span>
<span id="cb41-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mods =</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="cb41-7">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Studies are nested within years in this simulated example.</span></span>
<span id="cb41-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">random =</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> year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>study,</span>
<span id="cb41-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"REML"</span>,</span>
<span id="cb41-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study_effects</span>
<span id="cb41-11">)</span>
<span id="cb41-12"></span>
<span id="cb41-13">meta_damage_overall</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>
Multivariate Meta-Analysis Model (k = 18; method: REML)

Variance Components:

            estim    sqrt  nlvls  fixed      factor 
sigma^2.1  0.0000  0.0000      6     no        year 
sigma^2.2  0.0113  0.1065     18     no  year/study 

Test for Heterogeneity:
Q(df = 17) = 472.1951, p-val &lt; .0001

Model Results:

estimate      se     zval    pval   ci.lb   ci.ub      
  0.5466  0.0256  21.3612  &lt;.0001  0.4965  0.5968  *** 

---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</code></pre>
</div>
</div>
<p>This model answers a simple question: if ENSO is ignored and all study-level damage coefficients are pooled together, what is the average damage coefficient implied by the meta-analytic structure?</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb43" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb43-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Extract the pooled estimate and uncertainty from the overall meta-analysis.</span></span>
<span id="cb43-2">meta_overall_summary <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb43-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Meta-analysis"</span>,</span>
<span id="cb43-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(meta_damage_overall))[<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;">"estimate"</span>],</span>
<span id="cb43-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(meta_damage_overall))[<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;">"se"</span>],</span>
<span id="cb43-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_lb =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(meta_damage_overall))[<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;">"ci.lb"</span>],</span>
<span id="cb43-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_ub =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(meta_damage_overall))[<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;">"ci.ub"</span>]</span>
<span id="cb43-8">)</span>
<span id="cb43-9"></span>
<span id="cb43-10">meta_overall_summary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb43-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(estimate, se, ci_lb, ci_ub), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(.x, <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;">%&gt;%</span></span>
<span id="cb43-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Overall meta-analytic damage coefficient without moderators"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>Overall meta-analytic damage coefficient without moderators</caption>
<thead>
<tr class="header">
<th style="text-align: left;">method</th>
<th style="text-align: right;">estimate</th>
<th style="text-align: right;">se</th>
<th style="text-align: right;">ci_lb</th>
<th style="text-align: right;">ci_ub</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Meta-analysis</td>
<td style="text-align: right;">0.547</td>
<td style="text-align: right;">0.026</td>
<td style="text-align: right;">0.496</td>
<td style="text-align: right;">0.597</td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
<section id="a-meta-analytic-estimate-with-enso-as-moderator" class="level3">
<h3 class="anchored" data-anchor-id="a-meta-analytic-estimate-with-enso-as-moderator">A meta-analytic estimate with ENSO as moderator</h3>
<p>The second meta-analytic model introduces ENSO as a moderator, so that pooled damage coefficients are estimated separately for each phase.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb44" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb44-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Moderator model: estimate one pooled damage coefficient per ENSO phase.</span></span>
<span id="cb44-2">meta_damage <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rma.mv</span>(</span>
<span id="cb44-3">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># The effect size and variance are the same as above.</span></span>
<span id="cb44-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yi =</span> damage_coefficient,</span>
<span id="cb44-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">V =</span> vi_dc,</span>
<span id="cb44-6">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Removing the intercept gives one coefficient for each ENSO phase.</span></span>
<span id="cb44-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mods =</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;">0</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> enso,</span>
<span id="cb44-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">random =</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> year<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>study,</span>
<span id="cb44-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"REML"</span>,</span>
<span id="cb44-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study_effects</span>
<span id="cb44-11">)</span>
<span id="cb44-12"></span>
<span id="cb44-13">meta_damage</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>
Multivariate Meta-Analysis Model (k = 18; method: REML)

Variance Components:

            estim    sqrt  nlvls  fixed      factor 
sigma^2.1  0.0000  0.0000      6     no        year 
sigma^2.2  0.0033  0.0573     18     no  year/study 

Test for Residual Heterogeneity:
QE(df = 15) = 161.7665, p-val &lt; .0001

Test of Moderators (coefficients 1:3):
QM(df = 3) = 1481.4279, p-val &lt; .0001

Model Results:

             estimate      se     zval    pval   ci.lb   ci.ub      
ensoNeutral    0.5547  0.0250  22.2185  &lt;.0001  0.5057  0.6036  *** 
ensoCold       0.4335  0.0248  17.4659  &lt;.0001  0.3848  0.4821  *** 
ensoWarm       0.6522  0.0250  26.1287  &lt;.0001  0.6033  0.7011  *** 

---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</code></pre>
</div>
</div>
<p>This model estimates a pooled damage coefficient for each ENSO phase while accounting for residual heterogeneity and clustering among studies within years.</p>
</section>
<section id="extracting-pooled-estimates" class="level3">
<h3 class="anchored" data-anchor-id="extracting-pooled-estimates">Extracting pooled estimates</h3>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb46" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Convert the metafor coefficient table into a tidy summary.</span></span>
<span id="cb46-2">meta_summary <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb46-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^enso"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rownames</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(meta_damage)))),</span>
<span id="cb46-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(meta_damage))[,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"estimate"</span>],</span>
<span id="cb46-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(meta_damage))[,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"se"</span>],</span>
<span id="cb46-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_lb =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(meta_damage))[,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ci.lb"</span>],</span>
<span id="cb46-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_ub =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(meta_damage))[,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ci.ub"</span>]</span>
<span id="cb46-8">)</span>
<span id="cb46-9"></span>
<span id="cb46-10">meta_summary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb46-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb46-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(estimate, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb46-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(se, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb46-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_lb =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(ci_lb, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb46-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_ub =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(ci_ub, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb46-16">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb46-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Meta-analytic damage coefficient estimates by ENSO phase"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>Meta-analytic damage coefficient estimates by ENSO phase</caption>
<thead>
<tr class="header">
<th style="text-align: left;">enso</th>
<th style="text-align: right;">estimate</th>
<th style="text-align: right;">se</th>
<th style="text-align: right;">ci_lb</th>
<th style="text-align: right;">ci_ub</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">0.555</td>
<td style="text-align: right;">0.025</td>
<td style="text-align: right;">0.506</td>
<td style="text-align: right;">0.604</td>
</tr>
<tr class="even">
<td style="text-align: left;">Cold</td>
<td style="text-align: right;">0.433</td>
<td style="text-align: right;">0.025</td>
<td style="text-align: right;">0.385</td>
<td style="text-align: right;">0.482</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Warm</td>
<td style="text-align: right;">0.652</td>
<td style="text-align: right;">0.025</td>
<td style="text-align: right;">0.603</td>
<td style="text-align: right;">0.701</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The next figure summarizes the pooled damage coefficient estimates and their uncertainty at the meta-analytic level for the ENSO-specific model.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb47" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb47-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(meta_summary, <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> enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> estimate, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> enso)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb47-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb47-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbar</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> ci_lb, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> ci_ub), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.08</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb47-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> enso_palette) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb47-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb47-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb47-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Meta-analytic estimates of the damage coefficient"</span>,</span>
<span id="cb47-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ENSO phase"</span>,</span>
<span id="cb47-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Damage coefficient (% yield loss per 1% severity)"</span>,</span>
<span id="cb47-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ENSO phase"</span></span>
<span id="cb47-11">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb47-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-35-1.png" class="img-fluid figure-img" width="691"></p>
</figure>
</div>
</div>
</div>
</section>
</section>
<section id="comparing-mixed-effects-and-meta-analytic-estimates" class="level2">
<h2 class="anchored" data-anchor-id="comparing-mixed-effects-and-meta-analytic-estimates">Comparing mixed-effects and meta-analytic estimates</h2>
<p>At this point, it becomes possible to compare the two strategies directly. This comparison is informative because the two methods do not operate on the same inferential target:</p>
<ul>
<li>mixed-effects modeling summarizes the full hierarchical dataset at the observation level</li>
<li>meta-analysis summarizes study-level damage coefficients after the two-regression workflow</li>
</ul>
<section id="comparing-the-overall-damage-coefficient" class="level3">
<h3 class="anchored" data-anchor-id="comparing-the-overall-damage-coefficient">Comparing the overall damage coefficient</h3>
<p>The first comparison ignores moderators and asks whether both methods support a similar overall interpretation of disease damage.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb48" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb48-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Keep only the damage coefficient from the mixed-model summary.</span></span>
<span id="cb48-2">lmer_overall_compare <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> overall_damage <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb48-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(term <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Damage coefficient"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb48-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb48-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mixed-effects"</span>,</span>
<span id="cb48-6">    estimate,</span>
<span id="cb48-7">    ci_lb,</span>
<span id="cb48-8">    ci_ub</span>
<span id="cb48-9">  )</span>
<span id="cb48-10"></span>
<span id="cb48-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Put the two methods on the same scale for comparison.</span></span>
<span id="cb48-12">overall_compare <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb48-13">  lmer_overall_compare,</span>
<span id="cb48-14">  meta_overall_summary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb48-15">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb48-16">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Meta-analysis"</span>,</span>
<span id="cb48-17">      estimate,</span>
<span id="cb48-18">      ci_lb,</span>
<span id="cb48-19">      ci_ub</span>
<span id="cb48-20">    )</span>
<span id="cb48-21">)</span>
<span id="cb48-22"></span>
<span id="cb48-23">overall_compare <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb48-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(estimate, ci_lb, ci_ub), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(.x, <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;">%&gt;%</span></span>
<span id="cb48-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Comparison of the overall damage coefficient from mixed-effects and meta-analytic models"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>Comparison of the overall damage coefficient from mixed-effects and meta-analytic models</caption>
<thead>
<tr class="header">
<th style="text-align: left;">method</th>
<th style="text-align: right;">estimate</th>
<th style="text-align: right;">ci_lb</th>
<th style="text-align: right;">ci_ub</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Mixed-effects</td>
<td style="text-align: right;">0.550</td>
<td style="text-align: right;">0.500</td>
<td style="text-align: right;">0.600</td>
</tr>
<tr class="even">
<td style="text-align: left;">Meta-analysis</td>
<td style="text-align: right;">0.547</td>
<td style="text-align: right;">0.496</td>
<td style="text-align: right;">0.597</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The next plot presents that comparison graphically.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb49" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb49-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(overall_compare, <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> method, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> estimate, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> method)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb49-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># point estimate from each method</span></span>
<span id="cb49-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb49-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># uncertainty interval from each method</span></span>
<span id="cb49-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbar</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> ci_lb, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> ci_ub), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.08</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb49-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mixed-effects"</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;">"#154d57"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Meta-analysis"</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;">"#c84c09"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb49-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb49-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb49-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Overall damage coefficient: mixed-effects versus meta-analysis"</span>,</span>
<span id="cb49-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Method"</span>,</span>
<span id="cb49-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Damage coefficient (% yield loss per 1% severity)"</span></span>
<span id="cb49-12">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb49-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-37-1.png" class="img-fluid figure-img" width="652"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="comparing-the-enso-specific-damage-coefficients" class="level3">
<h3 class="anchored" data-anchor-id="comparing-the-enso-specific-damage-coefficients">Comparing the ENSO-specific damage coefficients</h3>
<p>The second comparison preserves the ENSO structure and asks whether the phase-specific pattern is consistent across methods.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb50" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb50-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Extract ENSO-specific damage coefficients from the mixed-model route.</span></span>
<span id="cb50-2">lmer_phase_compare <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> lmer_phase_estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb50-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(parameter <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Damage coefficient"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb50-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb50-5">    enso,</span>
<span id="cb50-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mixed-effects"</span>,</span>
<span id="cb50-7">    estimate,</span>
<span id="cb50-8">    ci_lb,</span>
<span id="cb50-9">    ci_ub</span>
<span id="cb50-10">  )</span>
<span id="cb50-11"></span>
<span id="cb50-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Put ENSO-specific mixed-model and meta-analytic estimates together.</span></span>
<span id="cb50-13">meta_phase_compare <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> meta_summary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb50-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb50-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(enso, <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;">"Neutral"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Warm"</span>)),</span>
<span id="cb50-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Meta-analysis"</span>,</span>
<span id="cb50-17">    estimate,</span>
<span id="cb50-18">    ci_lb,</span>
<span id="cb50-19">    ci_ub</span>
<span id="cb50-20">  )</span>
<span id="cb50-21"></span>
<span id="cb50-22">phase_compare <span class="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>(lmer_phase_compare, meta_phase_compare)</span>
<span id="cb50-23"></span>
<span id="cb50-24">phase_compare <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb50-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(estimate, ci_lb, ci_ub), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(.x, <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;">%&gt;%</span></span>
<span id="cb50-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ENSO-specific damage coefficient estimates from mixed-effects and meta-analytic models"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>ENSO-specific damage coefficient estimates from mixed-effects and meta-analytic models</caption>
<thead>
<tr class="header">
<th style="text-align: left;">enso</th>
<th style="text-align: left;">method</th>
<th style="text-align: right;">estimate</th>
<th style="text-align: right;">ci_lb</th>
<th style="text-align: right;">ci_ub</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Mixed-effects</td>
<td style="text-align: right;">0.550</td>
<td style="text-align: right;">0.510</td>
<td style="text-align: right;">0.600</td>
</tr>
<tr class="even">
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">Mixed-effects</td>
<td style="text-align: right;">0.430</td>
<td style="text-align: right;">0.380</td>
<td style="text-align: right;">0.480</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Mixed-effects</td>
<td style="text-align: right;">0.660</td>
<td style="text-align: right;">0.610</td>
<td style="text-align: right;">0.700</td>
</tr>
<tr class="even">
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Meta-analysis</td>
<td style="text-align: right;">0.555</td>
<td style="text-align: right;">0.506</td>
<td style="text-align: right;">0.604</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">Meta-analysis</td>
<td style="text-align: right;">0.433</td>
<td style="text-align: right;">0.385</td>
<td style="text-align: right;">0.482</td>
</tr>
<tr class="even">
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Meta-analysis</td>
<td style="text-align: right;">0.652</td>
<td style="text-align: right;">0.603</td>
<td style="text-align: right;">0.701</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The plot below allows the ENSO-specific <code>DC</code> values to be compared side by side.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb51" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb51-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(phase_compare, <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> enso, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> estimate, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> method)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb51-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># position dodge separates the two methods inside each ENSO phase</span></span>
<span id="cb51-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_dodge</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.35</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb51-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbar</span>(</span>
<span id="cb51-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> ci_lb, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> ci_ub),</span>
<span id="cb51-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">position =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">position_dodge</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.35</span>),</span>
<span id="cb51-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.08</span>,</span>
<span id="cb51-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span></span>
<span id="cb51-9">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb51-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mixed-effects"</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;">"#154d57"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Meta-analysis"</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;">"#c84c09"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb51-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">background_grid</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb51-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb51-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ENSO-specific damage coefficients: mixed-effects versus meta-analysis"</span>,</span>
<span id="cb51-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ENSO phase"</span>,</span>
<span id="cb51-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Damage coefficient (% yield loss per 1% severity)"</span>,</span>
<span id="cb51-16">    <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;">"Method"</span></span>
<span id="cb51-17">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-39-1.png" class="img-fluid figure-img" width="748"></p>
</figure>
</div>
</div>
</div>
<p>If both approaches support a similar biological interpretation, we should observe broad agreement in the ordering and magnitude of the damage coefficients. If they differ, that discrepancy is itself informative, because the methods summarize different statistical objects and use different weighting logic.</p>
<p>Under this type of model, interpretation is relatively straightforward:</p>
<ul>
<li>larger values indicate greater proportional yield loss per unit increase in disease</li>
<li>differences among phases suggest that the severity-yield relationship changes with context</li>
<li>residual heterogeneity indicates that the damage process is not fully explained by the moderator alone</li>
</ul>
</section>
</section>
<section id="mixed-effects-modeling-or-meta-analysis" class="level2">
<h2 class="anchored" data-anchor-id="mixed-effects-modeling-or-meta-analysis">Mixed-effects modeling or meta-analysis?</h2>
<p>These approaches answer related but distinct questions.</p>
<p>Use mixed-effects modeling when:</p>
<ul>
<li>you want to model the full hierarchical dataset directly</li>
<li>you need study-level random intercepts and random slopes</li>
<li>you want to test fixed effects and interactions at the observation level</li>
</ul>
<p>Use meta-analysis when:</p>
<ul>
<li>your primary unit of inference is the study-level effect size</li>
<li>you want to synthesize slopes or damage coefficients across many studies</li>
<li>you need a formal meta-analytic framework for moderators and heterogeneity</li>
</ul>
<p>In applied work, both approaches can be part of the same analytical workflow rather than viewed as competitors. A mixed model helps describe the raw hierarchical structure of the data, whereas a meta-analysis summarizes and compares study-level damage processes. The comparison above is useful precisely because it shows where the two perspectives converge and where they diverge.</p>
<p>For a reader trying to reproduce the workflow, the practical lesson is simple: choose the method after deciding what the unit of inference should be. If the question is about the full hierarchical dataset, start with the mixed model. If the question is about synthesizing study-specific damage estimates, build the study-level effect sizes carefully and then use meta-analysis.</p>
</section>
<section id="final-remarks" class="level2">
<h2 class="anchored" data-anchor-id="final-remarks">Final remarks</h2>
<p>Yield loss modeling in plant pathology involves considerably more than fitting a regression line between severity and yield. It requires deciding which disease metric is meaningful, which studies are informative, which yield baseline is defensible, and which inferential target the analysis is trying to estimate. The central parameters each address a different scientific question:</p>
<ul>
<li>attainable yield asks what the crop could produce in the absence of disease under the studied conditions</li>
<li>slope asks how quickly yield declines as disease increases</li>
<li>damage coefficient asks how large that decline is in relative terms</li>
</ul>
<p>From that point onward, model choice depends on the inferential objective. If the interest lies in the full hierarchical dataset, mixed-effects modeling is often the natural starting point. If the objective is the synthesis of study-specific damage estimates, a meta-analytic framework becomes essential.</p>
<p>The study-selection step belongs in the same inferential workflow as the models. It protects the analysis from studies that lack disease contrast, never reach meaningful disease pressure, or imply implausible attainable yields. Just as importantly, it forces the analyst to state the empirical domain over which the damage coefficient is being estimated.</p>
<p>For plant disease epidemiology, that domain matters. A damage coefficient is interpretable only in relation to the pathosystem, disease metric, assessment timing, production environment, and yield potential represented in the data. Mixed-effects models and meta-analysis provide complementary ways to summarize that evidence, but neither removes the need to inspect whether the included studies are biologically and statistically informative.</p>
<p>Finally, the numerical estimates in this article should be interpreted only as outputs from a simulated teaching example. They are useful for understanding the workflow, but they are not evidence for the magnitude of disease damage in any real production system. Readers interested in empirical conclusions about soybean rust damage under climate variability should refer to the original study and its accompanying analysis page.</p>


</section>

 ]]></description>
  <category>English</category>
  <category>epidemiology</category>
  <category>yield loss</category>
  <category>mixed models</category>
  <category>meta-analysis</category>
  <guid>https://alvesks.com.br/blog/posts/yield-loss/</guid>
  <pubDate>Sun, 12 Apr 2026 03:00:00 GMT</pubDate>
</item>
<item>
  <title>Fungal sensitivity to fungicides in R</title>
  <dc:creator>Kaique Alves</dc:creator>
  <link>https://alvesks.com.br/blog/posts/ec50/</link>
  <description><![CDATA[ 





<p>Hello everyone!</p>
<p>In this post I will show how to estimate fungicide <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D"> values in <code>R</code>. In dose-response terms, <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D"> is the concentration at which a compound inhibits 50% of growth relative to the untreated control.</p>
<p>In plant pathology, <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D"> is widely used to evaluate fungal sensitivity to fungicides. An increase in <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D"> for part of a population may indicate selection toward less sensitive isolates.</p>
<section id="load-the-packages" class="level1">
<h1>Load the packages</h1>
<p>The core model-fitting engine used here is <code>drc</code>, which provides several dose-response models. For stratified, multi-isolate workflows, I also recommend the <a href="https://alvesks.github.io/ec50estimator/" target="_blank"><code>ec50estimator</code></a> project, which was designed specifically to streamline <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D"> estimation in plant pathology datasets. If you do not have the packages installed yet, run <code>install.packages("drc")</code> in your console and install the others as needed.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(drc)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ec50estimator)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cowplot)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggridges)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggthemes)</span></code></pre></div>
</div>
</section>
<section id="data" class="level1">
<h1>Data</h1>
<p>First, we need a dataset from which <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D"> can be estimated. Here I will simulate data using a standard fungicide dose-response relationship (Noel et al.&nbsp;2018). If you already have your own dataset, you can import it directly in <code>R</code> and move to the modeling steps.</p>
<p><img src="https://latex.codecogs.com/png.latex?%20f(x)%20=%20c%20+%5Cfrac%7Bd-c%7D%7B1+exp(b(log(x)-log(e)))%7D"></p>
<p>This is the four-parameter log-logistic model, <code>LL.4()</code>. Its parameters are <code>b</code>, <code>c</code>, <code>d</code>, and <code>e</code>. Parameter <code>b</code> is the slope around the inflection point, <code>c</code> is the lower asymptote, <code>d</code> is the upper asymptote, and <code>e</code> corresponds to the <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D">. Variable <code>x</code> represents the fungicide dose or concentration.</p>
<p>Using this model, we can create a helper function to simulate mycelial growth values.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">grow <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(dose, b,c,d,e){</span>
<span id="cb2-2">  x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> dose</span>
<span id="cb2-3">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> c <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>c)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(b<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(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;">log</span>(e))))</span>
<span id="cb2-4">  erro <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> (y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> ( (d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> d) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> y ))</span>
<span id="cb2-5"> </span>
<span id="cb2-6">  </span>
<span id="cb2-7">  growth <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;">rnorm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(x),y, erro)</span>
<span id="cb2-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(growth)</span>
<span id="cb2-9">}</span></code></pre></div>
</div>
<p>Below is a simple example. I create a vector of doses called <code>doses</code>, simulate growth values, and inspect the resulting data frame.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># create dose vector</span></span>
<span id="cb3-2">doses <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;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-6</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-4</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-3</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-2</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb3-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># keeps the simulated values reproducible</span></span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># simulate mycelial growth</span></span>
<span id="cb3-6">growth <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;">grow</span>(doses, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">b =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c =</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;">d =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">e =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.001</span>)</span>
<span id="cb3-7"></span>
<span id="cb3-8">df1 <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;">data.frame</span>(doses,growth)</span>
<span id="cb3-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(df1)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>  doses    growth
1 0e+00 19.749418
2 1e-06 20.054870
3 1e-05 19.405505
4 1e-04 19.816651
5 1e-03 10.724917
6 1e-02  1.245888</code></pre>
</div>
</div>
<p>We can then visualize the simulated observations.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">df1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_jitter</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(doses),growth, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> growth),</span>
<span id="cb5-4">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>,</span>
<span id="cb5-5">              <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;">3.5</span>, </span>
<span id="cb5-6">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(doses),growth), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_viridis_c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">option =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">direction =</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="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dose"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mycelial growth"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal_hgrid</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/ec50/ec50_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="estimating-ec_50-for-a-single-isolate" class="level1">
<h1>Estimating <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D"> for a single isolate</h1>
<p>To estimate <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D">, we first fit an appropriate dose-response model. Here we use <code>drm()</code> from the <code>drc</code> package. We provide:</p>
<ul>
<li>the formula, which maps response and dose columns</li>
<li>the data frame</li>
<li>the model function used for fitting</li>
</ul>
<p>In this example, the formula is <code>growth ~ doses</code>, the data frame is <code>df1</code>, and the model is <code>LL.4()</code>.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">model1 <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;">drm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> growth<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>doses,  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fct =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">LL.4</span>())</span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(model1)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>
Model fitted: Log-logistic (ED50 as parameter) (4 parms)

Parameter estimates:

                 Estimate  Std. Error  t-value   p-value    
b:(Intercept)  1.0447e+00  7.9231e-02  13.1857 2.415e-15 ***
c:(Intercept) -1.7187e-02  2.3108e-01  -0.0744    0.9411    
d:(Intercept)  2.0030e+01  1.8943e-01 105.7401 &lt; 2.2e-16 ***
e:(Intercept)  9.7556e-04  6.5352e-05  14.9277 &lt; 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error:

 0.7130597 (36 degrees of freedom)</code></pre>
</div>
</div>
<p>The fitted curve can be inspected visually.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(model1)</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/ec50/ec50_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>To obtain the <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D"> estimate itself, we use the function <code>ED()</code>. The argument <code>respLev = 50</code> requests the effective dose corresponding to 50% response reduction. Confidence intervals can also be obtained with <code>interval = "delta"</code>. This low-level workflow is useful because it makes the underlying estimation step explicit before moving to larger automated pipelines such as <a href="https://alvesks.github.io/ec50estimator/" target="_blank"><code>ec50estimator</code></a>.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ED</span>(model1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">respLev=</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;">interval =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"delta"</span>)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>
Estimated effective doses

         Estimate Std. Error      Lower      Upper
e:1:50 9.7556e-04 6.5352e-05 8.4302e-04 1.1081e-03</code></pre>
</div>
</div>
</section>
<section id="estimating-ec_50-for-multiple-isolates" class="level1">
<h1>Estimating <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D"> for multiple isolates</h1>
<p>In practice, we often need to estimate <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D"> for many isolates rather than a single one. To illustrate this, I will create a hypothetical dataset with 50 fungal isolates, half collected in an organic field and half in a conventional field. These isolates will be evaluated against two fungicides, here called <code>Fungicide A</code> and <code>Fungicide B</code>.</p>
<section id="fungicide-a" class="level2">
<h2 class="anchored" data-anchor-id="fungicide-a">Fungicide A</h2>
<p>For <code>Fungicide A</code>, I assume isolates from the conventional field are less sensitive.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><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="cb11-2">n_isolates <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;">25</span></span>
<span id="cb11-3"></span>
<span id="cb11-4">nrep <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;">5</span></span>
<span id="cb11-5">n_dose <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;">7</span></span>
<span id="cb11-6">n_field <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;">2</span></span>
<span id="cb11-7">n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> n_isolates<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>nrep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_dose<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_field</span>
<span id="cb11-8">field <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Organic"</span>,nrep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_dose), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Conventional"</span>,nrep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_dose))</span>
<span id="cb11-9">isolate <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;">sort</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>((n_isolates<span 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>)),nrep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_dose))</span>
<span id="cb11-10">doses <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;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-4</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-3</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-2</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),nrep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_field))</span>
<span id="cb11-11">EC50 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5e-3</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-1</span>)</span>
<span id="cb11-12"></span>
<span id="cb11-13"></span>
<span id="cb11-14">fungicide_A <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;">data.frame</span>(isolate,</span>
<span id="cb11-15">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">field =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(field,n_isolates),</span>
<span id="cb11-16">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fungicide =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Fungicide A"</span>,</span>
<span id="cb11-17">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dose =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(doses,n_isolates)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb11-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">effect =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb11-19">    field <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Conventional"</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;">rnorm</span>(n,EC50[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>],<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0001</span>),</span>
<span id="cb11-20">    field <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Organic"</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;">rnorm</span>(n,EC50[<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.0001</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb11-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">growth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grow</span>(dose, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">b =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c =</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;">d =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">e =</span> effect))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb11-22">  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;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>effect)</span>
<span id="cb11-23"></span>
<span id="cb11-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(fungicide_A)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>  isolate   field   fungicide  dose     growth
1       1 Organic Fungicide A 0e+00 20.2082399
2       1 Organic Fungicide A 1e-05 20.1168279
3       1 Organic Fungicide A 1e-04 19.2479678
4       1 Organic Fungicide A 1e-03 15.8123455
5       1 Organic Fungicide A 1e-02  7.3206757
6       1 Organic Fungicide A 1e-01  0.6985264</code></pre>
</div>
</div>
</section>
<section id="fungicide-b" class="level2">
<h2 class="anchored" data-anchor-id="fungicide-b">Fungicide B</h2>
<p>For <code>Fungicide B</code>, I assume both field types have the same sensitivity pattern.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb13-2">n_isolates <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;">25</span></span>
<span id="cb13-3">nrep <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;">5</span></span>
<span id="cb13-4">n_dose <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;">7</span></span>
<span id="cb13-5">n_field <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;">2</span></span>
<span id="cb13-6">n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> n_isolates<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>nrep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_dose<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_field</span>
<span id="cb13-7">field <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Organic"</span>,nrep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_dose), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Conventional"</span>,nrep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_dose))</span>
<span id="cb13-8">isolate <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;">sort</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>((n_isolates<span 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>)),nrep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_dose))</span>
<span id="cb13-9">doses <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;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-4</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-3</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-2</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),nrep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_field))</span>
<span id="cb13-10">EC50 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5e-3</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5e-3</span>)</span>
<span id="cb13-11"></span>
<span id="cb13-12"></span>
<span id="cb13-13">fungicide_B <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;">data.frame</span>(isolate,</span>
<span id="cb13-14">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">field =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(field,n_isolates),</span>
<span id="cb13-15">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fungicide =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Fungicide B"</span>,</span>
<span id="cb13-16">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dose =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(doses,n_isolates)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb13-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">effect =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case_when</span>(</span>
<span id="cb13-18">    field <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Conventional"</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;">rnorm</span>(n,EC50[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>],<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0001</span>),</span>
<span id="cb13-19">    field <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Organic"</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;">rnorm</span>(n,EC50[<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.0001</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb13-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">growth =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grow</span>(dose, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">b =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c =</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;">d =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">e =</span> effect)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb13-21">  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;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>effect)</span>
<span id="cb13-22"></span>
<span id="cb13-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(fungicide_B)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>  isolate   field   fungicide  dose     growth
1       1 Organic Fungicide B 0e+00 20.2082399
2       1 Organic Fungicide B 1e-05 20.1168279
3       1 Organic Fungicide B 1e-04 19.2479678
4       1 Organic Fungicide B 1e-03 15.8123455
5       1 Organic Fungicide B 1e-02  7.3206757
6       1 Organic Fungicide B 1e-01  0.6985264</code></pre>
</div>
</div>
<p>Now we combine the two data frames.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1">fungicide <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> fungicide_A <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(fungicide_B)</span>
<span id="cb15-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(fungicide)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>  isolate   field   fungicide  dose     growth
1       1 Organic Fungicide A 0e+00 20.2082399
2       1 Organic Fungicide A 1e-05 20.1168279
3       1 Organic Fungicide A 1e-04 19.2479678
4       1 Organic Fungicide A 1e-03 15.8123455
5       1 Organic Fungicide A 1e-02  7.3206757
6       1 Organic Fungicide A 1e-01  0.6985264</code></pre>
</div>
</div>
<p>There is a way to fit all isolates at once using <code>drm()</code> with <code>curveid = isolate</code>. However, with large datasets this may become slow, and the resulting object can be difficult to handle.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># DO NOT RUN THIS ON VERY LARGE DATASETS WITHOUT CHECKING PERFORMANCE</span></span>
<span id="cb17-2">model <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;">drm</span>(growth<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>dose, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">curveid =</span> isolate,  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fct =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">LL.4</span>(), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> fungicide)</span>
<span id="cb17-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ED</span>(model, <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;">interval =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"delta"</span>)</span></code></pre></div>
</div>
<p>For more practical workflows, I prefer using <a href="https://alvesks.github.io/ec50estimator/" target="_blank"><code>ec50estimator</code></a> rather than writing a loop around <code>drm()</code> manually. That is exactly the use case the package was designed for: estimating <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D"> isolate by isolate within structured datasets while preserving grouping variables and confidence intervals in a tidy output.</p>
<p>In other words, <code>drc</code> is excellent for understanding and fitting an individual curve, whereas <code>ec50estimator</code> becomes the practical layer when the analysis involves many isolates, fungicides, or production systems.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1">EC50_est <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">estimate_EC50</span>(</span>
<span id="cb18-2">  growth <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> dose,</span>
<span id="cb18-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> fungicide,</span>
<span id="cb18-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">isolate_col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"isolate"</span>,</span>
<span id="cb18-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">strata_col =</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;">"field"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fungicide"</span>),</span>
<span id="cb18-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">interval =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"delta"</span>,</span>
<span id="cb18-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fct =</span> drc<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">LL.4</span>()</span>
<span id="cb18-8">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.frame</span>()</span>
<span id="cb18-10"></span>
<span id="cb18-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(EC50_est)</span></code></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>  ID   field   fungicide    Estimate   Std..Error       Lower       Upper
1  1 Organic Fungicide A 0.006373092 0.0007047683 0.004935707 0.007810476
2  3 Organic Fungicide A 0.003602134 0.0002580823 0.003075771 0.004128496
3  5 Organic Fungicide A 0.006064882 0.0005081581 0.005028487 0.007101277
4  7 Organic Fungicide A 0.006926374 0.0006407013 0.005619655 0.008233093
5  9 Organic Fungicide A 0.005180691 0.0005403256 0.004078689 0.006282692
6 11 Organic Fungicide A 0.005165555 0.0005897619 0.003962728 0.006368382</code></pre>
</div>
</div>
<p>Important note: in this post I used the same model, <code>LL.4()</code>, for both fungicides. In real applications, you should verify which model is most appropriate for your data. A useful strategy is to fit candidate models with <code>drm()</code> for a subset of isolates and compare them with <code>mselect()</code>. Once that modeling choice is clear, <code>ec50estimator</code> makes it much easier to apply the workflow consistently across all curves.</p>
</section>
<section id="visualizing-the-estimated-ec50-values" class="level2">
<h2 class="anchored" data-anchor-id="visualizing-the-estimated-ec50-values">Visualizing the estimated EC50 values</h2>
<p>Once estimates are available, one useful step is to compare their distributions across strata.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1">EC50_est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> field, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> Estimate, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> field)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_jitter</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">outlier.shape =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>fungicide, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_x"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</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="cb20-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_half_open</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_colorblind</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_log10</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb20-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb20-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Production system"</span>,</span>
<span id="cb20-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(EC[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>]),</span>
<span id="cb20-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Estimated distributions of "</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> EC[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" across production systems"</span>)</span>
<span id="cb20-13">  )</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/ec50/ec50_files/figure-html/unnamed-chunk-13-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>Another possibility is to inspect the full distribution more carefully.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1">EC50_est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb21-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> Estimate, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> field, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> field)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_density_ridges</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>fungicide, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_half_open</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">font_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_colourblind</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_log10</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb21-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb21-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(EC[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>]),</span>
<span id="cb21-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Production system"</span>,</span>
<span id="cb21-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density view of estimated "</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> EC[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" values"</span>)</span>
<span id="cb21-12">  )</span></code></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: `scale_fill_colorblind()` was deprecated in ggthemes 5.2.0.</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Picking joint bandwidth of 0.0489</code></pre>
</div>
<div class="cell-output cell-output-stderr">
<pre><code>Picking joint bandwidth of 0.0298</code></pre>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://alvesks.com.br/blog/posts/ec50/ec50_files/figure-html/unnamed-chunk-14-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
</section>
</section>
<section id="final-remarks" class="level1">
<h1>Final remarks</h1>
<p>Estimating <img src="https://latex.codecogs.com/png.latex?EC_%7B50%7D"> is an important step in fungicide sensitivity studies, but good inference depends on more than simply fitting one model and reporting one number. It is important to think about:</p>
<ul>
<li>the biological meaning of the response variable</li>
<li>the appropriateness of the selected dose-response model</li>
<li>the structure of the dataset</li>
<li>how estimates vary across isolates, years, fields, or treatments</li>
</ul>
<p>The workflow shown here provides a starting point for both teaching and applied analyses in plant pathology.</p>


</section>

 ]]></description>
  <category>English</category>
  <category>plant pathology</category>
  <category>code</category>
  <category>analysis</category>
  <guid>https://alvesks.com.br/blog/posts/ec50/</guid>
  <pubDate>Sun, 08 May 2022 03:00:00 GMT</pubDate>
</item>
</channel>
</rss>
