<?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</title>
<link>https://kaiquealves.netlify.app/docs/blog/</link>
<atom:link href="https://kaiquealves.netlify.app/docs/blog/index.xml" rel="self" type="application/rss+xml"/>
<description>Plant disease epidemiology, risk assessment, and quantitative modeling in plant health.</description>
<generator>quarto-1.6.40</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://kaiquealves.netlify.app/docs/blog/posts/epifitter-epidemias/epifitter-epidemias.html</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://kaiquealves.netlify.app/docs/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://kaiquealves.netlify.app/docs/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://kaiquealves.netlify.app/docs/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://kaiquealves.netlify.app/docs/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://kaiquealves.netlify.app/docs/blog/posts/epifitter-epidemias/epifitter-epidemias.html</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://kaiquealves.netlify.app/docs/blog/posts/yield-loss/yield-loss.html</link>
  <description><![CDATA[ 





<p>Yield loss analysis is one of the central quantitative problems in plant disease epidemiology because it provides the link between disease intensity and agronomic consequence. Disease variables such as incidence, severity, and epidemic progress are biologically informative in their own right, but, from an applied perspective, they are often intermediate quantities. The broader epidemiological and agronomic question is how variation in disease intensity translates into reduction in yield.</p>
<p>This question is fundamental for crop-loss assessment, breeding prioritization, cultivar evaluation, and disease management decision-making. It is also statistically nontrivial, because the severity-yield relationship is rarely estimated from a single homogeneous experiment. In most practical settings, yield loss datasets are hierarchical, with multiple studies, years, environments, and disease pressure scenarios contributing to substantial heterogeneity in both attainable yield and disease response.</p>
<p>This article introduces the basic yield loss framework commonly used in plant pathology and then discusses two complementary statistical approaches:</p>
<ul>
<li>mixed-effects modeling, when the goal is to model severity-yield relationships directly in hierarchical datasets</li>
<li>meta-analytic synthesis, when the goal is to combine study-specific damage estimates across experiments</li>
</ul>
<p>The discussion is informed both by the broader crop-loss literature in plant pathology and by my recent work on soybean rust damage under climate variability in Brazil. In practical terms, the mixed-effects examples below are fitted with the <code>lmer()</code> function from the <code>lme4</code> package, whereas the meta-analytic examples are fitted with the <code>metafor</code> package. The inferential focus, however, remains on the statistical framework rather than on the software itself. For readers interested in a direct connection to an applied research workflow, see the <a href="https://bsppjournals.onlinelibrary.wiley.com/doi/full/10.1111/ppa.70069" target="_blank">Plant Pathology paper</a> and the corresponding <a href="https://alvesks.github.io/paper_ENSO_SBR_damage/main_damage_coef.html" target="_blank">analysis page</a>.</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>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 and on which quantity is treated as the inferential target.</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>
</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.</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.</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.</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.</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="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>(cowplot)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggthemes)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(lme4)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(lmerTest)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(metafor)</span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(knitr)</span>
<span id="cb1-8"></span>
<span id="cb1-9"><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-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span>)</span>
<span id="cb1-11"></span>
<span id="cb1-12">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-13">  <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-14">  <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-15">  <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-16">)</span></code></pre></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">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-2"></span>
<span id="cb2-3">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-4">  severity_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">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-6">           <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-7">  severity_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">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-9">           <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-10">)</span>
<span id="cb2-11"></span>
<span id="cb2-12">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-13">  severity_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-14">    <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-15">           <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-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;">30</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;">"Higher damage slope"</span>)</span>
<span id="cb2-19">)</span>
<span id="cb2-20"></span>
<span id="cb2-21">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-22">  severity_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-23">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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-24">           <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-25">  severity_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-26">    <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-27">           <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-28">)</span></code></pre></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="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>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/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="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>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/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="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>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/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>
</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 simulate a 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.</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">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-2">  <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;">18</span>),</span>
<span id="cb6-3">  <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;">2015</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-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;">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;">"Warm"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</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;">6</span>),</span>
<span id="cb6-5">                <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-6">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-8">    <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-9">      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-10">      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-11">      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-12">    ),</span>
<span id="cb6-13">    <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-14">      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-15">      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-16">      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-17">    )</span>
<span id="cb6-18">  )</span>
<span id="cb6-19"></span>
<span id="cb6-20">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-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;">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;">map2</span>(attainable, slope, \(b0, b1) {</span>
<span id="cb6-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb6-23">      <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;">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-24">      <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-25">    )</span>
<span id="cb6-26">  })) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-27">  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-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-29">    <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-30">    <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-31">  )</span>
<span id="cb6-32"></span>
<span id="cb6-33">damage_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-34">  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, severity, yield) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-35">  <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-36">  <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 multi-study dataset"</span>)</span></code></pre></div>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>First rows of the simulated 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: 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;">2015</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">3.38</td>
<td style="text-align: right;">3642.89</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">12.01</td>
<td style="text-align: right;">3452.23</td>
</tr>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">12.98</td>
<td style="text-align: right;">3850.65</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">17.20</td>
<td style="text-align: right;">3237.47</td>
</tr>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">21.49</td>
<td style="text-align: right;">3345.90</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">21.96</td>
<td style="text-align: right;">3124.54</td>
</tr>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">24.73</td>
<td style="text-align: right;">3071.67</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">34.30</td>
<td style="text-align: right;">3086.50</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The next figure displays the full 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="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(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="cb7-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;">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="cb7-3">  <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="cb7-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>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="cb7-5">  <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="cb7-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="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb7-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;">"Simulated severity-yield relationships across studies"</span>,</span>
<span id="cb7-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="cb7-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="cb7-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ENSO phase"</span></span>
<span id="cb7-12">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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 class="cell-output cell-output-stderr">
<pre><code>`geom_smooth()` using formula = 'y ~ x'</code></pre>
</div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-7-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 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, and noisier study-specific relationships.</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.</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.</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">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="cb9-2">  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="cb9-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> damage_df,</span>
<span id="cb9-4">  <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="cb9-5">  <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="cb9-6">    <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="cb9-7">    <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="cb9-8">  )</span>
<span id="cb9-9">)</span>
<span id="cb9-10"></span>
<span id="cb9-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(damage_lmer_overall)</span></code></pre></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: 3274.7

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-2.50950 -0.67222 -0.03789  0.62647  2.69776 

Random effects:
 Groups   Name        Variance Std.Dev. Corr 
 study    (Intercept) 76122.92 275.904       
          severity       49.77   7.055  -0.70
 year     (Intercept)  8277.77  90.982       
 Residual             17235.75 131.285       
Number of obs: 252, groups:  study, 18; year, 6

Fixed effects:
            Estimate Std. Error       df t value Pr(&gt;|t|)    
(Intercept) 4142.673     76.737    9.436   53.99 4.47e-13 ***
severity     -23.961      1.716   17.171  -13.96 8.37e-11 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
         (Intr)
severity -0.618</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>
<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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># helper for percentile bootstrap intervals</span></span>
<span id="cb11-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="cb11-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="cb11-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="cb11-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="cb11-6">  </span>
<span id="cb11-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb11-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">term =</span> terms,</span>
<span id="cb11-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="cb11-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_lb =</span> lower,</span>
<span id="cb11-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ci_ub =</span> upper</span>
<span id="cb11-12">  )</span>
<span id="cb11-13">}</span>
<span id="cb11-14"></span>
<span id="cb11-15">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="cb11-16"></span>
<span id="cb11-17">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="cb11-18">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fixed effects define the population-average damage function</span></span>
<span id="cb11-19">  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="cb11-20">  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="cb11-21">  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="cb11-22">  </span>
<span id="cb11-23">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># population-average fitted values for the confidence band</span></span>
<span id="cb11-24">  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="cb11-25">  </span>
<span id="cb11-26">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># new observations include residual variation for prediction intervals</span></span>
<span id="cb11-27">  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="cb11-28">  </span>
<span id="cb11-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb11-30">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">attainable_yield =</span> b0,</span>
<span id="cb11-31">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">slope =</span> b1,</span>
<span id="cb11-32">    <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="cb11-33">    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="cb11-34">    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="cb11-35">  )</span>
<span id="cb11-36">}</span>
<span id="cb11-37"></span>
<span id="cb11-38">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="cb11-39">  damage_lmer_overall,</span>
<span id="cb11-40">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FUN =</span> overall_boot_fun,</span>
<span id="cb11-41">  <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="cb11-42">  <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="cb11-43">  <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="cb11-44">  <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="cb11-45">)</span>
<span id="cb11-46"></span>
<span id="cb11-47">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="cb11-48">  overall_boot,</span>
<span id="cb11-49">  <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="cb11-50">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-51">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb11-52">    <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="cb11-53">      term,</span>
<span id="cb11-54">      <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="cb11-55">      <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="cb11-56">      <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="cb11-57">    ),</span>
<span id="cb11-58">    <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), round, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb11-59">  )</span></code></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning: There was 1 warning in `mutate()`.
ℹ In argument: `across(c(estimate, ci_lb, ci_ub), round, 2)`.
Caused by warning:
! The `...` argument of `across()` is deprecated as of dplyr 1.1.0.
Supply arguments directly to `.fns` through an anonymous function instead.

  # Previously
  across(a:b, mean, na.rm = TRUE)

  # Now
  across(a:b, \(x) mean(x, na.rm = TRUE))</code></pre>
</div>
<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">overall_damage <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb13-2">  <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 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;">4142.67</td>
<td style="text-align: right;">3985.95</td>
<td style="text-align: right;">4296.14</td>
</tr>
<tr class="even">
<td style="text-align: left;">Slope</td>
<td style="text-align: right;">-23.96</td>
<td style="text-align: right;">-27.23</td>
<td style="text-align: right;">-20.46</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Damage coefficient</td>
<td style="text-align: right;">0.58</td>
<td style="text-align: right;">0.50</td>
<td style="text-align: right;">0.65</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</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>
<div class="cell">
<div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">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="cb14-2">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="cb14-3">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="cb14-4"></span>
<span id="cb14-5">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="cb14-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb14-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fit =</span> overall_fit,</span>
<span id="cb14-8">    <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="cb14-9">    <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="cb14-10">    <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="cb14-11">    <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="cb14-12">  )</span></code></pre></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="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(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="cb15-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># confidence interval for the mean fitted response</span></span>
<span id="cb15-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="cb15-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="cb15-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="cb15-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb15-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="cb15-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disease severity, S (%)"</span>,</span>
<span id="cb15-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="cb15-10">  )</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/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>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="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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="cb16-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># prediction interval for a new observation</span></span>
<span id="cb16-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="cb16-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="cb16-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="cb16-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb16-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="cb16-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="cb16-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="cb16-10">  )</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/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>
<p>Once that distinction is clear, both intervals can be displayed together in a single plot.</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="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="cb17-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># prediction interval is wider and shown first</span></span>
<span id="cb17-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="cb17-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="cb17-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="cb17-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="cb17-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="cb17-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb17-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="cb17-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="cb17-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="cb17-12">  )</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-13-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.</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="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1">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="cb18-2">  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="cb18-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> damage_df,</span>
<span id="cb18-4">  <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="cb18-5">  <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="cb18-6">    <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="cb18-7">    <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="cb18-8">  )</span>
<span id="cb18-9">)</span>
<span id="cb18-10"></span>
<span id="cb18-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(damage_lmer_enso)</span></code></pre></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: 3217.3

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-2.61328 -0.67266 -0.08572  0.63837  2.72989 

Random effects:
 Groups   Name        Variance  Std.Dev. Corr 
 study    (Intercept) 52708.762 229.584       
          severity        8.073   2.841  -0.36
 year     (Intercept)  6165.613  78.521       
 Residual             17220.223 131.226       
Number of obs: 252, groups:  study, 18; year, 6

Fixed effects:
                  Estimate Std. Error       df t value Pr(&gt;|t|)    
(Intercept)       4083.044    103.569   14.603  39.423 3.05e-16 ***
severity           -22.981      1.387   16.214 -16.566 1.38e-11 ***
ensoCold          -116.170    138.639   11.713  -0.838 0.418841    
ensoWarm           294.504    139.051   11.853   2.118 0.056014 .  
severity:ensoCold    6.322      1.947   15.755   3.247 0.005137 ** 
severity:ensoWarm   -9.291      1.946   15.752  -4.775 0.000215 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
            (Intr) sevrty ensCld ensWrm svrt:C
severity    -0.414                            
ensoCold    -0.675  0.309                     
ensoWarm    -0.673  0.308  0.503              
svrty:nsCld  0.295 -0.712 -0.427 -0.220       
svrty:nsWrm  0.295 -0.713 -0.221 -0.432  0.508</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="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1">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="cb20-2">  <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="cb20-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;">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="cb20-4">)</span>
<span id="cb20-5"></span>
<span id="cb20-6">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="cb20-7">  <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="cb20-8">  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="cb20-9">  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="cb20-10">  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="cb20-11">  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="cb20-12">  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="cb20-13">  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="cb20-14">  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="cb20-15">  </span>
<span id="cb20-16">  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="cb20-17">  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="cb20-18">  </span>
<span id="cb20-19">  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="cb20-20">    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="cb20-21">    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="cb20-22">    <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="cb20-23">  )</span>
<span id="cb20-24">  </span>
<span id="cb20-25">  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="cb20-26">  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="cb20-27">  </span>
<span id="cb20-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb20-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">neutral_attainable_yield =</span> b0_neutral,</span>
<span id="cb20-30">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">neutral_slope =</span> b1_neutral,</span>
<span id="cb20-31">    <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="cb20-32">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cold_attainable_yield =</span> b0_cold,</span>
<span id="cb20-33">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cold_slope =</span> b1_cold,</span>
<span id="cb20-34">    <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="cb20-35">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warm_attainable_yield =</span> b0_warm,</span>
<span id="cb20-36">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warm_slope =</span> b1_warm,</span>
<span id="cb20-37">    <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="cb20-38">    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="cb20-39">    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="cb20-40">    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="cb20-41">    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="cb20-42">  )</span>
<span id="cb20-43">}</span>
<span id="cb20-44"></span>
<span id="cb20-45">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="cb20-46">  damage_lmer_enso,</span>
<span id="cb20-47">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FUN =</span> enso_boot_fun,</span>
<span id="cb20-48">  <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="cb20-49">  <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="cb20-50">  <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="cb20-51">  <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="cb20-52">)</span>
<span id="cb20-53"></span>
<span id="cb20-54">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="cb20-55">  <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="cb20-56">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Neutral"</span>),</span>
<span id="cb20-57">  <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="cb20-58">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">enso =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>),</span>
<span id="cb20-59">  <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="cb20-60">    <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="cb20-61">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb20-62">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb20-63">    <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="cb20-64">      <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="cb20-65">      <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="cb20-66">      <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="cb20-67">    ),</span>
<span id="cb20-68">    <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="cb20-69">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb20-70">  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="cb20-71">  <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), round, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb20-72"></span>
<span id="cb20-73">lmer_phase_estimates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb20-74">  <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 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;">4083.04</td>
<td style="text-align: right;">3881.59</td>
<td style="text-align: right;">4255.68</td>
</tr>
<tr class="even">
<td style="text-align: left;">Neutral</td>
<td style="text-align: left;">Slope</td>
<td style="text-align: right;">-22.98</td>
<td style="text-align: right;">-25.33</td>
<td style="text-align: right;">-20.18</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.56</td>
<td style="text-align: right;">0.50</td>
<td style="text-align: right;">0.62</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;">3966.87</td>
<td style="text-align: right;">3783.28</td>
<td style="text-align: right;">4143.51</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Cold</td>
<td style="text-align: left;">Slope</td>
<td style="text-align: right;">-16.66</td>
<td style="text-align: right;">-19.16</td>
<td style="text-align: right;">-13.77</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.42</td>
<td style="text-align: right;">0.36</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;">4377.55</td>
<td style="text-align: right;">4222.27</td>
<td style="text-align: right;">4558.66</td>
</tr>
<tr class="even">
<td style="text-align: left;">Warm</td>
<td style="text-align: left;">Slope</td>
<td style="text-align: right;">-32.27</td>
<td style="text-align: right;">-35.12</td>
<td style="text-align: right;">-29.87</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.74</td>
<td style="text-align: right;">0.68</td>
<td style="text-align: right;">0.80</td>
</tr>
</tbody>
</table>
</div>
</div>
<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">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="cb21-2">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="cb21-3">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="cb21-4">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="cb21-5">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="cb21-6"></span>
<span id="cb21-7">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="cb21-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb21-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fit =</span> enso_fit,</span>
<span id="cb21-10">    <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="cb21-11">    <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="cb21-12">    <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="cb21-13">    <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="cb21-14">    <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="cb21-15">    <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="cb21-16">    <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="cb21-17">    <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="cb21-18">    <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="cb21-19">  )</span>
<span id="cb21-20"></span>
<span id="cb21-21">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="cb21-22">  <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="cb21-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb21-24">    enso,</span>
<span id="cb21-25">    <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="cb21-26">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb21-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(</span>
<span id="cb21-28">    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="cb21-29">    <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="cb21-30">  )</span></code></pre></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="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="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="cb22-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="cb22-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="cb22-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="cb22-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="cb22-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="cb22-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb22-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="cb22-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="cb22-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="cb22-11">  )</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/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>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="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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="cb23-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="cb23-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="cb23-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="cb23-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="cb23-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="cb23-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb23-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="cb23-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="cb23-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="cb23-11">  )</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/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>Once the distinction is clear, the two types of interval can be merged in a single view.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><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="cb24-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># wider prediction interval</span></span>
<span id="cb24-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="cb24-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># narrower confidence interval</span></span>
<span id="cb24-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="cb24-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="cb24-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(</span>
<span id="cb24-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> phase_label_df,</span>
<span id="cb24-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="cb24-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="cb24-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="cb24-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="cb24-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="cb24-14">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb24-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="cb24-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="cb24-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="cb24-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb24-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="cb24-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="cb24-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="cb24-22">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb24-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 class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/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>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="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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="cb25-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># prediction interval on the relative-loss scale</span></span>
<span id="cb25-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="cb25-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># confidence interval on the relative-loss scale</span></span>
<span id="cb25-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="cb25-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="cb25-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(</span>
<span id="cb25-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> phase_label_df,</span>
<span id="cb25-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="cb25-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="cb25-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="cb25-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="cb25-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="cb25-14">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb25-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="cb25-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="cb25-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="cb25-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb25-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="cb25-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="cb25-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="cb25-22">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb25-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 class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-20-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>
</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.</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.</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.</p>
<div class="cell">
<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">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="cb26-2">  <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="cb26-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb26-4">    <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="cb26-5">    <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="cb26-6">    <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="cb26-7">  )</span>
<span id="cb26-8"></span>
<span id="cb26-9">study_regression_1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb26-10">  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="cb26-11">  <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="cb26-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb26-13">    <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="cb26-14">    <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="cb26-15">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb26-16">  <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 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;">2015</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">3785.27</td>
<td style="text-align: right;">-23.06</td>
</tr>
<tr class="even">
<td style="text-align: left;">2</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: right;">4259.11</td>
<td style="text-align: right;">-29.66</td>
</tr>
<tr class="odd">
<td style="text-align: left;">3</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: right;">3595.32</td>
<td style="text-align: right;">-14.47</td>
</tr>
<tr class="even">
<td style="text-align: left;">4</td>
<td style="text-align: left;">2016</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">3894.87</td>
<td style="text-align: right;">-21.33</td>
</tr>
<tr class="odd">
<td style="text-align: left;">5</td>
<td style="text-align: left;">2016</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: right;">4386.36</td>
<td style="text-align: right;">-40.15</td>
</tr>
<tr class="even">
<td style="text-align: left;">6</td>
<td style="text-align: left;">2016</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: right;">3978.41</td>
<td style="text-align: right;">-19.38</td>
</tr>
<tr class="odd">
<td style="text-align: left;">7</td>
<td style="text-align: left;">2017</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">4678.26</td>
<td style="text-align: right;">-27.22</td>
</tr>
<tr class="even">
<td style="text-align: left;">8</td>
<td style="text-align: left;">2017</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: right;">4265.57</td>
<td style="text-align: right;">-27.34</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="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1">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="cb27-2">  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="cb27-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;">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="cb27-4">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb27-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb27-6">    <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="cb27-7">    <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;">"Warm"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>))</span>
<span id="cb27-8">  )</span></code></pre></div>
</div>
<div class="cell">
<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>(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="cb28-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="cb28-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="cb28-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="cb28-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="cb28-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb28-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="cb28-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="cb28-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="cb28-10">  )</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-23-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="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1">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="cb29-2">  study_regression_1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb29-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb29-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>(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;">"Warm"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>)),</span>
<span id="cb29-5">      <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="cb29-6">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> intercept</span>
<span id="cb29-7">    ),</span>
<span id="cb29-8">  study_regression_1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb29-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb29-10">      <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;">"Warm"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>)),</span>
<span id="cb29-11">      <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="cb29-12">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> slope_yield</span>
<span id="cb29-13">    )</span>
<span id="cb29-14">)</span>
<span id="cb29-15"></span>
<span id="cb29-16">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="cb29-17">  <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="cb29-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb29-19">    <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="cb29-20">    <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="cb29-21">    <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="cb29-22">    <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="cb29-23">  )</span></code></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1"><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="cb30-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(</span>
<span id="cb30-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="cb30-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="cb30-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="cb30-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="cb30-7">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb30-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_segment</span>(</span>
<span id="cb30-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study_parameter_summary,</span>
<span id="cb30-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="cb30-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="cb30-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="cb30-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="cb30-14">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb30-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(</span>
<span id="cb30-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study_parameter_summary,</span>
<span id="cb30-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="cb30-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="cb30-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="cb30-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="cb30-21">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb30-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="cb30-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="cb30-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="cb30-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb30-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="cb30-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="cb30-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="cb30-29">  )</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-25-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="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1">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="cb31-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(</span>
<span id="cb31-3">    study_regression_1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb31-4">      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="cb31-5">    <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="cb31-6">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb31-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb31-8">    <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="cb31-9">  )</span>
<span id="cb31-10"></span>
<span id="cb31-11">relative_loss_df <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb31-12">  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="cb31-13">  <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="cb31-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb31-15">    <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), round, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb31-16">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb31-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;">"Relative yield loss calculated from the study-specific attainable yield"</span>)</span></code></pre></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;">3.38</td>
<td style="text-align: right;">3642.89</td>
<td style="text-align: right;">3785.27</td>
<td style="text-align: right;">3.76</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">12.01</td>
<td style="text-align: right;">3452.23</td>
<td style="text-align: right;">3785.27</td>
<td style="text-align: right;">8.80</td>
</tr>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">12.98</td>
<td style="text-align: right;">3850.65</td>
<td style="text-align: right;">3785.27</td>
<td style="text-align: right;">-1.73</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">17.20</td>
<td style="text-align: right;">3237.47</td>
<td style="text-align: right;">3785.27</td>
<td style="text-align: right;">14.47</td>
</tr>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">21.49</td>
<td style="text-align: right;">3345.90</td>
<td style="text-align: right;">3785.27</td>
<td style="text-align: right;">11.61</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">21.96</td>
<td style="text-align: right;">3124.54</td>
<td style="text-align: right;">3785.27</td>
<td style="text-align: right;">17.46</td>
</tr>
<tr class="odd">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">24.73</td>
<td style="text-align: right;">3071.67</td>
<td style="text-align: right;">3785.27</td>
<td style="text-align: right;">18.85</td>
</tr>
<tr class="even">
<td style="text-align: left;">1</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">34.30</td>
<td style="text-align: right;">3086.50</td>
<td style="text-align: right;">3785.27</td>
<td style="text-align: right;">18.46</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.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><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="cb32-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="cb32-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="cb32-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="cb32-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="cb32-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="cb32-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb32-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="cb32-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="cb32-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="cb32-11">  )</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-27-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.</p>
<div class="cell">
<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">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="cb33-2">  <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="cb33-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb33-4">    <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="cb33-5">    <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="cb33-6">    <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="cb33-7">    <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="cb33-8">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb33-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>()</span>
<span id="cb33-10"></span>
<span id="cb33-11">study_effects <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb33-12">  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="cb33-13">  <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="cb33-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb33-15">    <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="cb33-16">    <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="cb33-17">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb33-18">  <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 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;">2015</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">0.609</td>
<td style="text-align: right;">0.0259</td>
</tr>
<tr class="even">
<td style="text-align: left;">2</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: right;">0.696</td>
<td style="text-align: right;">0.0123</td>
</tr>
<tr class="odd">
<td style="text-align: left;">3</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: right;">0.402</td>
<td style="text-align: right;">0.0209</td>
</tr>
<tr class="even">
<td style="text-align: left;">4</td>
<td style="text-align: left;">2016</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">0.548</td>
<td style="text-align: right;">0.0151</td>
</tr>
<tr class="odd">
<td style="text-align: left;">5</td>
<td style="text-align: left;">2016</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: right;">0.915</td>
<td style="text-align: right;">0.0215</td>
</tr>
<tr class="even">
<td style="text-align: left;">6</td>
<td style="text-align: left;">2016</td>
<td style="text-align: left;">Cold</td>
<td style="text-align: right;">0.487</td>
<td style="text-align: right;">0.0188</td>
</tr>
<tr class="odd">
<td style="text-align: left;">7</td>
<td style="text-align: left;">2017</td>
<td style="text-align: left;">Neutral</td>
<td style="text-align: right;">0.582</td>
<td style="text-align: right;">0.0174</td>
</tr>
<tr class="even">
<td style="text-align: left;">8</td>
<td style="text-align: left;">2017</td>
<td style="text-align: left;">Warm</td>
<td style="text-align: right;">0.641</td>
<td style="text-align: right;">0.0227</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="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1">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="cb34-2">  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="cb34-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;">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="cb34-4">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb34-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb34-6">    <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="cb34-7">    <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;">"Warm"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cold"</span>))</span>
<span id="cb34-8">  )</span></code></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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="cb35-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="cb35-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="cb35-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="cb35-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="cb35-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="cb35-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb35-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="cb35-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="cb35-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="cb35-11">  )</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/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>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="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>(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="cb36-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="cb36-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="cb36-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="cb36-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb36-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="cb36-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="cb36-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="cb36-9">  )</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-31-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.</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>.</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="sourceCode cell-code" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1">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="cb37-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yi =</span> damage_coefficient,</span>
<span id="cb37-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">V =</span> vi_dc,</span>
<span id="cb37-4">  <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="cb37-5">  <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="cb37-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;">"REML"</span>,</span>
<span id="cb37-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study_effects</span>
<span id="cb37-8">)</span>
<span id="cb37-9"></span>
<span id="cb37-10">meta_damage_overall</span></code></pre></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.0210  0.1449     18     no  year/study 

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

Model Results:

estimate      se     zval    pval   ci.lb   ci.ub      
  0.5735  0.0345  16.6247  &lt;.0001  0.5059  0.6411  *** 

---
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="sourceCode cell-code" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1">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="cb39-2">  <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="cb39-3">  <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="cb39-4">  <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="cb39-5">  <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="cb39-6">  <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="cb39-7">)</span>
<span id="cb39-8"></span>
<span id="cb39-9">meta_overall_summary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb39-10">  <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), round, <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="cb39-11">  <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 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.574</td>
<td style="text-align: right;">0.034</td>
<td style="text-align: right;">0.506</td>
<td style="text-align: right;">0.641</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="sourceCode cell-code" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1">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="cb40-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yi =</span> damage_coefficient,</span>
<span id="cb40-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">V =</span> vi_dc,</span>
<span id="cb40-4">  <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="cb40-5">  <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="cb40-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;">"REML"</span>,</span>
<span id="cb40-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> study_effects</span>
<span id="cb40-8">)</span>
<span id="cb40-9"></span>
<span id="cb40-10">meta_damage</span></code></pre></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.0003  0.0170      6     no        year 
sigma^2.2  0.0040  0.0632     18     no  year/study 

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

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

Model Results:

             estimate      se     zval    pval   ci.lb   ci.ub      
ensoNeutral    0.5629  0.0281  20.0565  &lt;.0001  0.5079  0.6180  *** 
ensoCold       0.4219  0.0282  14.9551  &lt;.0001  0.3666  0.4772  *** 
ensoWarm       0.7335  0.0278  26.3752  &lt;.0001  0.6790  0.7880  *** 

---
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="sourceCode cell-code" id="cb42" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1">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="cb42-2">  <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="cb42-3">  <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="cb42-4">  <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="cb42-5">  <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="cb42-6">  <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="cb42-7">)</span>
<span id="cb42-8"></span>
<span id="cb42-9">meta_summary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb42-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb42-11">    <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="cb42-12">    <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="cb42-13">    <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="cb42-14">    <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="cb42-15">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb42-16">  <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 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.563</td>
<td style="text-align: right;">0.028</td>
<td style="text-align: right;">0.508</td>
<td style="text-align: right;">0.618</td>
</tr>
<tr class="even">
<td style="text-align: left;">Cold</td>
<td style="text-align: right;">0.422</td>
<td style="text-align: right;">0.028</td>
<td style="text-align: right;">0.367</td>
<td style="text-align: right;">0.477</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Warm</td>
<td style="text-align: right;">0.733</td>
<td style="text-align: right;">0.028</td>
<td style="text-align: right;">0.679</td>
<td style="text-align: right;">0.788</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="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="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="cb43-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="cb43-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="cb43-4">  <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="cb43-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="cb43-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb43-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="cb43-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="cb43-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="cb43-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="cb43-11">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb43-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 class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-36-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="sourceCode cell-code" id="cb44" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb44-1">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="cb44-2">  <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="cb44-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb44-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mixed-effects"</span>,</span>
<span id="cb44-5">    estimate,</span>
<span id="cb44-6">    ci_lb,</span>
<span id="cb44-7">    ci_ub</span>
<span id="cb44-8">  )</span>
<span id="cb44-9"></span>
<span id="cb44-10">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="cb44-11">  lmer_overall_compare,</span>
<span id="cb44-12">  meta_overall_summary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb44-13">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb44-14">      <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="cb44-15">      estimate,</span>
<span id="cb44-16">      ci_lb,</span>
<span id="cb44-17">      ci_ub</span>
<span id="cb44-18">    )</span>
<span id="cb44-19">)</span>
<span id="cb44-20"></span>
<span id="cb44-21">overall_compare <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb44-22">  <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), round, <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="cb44-23">  <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 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.580</td>
<td style="text-align: right;">0.500</td>
<td style="text-align: right;">0.650</td>
</tr>
<tr class="even">
<td style="text-align: left;">Meta-analysis</td>
<td style="text-align: right;">0.574</td>
<td style="text-align: right;">0.506</td>
<td style="text-align: right;">0.641</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The next plot presents that comparison graphically.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb45" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb45-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="cb45-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># point estimate from each method</span></span>
<span id="cb45-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="cb45-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># uncertainty interval from each method</span></span>
<span id="cb45-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="cb45-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="cb45-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="cb45-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb45-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="cb45-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="cb45-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="cb45-12">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb45-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 class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-38-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="sourceCode cell-code" id="cb46" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1">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="cb46-2">  <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="cb46-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb46-4">    enso,</span>
<span id="cb46-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="cb46-6">    estimate,</span>
<span id="cb46-7">    ci_lb,</span>
<span id="cb46-8">    ci_ub</span>
<span id="cb46-9">  )</span>
<span id="cb46-10"></span>
<span id="cb46-11">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="cb46-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transmute</span>(</span>
<span id="cb46-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="cb46-14">    <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="cb46-15">    estimate,</span>
<span id="cb46-16">    ci_lb,</span>
<span id="cb46-17">    ci_ub</span>
<span id="cb46-18">  )</span>
<span id="cb46-19"></span>
<span id="cb46-20">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="cb46-21"></span>
<span id="cb46-22">phase_compare <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb46-23">  <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), round, <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="cb46-24">  <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 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.560</td>
<td style="text-align: right;">0.500</td>
<td style="text-align: right;">0.620</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.420</td>
<td style="text-align: right;">0.360</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.740</td>
<td style="text-align: right;">0.680</td>
<td style="text-align: right;">0.800</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.563</td>
<td style="text-align: right;">0.508</td>
<td style="text-align: right;">0.618</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.422</td>
<td style="text-align: right;">0.367</td>
<td style="text-align: right;">0.477</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.733</td>
<td style="text-align: right;">0.679</td>
<td style="text-align: right;">0.788</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="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>(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="cb47-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="cb47-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="cb47-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbar</span>(</span>
<span id="cb47-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="cb47-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="cb47-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="cb47-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="cb47-9">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb47-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="cb47-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="cb47-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb47-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="cb47-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="cb47-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="cb47-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="cb47-17">  )</span></code></pre></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://kaiquealves.netlify.app/docs/blog/posts/yield-loss/yield-loss_files/figure-html/unnamed-chunk-40-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.</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>
</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. 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>In a future post, I can extend this discussion by moving from linear damage functions to more specialized topics such as relative yield loss, nonlinear disease-response relationships, and the integration of yield loss models into economic decision frameworks.</p>


</section>

 ]]></description>
  <category>English</category>
  <category>epidemiology</category>
  <category>yield loss</category>
  <category>mixed models</category>
  <category>meta-analysis</category>
  <guid>https://kaiquealves.netlify.app/docs/blog/posts/yield-loss/yield-loss.html</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://kaiquealves.netlify.app/docs/blog/posts/ec50/ec50.html</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://kaiquealves.netlify.app/docs/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://kaiquealves.netlify.app/docs/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://kaiquealves.netlify.app/docs/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://kaiquealves.netlify.app/docs/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://kaiquealves.netlify.app/docs/blog/posts/ec50/ec50.html</guid>
  <pubDate>Sun, 08 May 2022 03:00:00 GMT</pubDate>
</item>
</channel>
</rss>
