<?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>Jan Vanhove</title>
<link>https://janhove.github.io/archive.html</link>
<atom:link href="https://janhove.github.io/archive.xml" rel="self" type="application/rss+xml"/>
<description>I blog about statistics and research design with an audience consisting of researchers in bilingualism, multilingualism, and applied linguistics in mind.</description>
<generator>quarto-1.9.37</generator>
<lastBuildDate>Mon, 15 Dec 2025 00:00:00 GMT</lastBuildDate>
<item>
  <title>Does multilingualism really protect against accelerated ageing? Some critical comments</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2025-12-15-multilingualism-accelerated-ageing/</link>
  <description><![CDATA[ 




<p>Amoruso et al.’s <a href="https://10.1038/s43587-025-01000-2"><em>Multilingualism protects against accelerated aging in cross-sectional and longitudinal analyses of 27 European countries</em></a> struck a chord with multilingualism enthusiasts. But whenever a study claims to have found something that suits us ideologically or economically, it behooves us, as academics, to take a closer look at it.</p>
<p>So I did.</p>
<p>You can find my critical comments below. Most are not very technical in nature, and many can be identified just by reading the paper and looking at the data and code the authors shared—without actually needing to run it. I believe that these comments should lead to a substantial revision of the published article.</p>
<p>Everything below is based on Amoruso et al.’s article, its supplementary materials, and the data and code provided on the project’s <a href="https://github.com/euroladbrainlat/Biobehavioral-age-gaps-Multilingualism">GitHub</a> page, which I’ve <a href="https://github.com/janhove/Biobehavioral-age-gaps-Multilingualism">forked</a>. I didn’t consult the sources that the authors obtained their data from.</p>
<section id="tldr" class="level2">
<h2 class="anchored" data-anchor-id="tldr">tl;dr</h2>
<ol type="1">
<li><strong>Missing predictors:</strong> The article suggests that 14 predictors were used, but the data and code suggest that only 12 predictors were used.</li>
<li><strong>Missing respondents and countries:</strong> The article claims that the evidence is based on data from 86,149 respondents in 27 European countries. However, the cross-sectional analyses are based on data from only 84,127 respondents in <em>26</em> countries; the longitudinal analyses are based on data from only 81,329 respondents.</li>
<li><strong>Unjustified causal claims:</strong> By their own admission in the discussion section, the authors can’t make any causal claims, but already the title and the abstract make a bold causal claim.</li>
<li><strong>Questionable construction of the outcome variable:</strong> The construction of the outcome variable (“BAGs”) requires some more scrutiny. For the time being, I’ll content myself by pointing out that it is a dichotomised version of a continuous metric.</li>
<li><strong>Conflation of country-level and individual multilingualism:</strong> The multilingual data that the authors used is situated at the country level, but the authors regularly frame their findings in terms of individual multilingualism.</li>
<li><strong>Meaningless odds ratios:</strong> The odds ratios reported in Table 1 are presented without mentioning how the data were coded. A closer look at the Jupyter notebooks reveals that they are essentially meaningless.</li>
<li><strong>Insufficient confounder control:</strong> Several confounders are controlled for in the analyses—but only one at a time.</li>
<li><strong>GDP incorrectly controlled for:</strong> The authors claim to have used per capita GDP as a control variable. Their data and code show that they used GDP—<em>not</em> per capita GDP—instead.</li>
<li><strong>Insufficient accounting for nesting:</strong> The nested nature of the data (respondents in cohorts in countries) isn’t accounted for sufficiently.</li>
</ol>
</section>
<section id="a-first-look" class="level2">
<h2 class="anchored" data-anchor-id="a-first-look">A first look</h2>
<p>The first few critical comments can be raised by just reading the article and comparing the claims made in it to the data and code made available by the authors.</p>
<section id="data-and-code-availability" class="level3">
<h3 class="anchored" data-anchor-id="data-and-code-availability">Data and code availability</h3>
<p>Let’s take a look at how Amoruso et al.’s analytical pipeline is supposed to work.</p>
<p>The dataset <a href="https://github.com/janhove/Biobehavioral-age-gaps-Multilingualism/blob/main/scripts/main/data/data.csv"><code>scripts/main/data/data.csv</code></a> contains 86,149 observations of 14 variables: the respondents’ country, age, sex, and scores and indicators of 11 biobehavioural factors:</p>
<ul>
<li><code>Education</code>,</li>
<li><a href="https://en.wikipedia.org/wiki/Barthel_scale"><code>Barthel</code></a>,</li>
<li><code>Diabetes</code>,</li>
<li><code>Hypertension</code>,</li>
<li><code>Heart_Disease</code>,</li>
<li><code>Physical_activity</code>,</li>
<li><code>Cognition</code>,</li>
<li><code>Well_being_domain</code>,</li>
<li><code>Sleep_problems</code>,</li>
<li><code>Audition_problems</code>,</li>
<li><code>Vision_problems</code>.</li>
</ul>
<p>The authors derived what they dubbed <em>biobehavioural age gaps</em> (‘BAGs’) from this dataset in the Jupyter notebook <code>scripts/main_BAGs_computation.ipynb</code>. Lots of the code in this notebook isn’t really important, but if you look for the string <code>vars_list</code>, you’ll see that the eleven biobehavioural factors as well as the participants’ sex were used as predictors, for a total of twelve predictors.</p>
<p>But their article (particularly Figure 1b) suggests that fourteen predictors were used to derive the BAGs. The factors <em>unhealthy weight</em> and <em>alcohol consumption</em> are mentioned both in this Figure and in the article’s Methods section, but they simply aren’t in the dataset and apparently weren’t used when deriving the BAGs.</p>
<p>Further, the Jupyter notebook doesn’t actually output the BAGs. Instead, two new datasets are fed to the second round of analyses. The first of these new datasets is <a href="https://github.com/janhove/Biobehavioral-age-gaps-Multilingualism/blob/main/scripts/main/data/BAG_OR_cross.csv"><code>scripts/main/data/BAG_OR_cross.csv</code></a>. It contains 84,127 observations of 21 variables. I’ll discuss these variables later. This dataset was used for the cross-sectional analyses carried out in the Jupyter notebook <a href="https://github.com/janhove/Biobehavioral-age-gaps-Multilingualism/blob/main/scripts/main/ORs_cross.ipynb"><code>scripts/main/ORs_cross.ipynb</code></a>. The second is <a href="https://github.com/janhove/Biobehavioral-age-gaps-Multilingualism/blob/main/scripts/main/data/BAG_OR_long.csv"><code>scripts/main/data/BAG_or_long.csv</code></a>, which contains 81,329 observations of 22 variables and was used for the longitudinal analyses carried out in the Jupyter notebook <a href="https://github.com/janhove/Biobehavioral-age-gaps-Multilingualism/blob/main/scripts/main/ORs_long.ipynb"><code>scripts/main/ORs_long.ipynb</code></a>.</p>
<p>The difference in sample sizes is not commented on anywhere. The difference between 86,149 (<code>data.csv</code>) and 84,127 (<code>BAG_OR_cross.csv</code>) is 2,022, which happens to be exactly the size of the Slovak sample. The supplementary Table 6 does not contain any information about Slovakia. But it does contain information about Serbia, which isn’t represented in <code>data.csv</code>. I suspect that the authors blundered when merging the BAGs with the country-level information. Neither the actual BAG computation nor the merging is documented in any of the notebooks, though.</p>
<p>Another 2,798 observations are missing from <code>BAG_OR_long.csv</code>. I didn’t investigate these further; for the time being, I’ll focus on the cross-sectional analyses.</p>
</section>
<section id="unjustifiable-causal-claims" class="level3">
<h3 class="anchored" data-anchor-id="unjustifiable-causal-claims">Unjustifiable causal claims</h3>
<p>As the authors correctly point out in their discussion, their design and analysis do not allow them to establish any causal links between the degree of multilingualism in a country and the extent to which its inhabitants show signs of accelerated ageing. Unfortunately, they don’t seem to have kept this insight in mind when they came up with the title (“Multilingualism protects…”) and the abstract (“These results underscore the protective role of multilingualism…”).</p>
<p>Further, the authors write</p>
<blockquote class="blockquote">
<p>“[R]andomized controlled trials could explicitly manipulate multilingualism and directly assess its effects on aging clocks.”</p>
</blockquote>
<p>Could they really, though?</p>
</section>
<section id="sec-bag" class="level3">
<h3 class="anchored" data-anchor-id="sec-bag">Construction of the outcome variable</h3>
<p>The study’s outcome variable was the presence or absence of “accelerated ageing”. Let’s see how this outcome variable was constructed.</p>
<p>First, the authors gathered data on individual “biobehavioural” factors (see <code>data.csv</code>). These are based on self-reports and are fairly coarse. For example, the variable <code>Hypertension</code> is simply the yes/no response to whether a physician has ever told the respondent that their blood pressure was too high. The list of specific questions can be found in the supplementary materials.</p>
<p>Then, they used the dataset to fit a model with the respondents’ age as the outcome variable and all of these biobehavioural factors as predictors. The model itself is gradient boosting, but that is not especially important conceptually. What is important is that the model is able to pick up on nonlinearities and interactions. The model’s hyperparameters were estimated from the data, and a couple of different cross-validation techniques were used. For our present purposes, I’m going to focus on the <em>leave one country out</em> cross-validation, because it makes the most sense to me. What this means is that 27 models predicting age from biobehavioural factors were fitted, with each leaving out the data from another country.</p>
<p>Next, the models fitted were used to predict the age of the inhabitants of the country that was left out when fitting them. That is, the Belgian respondents’ ages were predicted on the basis of the model fitted to the data from the respondents in the other 26 countries.</p>
<p>Then, the authors computed, for each respondent, <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BGAP%7D%20:=%20%5Ctextrm%7Bpredicted%20age%7D%20-%20%5Ctextrm%7Bactual%20age%7D,"> that is, the negative model residuals. As the authors correctly point out, though, the predictive model will tend to underestimate the age of the oldest respondents and overestimate the age of the youngest respondents. To account for this phenomenon, they fitted linear models with <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BGAP%7D"> as the outcome and the participants’ actual age as the predictor; let’s call the predicted values of model the predicted <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BGAP%7D"> values. They then defined <img src="https://latex.codecogs.com/png.latex?%5Ctextrm%7Bcorrected%20%7D%20%5Ctexttt%7BGAP%7D%20:=%20%5Ctexttt%7BGAP%7D%20-%20%5Ctextrm%7Bpredicted%20%7D%20%5Ctexttt%7BGAP%7D."></p>
<p>Finally, the authors defined the variable “biobehavioural age gap” (<img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BBAG%7D">) as <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BBAG%7D%20:=%20%5Cbegin%7Bcases%7D1,%20&amp;%5Ctextrm%7Bif%20corrected%20%7D%20%5Ctexttt%7BGAP%7D%20%3E%200,%20%5C%5C%200,%20&amp;%20%5Ctextrm%7Botherwise%7D.%5Cend%7Bcases%7D"> I’m always somewhat skeptical when the input to one statistical model is the output of another one. The <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BBAG%7D"> values that serve as the outcome variable in the models testing for a multilingualism effect are themselves the dichotomised output of another statistical model whose input, in turn, is the input the output of yet another statistical model. At the very least, the literal meaning of these <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BBAG%7D"> values is highly convoluted.</p>
<p>Further, I do not see why the corrected <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BGAP%7D">s had to be dichotomised in the first place, thereby losing the distinction between a corrected <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BGAP%7D"> of, say, half a year and one of 12 years. The authors write that these dichotomous variables were created because otherwise no odds ratios (and relative risks) could be computed. But this is hardly a satisfactory justification; it’s a bit like scattering dust throughout your living room before vacuum cleaning it as otherwise there would be no dust to get rid of.</p>
<p>Lastly, note that any given respondent’s <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BBAG%7D"> value doesn’t just depend on this respondent’s biobehavioural data: both the model to compute their raw <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BGAP%7D"> value as well as the one to compute their corrected <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BGAP%7D"> value are based on the data from the respondents in all the other countries. In fact, you’d expect roughly half the respondents to have a positive <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BGAP%7D"> value.</p>
</section>
<section id="country-level-vs-individual-multilingualism" class="level3">
<h3 class="anchored" data-anchor-id="country-level-vs-individual-multilingualism">Country-level vs individual multilingualism</h3>
<p>The authors use country-level data on multilingualism, namely the estimated percentage of monolinguals in the country, the estimated percentage of people in the country who know (exactly) one additional language, those who know (exactly) two additional languages, and those who know at least three additional languages. Throughout their article, though, they move back and forth between interpreting country-level and individual-level interpretations. For instance, they write</p>
<blockquote class="blockquote">
<p>“In the cross-sectional analysis, monolinguals (that is, those speaking only their mother tongue) were 2.11 times more likely to experience accelerated aging (…).”</p>
</blockquote>
<p>and</p>
<blockquote class="blockquote">
<p>“Individuals speaking one additional language were 1.11 less likely to develop accelerated aging (…), those speaking two additional languages were 1.25 times less likely (…), and those speaking three or more additional languages were 1.41 less likely (…).”</p>
</blockquote>
<p>Again, in the discussion they point out that their data are situated at the country level, which limits their ability to draw conclusions about individual multilingualism. A cleaner and more consistent choice of wording in the title and throughout the article would have been preferable.</p>
</section>
<section id="on-the-interpretation-of-the-reported-odds-ratios" class="level3">
<h3 class="anchored" data-anchor-id="on-the-interpretation-of-the-reported-odds-ratios">On the interpretation of the reported odds ratios</h3>
<p>Now that we’ve established that the multilingualism data are situated at the country level, what are we to make of the odds ratio of 2.11 in the claim that “monolinguals … were 2.11 times more likely to experience accelerated aging”?</p>
<p>Their Python code (<code>ORs_cross.ipynb</code>) shows that the authors scaled the multilingualism data to a range from 0.05 to 0.95. The highest degree of country-level monolingualism was 63.2, the lowest was 2.86. So, with <img src="https://latex.codecogs.com/png.latex?p"> the percentage of monolinguals in a given country, the scaled monolingualism variable <img src="https://latex.codecogs.com/png.latex?s(p)"> becomes</p>
<p><img src="https://latex.codecogs.com/png.latex?s(p)%20=%20%5Cleft(%5Cfrac%7Bp%20-%202.86%7D%7B63.2%20-%202.86%7D%5Cright)(0.95%20-%200.05)%20+0.05."> The odds ratio output by the model is the estimated ratio <img src="https://latex.codecogs.com/png.latex?%5Ctextrm%7BOR(monolingualism)%7D%20=%20%5Cfrac%7B%5Ctextrm%7Bodds%20of%20accelerated%20ageing%20if%20%7D%20s(p)%20=%201%7D%7B%5Ctextrm%7Bodds%20of%20accelerated%20ageing%20if%20%7D%20s(p)%20=%200%7D."> As some basic algebra reveals, <img src="https://latex.codecogs.com/png.latex?s(p)%20=%200"> corresponds to a percentage of monolinguals of <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B-0.05%7D%7B0.95%20-%200.05%7D(63.2-2.86)%20+%202.86%20=%20-0.49,"> that is negative (!) 49 monolinguals per 10,000 inhabitants. Similarly, <img src="https://latex.codecogs.com/png.latex?s(p)%20=%201"> corresponds to a percentage of monolinguals of <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B0.95%7D%7B0.95%20-%200.05%7D(63.2-2.86)%20+%202.86%20=%2066.55,"> that is 6,655 monolinguals for every 10,000 inhabitants.</p>
<p>What the odds ratio of 2.11 for monolingualism means, then, is that the model estimates that the inhabitants of a country with 6,655 monolinguals for every 10,000 inhabitants are 2.11 times more likely to show signs of accelerated ageing compared to the inhabitants of a country with negative 49 monolinguals per 10,000 inhabitants.</p>
<p>It would have been more sensible to set the baseline at 0% monolinguals and have the OR refer to a difference in monolingualism of, say, 1 or 10 percentage points.</p>
<p>The interpretation of the other odds ratios suffers from the same problem, of course. Further, these other odds ratios aren’t too useful for an additional reason Take, for example, the following statement:</p>
<blockquote class="blockquote">
<p>“speaking one foreign language were [sic.] 1.3 less likely (…).”</p>
</blockquote>
<p>The highest percentage of speakers of exactly one additional language was 62.08; the lowest was 9.48. The same computation as above shows that this odds ratio has the following interpretation: According to the model, inhabitants of a country with 6,500 speakers of exactly one additional language per 10,000 inhabitants are 1.3 times less likely to show signs of accelerated ageing compared to the inhabitants of a country with only 656 speakers of exactly one additional language per 10,000 inhabitants.</p>
<p>Crucially, a country with 6,500 speakers of exactly one additional language per 10,000 inhabitants isn’t necessarily more multilingual than a country with only 656 speakers of exactly one additional language per 10,000 inhabitants: In the 2016 data, Luxembourg only had 16.2% speakers of exactly one additional language compared to, say, Austria’s 49.6%. But Luxembourg had 72% speakers of at least three additional languages compared to Austria’s 13.4%—more speakers of exactly one additional language doesn’t mean that the country is more multilingual!</p>
<p>The same remark goes for the analyses concerning the percentage of speakers of exactly two additional languages or of speakers of at least three additional languages.</p>
<p>Further, the result that “individuals (sic.) speaking at least one additional foreign language were 2.17 times less likely (…) to experience accelerated ageing” is superfluous: if we already know the odds ratio for the degree of monolingualism, we also know the odds ratio for the degree of multilingualism: it must be the inverse. The fact that it isn’t <em>exactly</em> the inverse in this report is something I will come back to when reproducing the analyses.</p>
<p>Finally, the operative phrase in the interpretations above is <em>according to the model</em>. While the article contains quite a few graphs, none shows a data plot for the association between degree of mono/multilingualism versus prevalence of accelerated ageing. It is therefore entirely possible that the actual relationship between these two variables is nonlinear.</p>
<p>Incidentally, for some reason or other, the notebook <code>ORs_cross.ipynb</code> doesn’t actually fit the logistic regression models that the authors claim to have fitted: They fit log-linear regression models. Moreover, for reasons unspecified, the data were split up into a training set and a test set, but the test set was never used for anything. This isn’t mentioned anywhere in the article, either.</p>
</section>
<section id="insufficient-confounder-control" class="level3">
<h3 class="anchored" data-anchor-id="insufficient-confounder-control">Insufficient confounder control</h3>
<p>The authors write in the abstract that the “[e]ffects persisted after adjusting for linguistic, physical, social and sociopolitical exposomes.” This is true but also easily misunderstood: They only controlled for one exposome at a time. Hence, it is possible that the mono/multilingualism variables acted as a proxy for some of the exposomes that weren’t considered in the analysis.</p>
<p>Further, the authors write that one of the exposomes taken into consideration was the GDP <em>per capita</em>. However, the GDP variable in <code>BAG_OR_cross.csv</code> ranges from 13.5 billion (in nominal USD?) to about 3.9 trillion (in nominal USD?). I suspect the first figure is for Malta in 2017 and the second for Germany in 2019. But nowhere in their analysis code do they compute the <em>per capita</em> GDP.</p>
</section>
<section id="nesting-not-taken-into-account" class="level3">
<h3 class="anchored" data-anchor-id="nesting-not-taken-into-account">Nesting not taken into account</h3>
<p>The logistic models fitted in <code>ORs_cross.ipynb</code> don’t take the nested nature of the data into account: the respondents’ data were collected in different waves in different countries. It is quite plausible that the reported confidence intervals would be considerably wider once this nesting is properly accounted for. Since the predictors in these models are situated at the country level (e.g., country-level multilingualism and GDP), simple data aggregation would be a viable approach.</p>
</section>
</section>
<section id="getting-stuck-in" class="level2">
<h2 class="anchored" data-anchor-id="getting-stuck-in">Getting stuck in</h2>
<p>Now let’s get our hands dirty and try to (a) reproduce the authors’ findings using the code and data they provided and (b) improve on these analyses. In doing so, I will assume for the time being that their computation of the BAGs (the outcome variable) makes sense—even though I believe it ought to be scrutinised further. I will focus entirely on the cross-sectional analyses carried out in <code>ORs_cross.ipynb</code>.</p>
<p>I carried out part of the reproduction in Python, using a stripped-down and refactored version of the notebook that the authors shared in their GitHub repository; I’ll link to my Python script when we need it. I additionally also used R.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Load packages and set plotting theme</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.signif.stars =</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;">tidyverse.quiet =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(DT)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-5"></span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_set</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>))</span></code></pre></div></div>
</details>
</div>
<section id="reproducing-the-odds-ratios" class="level3">
<h3 class="anchored" data-anchor-id="reproducing-the-odds-ratios">Reproducing the odds ratios</h3>
<p>I tried to reproduce the first couple of odds ratios reported in the authors’ Table 1, namely those reported for the models without additional covariates. The table caption says that these were estimated using logistic regression models. In their Python code (<code>ORs_cross.ipynb</code>), however, they fit log-link models, not logistic models:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode default code-with-copy"><code class="sourceCode default"><span id="cb2-1">sm.GLM(y_train, X_train_scaled, family=sm.families.Binomial(link=sm.families.links.log())).fit()</span></code></pre></div></div>
<p>The output of such models can still be converted to odds ratios, though. When I run the <code>ORs_cross.ipynb</code> notebook and convert the parameters of the log-linear models fitted in it to odds ratio, I obtain slightly different results from the ones reported in the article, see Table&nbsp;1.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">log_to_OR <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>(intercept, slope) {</span>
<span id="cb3-2">  odds0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(intercept) <span 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>(intercept))</span>
<span id="cb3-3">  odds1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(intercept <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> slope) <span 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>(intercept <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> slope))</span>
<span id="cb3-4">  odds1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> odds0</span>
<span id="cb3-5">}</span>
<span id="cb3-6"></span>
<span id="cb3-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb3-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Predictor =</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;">"Mono"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Two"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Three"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>),</span>
<span id="cb3-9">  <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;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.916226</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.699792</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.628158</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.704455</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.527900</span>),</span>
<span id="cb3-10">  <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;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.388409</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.145554</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.343348</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.226496</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.388527</span>),</span>
<span id="cb3-11">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">OR reported</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.11</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.54</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.67</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.47</span>)</span>
<span id="cb3-12">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">OR computed</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log_to_OR</span>(Intercept, Slope)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate_if</span>(is.numeric, round, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
</details>
<div id="tbl-odds-ratios" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-odds-ratios-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1: The intercept and slope parameter for the log-linear models without any co-variables fitted in <code>ORs_cross.ipynb</code>, the odds ratios reported in Amoruso et al.’s Table 1, and the ORs recomputed from the log-linear models.
</figcaption>
<div aria-describedby="tbl-odds-ratios-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<div data-pagedtable="false">
  <script data-pagedtable-source="" type="application/json">
{"columns":[{"label":["Predictor"],"name":[1],"type":["chr"],"align":["left"]},{"label":["Intercept"],"name":[2],"type":["dbl"],"align":["right"]},{"label":["Slope"],"name":[3],"type":["dbl"],"align":["right"]},{"label":["OR reported"],"name":[4],"type":["dbl"],"align":["right"]},{"label":["OR computed"],"name":[5],"type":["dbl"],"align":["right"]}],"data":[{"1":"Mono","2":"-0.916","3":"0.388","4":"2.11","5":"2.157"},{"1":"One","2":"-0.700","3":"-0.146","4":"0.75","5":"0.763"},{"1":"Two","2":"-0.628","3":"-0.343","4":"0.54","5":"0.532"},{"1":"Three","2":"-0.704","3":"-0.226","4":"0.67","5":"0.665"},{"1":"Total","2":"-0.528","3":"-0.389","4":"0.47","5":"0.463"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
  </script>
</div>
</div>
</div>
</figure>
</div>
</div>
<p>There could be several reasons for the discrepancies between the reported odds ratios and the ones that are computed using their code. I’m not going to speculate on these reasons.</p>
<p>As already mentioned above, the authors rescaled the predictor variables (<code>Mono</code>, <code>One</code>, etc.) to a range from 0.05 and 0.95 and split off an used test set from the main data. I don’t see any added value in these steps. Further, I do not see much value in the results other than the one for either the <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BMono%7D"> or the <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BTotal%7D"> variable; the former is the percentage of monolinguals, the latter the percentage of non-monolinguals.</p>
<p>Next, let us take a closer look at some of the other results in their Table 1. These concern logistic regression models for which another predictor was taken into account. Because of the issue identified with the GDP variable above, I’ve focused on reproducing the findings for this analysis. As Table&nbsp;2 shows, the results in the authors’ Table 1 are indeed roughly consistent with the models fitted in <code>ORs_cross.pynb</code> in which GDP (<em>not</em> per capita GDP!) was used as a control variable. Again, there could be several reasons for the slight discrepancies; I’ll refrain from speculating on these.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb4-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Predictor =</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;">"Mono"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Two"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Three"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Total"</span>),</span>
<span id="cb4-3">  <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;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.905862</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.703005</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.618220</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.690530</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.512324</span>),</span>
<span id="cb4-4">  <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;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.393635</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.155711</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.348275</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.240334</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.393752</span>),</span>
<span id="cb4-5">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">OR reported</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.16</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.74</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.53</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.65</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.46</span>)</span>
<span id="cb4-6">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">OR computed</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log_to_OR</span>(Intercept, Slope)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate_if</span>(is.numeric, round, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
</details>
<div id="tbl-OR-gdp" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-OR-gdp-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;2: The intercept and slope parameter for the log-linear models with GDP as the co-variable fitted in <code>ORs_cross.ipynb</code>, the odds ratios reported in Amoruso et al.’s Table 1, and the ORs recomputed from the log-linear models.
</figcaption>
<div aria-describedby="tbl-OR-gdp-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<div data-pagedtable="false">
  <script data-pagedtable-source="" type="application/json">
{"columns":[{"label":["Predictor"],"name":[1],"type":["chr"],"align":["left"]},{"label":["Intercept"],"name":[2],"type":["dbl"],"align":["right"]},{"label":["Slope"],"name":[3],"type":["dbl"],"align":["right"]},{"label":["OR reported"],"name":[4],"type":["dbl"],"align":["right"]},{"label":["OR computed"],"name":[5],"type":["dbl"],"align":["right"]}],"data":[{"1":"Mono","2":"-0.906","3":"0.394","4":"2.16","5":"2.203"},{"1":"One","2":"-0.703","3":"-0.156","4":"0.74","5":"0.750"},{"1":"Two","2":"-0.618","3":"-0.348","4":"0.53","5":"0.525"},{"1":"Three","2":"-0.691","3":"-0.240","4":"0.65","5":"0.647"},{"1":"Total","2":"-0.512","3":"-0.394","4":"0.46","5":"0.454"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
  </script>
</div>
</div>
</div>
</figure>
</div>
</div>
</section>
<section id="missing-info" class="level3">
<h3 class="anchored" data-anchor-id="missing-info">Missing info</h3>
<p>Important information is missing from the dataset <code>BAG_OR_cross.csv</code>, on which the cross-sectional analyses are based: it doesn’t specify the country and the wave of data collection that the respondents belong to, nor does it contain any information about the respondents’ age or the corrected <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BGAP%7D"> value. Only country/cohort level covariates and the binary <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BBAG%7D"> variable are available; the latter is called <code>GAP_bin</code> in the dataset. Note that the <code>ID</code> variable is just the row number (using zero-based indexing); it doesn’t actually allow you to link a particular respondent’s data in one dataset to their data in another dataset.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">d_cross <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BAG_OR_cross.csv"</span>)</span></code></pre></div></div>
</details>
</div>
<p>There are 97 unique combinations of country- and cohort-level predictors.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">country_cohort <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d_cross <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-2">  <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>ID, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>GAP_bin) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by_all</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</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;">.groups =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drop"</span>)</span>
<span id="cb6-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># write_csv(country_cohort, "country_cohort.csv")</span></span></code></pre></div></div>
</details>
</div>
<p>Using the information provided in the supplementary materials, I could piece together which of these combinations corresponded to which country and wave of data collection. I also had ChatGPT create a table with the approximate population of each country in each year of data collection. I’ve put this information in the dataset <a href="country_cohort.csv"><code>country_cohort.csv</code></a>. Let’s add it to the dataset for the cross-sectional analyses. While we’re at it, let’s compute per capita GDP, too, expressed in 10,000 units of whatever currency the GDP variable is expressed in.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">country_cohort <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"country_cohort.csv"</span>)</span>
<span id="cb7-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">datatable</span>(country_cohort)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div class="datatables html-widget html-fill-item" id="htmlwidget-607c460c5dab8cca112f" style="width:100%;height:auto;"></div>
<script type="application/json" data-for="htmlwidget-607c460c5dab8cca112f">{"x":{"filter":"none","vertical":false,"data":[["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97"],["Austria","Austria","Belgium","Belgium","Belgium","Belgium","Belgium","Bulgaria","Bulgaria","Croatia","Croatia","Croatia","Cyprus","Cyprus","Czechia","Czechia","Czechia","Czechia","Czechia","Denmark","Denmark","Denmark","Denmark","Denmark","Estonia","Estonia","Estonia","Estonia","Estonia","Finland","Finland","France","France","France","France","France","Germany","Germany","Germany","Germany","Germany","Greece","Greece","Greece","Hungary","Hungary","Hungary","Italy","Italy","Italy","Italy","Italy","Latvia","Latvia","Lithuania","Lithuania","Luxembourg","Luxembourg","Luxembourg","Luxembourg","Malta","Malta","Netherlands","Netherlands","Netherlands","Poland","Poland","Poland","Poland","Portugal","Portugal","Portugal","Romania","Romania","Slovenia","Slovenia","Slovenia","Slovenia","Slovenia","Spain","Spain","Spain","Spain","Spain","Sweden","Sweden","Sweden","Sweden","Sweden","Switzerland","Switzerland","Switzerland","Switzerland","Switzerland","Austria","Austria","Austria"],[2011,2013,2011,2013,2017,2015,2019,2017,2019,2018,2019,2020,2019,2017,2011,2013,2015,2017,2019,2011,2013,2019,2017,2015,2019,2017,2015,2013,2011,2017,2019,2011,2017,2016,2013,2019,2011,2014,2019,2017,2016,2019,2017,2015,2011,2019,2017,2019,2017,2015,2013,2011,2019,2017,2017,2019,2013,2015,2019,2017,2017,2019,2011,2013,2019,2019,2017,2015,2011,2011,2016,2015,2019,2017,2019,2017,2015,2013,2011,2019,2017,2016,2013,2011,2011,2013,2015,2016,2019,2011,2013,2016,2017,2015,2017,2015,2019],[21.9,18.66,42.1,33.86,21.5833333333333,25.62,21.75,50.7166666666667,51.15,27.72,25.7833333333333,23.75,9.300000000000001,10.1,30.9,26.94,22.98,21.1833333333333,21.55,5.90000000000001,5.22,7,5.13333333333334,4.54,6.65,8.08333333333333,9.94,12.22,14.5,7.96666666666667,7.9,41.2,37.0166666666667,40.16,40.68,31.25,21.5,21.42,16.8,19.8,21.34,31.15,32.7166666666667,35.18,63.2,54.45,56.55,33.05,33.6833333333333,35.22,37.66,40.1,4.6,4.33333333333334,4.51666666666667,4.55,2.86,4.62,5.5,5.5,10.2333333333333,14.3,13.9,13.82,10.35,30,31.9333333333333,33.94,38.1,41.5,30.85,33.1,57.7,62.0333333333333,9.949999999999999,13.9166666666667,14.24,10.92,7.59999999999999,44.75,45.45,46.42,47.66,48.9,8.199999999999999,6.28,4.36000000000001,3.51666666666667,3.75,12.1,10.58,8.300000000000001,8.300000000000001,9.06,13.4333333333333,15.42,12.7],[50.5,50.14,13.8,15.56,19.35,17.32,21.65,32.8333333333333,33.5,44.1,46.05,47.75,61.85,62.0833333333333,39.6,41.64,43.68,45.0166666666667,45.65,26.3,27.74,29.55,29.7833333333333,29.18,22.85,25.2166666666667,25.94,25.02,24.1,16.4166666666667,18.05,34.9,35.25,35.3,35.1,34.95,41.9,41.82,41.55,41.65,41.74,51.75,49.5833333333333,47.4,25.9,29.6,28.9333333333333,39.55,40.9166666666667,41.2,40.4,39.6,30.05,32.4833333333333,42.1333333333333,40.6,9.48,13.96,16.75,16.3833333333333,34.8666666666667,39.8,25.2,26.6,24.7,46.2,45.4,43.74,38.7,26.6,29.25,28.44,29.95,26.45,18.65,20.0166666666667,19.56,17.28,15,34.7,34.7666666666667,34.64,34.32,34,31.6,37.32,43.04,46.7166666666667,48.35,20.9,20.42,19.7,19.7,19.94,50.1666666666667,49.78,51.3],[18.9,20.66,23.5,27.5,32.8333333333333,31.5,31.5,13.2833333333333,12.45,21.7,22.0333333333333,22.5,20.75,20.45,22.4,24.2,26,26.5,25.7,43.1,42.34,37.1,39.8333333333333,41.58,41.15,39.7833333333333,38.3,36.7,35.1,31.9166666666667,32.55,19.2,21.7166666666667,19.92,19.56,24.95,26.3,26.42,28.2,27.1333333333333,26.54,14.2,14.9333333333333,14.68,9.199999999999999,12.65,11.6166666666667,21.45,20.55,19.4,18,16.6,50.95,49.85,40.45,43.35,24.04,26.08,25.1,26.4333333333333,40.0833333333333,33.85,37.1,37.1,34.55,19.85,19.4166666666667,19.2,19.2,20.5,24.8333333333333,23.94,11.25,10.55,24.4,25.2666666666667,27.08,29.84,32.6,15.05,14.55,13.96,13.28,12.6,29.7,30.5,31.3,31.8,32,34.2,34.72,35.5,35.5,35.24,23.5166666666667,22.42,23.95],[8.800000000000001,10.64,20.6,23.12,26.3333333333333,25.64,25.2,3.16666666666667,2.9,6.48,6.13333333333333,6,8.1,7.36666666666667,7.1,7.22,7.34,7.3,7.1,24.7,24.66,26.35,25.1833333333333,24.62,29.35,26.9166666666667,25.82,26.06,26.3,43.7666666666667,41.5,4.6,6.01666666666667,4.6,4.6,8.85,10.3,10.34,13.5,11.4333333333333,10.38,2.9,2.76666666666667,2.76,1.7,3.25,2.88333333333333,6,4.93333333333333,4.26,3.98,3.7,14.35,13.25,12.9666666666667,11.5,63.68,55.36,52.65,51.6833333333333,14.8166666666667,12.05,23.7,22.46,30.4,3.9,3.16666666666667,3.04,4,11.5,15.0833333333333,14.54,1.05,0.95,47,40.8,39.14,42.02,44.9,5.5,5.3,5.06,4.78,4.5,30.5,25.9,21.3,17.95,15.85,32.9,34.34,36.5,36.5,35.78,12.9666666666667,12.48,12.1],[78.2,81.44,57.9,66.18000000000001,78.51666666666669,74.45999999999999,78.34999999999999,49.2833333333333,48.85,72.28,74.2166666666667,76.25,90.7,89.90000000000001,69.09999999999999,73.06,77.02,78.81666666666671,78.45,94.09999999999999,94.73999999999999,93,94.8,95.38,93.34999999999999,91.9166666666667,90.06,87.78,85.5,92.09999999999999,92.09999999999999,58.7,62.9833333333333,59.82,59.26,68.75,78.5,78.58,83.25,80.2166666666667,78.66,68.84999999999999,67.2833333333333,64.84,36.8,45.5,43.4333333333333,67,66.40000000000001,64.86,62.38,59.9,95.34999999999999,95.5833333333333,95.55,95.45,97.2,95.40000000000001,94.5,94.5,89.76666666666669,85.7,86,86.16,89.65000000000001,69.95,67.98333333333331,65.98,61.9,58.6,69.1666666666667,66.92,42.25,37.95,90.05,86.0833333333333,85.78,89.14,92.5,55.25,54.6166666666667,53.66,52.38,51.1,91.8,93.72,95.64,96.4666666666667,96.2,88,89.48,91.7,91.7,90.95999999999999,86.65000000000001,84.68000000000001,87.34999999999999],[0.580798724495706,0.612023796245296,0.649688601313795,0.700628907893829,0.706897645940199,0.707102146035726,0.706849627676817,0.352614298236295,0.303553046129488,0.467967507068733,0.416864850253943,0.431016090818687,0.518348976820751,0.508491840511581,0.57549588640669,0.584577168435884,0.570518373201654,0.577188066544074,0.540472231051049,0.738176215450677,0.74657664198943,0.752485295197633,0.740385625688507,0.739032644332725,0.739203700977757,0.777452744562331,0.693769165828153,0.630803479120532,0.658084727585558,0.728673272271674,0.758023657759448,0.611129847259675,0.6858322043898381,0.655835730660721,0.641501908198259,0.676407211089183,0.77243104419727,0.745797455655099,0.770107575389864,0.766072575949743,0.753989697066441,0.624962334324878,0.600759765179868,0.561763660628951,0.594386860859112,0.304635246429338,0.338991800480261,0.556318557239642,0.546244186397989,0.512581775838313,0.508190933959124,0.479988256685893,0.460142815797487,0.435598392763092,0.53116995027916,0.555819916901424,0.5263565565327391,0.543416709660275,0.517131905398845,0.514126776151578,0.449599553570998,0.446751589672481,0.737235578642613,0.696354270626467,0.664668829711179,0.49782387612697,0.555375343128699,0.598994507286445,0.505934763256214,0.580249142405441,0.673617029749779,0.636048131252454,0.402825936891591,0.331745304470748,0.629923544669341,0.657733489884756,0.629271354675515,0.658809332458844,0.682417292755148,0.734383399500478,0.6527307646667,0.646993119355833,0.667837241913958,0.653347152140712,0.78567488229906,0.796084282709819,0.785481024563946,0.7800436914014161,0.773035390304849,0.611132730821539,0.628778047658607,0.588084828450292,0.6138920371265471,0.631247208523444,0.632453993911947,0.607060203159468,0.623048696556997],[0.635756190801168,0.642925171296124,0.624768661487405,0.690016529252265,0.689837360594835,0.689837360594835,0.677363381641823,0.388660146611258,0.293015165082719,0.525543081308283,0.438108939455045,0.451121429551038,0.5915234651372731,0.583252419162839,0.6158312562462021,0.642258909503217,0.585529149167005,0.592882025943423,0.5490458664733,0.689799021050047,0.685316251411818,0.672756806208638,0.676340179357228,0.676340179357228,0.727283440292095,0.8047241517429971,0.695410411451305,0.682354469560685,0.680845255816266,0.660226364859378,0.657658280769555,0.671168277915854,0.6810742624174519,0.685307863306434,0.685307863306434,0.6810742624174519,0.863909245361325,0.797974165627674,0.834768258645469,0.834768258645469,0.797974165627674,0.714164243353444,0.706601247274399,0.703967917135623,0.727318365636899,0.204891265688374,0.290216734980804,0.612556195711775,0.6146981559719,0.578025922647491,0.578025922647491,0.577895516964031,0.336982179916302,0.346251549467754,0.57439773141487,0.575727286586563,0.547656308439092,0.547656308439092,0.530762992659873,0.547656308439092,0.424125475561718,0.424125475561718,0.72759410351785,0.675827165309369,0.657048451587722,0.564226860220629,0.690999880199329,0.762561321547621,0.683710672823743,0.696133748675272,0.757918821554342,0.727363720529281,0.421790720149067,0.382485611816826,0.57011900087543,0.6270512315353,0.596332366462193,0.681565991451114,0.74997133300007,0.767573520526197,0.673645401668012,0.689245859267658,0.7333167518756269,0.732521695817834,0.731432107600651,0.737716998227077,0.71893276089067,0.71893276089067,0.7008672234289099,0.659838779772511,0.677075975714684,0.580293266325754,0.629238309272155,0.6601432502821321,0.630783885407954,0.642925171296124,0.612824094029719],[0.50752210275509,0.570821962844191,0.682915187748982,0.71477874608258,0.729644693067351,0.730121859956913,0.746164622390143,0.304553167069678,0.317603554191847,0.391200074749334,0.388539397985808,0.404208972508887,0.420782992398723,0.408811068976571,0.52171539328734,0.5076681803461059,0.550504005247852,0.5562627873449409,0.529040717154713,0.802679141318183,0.8282571627595779,0.858789947182959,0.825779554130212,0.822622597633387,0.755097381891972,0.741090868321443,0.691580838330617,0.562068825200328,0.6277373566112791,0.81993581548807,0.891844160412638,0.53107860638477,0.692176127019685,0.61653955379977,0.583093968054025,0.670184475984824,0.650460109311862,0.676228509024998,0.683893331049057,0.674478332355441,0.695343738984797,0.506026455620124,0.459637789053827,0.372157985286723,0.417144854488729,0.437627220750622,0.404025221146204,0.481335039276799,0.454972226966108,0.425322913426076,0.415077615707969,0.349445242981708,0.6243569969724,0.554727517156876,0.473532908764879,0.529276757321238,0.497956887324268,0.537763911288519,0.49895712238414,0.469420733101561,0.483564990916704,0.476919741820165,0.750090878808964,0.723723744382597,0.674829333875788,0.40928656400209,0.374542627034525,0.380905421604876,0.268900217166174,0.425736334045665,0.561214640677027,0.514294012216685,0.377539559214956,0.264091561342644,0.709662936394557,0.698643167684032,0.673190005626612,0.62846712046915,0.5923452390952511,0.690129904799519,0.624844581998285,0.590656132806732,0.580531228631732,0.547781093904549,0.857998581896938,0.873907328686809,0.87421204279498,0.861524932082411,0.869259612806101,0.546191332220243,0.564380810250504,0.598473577949677,0.593430340932404,0.5927191528451931,0.634680805250606,0.559240245643925,0.6366814999267],[431685217367.511,430190979705.962,523330354138.133,521791015247.06,502764720556.354,462335574841.484,535865804349.803,59309748166.1179,68881010245.5498,51011170111.8487,56322449844.1579,61867157679.3215,25947020102.4332,22946583374.7569,229562733398.948,211685616592.931,188033050459.881,218628940951.675,252548179964.897,344003137611.271,343584391647.927,346498737961.635,332121063806.391,302673070846.857,31290453293.5451,26924385103.0659,22890762090.1508,25115753366.1114,23213994093.4631,255647979916.471,268514916972.549,2865157541994.17,2595151045197.65,2439188643162.5,2811876903329.03,2728870246705.88,3749314991050.59,3733804649549.03,3889177589254.9,3690849152517.65,3357585719351.56,205252760889.364,199844406013.531,195683527003.375,141942264554.475,164020460331.659,143112196040.326,2011302198827.45,1961796197354.36,1836637711060.55,2141924094298.56,2294994296589.5,34225547537.0745,30483806017.8318,47758736931.7801,54808531641.4117,65203276466.9763,60071584216.1375,69890505323.5842,65712180342.9836,13484541925.7714,16004563885.7539,905270626332.687,877172824534.512,910194347568.626,596058473058.766,524641252834.826,477111287969.227,524374183218.309,245117990242.248,221357874718.93,199394066525.44,251017797625.017,210147163769.848,54386654313.9685,48589100043.0954,43107506024.3254,48415657264.8758,51583869785.1849,1394320055129.41,1313245330197.65,1196156971279.69,1355579535912.55,1480710495710.12,574094112972.733,586841821796.891,505103781349.757,541018749769.097,533879529188.454,715888126682.396,706234937370.968,695200833086.499,721369112726.724,694118186379.6281,417261151844.977,381971148530.543,444596155845.254],[15.6570549611063,16.5613906058116,10.162808151585,11.2231706729085,12.2835331942319,12.2835331942319,12.2835331942319,1.428196392424,1.428196392424,13.6047139871854,13.6047139871854,13.6047139871854,16.834034154295,16.834034154295,3.79727925076362,3.81975246546639,3.84222568016916,3.84222568016916,3.84222568016916,9.36613248065313,9.73256191696272,10.0989913532723,10.0989913532723,10.0989913532723,15.4163092221449,15.4163092221449,15.4163092221449,15.7925916070553,16.1688739919657,5.73968325726902,5.73968325726902,11.5617252969557,12.0884793768866,12.0884793768866,11.8251023369212,12.0884793768866,14.5186915462586,14.6988714207909,14.8790512953233,14.8790512953233,14.8790512953233,11.3423773738507,11.3423773738507,11.3423773738507,4.40031731724867,4.56246525249104,4.56246525249104,9.6807677420957,9.6807677420957,9.6807677420957,9.69373440512658,9.70670106815747,13.3532402640341,13.3532402640341,4.72608962255138,4.72608962255138,39.2271146141833,43.9641339422687,43.9641339422687,43.9641339422687,9.8984880693625,9.8984880693625,11.1537458235597,11.4247142823404,11.6956827411211,1.60418083655994,1.60418083655994,1.60418083655994,1.65314423403824,7.3833357951508,8.089593589365901,8.089593589365901,1.16313480315329,1.16313480315329,11.4129640933173,11.4129640933173,11.4129640933173,11.7937170278644,12.1744699624115,12.6902371918259,12.6902371918259,12.6902371918259,13.0045834623447,13.3189297328634,15.162381155937,15.9649699531588,16.7675587503806,16.7675587503806,16.7675587503806,27.0782615919657,28.232473566981,29.3866855419963,29.3866855419963,29.3866855419963,17.465726250517,17.465726250517,17.465726250517],[2,2,3,3,3,3,3,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,2,2,2,2,1,1,2,2,2,1,1,1,1,2,2,2,2,2,2,2,2,2,2,4,4,4,4,4,2,2,2,2,2,3,3,3,3,3,2,2,2],[4,4,4,4,4,4,4,2,2,2,2,2,0,0,3,3,3,3,3,2,2,2,2,2,1,1,1,1,1,3,3,5,5,5,5,5,10,10,10,10,10,5,5,5,2,2,2,7,7,7,7,7,2,2,2,2,0,0,0,0,1,1,9,9,9,3,3,3,3,2,2,2,2,2,1,1,1,1,1,2,2,2,2,2,0,0,0,0,0,5,5,5,5,5,4,4,4],[31,31,17,17,17,17,17,27,27,11,11,11,44,44,9,9,9,9,9,11,11,11,11,11,84,84,84,84,84,51,51,15,15,15,15,15,31,31,31,31,31,566,566,566,84,84,84,21,21,21,21,21,60,60,83,83,20,20,20,20,24,24,14,14,14,45,45,45,45,21,21,21,144,144,12,12,12,12,12,9,9,9,9,9,21,21,21,21,21,28,28,28,28,28,31,31,31],[0.426828279760995,0.543639371099459,0.788752453285698,0.771795206135098,0.733479730340766,0.770577818785721,0.763582679863982,0.574077430237829,0.593385048182073,0.272754455252371,0.148182945804232,0.10819453215087,0.167355264855434,0.124090086972018,0.412856528398529,0.281728066583104,0.323979707848844,0.237989021748751,0.181914445229453,0.980318762388752,0.98815789868686,1,0.985380171917574,0.939743841507157,0.701844752720087,0.62552315664267,0.659284917677901,0.463750373948703,0.5097981974231151,0.65733831066174,0.9056802188781951,0.601169310764201,0.816265901000798,0.697502896409844,0.644580916982944,0.7244875339975561,0.825582477601391,0.860734649541857,0.814817730019517,0.80239382496182,0.872876922902425,0.479861203672287,0.429434305740094,0.33932483912477,0.269847186788382,0.18601363383361,0.126011095067465,0.582472706593823,0.584059033754853,0.553344457445312,0.496156449738574,0.462407048192141,0.818484879851504,0.666913512530305,0.455658050759793,0.507530485837698,0.279865332126045,0.395900861554826,0.334706929885288,0.254371244268105,0.09139601030674591,0.20502106892747,0.941901823111549,0.754033215488991,0.644007914732912,0.308738892318581,0.266344509582717,0.414607839209798,0.362256207054077,0.268378899560797,0.423898698498664,0.407074249443784,0.264307006775348,0,0.678219280400696,0.620825950603305,0.674147177895333,0.612509496370865,0.5392434957980971,0.898806430188091,0.728583250926207,0.754658682158509,0.716263551877634,0.682560690445687,0.8852632301735101,0.94755869945104,0.959349895627042,0.888476950589474,0.940462182332811,0.493945528283135,0.5362005238983431,0.530847647900476,0.598162130030467,0.568473789489118,0.551164626596747,0.43762701017644,0.597203310692323],[0.503145435911682,0.5762339248405211,0.5007338507019879,0.588590414828691,0.652985213058817,0.635837143801066,0.660096372491632,0.339582070971206,0.353252774887295,0.326771694921556,0.400151297535909,0.394555842165914,0.527092477772834,0.546787564402138,0.288092120599296,0.38325178309719,0.43247057949965,0.474009216829284,0.473108940802588,0.619076686257154,0.762045688357306,0.7924192242649279,0.769736268250839,0.775037531639919,0.970854800363237,0.980465497704374,0.940148955338641,0.895295607825121,0.8857595514230669,1,0.9859016450757701,0.553794903451837,0.717052603515046,0.676807123014157,0.617046666191478,0.718164659389015,0.527032418235431,0.618568161483755,0.699825226090617,0.696349814079812,0.65759873849641,0.587600879237466,0.579108691051016,0.505544178463795,0.290229351986448,0.484892719776279,0.48112629676621,0.50350771987855,0.503079869365694,0.413982307524276,0.409570224545826,0.258768186925823,0.690388580201498,0.700972742644027,0.773582650843486,0.765484971311202,0.69548681132824,0.754427909347769,0.779448387884415,0.789693424172379,0.667940937752009,0.645491242952779,0.530593035537567,0.657878758399541,0.689122062203096,0.203071416971638,0.196789544360365,0.197244228073966,0,0.755743682823111,0.852337816125009,0.833338651403803,0.522632658523842,0.520669745756327,0.46311520779532,0.47510355244879,0.419496913058577,0.396348655160043,0.281002098030865,0.795040074333924,0.794098643216795,0.758050457002427,0.766070874758303,0.670659134477839,0.89860905872718,0.9581139038933379,0.97192820806654,0.980048462941711,0.9821314709003089,0.607591431340556,0.669287585865513,0.789264443973245,0.787067164371683,0.709683669046461,0.692383961994576,0.628982615644225,0.683211559458146],[0.592592592592593,0.592592592592593,0.75925925925926,0.78395061728395,0.802469135802469,0.78395061728395,0.814814814814815,0,0.00617283950617287,0.574074074074074,0.617283950617283,0.709876543209877,0.567901234567901,0.555555555555555,0.864197530864197,0.8580246913580249,0.895061728395062,0.95679012345679,0.932098765432099,0.808641975308643,0.7345679012345681,0.78395061728395,0.722222222222222,0.753086419753086,0.592592592592593,0.617283950617283,0.475308641975309,0.327160493827161,0.487654320987654,0.802469135802469,0.78395061728395,0.438271604938271,0.543209876543211,0.475308641975309,0.487654320987654,0.567901234567901,0.598765432098765,0.549382716049383,0.537037037037037,0.524691358024691,0.555555555555555,0.450617283950618,0.37037037037037,0.271604938271605,0.691358024691358,0.6419753086419761,0.604938271604938,0.358024691358025,0.277777777777777,0.308641975308642,0.339506172839505,0.327160493827161,0.364197530864198,0.296296296296297,0.191358024691358,0.314814814814815,0.518518518518518,0.462962962962963,0.382716049382716,0.364197530864198,0.691358024691358,0.580246913580247,0.777777777777778,0.75925925925926,0.691358024691358,0.71604938271605,0.660493827160494,0.530864197530864,0.444444444444444,0.253086419753087,0.407407407407407,0.302469135802469,0.345679012345679,0.271604938271605,0.987654320987654,1,0.925925925925926,0.876543209876543,0.95679012345679,0.376543209876544,0.351851851851851,0.259259259259259,0.259259259259259,0.290123456790123,0.790123456790123,0.71604938271605,0.691358024691358,0.71604938271605,0.685185185185185,0.537037037037037,0.487654320987654,0.475308641975309,0.395061728395062,0.5,0.660493827160494,0.611111111111111,0.62962962962963],[0.456749385859517,0.480838247290084,0,0.259992735052012,0.259992735052012,0.259992735052012,0.259992735052012,0.187469048916231,0.187469048916231,0.391769162702179,0.391769162702179,0.391769162702179,0.480838247290084,0.480838247290084,0.593873626237206,0.603940490870655,0.512203096766381,0.512203096766381,0.512203096766381,0.456749385859517,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084,0.603940490870655,0.603940490870655,0.603940490870655,0.603940490870655,0.593873626237206,0.480838247290084,0.480838247290084,0.456749385859517,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084,0.456749385859517,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084,1,0.0274007053717487,0.115478642147258,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084,0.456749385859517,0.379773677279894,0.312628092200508,0.518012693042467,0.518012693042467,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084,0.0970280261725964,0.0970280261725964,0.456749385859517,0.480838247290084,0.480838247290084,0.518012693042467,0.518012693042467,0.746059748677704,0.279909980941069,0.456749385859517,0.480838247290084,0.480838247290084,0.379773677279894,0.391769162702179,0.518012693042467,0.518012693042467,0.518012693042467,0.746059748677704,1,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084,0.456749385859517,0.456749385859517,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084,0.456749385859517,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084,0.480838247290084],[0.841614906832298,0.839703774486383,0.939321548017201,0.939321548017201,0.938604873387483,0.938604873387483,0.916387959866222,0.650740563784042,0.650740563784042,0.730530339225992,0.730530339225992,0.766841853798376,0.794553272814143,0.81055900621118,0.851648351648352,0.815575728619208,0.815575728619208,0.861204013377927,0.861204013377927,0.913521261347349,0.913521261347349,0.90157668418538,0.915910176779743,0.915910176779743,0.883659818442428,0.904921165790731,0.904921165790731,0.914715719063546,0.914715719063546,0.842331581462017,0.832059245102724,0.841853798375538,0.883182035355949,0.839464882943145,0.839464882943145,0.883182035355949,1,0.8901098901098911,0.8834209268991881,0.8834209268991881,0.8901098901098911,0.963927376970856,0.903248924988056,0.903248924988056,0.889393215480173,0.792164357381749,0.799092212135691,0.760630673674152,0.778308647873866,0.778308647873866,0.778308647873866,0.942666029622552,0,0.0155279503105583,0.877687529861444,0.873865265169614,0.710463449593885,0.710463449593885,0.709030100334449,0.710463449593885,0.873387482083134,0.873387482083134,0.884854276158625,0.885809842331582,0.869087434304826,0.836120401337792,0.933588150979455,0.933588150979455,0.97372193024367,0.8449593884376499,0.896559961777354,0.896559961777354,0.832059245102724,0.829431438127091,0.8561872909699,0.8561872909699,0.84854276158624,0.849737219302438,0.849737219302438,0.972288580984234,0.8862876254180611,0.8862876254180611,0.906115623506929,0.906115623506929,0.813903487816532,0.813903487816532,0.809842331581462,0.809842331581462,0.7692307692307701,0.851887243191591,0.851887243191591,0.8354037267080749,0.830864787386528,0.8354037267080749,0.768514094601051,0.839703774486383,0.79933110367893],[0.5718729393752,0.578371132270373,0.766233537416515,0.767232273423944,0.767232273423944,0.767232273423944,0.7395532711331541,0.208886163671582,0.21168436629226,0.575696709268767,0.467892504637976,0.412555009063305,0.477537326919165,0.428447409624395,0.630001316158747,0.6328321718572451,0.6328321718572451,0.479952304254137,0.444233641742675,0.66010241467572,0.662057055419367,0.623763851768614,0.623763851768614,0.623763851768614,0.711498501544693,1,0.796832416988931,0.734814096153636,0.73884410580941,0.673663344529051,0.673663344529051,0.707429587299265,0.681636426894681,0.742287982863414,0.742287982863414,0.681636426894681,0.998887595585785,0.845391140221911,0.999256475503795,0.999256475503795,0.845391140221911,0.634468599490482,0.664895067157102,0.654361746601997,0.453926306612221,0,0.0980903522666448,0.597827287565276,0.621226415405655,0.606741175722192,0.606741175722192,0.474585908591476,0.603989380926697,0.605146139365442,0.533839426438748,0.5429799118173509,0.603656598184934,0.603656598184934,0.603656598184934,0.603656598184934,0.334000533759073,0.334000533759073,0.998887595585785,0.766775415148336,0.708382968288504,0.223680374023149,0.6024949784821449,0.660693688240078,0.730709365681395,0.712124287787362,0.883575144533371,0.761354740433126,0.453214588086925,0.286626476311311,0.511338699266945,0.625717031510266,0.510486100601497,0.62217908720575,0.641860202079278,0.816179017342091,0.526467497475526,0.5888693278741109,0.7453249002171199,0.766233537416515,0.7934627668320881,0.794513467907224,0.762164950552001,0.762164950552001,0.686623450532943,0.544753256358795,0.589613178696921,0.551448630301773,0.5315621476144879,0.5383657934502289,0.600995668603022,0.578371132270373,0.498339494012204],[0.672787531137658,0.672787531137658,0.793519560515903,0.793519560515903,0.793519560515903,0.793519560515903,0.793519560515903,0.507544810073176,0.122166681338342,0.404176114036193,0.162243751254032,0.233319692640291,0.613165013525699,0.613165013525699,0.387801730940502,0.516687246665763,0.381505599425188,0.518168689375248,0.378542714006216,0.728823022317601,0.684848441590473,0.684848441590473,0.684848441590473,0.684848441590473,0.710034950310603,0.710034950310603,0.475947572154904,0.475947572154904,0.475947572154904,0.644072286156362,0.644072286156362,0.678640340129095,0.678640340129095,0.678640340129095,0.678640340129095,0.678640340129095,1,0.9755573848888091,0.9755573848888091,0.9755573848888091,0.9755573848888091,0.777422749662354,0.777422749662354,0.777422749662354,0.565953940455203,0,0.148205733373621,0.610928574317589,0.578419313317995,0.446215619703823,0.446215619703823,0.43758074378258,0.364165661458619,0.451704015994506,0.368051276316823,0.368051276316823,0.395666938687464,0.395666938687464,0.329527024830027,0.395666938687464,0.392085860232066,0.392085860232066,0.569885156467473,0.569885156467473,0.569885156467473,0.679093972479109,0.709903698293248,0.709903698293248,0.75050141442884,0.7707019326165619,0.7707019326165619,0.7707019326165619,0.0221153701267236,0.0221153701267236,0.394937320222407,0.508287910618566,0.508287910618566,0.508287910618566,0.508287910618566,0.800988236488378,0.800988236488378,0.800988236488378,0.800988236488378,0.800988236488378,0.861612789894467,0.861612789894467,0.822885514139133,0.822885514139133,0.866776426661845,0.78596523368014,0.78596523368014,0.453482461003083,0.673688054797519,0.78596523368014,0.672787531137658,0.672787531137658,0.672787531137658],[2872,108,1852,1100,64,1149,777,1061,892,2390,272,136,522,683,2657,849,237,61,1771,233,1033,1026,36,281,2507,29,815,130,4041,836,1146,1967,50,378,118,1127,10,2394,2003,46,114,73,29,2497,2245,739,26,818,87,1327,1272,1037,776,908,634,1399,947,453,671,33,475,784,518,1049,979,1278,1943,359,32,1710,9,195,1248,835,1626,57,1533,532,1543,1064,106,329,2360,1053,42,1362,162,42,1184,1306,49,33,1179,67,36,123,1181],[8375164,8451860,11011716,11160992,11384723,11258434,11467933,6803468,6985000,4265344,4058200,4058200,1224000,1212900,10500000,10510000,10550000,10590000,10649800,5600940,5624000,5806100,5731110,5678910,1324800,1327439,1331475,1326898,1326040,5566210,5514100,65316851,65438667,64818789,66734800,67028000,80274983,82905782,83019200,80425823,80274983,10722800,10645000,10721582,9759755,9772800,9913588,60359500,60789190,60795612,60650000,59296632,1907800,1903000,2778000,2794200,543000,569000,613900,598000,464000,493600,16645000,16750000,17410000,37950000,38640000,38750000,38175000,10512254,10470000,10501200,19200000,19470000,2080200,2089000,2080000,2061500,2050191,47200000,46950000,46700000,46670000,46196548,9448073,9481000,9525000,9545000,9753000,7851000,8120000,8344000,8416000,8300000,8772865,8584926,8858775]],"container":"<table class=\"display\">\n  <thead>\n    <tr>\n      <th> <\/th>\n      <th>Country<\/th>\n      <th>Year<\/th>\n      <th>Mono<\/th>\n      <th>One<\/th>\n      <th>Two<\/th>\n      <th>Three<\/th>\n      <th>Total<\/th>\n      <th>total_exposomes<\/th>\n      <th>sociopolitical<\/th>\n      <th>social_physical<\/th>\n      <th>GDP<\/th>\n      <th>Migration<\/th>\n      <th>number_leng_inst<\/th>\n      <th>number_stable_inst<\/th>\n      <th>distance<\/th>\n      <th>gender_equal_l<\/th>\n      <th>Polution_conc_inv<\/th>\n      <th>Eq<\/th>\n      <th>free_parties_l<\/th>\n      <th>inclu_suff_est<\/th>\n      <th>cred_elect_est<\/th>\n      <th>local_dem_est<\/th>\n      <th>n<\/th>\n      <th>Pop<\/th>\n    <\/tr>\n  <\/thead>\n<\/table>","options":{"columnDefs":[{"className":"dt-right","targets":[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]},{"orderable":false,"targets":0},{"name":" ","targets":0},{"name":"Country","targets":1},{"name":"Year","targets":2},{"name":"Mono","targets":3},{"name":"One","targets":4},{"name":"Two","targets":5},{"name":"Three","targets":6},{"name":"Total","targets":7},{"name":"total_exposomes","targets":8},{"name":"sociopolitical","targets":9},{"name":"social_physical","targets":10},{"name":"GDP","targets":11},{"name":"Migration","targets":12},{"name":"number_leng_inst","targets":13},{"name":"number_stable_inst","targets":14},{"name":"distance","targets":15},{"name":"gender_equal_l","targets":16},{"name":"Polution_conc_inv","targets":17},{"name":"Eq","targets":18},{"name":"free_parties_l","targets":19},{"name":"inclu_suff_est","targets":20},{"name":"cred_elect_est","targets":21},{"name":"local_dem_est","targets":22},{"name":"n","targets":23},{"name":"Pop","targets":24}],"order":[],"autoWidth":false,"orderClasses":false}},"evals":[],"jsHooks":[]}</script>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">d_cross <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d_cross <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(country_cohort) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb8-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GDP_percapita =</span> (GDP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> Pop) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stderr">
<pre><code>Joining with `by = join_by(Mono, One, Two, Three, Total, total_exposomes,
sociopolitical, social_physical, GDP, Migration, number_leng_inst,
number_stable_inst, distance, gender_equal_l, Polution_conc_inv, Eq,
free_parties_l, inclu_suff_est, cred_elect_est, local_dem_est)`</code></pre>
</div>
</div>
</section>
<section id="drawing-some-plots" class="level3">
<h3 class="anchored" data-anchor-id="drawing-some-plots">Drawing some plots</h3>
<p>Amoruso et al.&nbsp;drew lots of plots—just none that show how the predictors and the BAGs are related. A first (naive) plot is shown in Figure&nbsp;1. The smooth trend line attempts to estimate the proportion of respondents showing accelerated ageing (again, I’m taking the accelerated ageing variable as given for now; I’ll scrutinise it later) based on the extent of country-level monolingualism.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">d_cross <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb10-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> Mono, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> GAP_bin)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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;">"gam"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">s</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bs =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cr"</span>),</span>
<span id="cb10-4">              <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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage of monolinguals in country"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb10-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proportion of accelerated ageing"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-naive" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-naive-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-12-15-multilingualism-accelerated-ageing/index_files/figure-html/fig-naive-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-naive-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: A naive trendline showing the extent of accelerated ageing according to country-level monolingualism.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The bumps in this graph highlight a problem with Amoruso et al.’s analysis: they didn’t take the nested nature of the data into account. To address this, I’ve computed the number and proportion of respondents showing accelerated ageing for each combination of country and year of data collection. Figure&nbsp;2 shows how the proportion of respondents with accelerated ageing varied between different waves of data collection within each country.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">by_country_year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d_cross <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Country, Year, Mono, GDP_percapita) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb11-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb11-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_accelerated =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(GAP_bin <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb11-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prop_accelerated =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(GAP_bin <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb11-7">    <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="cb11-8">  )</span>
<span id="cb11-9"></span>
<span id="cb11-10">by_country_year <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb11-11">  <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> Mono, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> prop_accelerated)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-12">  <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;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_smooth</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lm"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder</span>(Country, prop_accelerated))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proportion of monolinguals"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proportion of accelerated ageing"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-by_country_year" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-by_country_year-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-12-15-multilingualism-accelerated-ageing/index_files/figure-html/fig-by_country_year-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-by_country_year-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Each point represents a combination of country and year of data collection. The countries are sorted top to bottom, left to right, in increasing average proportion of respondents showing accelerated ageing.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The proportion of monolinguals tends to vary fairly little within each country, and I’m not convinced that we should put too much stock in the yearly changes in these proportions. So I’ll simply aggregate the data per country instead. Figure&nbsp;3 shows that there is indeed a tendency for countries with relatively more monolinguals to have a greater of respondents with accelerated ageing.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">by_country <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d_cross <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Country) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb12-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb12-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb12-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_accelerated =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(GAP_bin <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb12-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prop_accelerated =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(GAP_bin <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb12-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_Mono =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(Mono),</span>
<span id="cb12-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_GDP =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(GDP_percapita),</span>
<span id="cb12-9">    <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="cb12-10">  )</span>
<span id="cb12-11"></span>
<span id="cb12-12"></span>
<span id="cb12-13">by_country <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb12-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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> mean_Mono, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> prop_accelerated)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</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;">label =</span> Country), <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="cb12-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</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;">65</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage of monolinguals"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb12-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proportion of accelerated ageing"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-country_mono" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-country_mono-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-12-15-multilingualism-accelerated-ageing/index_files/figure-html/fig-country_mono-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-country_mono-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: The percentage of monolinguals shown is the weighted average of the percentages of monolinguals in the country at the different waves of data collection.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;4 shows the association of the proportion of respondents per country with accelerated ageing and the country’s per capita GDP.</p>
<div class="cell preview-image">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">by_country <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;">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> mean_GDP, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> prop_accelerated)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</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;">label =</span> Country), <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="cb13-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GDP per capita (in 10k)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</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;">12.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proportion of accelerated ageing"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-country_gdp" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-country_gdp-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-12-15-multilingualism-accelerated-ageing/index_files/figure-html/fig-country_gdp-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-country_gdp-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: The GDP per capita is the weighted average of the country’s GDP per capita at the different waves of data collection.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;5 shows the association between the per capita GDP and the proportion of monolinguals in the country.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">by_country <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb14-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> mean_GDP, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> mean_Mono)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</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;">label =</span> Country), <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="cb14-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GDP per capita (in 10k)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</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;">12.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proportion of monolinguals"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mono_gdp" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mono_gdp-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-12-15-multilingualism-accelerated-ageing/index_files/figure-html/fig-mono_gdp-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mono_gdp-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: The GDP per capita and the proportion of monolinguals are the weighted average of the country’s values at the different waves of data collection.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="refitting-the-models" class="level3">
<h3 class="anchored" data-anchor-id="refitting-the-models">Refitting the models</h3>
<p>To take the nested nature of the data into account, we could fit a binomial model to the data aggregated by country. I expressed the monolingualism variable in such a way that a one-unit increase in this variable corresponds to a difference of 10 percentage points in monolingualism. I also centred this variable at its median, corresponding to about 19% monolinguals.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1">by_country<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c.Mono10 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> by_country<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>mean_Mono <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span></span>
<span id="cb15-2">by_country<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c.Mono10 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> by_country<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c.Mono10 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(by_country<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c.Mono10)</span>
<span id="cb15-3">mono.glm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(n_accelerated, n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> n_accelerated) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> c.Mono10,</span>
<span id="cb15-4">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> by_country,</span>
<span id="cb15-5">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">binomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>))</span>
<span id="cb15-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(mono.glm)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
Call:
glm(formula = cbind(n_accelerated, n - n_accelerated) ~ c.Mono10, 
    family = binomial(link = "logit"), data = by_country)

Coefficients:
             Estimate Std. Error z value Pr(&gt;|z|)
(Intercept) -0.195093   0.007354  -26.53   &lt;2e-16
c.Mono10     0.099915   0.004304   23.21   &lt;2e-16

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 2565.1  on 25  degrees of freedom
Residual deviance: 2023.3  on 24  degrees of freedom
AIC: 2245.3

Number of Fisher Scoring iterations: 3</code></pre>
</div>
</div>
<p>The problem with this model is the <em>massive</em> overdispersion: <img src="https://latex.codecogs.com/png.latex?%5Cchi%5E2%20=%202023.3/24%20=%2084.3%20%5Cgg%201">. The binomial logistic model assumes that the number of respondents showing accelerated ageing in the <img src="https://latex.codecogs.com/png.latex?i">-th country is <img src="https://latex.codecogs.com/png.latex?Y_i%20%5Csim%20%5Ctextrm%7BBinomial%7D(n_i,%20%5Cpi_i),"> where <img src="https://latex.codecogs.com/png.latex?n_i"> is the number of respondents in the <img src="https://latex.codecogs.com/png.latex?i">-th country and <img src="https://latex.codecogs.com/png.latex?%5Cpi_i"> is the probability parameter modelled as <img src="https://latex.codecogs.com/png.latex?%5Cpi_i%20=%20%5Ctextrm%7BLogistic%7D(%5Cbeta_0%20+%20%5Cbeta_1x_i)%20=%20%5Cfrac%7B1%7D%7B1%20+%20%5Cexp(%7B-(%5Cbeta_0%20+%20%5Cbeta_1x_i)%7D)%7D,"> with <img src="https://latex.codecogs.com/png.latex?x_i"> the percentage of monolinguals in the <img src="https://latex.codecogs.com/png.latex?i">-th country.</p>
<p>Clearly, this model underspecifies the true data-generating mechanism. In normal (ordinary least squares) regression models, this isn’t a huge problem in and of itself: the error term doesn’t depend on the modelled mean and can absorb the variance associated with unmodelled factors.</p>
<p>But the binomial model does not <em>have</em> a separate error term. Instead, it assumes that the variance around <img src="https://latex.codecogs.com/png.latex?Y_i"> is the variance of the binomial distribution, i.e., <img src="https://latex.codecogs.com/png.latex?%5Ctextrm%7BVar%7D(Y_i)%20=%20n_i%5Cpi_i(1-%5Cpi_i)">. To the extent that other factors beyond the ones modelled contribute to the outcome, <img src="https://latex.codecogs.com/png.latex?%5Ctextrm%7BVar%7D(Y_i)"> can be considerably larger than <img src="https://latex.codecogs.com/png.latex?n_i%5Cpi_i(1-%5Cpi_i)">, and the standard errors and confidence intervals need to be widened to take this into account.</p>
<p>One option is to fit the data in a quasibinomial regression model instead. The resulting parameter estimates are the same as before, but the standard error increased by a factor of about 9.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1">mono.glm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(n_accelerated, n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> n_accelerated) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> c.Mono10,</span>
<span id="cb17-2">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> by_country,</span>
<span id="cb17-3">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasibinomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>))</span>
<span id="cb17-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(mono.glm)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
Call:
glm(formula = cbind(n_accelerated, n - n_accelerated) ~ c.Mono10, 
    family = quasibinomial(link = "logit"), data = by_country)

Coefficients:
            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept) -0.19509    0.06715  -2.905  0.00776
c.Mono10     0.09992    0.03930   2.542  0.01789

(Dispersion parameter for quasibinomial family taken to be 83.37782)

    Null deviance: 2565.1  on 25  degrees of freedom
Residual deviance: 2023.3  on 24  degrees of freedom
AIC: NA

Number of Fisher Scoring iterations: 3</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1">mono.conf <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">confint</span>(mono.glm)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stderr">
<pre><code>Waiting for profiling to be done...</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1">mono.conf[<span class="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;">plogis</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>    2.5 %    97.5 % 
0.4189363 0.4840508 </code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1">mono.conf[<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;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>   2.5 %   97.5 % 
1.023329 1.193924 </code></pre>
</div>
</div>
<p>The correct interpretation of these estimates is as follows. If the model for the <img src="https://latex.codecogs.com/png.latex?%5Cpi_i">s is correct, we’d expect that in a country with the median percentage of monolinguals (i.e., about 19%), about <img src="https://latex.codecogs.com/png.latex?%5Ctextrm%7BLogistic%7D(-0.19509)%20%5Capprox%2045%5C%25"> of the respondents show accelerated ageing; 95% CI: <img src="https://latex.codecogs.com/png.latex?(42%5C%25,%2048%5C%25)">. A 10-percentage point difference in the percentage of monolinguals is associated with an odds ratio of about <img src="https://latex.codecogs.com/png.latex?%5Cexp(0.09992)%20%5Capprox%201.105">; 95% CI: <img src="https://latex.codecogs.com/png.latex?(1.02,%201.19)">.</p>
<p>Let’s now add per capita GDP to the equation. The per capita GDP variable was centred at its sample median of about 26,800 units per capita of whatever currency the data are expressed in.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1">by_country<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>c.mean_GDP <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> by_country<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>mean_GDP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(by_country<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>mean_GDP)</span>
<span id="cb25-2">gdp.glm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(n_accelerated, n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> n_accelerated) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> c.Mono10 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb25-3">                 c.mean_GDP,</span>
<span id="cb25-4">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> by_country,</span>
<span id="cb25-5">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasibinomial</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">link =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"logit"</span>))</span>
<span id="cb25-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(gdp.glm)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
Call:
glm(formula = cbind(n_accelerated, n - n_accelerated) ~ c.Mono10 + 
    c.mean_GDP, family = quasibinomial(link = "logit"), data = by_country)

Coefficients:
            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept) -0.11740    0.06898  -1.702   0.1023
c.Mono10     0.06063    0.03930   1.543   0.1365
c.mean_GDP  -0.07211    0.02998  -2.405   0.0246

(Dispersion parameter for quasibinomial family taken to be 69.35127)

    Null deviance: 2565.1  on 25  degrees of freedom
Residual deviance: 1613.8  on 23  degrees of freedom
AIC: NA

Number of Fisher Scoring iterations: 3</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1">gdp.conf <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">confint</span>(gdp.glm)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stderr">
<pre><code>Waiting for profiling to be done...</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1">gdp.conf[<span class="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;">plogis</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>    2.5 %    97.5 % 
0.4371134 0.5044157 </code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1">gdp.conf[<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;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>    2.5 %    97.5 % 
0.9838391 1.1477900 </code></pre>
</div>
</div>
<p>The model predicts a country with a per capita GDP of about 26.8k and 19% monolinguals to have about <img src="https://latex.codecogs.com/png.latex?%5Ctextrm%7BLogistic%7D(-0.1174)%20%5Capprox%2047%5C%25"> of respondents with accelerated ageing; 95% CI: <img src="https://latex.codecogs.com/png.latex?(43.7%5C%25,%2050.4%5C%25)">. Keeping per capita GDP constant, a 10-percentage point difference in monolingualism is associated with <img src="https://latex.codecogs.com/png.latex?%5Cexp(0.06063)%20%5Capprox%201.06"> times larger odds of accelerated ageing in the country, 95% CI: <img src="https://latex.codecogs.com/png.latex?(0.98,%201.15)">. Hence, once GDP is taken into account, the association between accelerated ageing and monolingualism is no longer significant.</p>
<p>Alternative model specifications are, of course, possible. Some, for instance generalised linear mixed models using individual-level BAGs but country-level predictors, lead to parameter estimates that can be fairly difficult to wrap one’s head round. Moreover, here I only looked at a single possible confounder (per capita GDP) as I had earlier identified a problem with it. This doesn’t mean that <em>only</em> this confounder should be considered.</p>
</section>
<section id="using-a-continuous-outcome" class="level3">
<h3 class="anchored" data-anchor-id="using-a-continuous-outcome">Using a continuous outcome</h3>
<p>Up till now, I used the <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BBAG%7D"> values that Amoruso et al.&nbsp;provided in the <code>data.csv</code> dataset. To recall (see Section&nbsp;2.3), these values are binary indicators of whether the respondent’s predicted age is older than their actual age, after correcting for the overprediction of younger ages and the underprediction of older ages. The predicted ages aren’t actually shared in any of the datasets: Amoruso et al.&nbsp;fit the models predicting age from biobehavioural factors in a couple of scripts, but these don’t contain the code for exporting the predicted ages. So I adapted their Jupyter notebooks in order to compute and export the predicted ages myself.</p>
<p>I stuck to Amoruso et al.’s approach, even though I’m pretty skeptical about it. Based on their Python code, I wrote my own Python script, <a href="compute_bag.py"><code>compute_bag.py</code></a>. In it, 26 models are trained using gradient boosting to predict respondents’ age from their biobehavioural factors, always leaving out a different country. I excluded the Slovak data seeing as these did not enter into Amoruso et al.’s analyses. For each model, a hyperparameter search was conducted. The ages for the out-of-fold respondents were then predicted, and their <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BGAP%7D"> scores computed accordingly. To correct for the overestimation of the ages of the youngest participants and the underestimation of those of the oldest participants, I fitted linear regression models just like in the original to the training data. The corrected <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BGAP%7D"> scores were computed as in the original. One additional difference to the original is that didn’t set all the random seeds to 42.</p>
<p>The predicted ages and <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BGAP%7D"> values are stored in <a href="data_predictions.csv"><code>data_predictions.csv</code></a>. Let’s first reassure ourselves that the model output is comparable to that reported by Amoruso et al. As the scatterplot in Figure&nbsp;6 shows, the prediction is far from good. Up till age 66, the respondents’ age is overestimated; from then onwards, their age is underestimated.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1">d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data_predictions.csv"</span>)</span>
<span id="cb33-2"></span>
<span id="cb33-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(d,</span>
<span id="cb33-4">       <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> Age, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> predicted_age)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-5">  <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="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> Age), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">outlier.shape =</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;">varwidth =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_abline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">slope =</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;">intercept =</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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"solid"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-7">  <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;">"gam"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">s</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bs =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"True age (years)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Predicted age (years)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb33-11">    <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;">"Predicted vs. true age"</span></span>
<span id="cb33-12">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-predicted-ages" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-predicted-ages-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-12-15-multilingualism-accelerated-ageing/index_files/figure-html/fig-predicted-ages-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-predicted-ages-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6: The predicted ages are out-of-fold predictions based on gradient boosting. The red lines shows the identity; the blue line is a scatterplot smoother highlighting the mean trend.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The root mean squared error for the age prediction is 8.71 years, which is similar to the number reported by Amoruso et al.&nbsp; (8.65 in the leave-one-country-out cross-validation). The mean absolute error is 7.15 years, again similar to the number reported in the article (7.09). The mean directional error is about 0.03 years (an average overestimation of about 12 days); which is similar to the number reported in the article (0.03).</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>((d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>predicted_age <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>Age)<span 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></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 8.712974</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>predicted_age <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>Age))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 7.150154</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>predicted_age) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Age)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.03412678</code></pre>
</div>
</div>
<p>These differences can be explained by the fact that I excluded Slovakia from the data when fitting the models; Amoruso et al.&nbsp;didn’t. Further, Amoruso et al.&nbsp;set all their random seeds to 42; I decided to leave them unspecified by default.</p>
<p>Let’s now take a look at the corrected <img src="https://latex.codecogs.com/png.latex?%5Ctexttt%7BGAP%7D"> values, Figure&nbsp;7. Note that a slight nonlinear trend remains.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(d,</span>
<span id="cb40-2">       <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> Age, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> GAP_corrected)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb40-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</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;">group =</span> Age), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">outlier.shape =</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;">varwidth =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb40-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_smooth</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gam"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formula =</span> y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">s</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bs =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tp"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb40-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"True age (years)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb40-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Corrected GAP (years)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb40-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb40-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;">"Corrected GAP vs. true age"</span></span>
<span id="cb40-9">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-gap" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-gap-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-12-15-multilingualism-accelerated-ageing/index_files/figure-html/fig-gap-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-gap-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;7: The GAP values after correction for linear under- and overestimation.
</figcaption>
</figure>
</div>
</div>
</div>
<p>While the datasets <code>data.csv</code> and <code>data_predictions.csv</code> do specify the respondents’ countries, they don’t specify which year the data was collected in. For this reason, I calculated mean monolingualism and mean GDP per capita values per country and added these to the dataset.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb41" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb41-1">country_cohort <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"country_cohort.csv"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb41-2">  <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;">GDP =</span> (GDP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> Pop) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb41-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Country) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb41-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb41-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_Mono =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(Mono, n),</span>
<span id="cb41-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_GDP =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(GDP, n),</span>
<span id="cb41-7">    <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="cb41-8">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb41-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb41-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c.Mono10 =</span> (mean_Mono <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(mean_Mono <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>),</span>
<span id="cb41-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">c.GDP =</span> mean_GDP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(mean_GDP)</span>
<span id="cb41-12">  )</span>
<span id="cb41-13">d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb41-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(country_cohort, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join_by</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"country"</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;">"Country"</span>))</span></code></pre></div></div>
</details>
</div>
<p>I’ll go through a similar analysis as before but this time without discretising the <code>GAP_corrected</code> variable. Figure&nbsp;8 confirms that there is some association between the percentage of monolinguals in a country and the average corrected GAP value in this country.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb42" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1">by_country <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb42-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(country, mean_Mono, mean_GDP, c.Mono10, c.GDP) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb42-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb42-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb42-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_GAP =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(GAP),</span>
<span id="cb42-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_corrected_GAP =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(GAP_corrected),</span>
<span id="cb42-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_Age =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(Age),</span>
<span id="cb42-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_predicted_Age =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(predicted_age),</span>
<span id="cb42-9">    <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="cb42-10">  )</span>
<span id="cb42-11"></span>
<span id="cb42-12"></span>
<span id="cb42-13">by_country <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb42-14">  <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> mean_Mono, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> mean_corrected_GAP)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb42-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</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;">label =</span> country), <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="cb42-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</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;">65</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb42-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percentage of monolinguals"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb42-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mean corrected GAP (years)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mono-gap" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mono-gap-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-12-15-multilingualism-accelerated-ageing/index_files/figure-html/fig-mono-gap-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mono-gap-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;8: The percentage of monolinguals shown is the weighted average of the percentages of monolinguals in the country at the different waves of data collection.
</figcaption>
</figure>
</div>
</div>
</div>
<p>As Figure&nbsp;9 shows, per capita GDP is likewise associated with the average GAP value per country.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb43" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb43-1">by_country <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb43-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> mean_GDP, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> mean_corrected_GAP)) <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_text</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;">label =</span> country), <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-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</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;">12.5</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;">xlab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Per capita GDP"</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;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mean corrected GAP (years)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-gdp-gap" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-gdp-gap-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-12-15-multilingualism-accelerated-ageing/index_files/figure-html/fig-gdp-gap-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-gdp-gap-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;9: The GDP per capita is the weighted average of the country’s GDP per capita at the different waves of data collection.
</figcaption>
</figure>
</div>
</div>
</div>
<p>We don’t need to worry about logistic models and odds ratios this time. A simple OLS regression model at the country level is all we need.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb44" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb44-1">mono.lm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(mean_corrected_GAP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> c.Mono10, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> by_country)</span>
<span id="cb44-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(mono.lm)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
Call:
lm(formula = mean_corrected_GAP ~ c.Mono10, data = by_country)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.5164 -0.5098 -0.1333  0.3304  2.4568 

Coefficients:
            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept) -0.22313    0.17936  -1.244  0.22549
c.Mono10     0.36317    0.09901   3.668  0.00121

Residual standard error: 0.8815 on 24 degrees of freedom
Multiple R-squared:  0.3592,    Adjusted R-squared:  0.3325 
F-statistic: 13.46 on 1 and 24 DF,  p-value: 0.001213</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb46" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">confint</span>(mono.lm) <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;">365.25</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>                2.5 %    97.5 %
(Intercept) -216.7067  53.70753
c.Mono10      58.0121 207.28204</code></pre>
</div>
</div>
<p>This country predicts country with 19% monolinguals to have an average corrected GAP value of about <img src="https://latex.codecogs.com/png.latex?-0.22"> years (about <img src="https://latex.codecogs.com/png.latex?-80"> days), 95% CI: <img src="https://latex.codecogs.com/png.latex?(-217,%2054)"> days. A 10-percentage point difference in the extent of monolingualism is associated with a change in the average corrected GAP value of about <img src="https://latex.codecogs.com/png.latex?0.36"> years (about 133 days), 95% CI: <img src="https://latex.codecogs.com/png.latex?(58,%20207)"> days.</p>
<p>We can also control for per capita GDP:</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb48" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb48-1">gdp.lm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(mean_corrected_GAP <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> c.Mono10 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> c.GDP, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> by_country)</span>
<span id="cb48-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(gdp.lm)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
Call:
lm(formula = mean_corrected_GAP ~ c.Mono10 + c.GDP, data = by_country)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.40401 -0.37359 -0.06492  0.19045  2.43794 

Coefficients:
            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept) -0.08645    0.19926  -0.434   0.6684
c.Mono10     0.28744    0.11009   2.611   0.0156
c.GDP       -0.11308    0.07820  -1.446   0.1617

Residual standard error: 0.8621 on 23 degrees of freedom
Multiple R-squared:  0.4126,    Adjusted R-squared:  0.3616 
F-statistic: 8.079 on 2 and 23 DF,  p-value: 0.0022</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb50" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb50-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">confint</span>(gdp.lm) <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;">365.25</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>                 2.5 %    97.5 %
(Intercept) -182.13353 118.97890
c.Mono10      21.80848 188.16438
c.GDP       -100.38508  17.78279</code></pre>
</div>
</div>
<p>So, this model predicts that a country with a per capita GDP of about 26.8k and 19% monolinguals to have an average corrected GAP of about <img src="https://latex.codecogs.com/png.latex?-0.09"> years (about <img src="https://latex.codecogs.com/png.latex?-32"> days), 95% CI: <img src="https://latex.codecogs.com/png.latex?(-182,%20119)"> days). Keeping per capita GDP constant, it predicts a 10-percentage point change in the extent of monolingualism to be associated with a change in the average corrected GAP of about <img src="https://latex.codecogs.com/png.latex?0.287"> years (some 105 days), 95% CI: <img src="https://latex.codecogs.com/png.latex?(22,%20188)"> days.</p>
<p>Again, I only took into consideration per capita GDP because Amoruso et al.&nbsp;didn’t. This should in no way be taken to mean that I think that <em>only</em> per capita GDP should be taken into account as a possible confounder.</p>
</section>
</section>
<section id="now-what" class="level2">
<h2 class="anchored" data-anchor-id="now-what">Now what?</h2>
<p>Suffice it to say that I think the authors ought to substantially revise their article, both in terms of how the analyses are conducted and interpreted and in terms of how the overall method is described. The analyses that I carried out using per capita GDP (as opposed to overall GDP) as a control variable are a start—not a suggestion of what the final model should look like. Further, I’ve only looked at the cross-sectional analyses as I think my comments on these already ought to prompt readers to take the entire study with a grain of salt. This doesn’t mean that I think that the longitudinal analyses that are also reported in the article are trustworthy—I’ve literally not looked at them. Finally, we’ve taken the authors’ method for quantifying accelerated ageing as-is, but I am somewhat skeptical of it.</p>
<p><strong>Update 2026/01/09:</strong> A slightly edited version of this blog post is now available as a preprint from <a href="https://osf.io/preprints/psyarxiv/rmnv9_v1">PsyArxiv Preprints</a>. The main change is that I log-transformed the per-capita GDP data for the preprint.</p>
</section>
<section id="software-versions" class="level2">
<h2 class="anchored" data-anchor-id="software-versions">Software versions</h2>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb52" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb52-1">devtools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">session_info</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"attached"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.1 (2025-06-13)
 os       Ubuntu 25.10
 system   x86_64, linux-gnu
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Zurich
 date     2026-01-09
 pandoc   3.8 @ /home/jan/miniconda3/bin/ (via rmarkdown)
 quarto   1.8.25 @ /usr/local/bin/quarto

─ Packages ───────────────────────────────────────────────────────────────────
 package   * version date (UTC) lib source
 dplyr     * 1.1.4   2023-11-17 [1] CRAN (R 4.5.1)
 DT        * 0.34.0  2025-09-02 [1] CRAN (R 4.5.1)
 forcats   * 1.0.1   2025-09-25 [1] CRAN (R 4.5.1)
 ggplot2   * 4.0.0   2025-09-11 [1] CRAN (R 4.5.1)
 lubridate * 1.9.4   2024-12-08 [1] CRAN (R 4.5.1)
 purrr     * 1.1.0   2025-07-10 [1] CRAN (R 4.5.1)
 readr     * 2.1.5   2024-01-10 [1] CRAN (R 4.5.1)
 stringr   * 1.5.2   2025-09-08 [1] CRAN (R 4.5.1)
 tibble    * 3.3.0   2025-06-08 [1] CRAN (R 4.5.1)
 tidyr     * 1.3.1   2024-01-24 [1] CRAN (R 4.5.1)
 tidyverse * 2.0.0   2023-02-22 [1] CRAN (R 4.5.1)

 [1] /home/jan/R/x86_64-pc-linux-gnu-library/4.5
 [2] /usr/local/lib/R/site-library
 [3] /usr/lib/R/site-library
 [4] /usr/lib/R/library
 * ── Packages attached to the search path.

──────────────────────────────────────────────────────────────────────────────</code></pre>
</div>
</div>


</section>

 ]]></description>
  <category>correlational studies</category>
  <category>R</category>
  <guid>https://janhove.github.io/posts/2025-12-15-multilingualism-accelerated-ageing/</guid>
  <pubDate>Mon, 15 Dec 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>The population model and the randomisation model of statistical inference</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2025-11-09-population-randomisation/</link>
  <description><![CDATA[ 




<p>Much of statistical practice—and teaching—relies on an assumption that is demonstrably false: the fiction that the data were sampled randomly from some population. Now, in practice, this fiction turns out to be quite useful. But I think that it’s important to appreciate that it is a fiction and that it’s possible to do statistics without subscribing to it.</p>
<p>Let’s first take a look at the ubiquitous Student’s <em>t</em>-test for independent samples. This test is used to check if the difference between the means of two lists of numbers, <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20x%20=%20(x_1,%20%5Cdots,%20x_k)"> and <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20y%20=%20(y_1,%20%5Cdots,%20y_m)">, could plausibly be explained by chance. It is based on the following assumptions:</p>
<ol type="1">
<li>The observations <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20x"> and <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20y"> constitute simple random samples from some populations <img src="https://latex.codecogs.com/png.latex?P_1"> and <img src="https://latex.codecogs.com/png.latex?P_2">, respectively.</li>
<li>Population <img src="https://latex.codecogs.com/png.latex?P_1"> follows a normal distribution with mean <img src="https://latex.codecogs.com/png.latex?%5Cmu_1"> and variance <img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2">.</li>
<li>Population <img src="https://latex.codecogs.com/png.latex?P_2"> follows a normal distribution with mean <img src="https://latex.codecogs.com/png.latex?%5Cmu_2%20=%20%5Cmu_1%20+%20%5Cdelta"> and variance <img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2">.</li>
</ol>
<p>If these assumptions are well-founded, the Student’s <em>t</em>-test provides an exact test for the null hypothesis that <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20=%20%5Cdelta_0"> for some specified number <img src="https://latex.codecogs.com/png.latex?%5Cdelta_0">, where typically <img src="https://latex.codecogs.com/png.latex?%5Cdelta_0%20=%200">. (In this context, `exact’ means that the probability that the test yields a <em>p</em>-value no larger than <img src="https://latex.codecogs.com/png.latex?%5Calpha"> if the null hypothesis is true is itself no larger than <img src="https://latex.codecogs.com/png.latex?%5Calpha"> for <em>any</em> <img src="https://latex.codecogs.com/png.latex?%5Calpha%20%5Cin%20(0,%201)">.)</p>
<p>That’s a big <em>if</em>.</p>
<p>Thanks to the central limit theorem, though, the normality assumption isn’t <em>too</em> crucial: for “large enough” samples from non-normal distributions, the <em>t</em>-test behaves “more or less” as it does for normal distributions, at least under fairly general conditions such as that the distributions that are sampled have finite variance. And except for the smallest of samples, the equality of variances assumption can be dealt with by using Welch’ <em>t</em>-test instead of Student’s. I don’t want to go into what “large enough” and “more or less” mean in this context; interested readers may want to look up what “convergence in distribution” means.</p>
<p>But what strikes me as more fundamental than the shape of the populations <img src="https://latex.codecogs.com/png.latex?P_1"> and <img src="https://latex.codecogs.com/png.latex?P_2"> are the questions <em>Who’s drawing random samples from a population?</em> and <em>What’s the population, anyway?</em></p>
<p>Sure, it’s easy to set up computer simulations in which the data are sampled from some population. But at the coalface, most research is done with volunteers (or students needing credits) who’ve undergone a round of screening. And even if there is some population that these participants can be considered to be a sample from, their recruitment didn’t involve any mathematically well-defined sampling procedure. This <strong>population model</strong> of statistical inference, which treats data as random samples from some population (normal or other), is, then, mostly based on a fiction.</p>
<p>The population model of statistical inference contrasts with the <strong>randomisation model</strong>. In the population model, the randomness in the results is assumed to be caused by random sampling; in the randomisation model, it is assumed to be caused by randomly assigning the units (e.g., the participants) in the study to different conditions. Whereas random sampling is exceedingly rare in the social sciences, random assignment is quite common. And if random assignment was used, the randomisation model results in valid hypothesis tests that do not make any unverifiable distributional assumptions.</p>
<p>In what follows, I’ll illustrate the randomisation model in the simplest of settings.</p>
<section id="a-two-group-comparison" class="level2">
<h2 class="anchored" data-anchor-id="a-two-group-comparison">A two-group comparison</h2>
<p>Consider a two-group study in which <img src="https://latex.codecogs.com/png.latex?k%20+%20%5Cell%20=%20m"> participants are randomly assigned to one of two groups such that <img src="https://latex.codecogs.com/png.latex?k"> are assigned to the first group and <img src="https://latex.codecogs.com/png.latex?%5Cell"> to the second group. The participants in the first group engage in some activity or are subjected to some treatment, and those in the second group engage in another activity or are subjected to another treatment. For each participant <img src="https://latex.codecogs.com/png.latex?i%20=%201,%20%5Cdots,%20m">, we observe a numerical outcome <img src="https://latex.codecogs.com/png.latex?Y_i">, and the question of interest is whether the two treatments differentially affected the outcome.</p>
<p>To make the following a bit more concrete, I’ll start out by the fictitious data summarised in Table&nbsp;1 and shown in Figure&nbsp;1. Fictitious data are a bit boring, so I’ll apply the techniques discussed to a real but somewhat more complicated example later on.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">suppressPackageStartupMessages</span>(<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;">theme_set</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>())</span>
<span id="cb1-3"></span>
<span id="cb1-4">d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">structure</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;">Group =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb1-5"><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Outcome =</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;">7</span>,</span>
<span id="cb1-6"><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">9.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">8.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">7.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">7.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">8.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">7.5</span>,</span>
<span id="cb1-7"><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">9.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">7.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">9.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">8.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">8.5</span>)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">class =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data.frame"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,</span>
<span id="cb1-8"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">27</span>L))</span>
<span id="cb1-9"></span>
<span id="cb1-10">d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(Group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb1-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb1-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Mean =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(Outcome) <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;">round</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb1-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Median =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(Outcome),</span>
<span id="cb1-16">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Standard deviation</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(Outcome) <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;">round</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-17">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-18">  knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>()</span></code></pre></div></div>
</details>
<div id="tbl-summary" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-summary-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1: Results summary of a fictitious experiment.
</figcaption>
<div aria-describedby="tbl-summary-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<table class="cell caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: right;">Group</th>
<th style="text-align: right;">n</th>
<th style="text-align: right;">Mean</th>
<th style="text-align: right;">Median</th>
<th style="text-align: right;">Standard deviation</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">0</td>
<td style="text-align: right;">12</td>
<td style="text-align: right;">8.25</td>
<td style="text-align: right;">8</td>
<td style="text-align: right;">0.78</td>
</tr>
<tr class="even">
<td style="text-align: right;">1</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">8.87</td>
<td style="text-align: right;">9</td>
<td style="text-align: right;">1.04</td>
</tr>
</tbody>
</table>
</div>
</div>
</figure>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb2-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Group), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> Outcome)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-3">  <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;">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="cb2-4">  <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;">1</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_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;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Condition"</span>,</span>
<span id="cb2-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0"</span>, <span class="st" style="color: #20794D;
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;">"0"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>))</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-boxplot" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-boxplot-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-11-09-population-randomisation/index_files/figure-html/fig-boxplot-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-boxplot-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Data for a fictitious randomised experiment with two groups.
</figcaption>
</figure>
</div>
</div>
</div>
<section id="the-randomisation-model-theory" class="level3">
<h3 class="anchored" data-anchor-id="the-randomisation-model-theory">The randomisation model: Theory</h3>
<p>For each participant <img src="https://latex.codecogs.com/png.latex?i%20=%201,%20%5Cdots,%20m">, there exist two potential outcomes <img src="https://latex.codecogs.com/png.latex?y_i(0)"> and <img src="https://latex.codecogs.com/png.latex?y_i(1)">, only one of which is observed:</p>
<ul>
<li>either <img src="https://latex.codecogs.com/png.latex?y_i(0)"> if the participant is assigned to the first condition;</li>
<li>or <img src="https://latex.codecogs.com/png.latex?y_i(1)"> if the participant is assigned to the second condition.</li>
</ul>
<p>In the randomisation model, these potential outcomes are treated as fixed, though possibly unknown, quantities, and not as random variables having some distribution. What <em>is</em> random is which of these two quantities we end up observing. Specifically, let <img src="https://latex.codecogs.com/png.latex?B_i"> be the random variable that indicates which condition the <img src="https://latex.codecogs.com/png.latex?i">-th participant is assigned to. Then <img src="https://latex.codecogs.com/png.latex?B_i%20=%200"> if the participant is assigned to the first condition and <img src="https://latex.codecogs.com/png.latex?B_i%20=%201"> if the participant is assigned to the second condition. Then the observed outcome for the <img src="https://latex.codecogs.com/png.latex?i">-th participant is <img src="https://latex.codecogs.com/png.latex?Y_i%20=%20y_i(B_i)%20=%20%5Cbegin%7Bcases%7Dy_i(0)%20&amp;%5Ctextrm%7Bif%20%7D%20B_i%20=%200,%5C%5C%20y_i(1)%20&amp;%5Ctextrm%7Bif%20%7D%20B_i%20=%201.%5Cend%7Bcases%7D"></p>
<p>The researchers control the randomisation, so they <em>know</em> what the distribution of the assignment vector <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20B%20:=%20(B_1,%20%5Cdots,%20B_m)"> is. In the present example, the assignment vector was picked randomly from the set of vectors with length <img src="https://latex.codecogs.com/png.latex?12%20+%2015%20=%2027"> that contain exactly <img src="https://latex.codecogs.com/png.latex?12"> zeroes and <img src="https://latex.codecogs.com/png.latex?15"> ones, with each such vector having the same probability of being picked. Formally, <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20B%20%5Csim%20%5Ctextrm%7BUniform%7D(%5Cmathcal%7BB%7D_%7B12,%2015%7D),"> where <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BB%7D_%7Bk,%20%5Cell%7D%20:=%20%5C%7B%5Cboldsymbol%20b%20%5Cin%20%5C%7B0,%201%5C%7D%5E%7Bk%20+%20%5Cell%7D%20:%20%5Csum_%7Bi=1%7D%5E%7Bk%20+%20%5Cell%7D%20b_i%20=%20%5Cell%5C%7D."> According to the so-called <strong>sharp null hypothesis</strong>, there is no differential treatment effect whatsoever. That is, <img src="https://latex.codecogs.com/png.latex?H_0:%20y_i(1)%20=%20y_i(0)%20%5Ctextrm%7B%20for%20%7D%20%20i%20=%201,%20%5Cdots,%20m."> Under such a sharp null hypothesis, the values for <img src="https://latex.codecogs.com/png.latex?y_i(0)"> and <img src="https://latex.codecogs.com/png.latex?y_i(1)"> can immediately be reconstructed from the observed outcomes: <img src="https://latex.codecogs.com/png.latex?y_i(0)%20=%20y_i(1)%20=%20Y_i"> for <img src="https://latex.codecogs.com/png.latex?i%20=%201,%20%5Cdots,%20m">.</p>
<p>More generally, for any number <img src="https://latex.codecogs.com/png.latex?%5Cdelta">, we could set up the sharp null hypothesis that the second treatment boosts (or would have boosted) the outcome by <img src="https://latex.codecogs.com/png.latex?%5Cdelta"> for all participants: <img src="https://latex.codecogs.com/png.latex?H_0(%5Cdelta):%20y_i(1)%20=%20y_i(0)%20+%20%5Cdelta%20%5Ctextrm%7B%20for%20%7D%20%20i%20=%201,%20%5Cdots,%20m."> Under <img src="https://latex.codecogs.com/png.latex?H_0(%5Cdelta)">, too, we can straightforwardly reconstruct the <img src="https://latex.codecogs.com/png.latex?y_i"> values for all participants: <img src="https://latex.codecogs.com/png.latex?y_i(0)%20=%20Y_i%20-%20B_i%5Cdelta"> and <img src="https://latex.codecogs.com/png.latex?y_i(1)%20=%20Y_i%20+%20(1-B_i)%5Cdelta"> for <img src="https://latex.codecogs.com/png.latex?i%20=%201,%20%5Cdots,%20m">.</p>
<p>An exact <em>p</em>-value testing such sharp null hypotheses can now be computed as follows without needing to assume that the <img src="https://latex.codecogs.com/png.latex?y_i(0)"> and <img src="https://latex.codecogs.com/png.latex?y_i(1)"> values are randomly sampled from some population.</p>
<ol type="1">
<li><p>Decide on a relevant <strong>test statistic</strong> <img src="https://latex.codecogs.com/png.latex?T_%7B%5Cdelta%7D(%5Cboldsymbol%20y,%20%5Cboldsymbol%20b)">. The <em>p</em>-value that eventually results will be valid regardless of the test statistic chosen. But ideally, a test statistic is chosen that tends to be small (or close to zero) under the null hypothesis but large (or farther from zero) if the null hypothesis isn’t true. For the current setting, you could compute, for instance, the difference between the group means, or the difference between the group medians, or the probability that a randomly chosen participant who was assigned to the second condition has a higher score than a randomly chosen participant from the first condition.</p></li>
<li><p>Compute the test statistic for the data at hand: <img src="https://latex.codecogs.com/png.latex?T_%7B%5Cdelta,%20%5Ctextrm%7Bobs%7D%7D%20:=%20T_%7B%5Cdelta%7D(%5Cboldsymbol%20Y,%20%5Cboldsymbol%20B)">.</p></li>
<li><p>For a left-sided <em>p</em>-value, compute the probability that <img src="https://latex.codecogs.com/png.latex?T_%7B%5Cdelta%7D(%5Cboldsymbol%20Y,%20%5Cboldsymbol%20%7B%5Ctilde%20B%7D)%20%5Cleq%20T_%7B%5Cdelta,%20%5Ctextrm%7Bobs%7D%7D">, where <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20%7B%5Ctilde%20B%7D"> has the same distribution as <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20B"> (here: <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20%7B%5Ctilde%20B%7D%20%5Csim%20%5Ctextrm%7BUniform%7D(%5Cmathcal%7BB%7D_%7Bk,%20%5Cell%7D)">). This can be computed by going through all the possible assignment vectors <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20b"> and counting how often <img src="https://latex.codecogs.com/png.latex?T_%7B%5Cdelta%7D(%5Cboldsymbol%20Y,%20%5Cboldsymbol%20b)%20%5Cleq%20T_%7B%5Cdelta,%20%5Ctextrm%7Bobs%7D%7D">. For a right-sided <em>p</em>-value, instead compute the probability that <img src="https://latex.codecogs.com/png.latex?T_%7B%5Cdelta%7D(%5Cboldsymbol%20Y,%20%5Cboldsymbol%20%7B%5Ctilde%20B%7D)%20%5Cgeq%20T_%7B%5Cdelta,%20%5Ctextrm%7Bobs%7D%7D">. A two-sided <em>p</em>-value can be computed as twice the smaller of the left-side and the right-sided <em>p</em>-value.</p></li>
</ol>
<p>Step 3 poses a practical challenge: the set of possible assignment vectors is usually too large to handle. In our case, the set <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BB%7D_%7Bk,%20%5Cell%7D"> contains <img src="https://latex.codecogs.com/png.latex?%7B%7Bk%20+%20%5Cell%7D%5Cchoose%20%7Bk%7D%7D%20=%20%5Cfrac%7B(k%20+%20%5Cell)!%7D%7Bk!%5Cell!%7D"> elements. Even for fairly small <img src="https://latex.codecogs.com/png.latex?k,%20%5Cell">, this are too many vectors to iterate over. For instance, for <img src="https://latex.codecogs.com/png.latex?k%20=%2012,%20%5Cell%20=%2015">, we obtain 17,383,860 possible assignment vectors; for <img src="https://latex.codecogs.com/png.latex?k%20=%20%5Cell%20=%2020">, there are 137,846,528,820 such vectors.</p>
<p>What we can do instead is sample <img src="https://latex.codecogs.com/png.latex?M"> assignment vectors at random from the distribution of <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20B"> and count how often the resulting test statistic is no larger than <img src="https://latex.codecogs.com/png.latex?T_%7B%5Cdelta,%20%5Ctextrm%7Bobs%7D%7D"> (for a left-sided <em>p</em>-value) or no smaller than <img src="https://latex.codecogs.com/png.latex?T_%7B%5Cdelta,%20%5Ctextrm%7Bobs%7D%7D"> (for a right-sided <em>p</em>-value). This number plus one and then divided by <img src="https://latex.codecogs.com/png.latex?M+1"> is an exact left- or right-sided <em>p</em>-value. A two-sided <em>p</em>-value can then again be calculated as twice the smaller of these two one-sided <em>p</em>-values.</p>
</section>
<section id="the-randomisation-model-practice" class="level3">
<h3 class="anchored" data-anchor-id="the-randomisation-model-practice">The randomisation model: Practice</h3>
<p>Let’s put this theory into practice.</p>
<p>First, we need to decide on a test statistic. In the code snippet below, I define five such statistics, mainly to illustrate the flexibility of the approach.</p>
<ol type="1">
<li>The difference between the means in the 0 condition and in the 1 condition.</li>
<li>The difference between the medians in the 0 condition and in the 1 condition.</li>
<li>The difference between the <a href="https://en.wikipedia.org/wiki/Interquartile_mean">midmeans</a> in the 0 condition and in the 1 condition.</li>
<li>The rank sum of the observations in the 1 condition. To obtain this statistic, compute the ranks of all observations, and then sum the ranks of those in the 1 condition.</li>
<li>The probability of superiority: If you pick a random observation in the 1 condition and compare it to a randomly chosen observation the 0 condition, what’s the probability that the 1 observation is higher than the 0 observation? Both the rank sum and the probability of superiority are closely connected to the Wilcoxon–Mann–Whitney tests.</li>
</ol>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># All functions assume that one of the groups is coded as 0 and the other as 1.</span></span>
<span id="cb3-2">mean_diff <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, group) {</span>
<span id="cb3-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x[group <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x[group <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])</span>
<span id="cb3-4">}</span>
<span id="cb3-5">median_diff <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, group) {</span>
<span id="cb3-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(x[group <span 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;">median</span>(x[group <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])</span>
<span id="cb3-7">}</span>
<span id="cb3-8">midmean_diff <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, group) {</span>
<span id="cb3-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x[group <span 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="at" style="color: #657422;
background-color: null;
font-style: inherit;">trim =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(x[group <span 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="at" style="color: #657422;
background-color: null;
font-style: inherit;">trim =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>)</span>
<span id="cb3-10">}</span>
<span id="cb3-11">ranksum <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, group) {</span>
<span id="cb3-12">  ranks <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rank</span>(x)</span>
<span id="cb3-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(ranks[group <span 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="cb3-14">}</span>
<span id="cb3-15">probsup <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x, group) {</span>
<span id="cb3-16">  n0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(group <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb3-17">  n1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(group <span 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="cb3-18">  (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ranksum</span>(x, group) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> n1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(n1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (n0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> n1)</span>
<span id="cb3-19">}</span></code></pre></div></div>
</details>
</div>
<p>For the present data, the five observed test statistics are the following:</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">d <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;">summarise</span>(</span>
<span id="cb4-3">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Mean difference</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean_diff</span>(Outcome, Group),</span>
<span id="cb4-4">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Median difference</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median_diff</span>(Outcome, Group),</span>
<span id="cb4-5">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Midmean difference</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">midmean_diff</span>(Outcome, Group),</span>
<span id="cb4-6">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Rank sum</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ranksum</span>(Outcome, Group),</span>
<span id="cb4-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Probability of superiority</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">probsup</span>(Outcome, Group)</span>
<span id="cb4-8">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb4-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">everything</span>(), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Test statistic"</span>,</span>
<span id="cb4-10">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Value"</span>) <span 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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Value =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(Value, <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;">|&gt;</span> </span>
<span id="cb4-12">  knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>()</span></code></pre></div></div>
</details>
<div id="tbl-teststats" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-teststats-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;2: Observed test statistics.
</figcaption>
<div aria-describedby="tbl-teststats-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<table class="cell caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: left;">Test statistic</th>
<th style="text-align: right;">Value</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Mean difference</td>
<td style="text-align: right;">0.62</td>
</tr>
<tr class="even">
<td style="text-align: left;">Median difference</td>
<td style="text-align: right;">1.00</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Midmean difference</td>
<td style="text-align: right;">0.56</td>
</tr>
<tr class="even">
<td style="text-align: left;">Rank sum</td>
<td style="text-align: right;">240.00</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Probability of superiority</td>
<td style="text-align: right;">0.67</td>
</tr>
</tbody>
</table>
</div>
</div>
</figure>
</div>
</div>
<p>The next code snippet defines the function <code>randomisation_test()</code>, which computes a left-sided, right-sided or two-sided (= default) <em>p</em>-value by applying a randomisation test for the test statistic of choice, as explained above. By default, 19,999 new assignment vectors are randomly generated under the assumption that <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20B%20%5Csim%20%5Ctextrm%7BUniform%7D(%7B%5Cmathcal%7BB%7D_%7Bk,%20%5Cell%7D%7D)">.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">randomisation_test <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(</span>
<span id="cb5-2">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Randomisation test of sharp null in two-group comparison.</span></span>
<span id="cb5-3">    x,           <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># outcome</span></span>
<span id="cb5-4">    group,       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># grouping variable</span></span>
<span id="cb5-5">    fun,         <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># function for computing test statistic from x and group</span></span>
<span id="cb5-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">delta =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># delta for sharp null hypothesis</span></span>
<span id="cb5-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"two_sided"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># two-sided, left-sided or right-sided p-value?</span></span>
<span id="cb5-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">M =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">19999</span>,   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># number of new randomisations generated</span></span>
<span id="cb5-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plot histogram of test statistic under H0?</span></span>
<span id="cb5-10">    ...          <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># parameters passed to histogram</span></span>
<span id="cb5-11">) {</span>
<span id="cb5-12">  test_stat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fun</span>(x, group)</span>
<span id="cb5-13">  x[group <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> x[group <span 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> delta</span>
<span id="cb5-14">  test_stat_H0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">replicate</span>(M, {</span>
<span id="cb5-15">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fun</span>(x, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(group))</span>
<span id="cb5-16">  })</span>
<span id="cb5-17">  test_stat_H0 <span class="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>(test_stat, test_stat_H0)</span>
<span id="cb5-18">  </span>
<span id="cb5-19">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (plot) {</span>
<span id="cb5-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">hist</span>(test_stat_H0, ...)</span>
<span id="cb5-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v =</span> test_stat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb5-22">  }</span>
<span id="cb5-23">  </span>
<span id="cb5-24">  p_left <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(test_stat_H0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> test_stat)</span>
<span id="cb5-25">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(alternative, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"l"</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(p_left)</span>
<span id="cb5-26">  </span>
<span id="cb5-27">  p_right <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(test_stat_H0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> test_stat)</span>
<span id="cb5-28">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">substr</span>(alternative, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span>) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(p_right)</span>
<span id="cb5-29">  </span>
<span id="cb5-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(p_left, p_right), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb5-31">}</span></code></pre></div></div>
</details>
</div>
<p>Figure&nbsp;2 shows the distribution of the mean difference under the sharp null hypothesis for <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20=%200">. The vertical line highlights the observed mean difference. The resulting two-sided <em>p</em>-value is about 0.12.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="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;">2025-11-07</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># the day I wrote this</span></span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randomisation_test</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Outcome, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Group, mean_diff, </span>
<span id="cb6-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</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;">xlab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mean difference"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution under H0"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.1213</code></pre>
</div>
<div class="cell-output-display">
<div id="fig-meandiff" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-meandiff-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-11-09-population-randomisation/index_files/figure-html/fig-meandiff-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-meandiff-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: The distribution of the mean difference under the sharp null hypothesis for <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20=%200">.
</figcaption>
</figure>
</div>
</div>
</div>
<p>While the distribution of the mean difference under <img src="https://latex.codecogs.com/png.latex?H_0"> looks roughly bell-shaped but with some gaps, the distribution of the median difference shown in Figure&nbsp;3 looks much weirder. But no distributional assumptions are required for computing the randomisation-based <em>p</em>-value, and so the resulting <em>p</em>-value of 0.18 is also a valid, exact <em>p</em>-value testing <img src="https://latex.codecogs.com/png.latex?H_0">.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randomisation_test</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Outcome, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Group, median_diff, </span>
<span id="cb8-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</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;">xlab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Median difference"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution under H0"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.1801</code></pre>
</div>
<div class="cell-output-display">
<div id="fig-mediandiff" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mediandiff-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-11-09-population-randomisation/index_files/figure-html/fig-mediandiff-1.svg" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mediandiff-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: The distribution of the median difference under the sharp null hypothesis for <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20=%200">.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Similarly, we can compute exact <em>p</em>-values for the other test statistics, or indeed for any statistic you can come up with. For the midmean, we obtain <img src="https://latex.codecogs.com/png.latex?p%20=%200.20">; for the rank sum and the probability of superiority <img src="https://latex.codecogs.com/png.latex?p%20=%200.14">.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randomisation_test</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Outcome, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Group, midmean_diff, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.197</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randomisation_test</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Outcome, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Group, ranksum, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.1403</code></pre>
</div>
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randomisation_test</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Outcome, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Group, probsup, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.1426</code></pre>
</div>
</div>
<p>All of these <em>p</em>-values are exact for tests of the sharp null hypothesis. In fact, any test statistic can be used, and the resulting inference will still be exact as long as the randomisation procedure is correctly mirrored in the computation. Computing tests for several test statistics is a bad idea, however, as you’re just creating a multiple-comparisons problem. At present, I’m not aware of general rules of thumb for choosing among different test statistics, beyond the simple advice that the test statistic should be sensitive to the kinds of departures from the null hypothesis that are scientifically relevant. But I’ll look into it.</p>
<p>What may not sit so well with some readers is that repeated runs of the same randomisation test won’t produce identical results. This is due to the randomness involved in choosing the assignment vectors. For instance, another run of the randomisation test for the mean difference yields a slightly different result from the first one.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randomisation_test</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Outcome, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Group, mean_diff, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.1245</code></pre>
</div>
</div>
<p>Increasing <img src="https://latex.codecogs.com/png.latex?M"> decreases this variability, but crucially, the validity of the <em>p</em>-value does not depend on the specific choice of <img src="https://latex.codecogs.com/png.latex?M">. In practical terms, preregistering a test statistic, a random seed, and <img src="https://latex.codecogs.com/png.latex?M"> strikes me as a good idea.</p>
</section>
<section id="the-population-model-a-fiction-but-a-useful-one" class="level3">
<h3 class="anchored" data-anchor-id="the-population-model-a-fiction-but-a-useful-one">The population model: A fiction but a useful one</h3>
<p>Student’s two-sample <em>t</em>-test serves as the classical population-model counterpart to the randomisation test for the mean difference. In the present example, the <em>p</em>-value it outputs (0.10) is similar but not quite identical to the one we obtained above.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t.test</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Outcome <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>Group, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var.equal =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
    Two Sample t-test

data:  d$Outcome by d$Group
t = -1.698, df = 25, p-value = 0.1019
alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
95 percent confidence interval:
 -1.3646507  0.1313174
sample estimates:
mean in group 0 mean in group 1 
       8.250000        8.866667 </code></pre>
</div>
</div>
<p>This is typical: it’s surprisingly difficult to construct realistic examples, even with simulated data, where the <em>t</em>-test yields a markedly different <em>p</em>-value from the randomisation test for the mean difference. This similarity is not coincidental. Indeed, the <em>t</em>-test and its cousins gained their popularity precisely because, in the pre-computer era, they provided a computationally tractable approximation of randomisation tests. But just because the <em>t</em>-test generally produces similar <em>p</em>-values to those obtained by an exact procedure doesn’t mean that the <em>t</em>-test is also exact.</p>
<p>(Incidentally, population-based approaches tend to produce results close to those obtained under the randomisation model because, for moderately large samples and under mild regularity conditions, the distribution of the mean difference under all possible random permutations of the group labels is approximately normal.)</p>
</section>
</section>
<section id="the-scope-of-inference" class="level2">
<h2 class="anchored" data-anchor-id="the-scope-of-inference">The scope of inference</h2>
<p>Under the randomisation model, the null hypothesis concerns only the specific experimental units included in the study. As a result, any <em>statistical</em> inference drawn is about what happened in the experiment, not about what might happen in a larger population (whatever it may be). Since population-model tests used in randomised experiments are useful by virtue of how well they approximate randomisation-model methods, any statistical inferences they enable still concern only the experimental units included in the study.</p>
<p>This is not to say that generalisation beyond the experimental units is impossible. But it must be based on subject-matter arguments, not on statistical ones. In practice, this is precisely what reasonable researchers do: they interpret each others’ and their own findings by taking external validity into account.</p>
</section>
<section id="what-about-random-group-sizes" class="level2">
<h2 class="anchored" data-anchor-id="what-about-random-group-sizes">What about random group sizes?</h2>
<p>Before we apply the randomisation model to a real dataset, it is worth considering experiments in which the group sizes aren’t fixed in advance. Suppose we have an experiment with <img src="https://latex.codecogs.com/png.latex?m"> experimental units (e.g., participants) that are randomly assigned to two conditions. Unlike in our previous discussion, the number of units assigned to each condition isn’t predetermined. For instance, each participant may be assigned independently to the first or second condition with equal probability.</p>
<p>In this case, the assignment vector <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20B"> isn’t distributed according to <img src="https://latex.codecogs.com/png.latex?%5Ctextrm%7BUniform%7D(%5Cmathcal%7BB%7D_%7Bk,%20%5Cell%7D)"> with fixed group sizes <img src="https://latex.codecogs.com/png.latex?k,%20%5Cell">. Instead, <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20B"> follows some distribution over <img src="https://latex.codecogs.com/png.latex?%5C%7B0,%201%5C%7D%5Em">. Fortunately, we can still apply the same randomisation test as before: we simply use the observed number <img src="https://latex.codecogs.com/png.latex?K"> of units assigned to the first condition and the observed number <img src="https://latex.codecogs.com/png.latex?L"> of units assigned to the second condition in lieu of some fixed <img src="https://latex.codecogs.com/png.latex?k"> and <img src="https://latex.codecogs.com/png.latex?%5Cell">. In statistical parlance, we condition on the observed group sizes.</p>
<p>The reason why we can condition on the observed group sizes is as follows. Let <img src="https://latex.codecogs.com/png.latex?P"> denote the <em>p</em>-value obtained from the randomisation test conditional on the groups sizes <img src="https://latex.codecogs.com/png.latex?K"> and <img src="https://latex.codecogs.com/png.latex?L"> under the sharp null hypothesis. For any fixed group sizes <img src="https://latex.codecogs.com/png.latex?k,%20%5Cell">, the randomisation test is exact. Hence, <img src="https://latex.codecogs.com/png.latex?%5Ctextrm%7BProb%7D(P%20%5Cleq%20%5Calpha%20%7C%20K%20=%20k,%20L%20=%20%5Cell)%20%5Cleq%20%5Calpha"> for any <img src="https://latex.codecogs.com/png.latex?%5Calpha%20%5Cin%20(0,%201)"> and for any <img src="https://latex.codecogs.com/png.latex?k,%20%5Cell"> with <img src="https://latex.codecogs.com/png.latex?k%20+%20%5Cell%20=%20m">. So, under the null, <img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign*%7D%0A%20%20%5Ctextrm%7BProb%7D(P%20%5Cleq%20%5Calpha)%0A%20%20&amp;=%20%5Csum_%7B%5Cboldsymbol%20b%20%5Cin%20%5Cmathcal%7BB%7D_%7Bm%7D%7D%20%5Cunderbrace%7B%5Ctextrm%7BProb%7D(P%20%5Cleq%20%5Calpha%20%7C%20K%20=%20m%20-%20L,%20L%20=%20%5Csum_%7Bi%20=%201%7D%5Em%20b_i)%7D_%7B%5Cleq%20%5Calpha%7D%5Ctextrm%7BProb%7D(K%20=%20m%20-%20L,%20L%20=%20%5Csum_%7Bi%20=%201%7D%5Em%20b_i)%20%5C%5C%0A%20%20&amp;%5Cleq%20%5Calpha%20%5Csum_%7B%5Cboldsymbol%20b%20%5Cin%20%5Cmathcal%7BB%7D_%7Bm%7D%7D%20%5Ctextrm%7BProb%7D(K%20=%20m%20-%20L,%20L%20=%20%5Csum_%7Bi%20=%201%7D%5Em%20b_i)%20%5C%5C%0A%20%20&amp;=%20%5Calpha,%0A%5Cend%7Balign*%7D"> for any <img src="https://latex.codecogs.com/png.latex?%5Calpha%20%5Cin%20(0,1)">. So <img src="https://latex.codecogs.com/png.latex?P"> is an exact <em>p</em>-value even when the group sizes are random rather than fixed.</p>
<p>The same reasoning works if we condition on, say, the total number of experimental units. So randomisation tests also work when the participants trickle into the lab and the total number of participants isn’t known in advance.</p>
<p>(Alternatively, we could write a slight variant of the <code>randomisation_test()</code> function in which the new assignment vectors <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%20b"> are sampled from the unconditional distribution.)</p>
</section>
<section id="a-real-example" class="level2">
<h2 class="anchored" data-anchor-id="a-real-example">A real example</h2>
<p>Klein et al.&nbsp;(2014) replicated a study originally devised by Oppenheimer and Monin (2009) at 36 different sites. This is their description:</p>
<blockquote class="blockquote">
<p>``Oppenheimer &amp; Monin (2009) investigated whether the rarity of an independent, chance observation influenced beliefs about what occurred before that event. Participants imagined that they saw a man rolling dice in a casino. In one condition, participants imagined witnessing three dice being rolled and all came up 6’s. In a second condition two came up 6’s and one came up 3. In a third condition, two dice were rolled and both came up 6’s. All participants then estimated, in an open-ended format, how many times the man had rolled the dice before they entered the room to watch him. Participants estimated that the man rolled dice more times when they had seen him roll three 6’s than when they had seen him roll two 6’s or two 6’s and a 3. For the replication, the condition in which the man rolls two 6’s was removed leaving two conditions.’’</p>
</blockquote>
<p>Let’s use the data from the Brasília site as a more realistic example; see Table&nbsp;3 and Figure&nbsp;4. The participants were randomly assigned to the conditions, but without enforcing specific group sizes. For the randomisation tests, we’ll condition on the observed group sizes.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1">d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Klein2014_gambler.csv"</span>) <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;">filter</span>(Sample <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;">"brasilia"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb20-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(RollsImagined))</span>
<span id="cb20-4">d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n.Condition <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Condition <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;">"three6"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1">d <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;">group_by</span>(Condition) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb21-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb21-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb21-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Mean =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(RollsImagined) <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;">round</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb21-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Median =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(RollsImagined),</span>
<span id="cb21-7">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Standard deviation</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(RollsImagined) <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;">round</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb21-8">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb21-9">  knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>()</span></code></pre></div></div>
</details>
<div id="tbl-summaryklein" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-summaryklein-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;3: Results summary of Klein et al.’s replication of the gambler’s fallacy study in Brasília.
</figcaption>
<div aria-describedby="tbl-summaryklein-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<table class="cell caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: left;">Condition</th>
<th style="text-align: right;">n</th>
<th style="text-align: right;">Mean</th>
<th style="text-align: right;">Median</th>
<th style="text-align: right;">Standard deviation</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">three6</td>
<td style="text-align: right;">63</td>
<td style="text-align: right;">22.2</td>
<td style="text-align: right;">5</td>
<td style="text-align: right;">71.1</td>
</tr>
<tr class="even">
<td style="text-align: left;">two6</td>
<td style="text-align: right;">51</td>
<td style="text-align: right;">8.1</td>
<td style="text-align: right;">3</td>
<td style="text-align: right;">14.1</td>
</tr>
</tbody>
</table>
</div>
</div>
</figure>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1">d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb22-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> Condition, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> RollsImagined)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-3">  <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;">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="cb22-4">  <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;">1</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_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;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb22-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Condition"</span>,</span>
<span id="cb22-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"two6"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"three6"</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;">"two sixes"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"three sixes"</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;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of previous rolls imagined"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-boxplotklein" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-boxplotklein-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-11-09-population-randomisation/index_files/figure-html/fig-boxplotklein-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-boxplotklein-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: Data from the replication of the gambler’s fallacy study at the Brasília site.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;5 shows the distribution of the mean differences under the null hypothesis. Note the weird multimodal distribution of the test statistic. Nevertheless, the <em>p</em>-value of 0.17 is valid for the null hypothesis that none of the participants’ estimations would have been different in the other condition.</p>
<div class="cell preview-image">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randomisation_test</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RollsImagined, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n.Condition, mean_diff,</span>
<span id="cb23-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</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;">xlab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mean difference"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution under H0"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.1659</code></pre>
</div>
<div class="cell-output-display">
<div id="fig-meandiffklein" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-meandiffklein-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-11-09-population-randomisation/index_files/figure-html/fig-meandiffklein-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-meandiffklein-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: The distribution of the mean difference under the sharp null hypothesis for <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20=%200"> for the Brasília replication of the gambler’s fallacy.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Further, despite the wonky distribution of the mean difference under the null hypothesis, Student’s <em>t</em>-test produces a highly similar <em>p</em>-value.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t.test</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RollsImagined <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>n.Condition, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var.equal =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
    Two Sample t-test

data:  d$RollsImagined by d$n.Condition
t = -1.3905, df = 112, p-value = 0.1671
alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
95 percent confidence interval:
 -34.116850   5.978661
sample estimates:
mean in group 0 mean in group 1 
       8.137255       22.206349 </code></pre>
</div>
</div>
<p>Klein et al.&nbsp;actually square-root-transformed the data. If we feed the square-root-transformed data to a randomisation test, we obtain <img src="https://latex.codecogs.com/png.latex?p%20=%200.048">.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randomisation_test</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RollsImagined), d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n.Condition, mean_diff, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.0483</code></pre>
</div>
</div>
<p>The corresponding <em>t</em>-test again yields quite a similar result, though one that many researchers would interpret differently (<img src="https://latex.codecogs.com/png.latex?p%20=%200.06">).</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t.test</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RollsImagined) <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>n.Condition, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">var.equal =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.06051211</code></pre>
</div>
</div>
<p>I suspect that Klein et al.&nbsp;used a square-root transformation rather than a rank-based test because they wanted to compare results across replicated studies, and this required them to express the findings of all studies in terms of mean differences. But since we don’t have this problem, we can turn to other test statistics, such as the probability of superiority; see Figure&nbsp;6.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randomisation_test</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RollsImagined, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n.Condition, probsup,</span>
<span id="cb31-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</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;">xlab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Probability of superiority"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Distribution under H0"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.0489</code></pre>
</div>
<div class="cell-output-display">
<div id="fig-propsupklein" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-propsupklein-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-11-09-population-randomisation/index_files/figure-html/fig-propsupklein-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-propsupklein-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6: The distribution of the probability of superiority under the sharp null hypothesis for <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20=%200"> for the Brasília replication of the gambler’s fallacy.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The resulting <em>p</em>-value (0.049) is very similar to the one produced by the corresponding Wilcoxon–Mann–Whitney test.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">wilcox.test</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>RollsImagined <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>n.Condition, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">correct =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
    Wilcoxon rank sum test

data:  d$RollsImagined by d$n.Condition
W = 1265, p-value = 0.05037
alternative hypothesis: true location shift is not equal to 0</code></pre>
</div>
</div>
<p>Incidentally, you can use the <img src="https://latex.codecogs.com/png.latex?W%20=%201265"> statistic in the model output to compute the probability of superiority like so:</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1"><span class="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;">1265</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n.Condition <span 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;">sum</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n.Condition <span 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></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.606287</code></pre>
</div>
</div>
</section>
<section id="tldr" class="level2">
<h2 class="anchored" data-anchor-id="tldr">tl;dr</h2>
<p>The randomisation model offers a way to compute valid <em>p</em>-values that are justified by the research design rather than by alluding to an imagined population and an idealised sampling procedure. Nevertheless, the population model is useful, but mostly as an approximation. It allows for convenient, general-purpose methods (e.g., the <em>t</em>-test) that tend to work well for largish samples. But the asymptotic reasoning that underpins the use of these methods in randomised experiments involves complex mathematics and only guarantees large-sample validity. Randomisation tests, by contrast, are conceptually straightforward and the resulting inferences are exact for any sample size. In the words of Berger et al.&nbsp;(2002):</p>
<blockquote class="blockquote">
<p>``If credibility for the parametric [= population-model test, JV] derives from assurances that its p-value will likely be close to the corresponding exact one, then this is tantamount to an admission that the exact test is the gold standard (or, perhaps, the platinum standard).’’ (p.&nbsp;79)</p>
</blockquote>
<p>(Platinum was worth more than gold in 2002.)</p>
<p>Randomisation testing is also flexible: we can make up any test statistic we deem suitable and obtain a valid <em>p</em>-value for the test of the sharp null hypothesis. If the test statistic we choose has a classical population-model counterpart (e.g., Student’s two-sample <em>t</em>-test when testing the mean difference), the randomisation test and its classical counterpart usually result in similar <em>p</em>-values. But running the randomisation test instead of the classical counterpart is a small change that makes the resulting inferences more defensible.</p>
</section>
<section id="whats-next" class="level2">
<h2 class="anchored" data-anchor-id="whats-next">What’s next?</h2>
<p>The randomisation approach extends beyond simple two-group comparisons. In future posts, I’ll explore how it applies to more complex experimental designs.</p>
<p>What’s not obvious to me is how sensible confidence intervals could be constructed in the randomisation model. This, too, will have to be the subject for another post.</p>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<p>Berger, Vance W., Clifford E. Lunneborg, Michael D. Ernst &amp; Jonathan G. Levine. 2002. <a href="https://doi.org/10.22237/jmasm/1020255120">Parametric analysis in randomized clinical trials</a>. <em>Journal of Modern Applied Statistical Methods</em> 1(1). 74–82.</p>
<p>Klein, Richard A., Kate A. Ratliff, Michelangelo Vianello, Reginald B. Adams Jr., Štěpán Bahník, Michael J. Bernstein, Konrad Bocian et al.&nbsp;2014. <a href="https://doi.org/10.1027/1864-9335/a000178">Investigating variation in replicability: A “many labs” replication project</a>. <em>Social Psychology</em> 45(3). 142–152.</p>
<p>Oppenheimer, Daniel M. &amp; Benoît Monin. 2009. <a href="https://doi.org/10.1017/S1930297500001170">The retrospective gambler’s fallacy: Unlikely events, constructing the past, and multiple universes</a>. <em>Judgment and Decision Making</em> 4(5). 326–334.</p>
</section>
<section id="software-versions" class="level2">
<h2 class="anchored" data-anchor-id="software-versions">Software versions</h2>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1">devtools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">session_info</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"attached"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.1 (2025-06-13)
 os       Ubuntu 25.10
 system   x86_64, linux-gnu
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Zurich
 date     2025-11-09
 pandoc   3.8 @ /home/jan/miniconda3/bin/ (via rmarkdown)
 quarto   1.8.25 @ /usr/local/bin/quarto

─ Packages ───────────────────────────────────────────────────────────────────
 package   * version date (UTC) lib source
 dplyr     * 1.1.4   2023-11-17 [1] CRAN (R 4.5.1)
 forcats   * 1.0.1   2025-09-25 [1] CRAN (R 4.5.1)
 ggplot2   * 4.0.0   2025-09-11 [1] CRAN (R 4.5.1)
 lubridate * 1.9.4   2024-12-08 [1] CRAN (R 4.5.1)
 purrr     * 1.1.0   2025-07-10 [1] CRAN (R 4.5.1)
 readr     * 2.1.5   2024-01-10 [1] CRAN (R 4.5.1)
 stringr   * 1.5.2   2025-09-08 [1] CRAN (R 4.5.1)
 tibble    * 3.3.0   2025-06-08 [1] CRAN (R 4.5.1)
 tidyr     * 1.3.1   2024-01-24 [1] CRAN (R 4.5.1)
 tidyverse * 2.0.0   2023-02-22 [1] CRAN (R 4.5.1)

 [1] /home/jan/R/x86_64-pc-linux-gnu-library/4.5
 [2] /usr/local/lib/R/site-library
 [3] /usr/lib/R/site-library
 [4] /usr/lib/R/library
 * ── Packages attached to the search path.

──────────────────────────────────────────────────────────────────────────────</code></pre>
</div>
</div>


</section>

 ]]></description>
  <category>assumptions</category>
  <category>experiments</category>
  <category>design features</category>
  <category>nonparametric tests</category>
  <category>R</category>
  <category>significance</category>
  <guid>https://janhove.github.io/posts/2025-11-09-population-randomisation/</guid>
  <pubDate>Sun, 09 Nov 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Clarifying research questions by sketching possible outcomes</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2025-10-10-mock-outcomes/</link>
  <description><![CDATA[ 




<p>In this blog post, I’d like to share a technique that I’ve found useful both for teaching students how to read research articles and for advising colleagues on study design. The technique is low-tech: you sketch a few possible outcomes for the study you’re reading about or designing, and you evaluate each sketch in light of the study’s predictions, research questions, and theoretical rationale.</p>
<p>Applying this technique before reading results and discussion sections helps you become a more independent and critical reader of research articles. Applying it when designing your own studies allows you to clarify your research questions and expectations, and to anticipate and address plausible critical comments.</p>
<p>Let’s apply the technique to an example.</p>
<section id="study-design" class="level2">
<h2 class="anchored" data-anchor-id="study-design">Study design</h2>
<p>Rummer (2015) investigated the influence of taking Latin in secondary school on the use of grammatical tenses in L1 German. His quasi-experimental study included 22 8th-graders and 22 9th-graders. Of the 22 8th-graders, seven took Latin and 15 took French or Russian as a foreign language (in addition to English). Of the 22 9th-graders, nine took Latin and 13 French or Russian. The pupils were not randomly assigned to the ‘with Latin’ or ‘without Latin’ groups; these groups already existed before Rummer designed the study. The pupils had started learning their second foreign language (Latin, Russian or French) in 7th grade.</p>
<p>All pupils completed a test. The details of this test needn’t concern us, but the idea is that higher test scores reflect a more sophisticated use of the L1 German tense system.</p>
<p>Rummer’s explicit prediction, translated from the German original on p.&nbsp;255 and slightly rephrased, was</p>
<blockquote class="blockquote">
<p>Regardless of grade, pupils in the ‘with Latin’ group will show a more sophisticated use in the L1 German tense system compared to pupils in the ‘without Latin’ group. This difference will be larger in the ninth grade than in the eighth grade.</p>
</blockquote>
<p>The rationale underlying the study is that Latin classes have been said to sharpen pupils’ ‘linguistic logic’. The author, however, is skeptical of claims that Latin confers greater transferable linguistic benefits than other foreign languages.</p>
<p>While a few criticisms can be raised about this study, the article is a good read—especially for students who are still learning to read empirical research critically.</p>
</section>
<section id="step-1-sketch-mock-results" class="level2">
<h2 class="anchored" data-anchor-id="step-1-sketch-mock-results">Step 1: Sketch mock results</h2>
<p>The first step is to take a piece of paper and roughly sketch a few possible results. For simplicity, assume that there won’t be any statistical uncertainty about the outcomes. Also assume that you’re only interested in group means, not medians or other summaries. Don’t overthink the sketches—a couple of points and lines on a piece of paper are all you need.</p>
<p>The research design of our example features two times two cells (with vs without Latin, and 8th vs 9th grade), so a simple chart with two times two values suffices. These values could in principle range from 0 to 12, but you can simplify the charts even further by making only a broad distinction between, say, low, mid, and high values.</p>
<p>While I suggest you just draw these charts on a slip of paper, I wrote an R function called <code>mock_up()</code> for this blog post. Feel free to adapt it to suit your own needs.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create mock results</span></span>
<span id="cb1-2">mock_up <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plots =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show_data =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) {</span>
<span id="cb1-3">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (plots <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> levels<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) {</span>
<span id="cb1-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">warning</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"The number of datasets generated is lower than the requested number of plots."</span>)</span>
<span id="cb1-5">    plots <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> levels<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb1-6">  }</span>
<span id="cb1-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb1-8">  </span>
<span id="cb1-9">  d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand.grid</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Latin_8 =</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>levels, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Latin_9 =</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>levels, </span>
<span id="cb1-10">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">NoLatin_8 =</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>levels, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">NoLatin_9 =</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>levels)</span>
<span id="cb1-11">  d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Plot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rownames</span>(d) <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;">as.numeric</span>()</span>
<span id="cb1-12">  d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reshape</span>(d,</span>
<span id="cb1-13">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">varying   =</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;">"Latin_8"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Latin_9"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NoLatin_8"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NoLatin_9"</span>),</span>
<span id="cb1-14">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">v.names   =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outcome"</span>,</span>
<span id="cb1-15">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">timevar   =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Var"</span>,</span>
<span id="cb1-16">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">times     =</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;">"Latin_8"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Latin_9"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NoLatin_8"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"NoLatin_9"</span>),</span>
<span id="cb1-17">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">direction =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"long"</span>)</span>
<span id="cb1-18">  </span>
<span id="cb1-19">  split_names <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">do.call</span>(rbind, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strsplit</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Var, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>))</span>
<span id="cb1-20">  d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Group <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(split_names[,<span class="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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Latin"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"with Latin"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"without Latin"</span>)</span>
<span id="cb1-21">  d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Grade <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> split_names[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]</span>
<span id="cb1-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row.names</span>(d) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb1-23">  d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d[, <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;">"Plot"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Group"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Grade"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outcome"</span>)]</span>
<span id="cb1-24">  </span>
<span id="cb1-25">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Breaks at minimum ("low"), average ("mid"), and maximum ("high")</span></span>
<span id="cb1-26">  breaks <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (levels <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb1-27">  </span>
<span id="cb1-28">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (plots <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) {</span>
<span id="cb1-29">    my_plot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-30">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">subset</span>(Plot <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</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>levels<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, plots)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-31">      <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> Grade, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> Outcome,</span>
<span id="cb1-32">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> Group,</span>
<span id="cb1-33">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> Group,</span>
<span id="cb1-34">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape =</span> Group)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-35">      <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.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-36">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-37">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_shape_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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-38">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> breaks, <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;">"low"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mid"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-39">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">facets =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(Plot)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-40">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-41">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-42">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mock results"</span>)</span>
<span id="cb1-43">    </span>
<span id="cb1-44">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(my_plot)</span>
<span id="cb1-45">  }</span>
<span id="cb1-46">  </span>
<span id="cb1-47">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (show_data) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(d)</span>
<span id="cb1-48">}</span></code></pre></div></div>
</details>
</div>
<p>Figure&nbsp;1 shows a few rough sketches of possible findings, using four levels to distinguish between the outcomes. Since there are <img src="https://latex.codecogs.com/png.latex?%5Cell%5E4"> possible ways to assign one of <img src="https://latex.codecogs.com/png.latex?%5Cell"> values to four cells in the design (here: <img src="https://latex.codecogs.com/png.latex?%5Cell%20=%204">, so <img src="https://latex.codecogs.com/png.latex?%5Cell%5E4%20=%20256">), only a random subset of possible sketches is plotted. The numbers in the facets identify which of these <img src="https://latex.codecogs.com/png.latex?%5Cell%5E4"> sketches are plotted. If you run the function yourself, you’ll get a different set of sketches.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="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;">2025-10-09</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># comment out when running the function yourself</span></span>
<span id="cb2-2">d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mock_up</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plots =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show_data =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-mockup1" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-mockup1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-10-10-mock-outcomes/index_files/figure-html/fig-mockup1-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-mockup1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Four sketches of mock results for Rummer’s study. The numbers in the facet description (41, 70, 98, 188) identify the plotted mock results in the set of the 256 generated results.
</figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="step-2-compare-mock-results-to-predictions" class="level2">
<h2 class="anchored" data-anchor-id="step-2-compare-mock-results-to-predictions">Step 2: Compare mock results to predictions</h2>
<p>The second step is to decide, for each of the mock results you’ve drawn, whether it matches the predictions or hypotheses. Take these predictions or hypotheses literally.</p>
<p>For readers, the idea of this step is to figure out which aspects of the results are relevant for evaluating the predictions and which aspects are irrelevant. This way, once you move on to the article’s results section, you know what you should pay attention to.</p>
<p>If you’re designing a study, the idea of this step is to figure out whether your phrased your predictions clearly and if they match what you intended to say.</p>
<p>Let’s try this for the mock-up results in Figure&nbsp;1.</p>
<ul>
<li>Sketch 41: The with Latin group in 8th grade doesn’t score higher than the without Latin group in 8th grade. So the predictions aren’t confirmed.</li>
<li>Sketch 70: The with Latin group in 9th grade doesn’t score higher than the without Latin group in 9th grade. So the predictions aren’t confirmed.</li>
<li>Sketches 98 and 188: The predictions aren’t confirmed for the same reasons.</li>
</ul>
<p>This already tells us that the predictions aren’t so vague that pretty much any pattern in the results would confirm them—which is a good thing. Moreover, the predictions seem to be clear in the sense that we were able to make a decision for all four patterns.</p>
<p>Further, if you’re fairly novice reader of quantitative research, the sketches above may help you figure out some criteria that the results need to meet if they are to confirm the predictions:</p>
<ol type="1">
<li>The with Latin group should outperform the without Latin group in grade 8.</li>
<li>The with Latin group should outperform the without Latin group in grade 9.</li>
</ol>
<p>To more seasoned consumers of quantitative research, this may seem obvious. (It may also seem obvious to them that one more condition needs to be satisfied. We’ll return to this shortly.) But from experience, I can tell you that it isn’t obvious for everyone—not even if the predictions are spelt out as clearly and specifically as here.</p>
</section>
<section id="step-3-draw-confirmatory-results-and-come-up-with-alternative-explanations" class="level2">
<h2 class="anchored" data-anchor-id="step-3-draw-confirmatory-results-and-come-up-with-alternative-explanations">Step 3: Draw confirmatory results and come up with alternative explanations</h2>
<p>The next step is to sketch a couple of further possible results that satisfy the necessary conditions for them to confirm the predictions. If we notice that some of the patterns drawn still wouldn’t confirm the predictions, we need to revise the list of necessary conditions. Iteratively, we refine our understanding of what exactly counts as evidence for or against the predictions.</p>
<p>Figure&nbsp;2 shows sketches of four patterns that conform to the two necessary conditions we’ve identified.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb3-2"></span>
<span id="cb3-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Patterns satisfying the 2 necessary conditions</span></span>
<span id="cb3-4">d_confirm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id_cols =</span> Plot, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Group, Grade),</span>
<span id="cb3-6">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from =</span> Outcome) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with Latin_8</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">without Latin_8</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with Latin_9</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">without Latin_9</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cols =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contains</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Latin"</span>),</span>
<span id="cb3-10">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</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;">"Group"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Grade"</span>),</span>
<span id="cb3-11">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_pattern =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(.*)_(.*)"</span>,</span>
<span id="cb3-12">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outcome"</span>)</span>
<span id="cb3-13"></span>
<span id="cb3-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Other patterns (refuting or perhaps ambiguous)</span></span>
<span id="cb3-15">d_refute <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">anti_join</span>(d_confirm)</span>
<span id="cb3-17"></span>
<span id="cb3-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot some of the patterns confirming the predictions</span></span>
<span id="cb3-19">plots <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb3-20">levels <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb3-21">breaks <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <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;"># for nice plotting</span></span>
<span id="cb3-22"></span>
<span id="cb3-23">d_confirm <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Plot <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(Plot), plots)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-25">  <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> Grade, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> Outcome,</span>
<span id="cb3-26">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> Group,</span>
<span id="cb3-27">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> Group,</span>
<span id="cb3-28">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape =</span> Group)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-29">  <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.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_shape_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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> breaks, <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;">"low"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mid"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">facets =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(Plot)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Confirmatory mock results?"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-literal-confirm" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-literal-confirm-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-10-10-mock-outcomes/index_files/figure-html/fig-literal-confirm-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-literal-confirm-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Sketches of four patterns that conform to the two necessary conditions we’ve identified.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Let’s evaluate these sketches, too, in terms of the predictions:</p>
<ul>
<li>Sketch 6: The difference between the with and the without Latin groups isn’t larger in grade 9 than in grade 8. So the predictions aren’t confirmed.</li>
<li>Sketch 10: This pattern conforms fully to the predictions.</li>
<li>Sketches 16 and 159: The patterns don’t conform to the predictions for the same reason as sketch 6 doesn’t.</li>
</ul>
<p>This tells us that we need to add a third necessary condition to the list:</p>
<ol type="1">
<li>The with Latin group should outperform the without Latin group in grade 8.</li>
<li>The with Latin group should outperform the without Latin group in grade 9.</li>
<li>The difference between the with and without Latin groups is larger in grade 9 than in grade 8.</li>
</ol>
<p>We repeat the process, ending up with the eleven sketches shown in Figure&nbsp;3.</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Patterns satisfying the 3 necessary conditions</span></span>
<span id="cb4-2">d_confirm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id_cols =</span> Plot, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(Group, Grade),</span>
<span id="cb4-4">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from =</span> Outcome) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb4-5">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add another condition</span></span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with Latin_8</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">without Latin_8</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with Latin_9</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">without Latin_9</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with Latin_8</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">without Latin_8</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> </span>
<span id="cb4-9">           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with Latin_9</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">without Latin_9</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb4-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cols =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contains</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Latin"</span>),</span>
<span id="cb4-11">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</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;">"Group"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Grade"</span>),</span>
<span id="cb4-12">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_pattern =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(.*)_(.*)"</span>,</span>
<span id="cb4-13">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Outcome"</span>)</span>
<span id="cb4-14"></span>
<span id="cb4-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Other patterns (refuting or perhaps ambiguous)</span></span>
<span id="cb4-16">d_refute <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb4-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">anti_join</span>(d_confirm)</span>
<span id="cb4-18"></span>
<span id="cb4-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot</span></span>
<span id="cb4-20">d_confirm <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb4-21">  <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> Grade, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> Outcome,</span>
<span id="cb4-22">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> Group,</span>
<span id="cb4-23">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> Group,</span>
<span id="cb4-24">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape =</span> Group)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-25">  <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.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_shape_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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> breaks, <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;">"low"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mid"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">facets =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(Plot)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb4-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Confirmatory mock results"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-literal-confirm2" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-literal-confirm2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-10-10-mock-outcomes/index_files/figure-html/fig-literal-confirm2-1.svg" class="img-fluid figure-img" style="width:100.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-literal-confirm2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: All eleven out of 256 sketches that conform fully to the author’s predictions.
</figcaption>
</figure>
</div>
</div>
</div>
<p>As you can verify, all of these patterns literally conform to the author’s predictions. But some of these patterns probably don’t correspond to what the author had in mind. I suspect that the author pictured a pattern like the ones shown in sketches 78 and 95, where at least the with Latin groups show some improvement from grade 8 to grade 9. In some of the other sketches, the performance in the with Latin groups is constant whereas it declines in the without Latin groups. Such a pattern would be more consistent with Latin classes having a prophylactic effect against the decline of language logic than with their actively enhancing language logic.</p>
<p>If you’re designing a study, sketches that literally conform the predictions but look unlike what you expect may prompt you to rephrase your predictions. If you’re reading a quantitative research article, such sketches can help you appreciate that the author’s formal predictions don’t fully capture what are likely their actual expectations.</p>
<p>Moreover, having drawn patterns that would confirm the author’s predictions, we can try to think of plausible alternative explanations for them. As far as I’m concerned, all eleven patterns in Figure&nbsp;3 could possibly be explained by selection bias: The pupils weren’t randomly assigned to the language groups, and it’s entirely plausible that pupils choosing or being encouraged to take Latin tend to be the ones with a knack for language logic. This would show up as a better outcome for the with Latin group than for the without Latin group in grade 8, and an even greater difference in grade 9.</p>
<p>Another plausible alternative explanation for some of the sketches involves floor effects. In sketches 10, 14, 15 and 78, the without Latin group performs near the bottom of the scale. This leaves open the possibility that the difference between the with and the without Latin groups in grade 8 in terms of the sophistication of their use of L1 tenses is larger than the test scores suggests. As a result, it’s possible that the true gap in the sophistication of L1 tense use between the with and without Latin groups is equally as large in grade 9 as it is in grade 8, and that both groups show a parallel development. Likewise, ceiling effects in with Latin group in grade 8 (sketches 32, 44, 48, 112) may mask such a parallel development.</p>
<p>I don’t want to exhaustively list plausible alternative explanations for these patterns. If you’re a reader, the goal of this part of the exercise is to prepare yourself mentally that a pattern that conforms to the author’s predictions may be compatible with an explanation other than the one put forward by the author. If you’re the one designing the study, this may help you identify weaknesses in your design that you can hopefully still fix.</p>
</section>
<section id="step-4-draw-disconfirmatory-and-ambiguous-results-and-try-to-spin-them" class="level2">
<h2 class="anchored" data-anchor-id="step-4-draw-disconfirmatory-and-ambiguous-results-and-try-to-spin-them">Step 4: Draw disconfirmatory and ambiguous results and try to spin them</h2>
<p>Steps 2 and 3 allowed us to identify the patterns that would confirm the author’s predictions and to anticipate alternative explanations for them. In step 4, the goal is to take a closer look at results that would <em>not</em> confirm the predictions and to consider whether, and how, such results might still be interpreted in line with the broader idea underpinning the study.</p>
<p>Consider Figure&nbsp;4. None of the patterns sketched literally conforms to the author’s predictions. But how difficult would it be to spin these patterns in such a way that they are still consistent with the broader idea that Latin classes are more beneficial to language logic than French or Russian classes?</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">d_refute <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;">filter</span>(Plot <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">86</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">107</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">139</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">144</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">158</span>)) <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;">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> Grade, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> Outcome,</span>
<span id="cb5-4">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> Group,</span>
<span id="cb5-5">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> Group,</span>
<span id="cb5-6">             <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape =</span> Group)) <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;">0.5</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_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_shape_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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)) <span 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;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> breaks, <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;">"low"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mid"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"high"</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;">facet_wrap</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">facets =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vars</span>(Plot)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_bw</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-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;">"bottom"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Disconfirmatory results"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-literal-refute" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-literal-refute-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2025-10-10-mock-outcomes/index_files/figure-html/fig-literal-refute-1.svg" class="img-fluid figure-img" style="width:100.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-literal-refute-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: A few of the sketches that do not match with the author’s predictions.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The pattern in sketch 6 could easily be spun in these terms: The children had already taken Latin, French or Russian in grade 7, and the boost in language logic already happened before the start of this study.</p>
<p>Sketch 86 could also be explained away as a result of poor timing: Latin classes are more conducive to language logic, just not in the short term. Perhaps the structures targeted in this study aren’t even taught until grade 9? An alternative explanation for these results would be that the test used in this study just isn’t up to scratch.</p>
<p>Sketch 107 isn’t compatible with the author’s predictions, either. But such results could suggest that taking Latin protects against a decline in language logic—or that taking French or Russian expediates such a decline.</p>
<p>Sketch 139 might suggest that taking Latin hastens the development of language logic, even though admittedly this relative benefit isn’t long-lasting. But precocious levels of development of language logic may perhaps confer advantages in other respects that aren’t captured in this study?</p>
<p>Sketch 144 might also suggest that taking Latin hastens the development of language logic. This relative benefit seems to be more long-lasting. Moreover, the ceiling effect for the with Latin group may mask a continued development in language loss beyond grade 8.</p>
<p>Finally, sketch 158 could suggest that the benefit of taking Latin isn’t evident in grade 8 but that it does become visible by grade 9.</p>
<p>Step 4 may reveal that the author’s predictions were overly restrictive. For instance, the results in sketch 158 arguably represent stronger evidence for the claim that taking Latin boosts language logic than some of the results in Figure&nbsp;3: the pattern in sketch 158 renders less plausible the explanation that pupils taking Latin already were stronger in language logic before they even took Latin.</p>
<p>If, as the researcher planning the study, you notice that your predictions, taken literally, are too restrictive, you may want to revise them. Again, the idea is to iterate through these steps until you’re confident that what you wrote is what you mean.</p>
<p>Like step 3, step 4 highlights the role of auxiliary assumptions in deriving predictions from theories—or from vaguer notions such as ‘Latin boosts language logic’. In this particular example, some key assumptions appear to be</p>
<ol type="1">
<li>that this beneficial effect is already noticeable in grade 8 (cf.&nbsp;patterns 86, 107 and 158);</li>
<li>that this beneficial effect is cumulative (cf.&nbsp;patterns 6 and 139);</li>
<li>and that the test used could show such a cumulative beneficial effect (cf.&nbsp;patterns 86 and 144).</li>
</ol>
<p>As a reader, such insights may help you better appreciate the distinction between the specific predictions and the broader theoretical ideas that motivate them. They also make you more aware of how easily results can be interpreted—or spun—to fit a preferred narrative.</p>
<p>As a researcher planning a study, they hopefully encourage you to make explicit how you derived your predictions from the theoretical framework and to revise these predictions if needed. Further, they may prompt you to adjust your design to address potential criticisms (e.g., by including 7th- and 10-th graders) or to build in some checks of key assumptions.</p>
</section>
<section id="conclusion" class="level2">
<h2 class="anchored" data-anchor-id="conclusion">Conclusion</h2>
<p>Sketching possible results and then trying to interpret them is a simple enough exercise. But it forces you to understand or specify exactly what patterns would support the predictions, and what patterns would refute them. Further, it helps you to identify the often tacit auxiliary assumptions that the predictions are based on. For readers, it encourages critical engagement with research articles as opposed to merely taking the author’s interpretations at face value. For researchers, it sharpens research questions and predictions, and, by forcing them to anticipate alternative explanations, it may help them strengthen the study’s design.</p>
</section>
<section id="reference" class="level2">
<h2 class="anchored" data-anchor-id="reference">Reference</h2>
<p>Rummer, Ralf. 2015. <a href="https://doi.org/10.1515/zfal-2015-0015">Der Einfluss des schulischen Lateinunterrichts auf die Tempuswahl im Deutschen.</a> <em>Zeitschrift für Angewandte Linguistik</em> 63(1). 247–264.</p>
</section>
<section id="software-versions" class="level2">
<h2 class="anchored" data-anchor-id="software-versions">Software versions</h2>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">devtools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">session_info</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pkgs =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"attached"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.1 (2025-06-13)
 os       Ubuntu 22.04.5 LTS
 system   x86_64, linux-gnu
 ui       X11
 language en_US
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Zurich
 date     2025-10-10
 pandoc   2.12 @ /home/jan/miniconda3/bin/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────
 package   * version date (UTC) lib source
 dplyr     * 1.1.4   2023-11-17 [1] CRAN (R 4.5.1)
 forcats   * 1.0.0   2023-01-29 [1] CRAN (R 4.5.1)
 ggplot2   * 3.5.2   2025-04-09 [1] CRAN (R 4.5.1)
 lubridate * 1.9.4   2024-12-08 [1] CRAN (R 4.5.1)
 purrr     * 1.0.4   2025-02-05 [1] CRAN (R 4.5.1)
 readr     * 2.1.5   2024-01-10 [1] CRAN (R 4.5.1)
 stringr   * 1.5.1   2023-11-14 [1] CRAN (R 4.5.1)
 tibble    * 3.3.0   2025-06-08 [1] CRAN (R 4.5.1)
 tidyr     * 1.3.1   2024-01-24 [1] CRAN (R 4.5.1)
 tidyverse * 2.0.0   2023-02-22 [1] CRAN (R 4.5.1)

 [1] /home/jan/R/x86_64-pc-linux-gnu-library/4.5
 [2] /usr/local/lib/R/site-library
 [3] /usr/lib/R/site-library
 [4] /usr/lib/R/library

──────────────────────────────────────────────────────────────────────────────</code></pre>
</div>
</div>


</section>

 ]]></description>
  <category>research questions</category>
  <category>research design</category>
  <guid>https://janhove.github.io/posts/2025-10-10-mock-outcomes/</guid>
  <pubDate>Fri, 10 Oct 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Exact significance tests for 2 × 2 tables</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2024-09-10-contingency-p-value/</link>
  <description><![CDATA[ 




<p>Two-by-two contingency tables look so simple that you’d be forgiven for thinking they’re straightforward to analyse. A glance at the statistical literature on the analysis of contingency tables, however, reveals a plethora of techniques and controversies surrounding them that will quickly disabuse you of this notion (see, for instance, Fagerland et al.&nbsp;2017). In this blog post, I discuss a handful of different study designs that give rise to two-by-two tables and present a few exact significance tests that can be applied to these tables. A more exhaustive overview can be found in Fagerland et al.&nbsp;(2017).</p>
<section id="preliminaries" class="level2">
<h2 class="anchored" data-anchor-id="preliminaries">Preliminaries</h2>
<section id="two-by-two-contingency-tables" class="level3">
<h3 class="anchored" data-anchor-id="two-by-two-contingency-tables">Two-by-two contingency tables</h3>
<p>Two-by-two contingency tables arise when cross-tabulate obserations that have two binary properties (<img src="https://latex.codecogs.com/png.latex?X">: <img src="https://latex.codecogs.com/png.latex?x_1"> vs.&nbsp;<img src="https://latex.codecogs.com/png.latex?x_2">; <img src="https://latex.codecogs.com/png.latex?Y">: <img src="https://latex.codecogs.com/png.latex?y_1"> vs.&nbsp;<img src="https://latex.codecogs.com/png.latex?y_2">). The number of obervations for which <img src="https://latex.codecogs.com/png.latex?X%20=%20x_1"> and <img src="https://latex.codecogs.com/png.latex?Y%20=%20y_1"> is referred to as <img src="https://latex.codecogs.com/png.latex?n_%7B11%7D">, and similarly for the other combinations of <img src="https://latex.codecogs.com/png.latex?X"> and <img src="https://latex.codecogs.com/png.latex?Y"> values. We further define the row totals <img src="https://latex.codecogs.com/png.latex?n_%7B1+%7D%20:=%20n_%7B11%7D%20+%20n_%7B12%7D"> and <img src="https://latex.codecogs.com/png.latex?n_%7B2+%7D%20:=%20n_%7B21%7D%20+%20n_%7B22%7D"> as well as the column totals <img src="https://latex.codecogs.com/png.latex?n_%7B+1%7D%20:=%20n_%7B11%7D%20+%20n_%7B21%7D"> and <img src="https://latex.codecogs.com/png.latex?n_%7B+2%7D%20:=%20n_%7B12%7D%20+%20n_%7B22%7D">. We call the total number of observations <img src="https://latex.codecogs.com/png.latex?n_%7B++%7D">.</p>
<img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Barray%7D%7Bl%7Cc%7Cc%7C%7Cc%7D%0A%20%20&amp;%20Y%20=%20y_1%20&amp;%20Y%20=%20y_2%20&amp;%20%5Ctextrm%7BRow%20total%7D%20%5C%5C%0A%20%20%5Chline%0A%20%20X%20=%20x_1%20&amp;%20n_%7B11%7D%20&amp;%20n_%7B12%7D%20&amp;%20n_%7B1+%7D%20%5C%5C%0A%20%20X%20=%20x_2%20&amp;%20n_%7B21%7D%20&amp;%20n_%7B22%7D%20&amp;%20n_%7B2+%7D%20%5C%5C%0A%20%20%5Chline%0A%20%20%5Ctextrm%7BColumn%20total%7D%20&amp;%20n_%7B+1%7D%20&amp;%20n_%7B+2%7D%20&amp;%20n_%7B++%7D%20%5C%5C%0A%5Cend%7Barray%7D">
</section>
<section id="exact-and-approximate-tests" class="level3">
<h3 class="anchored" data-anchor-id="exact-and-approximate-tests">Exact and approximate tests</h3>
<p>This blog post is about <strong>exact significance tests</strong>. An exact test has the following defining property: If the null hypothesis is true, the <img src="https://latex.codecogs.com/png.latex?p">-value that the test yields is a random variable <img src="https://latex.codecogs.com/png.latex?P"> with the property that <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BP%7D(P%20%5Cleq%20%5Calpha)%20%5Cleq%20%5Calpha"> for each <img src="https://latex.codecogs.com/png.latex?%5Calpha%20%5Cin%20(0,%201)">. This means that, if the null hypothesis is true, there is at most a 5% probability that the test will yield a <img src="https://latex.codecogs.com/png.latex?p">-value of 0.05 or below. Similarly, if the null hypothesis is true, there is at most a 20% probability that the test will yield a <img src="https://latex.codecogs.com/png.latex?p">-value of 0.20 or below, and so for all values between 0 and 1. Ideally, <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BP%7D(P%20%5Cleq%20%5Calpha)"> should be close to, but no larger than, <img src="https://latex.codecogs.com/png.latex?%5Calpha">: If <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BP%7D(P%20%5Cleq%20%5Calpha)"> tends to be considerably lower than <img src="https://latex.codecogs.com/png.latex?%5Calpha">, i.e., if the test is <strong>conservative</strong>, this will negatively affect the test’s power.</p>
<p>Tests that aren’t exact can still be <strong>approximate</strong>. A possible problem with approximate tests is that their justification depends on results derived for large samples; for smaller samples, <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BP%7D(P%20%5Cleq%20%5Calpha)"> may be substantially larger than <img src="https://latex.codecogs.com/png.latex?%5Calpha">. The best-known approximate test used for the analysis of two-by-two contingency tables is Pearson’s <img src="https://latex.codecogs.com/png.latex?%5Cchi%5E2">-test.</p>
</section>
</section>
<section id="contingency-tables-with-both-marginals-fixed" class="level2">
<h2 class="anchored" data-anchor-id="contingency-tables-with-both-marginals-fixed">Contingency tables with both marginals fixed</h2>
<p>Two-by-two contingency tables can be the result of different research designs – some fairly common, others exceedingly rare.</p>
<p><strong>Example 1</strong> (Fisher’s exact test, one-sided)<strong>.</strong> Say we want to establish if a learner of English is able to tell the /æ/ phoneme in <em>bat</em> and the /ɛ/ phoneme in <em>bet</em> apart. To this end, we make 35 recordings, 21 of which contain the word <em>bet</em> and 14 contain the word <em>bat</em>. The learner is then asked to identify those 21 audio files that he thinks are recordings of <em>bet</em>; the remaining 14 audio files are suspected recordings of <em>bat</em>. The results are summarised in the following contingency table:</p>
<img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Barray%7D%7Bl%7Ccc%7D%0A%20%20&amp;%20%5Ctextrm%7BCategorised%20as%20%5Ctextit%7Bbet%7D%7D%20&amp;%20%5Ctextrm%7BCategorised%20as%20%5Ctextit%7Bbat%7D%7D%20%20%5C%5C%0A%20%20%5Chline%0A%20%20%5Ctextrm%7BIs%20%5Ctextit%7Bbet%7D%7D%20&amp;%2015%20&amp;%206%20%5C%5C%0A%20%20%5Ctextrm%7BIs%20%5Ctextit%7Bbat%7D%7D%20&amp;%206%20%20&amp;%208%20%5C%5C%0A%5Cend%7Barray%7D">
<p>Note that we insisted that the learner select exactly 21 suspected recordings of <em>bet</em>, no more and no fewer. As a result, the column total <img src="https://latex.codecogs.com/png.latex?n_%7B+1%7D"> was known in advance. Moreover, we knew beforehand that 21 of the recordings actually featured <em>bet</em> and 14 of the recordings actually featured <em>bat</em>. Hence, the row totals <img src="https://latex.codecogs.com/png.latex?n_%7B1+%7D,%20n_%7B2+%7D"> were also known in advance. As a result, <img src="https://latex.codecogs.com/png.latex?n_%7B++%7D"> and <img src="https://latex.codecogs.com/png.latex?n_%7B+2%7D"> were also known in advance. Consequently, this study design fixes both the row and column marginals. What wasn’t known in advance was the number of suspected <em>bet</em> recordings that actually were <em>bet</em> recordings (<img src="https://latex.codecogs.com/png.latex?n_%7B11%7D">).</p>
<p>The null hypothesis in this setting is that the learner is incapable of distinguishing <em>bet</em> from <em>bat</em> recordings and just selected 21 random audio files as suspected <em>bet</em> recordings in order to comply with the instructions. Under this null hypothesis, the top left entry in the contingency table (<img src="https://latex.codecogs.com/png.latex?n_%7B11%7D">) follows a hypergeometric distribution with parameters <img src="https://latex.codecogs.com/png.latex?n_%7B1+%7D%20=%2021,%20n_%7B2+%7D%20=%2014"> and <img src="https://latex.codecogs.com/png.latex?n_%7B+1%7D%20=%2021">. (Different authors parametrise this distribution differently; I use the parametrisation that’s used in R.) That is,</p>
<p><img src="https://latex.codecogs.com/png.latex?H_0%20:%20n_%7B11%7D%20%5Csim%20%5Ctextrm%7BHypergeometric%7D(%5Cunderbrace%7B21%7D_%7B%5Ctextrm%7Bis%20bet%7D%7D,%20%5Cunderbrace%7B14%7D_%7B%5Ctextrm%7Bis%20bat%7D%7D,%20%5Cunderbrace%7B21%7D_%7B%5Ctextrm%7Bto%20be%20categorised%20as%20bet%7D%7D)."></p>
<p>Figure&nbsp;1 shows the probability mass and cumulative probability functions of the <img src="https://latex.codecogs.com/png.latex?%5Ctextrm%7BHypergeometric%7D(21,%2014,%2021)"> distribution. The observed top-left entry, i.e., 15, is highlighted in blue.</p>
<div class="cell">
<div class="cell-output-display">
<div id="fig-hypergeometric" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-hypergeometric-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2024-09-10-contingency-p-value/index_files/figure-html/fig-hypergeometric-1.svg" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-hypergeometric-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: The probability mass function (left) and the cumulative probability function (right) of the <img src="https://latex.codecogs.com/png.latex?%5Ctextrm%7BHypergeometric%7D(21,%2014,%2021)"> distribution.
</figcaption>
</figure>
</div>
</div>
</div>
<p>If the learner did not just pick 21 audio files at random but was in fact able to tell <em>bet</em> and <em>bat</em> recordings apart to some degree, this top-left entry can be expected to be large as opposed to small. This means that we want to compute a right-sided <img src="https://latex.codecogs.com/png.latex?p">-value, which we do by calculating</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BP%7D(n_%7B11%7D%20%5Cgeq%2015)%20=%201%20-%20%5Cmathbb%7BP%7D(n_%7B11%7D%20%5Cleq%2014):"></p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="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;">phyper</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span 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;">21</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.09059986</code></pre>
</div>
</div>
<p>This computation amounts to running <strong>Fisher’s exact test</strong>:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">tab <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</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;">15</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</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;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>))</span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fisher.test</span>(tab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"greater"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.09059986</code></pre>
</div>
</div>
<p><strong>Example 2</strong> (Fisher’s exact test, two-sided)<strong>.</strong> Let’s slightly change the design of the study in Example 1. Instead of recording <em>bet</em> 21 times and <em>bat</em> 14 times and asking the learner to select 21 suspected <em>bet</em> recordings, we record both <em>bet</em> and <em>bat</em> 18 times and ask the learner to select 18 suspected <em>bet</em> recordings. The results are summarised in the following contingency table:</p>
<img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Barray%7D%7Bl%7Ccc%7D%0A%20%20&amp;%20%5Ctextrm%7BCategorised%20as%20%5Ctextit%7Bbet%7D%7D%20%20&amp;%20%5Ctextrm%7BCategorised%20as%20%5Ctextit%7Bbat%7D%7D%20%20%5C%5C%0A%20%20%5Chline%0A%20%20%5Ctextrm%7BIs%20%5Ctextit%7Bbet%7D%7D%20&amp;%205%20%20%20%20%20%20%20%20%20%20%20%20&amp;%2013%20%5C%5C%0A%20%20%5Ctextrm%7BIs%20%5Ctextit%7Bbat%7D%7D%20&amp;%2013%20%20%20%20%20%20%20%20%20%20%20&amp;%205%20%5C%5C%0A%5Cend%7Barray%7D">
<p>Under the null hypothesis that the learner possesses no relevant discriminatory ability, the top-left entry (<img src="https://latex.codecogs.com/png.latex?n_%7B11%7D">) follows a <img src="https://latex.codecogs.com/png.latex?%5Ctextrm%7BHypergeometric%7D(18,%2018,%2018)"> distribution; see Figure&nbsp;2. The observed top-left entry (5) is highlighted by the dashed blue line.</p>
<div class="cell">
<div class="cell-output-display">
<div id="fig-hypergeometric-twosided" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-hypergeometric-twosided-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2024-09-10-contingency-p-value/index_files/figure-html/fig-hypergeometric-twosided-1.svg" class="img-fluid figure-img" style="width:38.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-hypergeometric-twosided-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: The probability mass function of the <img src="https://latex.codecogs.com/png.latex?%5Ctextrm%7BHypergeometric%7D(18,%2018,%2018)"> distribution.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Of note, the learner seems to be able to tell <em>bet</em> and <em>bat</em> apart to some extent – it’s just that he seems to identify <em>bet</em> recordings as <em>bat</em> and vice versa. Since we’re interested in the learner’s discriminatory ability, regardless of whether he is then also able to correctly <em>label</em> the two categories, we want to compute a two-sided <img src="https://latex.codecogs.com/png.latex?p">-value. The most common way to do so is to sum the probability masses <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BP%7D(n_%7B11%7D%20=%20k),%20k%20=%201,%20%5Cdots,%20n_%7B+1%7D,"> that are no greater than the probability mass of the actually observed top-left entry. These are the probability masses coloured blue in Figure&nbsp;2.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">p_k <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dhyper</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>)</span>
<span id="cb5-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(p_k[p_k <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dhyper</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>)])</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.01839395</code></pre>
</div>
</div>
<p>Fisher’s exact test carries out the same computation.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">tab <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</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;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">13</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;">13</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span>
<span id="cb7-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fisher.test</span>(tab)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.01839395</code></pre>
</div>
</div>
</section>
<section id="contingency-tables-with-one-marginal-fixed" class="level2">
<h2 class="anchored" data-anchor-id="contingency-tables-with-one-marginal-fixed">Contingency tables with one marginal fixed</h2>
<p>Contingency tables in which both the row and column marginals are fixed in advance are a rare sight. More common in some areas of research are contingency tables where only the row marginals are fixed by design. Such tables can be found in, for instance, experimental research in which a fixed number of participants are assigned to one experimental condition and another fixed number of participants are assigned to the other experimental condition and where for each participant, we have a single binary outcome (e.g., died vs.&nbsp;survived, or passed vs.&nbsp;failed).</p>
<p><strong>Example 3</strong> (Boschloo’s test)<strong>.</strong> Let’s imagine we’re in charge of an agency that designs self-study courses to help students prepare for an entrance exam. We’ve developed a course whose efficacy we want to compare against that of its predecessor. More specifically, we’re interested in finding out whether the new course is better than the old one in terms of helping the students pass the entrance exam. We recruit 24 students willing to participate in an evaluation study and, using complete randomisation, we assign 12 of them to work with the new course and 12 to work with the old one. The results look as follows:</p>
<img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Barray%7D%7Bl%7Ccc%7D%0A%20%20&amp;%20%5Ctextrm%7BPass%7D%20%20&amp;%20%5Ctextrm%7BFail%7D%20%20%5C%5C%0A%20%20%5Chline%0A%20%20%5Ctextrm%7BNew%20course%7D%20&amp;%2010%20%20%20%20%20%20%20%20%20%20&amp;%202%20%5C%5C%0A%20%20%5Ctextrm%7BOld%20course%7D%20&amp;%206%20%20%20%20%20%20%20%20%20%20%20&amp;%206%20%5C%5C%0A%5Cend%7Barray%7D">
<p>In contrast to the previous two examples, it’s only the row marginals that were known beforehand in this example. Nevertheless, applying Fisher’s exact test to this contingency table is reasonable. In doing so, we would be <strong>conditioning</strong> the analysis on the observed column marginals (<img src="https://latex.codecogs.com/png.latex?n_%7B+1%7D%20=%2016">, <img src="https://latex.codecogs.com/png.latex?n_%7B+2%7D%20=%208">), even though the study design did not fix these marginals. The corresponding null hypothesis is</p>
<p><img src="https://latex.codecogs.com/png.latex?H_0%20%7C%20n_%7B+1%7D%20=%2016,%20n_%7B+2%7D%20=%208~:~%20n_%7B11%7D%20%5Csim%20%5Ctextrm%7BHypergeometric%7D(12,%2012,%2016)."></p>
<p>An exact test remains exact when it is used conditionally (Lydersen 2009:1165), so the resulting <img src="https://latex.codecogs.com/png.latex?p">-value is perfectly valid:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">tab <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</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;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>))</span>
<span id="cb9-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fisher.test</span>(tab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"greater"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.09651366</code></pre>
</div>
</div>
<p>That said, conditional exact tests tend to be pretty conservative. Intuitively, the reason is that the conditional exact test only considers <img src="https://latex.codecogs.com/png.latex?%5Cmin(n_%7B+1%7D,%20n_%7B1+%7D)%20+%201"> of the possible tables that could have been observed under the null hypothesis; in this example, these would be the thirteen different tables where <img src="https://latex.codecogs.com/png.latex?n_%7B1+%7D%20=%20n_%7B2+%7D%20=%2012"> and <img src="https://latex.codecogs.com/png.latex?n_%7B+1%7D%20=%2016">, i.e., with <img src="https://latex.codecogs.com/png.latex?n_%7B11%7D%20=%200,%201,%20%5Cdots,%2012">. The actual sample space under the null hypothesis in this design, however, comprises <img src="https://latex.codecogs.com/png.latex?(n_%7B1+%7D%20+%201)%20%5Ccdot%20(n_%7B2+%7D%20+%201)"> tables. In this example, these would be the 169 different tables where <img src="https://latex.codecogs.com/png.latex?n_%7B1+%7D%20=%20n_%7B2+%7D%20=%2012">. By only considering a small part of the sample space, the conditional exact test in essence misses out on opportunities to return small <img src="https://latex.codecogs.com/png.latex?p">-values.</p>
<p>Unconditional exact tests consider the whole sample space and are consequently less conservative than conditional exact tests. The contingency table in the fixed row marginals design can be considered the result of two draws from binomial distributions: one with <img src="https://latex.codecogs.com/png.latex?n_%7B1+%7D"> attempts and success probability <img src="https://latex.codecogs.com/png.latex?%5Cpi_1">, and one with <img src="https://latex.codecogs.com/png.latex?n_%7B2+%7D"> attempts and success probability <img src="https://latex.codecogs.com/png.latex?%5Cpi_2">. The null hypothesis is that <img src="https://latex.codecogs.com/png.latex?%5Cpi_1%20=%20%5Cpi_2">. That is, <img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign*%7D%0AH_0~:~%20&amp;%20n_%7B11%7D%20%5Csim%20%5Ctextrm%7BBinomial%7D(n_%7B1+%7D,%20%5Cpi),%20%5C%5C%0A%20%20%20%20%20%20%20&amp;%20n_%7B21%7D%20%5Csim%20%5Ctextrm%7BBinomial%7D(n_%7B2+%7D,%20%5Cpi),%0A%5Cend%7Balign*%7D"> with some <img src="https://latex.codecogs.com/png.latex?%5Cpi%20%5Cin%20%5B0,1%5D"> that is common to both binomial distributions. This <img src="https://latex.codecogs.com/png.latex?%5Cpi"> parameter is known as a <strong>nuisance parameter</strong>: its value is unknown and not of primary interest, but if we want to carry out an unconditional test, we need to somehow take it into account.</p>
<p>An unconditional exact test for the fixed row marginals design that is often recommended is <strong>Boschloo’s test</strong> (Boschloo 1970). The idea behind this test is as follows. First, we define a test statistic that captures the extent to which observed contingency tables differ from the contingency table you’d expect to find under the null hypothesis, given <img src="https://latex.codecogs.com/png.latex?n_%7B1+%7D">, <img src="https://latex.codecogs.com/png.latex?n_%7B2+%7D"> and some candidate value for <img src="https://latex.codecogs.com/png.latex?%5Cpi">. Second, for each table that we could have observed, we compute both how likely it was to occur (this depends on <img src="https://latex.codecogs.com/png.latex?n_%7B1+%7D">, <img src="https://latex.codecogs.com/png.latex?n_%7B2+%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Cpi">) and the test statistic it would have resulted in. Third, using the results of these calculations, we compute the probability that we would observe a test statistic at least as extreme as the test statistic that we actually did observe under the null hypothesis and for the given <img src="https://latex.codecogs.com/png.latex?n_%7B1+%7D,%20n_%7B2+%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Cpi"> values. This probability is a <img src="https://latex.codecogs.com/png.latex?p">-value conditional on the <img src="https://latex.codecogs.com/png.latex?%5Cpi"> value considered. We repeat this procedure for different <img src="https://latex.codecogs.com/png.latex?%5Cpi"> values – say, for 101 equally spaced <img src="https://latex.codecogs.com/png.latex?%5Cpi"> values in the interval <img src="https://latex.codecogs.com/png.latex?%5B0,%201%5D">. Our unconditional exact <img src="https://latex.codecogs.com/png.latex?p">-value is now the maximum of the 101 values so computed. (Theoretically, it should be the supremum of the <img src="https://latex.codecogs.com/png.latex?p">-values when varying <img src="https://latex.codecogs.com/png.latex?%5Cpi"> over the entire <img src="https://latex.codecogs.com/png.latex?%5B0,1%5D"> interval. But the maximum of the 101 <img src="https://latex.codecogs.com/png.latex?p">-values compute will be close enough to this supremum.) In Boschloo’s test, the test statistic used is in fact the one-sided <img src="https://latex.codecogs.com/png.latex?p">-value obtained from Fisher’s exact test. But this <img src="https://latex.codecogs.com/png.latex?p">-value is used as a test statistic, not as a <img src="https://latex.codecogs.com/png.latex?p">-value in its own right.</p>
<p>Let’s walk through the computation step by step. First, we run a one-sided Fisher’s exact test in order to obtain the observed test statistic:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">(obs_test_stat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fisher.test</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</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;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"greater"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.09651366</code></pre>
</div>
</div>
<p>Next, we create a grid with all possible combinations of <img src="https://latex.codecogs.com/png.latex?(n_%7B11%7D,%20n_%7B21%7D)"> entries that we could have observed:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">n_row1 <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;">12</span></span>
<span id="cb13-2">n_row2 <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;">12</span></span>
<span id="cb13-3">tables <span class="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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n11 =</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>n_row1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n21 =</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>n_row2)</span></code></pre></div></div>
</div>
<p>We now fix some <img src="https://latex.codecogs.com/png.latex?%5Cpi%20%5Cin%20%5B0,%201%5D">, for instance, <img src="https://latex.codecogs.com/png.latex?%5Cpi%20=%200.43">. For each possible table, we compute how likely it would have been to observe this table if <img src="https://latex.codecogs.com/png.latex?%5Cpi%20=%200.43">. For instance, the 61st row in the grid corresponds to the table</p>
<img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Barray%7D%7Bl%7Ccc%7D%0A%20%20&amp;%20%5Ctextrm%7BPass%7D%20%20&amp;%20%5Ctextrm%7BFail%7D%20%20%5C%5C%0A%20%20%5Chline%0A%20%20%5Ctextrm%7BNew%20course%7D%20&amp;%208%20%20%20%20%20%20%20%20%20&amp;%204%20%5C%5C%0A%20%20%5Ctextrm%7BOld%20course%7D%20&amp;%206%20%20%20%20%20%20%20%20%20&amp;%206%20%5C%5C%0A%5Cend%7Barray%7D">
<p>The probability of observing the first row is given by the probability mass of <img src="https://latex.codecogs.com/png.latex?k%20=%208"> under a Binomial(12, 0.43) distribution; the probability of observing the second row is given by the probability mass of <img src="https://latex.codecogs.com/png.latex?k%20=%206">, also under a Binomial(12, 0.43) distribution. So the probability of observing this table is the product of these two probabilities:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dbinom</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.43</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;">dbinom</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.43</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.01223444</code></pre>
</div>
</div>
<p>We compute this probability for all 169 tables:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1">tables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>probability <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dbinom</span>(tables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n11, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.43</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;">dbinom</span>(tables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n21, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.43</span>)</span></code></pre></div></div>
</div>
<p>For each table, we also compute the test statistic:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1">tables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>test_statistic <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span></span>
<span id="cb17-2"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(tables)) {</span>
<span id="cb17-3">  current_table <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(tables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n11[i], <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> tables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n11[i]),</span>
<span id="cb17-4">                         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(tables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n21[i], <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> tables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n21[i]))</span>
<span id="cb17-5">  tables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>test_statistic[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fisher.test</span>(current_table, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"greater"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value</span>
<span id="cb17-6">}</span></code></pre></div></div>
</div>
<p>We can now compute the probability that we’d observe a test statistic at least as extreme as the test statistic associated with the table we actually observed, assuming the null hypothesis is true and <img src="https://latex.codecogs.com/png.latex?%5Cpi%20=%200.43">. Since the <img src="https://latex.codecogs.com/png.latex?p">-value produced by Fisher’s exact test is smaller for tables that are more surprising under the null hypothesis, ‘at least as extreme’ corresponds to ‘at most as large’. We can compute the figure we’re interested in by computing the proportion of tables resulting in test statistics no larger than the one we observed but weighted by their probability of occurring under the assumption that <img src="https://latex.codecogs.com/png.latex?%5Cpi%20=%200.43">:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(tables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>test_statistic <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> obs_test_stat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> tables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>probability)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.04312598</code></pre>
</div>
</div>
<p>Assuming <img src="https://latex.codecogs.com/png.latex?%5Cpi%20=%200.43">, the resulting <img src="https://latex.codecogs.com/png.latex?p">-value is hence <img src="https://latex.codecogs.com/png.latex?0.043">. We repeat this procedure for different candidate values of <img src="https://latex.codecogs.com/png.latex?%5Cpi">. The <img src="https://latex.codecogs.com/png.latex?p">-value of Boschloo’s test is then the maximum of the resulting <img src="https://latex.codecogs.com/png.latex?p">-values. In this specific example, the maximum <img src="https://latex.codecogs.com/png.latex?p">-value is <img src="https://latex.codecogs.com/png.latex?p%20=%200.0495">, which is obtained for <img src="https://latex.codecogs.com/png.latex?%5Cpi%20=%200.68">; see Figure&nbsp;3.</p>
<div class="cell preview-image">
<div class="cell-output-display">
<div id="fig-boschloo" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-boschloo-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://janhove.github.io/posts/2024-09-10-contingency-p-value/index_files/figure-html/fig-boschloo-1.svg" class="img-fluid figure-img" style="width:66.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-boschloo-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: In Boschloo’s test, a <img src="https://latex.codecogs.com/png.latex?p">-value is computed for each candidate value of <img src="https://latex.codecogs.com/png.latex?%5Cpi">. The test then outputs the maximum of these <img src="https://latex.codecogs.com/png.latex?p">-values.
</figcaption>
</figure>
</div>
</div>
</div>
<p>If our alternative hypothesis were that the new programme produced worse results than the old one, we’d have used the left-sided <img src="https://latex.codecogs.com/png.latex?p">-value of Fisher’s exact test as the test statistic in Boschloo’s procedure. A two-sided <img src="https://latex.codecogs.com/png.latex?p">-value can be obtained by carrying out Boschloo’s test once using the right-sided <img src="https://latex.codecogs.com/png.latex?p">-value of Fisher’s exact test as the test statistic and once using the left-sided <img src="https://latex.codecogs.com/png.latex?p">-value, and then doubling the smaller of the two resulting <img src="https://latex.codecogs.com/png.latex?p">-values.</p>
<p>To run Boschloo’s test, you can use the following <code>boschloo_test()</code> function:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1">boschloo_test <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>(tab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"two.sided"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pi_range =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stepsize =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>) {</span>
<span id="cb20-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This test assumes fixed row sums.</span></span>
<span id="cb20-3">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Nuisance parameter values in the interval pi_range are tried out.</span></span>
<span id="cb20-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># stepsize governs granularity of search through nuisance parameter value candidates.</span></span>
<span id="cb20-5">  </span>
<span id="cb20-6">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dim</span>(tab) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stop</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tab needs to be a 2*2 contingency table."</span>)</span>
<span id="cb20-7">  </span>
<span id="cb20-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (alternative <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;">"two.sided"</span>) {</span>
<span id="cb20-9">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Truncate two-sided p-value at 1</span></span>
<span id="cb20-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(</span>
<span id="cb20-11">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boschloo_test</span>(tab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"less"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pi_range =</span> pi_range, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stepsize =</span> stepsize),</span>
<span id="cb20-12">                  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boschloo_test</span>(tab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"greater"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pi_range =</span> pi_range, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stepsize =</span> stepsize)), </span>
<span id="cb20-13">          <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb20-14">      )</span>
<span id="cb20-15">  }</span>
<span id="cb20-16">  </span>
<span id="cb20-17">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Use Fisher's exact test p-value as test statistic</span></span>
<span id="cb20-18">  statistic <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fisher.test</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> alternative)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value</span>
<span id="cb20-19">  </span>
<span id="cb20-20">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Construct grid with possible results</span></span>
<span id="cb20-21">  row_sums <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rowSums</span>(tab)</span>
<span id="cb20-22">  my_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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n1 =</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>row_sums[<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;">n2 =</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>row_sums[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb20-23">  my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>statistic <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span></span>
<span id="cb20-24">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(my_grid)) {</span>
<span id="cb20-25">    my_tab <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n1[i], row_sums[<span class="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> my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n1[i]),</span>
<span id="cb20-26">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n2[i], row_sums[<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> my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n2[i]))</span>
<span id="cb20-27">    my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>statistic[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">statistic</span>(my_tab)</span>
<span id="cb20-28">  }</span>
<span id="cb20-29">  </span>
<span id="cb20-30">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Compute observed test statistic</span></span>
<span id="cb20-31">  obs_p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">statistic</span>(tab)</span>
<span id="cb20-32">  is_extreme <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>statistic <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> obs_p</span>
<span id="cb20-33">  </span>
<span id="cb20-34">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Maximise p-value over range</span></span>
<span id="cb20-35">  pis <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(pi_range[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], pi_range[<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;">by =</span> stepsize)</span>
<span id="cb20-36">  max_p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb20-37">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (current_pi <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> pis) {</span>
<span id="cb20-38">    current_p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> is_extreme,</span>
<span id="cb20-39">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dbinom</span>(my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n1, row_sums[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], current_pi) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> </span>
<span id="cb20-40">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dbinom</span>(my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n2, row_sums[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>], current_pi))</span>
<span id="cb20-41">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (current_p <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> max_p) max_p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> current_p</span>
<span id="cb20-42">  }</span>
<span id="cb20-43">  max_p</span>
<span id="cb20-44">}</span></code></pre></div></div>
</div>
<p>It works like so:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boschloo_test</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tab =</span> tab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"greater"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.04954898</code></pre>
</div>
</div>
<p>Alternatively, you can use the <code>boschloo()</code> function in the <a href="https://cran.r-project.org/web/packages/exact2x2/index.html"><code>exact2x2</code> package</a>. See <code>?boschloo</code> for details on the parameters. Here I specify the number of grid points (<code>nPgrid</code>) in order to make the results agree exactly with those produced by <code>boschloo_test()</code>:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1">exact2x2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boschloo</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</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;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"greater"</span>,</span>
<span id="cb23-2">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">control =</span> exact2x2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ucControl</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nPgrid =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">101</span>))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.04954898</code></pre>
</div>
</div>
</section>
<section id="contingency-tables-with-only-the-total-sum-fixed" class="level2">
<h2 class="anchored" data-anchor-id="contingency-tables-with-only-the-total-sum-fixed">Contingency tables with only the total sum fixed</h2>
<p>A third possibility is that neither the row sums (<img src="https://latex.codecogs.com/png.latex?n_%7B1+%7D,%20n_%7B2+%7D">) nor the column sums (<img src="https://latex.codecogs.com/png.latex?n_%7B+1%7D,%20n_%7B+2%7D">) are known beforehand but that the total number of observations (<img src="https://latex.codecogs.com/png.latex?n_%7B++%7D">) is. One general case where such contingency tables arise is in observational research in which two binary features are measured in a fixed number of randomly sampled units. A second general case is comprised of experiments that have a binary outcome variable and in which the participants are assigned to the conditions using simple randomisation so that the precise number of participants isn’t fixed in advance.</p>
<section id="observational-studies" class="level3">
<h3 class="anchored" data-anchor-id="observational-studies">Observational studies</h3>
<p><strong>Example 4</strong> (Boschloo’s test)<strong>.</strong> During a hike through the Fribourg Prealpes near <a href="https://www.myswitzerland.com/en-ch/destinations/schwarzsee/">Schwarzsee</a>, we conduct a linguistic field experiment. Any time we encounter a hiking party chatting in French, we greet them in German; any time we encounter a hiking party chatting in German, we greet them in French. Afterwards, we jot down for each party whether the first person greeting us back did so in the same language in which they were addressed or in a different language. (Parties not chatting in French or German are ignored in this field experiment.) We planned to continue the field experiment until we’ve encountered the 20th French- or German-speaking hiking party. Here’s the resulting contingency table:</p>
<img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Barray%7D%7Bl%7Ccc%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&amp;%20%5Ctextrm%7BSame%20language%7D%20%20&amp;%20%5Ctextrm%7BDifferent%20language%7D%20%20%5C%5C%0A%20%20%5Chline%0A%20%20%5Ctextrm%7BFrench-speaking%20party%7D%20&amp;%202%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&amp;%206%20%5C%5C%0A%20%20%5Ctextrm%7BGerman-speaking%20party%7D%20&amp;%208%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&amp;%204%20%5C%5C%0A%5Cend%7Barray%7D">
<p>Note that only the total number of observations (<img src="https://latex.codecogs.com/png.latex?n_%7B++%7D%20=%2020">) was known beforehand.</p>
<p>The null hypothesis is that whether the first greeter in the party responded in the same language or in a different language is independent of the language in which the party was chatting. More formally, let <img src="https://latex.codecogs.com/png.latex?%5Cpi_%7B%5Ctextrm%7Brow%7D%7D"> be the probability that a randomly encountered French- or German-speaking party is French-speaking and let <img src="https://latex.codecogs.com/png.latex?%5Cpi_%7B%5Ctextrm%7Bcol%7D%7D"> be the probability that the first greeter in a French- or German-speaking party responds in the same language. Then our null hypothesis is</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign*%7D%0AH_0~:~&amp;%5Cmathbb%7BP%7D(%5Ctextrm%7Bis%20French-speaking%20and%20responds%20in%20same%20language%7D)%20=%20%5Cpi_%7B%5Ctextrm%7Brow%7D%7D%5Cpi_%7B%5Ctextrm%7Bcol%7D%7D,%20%5C%5C%0A%20%20%20%20%20%20&amp;%5Cmathbb%7BP%7D(%5Ctextrm%7Bis%20French-speaking%20and%20responds%20in%20different%20language%7D)%20=%20%5Cpi_%7B%5Ctextrm%7Brow%7D%7D(1-%5Cpi_%7B%5Ctextrm%7Bcol%7D%7D),%20%5C%5C%0A%20%20%20%20%20%20&amp;%5Cmathbb%7BP%7D(%5Ctextrm%7Bis%20German-speaking%20and%20responds%20in%20same%20language%7D)%20=%20(1-%5Cpi_%7B%5Ctextrm%7Brow%7D%7D)%5Cpi_%7B%5Ctextrm%7Bcol%7D%7D,%20%5C%5C%0A%20%20%20%20%20%20&amp;%5Cmathbb%7BP%7D(%5Ctextrm%7Bis%20German-speaking%20and%20responds%20in%20different%20language%7D)%20=%20(1-%5Cpi_%7B%5Ctextrm%7Brow%7D%7D)(1-%5Cpi_%7B%5Ctextrm%7Bcol%7D%7D).%0A%5Cend%7Balign*%7D"></p>
<p>More compactly, our null hypothesis is that the tuple <img src="https://latex.codecogs.com/png.latex?(n_%7B11%7D,%20n_%7B12%7D,%20n_%7B21%7D,%20n_%7B22%7D)"> is multinomially distributed with the probabilities above, i.e.,</p>
<p><img src="https://latex.codecogs.com/png.latex?H_0~:~(n_%7B11%7D,%20n_%7B12%7D,%20n_%7B21%7D,%20n_%7B22%7D)%20%5Csim%20%5Ctextrm%7BMultinomial%7D(20,%20%5Cpi_%7B%5Ctextrm%7Brow%7D%7D%5Cpi_%7B%5Ctextrm%7Bcol%7D%7D,%5Cpi_%7B%5Ctextrm%7Brow%7D%7D(1-%5Cpi_%7B%5Ctextrm%7Bcol%7D%7D),(1-%5Cpi_%7B%5Ctextrm%7Brow%7D%7D)%5Cpi_%7B%5Ctextrm%7Bcol%7D%7D,%20(1-%5Cpi_%7B%5Ctextrm%7Brow%7D%7D)(1-%5Cpi_%7B%5Ctextrm%7Bcol%7D%7D)),"> for some unknown <img src="https://latex.codecogs.com/png.latex?%5Cpi_%7B%5Ctextrm%7Brow%7D%7D,%20%5Cpi_%7B%5Ctextrm%7Bcol%7D%7D%20%5Cin%20%5B0,1%5D">.</p>
<p>In terms of the analysis, we could condition on both marginals or on one of them and run Fisher’s or Boschloo’s test, respectively:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1">tab <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</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;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>))</span>
<span id="cb25-2"></span>
<span id="cb25-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Condition on both marginals</span></span>
<span id="cb25-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fisher.test</span>(tab)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.1698023</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Condition on row marginals only</span></span>
<span id="cb27-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boschloo_test</span>(tab)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.08332351</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Condition on column marginals only</span></span>
<span id="cb29-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boschloo_test</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(tab))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.08564046</code></pre>
</div>
</div>
<p>The resulting <img src="https://latex.codecogs.com/png.latex?p">-values are all valid. But like before, these tests only consider a part of the sample space: Fisher’s exact test only takes into account the nine tables where <img src="https://latex.codecogs.com/png.latex?n_%7B1+%7D%20=%208"> and <img src="https://latex.codecogs.com/png.latex?n_%7B+1%7D%20=%2010">; Boschloo’s test considers the <img src="https://latex.codecogs.com/png.latex?9%20%5Ccdot%2013%20=%20117"> tables where <img src="https://latex.codecogs.com/png.latex?n_%7B1+%7D%20=%208"> and <img src="https://latex.codecogs.com/png.latex?n_%7B2+%7D%20=%2012"> when conditioning on the row marginals and the <img src="https://latex.codecogs.com/png.latex?11%20%5Ccdot%2011%20=%20121"> tables where <img src="https://latex.codecogs.com/png.latex?n_%7B+1%7D%20=%20n_%7B+2%7D%20=%2010"> when conditioning on the column marginals. But the table observed is in actual fact one of <img src="https://latex.codecogs.com/png.latex?%5Csum_%7Bi%20=%200%7D%5E%7B20%7D%5Csum_%7Bj%20=%200%7D%5E%7B20-i%7D%5Csum_%7Bk=%200%7D%5E%7B20-i-j%7D1%20=%201771"> tables where <img src="https://latex.codecogs.com/png.latex?n_%7B++%7D%20=%2020">.</p>
<p>One possible solution is to generalise Boschloo’s test to two nuisance parameters. That is, rather computing a <img src="https://latex.codecogs.com/png.latex?p">-value for each candidate value of <img src="https://latex.codecogs.com/png.latex?%5Cpi%20%5Cin%20%5B0,1%5D"> and then taking the maximum, we compute a <img src="https://latex.codecogs.com/png.latex?p">-value for each pair of candidate values of <img src="https://latex.codecogs.com/png.latex?(%5Cpi_%7B%5Ctextrm%7Brow%7D%7D,%20%5Cpi_%7B%5Ctextrm%7Bcol%7D%7D)%20%5Cin%20%5B0,1%5D%20%5Ctimes%20%5B0,1%5D">. The <code>unconditional_test()</code> function defined below carries out this procedure:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1">unconditional_test <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(</span>
<span id="cb31-2">    tab, </span>
<span id="cb31-3">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"two.sided"</span>, </span>
<span id="cb31-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pi_range_row =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), </span>
<span id="cb31-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pi_range_col =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb31-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stepsize =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>)</span>
<span id="cb31-7">  {</span>
<span id="cb31-8">  </span>
<span id="cb31-9">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This test assumes a fixed total sum.</span></span>
<span id="cb31-10">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Nuisance parameter values in the rectangle pi_range_row * pi_range_col are tried out.</span></span>
<span id="cb31-11">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># stepsize governs granularity of search through nuisance parameter value candidates.</span></span>
<span id="cb31-12">  </span>
<span id="cb31-13">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dim</span>(tab) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stop</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tab needs to be a 2*2 contingency table."</span>)</span>
<span id="cb31-14">  </span>
<span id="cb31-15">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (alternative <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;">"two.sided"</span>) {</span>
<span id="cb31-16">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Truncate two-sided p-value at 1</span></span>
<span id="cb31-17">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(</span>
<span id="cb31-18">      <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unconditional_test</span>(tab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"less"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stepsize =</span> stepsize),</span>
<span id="cb31-19">              <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unconditional_test</span>(tab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"greater"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stepsize =</span> stepsize)),</span>
<span id="cb31-20">      <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb31-21">  }</span>
<span id="cb31-22">  </span>
<span id="cb31-23">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Use Fisher's exact test p-value as test statistic</span></span>
<span id="cb31-24">  statistic <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fisher.test</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> alternative)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value</span>
<span id="cb31-25">  </span>
<span id="cb31-26">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Helper function for multinomial weights</span></span>
<span id="cb31-27">  weights <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>(pi_row, pi_col, n11, n12, n21, n22) {</span>
<span id="cb31-28">    total_sum <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> n11 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> n12 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> n21 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> n22</span>
<span id="cb31-29">    (pi_row<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pi_col)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>n11 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (pi_row <span 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> pi_col))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>n12 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span></span>
<span id="cb31-30">      ((<span class="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> pi_row)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pi_col)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>n21 <span 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> pi_row)<span 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> pi_col))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>n22 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> </span>
<span id="cb31-31">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factorial</span>(total_sum)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factorial</span>(n11) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factorial</span>(n12) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factorial</span>(n21) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factorial</span>(n22))</span>
<span id="cb31-32">  }</span>
<span id="cb31-33">  </span>
<span id="cb31-34">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Construct grid with possible results</span></span>
<span id="cb31-35">  total_sum <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(tab)</span>
<span id="cb31-36">  my_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 class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n11 =</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>total_sum, </span>
<span id="cb31-37">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n12 =</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>total_sum,</span>
<span id="cb31-38">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n21 =</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>total_sum)</span>
<span id="cb31-39">  my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n22 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> total_sum <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n11 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n12 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n21</span>
<span id="cb31-40">  my_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;">subset</span>(my_grid, n22 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb31-41">  my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>statistic <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span></span>
<span id="cb31-42">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(my_grid)) {</span>
<span id="cb31-43">    my_tab <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n11[i], my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n12[i]),</span>
<span id="cb31-44">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n21[i], my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n22[i]))</span>
<span id="cb31-45">    my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>statistic[i] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">statistic</span>(my_tab)</span>
<span id="cb31-46">  }</span>
<span id="cb31-47">  my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>statistic[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>statistic)] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb31-48"></span>
<span id="cb31-49">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Compute observed test statistic</span></span>
<span id="cb31-50">  obs_p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">statistic</span>(tab)</span>
<span id="cb31-51">  is_lower <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>statistic <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> obs_p</span>
<span id="cb31-52">  </span>
<span id="cb31-53">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Maximise p value over grid</span></span>
<span id="cb31-54">  pis <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand.grid</span>(</span>
<span id="cb31-55">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pi_row =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(pi_range_row[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], pi_range_row[<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;">by =</span> stepsize),</span>
<span id="cb31-56">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pi_col =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(pi_range_col[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], pi_range_col[<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;">by =</span> stepsize)</span>
<span id="cb31-57">  )</span>
<span id="cb31-58">  max_p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb31-59">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(pis)) {</span>
<span id="cb31-60">    w <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weights</span>(pis<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pi_row[i], pis<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>pi_col[i], </span>
<span id="cb31-61">                 my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n11, my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n12, my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n21, my_grid<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n22)</span>
<span id="cb31-62">    current_p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">weighted.mean</span>(is_lower, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">w =</span> w)</span>
<span id="cb31-63">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (current_p <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> max_p) max_p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> current_p</span>
<span id="cb31-64">  }</span>
<span id="cb31-65">  </span>
<span id="cb31-66">  max_p</span>
<span id="cb31-67">}</span></code></pre></div></div>
</div>
<p>While it takes noticeably longer to run this test, it should be a bit more powerful than the tests that condition on one or both marginals:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unconditional_test</span>(tab)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.07469479</code></pre>
</div>
</div>
<p>The <code>exact.test()</code> function in the <a href="https://cran.r-project.org/package=Exact"><code>Exact</code></a> also implements this procedure. For one-sided tests (i.e., <code>alternative = "less"</code> or <code>"greater"</code>), it produces the same <img src="https://latex.codecogs.com/png.latex?p">-values as <code>unconditional_test()</code>, but it computes the two-sided <img src="https://latex.codecogs.com/png.latex?p">-value differently:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1">Exact<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exact.test</span>(tab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">model =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"multinomial"</span>,</span>
<span id="cb34-2">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">npNumber =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">101</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ref.pvalue =</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;">method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"boschloo"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.1139588</code></pre>
</div>
</div>
</section>
<section id="experiments-with-simple-randomisation" class="level3">
<h3 class="anchored" data-anchor-id="experiments-with-simple-randomisation">Experiments with simple randomisation</h3>
<p><strong>Example 5</strong> (Boschloo’s test)<strong>.</strong> We conduct the same experiment as in Example 3, but with one change: We assign the participants to the conditions using simple randomisation rather than using complete randomisation. Hence, we’re not guaranteed to have exactly 12 participants in each condition, and the row marginals aren’t fixed in advance. For the sake of comparison, let’s assume we obtain the same results as in Example 3:</p>
<img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Barray%7D%7Bl%7Ccc%7D%0A%20%20&amp;%20%5Ctextrm%7BPass%7D%20%20&amp;%20%5Ctextrm%7BFail%7D%20%20%5C%5C%0A%20%20%5Chline%0A%20%20%5Ctextrm%7BNew%20course%7D%20&amp;%2010%20%20%20%20%20%20%20%20&amp;%202%20%5C%5C%0A%20%20%5Ctextrm%7BOld%20course%7D%20&amp;%206%20%20%20%20%20%20%20%20%20&amp;%206%20%5C%5C%0A%5Cend%7Barray%7D">
<p>We could again condition on the row marginals:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1">tab <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</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;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb36-2">             <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;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>))</span>
<span id="cb36-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boschloo_test</span>(tab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"greater"</span>)      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># condition on row marginals</span></span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.04954898</code></pre>
</div>
</div>
<p>Alternatively, we could run an unconditional test. Note, however that while <img src="https://latex.codecogs.com/png.latex?n_%7B1+%7D"> and <img src="https://latex.codecogs.com/png.latex?n_%7B2+%7D"> weren’t fixed by design, <img src="https://latex.codecogs.com/png.latex?%5Cpi_%7B%5Ctextrm%7Brow%7D%7D"> is known to be <img src="https://latex.codecogs.com/png.latex?0.5">. Hence, we don’t need to iterate through different candidate values for <img src="https://latex.codecogs.com/png.latex?%5Cpi_%7B%5Ctextrm%7Brow%7D%7D">:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unconditional_test</span>(tab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"greater"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pi_range_row =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.04364773</code></pre>
</div>
</div>
</section>
</section>
<section id="contingency-tables-with-nothing-fixed" class="level2">
<h2 class="anchored" data-anchor-id="contingency-tables-with-nothing-fixed">Contingency tables with nothing fixed</h2>
<p>Contingency tables where not even <img src="https://latex.codecogs.com/png.latex?n_%7B++%7D"> is fixed are mentioned by Fagerland et al.&nbsp;(2017) but not discussed in any detail. An analysis that conditions on the observed <img src="https://latex.codecogs.com/png.latex?n_%7B++%7D"> seems reasonable.</p>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<p>Boschloo, R. D. 1970. <a href="https://doi.org/10.1111%2Fj.1467-9574.1970.tb00104.x">Raised conditional level of significance for the 2 × 2 table when testing the equality of two probabilities.</a> <em>Statistica Neerlandica</em> 24. 1-35.</p>
<p>Fagerland, Morten W., Stian Lydersen &amp; Petter Laake. 2017. <a href="https://doi.org/10.1201/9781315374116"><em>Statistical analysis of contingency tables</em>.</a> Boca Raton, FL: Chapman and Hall/CRC.</p>
<p>Lydersen, Stian, Morten W. Fagerland &amp; Petter Laake. 2009. <a href="https://doi.org.10.1002/sim.3531">Recommended tests for association in 2 × 2 tables.</a> <em>Statistics in Medicine</em> 28. 1159-1175.</p>


</section>

 ]]></description>
  <category>R</category>
  <category>significance</category>
  <guid>https://janhove.github.io/posts/2024-09-10-contingency-p-value/</guid>
  <pubDate>Tue, 10 Sep 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>New and updated teaching resources</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2024-09-04-updated-resources/</link>
  <description><![CDATA[ 




<p>This is just a quick blog post to let you know that I’ve added a few entries to the <a href="../../resources.html">Teaching resources</a> page and updated a few others:</p>
<ul>
<li>I’ve added more exercises to the <a href="../../resources.html#quantitative-methodology-an-introduction"><em>Quantitative methodology</em></a> script, and I’ve embedded the reading assignments into the lecture chapters.</li>
<li>I’ve taught another summer school course on the general linear model and I’ve updated the <a href="../../resources.html#introduction-to-the-general-linear-model">script</a> accordingly.</li>
<li>I’ve taught a crash course on working with datasets in R and another on visualising data. Both the scripts and datasets can be accessed on the <a href="../../resources.html#working-with-datasets-and-visualising-data-in-r-two-primers">Teaching resources</a> page.</li>
<li>I’ve substantially revised the German-language introduction to quantitative data (<a href="../../resources.html#einführung-in-die-quantitative-datenanalyse"><em>Einführung in die quantitative Datenanalyse</em></a>).</li>
</ul>



 ]]></description>
  <category>teaching materials</category>
  <guid>https://janhove.github.io/posts/2024-09-04-updated-resources/</guid>
  <pubDate>Wed, 04 Sep 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Adjusting to Julia: Piecewise regression</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2023-03-07-julia-breakpoint-regression/</link>
  <description><![CDATA[ 




<p>In this fourth installment of <em>Adjusting to <a href="https://julialang.org/">Julia</a></em>, I will at long last analyse some actual data. One of the first posts on this blog was <a href="../2014-08-20-adjusted-pvalues-breakpoint-regression">Calibrating p-values in ‘flexible’ piecewise regression models</a>. In that post, I fitted a piecewise regression to a dataset comprising the ages at which a number of language learners started learning a second language (age of acquisition, AOA) and their scores on a grammaticality judgement task (GJT) in that second language. A piecewise regression is a regression model in which the slope of the function relating the predictor (here: AOA) to the outcome (here: GJT) changes at some value of the predictor, the so-called breakpoint. The problem, however, was that I didn’t specify the breakpoint beforehand but pick the breakpoint that minimised the model’s deviance. This increased the probability that I would find that the slope before and after the breakpoint differed, even if they in fact were the same. In the blog post I wrote almost nine years ago, I sought to recalibrate the p-value for the change in slope by running a bunch of simulations in R. In this blog post, I’ll do the same, but in Julia.</p>
<section id="the-data-set" class="level2">
<h2 class="anchored" data-anchor-id="the-data-set">The data set</h2>
<p>We’ll work with the data from the North America study conducted by <a href="https://doi.org/10.1017/S0142716410000056">DeKeyser et al.&nbsp;(2010)</a>. If you want to follow along, you can download this dataset <a href="https://janhove.github.io/datasets/dekeyser2010.csv">here</a> and save it to a subdirectory called <code>data</code> in your working directory.</p>
<p>We need the <code>DataFrames</code>, <code>CSV</code> and <code>StatsPlots</code> packages in order to read in the CSV with the dataset as a data frame and draw some basic graphs.</p>
<div id="3213b34c" class="cell" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">using</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">DataFrames</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">CSV</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">StatsPlots</span></span>
<span id="cb1-2"></span>
<span id="cb1-3">d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> CSV.<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data/dekeyser2010.csv"</span>, DataFrame);</span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@df</span> d <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>AOA, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>GJT</span>
<span id="cb1-6">           , seriestype <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>scatter</span>
<span id="cb1-7">           , legend <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>none</span>
<span id="cb1-8">           , xlabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AOA"</span></span>
<span id="cb1-9">           , ylabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GJT"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="2">
<!--?xml version="1.0" encoding="utf-8"?-->
<svg xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" width="672" height="480" viewbox="0 0 2688 1920">
<defs>
  <clippath id="clip920">
    <rect x="0" y="0" width="2688" height="1920"></rect>
  </clippath>
</defs>
<path clip-path="url(#clip920)" d="M0 1920 L2688 1920 L2688 0 L0 0  Z" fill="#ffffff" fill-rule="evenodd" fill-opacity="1"></path>
<defs>
  <clippath id="clip921">
    <rect x="537" y="0" width="1883" height="1883"></rect>
  </clippath>
</defs>
<path clip-path="url(#clip920)" d="M240.4 1734.12 L2640.76 1734.12 L2640.76 47.2441 L240.4 47.2441  Z" fill="#ffffff" fill-rule="evenodd" fill-opacity="1"></path>
<defs>
  <clippath id="clip922">
    <rect x="240" y="47" width="2401" height="1688"></rect>
  </clippath>
</defs>
<polyline clip-path="url(#clip922)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="479.886,1734.12 479.886,47.2441 "></polyline>
<polyline clip-path="url(#clip922)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="822.99,1734.12 822.99,47.2441 "></polyline>
<polyline clip-path="url(#clip922)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="1166.09,1734.12 1166.09,47.2441 "></polyline>
<polyline clip-path="url(#clip922)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="1509.2,1734.12 1509.2,47.2441 "></polyline>
<polyline clip-path="url(#clip922)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="1852.3,1734.12 1852.3,47.2441 "></polyline>
<polyline clip-path="url(#clip922)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="2195.41,1734.12 2195.41,47.2441 "></polyline>
<polyline clip-path="url(#clip922)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="2538.51,1734.12 2538.51,47.2441 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,1734.12 2640.76,1734.12 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="479.886,1734.12 479.886,1715.22 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="822.99,1734.12 822.99,1715.22 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="1166.09,1734.12 1166.09,1715.22 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="1509.2,1734.12 1509.2,1715.22 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="1852.3,1734.12 1852.3,1715.22 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="2195.41,1734.12 2195.41,1715.22 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="2538.51,1734.12 2538.51,1715.22 "></polyline>
<path clip-path="url(#clip920)" d="M454.574 1794.89 L462.213 1794.89 L462.213 1768.52 L453.903 1770.19 L453.903 1765.93 L462.167 1764.26 L466.842 1764.26 L466.842 1794.89 L474.481 1794.89 L474.481 1798.82 L454.574 1798.82 L454.574 1794.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M493.926 1767.34 Q490.315 1767.34 488.486 1770.9 Q486.68 1774.45 486.68 1781.58 Q486.68 1788.68 488.486 1792.25 Q490.315 1795.79 493.926 1795.79 Q497.56 1795.79 499.365 1792.25 Q501.194 1788.68 501.194 1781.58 Q501.194 1774.45 499.365 1770.9 Q497.56 1767.34 493.926 1767.34 M493.926 1763.64 Q499.736 1763.64 502.791 1768.24 Q505.87 1772.83 505.87 1781.58 Q505.87 1790.3 502.791 1794.91 Q499.736 1799.49 493.926 1799.49 Q488.116 1799.49 485.037 1794.91 Q481.981 1790.3 481.981 1781.58 Q481.981 1772.83 485.037 1768.24 Q488.116 1763.64 493.926 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M801.764 1794.89 L818.083 1794.89 L818.083 1798.82 L796.139 1798.82 L796.139 1794.89 Q798.801 1792.13 803.384 1787.5 Q807.991 1782.85 809.171 1781.51 Q811.416 1778.98 812.296 1777.25 Q813.199 1775.49 813.199 1773.8 Q813.199 1771.04 811.254 1769.31 Q809.333 1767.57 806.231 1767.57 Q804.032 1767.57 801.579 1768.34 Q799.148 1769.1 796.37 1770.65 L796.37 1765.93 Q799.194 1764.79 801.648 1764.21 Q804.102 1763.64 806.139 1763.64 Q811.509 1763.64 814.703 1766.32 Q817.898 1769.01 817.898 1773.5 Q817.898 1775.63 817.088 1777.55 Q816.301 1779.45 814.194 1782.04 Q813.616 1782.71 810.514 1785.93 Q807.412 1789.12 801.764 1794.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M837.898 1767.34 Q834.287 1767.34 832.458 1770.9 Q830.652 1774.45 830.652 1781.58 Q830.652 1788.68 832.458 1792.25 Q834.287 1795.79 837.898 1795.79 Q841.532 1795.79 843.338 1792.25 Q845.166 1788.68 845.166 1781.58 Q845.166 1774.45 843.338 1770.9 Q841.532 1767.34 837.898 1767.34 M837.898 1763.64 Q843.708 1763.64 846.763 1768.24 Q849.842 1772.83 849.842 1781.58 Q849.842 1790.3 846.763 1794.91 Q843.708 1799.49 837.898 1799.49 Q832.088 1799.49 829.009 1794.91 Q825.953 1790.3 825.953 1781.58 Q825.953 1772.83 829.009 1768.24 Q832.088 1763.64 837.898 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M1154.94 1780.19 Q1158.29 1780.9 1160.17 1783.17 Q1162.07 1785.44 1162.07 1788.77 Q1162.07 1793.89 1158.55 1796.69 Q1155.03 1799.49 1148.55 1799.49 Q1146.37 1799.49 1144.06 1799.05 Q1141.77 1798.64 1139.31 1797.78 L1139.31 1793.27 Q1141.26 1794.4 1143.57 1794.98 Q1145.89 1795.56 1148.41 1795.56 Q1152.81 1795.56 1155.1 1793.82 Q1157.41 1792.08 1157.41 1788.77 Q1157.41 1785.72 1155.26 1784.01 Q1153.13 1782.27 1149.31 1782.27 L1145.28 1782.27 L1145.28 1778.43 L1149.5 1778.43 Q1152.95 1778.43 1154.78 1777.06 Q1156.6 1775.67 1156.6 1773.08 Q1156.6 1770.42 1154.71 1769.01 Q1152.83 1767.57 1149.31 1767.57 Q1147.39 1767.57 1145.19 1767.99 Q1142.99 1768.4 1140.35 1769.28 L1140.35 1765.12 Q1143.02 1764.38 1145.33 1764.01 Q1147.67 1763.64 1149.73 1763.64 Q1155.05 1763.64 1158.15 1766.07 Q1161.26 1768.47 1161.26 1772.59 Q1161.26 1775.46 1159.61 1777.46 Q1157.97 1779.42 1154.94 1780.19 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M1180.93 1767.34 Q1177.32 1767.34 1175.49 1770.9 Q1173.69 1774.45 1173.69 1781.58 Q1173.69 1788.68 1175.49 1792.25 Q1177.32 1795.79 1180.93 1795.79 Q1184.57 1795.79 1186.37 1792.25 Q1188.2 1788.68 1188.2 1781.58 Q1188.2 1774.45 1186.37 1770.9 Q1184.57 1767.34 1180.93 1767.34 M1180.93 1763.64 Q1186.74 1763.64 1189.8 1768.24 Q1192.88 1772.83 1192.88 1781.58 Q1192.88 1790.3 1189.8 1794.91 Q1186.74 1799.49 1180.93 1799.49 Q1175.12 1799.49 1172.04 1794.91 Q1168.99 1790.3 1168.99 1781.58 Q1168.99 1772.83 1172.04 1768.24 Q1175.12 1763.64 1180.93 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M1497.37 1768.34 L1485.56 1786.78 L1497.37 1786.78 L1497.37 1768.34 M1496.14 1764.26 L1502.02 1764.26 L1502.02 1786.78 L1506.95 1786.78 L1506.95 1790.67 L1502.02 1790.67 L1502.02 1798.82 L1497.37 1798.82 L1497.37 1790.67 L1481.77 1790.67 L1481.77 1786.16 L1496.14 1764.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M1524.68 1767.34 Q1521.07 1767.34 1519.24 1770.9 Q1517.44 1774.45 1517.44 1781.58 Q1517.44 1788.68 1519.24 1792.25 Q1521.07 1795.79 1524.68 1795.79 Q1528.32 1795.79 1530.12 1792.25 Q1531.95 1788.68 1531.95 1781.58 Q1531.95 1774.45 1530.12 1770.9 Q1528.32 1767.34 1524.68 1767.34 M1524.68 1763.64 Q1530.49 1763.64 1533.55 1768.24 Q1536.63 1772.83 1536.63 1781.58 Q1536.63 1790.3 1533.55 1794.91 Q1530.49 1799.49 1524.68 1799.49 Q1518.87 1799.49 1515.8 1794.91 Q1512.74 1790.3 1512.74 1781.58 Q1512.74 1772.83 1515.8 1768.24 Q1518.87 1763.64 1524.68 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M1827 1764.26 L1845.36 1764.26 L1845.36 1768.2 L1831.28 1768.2 L1831.28 1776.67 Q1832.3 1776.32 1833.32 1776.16 Q1834.34 1775.97 1835.36 1775.97 Q1841.15 1775.97 1844.52 1779.15 Q1847.9 1782.32 1847.9 1787.73 Q1847.9 1793.31 1844.43 1796.41 Q1840.96 1799.49 1834.64 1799.49 Q1832.46 1799.49 1830.2 1799.12 Q1827.95 1798.75 1825.54 1798.01 L1825.54 1793.31 Q1827.63 1794.45 1829.85 1795 Q1832.07 1795.56 1834.55 1795.56 Q1838.55 1795.56 1840.89 1793.45 Q1843.23 1791.34 1843.23 1787.73 Q1843.23 1784.12 1840.89 1782.02 Q1838.55 1779.91 1834.55 1779.91 Q1832.67 1779.91 1830.8 1780.33 Q1828.95 1780.74 1827 1781.62 L1827 1764.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M1867.12 1767.34 Q1863.51 1767.34 1861.68 1770.9 Q1859.87 1774.45 1859.87 1781.58 Q1859.87 1788.68 1861.68 1792.25 Q1863.51 1795.79 1867.12 1795.79 Q1870.75 1795.79 1872.56 1792.25 Q1874.39 1788.68 1874.39 1781.58 Q1874.39 1774.45 1872.56 1770.9 Q1870.75 1767.34 1867.12 1767.34 M1867.12 1763.64 Q1872.93 1763.64 1875.98 1768.24 Q1879.06 1772.83 1879.06 1781.58 Q1879.06 1790.3 1875.98 1794.91 Q1872.93 1799.49 1867.12 1799.49 Q1861.31 1799.49 1858.23 1794.91 Q1855.17 1790.3 1855.17 1781.58 Q1855.17 1772.83 1858.23 1768.24 Q1861.31 1763.64 1867.12 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M2180.81 1779.68 Q2177.66 1779.68 2175.81 1781.83 Q2173.98 1783.98 2173.98 1787.73 Q2173.98 1791.46 2175.81 1793.64 Q2177.66 1795.79 2180.81 1795.79 Q2183.96 1795.79 2185.79 1793.64 Q2187.64 1791.46 2187.64 1787.73 Q2187.64 1783.98 2185.79 1781.83 Q2183.96 1779.68 2180.81 1779.68 M2190.09 1765.02 L2190.09 1769.28 Q2188.34 1768.45 2186.53 1768.01 Q2184.75 1767.57 2182.99 1767.57 Q2178.36 1767.57 2175.9 1770.7 Q2173.47 1773.82 2173.13 1780.14 Q2174.49 1778.13 2176.55 1777.06 Q2178.61 1775.97 2181.09 1775.97 Q2186.3 1775.97 2189.31 1779.15 Q2192.34 1782.29 2192.34 1787.73 Q2192.34 1793.06 2189.19 1796.27 Q2186.04 1799.49 2180.81 1799.49 Q2174.82 1799.49 2171.65 1794.91 Q2168.47 1790.3 2168.47 1781.58 Q2168.47 1773.38 2172.36 1768.52 Q2176.25 1763.64 2182.8 1763.64 Q2184.56 1763.64 2186.34 1763.98 Q2188.15 1764.33 2190.09 1765.02 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M2210.4 1767.34 Q2206.78 1767.34 2204.96 1770.9 Q2203.15 1774.45 2203.15 1781.58 Q2203.15 1788.68 2204.96 1792.25 Q2206.78 1795.79 2210.4 1795.79 Q2214.03 1795.79 2215.83 1792.25 Q2217.66 1788.68 2217.66 1781.58 Q2217.66 1774.45 2215.83 1770.9 Q2214.03 1767.34 2210.4 1767.34 M2210.4 1763.64 Q2216.21 1763.64 2219.26 1768.24 Q2222.34 1772.83 2222.34 1781.58 Q2222.34 1790.3 2219.26 1794.91 Q2216.21 1799.49 2210.4 1799.49 Q2204.58 1799.49 2201.51 1794.91 Q2198.45 1790.3 2198.45 1781.58 Q2198.45 1772.83 2201.51 1768.24 Q2204.58 1763.64 2210.4 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M2511.87 1764.26 L2534.09 1764.26 L2534.09 1766.25 L2521.54 1798.82 L2516.66 1798.82 L2528.46 1768.2 L2511.87 1768.2 L2511.87 1764.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M2553.21 1767.34 Q2549.6 1767.34 2547.77 1770.9 Q2545.96 1774.45 2545.96 1781.58 Q2545.96 1788.68 2547.77 1792.25 Q2549.6 1795.79 2553.21 1795.79 Q2556.84 1795.79 2558.65 1792.25 Q2560.48 1788.68 2560.48 1781.58 Q2560.48 1774.45 2558.65 1770.9 Q2556.84 1767.34 2553.21 1767.34 M2553.21 1763.64 Q2559.02 1763.64 2562.08 1768.24 Q2565.15 1772.83 2565.15 1781.58 Q2565.15 1790.3 2562.08 1794.91 Q2559.02 1799.49 2553.21 1799.49 Q2547.4 1799.49 2544.32 1794.91 Q2541.27 1790.3 2541.27 1781.58 Q2541.27 1772.83 2544.32 1768.24 Q2547.4 1763.64 2553.21 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M1393.77 1842.11 L1385.05 1865.76 L1402.53 1865.76 L1393.77 1842.11 M1390.15 1835.78 L1397.43 1835.78 L1415.54 1883.3 L1408.86 1883.3 L1404.53 1871.11 L1383.11 1871.11 L1378.78 1883.3 L1372 1883.3 L1390.15 1835.78 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M1440.63 1840.14 Q1433.62 1840.14 1429.49 1845.36 Q1425.38 1850.58 1425.38 1859.59 Q1425.38 1868.56 1429.49 1873.78 Q1433.62 1879 1440.63 1879 Q1447.63 1879 1451.7 1873.78 Q1455.81 1868.56 1455.81 1859.59 Q1455.81 1850.58 1451.7 1845.36 Q1447.63 1840.14 1440.63 1840.14 M1440.63 1834.92 Q1450.62 1834.92 1456.6 1841.64 Q1462.59 1848.32 1462.59 1859.59 Q1462.59 1870.82 1456.6 1877.54 Q1450.62 1884.22 1440.63 1884.22 Q1430.6 1884.22 1424.58 1877.54 Q1418.6 1870.86 1418.6 1859.59 Q1418.6 1848.32 1424.58 1841.64 Q1430.6 1834.92 1440.63 1834.92 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M1487.38 1842.11 L1478.66 1865.76 L1496.13 1865.76 L1487.38 1842.11 M1483.75 1835.78 L1491.04 1835.78 L1509.15 1883.3 L1502.47 1883.3 L1498.14 1871.11 L1476.72 1871.11 L1472.39 1883.3 L1465.61 1883.3 L1483.75 1835.78 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><polyline clip-path="url(#clip922)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,1415.5 2640.76,1415.5 "></polyline>
<polyline clip-path="url(#clip922)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,1076.91 2640.76,1076.91 "></polyline>
<polyline clip-path="url(#clip922)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,738.313 2640.76,738.313 "></polyline>
<polyline clip-path="url(#clip922)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,399.72 2640.76,399.72 "></polyline>
<polyline clip-path="url(#clip922)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,61.1264 2640.76,61.1264 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,1734.12 240.4,47.2441 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,1415.5 259.297,1415.5 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,1076.91 259.297,1076.91 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,738.313 259.297,738.313 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,399.72 259.297,399.72 "></polyline>
<polyline clip-path="url(#clip920)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,61.1264 259.297,61.1264 "></polyline>
<path clip-path="url(#clip920)" d="M118.622 1428.85 L126.261 1428.85 L126.261 1402.48 L117.951 1404.15 L117.951 1399.89 L126.214 1398.22 L130.89 1398.22 L130.89 1428.85 L138.529 1428.85 L138.529 1432.78 L118.622 1432.78 L118.622 1428.85 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M152.001 1428.85 L168.321 1428.85 L168.321 1432.78 L146.376 1432.78 L146.376 1428.85 Q149.038 1426.09 153.622 1421.46 Q158.228 1416.81 159.409 1415.47 Q161.654 1412.94 162.534 1411.21 Q163.436 1409.45 163.436 1407.76 Q163.436 1405 161.492 1403.27 Q159.571 1401.53 156.469 1401.53 Q154.27 1401.53 151.816 1402.29 Q149.386 1403.06 146.608 1404.61 L146.608 1399.89 Q149.432 1398.75 151.886 1398.17 Q154.339 1397.6 156.376 1397.6 Q161.747 1397.6 164.941 1400.28 Q168.135 1402.97 168.135 1407.46 Q168.135 1409.59 167.325 1411.51 Q166.538 1413.41 164.432 1416 Q163.853 1416.67 160.751 1419.89 Q157.649 1423.08 152.001 1428.85 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M188.135 1401.3 Q184.524 1401.3 182.696 1404.86 Q180.89 1408.41 180.89 1415.54 Q180.89 1422.64 182.696 1426.21 Q184.524 1429.75 188.135 1429.75 Q191.77 1429.75 193.575 1426.21 Q195.404 1422.64 195.404 1415.54 Q195.404 1408.41 193.575 1404.86 Q191.77 1401.3 188.135 1401.3 M188.135 1397.6 Q193.946 1397.6 197.001 1402.2 Q200.08 1406.79 200.08 1415.54 Q200.08 1424.26 197.001 1428.87 Q193.946 1433.45 188.135 1433.45 Q182.325 1433.45 179.247 1428.87 Q176.191 1424.26 176.191 1415.54 Q176.191 1406.79 179.247 1402.2 Q182.325 1397.6 188.135 1397.6 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M118.622 1090.25 L126.261 1090.25 L126.261 1063.89 L117.951 1065.55 L117.951 1061.29 L126.214 1059.63 L130.89 1059.63 L130.89 1090.25 L138.529 1090.25 L138.529 1094.19 L118.622 1094.19 L118.622 1090.25 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M160.821 1063.7 L149.015 1082.15 L160.821 1082.15 L160.821 1063.7 M159.594 1059.63 L165.473 1059.63 L165.473 1082.15 L170.404 1082.15 L170.404 1086.04 L165.473 1086.04 L165.473 1094.19 L160.821 1094.19 L160.821 1086.04 L145.219 1086.04 L145.219 1081.53 L159.594 1059.63 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M188.135 1062.71 Q184.524 1062.71 182.696 1066.27 Q180.89 1069.81 180.89 1076.94 Q180.89 1084.05 182.696 1087.61 Q184.524 1091.15 188.135 1091.15 Q191.77 1091.15 193.575 1087.61 Q195.404 1084.05 195.404 1076.94 Q195.404 1069.81 193.575 1066.27 Q191.77 1062.71 188.135 1062.71 M188.135 1059 Q193.946 1059 197.001 1063.61 Q200.08 1068.19 200.08 1076.94 Q200.08 1085.67 197.001 1090.27 Q193.946 1094.86 188.135 1094.86 Q182.325 1094.86 179.247 1090.27 Q176.191 1085.67 176.191 1076.94 Q176.191 1068.19 179.247 1063.61 Q182.325 1059 188.135 1059 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M118.622 751.658 L126.261 751.658 L126.261 725.293 L117.951 726.959 L117.951 722.7 L126.214 721.033 L130.89 721.033 L130.89 751.658 L138.529 751.658 L138.529 755.593 L118.622 755.593 L118.622 751.658 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M158.552 736.45 Q155.404 736.45 153.552 738.603 Q151.724 740.756 151.724 744.506 Q151.724 748.232 153.552 750.408 Q155.404 752.561 158.552 752.561 Q161.7 752.561 163.529 750.408 Q165.381 748.232 165.381 744.506 Q165.381 740.756 163.529 738.603 Q161.7 736.45 158.552 736.45 M167.835 721.797 L167.835 726.057 Q166.075 725.223 164.27 724.783 Q162.487 724.344 160.728 724.344 Q156.098 724.344 153.645 727.469 Q151.214 730.594 150.867 736.913 Q152.233 734.899 154.293 733.834 Q156.353 732.746 158.83 732.746 Q164.038 732.746 167.048 735.918 Q170.08 739.066 170.08 744.506 Q170.08 749.83 166.932 753.047 Q163.784 756.265 158.552 756.265 Q152.557 756.265 149.386 751.681 Q146.214 747.075 146.214 738.348 Q146.214 730.154 150.103 725.293 Q153.992 720.408 160.543 720.408 Q162.302 720.408 164.085 720.756 Q165.89 721.103 167.835 721.797 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M188.135 724.112 Q184.524 724.112 182.696 727.677 Q180.89 731.219 180.89 738.348 Q180.89 745.455 182.696 749.019 Q184.524 752.561 188.135 752.561 Q191.77 752.561 193.575 749.019 Q195.404 745.455 195.404 738.348 Q195.404 731.219 193.575 727.677 Q191.77 724.112 188.135 724.112 M188.135 720.408 Q193.946 720.408 197.001 725.015 Q200.08 729.598 200.08 738.348 Q200.08 747.075 197.001 751.681 Q193.946 756.265 188.135 756.265 Q182.325 756.265 179.247 751.681 Q176.191 747.075 176.191 738.348 Q176.191 729.598 179.247 725.015 Q182.325 720.408 188.135 720.408 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M118.622 413.065 L126.261 413.065 L126.261 386.699 L117.951 388.366 L117.951 384.107 L126.214 382.44 L130.89 382.44 L130.89 413.065 L138.529 413.065 L138.529 417 L118.622 417 L118.622 413.065 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M157.973 400.588 Q154.64 400.588 152.719 402.37 Q150.821 404.153 150.821 407.278 Q150.821 410.403 152.719 412.185 Q154.64 413.968 157.973 413.968 Q161.307 413.968 163.228 412.185 Q165.149 410.38 165.149 407.278 Q165.149 404.153 163.228 402.37 Q161.33 400.588 157.973 400.588 M153.298 398.597 Q150.288 397.857 148.599 395.796 Q146.932 393.736 146.932 390.773 Q146.932 386.63 149.872 384.222 Q152.835 381.815 157.973 381.815 Q163.135 381.815 166.075 384.222 Q169.015 386.63 169.015 390.773 Q169.015 393.736 167.325 395.796 Q165.659 397.857 162.673 398.597 Q166.052 399.384 167.927 401.676 Q169.825 403.968 169.825 407.278 Q169.825 412.301 166.747 414.986 Q163.691 417.671 157.973 417.671 Q152.256 417.671 149.177 414.986 Q146.122 412.301 146.122 407.278 Q146.122 403.968 148.02 401.676 Q149.918 399.384 153.298 398.597 M151.585 391.213 Q151.585 393.898 153.251 395.403 Q154.941 396.907 157.973 396.907 Q160.983 396.907 162.673 395.403 Q164.385 393.898 164.385 391.213 Q164.385 388.528 162.673 387.023 Q160.983 385.519 157.973 385.519 Q154.941 385.519 153.251 387.023 Q151.585 388.528 151.585 391.213 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M188.135 385.519 Q184.524 385.519 182.696 389.083 Q180.89 392.625 180.89 399.755 Q180.89 406.861 182.696 410.426 Q184.524 413.968 188.135 413.968 Q191.77 413.968 193.575 410.426 Q195.404 406.861 195.404 399.755 Q195.404 392.625 193.575 389.083 Q191.77 385.519 188.135 385.519 M188.135 381.815 Q193.946 381.815 197.001 386.421 Q200.08 391.005 200.08 399.755 Q200.08 408.481 197.001 413.088 Q193.946 417.671 188.135 417.671 Q182.325 417.671 179.247 413.088 Q176.191 408.481 176.191 399.755 Q176.191 391.005 179.247 386.421 Q182.325 381.815 188.135 381.815 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M121.839 74.4713 L138.159 74.4713 L138.159 78.4064 L116.214 78.4064 L116.214 74.4713 Q118.876 71.7166 123.46 67.087 Q128.066 62.4343 129.247 61.0917 Q131.492 58.5686 132.372 56.8325 Q133.275 55.0732 133.275 53.3834 Q133.275 50.6288 131.33 48.8927 Q129.409 47.1566 126.307 47.1566 Q124.108 47.1566 121.654 47.9205 Q119.224 48.6844 116.446 50.2353 L116.446 45.5131 Q119.27 44.3788 121.724 43.8001 Q124.177 43.2214 126.214 43.2214 Q131.585 43.2214 134.779 45.9066 Q137.974 48.5918 137.974 53.0825 Q137.974 55.2121 137.163 57.1334 Q136.376 59.0315 134.27 61.6241 Q133.691 62.2954 130.589 65.513 Q127.488 68.7074 121.839 74.4713 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M157.973 46.9251 Q154.362 46.9251 152.534 50.4899 Q150.728 54.0316 150.728 61.1612 Q150.728 68.2676 152.534 71.8324 Q154.362 75.374 157.973 75.374 Q161.608 75.374 163.413 71.8324 Q165.242 68.2676 165.242 61.1612 Q165.242 54.0316 163.413 50.4899 Q161.608 46.9251 157.973 46.9251 M157.973 43.2214 Q163.784 43.2214 166.839 47.8279 Q169.918 52.4112 169.918 61.1612 Q169.918 69.888 166.839 74.4944 Q163.784 79.0777 157.973 79.0777 Q152.163 79.0777 149.085 74.4944 Q146.029 69.888 146.029 61.1612 Q146.029 52.4112 149.085 47.8279 Q152.163 43.2214 157.973 43.2214 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M188.135 46.9251 Q184.524 46.9251 182.696 50.4899 Q180.89 54.0316 180.89 61.1612 Q180.89 68.2676 182.696 71.8324 Q184.524 75.374 188.135 75.374 Q191.77 75.374 193.575 71.8324 Q195.404 68.2676 195.404 61.1612 Q195.404 54.0316 193.575 50.4899 Q191.77 46.9251 188.135 46.9251 M188.135 43.2214 Q193.946 43.2214 197.001 47.8279 Q200.08 52.4112 200.08 61.1612 Q200.08 69.888 197.001 74.4944 Q193.946 79.0777 188.135 79.0777 Q182.325 79.0777 179.247 74.4944 Q176.191 69.888 176.191 61.1612 Q176.191 52.4112 179.247 47.8279 Q182.325 43.2214 188.135 43.2214 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M54.859 908.584 L42.0957 908.584 L42.0957 919.088 L36.8122 919.088 L36.8122 902.218 L57.2143 902.218 Q59.856 905.942 61.2247 910.43 Q62.5615 914.918 62.5615 920.011 Q62.5615 931.151 56.0684 937.453 Q49.5436 943.723 37.9262 943.723 Q26.2769 943.723 19.7839 937.453 Q13.2591 931.151 13.2591 920.011 Q13.2591 915.364 14.4049 911.194 Q15.5507 906.993 17.7787 903.46 L24.6219 903.46 Q21.5981 907.024 20.0704 911.035 Q18.5426 915.045 18.5426 919.469 Q18.5426 928.19 23.4124 932.583 Q28.2821 936.943 37.9262 936.943 Q47.5384 936.943 52.4082 932.583 Q57.2779 928.19 57.2779 919.469 Q57.2779 916.064 56.705 913.39 Q56.1003 910.717 54.859 908.584 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M14.1184 890.474 L14.1184 884.044 L58.3283 884.044 Q66.922 884.044 70.8051 887.323 Q74.6881 890.569 74.6881 897.794 L74.6881 900.245 L69.2773 900.245 L69.2773 898.24 Q69.2773 893.975 66.8902 892.224 Q64.503 890.474 58.3283 890.474 L14.1184 890.474 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip920)" d="M14.1184 877.838 L14.1184 837.638 L19.5293 837.638 L19.5293 854.507 L61.6384 854.507 L61.6384 860.969 L19.5293 860.969 L19.5293 877.838 L14.1184 877.838 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><circle clip-path="url(#clip922)" cx="2161.1" cy="890.681" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="445.576" cy="365.861" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1886.61" cy="1296.99" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="2126.79" cy="1534.01" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1063.16" cy="789.102" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="514.197" cy="264.283" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="720.059" cy="1330.85" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="2092.48" cy="1110.77" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="479.886" cy="552.087" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="617.128" cy="602.876" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="822.99" cy="501.298" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1303.34" cy="924.54" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="788.68" cy="822.962" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1989.54" cy="924.54" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="2298.34" cy="1635.59" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="2572.82" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="960.232" cy="467.439" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="685.749" cy="1026.12" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="891.611" cy="1195.41" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1783.68" cy="1534.01" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="720.059" cy="552.087" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="822.99" cy="1009.19" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1646.44" cy="890.681" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="960.232" cy="365.861" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="2058.17" cy="1534.01" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="308.334" cy="111.915" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="2572.82" cy="1517.08" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1371.96" cy="569.017" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="2092.48" cy="1500.15" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1680.75" cy="1500.15" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="2058.17" cy="1449.36" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1646.44" cy="1449.36" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="925.922" cy="822.962" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="754.37" cy="298.142" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1577.82" cy="1212.34" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1989.54" cy="1483.22" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="617.128" cy="585.946" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1749.37" cy="1229.27" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="411.266" cy="128.845" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="960.232" cy="1381.64" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1920.92" cy="941.47" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1063.16" cy="264.283" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="514.197" cy="94.9858" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="754.37" cy="501.298" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1783.68" cy="907.61" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1200.4" cy="772.173" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1817.99" cy="1229.27" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1783.68" cy="1229.27" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="651.438" cy="399.72" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1817.99" cy="1534.01" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="925.922" cy="619.806" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="479.886" cy="179.634" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="822.99" cy="670.595" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="960.232" cy="348.931" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1337.65" cy="1449.36" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1371.96" cy="1144.63" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1646.44" cy="1500.15" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1817.99" cy="1059.98" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="651.438" cy="382.79" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="548.507" cy="179.634" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1955.23" cy="1076.91" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="685.749" cy="856.821" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1989.54" cy="1584.8" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="445.576" cy="687.524" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="994.543" cy="501.298" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1063.16" cy="585.946" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="754.37" cy="416.65" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1028.85" cy="1026.12" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="891.611" cy="704.454" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1852.3" cy="1280.06" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1577.82" cy="1432.43" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="308.334" cy="111.915" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="617.128" cy="602.876" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="1474.89" cy="1212.34" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="2058.17" cy="1076.91" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip922)" cx="548.507" cy="365.861" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
</svg>
</div>
</div>
<p>The <code>StatsPlots</code> package uses the <code>@df</code> macro to specify that the variables in the <code>plot()</code> function can be found in the data frame provided just after it (i.e., <code>d</code>).</p>
</section>
<section id="two-regression-models" class="level2">
<h2 class="anchored" data-anchor-id="two-regression-models">Two regression models</h2>
<p>Let’s fit two regression models to this data set using the <code>GLM</code> package. The first model, <code>lm1</code>, is a simple regression model with <code>AOA</code> as the predictor and <code>GJT</code> as the outcome. The syntax should be self-explanatory:</p>
<div id="058a4953" class="cell" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb2-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">using</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">GLM</span> </span>
<span id="cb2-2"></span>
<span id="cb2-3">lm1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(<span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@formula</span>(GJT <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> AOA), d);</span>
<span id="cb2-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coeftable</span>(lm1)</span></code></pre></div></div>
<div class="cell-output cell-output-display cell-output-markdown" data-execution_count="3">
<table class="caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 17%">
<col style="width: 14%">
<col style="width: 15%">
<col style="width: 10%">
<col style="width: 13%">
<col style="width: 14%">
<col style="width: 14%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;"></th>
<th style="text-align: right;">Coef.</th>
<th style="text-align: right;">Std. Error</th>
<th style="text-align: right;">t</th>
<th style="text-align: left;">Pr(&gt;</th>
<th style="text-align: left;">t</th>
<th style="text-align: right;">)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">(Intercept)</td>
<td style="text-align: right;">190.409</td>
<td style="text-align: right;">3.90403</td>
<td style="text-align: right;">48.77</td>
<td style="text-align: left;">&lt;1e-57</td>
<td style="text-align: left;">182.63</td>
<td style="text-align: right;">198.188</td>
</tr>
<tr class="even">
<td style="text-align: left;">AOA</td>
<td style="text-align: right;">-1.21798</td>
<td style="text-align: right;">0.105139</td>
<td style="text-align: right;">-11.58</td>
<td style="text-align: left;">&lt;1e-17</td>
<td style="text-align: left;">-1.42747</td>
<td style="text-align: right;">-1.00848</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>We can visualise this model by plotting the data in a scatterplot and adding the model predictions to it like so. I use <code>begin</code> and <code>end</code> to force Julia to only produce a single plot.</p>
<div id="23630779" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb3-1">d[!, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"prediction"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">predict</span>(lm1);</span>
<span id="cb3-2"></span>
<span id="cb3-3"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">begin</span></span>
<span id="cb3-4"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@df</span> d <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>AOA, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>GJT</span>
<span id="cb3-5">           , seriestype <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>scatter</span>
<span id="cb3-6">           , legend <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>none</span>
<span id="cb3-7">           , xlabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AOA"</span></span>
<span id="cb3-8">           , ylabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GJT"</span>);</span>
<span id="cb3-9"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@df</span> d <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot!</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>AOA, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>prediction</span>
<span id="cb3-10">            , seriestype <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>line)</span>
<span id="cb3-11"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="4">
<!--?xml version="1.0" encoding="utf-8"?-->
<svg xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" width="672" height="480" viewbox="0 0 2688 1920">
<defs>
  <clippath id="clip010">
    <rect x="0" y="0" width="2688" height="1920"></rect>
  </clippath>
</defs>
<path clip-path="url(#clip010)" d="M0 1920 L2688 1920 L2688 0 L0 0  Z" fill="#ffffff" fill-rule="evenodd" fill-opacity="1"></path>
<defs>
  <clippath id="clip011">
    <rect x="537" y="0" width="1883" height="1883"></rect>
  </clippath>
</defs>
<path clip-path="url(#clip010)" d="M240.4 1734.12 L2640.76 1734.12 L2640.76 47.2441 L240.4 47.2441  Z" fill="#ffffff" fill-rule="evenodd" fill-opacity="1"></path>
<defs>
  <clippath id="clip012">
    <rect x="240" y="47" width="2401" height="1688"></rect>
  </clippath>
</defs>
<polyline clip-path="url(#clip012)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="479.886,1734.12 479.886,47.2441 "></polyline>
<polyline clip-path="url(#clip012)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="822.99,1734.12 822.99,47.2441 "></polyline>
<polyline clip-path="url(#clip012)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="1166.09,1734.12 1166.09,47.2441 "></polyline>
<polyline clip-path="url(#clip012)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="1509.2,1734.12 1509.2,47.2441 "></polyline>
<polyline clip-path="url(#clip012)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="1852.3,1734.12 1852.3,47.2441 "></polyline>
<polyline clip-path="url(#clip012)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="2195.41,1734.12 2195.41,47.2441 "></polyline>
<polyline clip-path="url(#clip012)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="2538.51,1734.12 2538.51,47.2441 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,1734.12 2640.76,1734.12 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="479.886,1734.12 479.886,1715.22 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="822.99,1734.12 822.99,1715.22 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="1166.09,1734.12 1166.09,1715.22 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="1509.2,1734.12 1509.2,1715.22 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="1852.3,1734.12 1852.3,1715.22 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="2195.41,1734.12 2195.41,1715.22 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="2538.51,1734.12 2538.51,1715.22 "></polyline>
<path clip-path="url(#clip010)" d="M454.574 1794.89 L462.213 1794.89 L462.213 1768.52 L453.903 1770.19 L453.903 1765.93 L462.167 1764.26 L466.842 1764.26 L466.842 1794.89 L474.481 1794.89 L474.481 1798.82 L454.574 1798.82 L454.574 1794.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M493.926 1767.34 Q490.315 1767.34 488.486 1770.9 Q486.68 1774.45 486.68 1781.58 Q486.68 1788.68 488.486 1792.25 Q490.315 1795.79 493.926 1795.79 Q497.56 1795.79 499.365 1792.25 Q501.194 1788.68 501.194 1781.58 Q501.194 1774.45 499.365 1770.9 Q497.56 1767.34 493.926 1767.34 M493.926 1763.64 Q499.736 1763.64 502.791 1768.24 Q505.87 1772.83 505.87 1781.58 Q505.87 1790.3 502.791 1794.91 Q499.736 1799.49 493.926 1799.49 Q488.116 1799.49 485.037 1794.91 Q481.981 1790.3 481.981 1781.58 Q481.981 1772.83 485.037 1768.24 Q488.116 1763.64 493.926 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M801.764 1794.89 L818.083 1794.89 L818.083 1798.82 L796.139 1798.82 L796.139 1794.89 Q798.801 1792.13 803.384 1787.5 Q807.991 1782.85 809.171 1781.51 Q811.416 1778.98 812.296 1777.25 Q813.199 1775.49 813.199 1773.8 Q813.199 1771.04 811.254 1769.31 Q809.333 1767.57 806.231 1767.57 Q804.032 1767.57 801.579 1768.34 Q799.148 1769.1 796.37 1770.65 L796.37 1765.93 Q799.194 1764.79 801.648 1764.21 Q804.102 1763.64 806.139 1763.64 Q811.509 1763.64 814.703 1766.32 Q817.898 1769.01 817.898 1773.5 Q817.898 1775.63 817.088 1777.55 Q816.301 1779.45 814.194 1782.04 Q813.616 1782.71 810.514 1785.93 Q807.412 1789.12 801.764 1794.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M837.898 1767.34 Q834.287 1767.34 832.458 1770.9 Q830.652 1774.45 830.652 1781.58 Q830.652 1788.68 832.458 1792.25 Q834.287 1795.79 837.898 1795.79 Q841.532 1795.79 843.338 1792.25 Q845.166 1788.68 845.166 1781.58 Q845.166 1774.45 843.338 1770.9 Q841.532 1767.34 837.898 1767.34 M837.898 1763.64 Q843.708 1763.64 846.763 1768.24 Q849.842 1772.83 849.842 1781.58 Q849.842 1790.3 846.763 1794.91 Q843.708 1799.49 837.898 1799.49 Q832.088 1799.49 829.009 1794.91 Q825.953 1790.3 825.953 1781.58 Q825.953 1772.83 829.009 1768.24 Q832.088 1763.64 837.898 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M1154.94 1780.19 Q1158.29 1780.9 1160.17 1783.17 Q1162.07 1785.44 1162.07 1788.77 Q1162.07 1793.89 1158.55 1796.69 Q1155.03 1799.49 1148.55 1799.49 Q1146.37 1799.49 1144.06 1799.05 Q1141.77 1798.64 1139.31 1797.78 L1139.31 1793.27 Q1141.26 1794.4 1143.57 1794.98 Q1145.89 1795.56 1148.41 1795.56 Q1152.81 1795.56 1155.1 1793.82 Q1157.41 1792.08 1157.41 1788.77 Q1157.41 1785.72 1155.26 1784.01 Q1153.13 1782.27 1149.31 1782.27 L1145.28 1782.27 L1145.28 1778.43 L1149.5 1778.43 Q1152.95 1778.43 1154.78 1777.06 Q1156.6 1775.67 1156.6 1773.08 Q1156.6 1770.42 1154.71 1769.01 Q1152.83 1767.57 1149.31 1767.57 Q1147.39 1767.57 1145.19 1767.99 Q1142.99 1768.4 1140.35 1769.28 L1140.35 1765.12 Q1143.02 1764.38 1145.33 1764.01 Q1147.67 1763.64 1149.73 1763.64 Q1155.05 1763.64 1158.15 1766.07 Q1161.26 1768.47 1161.26 1772.59 Q1161.26 1775.46 1159.61 1777.46 Q1157.97 1779.42 1154.94 1780.19 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M1180.93 1767.34 Q1177.32 1767.34 1175.49 1770.9 Q1173.69 1774.45 1173.69 1781.58 Q1173.69 1788.68 1175.49 1792.25 Q1177.32 1795.79 1180.93 1795.79 Q1184.57 1795.79 1186.37 1792.25 Q1188.2 1788.68 1188.2 1781.58 Q1188.2 1774.45 1186.37 1770.9 Q1184.57 1767.34 1180.93 1767.34 M1180.93 1763.64 Q1186.74 1763.64 1189.8 1768.24 Q1192.88 1772.83 1192.88 1781.58 Q1192.88 1790.3 1189.8 1794.91 Q1186.74 1799.49 1180.93 1799.49 Q1175.12 1799.49 1172.04 1794.91 Q1168.99 1790.3 1168.99 1781.58 Q1168.99 1772.83 1172.04 1768.24 Q1175.12 1763.64 1180.93 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M1497.37 1768.34 L1485.56 1786.78 L1497.37 1786.78 L1497.37 1768.34 M1496.14 1764.26 L1502.02 1764.26 L1502.02 1786.78 L1506.95 1786.78 L1506.95 1790.67 L1502.02 1790.67 L1502.02 1798.82 L1497.37 1798.82 L1497.37 1790.67 L1481.77 1790.67 L1481.77 1786.16 L1496.14 1764.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M1524.68 1767.34 Q1521.07 1767.34 1519.24 1770.9 Q1517.44 1774.45 1517.44 1781.58 Q1517.44 1788.68 1519.24 1792.25 Q1521.07 1795.79 1524.68 1795.79 Q1528.32 1795.79 1530.12 1792.25 Q1531.95 1788.68 1531.95 1781.58 Q1531.95 1774.45 1530.12 1770.9 Q1528.32 1767.34 1524.68 1767.34 M1524.68 1763.64 Q1530.49 1763.64 1533.55 1768.24 Q1536.63 1772.83 1536.63 1781.58 Q1536.63 1790.3 1533.55 1794.91 Q1530.49 1799.49 1524.68 1799.49 Q1518.87 1799.49 1515.8 1794.91 Q1512.74 1790.3 1512.74 1781.58 Q1512.74 1772.83 1515.8 1768.24 Q1518.87 1763.64 1524.68 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M1827 1764.26 L1845.36 1764.26 L1845.36 1768.2 L1831.28 1768.2 L1831.28 1776.67 Q1832.3 1776.32 1833.32 1776.16 Q1834.34 1775.97 1835.36 1775.97 Q1841.15 1775.97 1844.52 1779.15 Q1847.9 1782.32 1847.9 1787.73 Q1847.9 1793.31 1844.43 1796.41 Q1840.96 1799.49 1834.64 1799.49 Q1832.46 1799.49 1830.2 1799.12 Q1827.95 1798.75 1825.54 1798.01 L1825.54 1793.31 Q1827.63 1794.45 1829.85 1795 Q1832.07 1795.56 1834.55 1795.56 Q1838.55 1795.56 1840.89 1793.45 Q1843.23 1791.34 1843.23 1787.73 Q1843.23 1784.12 1840.89 1782.02 Q1838.55 1779.91 1834.55 1779.91 Q1832.67 1779.91 1830.8 1780.33 Q1828.95 1780.74 1827 1781.62 L1827 1764.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M1867.12 1767.34 Q1863.51 1767.34 1861.68 1770.9 Q1859.87 1774.45 1859.87 1781.58 Q1859.87 1788.68 1861.68 1792.25 Q1863.51 1795.79 1867.12 1795.79 Q1870.75 1795.79 1872.56 1792.25 Q1874.39 1788.68 1874.39 1781.58 Q1874.39 1774.45 1872.56 1770.9 Q1870.75 1767.34 1867.12 1767.34 M1867.12 1763.64 Q1872.93 1763.64 1875.98 1768.24 Q1879.06 1772.83 1879.06 1781.58 Q1879.06 1790.3 1875.98 1794.91 Q1872.93 1799.49 1867.12 1799.49 Q1861.31 1799.49 1858.23 1794.91 Q1855.17 1790.3 1855.17 1781.58 Q1855.17 1772.83 1858.23 1768.24 Q1861.31 1763.64 1867.12 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M2180.81 1779.68 Q2177.66 1779.68 2175.81 1781.83 Q2173.98 1783.98 2173.98 1787.73 Q2173.98 1791.46 2175.81 1793.64 Q2177.66 1795.79 2180.81 1795.79 Q2183.96 1795.79 2185.79 1793.64 Q2187.64 1791.46 2187.64 1787.73 Q2187.64 1783.98 2185.79 1781.83 Q2183.96 1779.68 2180.81 1779.68 M2190.09 1765.02 L2190.09 1769.28 Q2188.34 1768.45 2186.53 1768.01 Q2184.75 1767.57 2182.99 1767.57 Q2178.36 1767.57 2175.9 1770.7 Q2173.47 1773.82 2173.13 1780.14 Q2174.49 1778.13 2176.55 1777.06 Q2178.61 1775.97 2181.09 1775.97 Q2186.3 1775.97 2189.31 1779.15 Q2192.34 1782.29 2192.34 1787.73 Q2192.34 1793.06 2189.19 1796.27 Q2186.04 1799.49 2180.81 1799.49 Q2174.82 1799.49 2171.65 1794.91 Q2168.47 1790.3 2168.47 1781.58 Q2168.47 1773.38 2172.36 1768.52 Q2176.25 1763.64 2182.8 1763.64 Q2184.56 1763.64 2186.34 1763.98 Q2188.15 1764.33 2190.09 1765.02 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M2210.4 1767.34 Q2206.78 1767.34 2204.96 1770.9 Q2203.15 1774.45 2203.15 1781.58 Q2203.15 1788.68 2204.96 1792.25 Q2206.78 1795.79 2210.4 1795.79 Q2214.03 1795.79 2215.83 1792.25 Q2217.66 1788.68 2217.66 1781.58 Q2217.66 1774.45 2215.83 1770.9 Q2214.03 1767.34 2210.4 1767.34 M2210.4 1763.64 Q2216.21 1763.64 2219.26 1768.24 Q2222.34 1772.83 2222.34 1781.58 Q2222.34 1790.3 2219.26 1794.91 Q2216.21 1799.49 2210.4 1799.49 Q2204.58 1799.49 2201.51 1794.91 Q2198.45 1790.3 2198.45 1781.58 Q2198.45 1772.83 2201.51 1768.24 Q2204.58 1763.64 2210.4 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M2511.87 1764.26 L2534.09 1764.26 L2534.09 1766.25 L2521.54 1798.82 L2516.66 1798.82 L2528.46 1768.2 L2511.87 1768.2 L2511.87 1764.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M2553.21 1767.34 Q2549.6 1767.34 2547.77 1770.9 Q2545.96 1774.45 2545.96 1781.58 Q2545.96 1788.68 2547.77 1792.25 Q2549.6 1795.79 2553.21 1795.79 Q2556.84 1795.79 2558.65 1792.25 Q2560.48 1788.68 2560.48 1781.58 Q2560.48 1774.45 2558.65 1770.9 Q2556.84 1767.34 2553.21 1767.34 M2553.21 1763.64 Q2559.02 1763.64 2562.08 1768.24 Q2565.15 1772.83 2565.15 1781.58 Q2565.15 1790.3 2562.08 1794.91 Q2559.02 1799.49 2553.21 1799.49 Q2547.4 1799.49 2544.32 1794.91 Q2541.27 1790.3 2541.27 1781.58 Q2541.27 1772.83 2544.32 1768.24 Q2547.4 1763.64 2553.21 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M1393.77 1842.11 L1385.05 1865.76 L1402.53 1865.76 L1393.77 1842.11 M1390.15 1835.78 L1397.43 1835.78 L1415.54 1883.3 L1408.86 1883.3 L1404.53 1871.11 L1383.11 1871.11 L1378.78 1883.3 L1372 1883.3 L1390.15 1835.78 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M1440.63 1840.14 Q1433.62 1840.14 1429.49 1845.36 Q1425.38 1850.58 1425.38 1859.59 Q1425.38 1868.56 1429.49 1873.78 Q1433.62 1879 1440.63 1879 Q1447.63 1879 1451.7 1873.78 Q1455.81 1868.56 1455.81 1859.59 Q1455.81 1850.58 1451.7 1845.36 Q1447.63 1840.14 1440.63 1840.14 M1440.63 1834.92 Q1450.62 1834.92 1456.6 1841.64 Q1462.59 1848.32 1462.59 1859.59 Q1462.59 1870.82 1456.6 1877.54 Q1450.62 1884.22 1440.63 1884.22 Q1430.6 1884.22 1424.58 1877.54 Q1418.6 1870.86 1418.6 1859.59 Q1418.6 1848.32 1424.58 1841.64 Q1430.6 1834.92 1440.63 1834.92 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M1487.38 1842.11 L1478.66 1865.76 L1496.13 1865.76 L1487.38 1842.11 M1483.75 1835.78 L1491.04 1835.78 L1509.15 1883.3 L1502.47 1883.3 L1498.14 1871.11 L1476.72 1871.11 L1472.39 1883.3 L1465.61 1883.3 L1483.75 1835.78 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><polyline clip-path="url(#clip012)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,1414.55 2640.76,1414.55 "></polyline>
<polyline clip-path="url(#clip012)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,1076.2 2640.76,1076.2 "></polyline>
<polyline clip-path="url(#clip012)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,737.85 2640.76,737.85 "></polyline>
<polyline clip-path="url(#clip012)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,399.501 2640.76,399.501 "></polyline>
<polyline clip-path="url(#clip012)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,61.1508 2640.76,61.1508 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,1734.12 240.4,47.2441 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,1414.55 259.297,1414.55 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,1076.2 259.297,1076.2 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,737.85 259.297,737.85 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,399.501 259.297,399.501 "></polyline>
<polyline clip-path="url(#clip010)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,61.1508 259.297,61.1508 "></polyline>
<path clip-path="url(#clip010)" d="M118.622 1427.89 L126.261 1427.89 L126.261 1401.53 L117.951 1403.2 L117.951 1398.94 L126.214 1397.27 L130.89 1397.27 L130.89 1427.89 L138.529 1427.89 L138.529 1431.83 L118.622 1431.83 L118.622 1427.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M152.001 1427.89 L168.321 1427.89 L168.321 1431.83 L146.376 1431.83 L146.376 1427.89 Q149.038 1425.14 153.622 1420.51 Q158.228 1415.86 159.409 1414.52 Q161.654 1411.99 162.534 1410.26 Q163.436 1408.5 163.436 1406.81 Q163.436 1404.05 161.492 1402.32 Q159.571 1400.58 156.469 1400.58 Q154.27 1400.58 151.816 1401.34 Q149.386 1402.11 146.608 1403.66 L146.608 1398.94 Q149.432 1397.8 151.886 1397.22 Q154.339 1396.65 156.376 1396.65 Q161.747 1396.65 164.941 1399.33 Q168.135 1402.02 168.135 1406.51 Q168.135 1408.64 167.325 1410.56 Q166.538 1412.46 164.432 1415.05 Q163.853 1415.72 160.751 1418.94 Q157.649 1422.13 152.001 1427.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M188.135 1400.35 Q184.524 1400.35 182.696 1403.91 Q180.89 1407.46 180.89 1414.58 Q180.89 1421.69 182.696 1425.26 Q184.524 1428.8 188.135 1428.8 Q191.77 1428.8 193.575 1425.26 Q195.404 1421.69 195.404 1414.58 Q195.404 1407.46 193.575 1403.91 Q191.77 1400.35 188.135 1400.35 M188.135 1396.65 Q193.946 1396.65 197.001 1401.25 Q200.08 1405.83 200.08 1414.58 Q200.08 1423.31 197.001 1427.92 Q193.946 1432.5 188.135 1432.5 Q182.325 1432.5 179.247 1427.92 Q176.191 1423.31 176.191 1414.58 Q176.191 1405.83 179.247 1401.25 Q182.325 1396.65 188.135 1396.65 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M118.622 1089.55 L126.261 1089.55 L126.261 1063.18 L117.951 1064.85 L117.951 1060.59 L126.214 1058.92 L130.89 1058.92 L130.89 1089.55 L138.529 1089.55 L138.529 1093.48 L118.622 1093.48 L118.622 1089.55 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M160.821 1062.99 L149.015 1081.44 L160.821 1081.44 L160.821 1062.99 M159.594 1058.92 L165.473 1058.92 L165.473 1081.44 L170.404 1081.44 L170.404 1085.33 L165.473 1085.33 L165.473 1093.48 L160.821 1093.48 L160.821 1085.33 L145.219 1085.33 L145.219 1080.82 L159.594 1058.92 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M188.135 1062 Q184.524 1062 182.696 1065.56 Q180.89 1069.11 180.89 1076.23 Q180.89 1083.34 182.696 1086.91 Q184.524 1090.45 188.135 1090.45 Q191.77 1090.45 193.575 1086.91 Q195.404 1083.34 195.404 1076.23 Q195.404 1069.11 193.575 1065.56 Q191.77 1062 188.135 1062 M188.135 1058.3 Q193.946 1058.3 197.001 1062.9 Q200.08 1067.48 200.08 1076.23 Q200.08 1084.96 197.001 1089.57 Q193.946 1094.15 188.135 1094.15 Q182.325 1094.15 179.247 1089.57 Q176.191 1084.96 176.191 1076.23 Q176.191 1067.48 179.247 1062.9 Q182.325 1058.3 188.135 1058.3 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M118.622 751.195 L126.261 751.195 L126.261 724.83 L117.951 726.496 L117.951 722.237 L126.214 720.57 L130.89 720.57 L130.89 751.195 L138.529 751.195 L138.529 755.13 L118.622 755.13 L118.622 751.195 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M158.552 735.987 Q155.404 735.987 153.552 738.14 Q151.724 740.293 151.724 744.043 Q151.724 747.769 153.552 749.945 Q155.404 752.098 158.552 752.098 Q161.7 752.098 163.529 749.945 Q165.381 747.769 165.381 744.043 Q165.381 740.293 163.529 738.14 Q161.7 735.987 158.552 735.987 M167.835 721.334 L167.835 725.594 Q166.075 724.76 164.27 724.32 Q162.487 723.881 160.728 723.881 Q156.098 723.881 153.645 727.006 Q151.214 730.131 150.867 736.45 Q152.233 734.436 154.293 733.371 Q156.353 732.283 158.83 732.283 Q164.038 732.283 167.048 735.455 Q170.08 738.603 170.08 744.043 Q170.08 749.367 166.932 752.584 Q163.784 755.802 158.552 755.802 Q152.557 755.802 149.386 751.218 Q146.214 746.612 146.214 737.885 Q146.214 729.691 150.103 724.83 Q153.992 719.945 160.543 719.945 Q162.302 719.945 164.085 720.293 Q165.89 720.64 167.835 721.334 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M188.135 723.649 Q184.524 723.649 182.696 727.214 Q180.89 730.756 180.89 737.885 Q180.89 744.992 182.696 748.556 Q184.524 752.098 188.135 752.098 Q191.77 752.098 193.575 748.556 Q195.404 744.992 195.404 737.885 Q195.404 730.756 193.575 727.214 Q191.77 723.649 188.135 723.649 M188.135 719.945 Q193.946 719.945 197.001 724.552 Q200.08 729.135 200.08 737.885 Q200.08 746.612 197.001 751.218 Q193.946 755.802 188.135 755.802 Q182.325 755.802 179.247 751.218 Q176.191 746.612 176.191 737.885 Q176.191 729.135 179.247 724.552 Q182.325 719.945 188.135 719.945 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M118.622 412.845 L126.261 412.845 L126.261 386.48 L117.951 388.147 L117.951 383.887 L126.214 382.221 L130.89 382.221 L130.89 412.845 L138.529 412.845 L138.529 416.781 L118.622 416.781 L118.622 412.845 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M157.973 400.369 Q154.64 400.369 152.719 402.151 Q150.821 403.933 150.821 407.058 Q150.821 410.183 152.719 411.966 Q154.64 413.748 157.973 413.748 Q161.307 413.748 163.228 411.966 Q165.149 410.16 165.149 407.058 Q165.149 403.933 163.228 402.151 Q161.33 400.369 157.973 400.369 M153.298 398.378 Q150.288 397.637 148.599 395.577 Q146.932 393.517 146.932 390.554 Q146.932 386.41 149.872 384.003 Q152.835 381.596 157.973 381.596 Q163.135 381.596 166.075 384.003 Q169.015 386.41 169.015 390.554 Q169.015 393.517 167.325 395.577 Q165.659 397.637 162.673 398.378 Q166.052 399.165 167.927 401.457 Q169.825 403.748 169.825 407.058 Q169.825 412.082 166.747 414.767 Q163.691 417.452 157.973 417.452 Q152.256 417.452 149.177 414.767 Q146.122 412.082 146.122 407.058 Q146.122 403.748 148.02 401.457 Q149.918 399.165 153.298 398.378 M151.585 390.994 Q151.585 393.679 153.251 395.184 Q154.941 396.688 157.973 396.688 Q160.983 396.688 162.673 395.184 Q164.385 393.679 164.385 390.994 Q164.385 388.309 162.673 386.804 Q160.983 385.299 157.973 385.299 Q154.941 385.299 153.251 386.804 Q151.585 388.309 151.585 390.994 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M188.135 385.299 Q184.524 385.299 182.696 388.864 Q180.89 392.406 180.89 399.535 Q180.89 406.642 182.696 410.207 Q184.524 413.748 188.135 413.748 Q191.77 413.748 193.575 410.207 Q195.404 406.642 195.404 399.535 Q195.404 392.406 193.575 388.864 Q191.77 385.299 188.135 385.299 M188.135 381.596 Q193.946 381.596 197.001 386.202 Q200.08 390.785 200.08 399.535 Q200.08 408.262 197.001 412.869 Q193.946 417.452 188.135 417.452 Q182.325 417.452 179.247 412.869 Q176.191 408.262 176.191 399.535 Q176.191 390.785 179.247 386.202 Q182.325 381.596 188.135 381.596 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M121.839 74.4956 L138.159 74.4956 L138.159 78.4308 L116.214 78.4308 L116.214 74.4956 Q118.876 71.741 123.46 67.1114 Q128.066 62.4587 129.247 61.1161 Q131.492 58.5929 132.372 56.8568 Q133.275 55.0976 133.275 53.4078 Q133.275 50.6532 131.33 48.9171 Q129.409 47.181 126.307 47.181 Q124.108 47.181 121.654 47.9449 Q119.224 48.7087 116.446 50.2597 L116.446 45.5375 Q119.27 44.4032 121.724 43.8245 Q124.177 43.2458 126.214 43.2458 Q131.585 43.2458 134.779 45.931 Q137.974 48.6161 137.974 53.1069 Q137.974 55.2365 137.163 57.1578 Q136.376 59.0559 134.27 61.6485 Q133.691 62.3198 130.589 65.5373 Q127.488 68.7318 121.839 74.4956 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M157.973 46.9495 Q154.362 46.9495 152.534 50.5143 Q150.728 54.0559 150.728 61.1855 Q150.728 68.292 152.534 71.8568 Q154.362 75.3984 157.973 75.3984 Q161.608 75.3984 163.413 71.8568 Q165.242 68.292 165.242 61.1855 Q165.242 54.0559 163.413 50.5143 Q161.608 46.9495 157.973 46.9495 M157.973 43.2458 Q163.784 43.2458 166.839 47.8523 Q169.918 52.4356 169.918 61.1855 Q169.918 69.9123 166.839 74.5188 Q163.784 79.1021 157.973 79.1021 Q152.163 79.1021 149.085 74.5188 Q146.029 69.9123 146.029 61.1855 Q146.029 52.4356 149.085 47.8523 Q152.163 43.2458 157.973 43.2458 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M188.135 46.9495 Q184.524 46.9495 182.696 50.5143 Q180.89 54.0559 180.89 61.1855 Q180.89 68.292 182.696 71.8568 Q184.524 75.3984 188.135 75.3984 Q191.77 75.3984 193.575 71.8568 Q195.404 68.292 195.404 61.1855 Q195.404 54.0559 193.575 50.5143 Q191.77 46.9495 188.135 46.9495 M188.135 43.2458 Q193.946 43.2458 197.001 47.8523 Q200.08 52.4356 200.08 61.1855 Q200.08 69.9123 197.001 74.5188 Q193.946 79.1021 188.135 79.1021 Q182.325 79.1021 179.247 74.5188 Q176.191 69.9123 176.191 61.1855 Q176.191 52.4356 179.247 47.8523 Q182.325 43.2458 188.135 43.2458 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M54.859 908.584 L42.0957 908.584 L42.0957 919.088 L36.8122 919.088 L36.8122 902.218 L57.2143 902.218 Q59.856 905.942 61.2247 910.43 Q62.5615 914.918 62.5615 920.011 Q62.5615 931.151 56.0684 937.453 Q49.5436 943.723 37.9262 943.723 Q26.2769 943.723 19.7839 937.453 Q13.2591 931.151 13.2591 920.011 Q13.2591 915.364 14.4049 911.194 Q15.5507 906.993 17.7787 903.46 L24.6219 903.46 Q21.5981 907.024 20.0704 911.035 Q18.5426 915.045 18.5426 919.469 Q18.5426 928.19 23.4124 932.583 Q28.2821 936.943 37.9262 936.943 Q47.5384 936.943 52.4082 932.583 Q57.2779 928.19 57.2779 919.469 Q57.2779 916.064 56.705 913.39 Q56.1003 910.717 54.859 908.584 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M14.1184 890.474 L14.1184 884.044 L58.3283 884.044 Q66.922 884.044 70.8051 887.323 Q74.6881 890.569 74.6881 897.794 L74.6881 900.245 L69.2773 900.245 L69.2773 898.24 Q69.2773 893.975 66.8902 892.224 Q64.503 890.474 58.3283 890.474 L14.1184 890.474 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip010)" d="M14.1184 877.838 L14.1184 837.638 L19.5293 837.638 L19.5293 854.507 L61.6384 854.507 L61.6384 860.969 L19.5293 860.969 L19.5293 877.838 L14.1184 877.838 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><circle clip-path="url(#clip012)" cx="2161.1" cy="890.108" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="445.576" cy="365.666" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1886.61" cy="1296.13" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="2126.79" cy="1532.97" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1063.16" cy="788.603" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="514.197" cy="264.161" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="720.059" cy="1329.96" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="2092.48" cy="1110.04" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="479.886" cy="551.758" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="617.128" cy="602.51" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="822.99" cy="501.006" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1303.34" cy="923.943" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="788.68" cy="822.438" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1989.54" cy="923.943" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="2298.34" cy="1634.48" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="2572.82" cy="1685.23" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="960.232" cy="467.171" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="685.749" cy="1025.45" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="891.611" cy="1194.62" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1783.68" cy="1532.97" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="720.059" cy="551.758" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="822.99" cy="1008.53" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1646.44" cy="890.108" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="960.232" cy="365.666" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="2058.17" cy="1532.97" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="308.334" cy="111.903" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="2572.82" cy="1516.05" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1371.96" cy="568.676" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="2092.48" cy="1499.14" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1680.75" cy="1499.14" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="2058.17" cy="1448.39" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1646.44" cy="1448.39" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="925.922" cy="822.438" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="754.37" cy="297.996" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1577.82" cy="1211.54" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1989.54" cy="1482.22" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="617.128" cy="585.593" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1749.37" cy="1228.46" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="411.266" cy="128.821" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="960.232" cy="1380.72" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1920.92" cy="940.86" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1063.16" cy="264.161" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="514.197" cy="94.9858" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="754.37" cy="501.006" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1783.68" cy="907.025" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1200.4" cy="771.685" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1817.99" cy="1228.46" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1783.68" cy="1228.46" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="651.438" cy="399.501" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1817.99" cy="1532.97" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="925.922" cy="619.428" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="479.886" cy="179.573" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="822.99" cy="670.18" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="960.232" cy="348.748" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1337.65" cy="1448.39" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1371.96" cy="1143.87" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1646.44" cy="1499.14" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1817.99" cy="1059.28" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="651.438" cy="382.583" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="548.507" cy="179.573" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1955.23" cy="1076.2" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="685.749" cy="856.273" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1989.54" cy="1583.72" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="445.576" cy="687.098" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="994.543" cy="501.006" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1063.16" cy="585.593" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="754.37" cy="416.418" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1028.85" cy="1025.45" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="891.611" cy="704.015" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1852.3" cy="1279.21" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1577.82" cy="1431.47" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="308.334" cy="111.903" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="617.128" cy="602.51" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="1474.89" cy="1211.54" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="2058.17" cy="1076.2" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip012)" cx="548.507" cy="365.666" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<polyline clip-path="url(#clip012)" style="stroke:#e26f46; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="308.334,326.438 308.334,326.438 411.266,388.254 445.576,408.859 479.886,429.464 514.197,450.069 548.507,470.674 617.128,511.884 651.438,532.489 685.749,553.094 720.059,573.699 754.37,594.305 788.68,614.91 822.99,635.515 891.611,676.725 925.922,697.33 960.232,717.935 994.543,738.54 1028.85,759.145 1063.16,779.751 1200.4,862.171 1303.34,923.986 1337.65,944.591 1371.96,965.197 1474.89,1027.01 1577.82,1088.83 1646.44,1130.04 1680.75,1150.64 1749.37,1191.85 1783.68,1212.46 1817.99,1233.06 1852.3,1253.67 1886.61,1274.27 1920.92,1294.88 1955.23,1315.48 1989.54,1336.09 2058.17,1377.3 2092.48,1397.9 2126.79,1418.51 2161.1,1439.11 2298.34,1521.53 2572.82,1686.38 "></polyline>
</svg>
</div>
</div>
<p>Our second model will incorporate an ‘elbow’ in the regression line at a given breakpoint – a piecewise regression model. For a breakpoint <code>bp</code>, we need to create a variable <code>since_bp</code> that encodes how many years beyond this breakpoint the participants’ <code>AOA</code> values are. If an <code>AOA</code> value is lower than the breakpoint, the corresponding <code>since_bp</code> value is just 0. The <code>add_breakpoint()</code> value takes a dataset containing an <code>AOA</code> variable and adds a variable called <code>since_bp</code> to it.</p>
<div id="351e08cc" class="cell" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb4-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_breakpoint</span>(data, bp)</span>
<span id="cb4-2">    data[!, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"since_bp"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>.(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, data[!, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AOA"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.-</span> bp);</span>
<span id="cb4-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span>;</span></code></pre></div></div>
</div>
<p>To add the <code>since_bp</code> variable for a breakpoint at age 12 to our dataset <code>d</code>, we just run this function. Note that in Julia, arguments are not copied when they are passed to a function. That is, the <code>add_breakpoint()</code> function <em>changes</em> the dataset; it does not create a changed <em>copy</em> of the dataset like R would:</p>
<div id="5cd54840" class="cell" data-execution_count="5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># changes d!</span></span>
<span id="cb5-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_breakpoint</span>(d, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>);</span>
<span id="cb5-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(d);</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<div class="ansi-escaped-output">
<pre><span class="ansi-bold">76×4 DataFrame</span>

<span class="ansi-bold"> Row </span>│<span class="ansi-bold"> AOA   </span><span class="ansi-bold"> GJT   </span><span class="ansi-bold"> prediction </span><span class="ansi-bold"> since_bp </span>

     │<span class="ansi-bright-black-fg"> Int64 </span><span class="ansi-bright-black-fg"> Int64 </span><span class="ansi-bright-black-fg"> Float64    </span><span class="ansi-bright-black-fg"> Int64    </span>

─────┼────────────────────────────────────

   1 │    59    151     118.548        47

   2 │     9    182     179.447         0

   3 │    51    127     128.292        39

   4 │    58    113     119.766        46

   5 │    27    157     157.523        15

   6 │    11    188     177.011         0

   7 │    17    125     169.703         5

   8 │    57    138     120.984        45

   9 │    10    171     178.229         0

  10 │    14    168     173.357         2

  11 │    20    174     166.049         8

  12 │    34    149     148.997        22

  13 │    19    155     167.267         7

  14 │    54    149     124.638        42

  15 │    63    107     113.676        51

  16 │    71    104     103.932        59

  17 │    24    176     161.177        12

  18 │    16    143     170.921         4

  19 │    22    133     163.613        10

  20 │    48    113     131.946        36

  21 │    17    171     169.703         5

  22 │    20    144     166.049         8

  23 │    44    151     136.818        32

  24 │    24    182     161.177        12

  25 │    56    113     122.202        44

  26 │     5    197     184.319         0

  27 │    71    114     103.932        59

  28 │    36    170     146.561        24

  29 │    57    115     120.984        45

  30 │    45    115     135.6          33

  31 │    56    118     122.202        44

  32 │    44    118     136.818        32

  33 │    23    155     162.395        11

  34 │    18    186     168.485         6

  35 │    42    132     139.254        30

  36 │    54    116     124.638        42

  37 │    14    169     173.357         2

  38 │    47    131     133.164        35

  39 │     8    196     180.665         0

  40 │    24    122     161.177        12

  41 │    52    148     127.074        40

  42 │    27    188     157.523        15

  43 │    11    198     177.011         0

  44 │    18    174     168.485         6

  45 │    48    150     131.946        36

  46 │    31    158     152.651        19

  47 │    49    131     130.728        37

  48 │    48    131     131.946        36

  49 │    15    180     172.139         3

  50 │    49    113     130.728        37

  51 │    23    167     162.395        11

  52 │    10    193     178.229         0

  53 │    20    164     166.049         8

  54 │    24    183     161.177        12

  55 │    35    118     147.779        23

  56 │    36    136     146.561        24

  57 │    44    115     136.818        32

  58 │    49    141     130.728        37

  59 │    15    181     172.139         3

  60 │    12    193     175.793         0

  61 │    53    140     125.856        41

  62 │    16    153     170.921         4

  63 │    54    110     124.638        42

  64 │     9    163     179.447         0

  65 │    25    174     159.959        13

  66 │    27    169     157.523        15

  67 │    18    179     168.485         6

  68 │    26    143     158.741        14

  69 │    22    162     163.613        10

  70 │    50    128     129.51         38

  71 │    42    119     139.254        30

  72 │     5    197     184.319         0

  73 │    14    168     173.357         2

  74 │    39    132     142.908        27

  75 │    56    140     122.202        44

  76 │    12    182     175.793         0</pre>
</div>
</div>
</div>
<p>Since we don’t know what the best breakpoint is, we’re going to estimate it from the data. For each integer in a given range (<code>minbp</code> through <code>maxbp</code>), we’re going to fit a piecewise regression model with that integer as the breakpoint. We’ll then pick the breakpoint that minimises the deviance of the fit (i.e., the sum of squared differences between the model fit and the actual outcome). The <code>fit_piecewise()</code> function takes care of this. It outputs both the best fitting piecewise regression model and the breakpoint used for this model.</p>
<div id="8121dd09" class="cell" data-execution_count="6">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fit_piecewise</span>(data, minbp, maxbp)</span>
<span id="cb6-2">  min_deviance <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">Inf</span></span>
<span id="cb6-3">  best_model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">nothing</span></span>
<span id="cb6-4">  best_bp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb6-5">  current_model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">nothing</span></span>
<span id="cb6-6">  </span>
<span id="cb6-7">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> bp <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> minbp<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>maxbp</span>
<span id="cb6-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_breakpoint</span>(data, bp)</span>
<span id="cb6-9">    current_model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(<span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@formula</span>(GJT <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> AOA <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> since_bp), data)</span>
<span id="cb6-10">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">deviance</span>(current_model) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> min_deviance</span>
<span id="cb6-11">      min_deviance <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">deviance</span>(current_model)</span>
<span id="cb6-12">      best_model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> current_model</span>
<span id="cb6-13">      best_bp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> bp</span>
<span id="cb6-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb6-15">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb6-16">  </span>
<span id="cb6-17">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> best_model, best_bp</span>
<span id="cb6-18"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span>;</span></code></pre></div></div>
</div>
<p>Let’s now apply this function to our dataset. The estimated breakpoint is at age 16, and the model coefficients are shown below:</p>
<div id="15245876" class="cell" data-execution_count="7">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb7-1">lm2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fit_piecewise</span>(d, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>);</span>
<span id="cb7-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># the first output is the model itself, the second the breakpoint used</span></span>
<span id="cb7-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coeftable</span>(lm2[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb7-4">lm2[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="8">
<pre><code>16</code></pre>
</div>
</div>
<p>Let’s visualise this model by drawing a scatterplot and adding the regression fit to it. While we’re at it, we might as well add a 95% confidence band around the regression fit.</p>
<div id="98876a9d" class="cell" data-execution_count="8">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_breakpoint</span>(d, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>);</span>
<span id="cb9-2">predictions <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">predict</span>(lm2[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], d;</span>
<span id="cb9-3">                      interval <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>confidence,</span>
<span id="cb9-4">                      level <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>);</span>
<span id="cb9-5">d[!, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"prediction"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> predictions[!, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"prediction"</span>];</span>
<span id="cb9-6">d[!, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lower"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> predictions[!, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lower"</span>];</span>
<span id="cb9-7">d[!, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"upper"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> predictions[!, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"upper"</span>];</span>
<span id="cb9-8"></span>
<span id="cb9-9"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">begin</span></span>
<span id="cb9-10"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@df</span> d <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>AOA, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>GJT</span>
<span id="cb9-11">           , seriestype <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>scatter</span>
<span id="cb9-12">           , legend <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>none</span>
<span id="cb9-13">           , xlabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AOA"</span></span>
<span id="cb9-14">           , ylabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GJT"</span></span>
<span id="cb9-15">      );</span>
<span id="cb9-16"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@df</span> d <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot!</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>AOA, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>prediction</span>
<span id="cb9-17">            , seriestype <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>line</span>
<span id="cb9-18">            , ribbon <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>prediction <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.-</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>lower, </span>
<span id="cb9-19">                        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>upper <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.-</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>prediction)</span>
<span id="cb9-20">      )</span>
<span id="cb9-21"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="9">
<!--?xml version="1.0" encoding="utf-8"?-->
<svg xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" width="672" height="480" viewbox="0 0 2688 1920">
<defs>
  <clippath id="clip100">
    <rect x="0" y="0" width="2688" height="1920"></rect>
  </clippath>
</defs>
<path clip-path="url(#clip100)" d="M0 1920 L2688 1920 L2688 0 L0 0  Z" fill="#ffffff" fill-rule="evenodd" fill-opacity="1"></path>
<defs>
  <clippath id="clip101">
    <rect x="537" y="0" width="1883" height="1883"></rect>
  </clippath>
</defs>
<path clip-path="url(#clip100)" d="M240.4 1734.12 L2640.76 1734.12 L2640.76 47.2441 L240.4 47.2441  Z" fill="#ffffff" fill-rule="evenodd" fill-opacity="1"></path>
<defs>
  <clippath id="clip102">
    <rect x="240" y="47" width="2401" height="1688"></rect>
  </clippath>
</defs>
<polyline clip-path="url(#clip102)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="479.886,1734.12 479.886,47.2441 "></polyline>
<polyline clip-path="url(#clip102)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="822.99,1734.12 822.99,47.2441 "></polyline>
<polyline clip-path="url(#clip102)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="1166.09,1734.12 1166.09,47.2441 "></polyline>
<polyline clip-path="url(#clip102)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="1509.2,1734.12 1509.2,47.2441 "></polyline>
<polyline clip-path="url(#clip102)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="1852.3,1734.12 1852.3,47.2441 "></polyline>
<polyline clip-path="url(#clip102)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="2195.41,1734.12 2195.41,47.2441 "></polyline>
<polyline clip-path="url(#clip102)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="2538.51,1734.12 2538.51,47.2441 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,1734.12 2640.76,1734.12 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="479.886,1734.12 479.886,1715.22 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="822.99,1734.12 822.99,1715.22 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="1166.09,1734.12 1166.09,1715.22 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="1509.2,1734.12 1509.2,1715.22 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="1852.3,1734.12 1852.3,1715.22 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="2195.41,1734.12 2195.41,1715.22 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="2538.51,1734.12 2538.51,1715.22 "></polyline>
<path clip-path="url(#clip100)" d="M454.574 1794.89 L462.213 1794.89 L462.213 1768.52 L453.903 1770.19 L453.903 1765.93 L462.167 1764.26 L466.842 1764.26 L466.842 1794.89 L474.481 1794.89 L474.481 1798.82 L454.574 1798.82 L454.574 1794.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M493.926 1767.34 Q490.315 1767.34 488.486 1770.9 Q486.68 1774.45 486.68 1781.58 Q486.68 1788.68 488.486 1792.25 Q490.315 1795.79 493.926 1795.79 Q497.56 1795.79 499.365 1792.25 Q501.194 1788.68 501.194 1781.58 Q501.194 1774.45 499.365 1770.9 Q497.56 1767.34 493.926 1767.34 M493.926 1763.64 Q499.736 1763.64 502.791 1768.24 Q505.87 1772.83 505.87 1781.58 Q505.87 1790.3 502.791 1794.91 Q499.736 1799.49 493.926 1799.49 Q488.116 1799.49 485.037 1794.91 Q481.981 1790.3 481.981 1781.58 Q481.981 1772.83 485.037 1768.24 Q488.116 1763.64 493.926 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M801.764 1794.89 L818.083 1794.89 L818.083 1798.82 L796.139 1798.82 L796.139 1794.89 Q798.801 1792.13 803.384 1787.5 Q807.991 1782.85 809.171 1781.51 Q811.416 1778.98 812.296 1777.25 Q813.199 1775.49 813.199 1773.8 Q813.199 1771.04 811.254 1769.31 Q809.333 1767.57 806.231 1767.57 Q804.032 1767.57 801.579 1768.34 Q799.148 1769.1 796.37 1770.65 L796.37 1765.93 Q799.194 1764.79 801.648 1764.21 Q804.102 1763.64 806.139 1763.64 Q811.509 1763.64 814.703 1766.32 Q817.898 1769.01 817.898 1773.5 Q817.898 1775.63 817.088 1777.55 Q816.301 1779.45 814.194 1782.04 Q813.616 1782.71 810.514 1785.93 Q807.412 1789.12 801.764 1794.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M837.898 1767.34 Q834.287 1767.34 832.458 1770.9 Q830.652 1774.45 830.652 1781.58 Q830.652 1788.68 832.458 1792.25 Q834.287 1795.79 837.898 1795.79 Q841.532 1795.79 843.338 1792.25 Q845.166 1788.68 845.166 1781.58 Q845.166 1774.45 843.338 1770.9 Q841.532 1767.34 837.898 1767.34 M837.898 1763.64 Q843.708 1763.64 846.763 1768.24 Q849.842 1772.83 849.842 1781.58 Q849.842 1790.3 846.763 1794.91 Q843.708 1799.49 837.898 1799.49 Q832.088 1799.49 829.009 1794.91 Q825.953 1790.3 825.953 1781.58 Q825.953 1772.83 829.009 1768.24 Q832.088 1763.64 837.898 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M1154.94 1780.19 Q1158.29 1780.9 1160.17 1783.17 Q1162.07 1785.44 1162.07 1788.77 Q1162.07 1793.89 1158.55 1796.69 Q1155.03 1799.49 1148.55 1799.49 Q1146.37 1799.49 1144.06 1799.05 Q1141.77 1798.64 1139.31 1797.78 L1139.31 1793.27 Q1141.26 1794.4 1143.57 1794.98 Q1145.89 1795.56 1148.41 1795.56 Q1152.81 1795.56 1155.1 1793.82 Q1157.41 1792.08 1157.41 1788.77 Q1157.41 1785.72 1155.26 1784.01 Q1153.13 1782.27 1149.31 1782.27 L1145.28 1782.27 L1145.28 1778.43 L1149.5 1778.43 Q1152.95 1778.43 1154.78 1777.06 Q1156.6 1775.67 1156.6 1773.08 Q1156.6 1770.42 1154.71 1769.01 Q1152.83 1767.57 1149.31 1767.57 Q1147.39 1767.57 1145.19 1767.99 Q1142.99 1768.4 1140.35 1769.28 L1140.35 1765.12 Q1143.02 1764.38 1145.33 1764.01 Q1147.67 1763.64 1149.73 1763.64 Q1155.05 1763.64 1158.15 1766.07 Q1161.26 1768.47 1161.26 1772.59 Q1161.26 1775.46 1159.61 1777.46 Q1157.97 1779.42 1154.94 1780.19 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M1180.93 1767.34 Q1177.32 1767.34 1175.49 1770.9 Q1173.69 1774.45 1173.69 1781.58 Q1173.69 1788.68 1175.49 1792.25 Q1177.32 1795.79 1180.93 1795.79 Q1184.57 1795.79 1186.37 1792.25 Q1188.2 1788.68 1188.2 1781.58 Q1188.2 1774.45 1186.37 1770.9 Q1184.57 1767.34 1180.93 1767.34 M1180.93 1763.64 Q1186.74 1763.64 1189.8 1768.24 Q1192.88 1772.83 1192.88 1781.58 Q1192.88 1790.3 1189.8 1794.91 Q1186.74 1799.49 1180.93 1799.49 Q1175.12 1799.49 1172.04 1794.91 Q1168.99 1790.3 1168.99 1781.58 Q1168.99 1772.83 1172.04 1768.24 Q1175.12 1763.64 1180.93 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M1497.37 1768.34 L1485.56 1786.78 L1497.37 1786.78 L1497.37 1768.34 M1496.14 1764.26 L1502.02 1764.26 L1502.02 1786.78 L1506.95 1786.78 L1506.95 1790.67 L1502.02 1790.67 L1502.02 1798.82 L1497.37 1798.82 L1497.37 1790.67 L1481.77 1790.67 L1481.77 1786.16 L1496.14 1764.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M1524.68 1767.34 Q1521.07 1767.34 1519.24 1770.9 Q1517.44 1774.45 1517.44 1781.58 Q1517.44 1788.68 1519.24 1792.25 Q1521.07 1795.79 1524.68 1795.79 Q1528.32 1795.79 1530.12 1792.25 Q1531.95 1788.68 1531.95 1781.58 Q1531.95 1774.45 1530.12 1770.9 Q1528.32 1767.34 1524.68 1767.34 M1524.68 1763.64 Q1530.49 1763.64 1533.55 1768.24 Q1536.63 1772.83 1536.63 1781.58 Q1536.63 1790.3 1533.55 1794.91 Q1530.49 1799.49 1524.68 1799.49 Q1518.87 1799.49 1515.8 1794.91 Q1512.74 1790.3 1512.74 1781.58 Q1512.74 1772.83 1515.8 1768.24 Q1518.87 1763.64 1524.68 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M1827 1764.26 L1845.36 1764.26 L1845.36 1768.2 L1831.28 1768.2 L1831.28 1776.67 Q1832.3 1776.32 1833.32 1776.16 Q1834.34 1775.97 1835.36 1775.97 Q1841.15 1775.97 1844.52 1779.15 Q1847.9 1782.32 1847.9 1787.73 Q1847.9 1793.31 1844.43 1796.41 Q1840.96 1799.49 1834.64 1799.49 Q1832.46 1799.49 1830.2 1799.12 Q1827.95 1798.75 1825.54 1798.01 L1825.54 1793.31 Q1827.63 1794.45 1829.85 1795 Q1832.07 1795.56 1834.55 1795.56 Q1838.55 1795.56 1840.89 1793.45 Q1843.23 1791.34 1843.23 1787.73 Q1843.23 1784.12 1840.89 1782.02 Q1838.55 1779.91 1834.55 1779.91 Q1832.67 1779.91 1830.8 1780.33 Q1828.95 1780.74 1827 1781.62 L1827 1764.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M1867.12 1767.34 Q1863.51 1767.34 1861.68 1770.9 Q1859.87 1774.45 1859.87 1781.58 Q1859.87 1788.68 1861.68 1792.25 Q1863.51 1795.79 1867.12 1795.79 Q1870.75 1795.79 1872.56 1792.25 Q1874.39 1788.68 1874.39 1781.58 Q1874.39 1774.45 1872.56 1770.9 Q1870.75 1767.34 1867.12 1767.34 M1867.12 1763.64 Q1872.93 1763.64 1875.98 1768.24 Q1879.06 1772.83 1879.06 1781.58 Q1879.06 1790.3 1875.98 1794.91 Q1872.93 1799.49 1867.12 1799.49 Q1861.31 1799.49 1858.23 1794.91 Q1855.17 1790.3 1855.17 1781.58 Q1855.17 1772.83 1858.23 1768.24 Q1861.31 1763.64 1867.12 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M2180.81 1779.68 Q2177.66 1779.68 2175.81 1781.83 Q2173.98 1783.98 2173.98 1787.73 Q2173.98 1791.46 2175.81 1793.64 Q2177.66 1795.79 2180.81 1795.79 Q2183.96 1795.79 2185.79 1793.64 Q2187.64 1791.46 2187.64 1787.73 Q2187.64 1783.98 2185.79 1781.83 Q2183.96 1779.68 2180.81 1779.68 M2190.09 1765.02 L2190.09 1769.28 Q2188.34 1768.45 2186.53 1768.01 Q2184.75 1767.57 2182.99 1767.57 Q2178.36 1767.57 2175.9 1770.7 Q2173.47 1773.82 2173.13 1780.14 Q2174.49 1778.13 2176.55 1777.06 Q2178.61 1775.97 2181.09 1775.97 Q2186.3 1775.97 2189.31 1779.15 Q2192.34 1782.29 2192.34 1787.73 Q2192.34 1793.06 2189.19 1796.27 Q2186.04 1799.49 2180.81 1799.49 Q2174.82 1799.49 2171.65 1794.91 Q2168.47 1790.3 2168.47 1781.58 Q2168.47 1773.38 2172.36 1768.52 Q2176.25 1763.64 2182.8 1763.64 Q2184.56 1763.64 2186.34 1763.98 Q2188.15 1764.33 2190.09 1765.02 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M2210.4 1767.34 Q2206.78 1767.34 2204.96 1770.9 Q2203.15 1774.45 2203.15 1781.58 Q2203.15 1788.68 2204.96 1792.25 Q2206.78 1795.79 2210.4 1795.79 Q2214.03 1795.79 2215.83 1792.25 Q2217.66 1788.68 2217.66 1781.58 Q2217.66 1774.45 2215.83 1770.9 Q2214.03 1767.34 2210.4 1767.34 M2210.4 1763.64 Q2216.21 1763.64 2219.26 1768.24 Q2222.34 1772.83 2222.34 1781.58 Q2222.34 1790.3 2219.26 1794.91 Q2216.21 1799.49 2210.4 1799.49 Q2204.58 1799.49 2201.51 1794.91 Q2198.45 1790.3 2198.45 1781.58 Q2198.45 1772.83 2201.51 1768.24 Q2204.58 1763.64 2210.4 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M2511.87 1764.26 L2534.09 1764.26 L2534.09 1766.25 L2521.54 1798.82 L2516.66 1798.82 L2528.46 1768.2 L2511.87 1768.2 L2511.87 1764.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M2553.21 1767.34 Q2549.6 1767.34 2547.77 1770.9 Q2545.96 1774.45 2545.96 1781.58 Q2545.96 1788.68 2547.77 1792.25 Q2549.6 1795.79 2553.21 1795.79 Q2556.84 1795.79 2558.65 1792.25 Q2560.48 1788.68 2560.48 1781.58 Q2560.48 1774.45 2558.65 1770.9 Q2556.84 1767.34 2553.21 1767.34 M2553.21 1763.64 Q2559.02 1763.64 2562.08 1768.24 Q2565.15 1772.83 2565.15 1781.58 Q2565.15 1790.3 2562.08 1794.91 Q2559.02 1799.49 2553.21 1799.49 Q2547.4 1799.49 2544.32 1794.91 Q2541.27 1790.3 2541.27 1781.58 Q2541.27 1772.83 2544.32 1768.24 Q2547.4 1763.64 2553.21 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M1393.77 1842.11 L1385.05 1865.76 L1402.53 1865.76 L1393.77 1842.11 M1390.15 1835.78 L1397.43 1835.78 L1415.54 1883.3 L1408.86 1883.3 L1404.53 1871.11 L1383.11 1871.11 L1378.78 1883.3 L1372 1883.3 L1390.15 1835.78 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M1440.63 1840.14 Q1433.62 1840.14 1429.49 1845.36 Q1425.38 1850.58 1425.38 1859.59 Q1425.38 1868.56 1429.49 1873.78 Q1433.62 1879 1440.63 1879 Q1447.63 1879 1451.7 1873.78 Q1455.81 1868.56 1455.81 1859.59 Q1455.81 1850.58 1451.7 1845.36 Q1447.63 1840.14 1440.63 1840.14 M1440.63 1834.92 Q1450.62 1834.92 1456.6 1841.64 Q1462.59 1848.32 1462.59 1859.59 Q1462.59 1870.82 1456.6 1877.54 Q1450.62 1884.22 1440.63 1884.22 Q1430.6 1884.22 1424.58 1877.54 Q1418.6 1870.86 1418.6 1859.59 Q1418.6 1848.32 1424.58 1841.64 Q1430.6 1834.92 1440.63 1834.92 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M1487.38 1842.11 L1478.66 1865.76 L1496.13 1865.76 L1487.38 1842.11 M1483.75 1835.78 L1491.04 1835.78 L1509.15 1883.3 L1502.47 1883.3 L1498.14 1871.11 L1476.72 1871.11 L1472.39 1883.3 L1465.61 1883.3 L1483.75 1835.78 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><polyline clip-path="url(#clip102)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,1659.76 2640.76,1659.76 "></polyline>
<polyline clip-path="url(#clip102)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,1314.56 2640.76,1314.56 "></polyline>
<polyline clip-path="url(#clip102)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,969.354 2640.76,969.354 "></polyline>
<polyline clip-path="url(#clip102)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,624.149 2640.76,624.149 "></polyline>
<polyline clip-path="url(#clip102)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="240.4,278.944 2640.76,278.944 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,1734.12 240.4,47.2441 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,1659.76 259.297,1659.76 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,1314.56 259.297,1314.56 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,969.354 259.297,969.354 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,624.149 259.297,624.149 "></polyline>
<polyline clip-path="url(#clip100)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="240.4,278.944 259.297,278.944 "></polyline>
<path clip-path="url(#clip100)" d="M118.622 1673.11 L126.261 1673.11 L126.261 1646.74 L117.951 1648.41 L117.951 1644.15 L126.214 1642.48 L130.89 1642.48 L130.89 1673.11 L138.529 1673.11 L138.529 1677.04 L118.622 1677.04 L118.622 1673.11 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M157.973 1645.56 Q154.362 1645.56 152.534 1649.13 Q150.728 1652.67 150.728 1659.8 Q150.728 1666.9 152.534 1670.47 Q154.362 1674.01 157.973 1674.01 Q161.608 1674.01 163.413 1670.47 Q165.242 1666.9 165.242 1659.8 Q165.242 1652.67 163.413 1649.13 Q161.608 1645.56 157.973 1645.56 M157.973 1641.86 Q163.784 1641.86 166.839 1646.46 Q169.918 1651.05 169.918 1659.8 Q169.918 1668.52 166.839 1673.13 Q163.784 1677.71 157.973 1677.71 Q152.163 1677.71 149.085 1673.13 Q146.029 1668.52 146.029 1659.8 Q146.029 1651.05 149.085 1646.46 Q152.163 1641.86 157.973 1641.86 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M188.135 1645.56 Q184.524 1645.56 182.696 1649.13 Q180.89 1652.67 180.89 1659.8 Q180.89 1666.9 182.696 1670.47 Q184.524 1674.01 188.135 1674.01 Q191.77 1674.01 193.575 1670.47 Q195.404 1666.9 195.404 1659.8 Q195.404 1652.67 193.575 1649.13 Q191.77 1645.56 188.135 1645.56 M188.135 1641.86 Q193.946 1641.86 197.001 1646.46 Q200.08 1651.05 200.08 1659.8 Q200.08 1668.52 197.001 1673.13 Q193.946 1677.71 188.135 1677.71 Q182.325 1677.71 179.247 1673.13 Q176.191 1668.52 176.191 1659.8 Q176.191 1651.05 179.247 1646.46 Q182.325 1641.86 188.135 1641.86 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M119.617 1327.9 L127.256 1327.9 L127.256 1301.54 L118.946 1303.2 L118.946 1298.95 L127.21 1297.28 L131.886 1297.28 L131.886 1327.9 L139.525 1327.9 L139.525 1331.84 L119.617 1331.84 L119.617 1327.9 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M152.997 1327.9 L169.316 1327.9 L169.316 1331.84 L147.372 1331.84 L147.372 1327.9 Q150.034 1325.15 154.617 1320.52 Q159.223 1315.87 160.404 1314.52 Q162.649 1312 163.529 1310.26 Q164.432 1308.51 164.432 1306.82 Q164.432 1304.06 162.487 1302.32 Q160.566 1300.59 157.464 1300.59 Q155.265 1300.59 152.811 1301.35 Q150.381 1302.12 147.603 1303.67 L147.603 1298.95 Q150.427 1297.81 152.881 1297.23 Q155.335 1296.65 157.372 1296.65 Q162.742 1296.65 165.936 1299.34 Q169.131 1302.02 169.131 1306.51 Q169.131 1308.64 168.321 1310.57 Q167.534 1312.46 165.427 1315.06 Q164.848 1315.73 161.747 1318.95 Q158.645 1322.14 152.997 1327.9 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M179.177 1297.28 L197.533 1297.28 L197.533 1301.21 L183.459 1301.21 L183.459 1309.69 Q184.478 1309.34 185.496 1309.18 Q186.515 1308.99 187.534 1308.99 Q193.321 1308.99 196.7 1312.16 Q200.08 1315.33 200.08 1320.75 Q200.08 1326.33 196.608 1329.43 Q193.135 1332.51 186.816 1332.51 Q184.64 1332.51 182.371 1332.14 Q180.126 1331.77 177.719 1331.03 L177.719 1326.33 Q179.802 1327.46 182.024 1328.02 Q184.246 1328.57 186.723 1328.57 Q190.728 1328.57 193.066 1326.47 Q195.404 1324.36 195.404 1320.75 Q195.404 1317.14 193.066 1315.03 Q190.728 1312.93 186.723 1312.93 Q184.848 1312.93 182.973 1313.34 Q181.122 1313.76 179.177 1314.64 L179.177 1297.28 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M118.622 982.699 L126.261 982.699 L126.261 956.333 L117.951 958 L117.951 953.74 L126.214 952.074 L130.89 952.074 L130.89 982.699 L138.529 982.699 L138.529 986.634 L118.622 986.634 L118.622 982.699 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M148.02 952.074 L166.376 952.074 L166.376 956.009 L152.302 956.009 L152.302 964.481 Q153.321 964.134 154.339 963.972 Q155.358 963.787 156.376 963.787 Q162.163 963.787 165.543 966.958 Q168.922 970.129 168.922 975.546 Q168.922 981.125 165.45 984.226 Q161.978 987.305 155.659 987.305 Q153.483 987.305 151.214 986.935 Q148.969 986.564 146.562 985.824 L146.562 981.125 Q148.645 982.259 150.867 982.814 Q153.089 983.37 155.566 983.37 Q159.571 983.37 161.909 981.263 Q164.247 979.157 164.247 975.546 Q164.247 971.935 161.909 969.828 Q159.571 967.722 155.566 967.722 Q153.691 967.722 151.816 968.138 Q149.964 968.555 148.02 969.435 L148.02 952.074 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M188.135 955.152 Q184.524 955.152 182.696 958.717 Q180.89 962.259 180.89 969.388 Q180.89 976.495 182.696 980.06 Q184.524 983.601 188.135 983.601 Q191.77 983.601 193.575 980.06 Q195.404 976.495 195.404 969.388 Q195.404 962.259 193.575 958.717 Q191.77 955.152 188.135 955.152 M188.135 951.449 Q193.946 951.449 197.001 956.055 Q200.08 960.639 200.08 969.388 Q200.08 978.115 197.001 982.722 Q193.946 987.305 188.135 987.305 Q182.325 987.305 179.247 982.722 Q176.191 978.115 176.191 969.388 Q176.191 960.639 179.247 956.055 Q182.325 951.449 188.135 951.449 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M119.617 637.494 L127.256 637.494 L127.256 611.128 L118.946 612.795 L118.946 608.536 L127.21 606.869 L131.886 606.869 L131.886 637.494 L139.525 637.494 L139.525 641.429 L119.617 641.429 L119.617 637.494 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M147.788 606.869 L170.01 606.869 L170.01 608.86 L157.464 641.429 L152.58 641.429 L164.385 610.804 L147.788 610.804 L147.788 606.869 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M179.177 606.869 L197.533 606.869 L197.533 610.804 L183.459 610.804 L183.459 619.276 Q184.478 618.929 185.496 618.767 Q186.515 618.582 187.534 618.582 Q193.321 618.582 196.7 621.753 Q200.08 624.924 200.08 630.341 Q200.08 635.92 196.608 639.022 Q193.135 642.1 186.816 642.1 Q184.64 642.1 182.371 641.73 Q180.126 641.359 177.719 640.619 L177.719 635.92 Q179.802 637.054 182.024 637.61 Q184.246 638.165 186.723 638.165 Q190.728 638.165 193.066 636.059 Q195.404 633.952 195.404 630.341 Q195.404 626.73 193.066 624.623 Q190.728 622.517 186.723 622.517 Q184.848 622.517 182.973 622.934 Q181.122 623.35 179.177 624.23 L179.177 606.869 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M121.839 292.289 L138.159 292.289 L138.159 296.224 L116.214 296.224 L116.214 292.289 Q118.876 289.534 123.46 284.905 Q128.066 280.252 129.247 278.909 Q131.492 276.386 132.372 274.65 Q133.275 272.891 133.275 271.201 Q133.275 268.447 131.33 266.71 Q129.409 264.974 126.307 264.974 Q124.108 264.974 121.654 265.738 Q119.224 266.502 116.446 268.053 L116.446 263.331 Q119.27 262.197 121.724 261.618 Q124.177 261.039 126.214 261.039 Q131.585 261.039 134.779 263.724 Q137.974 266.409 137.974 270.9 Q137.974 273.03 137.163 274.951 Q136.376 276.849 134.27 279.442 Q133.691 280.113 130.589 283.331 Q127.488 286.525 121.839 292.289 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M157.973 264.743 Q154.362 264.743 152.534 268.308 Q150.728 271.849 150.728 278.979 Q150.728 286.085 152.534 289.65 Q154.362 293.192 157.973 293.192 Q161.608 293.192 163.413 289.65 Q165.242 286.085 165.242 278.979 Q165.242 271.849 163.413 268.308 Q161.608 264.743 157.973 264.743 M157.973 261.039 Q163.784 261.039 166.839 265.646 Q169.918 270.229 169.918 278.979 Q169.918 287.706 166.839 292.312 Q163.784 296.895 157.973 296.895 Q152.163 296.895 149.085 292.312 Q146.029 287.706 146.029 278.979 Q146.029 270.229 149.085 265.646 Q152.163 261.039 157.973 261.039 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M188.135 264.743 Q184.524 264.743 182.696 268.308 Q180.89 271.849 180.89 278.979 Q180.89 286.085 182.696 289.65 Q184.524 293.192 188.135 293.192 Q191.77 293.192 193.575 289.65 Q195.404 286.085 195.404 278.979 Q195.404 271.849 193.575 268.308 Q191.77 264.743 188.135 264.743 M188.135 261.039 Q193.946 261.039 197.001 265.646 Q200.08 270.229 200.08 278.979 Q200.08 287.706 197.001 292.312 Q193.946 296.895 188.135 296.895 Q182.325 296.895 179.247 292.312 Q176.191 287.706 176.191 278.979 Q176.191 270.229 179.247 265.646 Q182.325 261.039 188.135 261.039 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M54.859 908.584 L42.0957 908.584 L42.0957 919.088 L36.8122 919.088 L36.8122 902.218 L57.2143 902.218 Q59.856 905.942 61.2247 910.43 Q62.5615 914.918 62.5615 920.011 Q62.5615 931.151 56.0684 937.453 Q49.5436 943.723 37.9262 943.723 Q26.2769 943.723 19.7839 937.453 Q13.2591 931.151 13.2591 920.011 Q13.2591 915.364 14.4049 911.194 Q15.5507 906.993 17.7787 903.46 L24.6219 903.46 Q21.5981 907.024 20.0704 911.035 Q18.5426 915.045 18.5426 919.469 Q18.5426 928.19 23.4124 932.583 Q28.2821 936.943 37.9262 936.943 Q47.5384 936.943 52.4082 932.583 Q57.2779 928.19 57.2779 919.469 Q57.2779 916.064 56.705 913.39 Q56.1003 910.717 54.859 908.584 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M14.1184 890.474 L14.1184 884.044 L58.3283 884.044 Q66.922 884.044 70.8051 887.323 Q74.6881 890.569 74.6881 897.794 L74.6881 900.245 L69.2773 900.245 L69.2773 898.24 Q69.2773 893.975 66.8902 892.224 Q64.503 890.474 58.3283 890.474 L14.1184 890.474 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip100)" d="M14.1184 877.838 L14.1184 837.638 L19.5293 837.638 L19.5293 854.507 L61.6384 854.507 L61.6384 860.969 L19.5293 860.969 L19.5293 877.838 L14.1184 877.838 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><circle clip-path="url(#clip102)" cx="2161.1" cy="955.546" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="445.576" cy="527.492" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1886.61" cy="1286.94" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="2126.79" cy="1480.26" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1063.16" cy="872.696" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="514.197" cy="444.642" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="720.059" cy="1314.56" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="2092.48" cy="1135.05" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="479.886" cy="679.382" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="617.128" cy="720.806" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="822.99" cy="637.957" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1303.34" cy="983.162" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="788.68" cy="900.313" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1989.54" cy="983.162" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="2298.34" cy="1563.11" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="2572.82" cy="1604.53" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="960.232" cy="610.341" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="685.749" cy="1066.01" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="891.611" cy="1204.09" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1783.68" cy="1480.26" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="720.059" cy="679.382" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="822.99" cy="1052.2" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1646.44" cy="955.546" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="960.232" cy="527.492" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="2058.17" cy="1480.26" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="308.334" cy="320.369" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="2572.82" cy="1466.45" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1371.96" cy="693.19" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="2092.48" cy="1452.64" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1680.75" cy="1452.64" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="2058.17" cy="1411.22" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1646.44" cy="1411.22" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="925.922" cy="900.313" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="754.37" cy="472.259" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1577.82" cy="1217.9" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1989.54" cy="1438.83" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="617.128" cy="706.998" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1749.37" cy="1231.71" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="411.266" cy="334.177" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="960.232" cy="1355.98" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1920.92" cy="996.97" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1063.16" cy="444.642" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="514.197" cy="306.561" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="754.37" cy="637.957" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1783.68" cy="969.354" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1200.4" cy="858.888" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1817.99" cy="1231.71" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1783.68" cy="1231.71" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="651.438" cy="555.108" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1817.99" cy="1480.26" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="925.922" cy="734.614" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="479.886" cy="375.601" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="822.99" cy="776.039" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="960.232" cy="513.683" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1337.65" cy="1411.22" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1371.96" cy="1162.67" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1646.44" cy="1452.64" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1817.99" cy="1093.63" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="651.438" cy="541.3" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="548.507" cy="375.601" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1955.23" cy="1107.44" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="685.749" cy="927.929" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1989.54" cy="1521.68" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="445.576" cy="789.847" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="994.543" cy="637.957" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1063.16" cy="706.998" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="754.37" cy="568.916" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1028.85" cy="1066.01" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="891.611" cy="803.655" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1852.3" cy="1273.13" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1577.82" cy="1397.41" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="308.334" cy="320.369" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="617.128" cy="720.806" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="1474.89" cy="1217.9" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="2058.17" cy="1107.44" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip102)" cx="548.507" cy="527.492" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<path clip-path="url(#clip102)" d="M308.334 514.796 L308.334 514.796 L411.266 571.858 L445.576 592.276 L445.576 592.276 L479.886 614.002 L479.886 614.002 L514.197 637.767 L514.197 637.767 L548.507 664.733 L548.507 664.733 L617.128 734.604 L617.128 734.604 L617.128 734.604 L651.438 779.36 L651.438 779.36 L685.749 829.618 L685.749 829.618 L720.059 841.795 L720.059 841.795 L754.37 854.024 L754.37 854.024 L754.37 854.024 L788.68 866.312 L822.99 878.664 L822.99 878.664 L822.99 878.664 L891.611 903.585 L891.611 903.585 L925.922 916.169 L925.922 916.169 L960.232 928.846 L960.232 928.846 L960.232 928.846 L960.232 928.846 L994.543 941.625 L1028.85 954.515 L1063.16 967.527 L1063.16 967.527 L1063.16 967.527 L1200.4 1021.01 L1303.34 1062.93 L1337.65 1077.3 L1371.96 1091.89 L1371.96 1091.89 L1474.89 1136.9 L1577.82 1183.77 L1577.82 1183.77 L1646.44 1215.94 L1646.44 1215.94 L1646.44 1215.94 L1680.75 1232.28 L1749.37 1265.4 L1783.68 1282.16 L1783.68 1282.16 L1783.68 1282.16 L1817.99 1299.03 L1817.99 1299.03 L1817.99 1299.03 L1852.3 1316.02 L1886.61 1333.1 L1920.92 1350.27 L1955.23 1367.53 L1989.54 1384.86 L1989.54 1384.86 L1989.54 1384.86 L2058.17 1419.72 L2058.17 1419.72 L2058.17 1419.72 L2092.48 1437.24 L2092.48 1437.24 L2126.79 1454.81 L2161.1 1472.43 L2298.34 1543.29 L2572.82 1686.38 L2572.82 1686.38 L2572.82 1427.48 L2572.82 1427.48 L2298.34 1332.72 L2161.1 1284.67 L2126.79 1272.55 L2092.48 1260.39 L2092.48 1260.39 L2058.17 1248.18 L2058.17 1248.18 L2058.17 1248.18 L1989.54 1223.58 L1989.54 1223.58 L1989.54 1223.58 L1955.23 1211.18 L1920.92 1198.71 L1886.61 1186.15 L1852.3 1173.51 L1817.99 1160.76 L1817.99 1160.76 L1817.99 1160.76 L1783.68 1147.91 L1783.68 1147.91 L1783.68 1147.91 L1749.37 1134.93 L1680.75 1108.59 L1646.44 1095.2 L1646.44 1095.2 L1646.44 1095.2 L1577.82 1067.92 L1577.82 1067.92 L1474.89 1025.59 L1371.96 981.417 L1371.96 981.417 L1337.65 966.267 L1303.34 950.908 L1200.4 903.643 L1063.16 838.204 L1063.16 838.204 L1063.16 838.204 L1028.85 821.486 L994.543 804.646 L960.232 787.694 L960.232 787.694 L960.232 787.694 L960.232 787.694 L925.922 770.641 L925.922 770.641 L891.611 753.495 L891.611 753.495 L822.99 718.956 L822.99 718.956 L822.99 718.956 L788.68 701.578 L754.37 684.136 L754.37 684.136 L754.37 684.136 L720.059 666.635 L720.059 666.635 L685.749 649.081 L685.749 649.081 L651.438 620.347 L651.438 620.347 L617.128 586.11 L617.128 586.11 L617.128 586.11 L548.507 497.997 L548.507 497.997 L514.197 445.97 L514.197 445.97 L479.886 390.742 L479.886 390.742 L445.576 333.476 L445.576 333.476 L411.266 274.902 L308.334 94.9858 L308.334 94.9858  Z" fill="#e26f46" fill-rule="evenodd" fill-opacity="0.5"></path>
<polyline clip-path="url(#clip102)" style="stroke:#e26f46; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="308.334,304.891 308.334,304.891 411.266,423.38 445.576,462.876 479.886,502.372 514.197,541.868 548.507,581.365 617.128,660.357 651.438,699.854 685.749,739.35 720.059,754.215 754.37,769.08 788.68,783.945 822.99,798.81 891.611,828.54 925.922,843.405 960.232,858.27 994.543,873.135 1028.85,888 1063.16,902.865 1200.4,962.326 1303.34,1006.92 1337.65,1021.79 1371.96,1036.65 1474.89,1081.25 1577.82,1125.84 1646.44,1155.57 1680.75,1170.44 1749.37,1200.17 1783.68,1215.03 1817.99,1229.9 1852.3,1244.76 1886.61,1259.63 1920.92,1274.49 1955.23,1289.36 1989.54,1304.22 2058.17,1333.95 2092.48,1348.82 2126.79,1363.68 2161.1,1378.55 2298.34,1438.01 2572.82,1556.93 "></polyline>
</svg>
</div>
</div>
<p>We could run an <img src="https://latex.codecogs.com/png.latex?F">-test for the model comparison like below, but the <img src="https://latex.codecogs.com/png.latex?p">-value corresponds to the <img src="https://latex.codecogs.com/png.latex?p">-value for the <code>since_bp</code> value, anyway:</p>
<div id="71b2c915" class="cell" data-execution_count="9">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb10-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ftest</span>(lm1.model, lm2[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>].model);</span></code></pre></div></div>
</div>
<p>But there’s a problem: This <img src="https://latex.codecogs.com/png.latex?p">-value can’t be taken at face value. By looping through different possible breakpoint and then picking the one that worked best for our dataset, we’ve increased our chances of finding some pattern in the data even if nothing is going on. So we need to recalibrate the <img src="https://latex.codecogs.com/png.latex?p">-value we’ve obtained.</p>
</section>
<section id="recalibrating-the-p-value" class="level2">
<h2 class="anchored" data-anchor-id="recalibrating-the-p-value">Recalibrating the p-value</h2>
<p>Our strategy is as follows. We will generate a fairly large number of datasets similar to <code>d</code> but of which we know that there isn’t any breakpoint in the <code>GJT</code>/<code>AOA</code> relationship. We will do this by simulating new <code>GJT</code> values from the simple regression model fitted above (<code>lm1</code>). We will then apply the <code>fit_piecewise()</code> function to each of these datasets, using the same <code>minbp</code> and <code>maxbp</code> values as before and obtain the <img src="https://latex.codecogs.com/png.latex?p">-value associated with each model. We will then compute the proportion of the <img src="https://latex.codecogs.com/png.latex?p">-value so obtained that is lower than the <img src="https://latex.codecogs.com/png.latex?p">-value from our original model, i.e., 0.0472.</p>
<p>I wasn’t able to find a Julia function similar to R’s <code>simulate()</code> that simulates a new outcome variable based on a linear regression model. But such a function is easy enough to put together:</p>
<div id="3efb237b" class="cell" data-execution_count="10">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb11-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">using</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Distributions</span></span>
<span id="cb11-2"></span>
<span id="cb11-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simulate_outcome</span>(null_model)</span>
<span id="cb11-4">  resid_distr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Normal</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dispersion</span>(null_model.model))</span>
<span id="cb11-5">  prediction <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fitted</span>(null_model)</span>
<span id="cb11-6">  new_outcome <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> prediction <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rand</span>(resid_distr, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(prediction))</span>
<span id="cb11-7">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> new_outcome</span>
<span id="cb11-8"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span>;</span></code></pre></div></div>
</div>
<p>The <code>one_run()</code> function generates a single new outcome vector, overwrites the <code>GJT</code> variable in our dataset with it, and then applies the <code>fit_piecewise()</code> function to the dataset, returning the <img src="https://latex.codecogs.com/png.latex?p">-value of the best-fitting piecewise regression model.</p>
<div id="dd936c10" class="cell" data-execution_count="11">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb12-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">one_run</span>(data, null_model, min_bp, max_bp)</span>
<span id="cb12-2">  new_outcome <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simulate_outcome</span>(null_model)</span>
<span id="cb12-3">  data[!, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GJT"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> new_outcome</span>
<span id="cb12-4">  best_model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fit_piecewise</span>(data, min_bp, max_bp)</span>
<span id="cb12-5">  pval <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coeftable</span>(best_model[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]).cols[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>][<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]</span>
<span id="cb12-6">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pval</span>
<span id="cb12-7"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span>;</span></code></pre></div></div>
</div>
<p>Finally, the <code>generate_p_distr()</code> function runs the <code>one_run()</code> function a large number of times and output the <img src="https://latex.codecogs.com/png.latex?p">-values generated.</p>
<div id="b5b203d6" class="cell" data-execution_count="12">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb13-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">generate_p_distr</span>(data, null_model, min_bp, max_bp, n_runs)</span>
<span id="cb13-2">  pvals <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">one_run</span>(data, null_model, min_bp, max_bp) for _ <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>n_runs]</span>
<span id="cb13-3">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pvals</span>
<span id="cb13-4"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span>;</span></code></pre></div></div>
</div>
<p>Our simulation will consist of 25,000 runs, and in each run, 16 regression models will be fitted, for a total of 400,000 models. On my machine, this takes less than 20 seconds (i.e., less than 50 microseconds per model).</p>
<div id="07d68f9b" class="cell" data-execution_count="13">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb14-1">n_runs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">25_000</span>;</span>
<span id="cb14-2">pvals <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">generate_p_distr</span>(d, lm1, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, n_runs);</span></code></pre></div></div>
</div>
<p>For about 11–12% of the datasets in which no breakpoint governed the data, the <code>fit_piecewise()</code> procedure returned a <img src="https://latex.codecogs.com/png.latex?p">-value of 0.0472 or lower. So our original <img src="https://latex.codecogs.com/png.latex?p">-value of 0.0472 ought to be recalibrated to about 0.12.</p>
<div id="e3e828be" class="cell" data-execution_count="14">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb15-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(pvals <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.&lt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0472</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> n_runs</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="15">
<pre><code>0.11496</code></pre>
</div>
</div>


</section>

 ]]></description>
  <category>Julia</category>
  <category>piecewise regression</category>
  <category>non-linearities</category>
  <guid>https://janhove.github.io/posts/2023-03-07-julia-breakpoint-regression/</guid>
  <pubDate>Tue, 07 Mar 2023 00:00:00 GMT</pubDate>
  <media:content url="https://janhove.github.io/posts/2023-03-07-julia-breakpoint-regression/image.png" medium="image" type="image/png" height="96" width="144"/>
</item>
<item>
  <title>Adjusting to Julia: Tea tasting</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2023-02-23-julia-tea-tasting/</link>
  <description><![CDATA[ 




<p>In this third blog post in which I try my hand at the <a href="https://julialang.org/">Julia</a> language, I’ll tackle a slight variation of an old problem – Fisher’s tea tasting lady – both analytically and using a brute-force simulation.</p>
<section id="the-lady-tasting-tea" class="level2">
<h2 class="anchored" data-anchor-id="the-lady-tasting-tea">The lady tasting tea</h2>
<p>In <em>The Design of Experiments</em>, Ronald A. Fisher explained the Fisher exact test using the following example. Imagine that a lady claims she can taste the difference between cups of tea in which the tea was poured into the cup first and then milk was added, and cups of tea in which the milk was poured first and then the tea was added. A sceptic might put the lady to the test and prepare eight cups of tea – four with tea to which milk was added, and four with milk to which tea was added. (Yuck to both, by the way.) The lady is presented with these in a random order and is asked to identify those four cups with tea to which milk was added. Now, if the lady has no discriminatory ability whatever, there is only a 1-in-70 chance she identifies all four cups correctly. This is because there are 70 ways of picking four cups out of eight, and only one of these ways is correct. In Julia:</p>
<div id="757099d8" class="cell" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">binomial</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="2">
<pre><code>70</code></pre>
</div>
</div>
<p>We can now imagine a slight variation on this experiment. If the lady identifies all four cups correctly, we choose to believe she has the purported discriminatory ability. If she identifies two or fewer cups correctly, we remain sceptical. But she identifies three out of four cups correctly, we prepare another eight cups of tea and give her another chance under the same conditions.</p>
<p>We can ask two questions about this new procedure:</p>
<ol type="1">
<li>With which probability will we believe the lady if she, in fact, does not have any discriminatory ability?</li>
<li>How many rounds of tea tasting will we need on average before the experiment terminates?</li>
</ol>
<p>In the following, I’ll share both analytical and a simulation-based answers to these questions.</p>
</section>
<section id="analytical-solution" class="level2">
<h2 class="anchored" data-anchor-id="analytical-solution">Analytical solution</h2>
<p>Under the null hypothesis of no discriminatory ability, the number of correctly identified cups in any one draw (<img src="https://latex.codecogs.com/png.latex?X">) follows a <a href="https://en.wikipedia.org/wiki/Hypergeometric_distribution">hypergeometric distribution</a> with parameters <img src="https://latex.codecogs.com/png.latex?N%20=%208"> (total), <img src="https://latex.codecogs.com/png.latex?K%20=%204"> (successes) and <img src="https://latex.codecogs.com/png.latex?n%20=%204"> (draws), i.e., [ X (8, 4, 4). ] In any given round, the subject fails the test if she only identifies 0, 1 or 2 cups correctly. Under the null hypothesis, the probability of this happening is given by <img src="https://latex.codecogs.com/png.latex?p%20=%20%5Cmathbb%7BP%7D(X%20%5Cleq%202)">, the value of which we can determine using the cumulative mass function of the Hypergeometric(8, 4, 4) distribution. We suspend judgement on the subject’s discriminatory abilities if she identifies exactly three cups correctly, in which case she has another go. Under the null hypothesis, the probability of this happening in any given round is given by <img src="https://latex.codecogs.com/png.latex?q%20=%20%5Cmathbb%7BP%7D(X%20=%203)">, the value of which can be determined using the probability mass function of the Hypergeometric(8, 4, 4) distribution.</p>
<p>With those probabilities in hand, we can now compute the probability that the subject fails the experiment in a specific round, assuming the null hypothesis is correct. In the first round, she will fail the experiment with probability <img src="https://latex.codecogs.com/png.latex?p">. In order to fail in the second round, she needed to have advanced to the second round, which happens with probability <img src="https://latex.codecogs.com/png.latex?q">, and then fail in that round, which happens with probability <img src="https://latex.codecogs.com/png.latex?p">. That is, she will fail in the second round with probability <img src="https://latex.codecogs.com/png.latex?pq">. To fail in the third round, she needed to advance to the third round, which happens with probability <img src="https://latex.codecogs.com/png.latex?q%5E2"> and then fail in the third round, which happens with probability <img src="https://latex.codecogs.com/png.latex?p">. That is, she will fail in the third round with probability <img src="https://latex.codecogs.com/png.latex?pq%5E2">. Etc. etc. The probability that she will fail somewhere in the experiment if the null hypothesis is true, then, is given by <img src="https://latex.codecogs.com/png.latex?%0A%5Csum_%7Bi%20=%201%7D%5E%7B%5Cinfty%7Dpq%5E%7Bi-1%7D%20=%20%5Csum_%7Bi%20=%200%7D%5E%7B%5Cinfty%7Dpq%5Ei%20=%20%5Cfrac%7Bp%7D%7B1-q%7D,%0A"> where the first equality is just a matter of shifting the index and the second equality holds because the expression is a <a href="https://en.wikipedia.org/wiki/Geometric_series">geometric series</a>.</p>
<p>Let’s compute the final results using Julia. The following loads the <code>DataFrames</code> and <code>Distributions</code> packages and then defines <code>d</code> as the Hypergeometric(8, 4, 4) distribution. Note that in Julia, the parameters for the Hypergeometric distribution aren’t <img src="https://latex.codecogs.com/png.latex?N"> (total), <img src="https://latex.codecogs.com/png.latex?K"> (successes) and <img src="https://latex.codecogs.com/png.latex?n"> (draws), but rather <img src="https://latex.codecogs.com/png.latex?k"> (successes), <img src="https://latex.codecogs.com/png.latex?N-k"> (failures) and <img src="https://latex.codecogs.com/png.latex?n"> (draws); see the <a href="https://juliastats.org/Distributions.jl/v0.14/univariate.html#Distributions.Hypergeometric">documentation</a>. We then read off the values for <img src="https://latex.codecogs.com/png.latex?p"> and <img src="https://latex.codecogs.com/png.latex?q"> from the cumulative mass function and probability mass function, respectively:</p>
<div id="c2f54b29" class="cell" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb3-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">using</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Distributions</span></span>
<span id="cb3-2">d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Hypergeometric</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>);</span>
<span id="cb3-3">p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cdf</span>(d, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>);</span>
<span id="cb3-4">q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pdf</span>(d, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>);</span></code></pre></div></div>
</div>
<p>The probability that the subject will fail the experiment if she does indeed not have the purported discriminatory ability is now easily computed:</p>
<div id="71d70f35" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb4-1">p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> q)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="4">
<pre><code>0.9814814814814815</code></pre>
</div>
</div>
<p>The next question is how many rounds we expect the experiment to carry on for if the null hypothesis is true. At each round, the probability that the experiment terminates in that round is given by <img src="https://latex.codecogs.com/png.latex?1%20-%20q">. From the <a href="https://en.wikipedia.org/wiki/Geometric_distribution">geometric distribution</a>, we know that we then on average need <img src="https://latex.codecogs.com/png.latex?1/(1-q)"> attempts before the first terminating event occurs:</p>
<div id="9041865b" class="cell" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-1"><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> q)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="5">
<pre><code>1.2962962962962965</code></pre>
</div>
</div>
<p>In sum, if the subject lacks any discriminatory ability, there is only a 1.85% chance that she will pass the test, and on average, the experiment will run for 1.3 rounds.</p>
</section>
<section id="brute-force-solution" class="level2">
<h2 class="anchored" data-anchor-id="brute-force-solution">Brute-force solution</h2>
<p>First, we define a function <code>experiment()</code> that runs the experiment once. In essence, we have an <code>urn</code> that contains four correct identifications (<code>true</code>) and four incorrect identifications (<code>false</code>). From this <code>urn</code>, we <code>sample()</code> four identifications without replacement.</p>
<p>Note, incidentally, that Julia functions can take both positional arguments and keyword arguments. In the <code>sample()</code> command below, both <code>urn</code> and <code>4</code> are passed as positional arguments, and you’d have to read the <a href="https://juliastats.org/StatsBase.jl/stable/sampling/#StatsBase.sample">documentation</a> to figure out which argument specifies what. The keyword arguments are separated from the positional arguments by a semi-colon and are identified with the parameter’s name.</p>
<p>Next, we count the number of <code>true</code>s in our <code>pick</code> using <code>sum()</code>. Depending on how many <code>true</code>s there are in <code>pick</code>, we terminate the experiment, returning <code>false</code> if we remain sceptic and <code>true</code> if we choose to believe the lady, or we run the experiment for one more round. The number of attempts are tallied and output as well.</p>
<div id="f60f4e5b" class="cell" data-execution_count="5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb8-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">experiment</span>(attempt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb8-2">    urn <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">false</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">false</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">false</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">false</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">true</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">true</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">true</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">true</span>]</span>
<span id="cb8-3">    pick <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(urn, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>; replace <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">false</span>)</span>
<span id="cb8-4">    number <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(pick)</span>
<span id="cb8-5">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> number <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb8-6">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">false</span>, attempt</span>
<span id="cb8-7">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">elseif</span> number <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb8-8">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">true</span>, attempt</span>
<span id="cb8-9">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span></span>
<span id="cb8-10">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">experiment</span>(attempt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb8-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb8-12"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span>;</span></code></pre></div></div>
</div>
<p>A single run of <code>experiment()</code> could produce the following output:</p>
<div id="3dc73e66" class="cell" data-execution_count="6">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">experiment</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="7">
<pre><code>(false, 3)</code></pre>
</div>
</div>
<p>Next, we write a function <code>simulate()</code> that runs the <code>experiment()</code> a large number of times, and outputs both whether each <code>experiment()</code> led to us believe the lady or remaining sceptical, and how many round each <code>experiment()</code> took. These results are tabulated in a <code>DataFrame</code> – just because. Of note, Julia supports list comprehension that Python users will be familiar with. I use this feature here both the run the experiment a large number of times as well as to parse the output.</p>
<div id="96b8cf1e" class="cell" data-execution_count="7">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb11-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">using</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">DataFrames</span></span>
<span id="cb11-2"></span>
<span id="cb11-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simulate</span>(runs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>)</span>
<span id="cb11-4">    results <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">experiment</span>() for _ <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>runs]</span>
<span id="cb11-5">    success <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [results[i][<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] for i <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>runs]</span>
<span id="cb11-6">    attempts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [results[i][<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>] for i <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>runs]</span>
<span id="cb11-7">    d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">DataFrame</span>(Successful <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> success, Attempts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> attempts)</span>
<span id="cb11-8">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> d</span>
<span id="cb11-9"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span>;</span></code></pre></div></div>
</div>
<p>Let’s swing for the fences and run this experiment a million times. Like in Python, we can make large numbers easier to parse by inserting underscores in them:</p>
<div id="44e8a871" class="cell" data-execution_count="8">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb12-1">runs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1_000_000</span>;</span></code></pre></div></div>
</div>
<p>Using the <code>@time</code> macro, we can check how long it take for this simulation to finish.</p>
<div id="5e574a9b" class="cell" data-execution_count="9">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb13-1"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@time</span> d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simulate</span>(runs)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>  0.738348 seconds (4.08 M allocations: 361.510 MiB, 12.90% gc time, 35.59% compilation time)</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="10">
<div><div style="float: left;"><span>1000000×2 DataFrame</span></div><div style="float: right;"><span style="font-style: italic;">999975 rows omitted</span></div><div style="clear: both;"></div></div><div class="data-frame" style="overflow-x: scroll;">
<table class="data-frame caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th class="rowNumber" data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold;">Row</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Successful</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Attempts</th>
</tr>
<tr class="subheader headerLastRow even">
<th class="rowNumber" data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold;"></th>
<th style="text-align: left;" data-quarto-table-cell-role="th" title="Bool">Bool</th>
<th style="text-align: left;" data-quarto-table-cell-role="th" title="Int64">Int64</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">1</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">2</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">3</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">4</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">4</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">5</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">6</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">7</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">8</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">9</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">10</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">11</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">12</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">13</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td style="text-align: right;">⋮</td>
<td style="text-align: right;">⋮</td>
<td style="text-align: right;">⋮</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999989</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999990</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999991</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999992</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">2</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999993</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999994</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999995</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999996</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999997</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999998</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999999</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">1000000</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>On my machine then, running this simulation takes less than a second. Note that 60% of this time is compilation time. (Update: When migrating my blog to Quarto, I reran this code using a new Julia version (1.9.1). Now the code runs faster.) Indeed, if we run the function another time, i.e., after it’s been compiled, the run time drops to about 0.3 seconds (Update: 0.2 seconds now.):</p>
<div id="e7652377" class="cell" data-execution_count="10">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb15-1"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">@time</span> d2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simulate</span>(runs)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>  0.413045 seconds (3.89 M allocations: 348.780 MiB, 14.03% gc time)</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="11">
<div><div style="float: left;"><span>1000000×2 DataFrame</span></div><div style="float: right;"><span style="font-style: italic;">999975 rows omitted</span></div><div style="clear: both;"></div></div><div class="data-frame" style="overflow-x: scroll;">
<table class="data-frame caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th class="rowNumber" data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold;">Row</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Successful</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">Attempts</th>
</tr>
<tr class="subheader headerLastRow even">
<th class="rowNumber" data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold;"></th>
<th style="text-align: left;" data-quarto-table-cell-role="th" title="Bool">Bool</th>
<th style="text-align: left;" data-quarto-table-cell-role="th" title="Int64">Int64</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">1</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">2</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">3</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">4</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">5</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">6</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">2</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">7</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">8</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">9</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">10</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">11</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">12</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">13</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td style="text-align: right;">⋮</td>
<td style="text-align: right;">⋮</td>
<td style="text-align: right;">⋮</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999989</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999990</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999991</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">2</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999992</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999993</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">2</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999994</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999995</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999996</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">2</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999997</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999998</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">2</td>
</tr>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">999999</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">1000000</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">1</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Using <code>describe()</code>, we see that this simulation – which doesn’t ‘know’ anything about hypergeometric and geometric distributions, produces the same answers that we arrived at by analytical means: There’s a 1.86% chance that we end up believing the lady even if she has no discriminatory ability whatsoever. And if she doesn’t have any discriminatory ability, we’ll need 1.3 rounds on average before terminating the experiment:</p>
<div id="dcc82a82" class="cell" data-execution_count="11">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb17-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">describe</span>(d)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="12">
<div><div style="float: left;"><span>2×7 DataFrame</span></div><div style="clear: both;"></div></div><div class="data-frame" style="overflow-x: scroll;">
<table class="data-frame caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th class="rowNumber" data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold;">Row</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">variable</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">mean</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">min</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">median</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">max</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">nmissing</th>
<th style="text-align: left;" data-quarto-table-cell-role="th">eltype</th>
</tr>
<tr class="subheader headerLastRow even">
<th class="rowNumber" data-quarto-table-cell-role="th" style="text-align: right; font-weight: bold;"></th>
<th style="text-align: left;" data-quarto-table-cell-role="th" title="Symbol">Symbol</th>
<th style="text-align: left;" data-quarto-table-cell-role="th" title="Float64">Float64</th>
<th style="text-align: left;" data-quarto-table-cell-role="th" title="Integer">Integer</th>
<th style="text-align: left;" data-quarto-table-cell-role="th" title="Float64">Float64</th>
<th style="text-align: left;" data-quarto-table-cell-role="th" title="Integer">Integer</th>
<th style="text-align: left;" data-quarto-table-cell-role="th" title="Int64">Int64</th>
<th style="text-align: left;" data-quarto-table-cell-role="th" title="DataType">DataType</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td class="rowNumber" style="text-align: right; font-weight: bold;">1</td>
<td style="text-align: left;">Successful</td>
<td style="text-align: right;">0.018794</td>
<td style="text-align: right;">false</td>
<td style="text-align: right;">0.0</td>
<td style="text-align: right;">true</td>
<td style="text-align: right;">0</td>
<td style="text-align: left;">Bool</td>
</tr>
<tr class="even">
<td class="rowNumber" style="text-align: right; font-weight: bold;">2</td>
<td style="text-align: left;">Attempts</td>
<td style="text-align: right;">1.29683</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">1.0</td>
<td style="text-align: right;">10</td>
<td style="text-align: right;">0</td>
<td style="text-align: left;">Int64</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>The slight discrepancy between the simulation-based results and the analytical ones are just due to randomness. Below is a quick way for constructing 95% confidence intervals around both of our simulation-based estimates, and the analytical solutions fall within both intervals.</p>
<div id="dcbaf718" class="cell" data-execution_count="12">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb18-1">means <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>.(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">eachcol</span>(d))</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="13">
<pre><code>2-element Vector{Float64}:
 0.018794
 1.296835</code></pre>
</div>
</div>
<div id="7143e7f3" class="cell" data-execution_count="13">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb20-1">ses <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">std</span>.(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">eachcol</span>(d)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(runs)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="14">
<pre><code>2-element Vector{Float64}:
 0.00013579692192683897
 0.0006203340774045607</code></pre>
</div>
</div>
<div id="df6ae9e4" class="cell" data-execution_count="14">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb22-1">upr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> means <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.96</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>ses</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="15">
<pre><code>2-element Vector{Float64}:
 0.019060161966976606
 1.298050854791713</code></pre>
</div>
</div>
<div id="05bbf0c2" class="cell" data-execution_count="15">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb24-1">lwr <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> means <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.96</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>ses</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="16">
<pre><code>2-element Vector{Float64}:
 0.018527838033023398
 1.295619145208287</code></pre>
</div>
</div>


</section>

 ]]></description>
  <category>Julia</category>
  <guid>https://janhove.github.io/posts/2023-02-23-julia-tea-tasting/</guid>
  <pubDate>Thu, 23 Feb 2023 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Adjusting to Julia: The Levenshtein algorithm</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2023-02-09-julia-levenshtein/</link>
  <description><![CDATA[ 




<p>In this second blog post about <a href="https://julialang.org/">Julia</a>, I’ll share with you a Julia implementation of the Levenshtein algorithm.</p>
<section id="the-levenshtein-algorithm" class="level2">
<h2 class="anchored" data-anchor-id="the-levenshtein-algorithm">The Levenshtein algorithm</h2>
<p>The basic Levenshtein algorithm is used to count the minimum number of insertions, deletions and substitutions that are needed to convert one string into another. For instance, to convert English <em>doubt</em> into French <em>doute</em>, you need at least two operations. You could replace the <em>b</em> by a <em>t</em> and then replace the <em>t</em> by an <em>e</em>; or you could delete the <em>b</em> and then insert the <em>e</em>. As this example shows, there may be more than one way to convert one string into another using the minimum number of required operations, but this minimum number itself is unique for each pair of strings.</p>
</section>
<section id="implementation-in-julia" class="level2">
<h2 class="anchored" data-anchor-id="implementation-in-julia">Implementation in Julia</h2>
<p>I won’t cover the logic of the Levenshtein algorithm here. The following is a straightforward Julia implementation of the pseudocode found on Wikipedia, assuming a cost of 1 for all operations. The function takes two inputs (a string <code>a</code> that is to be converted to a string <code>b</code>) and outputs an array with the Levenshtein distances between all substrings of <code>a</code> on the one hand and all substrings of <code>b</code> on the other hand. The entry in the bottom right corner of this array is the Levenshtein distances between the full strings and this is output separately as well.</p>
<div id="51237d61" class="cell" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb1-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levenshtein</span>(a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">String</span>, b<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">String</span>)</span>
<span id="cb1-2">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Initialise table</span></span>
<span id="cb1-3">    distances <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">zeros</span>(<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Int</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(a) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(b) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-4">    distances[<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(a)</span>
<span id="cb1-5">    distances[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(b)</span>
<span id="cb1-6"></span>
<span id="cb1-7">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Levenshtein logic</span></span>
<span id="cb1-8">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> row <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(a) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-9">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> col <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(b) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-10">            distances[row, col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(</span>
<span id="cb1-11">                distances[row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Int</span>(a[row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> b[col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] ? <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb1-12">                , distances[row, col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb1-13">                , distances[row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb1-14">            )</span>
<span id="cb1-15">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb1-16">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb1-17"></span>
<span id="cb1-18">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> distances, distances[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(a) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(b) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb1-19"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="2">
<pre><code>levenshtein (generic function with 1 method)</code></pre>
</div>
</div>
<p>Let’s compute the Levenshtein distance between the German word <em>Zyklus</em> (‘cycle’) and its Swedish counterpart <em>cykel</em>. Note the use of <code>;</code> at the end of the line to suppress the output.</p>
<div id="ea4db0f7" class="cell" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb3-1">dist_matrix, lev_cost <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levenshtein</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zyklus"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cykel"</span>);</span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">display</span>(dist_matrix)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<pre><code>7×6 Matrix{Int64}:
 0  1  2  3  4  5
 1  1  2  3  4  5
 2  2  1  2  3  4
 3  3  2  1  2  3
 4  4  3  2  2  2
 5  5  4  3  3  3
 6  6  5  4  4  4</code></pre>
</div>
</div>
<p>This checks out: you do indeed need four operations to transform <em>Zyklus</em> into <em>cykel</em>.</p>
</section>
<section id="a-vectorised-function" class="level2">
<h2 class="anchored" data-anchor-id="a-vectorised-function">A vectorised function</h2>
<p>But what if we wanted to apply our new functions to several pairs of strings? Let’s first define three Dutch-German word pairs:</p>
<div id="8b461f8e" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb5-1">dutch <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"boek"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zuster"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sneeuw"</span>);</span>
<span id="cb5-2">german <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"buch"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"schwester"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"schnee"</span>);</span></code></pre></div></div>
</div>
<p>We can run our <code>levenshtein()</code> on these three word pairs without introducing for-loops by simply appending a dot to the function name:</p>
<div id="3b28db95" class="cell" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levenshtein</span>.(dutch, german)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="5">
<pre><code>(([0 1 … 3 4; 1 0 … 2 3; … ; 3 2 … 2 3; 4 3 … 3 3], 3), ([0 1 … 8 9; 1 1 … 8 9; … ; 5 4 … 5 6; 6 5 … 6 5], 5), ([0 1 … 5 6; 1 0 … 4 5; … ; 5 4 … 4 3; 6 5 … 5 4], 4))</code></pre>
</div>
</div>
<p>However, since the <code>levenshtein()</code> function outputs two pieces of information (both the matrix with the distances between the substrings as well as the final Levenshtein distance), this vectorised call yields a tuple of three subtuples, each subtuple containing both a matrix and the corresponding final Levenshtein distance. This is why the output above looks so messy. If we wanted to obtain just the Levenshtein distances, we could write a for-loop to extract them. But I think an easier solution is to first write a wrapper around the <code>levenshtein()</code> function that outputs only the final Levenshtein distance and use the vectorised version of this wrapper instead:</p>
<div id="e48bf10c" class="cell" data-execution_count="5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb8-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lev_dist</span>(a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">String</span>, b<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">String</span>)</span>
<span id="cb8-2">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levenshtein</span>(a, b)[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]</span>
<span id="cb8-3"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="6">
<pre><code>lev_dist (generic function with 1 method)</code></pre>
</div>
</div>
<p>Now use the vectorised version of <code>lev_dist()</code>:</p>
<div id="9e1fb9c5" class="cell" data-execution_count="6">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb10-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lev_dist</span>.(dutch, german)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="7">
<pre><code>(3, 5, 4)</code></pre>
</div>
</div>
<p>Nice!</p>
</section>
<section id="obtaining-the-operations" class="level2">
<h2 class="anchored" data-anchor-id="obtaining-the-operations">Obtaining the operations</h2>
<p>We now know that we need four operations to transform <em>Zyklus</em> into <em>cykel</em> and five to transform <em>zuster</em> into <em>Schwester</em>. But which are the operations that you need for these transformations? The function <code>lev_alignment()</code> defined below outputs one possible set of operations that would do the job. (Unlike the minimum number of operations required to transform one string into another, the set of operations needed isn’t uniquely defined.)</p>
<div id="f463d419" class="cell" data-execution_count="7">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb12-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lev_alignment</span>(a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">String</span>, b<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">String</span>)</span>
<span id="cb12-2">    source <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Vector</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">{Char}</span>()</span>
<span id="cb12-3">    target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Vector</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">{Char}</span>()</span>
<span id="cb12-4">    operations <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Vector</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">{Char}</span>()</span>
<span id="cb12-5">    </span>
<span id="cb12-6">    lev_matrix <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levenshtein</span>(a, b)[<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb12-7">    </span>
<span id="cb12-8">    row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">size</span>(lev_matrix, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb12-9">    col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">size</span>(lev_matrix, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb12-10"></span>
<span id="cb12-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb12-12">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> lev_matrix[row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> lev_matrix[row, col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span></span>
<span id="cb12-13">            lev_matrix[row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(</span>
<span id="cb12-14">              lev_matrix[row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, col]</span>
<span id="cb12-15">              , lev_matrix[row, col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb12-16">              )</span>
<span id="cb12-17">            row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb12-18">            col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb12-19">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(source, a[row])</span>
<span id="cb12-20">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(target, b[col])</span>
<span id="cb12-21">            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(operations, <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">' '</span>)</span>
<span id="cb12-22">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> </span>
<span id="cb12-23">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> lev_matrix[row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(lev_matrix[row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], lev_matrix[row, col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb12-24">                row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb12-25">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(source, a[row])</span>
<span id="cb12-26">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(target, <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">' '</span>)</span>
<span id="cb12-27">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(operations, <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'D'</span>)</span>
<span id="cb12-28">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">elseif</span> lev_matrix[row, col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> lev_matrix[row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb12-29">                col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb12-30">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(source, <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">' '</span>)</span>
<span id="cb12-31">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(target, b[col])</span>
<span id="cb12-32">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(operations, <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'I'</span>)</span>
<span id="cb12-33">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span></span>
<span id="cb12-34">                row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb12-35">                col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb12-36">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(source, a[row])</span>
<span id="cb12-37">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(target, b[col])</span>
<span id="cb12-38">                <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(operations, <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'S'</span>)</span>
<span id="cb12-39">            <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb12-40">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb12-41">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb12-42"></span>
<span id="cb12-43">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># If first column reached, move up.</span></span>
<span id="cb12-44">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb12-45">        row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb12-46">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(source, a[row])</span>
<span id="cb12-47">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(target, <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">' '</span>)</span>
<span id="cb12-48">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(operations, <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'D'</span>)</span>
<span id="cb12-49">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb12-50"></span>
<span id="cb12-51">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># If first row reached, move left.</span></span>
<span id="cb12-52">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb12-53">        col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb12-54">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(source, <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">' '</span>)</span>
<span id="cb12-55">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(target, b[col])</span>
<span id="cb12-56">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pushfirst!</span>(operations, <span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">'I'</span>)</span>
<span id="cb12-57">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb12-58">    </span>
<span id="cb12-59">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vcat</span>(</span>
<span id="cb12-60">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reshape</span>(source, (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>))</span>
<span id="cb12-61">        , <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reshape</span>(target, (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>))</span>
<span id="cb12-62">        , <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reshape</span>(operations, (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>))</span>
<span id="cb12-63">    )</span>
<span id="cb12-64"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="8">
<pre><code>lev_alignment (generic function with 1 method)</code></pre>
</div>
</div>
<p>I won’t cover the logic behind the algorithm as this is more about learning Julia that the Levenshtein algorithm. On the Julia side, note first how empty character vectors can be initialised. Moreover, notice that the <code>pushfirst!()</code><br>
function is decorated with a <code>!</code> (a ‘bang’). This communicates to whoever is reading the code that this function changes some of its input. For instance, <code>pushfirst!(source, a[row])</code> means that the current character of <code>a</code> (i.e., <code>a[row]</code>) is added to the front of the <code>source</code> vector. That is, this command changes the <code>source</code> vector. Finally, the <code>source</code>, <code>target</code> and <code>operations</code> vectors are all column vectors. In order to display them somewhat nicely, I converted each of them to a single-row matrix using <code>reshape()</code>. Then, the three resulting rows are concatenated vertically using <code>vcat()</code> to show how the two strings can be aligned and which operations are needed to transform one into the other.</p>
<p>Let’s see how we can transform <em>Zyklus</em> into <em>cykel</em>:</p>
<div id="b7201b22" class="cell" data-execution_count="8">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb14-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lev_alignment</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zyklus"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cykel"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="9">
<pre><code>3×7 Matrix{Char}:
 'z'  'y'  'k'  ' '  'l'  'u'  's'
 'c'  'y'  'k'  'e'  'l'  ' '  ' '
 'S'  ' '  ' '  'I'  ' '  'D'  'D'</code></pre>
</div>
</div>
<p>So we substitute <em>c</em> for <em>z</em>, insert an <em>e</em> and delete the <em>u</em> and <em>s</em>. As I mentioned, this set of operations isn’t uniquely defined. Indeed, we could have also substituted <em>c</em> for <em>z</em>, <em>e</em> for <em>l</em> and <em>l</em> for <em>u</em> and then deleted the <em>s</em>. This also corresponds to a Levenshtein distance of four operations.</p>
</section>
<section id="normalised-levenshtein-distances" class="level2">
<h2 class="anchored" data-anchor-id="normalised-levenshtein-distances">Normalised Levenshtein distances</h2>
<p>Above, we computed raw Levenshtein distances. The problem with these is that longer string pairs will tend to have larger raw Levenshtein distances than shorter string pairs, even if they do seem more similar. To correct for this, we can computed normalised Levenshtein distances instead. There are various ways to compute these; one option is to divide the raw Levenshtein distance by the length of the alignment:</p>
<div id="5677bf2d" class="cell" data-execution_count="9">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb16-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">norm_lev_dist</span>(a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">String</span>, b<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">String</span>)</span>
<span id="cb16-2">  raw_dist <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lev_dist</span>(a, b)</span>
<span id="cb16-3">  alignment_length <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">size</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lev_alignment</span>(a, b), <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb16-4">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> raw_dist <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> alignment_length</span>
<span id="cb16-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="10">
<pre><code>norm_lev_dist (generic function with 1 method)</code></pre>
</div>
</div>
<p>(Behind the scenes, we run the Levenshtein algorithm twice: once in <code>lev_dist()</code> and again in <code>lev_alignment()</code>. This seems wasteful - unless the Julia compiler is able to clean up the double work? I’m not sure.)</p>
<p>We obtain a normalised Levenshtein distance of about 0.57 for <em>Zyklus</em> - <em>cykel</em>:</p>
<div id="309d67eb" class="cell" data-execution_count="10">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb18-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">norm_lev_dist</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"zyklus"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cykel"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="11">
<pre><code>0.5714285714285714</code></pre>
</div>
</div>
<p>We can use a vectorised version of this function, too:</p>
<div id="14330e83" class="cell" data-execution_count="11">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb20-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">norm_lev_dist</span>.(dutch, german)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="12">
<pre><code>(0.75, 0.5555555555555556, 0.5)</code></pre>
</div>
</div>
<p>Of course, normalised Levenshtein distances are symmetric, so we obtain the same result when running the following command:</p>
<div id="cf5d39d5" class="cell" data-execution_count="12">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb22-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">norm_lev_dist</span>.(german, dutch)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="13">
<pre><code>(0.75, 0.5555555555555556, 0.5)</code></pre>
</div>
</div>


</section>

 ]]></description>
  <category>Julia</category>
  <guid>https://janhove.github.io/posts/2023-02-09-julia-levenshtein/</guid>
  <pubDate>Thu, 09 Feb 2023 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Adjusting to Julia: Generating the Fibonacci sequence</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2022-12-20-julia-fibonacci/</link>
  <description><![CDATA[ 




<p>I’m currently learning a bit of <a href="https://julialang.org/">Julia</a> and I thought I’d share with you a couple of my attempts at writing Julia code. I’ll spare you the sales pitch, and I’ll skip straight to the goal of this blog post: writing three different Julia functions that can generate the Fibonacci sequence.</p>
<section id="the-fibonacci-sequence" class="level2">
<h2 class="anchored" data-anchor-id="the-fibonacci-sequence">The Fibonacci sequence</h2>
<p>The famous Fibonacci sequence is an infinite sequence of natural numbers, the first of which are 1, 1, 2, 3, 5, 8, 13, …. The sequence is defined as follows:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctextrm%7BFibonacci%7D(n)%20=%0A%20%20%5Cbegin%7Bcases%7D%0A%20%20%20%201,%20&amp;%20%5Ctextrm%7Bfor%20$n%20=%201$%20or%20$n%20=%202$%7D,%20%5C%5C%0A%20%20%20%20%5Ctextrm%7BFibonacci%7D(n%20-%201)%20+%20%5Ctextrm%7BFibonacci%7D(n%20-%202),%20&amp;%20%5Ctextrm%7Botherwise%7D.%20%20%0A%20%20%5Cend%7Bcases%7D%0A"></p>
<p>Let’s write some Julia functions that can generate this sequence.</p>
</section>
<section id="julia" class="level2">
<h2 class="anchored" data-anchor-id="julia">Julia</h2>
<p>You can download Julia from <a href="julialang.org">julialang.org</a>. I’m currently using the <a href="https://github.com/fonsp/Pluto.jl#lets-do-it">Pluto.jl</a> package that allows you to write Julia code in a reactive notebook. Check out the Pluto.jl page for more information.</p>
</section>
<section id="first-alternative-a-purely-recursive-function" class="level2">
<h2 class="anchored" data-anchor-id="first-alternative-a-purely-recursive-function">First alternative: A purely recursive function</h2>
<p>The Fibonacci sequence is defined recursively: To obtain the <em>n</em>th Fibonacci number, you first need to compute the <em>n-1</em>th and <em>n-2</em>th Fibonacci number and then add them. We can write a Julia function that exactly reflects the definition of the Fibonacci sequence like so:</p>
<div id="64896c9c" class="cell" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb1-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fibonacci</span>(n)</span>
<span id="cb1-2">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb1-3">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb1-4">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb1-5">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fibonacci</span>(n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fibonacci</span>(n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-6"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="2">
<pre><code>fibonacci (generic function with 1 method)</code></pre>
</div>
</div>
<p>This function tacitly assumes that <code>n</code> is a non-zero natural number. If <code>n</code> is equal to or lower than 2, i.e., if <code>n</code> is 1 or 2, it immediately returns 1, as per the definition of the sequence. If this condition isn’t met, the output is computed recursively. The function can be run as follows:</p>
<div id="c12f6ef4" class="cell" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fibonacci</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="3">
<pre><code>55</code></pre>
</div>
</div>
<p>Checks out! But from a computational point of view, the <code>fibonacci()</code> function is quite wasteful. In order to obtain <code>fibonacci(10)</code>, we need to compute <code>fibonacci(9)</code> and <code>fibonacci(8)</code>. But in order to compute <code>fibonacci(9)</code>, we <em>also</em> need to compute <code>fibonacci(8)</code>. For both <code>fibonacci(9)</code> and <code>fibonacci(8)</code>, we need to compute <code>fibonacci(7)</code>, etc. In fact, we need to compute the value of <code>fibonacci(8)</code> two times, that of <code>fibonacci(7)</code> three times, that of <code>fibonacci(6)</code> five times, and that of <code>fibonacci(5)</code> seven times. So we’d be doing lots of computations over and over again. For this reason, the <code>fibonacci()</code> function is hopelessly inefficient: While you can compute <code>fibonacci(10)</code> in a fraction of a second, it may take minutes to compute, say, <code>fibonacci(60)</code>. Luckily, we can speed up our function considerably.</p>
</section>
<section id="second-alternative-recursion-with-memoisation" class="level2">
<h2 class="anchored" data-anchor-id="second-alternative-recursion-with-memoisation">Second alternative: Recursion with memoisation</h2>
<p>Memoisation is a programming technique where any intermediate result that you computed is stored in an array. Before computing any further intermediate results, you then first look up in the array if you haven’t in fact already computed it, saving you a lot of unnecessary computations. The following Julia function is a bit more involved that the previous one, but it’s much more efficient.</p>
<div id="72613bb0" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb5-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fib_memo</span>(n)</span>
<span id="cb5-2">  known <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">zeros</span>(<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Int64</span>, n)</span>
<span id="cb5-3">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">memoize</span>(k)</span>
<span id="cb5-4">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> known[k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb5-5">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># do nothing</span></span>
<span id="cb5-6">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">elseif</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb5-7">      known[k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb5-8">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span></span>
<span id="cb5-9">      known[k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">memoize</span>(k<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">memoize</span>(k<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb5-10">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb5-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> known[k]</span>
<span id="cb5-12">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb5-13">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">memoize</span>(n)</span>
<span id="cb5-14"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="4">
<pre><code>fib_memo (generic function with 1 method)</code></pre>
</div>
</div>
<p>The overall function that we’ll actually call is <code>fib_memo()</code>. It creates an array called <code>known</code> with <code>n</code> zeroes. Then it defines an inner function <code>memoize()</code>. This latter function obtains an integer <code>k</code> that in practice will range from 0 to <code>n</code> and does the following. First, it checks if the <code>k</code>th value in the array <code>known</code> is still 0. If it got changed, the function just returns the <code>k</code>th value in <code>known</code>. Otherwise, if <code>k</code> is equal to either 1 or 2, it sets the first or second value of <code>known</code> to 1. If <code>k</code> is greater than 2, the <code>k</code>th value of <code>known</code> is computed recursively. In all cases, the <code>memoize()</code> function returns the <code>k</code> value of the <code>known</code> array. The outer <code>fib_memo()</code> function then just returns the result of <code>memoize(n)</code>.</p>
<p>Perhaps by now, your computer has finished running <code>fibonacci(60)</code> and you can try out the alternative implementation:</p>
<div id="0f784cf4" class="cell" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fib_memo</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="5">
<pre><code>1548008755920</code></pre>
</div>
</div>
<p>Notice how much faster this new function is! Even the 200th Fibonacci number can be computed in a fraction of a second:</p>
<div id="b7020791" class="cell" data-execution_count="5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fib_memo</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="6">
<pre><code>-1123705814761610347</code></pre>
</div>
</div>
<p>Unfortunately, we’ve ran into a different problem now: <a href="https://en.wikipedia.org/wiki/Integer_overflow">integer overflow</a>. The result of the computations has become so large that it exceeded the range of 64-bit integers. To fix this problem, we can work with BigIntegers instead:</p>
<div id="e64dff9f" class="cell" data-execution_count="6">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb11-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fib_memo</span>(n)</span>
<span id="cb11-2">  known <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">zeros</span>(<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">BigInt</span>, n)</span>
<span id="cb11-3">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">memoize</span>(k)</span>
<span id="cb11-4">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> known[k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb11-5">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># do nothing</span></span>
<span id="cb11-6">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">elseif</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb11-7">      known[k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb11-8">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span></span>
<span id="cb11-9">      known[k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">memoize</span>(k<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">memoize</span>(k<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb11-10">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb11-11">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> known[k]</span>
<span id="cb11-12">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span>
<span id="cb11-13">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">memoize</span>(n)</span>
<span id="cb11-14"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="7">
<pre><code>fib_memo (generic function with 1 method)</code></pre>
</div>
</div>
<div id="db16525e" class="cell" data-execution_count="7">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fib_memo</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="8">
<pre><code>280571172992510140037611932413038677189525</code></pre>
</div>
</div>
<p>Nice!</p>
</section>
<section id="third-alternative-using-binets-formula" class="level2">
<h2 class="anchored" data-anchor-id="third-alternative-using-binets-formula">Third alternative: Using Binet’s formula</h2>
<p>The third alternative is more of a mathematical solution rather than a programming solution. According to Binet’s formula, the <em>n</em>th Fibonacci number can be computed as <img src="https://latex.codecogs.com/png.latex?%0A%5Ctextrm%7BFibonacci%7D(n)%20=%20%5Cfrac%7B%5Cvarphi%5En%20-%20%5Cpsi%5En%7D%7B%5Csqrt%7B5%7D%7D,%0A"> where <img src="https://latex.codecogs.com/png.latex?%5Cvarphi%20=%20%5Cfrac%7B1%20+%20%5Csqrt%7B5%7D%7D%7B2%7D">, the Golden Ratio, and <img src="https://latex.codecogs.com/png.latex?%5Cpsi%20=%20%5Cfrac%7B1%20-%20%5Csqrt%7B5%7D%7D%7B2%7D">, its conjugate. In Julia:</p>
<div id="cfb547b4" class="cell" data-execution_count="8">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb15-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fib_binet</span>(n)</span>
<span id="cb15-2">  <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">φ</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb15-3">  ψ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb15-4">  fib_n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">φ</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> ψ<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>n)</span>
<span id="cb15-5">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">BigInt</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(fib_n))</span>
<span id="cb15-6"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">end</span></span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="9">
<pre><code>fib_binet (generic function with 1 method)</code></pre>
</div>
</div>
<p>Note that you can use mathematical symbols like <img src="https://latex.codecogs.com/png.latex?%5Cvarphi"> and <img src="https://latex.codecogs.com/png.latex?%5Cpsi"> in Julia. This function runs very fast, too:</p>
<div id="4aeba7ca" class="cell" data-execution_count="9">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb17-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fib_binet</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="10">
<pre><code>1548008755920</code></pre>
</div>
</div>
<div id="c269380f" class="cell" data-execution_count="10">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb19-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fib_binet</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="11">
<pre><code>280571172992512015699912586503521287798784</code></pre>
</div>
</div>
<p>Notice, however, that the result for the 200th Fibonacci number differs by 27 orders of magnitude from the one obtained using <code>fib_memo()</code>:</p>
<div id="e2eaf780" class="cell" data-execution_count="11">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb21-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fib_binet</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fib_memo</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="12">
<pre><code>1875662300654090482610609259</code></pre>
</div>
</div>
<p>By using Binet’s formula, we’ve left the fairly neat world of integer arithmetic and entered the realm of floating point arithmetic that is rife with approximation errors. While we’re at it, we might as well compute and plot the size of these approximation errors. In the snippet below, I first use list comprehension in order to compute the first 200 Fibonacci numbers using both <code>fib_memo()</code> and <code>fib_binet()</code>. Note that I added a dot (<code>.</code>) to both function names. This is Julia notation for running vectorised computations. Further note that I end all lines with a semi-colon so that the results don’t get printed to the prompt. Then, I compute the absolute values of the differences between the numbers obtained by both computation methods. Note again the use of a dot in both <code>abs.()</code> and <code>.-</code> that is required to have both of these functions work on vectors. Finally, I convert these absolute differences to differences relative to the correct answers;</p>
<div id="05356a50" class="cell" data-execution_count="12">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb23-1">fib_integer <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fib_memo</span>.(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>);</span>
<span id="cb23-2">fib_math    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fib_binet</span>.(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>);</span>
<span id="cb23-3">abs_diff <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>.(fib_math <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.-</span> fib_integer);</span>
<span id="cb23-4">rel_diff <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> abs_diff <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">./</span> fib_integer;</span></code></pre></div></div>
</div>
<p>To wrap off this blog post, let’s now plot these absolute and relative differences using the Plots.jl package. While Figure 1 shows that the absolute error becomes huge, Figure 2 shows that these discrepancies only amount to a negligble fraction of the correct answers.</p>
<div id="2af3671f" class="cell" data-execution_count="13">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb24-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">using</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Plots</span></span>
<span id="cb24-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>, abs_diff, seriestype<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=:</span>scatter,</span>
<span id="cb24-3">     xlabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"n"</span>,</span>
<span id="cb24-4">     ylabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"absolute difference"</span>,</span>
<span id="cb24-5">     label <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="14">
<!--?xml version="1.0" encoding="utf-8"?-->
<svg xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" width="672" height="480" viewbox="0 0 2688 1920">
<defs>
  <clippath id="clip320">
    <rect x="0" y="0" width="2688" height="1920"></rect>
  </clippath>
</defs>
<path clip-path="url(#clip320)" d="M0 1920 L2688 1920 L2688 0 L0 0  Z" fill="#ffffff" fill-rule="evenodd" fill-opacity="1"></path>
<defs>
  <clippath id="clip321">
    <rect x="537" y="0" width="1883" height="1883"></rect>
  </clippath>
</defs>
<path clip-path="url(#clip320)" d="M399.095 1734.12 L2640.76 1734.12 L2640.76 47.2441 L399.095 47.2441  Z" fill="#ffffff" fill-rule="evenodd" fill-opacity="1"></path>
<defs>
  <clippath id="clip322">
    <rect x="399" y="47" width="2243" height="1688"></rect>
  </clippath>
</defs>
<polyline clip-path="url(#clip322)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="451.912,1734.12 451.912,47.2441 "></polyline>
<polyline clip-path="url(#clip322)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="983.262,1734.12 983.262,47.2441 "></polyline>
<polyline clip-path="url(#clip322)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="1514.61,1734.12 1514.61,47.2441 "></polyline>
<polyline clip-path="url(#clip322)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="2045.96,1734.12 2045.96,47.2441 "></polyline>
<polyline clip-path="url(#clip322)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="2577.31,1734.12 2577.31,47.2441 "></polyline>
<polyline clip-path="url(#clip320)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="399.095,1734.12 2640.76,1734.12 "></polyline>
<polyline clip-path="url(#clip320)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="451.912,1734.12 451.912,1715.22 "></polyline>
<polyline clip-path="url(#clip320)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="983.262,1734.12 983.262,1715.22 "></polyline>
<polyline clip-path="url(#clip320)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="1514.61,1734.12 1514.61,1715.22 "></polyline>
<polyline clip-path="url(#clip320)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="2045.96,1734.12 2045.96,1715.22 "></polyline>
<polyline clip-path="url(#clip320)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="2577.31,1734.12 2577.31,1715.22 "></polyline>
<path clip-path="url(#clip320)" d="M451.912 1767.34 Q448.3 1767.34 446.472 1770.9 Q444.666 1774.45 444.666 1781.58 Q444.666 1788.68 446.472 1792.25 Q448.3 1795.79 451.912 1795.79 Q455.546 1795.79 457.351 1792.25 Q459.18 1788.68 459.18 1781.58 Q459.18 1774.45 457.351 1770.9 Q455.546 1767.34 451.912 1767.34 M451.912 1763.64 Q457.722 1763.64 460.777 1768.24 Q463.856 1772.83 463.856 1781.58 Q463.856 1790.3 460.777 1794.91 Q457.722 1799.49 451.912 1799.49 Q446.101 1799.49 443.023 1794.91 Q439.967 1790.3 439.967 1781.58 Q439.967 1772.83 443.023 1768.24 Q446.101 1763.64 451.912 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M957.961 1764.26 L976.317 1764.26 L976.317 1768.2 L962.243 1768.2 L962.243 1776.67 Q963.262 1776.32 964.28 1776.16 Q965.299 1775.97 966.317 1775.97 Q972.105 1775.97 975.484 1779.15 Q978.864 1782.32 978.864 1787.73 Q978.864 1793.31 975.392 1796.41 Q971.919 1799.49 965.6 1799.49 Q963.424 1799.49 961.155 1799.12 Q958.91 1798.75 956.503 1798.01 L956.503 1793.31 Q958.586 1794.45 960.808 1795 Q963.03 1795.56 965.507 1795.56 Q969.512 1795.56 971.85 1793.45 Q974.188 1791.34 974.188 1787.73 Q974.188 1784.12 971.85 1782.02 Q969.512 1779.91 965.507 1779.91 Q963.632 1779.91 961.757 1780.33 Q959.905 1780.74 957.961 1781.62 L957.961 1764.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M998.077 1767.34 Q994.465 1767.34 992.637 1770.9 Q990.831 1774.45 990.831 1781.58 Q990.831 1788.68 992.637 1792.25 Q994.465 1795.79 998.077 1795.79 Q1001.71 1795.79 1003.52 1792.25 Q1005.35 1788.68 1005.35 1781.58 Q1005.35 1774.45 1003.52 1770.9 Q1001.71 1767.34 998.077 1767.34 M998.077 1763.64 Q1003.89 1763.64 1006.94 1768.24 Q1010.02 1772.83 1010.02 1781.58 Q1010.02 1790.3 1006.94 1794.91 Q1003.89 1799.49 998.077 1799.49 Q992.266 1799.49 989.188 1794.91 Q986.132 1790.3 986.132 1781.58 Q986.132 1772.83 989.188 1768.24 Q992.266 1763.64 998.077 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M1474.22 1794.89 L1481.86 1794.89 L1481.86 1768.52 L1473.55 1770.19 L1473.55 1765.93 L1481.81 1764.26 L1486.49 1764.26 L1486.49 1794.89 L1494.13 1794.89 L1494.13 1798.82 L1474.22 1798.82 L1474.22 1794.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M1513.57 1767.34 Q1509.96 1767.34 1508.13 1770.9 Q1506.33 1774.45 1506.33 1781.58 Q1506.33 1788.68 1508.13 1792.25 Q1509.96 1795.79 1513.57 1795.79 Q1517.2 1795.79 1519.01 1792.25 Q1520.84 1788.68 1520.84 1781.58 Q1520.84 1774.45 1519.01 1770.9 Q1517.2 1767.34 1513.57 1767.34 M1513.57 1763.64 Q1519.38 1763.64 1522.44 1768.24 Q1525.51 1772.83 1525.51 1781.58 Q1525.51 1790.3 1522.44 1794.91 Q1519.38 1799.49 1513.57 1799.49 Q1507.76 1799.49 1504.68 1794.91 Q1501.63 1790.3 1501.63 1781.58 Q1501.63 1772.83 1504.68 1768.24 Q1507.76 1763.64 1513.57 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M1543.73 1767.34 Q1540.12 1767.34 1538.29 1770.9 Q1536.49 1774.45 1536.49 1781.58 Q1536.49 1788.68 1538.29 1792.25 Q1540.12 1795.79 1543.73 1795.79 Q1547.37 1795.79 1549.17 1792.25 Q1551 1788.68 1551 1781.58 Q1551 1774.45 1549.17 1770.9 Q1547.37 1767.34 1543.73 1767.34 M1543.73 1763.64 Q1549.54 1763.64 1552.6 1768.24 Q1555.68 1772.83 1555.68 1781.58 Q1555.68 1790.3 1552.6 1794.91 Q1549.54 1799.49 1543.73 1799.49 Q1537.92 1799.49 1534.84 1794.91 Q1531.79 1790.3 1531.79 1781.58 Q1531.79 1772.83 1534.84 1768.24 Q1537.92 1763.64 1543.73 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M2005.57 1794.89 L2013.21 1794.89 L2013.21 1768.52 L2004.9 1770.19 L2004.9 1765.93 L2013.16 1764.26 L2017.84 1764.26 L2017.84 1794.89 L2025.48 1794.89 L2025.48 1798.82 L2005.57 1798.82 L2005.57 1794.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M2034.97 1764.26 L2053.32 1764.26 L2053.32 1768.2 L2039.25 1768.2 L2039.25 1776.67 Q2040.27 1776.32 2041.29 1776.16 Q2042.31 1775.97 2043.32 1775.97 Q2049.11 1775.97 2052.49 1779.15 Q2055.87 1782.32 2055.87 1787.73 Q2055.87 1793.31 2052.4 1796.41 Q2048.93 1799.49 2042.61 1799.49 Q2040.43 1799.49 2038.16 1799.12 Q2035.92 1798.75 2033.51 1798.01 L2033.51 1793.31 Q2035.59 1794.45 2037.81 1795 Q2040.04 1795.56 2042.51 1795.56 Q2046.52 1795.56 2048.86 1793.45 Q2051.19 1791.34 2051.19 1787.73 Q2051.19 1784.12 2048.86 1782.02 Q2046.52 1779.91 2042.51 1779.91 Q2040.64 1779.91 2038.76 1780.33 Q2036.91 1780.74 2034.97 1781.62 L2034.97 1764.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M2075.08 1767.34 Q2071.47 1767.34 2069.64 1770.9 Q2067.84 1774.45 2067.84 1781.58 Q2067.84 1788.68 2069.64 1792.25 Q2071.47 1795.79 2075.08 1795.79 Q2078.72 1795.79 2080.52 1792.25 Q2082.35 1788.68 2082.35 1781.58 Q2082.35 1774.45 2080.52 1770.9 Q2078.72 1767.34 2075.08 1767.34 M2075.08 1763.64 Q2080.89 1763.64 2083.95 1768.24 Q2087.03 1772.83 2087.03 1781.58 Q2087.03 1790.3 2083.95 1794.91 Q2080.89 1799.49 2075.08 1799.49 Q2069.27 1799.49 2066.19 1794.91 Q2063.14 1790.3 2063.14 1781.58 Q2063.14 1772.83 2066.19 1768.24 Q2069.27 1763.64 2075.08 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M2541.01 1794.89 L2557.32 1794.89 L2557.32 1798.82 L2535.38 1798.82 L2535.38 1794.89 Q2538.04 1792.13 2542.63 1787.5 Q2547.23 1782.85 2548.41 1781.51 Q2550.66 1778.98 2551.54 1777.25 Q2552.44 1775.49 2552.44 1773.8 Q2552.44 1771.04 2550.5 1769.31 Q2548.57 1767.57 2545.47 1767.57 Q2543.27 1767.57 2540.82 1768.34 Q2538.39 1769.1 2535.61 1770.65 L2535.61 1765.93 Q2538.44 1764.79 2540.89 1764.21 Q2543.34 1763.64 2545.38 1763.64 Q2550.75 1763.64 2553.94 1766.32 Q2557.14 1769.01 2557.14 1773.5 Q2557.14 1775.63 2556.33 1777.55 Q2555.54 1779.45 2553.44 1782.04 Q2552.86 1782.71 2549.75 1785.93 Q2546.65 1789.12 2541.01 1794.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M2577.14 1767.34 Q2573.53 1767.34 2571.7 1770.9 Q2569.89 1774.45 2569.89 1781.58 Q2569.89 1788.68 2571.7 1792.25 Q2573.53 1795.79 2577.14 1795.79 Q2580.77 1795.79 2582.58 1792.25 Q2584.41 1788.68 2584.41 1781.58 Q2584.41 1774.45 2582.58 1770.9 Q2580.77 1767.34 2577.14 1767.34 M2577.14 1763.64 Q2582.95 1763.64 2586 1768.24 Q2589.08 1772.83 2589.08 1781.58 Q2589.08 1790.3 2586 1794.91 Q2582.95 1799.49 2577.14 1799.49 Q2571.33 1799.49 2568.25 1794.91 Q2565.19 1790.3 2565.19 1781.58 Q2565.19 1772.83 2568.25 1768.24 Q2571.33 1763.64 2577.14 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M2607.3 1767.34 Q2603.69 1767.34 2601.86 1770.9 Q2600.06 1774.45 2600.06 1781.58 Q2600.06 1788.68 2601.86 1792.25 Q2603.69 1795.79 2607.3 1795.79 Q2610.94 1795.79 2612.74 1792.25 Q2614.57 1788.68 2614.57 1781.58 Q2614.57 1774.45 2612.74 1770.9 Q2610.94 1767.34 2607.3 1767.34 M2607.3 1763.64 Q2613.11 1763.64 2616.17 1768.24 Q2619.25 1772.83 2619.25 1781.58 Q2619.25 1790.3 2616.17 1794.91 Q2613.11 1799.49 2607.3 1799.49 Q2601.49 1799.49 2598.41 1794.91 Q2595.36 1790.3 2595.36 1781.58 Q2595.36 1772.83 2598.41 1768.24 Q2601.49 1763.64 2607.3 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M1534.85 1861.78 L1534.85 1883.3 L1529 1883.3 L1529 1861.98 Q1529 1856.92 1527.02 1854.4 Q1525.05 1851.89 1521.1 1851.89 Q1516.36 1851.89 1513.62 1854.91 Q1510.89 1857.93 1510.89 1863.15 L1510.89 1883.3 L1505 1883.3 L1505 1847.65 L1510.89 1847.65 L1510.89 1853.19 Q1512.99 1849.98 1515.82 1848.39 Q1518.68 1846.79 1522.41 1846.79 Q1528.55 1846.79 1531.7 1850.61 Q1534.85 1854.4 1534.85 1861.78 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><polyline clip-path="url(#clip322)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="399.095,1686.38 2640.76,1686.38 "></polyline>
<polyline clip-path="url(#clip322)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="399.095,1262.15 2640.76,1262.15 "></polyline>
<polyline clip-path="url(#clip322)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="399.095,837.934 2640.76,837.934 "></polyline>
<polyline clip-path="url(#clip322)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="399.095,413.713 2640.76,413.713 "></polyline>
<polyline clip-path="url(#clip320)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="399.095,1734.12 399.095,47.2441 "></polyline>
<polyline clip-path="url(#clip320)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="399.095,1686.38 417.993,1686.38 "></polyline>
<polyline clip-path="url(#clip320)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="399.095,1262.15 417.993,1262.15 "></polyline>
<polyline clip-path="url(#clip320)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="399.095,837.934 417.993,837.934 "></polyline>
<polyline clip-path="url(#clip320)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="399.095,413.713 417.993,413.713 "></polyline>
<path clip-path="url(#clip320)" d="M346.831 1672.17 Q343.22 1672.17 341.391 1675.74 Q339.586 1679.28 339.586 1686.41 Q339.586 1693.52 341.391 1697.08 Q343.22 1700.62 346.831 1700.62 Q350.465 1700.62 352.271 1697.08 Q354.099 1693.52 354.099 1686.41 Q354.099 1679.28 352.271 1675.74 Q350.465 1672.17 346.831 1672.17 M346.831 1668.47 Q352.641 1668.47 355.697 1673.08 Q358.775 1677.66 358.775 1686.41 Q358.775 1695.14 355.697 1699.74 Q352.641 1704.33 346.831 1704.33 Q341.021 1704.33 337.942 1699.74 Q334.887 1695.14 334.887 1686.41 Q334.887 1677.66 337.942 1673.08 Q341.021 1668.47 346.831 1668.47 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M117.673 1251.32 L136.029 1251.32 L136.029 1255.26 L121.955 1255.26 L121.955 1263.73 Q122.974 1263.38 123.992 1263.22 Q125.011 1263.04 126.029 1263.04 Q131.816 1263.04 135.196 1266.21 Q138.575 1269.38 138.575 1274.79 Q138.575 1280.37 135.103 1283.47 Q131.631 1286.55 125.312 1286.55 Q123.136 1286.55 120.867 1286.18 Q118.622 1285.81 116.214 1285.07 L116.214 1280.37 Q118.298 1281.51 120.52 1282.06 Q122.742 1282.62 125.219 1282.62 Q129.224 1282.62 131.562 1280.51 Q133.9 1278.41 133.9 1274.79 Q133.9 1271.18 131.562 1269.08 Q129.224 1266.97 125.219 1266.97 Q123.344 1266.97 121.469 1267.39 Q119.617 1267.8 117.673 1268.68 L117.673 1251.32 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M147.788 1280 L152.673 1280 L152.673 1285.88 L147.788 1285.88 L147.788 1280 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M172.858 1254.4 Q169.247 1254.4 167.418 1257.97 Q165.612 1261.51 165.612 1268.64 Q165.612 1275.74 167.418 1279.31 Q169.247 1282.85 172.858 1282.85 Q176.492 1282.85 178.297 1279.31 Q180.126 1275.74 180.126 1268.64 Q180.126 1261.51 178.297 1257.97 Q176.492 1254.4 172.858 1254.4 M172.858 1250.7 Q178.668 1250.7 181.723 1255.3 Q184.802 1259.89 184.802 1268.64 Q184.802 1277.36 181.723 1281.97 Q178.668 1286.55 172.858 1286.55 Q167.048 1286.55 163.969 1281.97 Q160.913 1277.36 160.913 1268.64 Q160.913 1259.89 163.969 1255.3 Q167.048 1250.7 172.858 1250.7 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M203.02 1254.4 Q199.408 1254.4 197.58 1257.97 Q195.774 1261.51 195.774 1268.64 Q195.774 1275.74 197.58 1279.31 Q199.408 1282.85 203.02 1282.85 Q206.654 1282.85 208.459 1279.31 Q210.288 1275.74 210.288 1268.64 Q210.288 1261.51 208.459 1257.97 Q206.654 1254.4 203.02 1254.4 M203.02 1250.7 Q208.83 1250.7 211.885 1255.3 Q214.964 1259.89 214.964 1268.64 Q214.964 1277.36 211.885 1281.97 Q208.83 1286.55 203.02 1286.55 Q197.209 1286.55 194.131 1281.97 Q191.075 1277.36 191.075 1268.64 Q191.075 1259.89 194.131 1255.3 Q197.209 1250.7 203.02 1250.7 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M251.353 1260.42 L240.774 1271.04 L251.353 1281.62 L248.598 1284.42 L237.973 1273.8 L227.348 1284.42 L224.617 1281.62 L235.172 1271.04 L224.617 1260.42 L227.348 1257.62 L237.973 1268.24 L248.598 1257.62 L251.353 1260.42 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M263.714 1281.95 L271.353 1281.95 L271.353 1255.58 L263.042 1257.25 L263.042 1252.99 L271.306 1251.32 L275.982 1251.32 L275.982 1281.95 L283.621 1281.95 L283.621 1285.88 L263.714 1285.88 L263.714 1281.95 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M303.065 1254.4 Q299.454 1254.4 297.626 1257.97 Q295.82 1261.51 295.82 1268.64 Q295.82 1275.74 297.626 1279.31 Q299.454 1282.85 303.065 1282.85 Q306.7 1282.85 308.505 1279.31 Q310.334 1275.74 310.334 1268.64 Q310.334 1261.51 308.505 1257.97 Q306.7 1254.4 303.065 1254.4 M303.065 1250.7 Q308.875 1250.7 311.931 1255.3 Q315.01 1259.89 315.01 1268.64 Q315.01 1277.36 311.931 1281.97 Q308.875 1286.55 303.065 1286.55 Q297.255 1286.55 294.176 1281.97 Q291.121 1277.36 291.121 1268.64 Q291.121 1259.89 294.176 1255.3 Q297.255 1250.7 303.065 1250.7 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M319.58 1255.27 L332.839 1255.27 L332.839 1258.47 L315.01 1258.47 L315.01 1255.27 Q317.173 1253.04 320.897 1249.27 Q324.639 1245.49 325.598 1244.4 Q327.423 1242.35 328.137 1240.94 Q328.871 1239.51 328.871 1238.14 Q328.871 1235.9 327.291 1234.49 Q325.73 1233.08 323.21 1233.08 Q321.423 1233.08 319.43 1233.7 Q317.455 1234.32 315.198 1235.58 L315.198 1231.75 Q317.492 1230.82 319.486 1230.35 Q321.48 1229.88 323.135 1229.88 Q327.498 1229.88 330.094 1232.07 Q332.689 1234.25 332.689 1237.9 Q332.689 1239.63 332.031 1241.19 Q331.391 1242.73 329.68 1244.84 Q329.21 1245.38 326.689 1248 Q324.169 1250.59 319.58 1255.27 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M349.409 1242.92 Q346.851 1242.92 345.347 1244.67 Q343.861 1246.42 343.861 1249.46 Q343.861 1252.49 345.347 1254.26 Q346.851 1256.01 349.409 1256.01 Q351.967 1256.01 353.453 1254.26 Q354.957 1252.49 354.957 1249.46 Q354.957 1246.42 353.453 1244.67 Q351.967 1242.92 349.409 1242.92 M356.951 1231.01 L356.951 1234.47 Q355.522 1233.8 354.055 1233.44 Q352.606 1233.08 351.177 1233.08 Q347.415 1233.08 345.422 1235.62 Q343.447 1238.16 343.165 1243.29 Q344.275 1241.66 345.948 1240.79 Q347.622 1239.91 349.635 1239.91 Q353.867 1239.91 356.312 1242.49 Q358.775 1245.04 358.775 1249.46 Q358.775 1253.79 356.217 1256.4 Q353.66 1259.02 349.409 1259.02 Q344.538 1259.02 341.961 1255.29 Q339.385 1251.55 339.385 1244.46 Q339.385 1237.8 342.544 1233.85 Q345.704 1229.88 351.027 1229.88 Q352.456 1229.88 353.904 1230.17 Q355.371 1230.45 356.951 1231.01 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M119.302 857.726 L126.941 857.726 L126.941 831.361 L118.631 833.027 L118.631 828.768 L126.894 827.102 L131.57 827.102 L131.57 857.726 L139.209 857.726 L139.209 861.662 L119.302 861.662 L119.302 857.726 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M148.654 855.782 L153.538 855.782 L153.538 861.662 L148.654 861.662 L148.654 855.782 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M173.723 830.18 Q170.112 830.18 168.283 833.745 Q166.477 837.287 166.477 844.416 Q166.477 851.523 168.283 855.087 Q170.112 858.629 173.723 858.629 Q177.357 858.629 179.163 855.087 Q180.991 851.523 180.991 844.416 Q180.991 837.287 179.163 833.745 Q177.357 830.18 173.723 830.18 M173.723 826.477 Q179.533 826.477 182.589 831.083 Q185.667 835.666 185.667 844.416 Q185.667 853.143 182.589 857.749 Q179.533 862.333 173.723 862.333 Q167.913 862.333 164.834 857.749 Q161.778 853.143 161.778 844.416 Q161.778 835.666 164.834 831.083 Q167.913 826.477 173.723 826.477 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M203.885 830.18 Q200.274 830.18 198.445 833.745 Q196.639 837.287 196.639 844.416 Q196.639 851.523 198.445 855.087 Q200.274 858.629 203.885 858.629 Q207.519 858.629 209.324 855.087 Q211.153 851.523 211.153 844.416 Q211.153 837.287 209.324 833.745 Q207.519 830.18 203.885 830.18 M203.885 826.477 Q209.695 826.477 212.75 831.083 Q215.829 835.666 215.829 844.416 Q215.829 853.143 212.75 857.749 Q209.695 862.333 203.885 862.333 Q198.075 862.333 194.996 857.749 Q191.94 853.143 191.94 844.416 Q191.94 835.666 194.996 831.083 Q198.075 826.477 203.885 826.477 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M252.218 836.199 L241.639 846.824 L252.218 857.402 L249.463 860.203 L238.838 849.578 L228.213 860.203 L225.482 857.402 L236.037 846.824 L225.482 836.199 L228.213 833.398 L238.838 844.023 L249.463 833.398 L252.218 836.199 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M264.579 857.726 L272.218 857.726 L272.218 831.361 L263.908 833.027 L263.908 828.768 L272.171 827.102 L276.847 827.102 L276.847 857.726 L284.486 857.726 L284.486 861.662 L264.579 861.662 L264.579 857.726 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M303.93 830.18 Q300.319 830.18 298.491 833.745 Q296.685 837.287 296.685 844.416 Q296.685 851.523 298.491 855.087 Q300.319 858.629 303.93 858.629 Q307.565 858.629 309.37 855.087 Q311.199 851.523 311.199 844.416 Q311.199 837.287 309.37 833.745 Q307.565 830.18 303.93 830.18 M303.93 826.477 Q309.741 826.477 312.796 831.083 Q315.875 835.666 315.875 844.416 Q315.875 853.143 312.796 857.749 Q309.741 862.333 303.93 862.333 Q298.12 862.333 295.042 857.749 Q291.986 853.143 291.986 844.416 Q291.986 835.666 295.042 831.083 Q298.12 826.477 303.93 826.477 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M320.445 831.054 L333.705 831.054 L333.705 834.251 L315.875 834.251 L315.875 831.054 Q318.038 828.816 321.762 825.054 Q325.504 821.274 326.464 820.183 Q328.288 818.133 329.003 816.722 Q329.736 815.293 329.736 813.92 Q329.736 811.682 328.156 810.271 Q326.595 808.861 324.075 808.861 Q322.288 808.861 320.295 809.481 Q318.32 810.102 316.063 811.362 L316.063 807.525 Q318.357 806.604 320.351 806.133 Q322.345 805.663 324 805.663 Q328.363 805.663 330.959 807.845 Q333.554 810.027 333.554 813.675 Q333.554 815.406 332.896 816.967 Q332.256 818.509 330.545 820.615 Q330.075 821.161 327.554 823.775 Q325.034 826.371 320.445 831.054 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M340.72 806.171 L358.775 806.171 L358.775 807.789 L348.582 834.251 L344.613 834.251 L354.205 809.368 L340.72 809.368 L340.72 806.171 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M119.302 433.506 L126.941 433.506 L126.941 407.14 L118.631 408.807 L118.631 404.547 L126.894 402.881 L131.57 402.881 L131.57 433.506 L139.209 433.506 L139.209 437.441 L119.302 437.441 L119.302 433.506 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M148.654 431.561 L153.538 431.561 L153.538 437.441 L148.654 437.441 L148.654 431.561 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M163.769 402.881 L182.126 402.881 L182.126 406.816 L168.052 406.816 L168.052 415.288 Q169.07 414.941 170.089 414.779 Q171.107 414.594 172.126 414.594 Q177.913 414.594 181.292 417.765 Q184.672 420.936 184.672 426.353 Q184.672 431.932 181.2 435.033 Q177.727 438.112 171.408 438.112 Q169.232 438.112 166.964 437.742 Q164.718 437.371 162.311 436.631 L162.311 431.932 Q164.394 433.066 166.616 433.621 Q168.839 434.177 171.315 434.177 Q175.32 434.177 177.658 432.07 Q179.996 429.964 179.996 426.353 Q179.996 422.742 177.658 420.635 Q175.32 418.529 171.315 418.529 Q169.44 418.529 167.565 418.946 Q165.714 419.362 163.769 420.242 L163.769 402.881 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M203.885 405.96 Q200.274 405.96 198.445 409.524 Q196.639 413.066 196.639 420.196 Q196.639 427.302 198.445 430.867 Q200.274 434.408 203.885 434.408 Q207.519 434.408 209.324 430.867 Q211.153 427.302 211.153 420.196 Q211.153 413.066 209.324 409.524 Q207.519 405.96 203.885 405.96 M203.885 402.256 Q209.695 402.256 212.75 406.862 Q215.829 411.446 215.829 420.196 Q215.829 428.922 212.75 433.529 Q209.695 438.112 203.885 438.112 Q198.075 438.112 194.996 433.529 Q191.94 428.922 191.94 420.196 Q191.94 411.446 194.996 406.862 Q198.075 402.256 203.885 402.256 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M252.218 411.978 L241.639 422.603 L252.218 433.182 L249.463 435.982 L238.838 425.358 L228.213 435.982 L225.482 433.182 L236.037 422.603 L225.482 411.978 L228.213 409.177 L238.838 419.802 L249.463 409.177 L252.218 411.978 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M264.579 433.506 L272.218 433.506 L272.218 407.14 L263.908 408.807 L263.908 404.547 L272.171 402.881 L276.847 402.881 L276.847 433.506 L284.486 433.506 L284.486 437.441 L264.579 437.441 L264.579 433.506 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M303.93 405.96 Q300.319 405.96 298.491 409.524 Q296.685 413.066 296.685 420.196 Q296.685 427.302 298.491 430.867 Q300.319 434.408 303.93 434.408 Q307.565 434.408 309.37 430.867 Q311.199 427.302 311.199 420.196 Q311.199 413.066 309.37 409.524 Q307.565 405.96 303.93 405.96 M303.93 402.256 Q309.741 402.256 312.796 406.862 Q315.875 411.446 315.875 420.196 Q315.875 428.922 312.796 433.529 Q309.741 438.112 303.93 438.112 Q298.12 438.112 295.042 433.529 Q291.986 428.922 291.986 420.196 Q291.986 411.446 295.042 406.862 Q298.12 402.256 303.93 402.256 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M320.445 406.833 L333.705 406.833 L333.705 410.03 L315.875 410.03 L315.875 406.833 Q318.038 404.595 321.762 400.833 Q325.504 397.053 326.464 395.962 Q328.288 393.912 329.003 392.502 Q329.736 391.072 329.736 389.699 Q329.736 387.461 328.156 386.051 Q326.595 384.64 324.075 384.64 Q322.288 384.64 320.295 385.261 Q318.32 385.881 316.063 387.141 L316.063 383.305 Q318.357 382.383 320.351 381.913 Q322.345 381.443 324 381.443 Q328.363 381.443 330.959 383.624 Q333.554 385.806 333.554 389.455 Q333.554 391.185 332.896 392.746 Q332.256 394.288 330.545 396.395 Q330.075 396.94 327.554 399.554 Q325.034 402.15 320.445 406.833 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M340.72 381.95 L358.775 381.95 L358.775 383.568 L348.582 410.03 L344.613 410.03 L354.205 385.148 L340.72 385.148 L340.72 381.95 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M43.719 1183.15 Q43.719 1190.25 45.3422 1192.99 Q46.9655 1195.73 50.8804 1195.73 Q53.9996 1195.73 55.8457 1193.69 Q57.6599 1191.62 57.6599 1188.09 Q57.6599 1183.22 54.2224 1180.29 Q50.7531 1177.33 45.0239 1177.33 L43.719 1177.33 L43.719 1183.15 M41.3 1171.47 L61.6384 1171.47 L61.6384 1177.33 L56.2276 1177.33 Q59.4741 1179.33 61.0337 1182.33 Q62.5615 1185.32 62.5615 1189.65 Q62.5615 1195.12 59.5059 1198.37 Q56.4186 1201.58 51.2623 1201.58 Q45.2467 1201.58 42.1912 1197.57 Q39.1357 1193.53 39.1357 1185.54 L39.1357 1177.33 L38.5628 1177.33 Q34.5205 1177.33 32.3244 1180 Q30.0964 1182.64 30.0964 1187.45 Q30.0964 1190.51 30.8284 1193.4 Q31.5605 1196.3 33.0246 1198.97 L27.6137 1198.97 Q26.3724 1195.76 25.7677 1192.73 Q25.1311 1189.71 25.1311 1186.85 Q25.1311 1179.11 29.1415 1175.29 Q33.1519 1171.47 41.3 1171.47 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M43.8463 1133.82 Q37.3851 1133.82 33.7248 1136.49 Q30.0327 1139.13 30.0327 1143.78 Q30.0327 1148.43 33.7248 1151.1 Q37.3851 1153.74 43.8463 1153.74 Q50.3075 1153.74 53.9996 1151.1 Q57.6599 1148.43 57.6599 1143.78 Q57.6599 1139.13 53.9996 1136.49 Q50.3075 1133.82 43.8463 1133.82 M31.4013 1153.74 Q28.2185 1151.9 26.6907 1149.1 Q25.1311 1146.26 25.1311 1142.35 Q25.1311 1135.86 30.2873 1131.81 Q35.4436 1127.74 43.8463 1127.74 Q52.249 1127.74 57.4052 1131.81 Q62.5615 1135.86 62.5615 1142.35 Q62.5615 1146.26 61.0337 1149.1 Q59.4741 1151.9 56.2912 1153.74 L61.6384 1153.74 L61.6384 1159.63 L12.1132 1159.63 L12.1132 1153.74 L31.4013 1153.74 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M27.0408 1095.31 L32.579 1095.31 Q31.3059 1097.79 30.6693 1100.46 Q30.0327 1103.14 30.0327 1106 Q30.0327 1110.36 31.3695 1112.56 Q32.7063 1114.72 35.3799 1114.72 Q37.4169 1114.72 38.5946 1113.16 Q39.7404 1111.6 40.7908 1106.89 L41.2364 1104.89 Q42.5732 1098.65 45.0239 1096.04 Q47.4429 1093.4 51.8034 1093.4 Q56.7687 1093.4 59.6651 1097.34 Q62.5615 1101.26 62.5615 1108.13 Q62.5615 1111 61.9886 1114.12 Q61.4475 1117.2 60.3335 1120.64 L54.2861 1120.64 Q55.973 1117.4 56.8323 1114.24 Q57.6599 1111.09 57.6599 1108.01 Q57.6599 1103.87 56.2594 1101.64 Q54.8271 1099.41 52.249 1099.41 Q49.8619 1099.41 48.5887 1101.04 Q47.3156 1102.63 46.1379 1108.07 L45.6605 1110.11 Q44.5147 1115.55 42.1594 1117.97 Q39.7722 1120.39 35.6345 1120.39 Q30.6056 1120.39 27.8684 1116.82 Q25.1311 1113.26 25.1311 1106.7 Q25.1311 1103.45 25.6085 1100.59 Q26.086 1097.73 27.0408 1095.31 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M30.0964 1070.26 Q30.0964 1074.97 33.7885 1077.71 Q37.4488 1080.44 43.8463 1080.44 Q50.2438 1080.44 53.9359 1077.74 Q57.5962 1075 57.5962 1070.26 Q57.5962 1065.58 53.9041 1062.84 Q50.212 1060.1 43.8463 1060.1 Q37.5124 1060.1 33.8203 1062.84 Q30.0964 1065.58 30.0964 1070.26 M25.1311 1070.26 Q25.1311 1062.62 30.0964 1058.26 Q35.0616 1053.9 43.8463 1053.9 Q52.5991 1053.9 57.5962 1058.26 Q62.5615 1062.62 62.5615 1070.26 Q62.5615 1077.93 57.5962 1082.29 Q52.5991 1086.62 43.8463 1086.62 Q35.0616 1086.62 30.0964 1082.29 Q25.1311 1077.93 25.1311 1070.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M12.1132 1044.19 L12.1132 1038.33 L61.6384 1038.33 L61.6384 1044.19 L12.1132 1044.19 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M47.5702 1026.68 L25.9905 1026.68 L25.9905 1020.83 L47.3474 1020.83 Q52.4082 1020.83 54.9545 1018.85 Q57.4689 1016.88 57.4689 1012.93 Q57.4689 1008.19 54.4452 1005.45 Q51.4215 1002.69 46.2016 1002.69 L25.9905 1002.69 L25.9905 996.829 L61.6384 996.829 L61.6384 1002.69 L56.1639 1002.69 Q59.4104 1004.82 61.0019 1007.65 Q62.5615 1010.45 62.5615 1014.18 Q62.5615 1020.32 58.742 1023.5 Q54.9226 1026.68 47.5702 1026.68 M25.1311 1011.95 L25.1311 1011.95 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M15.869 978.973 L25.9905 978.973 L25.9905 966.91 L30.542 966.91 L30.542 978.973 L49.8937 978.973 Q54.2542 978.973 55.4955 977.795 Q56.7368 976.586 56.7368 972.925 L56.7368 966.91 L61.6384 966.91 L61.6384 972.925 Q61.6384 979.705 59.124 982.283 Q56.5777 984.861 49.8937 984.861 L30.542 984.861 L30.542 989.158 L25.9905 989.158 L25.9905 984.861 L15.869 984.861 L15.869 978.973 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M42.3504 928.716 L45.2149 928.716 L45.2149 955.643 Q51.2623 955.261 54.4452 952.014 Q57.5962 948.736 57.5962 942.911 Q57.5962 939.537 56.7687 936.386 Q55.9411 933.203 54.2861 930.084 L59.8242 930.084 Q61.161 933.235 61.8612 936.545 Q62.5615 939.856 62.5615 943.261 Q62.5615 951.791 57.5962 956.788 Q52.631 961.754 44.1646 961.754 Q35.4117 961.754 30.2873 957.043 Q25.1311 952.301 25.1311 944.28 Q25.1311 937.087 29.7781 932.917 Q34.3932 928.716 42.3504 928.716 M40.6316 934.572 Q35.8255 934.636 32.9609 937.278 Q30.0964 939.887 30.0964 944.216 Q30.0964 949.118 32.8654 952.078 Q35.6345 955.006 40.6634 955.452 L40.6316 934.572 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M31.4013 874.925 L12.1132 874.925 L12.1132 869.069 L61.6384 869.069 L61.6384 874.925 L56.2912 874.925 Q59.4741 876.771 61.0337 879.604 Q62.5615 882.405 62.5615 886.352 Q62.5615 892.813 57.4052 896.887 Q52.249 900.929 43.8463 900.929 Q35.4436 900.929 30.2873 896.887 Q25.1311 892.813 25.1311 886.352 Q25.1311 882.405 26.6907 879.604 Q28.2185 876.771 31.4013 874.925 M43.8463 894.882 Q50.3075 894.882 53.9996 892.24 Q57.6599 889.567 57.6599 884.92 Q57.6599 880.273 53.9996 877.599 Q50.3075 874.925 43.8463 874.925 Q37.3851 874.925 33.7248 877.599 Q30.0327 880.273 30.0327 884.92 Q30.0327 889.567 33.7248 892.24 Q37.3851 894.882 43.8463 894.882 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M25.9905 857.006 L25.9905 851.15 L61.6384 851.15 L61.6384 857.006 L25.9905 857.006 M12.1132 857.006 L12.1132 851.15 L19.5293 851.15 L19.5293 857.006 L12.1132 857.006 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M12.1132 820.849 L16.983 820.849 L16.983 826.451 Q16.983 829.602 18.2562 830.843 Q19.5293 832.052 22.8395 832.052 L25.9905 832.052 L25.9905 822.408 L30.542 822.408 L30.542 832.052 L61.6384 832.052 L61.6384 837.941 L30.542 837.941 L30.542 843.542 L25.9905 843.542 L25.9905 837.941 L23.5079 837.941 Q17.5559 837.941 14.8505 835.172 Q12.1132 832.402 12.1132 826.387 L12.1132 820.849 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M12.1132 797.9 L16.983 797.9 L16.983 803.502 Q16.983 806.653 18.2562 807.895 Q19.5293 809.104 22.8395 809.104 L25.9905 809.104 L25.9905 799.46 L30.542 799.46 L30.542 809.104 L61.6384 809.104 L61.6384 814.992 L30.542 814.992 L30.542 820.594 L25.9905 820.594 L25.9905 814.992 L23.5079 814.992 Q17.5559 814.992 14.8505 812.223 Q12.1132 809.454 12.1132 803.439 L12.1132 797.9 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M42.3504 762.507 L45.2149 762.507 L45.2149 789.434 Q51.2623 789.052 54.4452 785.806 Q57.5962 782.527 57.5962 776.703 Q57.5962 773.329 56.7687 770.178 Q55.9411 766.995 54.2861 763.876 L59.8242 763.876 Q61.161 767.027 61.8612 770.337 Q62.5615 773.647 62.5615 777.053 Q62.5615 785.583 57.5962 790.58 Q52.631 795.545 44.1646 795.545 Q35.4117 795.545 30.2873 790.834 Q25.1311 786.092 25.1311 778.071 Q25.1311 770.878 29.7781 766.708 Q34.3932 762.507 42.3504 762.507 M40.6316 768.363 Q35.8255 768.427 32.9609 771.069 Q30.0964 773.679 30.0964 778.008 Q30.0964 782.909 32.8654 785.869 Q35.6345 788.797 40.6634 789.243 L40.6316 768.363 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M31.465 732.238 Q30.8921 733.225 30.6375 734.402 Q30.351 735.548 30.351 736.949 Q30.351 741.914 33.5975 744.588 Q36.8122 747.229 42.8596 747.229 L61.6384 747.229 L61.6384 753.118 L25.9905 753.118 L25.9905 747.229 L31.5287 747.229 Q28.2821 745.383 26.7225 742.423 Q25.1311 739.463 25.1311 735.23 Q25.1311 734.625 25.2266 733.893 Q25.2903 733.161 25.4494 732.27 L31.465 732.238 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M42.3504 697.036 L45.2149 697.036 L45.2149 723.963 Q51.2623 723.581 54.4452 720.334 Q57.5962 717.056 57.5962 711.231 Q57.5962 707.857 56.7687 704.706 Q55.9411 701.524 54.2861 698.404 L59.8242 698.404 Q61.161 701.555 61.8612 704.866 Q62.5615 708.176 62.5615 711.581 Q62.5615 720.111 57.5962 725.109 Q52.631 730.074 44.1646 730.074 Q35.4117 730.074 30.2873 725.363 Q25.1311 720.621 25.1311 712.6 Q25.1311 705.407 29.7781 701.237 Q34.3932 697.036 42.3504 697.036 M40.6316 702.892 Q35.8255 702.956 32.9609 705.598 Q30.0964 708.208 30.0964 712.536 Q30.0964 717.438 32.8654 720.398 Q35.6345 723.326 40.6634 723.772 L40.6316 702.892 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M40.1224 657.791 L61.6384 657.791 L61.6384 663.648 L40.3133 663.648 Q35.2526 663.648 32.7381 665.621 Q30.2237 667.594 30.2237 671.541 Q30.2237 676.284 33.2474 679.021 Q36.2711 681.758 41.491 681.758 L61.6384 681.758 L61.6384 687.646 L25.9905 687.646 L25.9905 681.758 L31.5287 681.758 Q28.314 679.657 26.7225 676.825 Q25.1311 673.96 25.1311 670.236 Q25.1311 664.093 28.9505 660.942 Q32.7381 657.791 40.1224 657.791 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M27.3591 620.456 L32.8336 620.456 Q31.465 622.939 30.7966 625.453 Q30.0964 627.936 30.0964 630.482 Q30.0964 636.18 33.7248 639.331 Q37.3214 642.482 43.8463 642.482 Q50.3711 642.482 53.9996 639.331 Q57.5962 636.18 57.5962 630.482 Q57.5962 627.936 56.9278 625.453 Q56.2276 622.939 54.859 620.456 L60.2698 620.456 Q61.4156 622.907 61.9886 625.549 Q62.5615 628.159 62.5615 631.119 Q62.5615 639.171 57.5007 643.914 Q52.44 648.656 43.8463 648.656 Q35.1253 648.656 30.1282 643.882 Q25.1311 639.076 25.1311 630.737 Q25.1311 628.031 25.704 625.453 Q26.2451 622.875 27.3591 620.456 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip320)" d="M42.3504 579.779 L45.2149 579.779 L45.2149 606.706 Q51.2623 606.324 54.4452 603.078 Q57.5962 599.8 57.5962 593.975 Q57.5962 590.601 56.7687 587.45 Q55.9411 584.267 54.2861 581.148 L59.8242 581.148 Q61.161 584.299 61.8612 587.609 Q62.5615 590.919 62.5615 594.325 Q62.5615 602.855 57.5962 607.852 Q52.631 612.817 44.1646 612.817 Q35.4117 612.817 30.2873 608.107 Q25.1311 603.364 25.1311 595.344 Q25.1311 588.15 29.7781 583.981 Q34.3932 579.779 42.3504 579.779 M40.6316 585.636 Q35.8255 585.7 32.9609 588.341 Q30.0964 590.951 30.0964 595.28 Q30.0964 600.182 32.8654 603.142 Q35.6345 606.07 40.6634 606.515 L40.6316 585.636 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><circle clip-path="url(#clip322)" cx="462.539" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="473.166" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="483.793" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="494.42" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="505.047" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="515.674" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="526.301" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="536.928" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="547.555" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="558.182" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="568.809" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="579.436" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="590.063" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="600.69" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="611.317" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="621.944" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="632.571" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="643.198" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="653.825" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="664.452" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="675.079" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="685.706" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="696.333" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="706.96" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="717.587" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="728.214" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="738.841" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="749.468" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="760.095" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="770.722" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="781.349" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="791.976" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="802.603" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="813.23" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="823.857" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="834.484" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="845.111" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="855.738" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="866.365" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="876.992" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="887.619" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="898.246" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="908.873" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="919.5" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="930.127" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="940.754" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="951.381" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="962.008" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="972.635" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="983.262" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="993.889" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1004.52" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1015.14" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1025.77" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1036.4" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1047.02" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1057.65" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1068.28" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1078.9" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1089.53" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1100.16" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1110.79" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1121.41" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1132.04" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1142.67" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1153.29" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1163.92" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1174.55" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1185.17" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1195.8" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1206.43" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1217.06" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1227.68" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1238.31" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1248.94" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1259.56" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1270.19" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1280.82" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1291.45" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1302.07" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1312.7" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1323.33" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1333.95" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1344.58" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1355.21" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1365.83" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1376.46" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1387.09" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1397.72" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1408.34" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1418.97" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1429.6" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1440.22" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1450.85" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1461.48" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1472.1" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1482.73" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1493.36" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1503.99" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1514.61" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1525.24" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1535.87" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1546.49" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1557.12" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1567.75" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1578.37" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1589" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1599.63" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1610.26" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1620.88" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1631.51" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1642.14" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1652.76" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1663.39" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1674.02" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1684.64" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1695.27" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1705.9" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1716.53" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1727.15" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1737.78" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1748.41" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1759.03" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1769.66" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1780.29" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1790.91" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1801.54" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1812.17" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1822.8" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1833.42" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1844.05" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1854.68" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1865.3" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1875.93" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1886.56" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1897.18" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1907.81" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1918.44" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1929.07" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1939.69" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1950.32" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1960.95" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1971.57" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1982.2" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="1992.83" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2003.45" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2014.08" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2024.71" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2035.34" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2045.96" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2056.59" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2067.22" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2077.84" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2088.47" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2099.1" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2109.72" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2120.35" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2130.98" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2141.61" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2152.23" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2162.86" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2173.49" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2184.11" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2194.74" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2205.37" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2215.99" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2226.62" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2237.25" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2247.88" cy="1686.37" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2258.5" cy="1686.37" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2269.13" cy="1686.37" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2279.76" cy="1686.37" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2290.38" cy="1686.37" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2301.01" cy="1686.37" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2311.64" cy="1686.37" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2322.26" cy="1686.36" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2332.89" cy="1686.35" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2343.52" cy="1686.34" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2354.15" cy="1686.32" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2364.77" cy="1686.28" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2375.4" cy="1686.22" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2386.03" cy="1686.12" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2396.65" cy="1685.97" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2407.28" cy="1685.71" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2417.91" cy="1685.3" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2428.53" cy="1684.65" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2439.16" cy="1683.55" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2449.79" cy="1681.73" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2460.42" cy="1678.72" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2471.04" cy="1674.08" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2481.67" cy="1666.16" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2492.3" cy="1654.12" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2502.92" cy="1633.4" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2513.55" cy="1599.09" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2524.18" cy="1547.13" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2534.8" cy="1455.74" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2545.43" cy="1320.61" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2556.06" cy="1089.98" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2566.69" cy="707.796" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip322)" cx="2577.31" cy="94.9858" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
</svg>
</div>
</div>
<blockquote class="blockquote">
<p><strong>Figure 1.</strong> Absolute difference between the Fibonacci numbers obtained using <code>fib_binet()</code> and those obtained using <code>fib_memo()</code>.</p>
</blockquote>
<div id="f6379a54" class="cell" data-execution_count="14">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb25-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>, rel_diff, seriestype<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=:</span>scatter, </span>
<span id="cb25-2">     xlabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"n"</span>,</span>
<span id="cb25-3">     ylabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"relative difference"</span>,</span>
<span id="cb25-4">     label <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="15">
<!--?xml version="1.0" encoding="utf-8"?-->
<svg xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" width="672" height="480" viewbox="0 0 2688 1920">
<defs>
  <clippath id="clip410">
    <rect x="0" y="0" width="2688" height="1920"></rect>
  </clippath>
</defs>
<path clip-path="url(#clip410)" d="M0 1920 L2688 1920 L2688 0 L0 0  Z" fill="#ffffff" fill-rule="evenodd" fill-opacity="1"></path>
<defs>
  <clippath id="clip411">
    <rect x="537" y="0" width="1883" height="1883"></rect>
  </clippath>
</defs>
<path clip-path="url(#clip410)" d="M400.35 1734.12 L2640.76 1734.12 L2640.76 47.2441 L400.35 47.2441  Z" fill="#ffffff" fill-rule="evenodd" fill-opacity="1"></path>
<defs>
  <clippath id="clip412">
    <rect x="400" y="47" width="2241" height="1688"></rect>
  </clippath>
</defs>
<polyline clip-path="url(#clip412)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="453.136,1734.12 453.136,47.2441 "></polyline>
<polyline clip-path="url(#clip412)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="984.189,1734.12 984.189,47.2441 "></polyline>
<polyline clip-path="url(#clip412)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="1515.24,1734.12 1515.24,47.2441 "></polyline>
<polyline clip-path="url(#clip412)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="2046.3,1734.12 2046.3,47.2441 "></polyline>
<polyline clip-path="url(#clip412)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="2577.35,1734.12 2577.35,47.2441 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="400.35,1734.12 2640.76,1734.12 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="453.136,1734.12 453.136,1715.22 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="984.189,1734.12 984.189,1715.22 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="1515.24,1734.12 1515.24,1715.22 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="2046.3,1734.12 2046.3,1715.22 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="2577.35,1734.12 2577.35,1715.22 "></polyline>
<path clip-path="url(#clip410)" d="M453.136 1767.34 Q449.525 1767.34 447.697 1770.9 Q445.891 1774.45 445.891 1781.58 Q445.891 1788.68 447.697 1792.25 Q449.525 1795.79 453.136 1795.79 Q456.771 1795.79 458.576 1792.25 Q460.405 1788.68 460.405 1781.58 Q460.405 1774.45 458.576 1770.9 Q456.771 1767.34 453.136 1767.34 M453.136 1763.64 Q458.947 1763.64 462.002 1768.24 Q465.081 1772.83 465.081 1781.58 Q465.081 1790.3 462.002 1794.91 Q458.947 1799.49 453.136 1799.49 Q447.326 1799.49 444.248 1794.91 Q441.192 1790.3 441.192 1781.58 Q441.192 1772.83 444.248 1768.24 Q447.326 1763.64 453.136 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M958.889 1764.26 L977.245 1764.26 L977.245 1768.2 L963.171 1768.2 L963.171 1776.67 Q964.189 1776.32 965.208 1776.16 Q966.226 1775.97 967.245 1775.97 Q973.032 1775.97 976.412 1779.15 Q979.791 1782.32 979.791 1787.73 Q979.791 1793.31 976.319 1796.41 Q972.847 1799.49 966.527 1799.49 Q964.351 1799.49 962.083 1799.12 Q959.838 1798.75 957.43 1798.01 L957.43 1793.31 Q959.514 1794.45 961.736 1795 Q963.958 1795.56 966.435 1795.56 Q970.439 1795.56 972.777 1793.45 Q975.115 1791.34 975.115 1787.73 Q975.115 1784.12 972.777 1782.02 Q970.439 1779.91 966.435 1779.91 Q964.56 1779.91 962.685 1780.33 Q960.833 1780.74 958.889 1781.62 L958.889 1764.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M999.004 1767.34 Q995.393 1767.34 993.564 1770.9 Q991.759 1774.45 991.759 1781.58 Q991.759 1788.68 993.564 1792.25 Q995.393 1795.79 999.004 1795.79 Q1002.64 1795.79 1004.44 1792.25 Q1006.27 1788.68 1006.27 1781.58 Q1006.27 1774.45 1004.44 1770.9 Q1002.64 1767.34 999.004 1767.34 M999.004 1763.64 Q1004.81 1763.64 1007.87 1768.24 Q1010.95 1772.83 1010.95 1781.58 Q1010.95 1790.3 1007.87 1794.91 Q1004.81 1799.49 999.004 1799.49 Q993.194 1799.49 990.115 1794.91 Q987.06 1790.3 987.06 1781.58 Q987.06 1772.83 990.115 1768.24 Q993.194 1763.64 999.004 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M1474.85 1794.89 L1482.49 1794.89 L1482.49 1768.52 L1474.18 1770.19 L1474.18 1765.93 L1482.44 1764.26 L1487.12 1764.26 L1487.12 1794.89 L1494.76 1794.89 L1494.76 1798.82 L1474.85 1798.82 L1474.85 1794.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M1514.2 1767.34 Q1510.59 1767.34 1508.76 1770.9 Q1506.96 1774.45 1506.96 1781.58 Q1506.96 1788.68 1508.76 1792.25 Q1510.59 1795.79 1514.2 1795.79 Q1517.83 1795.79 1519.64 1792.25 Q1521.47 1788.68 1521.47 1781.58 Q1521.47 1774.45 1519.64 1770.9 Q1517.83 1767.34 1514.2 1767.34 M1514.2 1763.64 Q1520.01 1763.64 1523.07 1768.24 Q1526.14 1772.83 1526.14 1781.58 Q1526.14 1790.3 1523.07 1794.91 Q1520.01 1799.49 1514.2 1799.49 Q1508.39 1799.49 1505.31 1794.91 Q1502.26 1790.3 1502.26 1781.58 Q1502.26 1772.83 1505.31 1768.24 Q1508.39 1763.64 1514.2 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M1544.36 1767.34 Q1540.75 1767.34 1538.92 1770.9 Q1537.12 1774.45 1537.12 1781.58 Q1537.12 1788.68 1538.92 1792.25 Q1540.75 1795.79 1544.36 1795.79 Q1548 1795.79 1549.8 1792.25 Q1551.63 1788.68 1551.63 1781.58 Q1551.63 1774.45 1549.8 1770.9 Q1548 1767.34 1544.36 1767.34 M1544.36 1763.64 Q1550.17 1763.64 1553.23 1768.24 Q1556.31 1772.83 1556.31 1781.58 Q1556.31 1790.3 1553.23 1794.91 Q1550.17 1799.49 1544.36 1799.49 Q1538.55 1799.49 1535.47 1794.91 Q1532.42 1790.3 1532.42 1781.58 Q1532.42 1772.83 1535.47 1768.24 Q1538.55 1763.64 1544.36 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M2005.9 1794.89 L2013.54 1794.89 L2013.54 1768.52 L2005.23 1770.19 L2005.23 1765.93 L2013.49 1764.26 L2018.17 1764.26 L2018.17 1794.89 L2025.81 1794.89 L2025.81 1798.82 L2005.9 1798.82 L2005.9 1794.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M2035.3 1764.26 L2053.66 1764.26 L2053.66 1768.2 L2039.58 1768.2 L2039.58 1776.67 Q2040.6 1776.32 2041.62 1776.16 Q2042.64 1775.97 2043.66 1775.97 Q2049.44 1775.97 2052.82 1779.15 Q2056.2 1782.32 2056.2 1787.73 Q2056.2 1793.31 2052.73 1796.41 Q2049.26 1799.49 2042.94 1799.49 Q2040.76 1799.49 2038.49 1799.12 Q2036.25 1798.75 2033.84 1798.01 L2033.84 1793.31 Q2035.92 1794.45 2038.15 1795 Q2040.37 1795.56 2042.85 1795.56 Q2046.85 1795.56 2049.19 1793.45 Q2051.53 1791.34 2051.53 1787.73 Q2051.53 1784.12 2049.19 1782.02 Q2046.85 1779.91 2042.85 1779.91 Q2040.97 1779.91 2039.1 1780.33 Q2037.24 1780.74 2035.3 1781.62 L2035.3 1764.26 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M2075.42 1767.34 Q2071.8 1767.34 2069.98 1770.9 Q2068.17 1774.45 2068.17 1781.58 Q2068.17 1788.68 2069.98 1792.25 Q2071.8 1795.79 2075.42 1795.79 Q2079.05 1795.79 2080.86 1792.25 Q2082.68 1788.68 2082.68 1781.58 Q2082.68 1774.45 2080.86 1770.9 Q2079.05 1767.34 2075.42 1767.34 M2075.42 1763.64 Q2081.23 1763.64 2084.28 1768.24 Q2087.36 1772.83 2087.36 1781.58 Q2087.36 1790.3 2084.28 1794.91 Q2081.23 1799.49 2075.42 1799.49 Q2069.61 1799.49 2066.53 1794.91 Q2063.47 1790.3 2063.47 1781.58 Q2063.47 1772.83 2066.53 1768.24 Q2069.61 1763.64 2075.42 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M2541.04 1794.89 L2557.36 1794.89 L2557.36 1798.82 L2535.42 1798.82 L2535.42 1794.89 Q2538.08 1792.13 2542.66 1787.5 Q2547.27 1782.85 2548.45 1781.51 Q2550.69 1778.98 2551.57 1777.25 Q2552.48 1775.49 2552.48 1773.8 Q2552.48 1771.04 2550.53 1769.31 Q2548.61 1767.57 2545.51 1767.57 Q2543.31 1767.57 2540.86 1768.34 Q2538.42 1769.1 2535.65 1770.65 L2535.65 1765.93 Q2538.47 1764.79 2540.92 1764.21 Q2543.38 1763.64 2545.42 1763.64 Q2550.79 1763.64 2553.98 1766.32 Q2557.17 1769.01 2557.17 1773.5 Q2557.17 1775.63 2556.36 1777.55 Q2555.58 1779.45 2553.47 1782.04 Q2552.89 1782.71 2549.79 1785.93 Q2546.69 1789.12 2541.04 1794.89 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M2577.17 1767.34 Q2573.56 1767.34 2571.73 1770.9 Q2569.93 1774.45 2569.93 1781.58 Q2569.93 1788.68 2571.73 1792.25 Q2573.56 1795.79 2577.17 1795.79 Q2580.81 1795.79 2582.61 1792.25 Q2584.44 1788.68 2584.44 1781.58 Q2584.44 1774.45 2582.61 1770.9 Q2580.81 1767.34 2577.17 1767.34 M2577.17 1763.64 Q2582.98 1763.64 2586.04 1768.24 Q2589.12 1772.83 2589.12 1781.58 Q2589.12 1790.3 2586.04 1794.91 Q2582.98 1799.49 2577.17 1799.49 Q2571.36 1799.49 2568.29 1794.91 Q2565.23 1790.3 2565.23 1781.58 Q2565.23 1772.83 2568.29 1768.24 Q2571.36 1763.64 2577.17 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M2607.34 1767.34 Q2603.73 1767.34 2601.9 1770.9 Q2600.09 1774.45 2600.09 1781.58 Q2600.09 1788.68 2601.9 1792.25 Q2603.73 1795.79 2607.34 1795.79 Q2610.97 1795.79 2612.78 1792.25 Q2614.6 1788.68 2614.6 1781.58 Q2614.6 1774.45 2612.78 1770.9 Q2610.97 1767.34 2607.34 1767.34 M2607.34 1763.64 Q2613.15 1763.64 2616.2 1768.24 Q2619.28 1772.83 2619.28 1781.58 Q2619.28 1790.3 2616.2 1794.91 Q2613.15 1799.49 2607.34 1799.49 Q2601.53 1799.49 2598.45 1794.91 Q2595.39 1790.3 2595.39 1781.58 Q2595.39 1772.83 2598.45 1768.24 Q2601.53 1763.64 2607.34 1763.64 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M1535.48 1861.78 L1535.48 1883.3 L1529.62 1883.3 L1529.62 1861.98 Q1529.62 1856.92 1527.65 1854.4 Q1525.68 1851.89 1521.73 1851.89 Q1516.99 1851.89 1514.25 1854.91 Q1511.51 1857.93 1511.51 1863.15 L1511.51 1883.3 L1505.63 1883.3 L1505.63 1847.65 L1511.51 1847.65 L1511.51 1853.19 Q1513.61 1849.98 1516.45 1848.39 Q1519.31 1846.79 1523.04 1846.79 Q1529.18 1846.79 1532.33 1850.61 Q1535.48 1854.4 1535.48 1861.78 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><polyline clip-path="url(#clip412)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="400.35,1686.38 2640.76,1686.38 "></polyline>
<polyline clip-path="url(#clip412)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="400.35,1448.33 2640.76,1448.33 "></polyline>
<polyline clip-path="url(#clip412)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="400.35,1210.28 2640.76,1210.28 "></polyline>
<polyline clip-path="url(#clip412)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="400.35,972.231 2640.76,972.231 "></polyline>
<polyline clip-path="url(#clip412)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="400.35,734.183 2640.76,734.183 "></polyline>
<polyline clip-path="url(#clip412)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="400.35,496.134 2640.76,496.134 "></polyline>
<polyline clip-path="url(#clip412)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none" points="400.35,258.086 2640.76,258.086 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="400.35,1734.12 400.35,47.2441 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="400.35,1686.38 419.247,1686.38 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="400.35,1448.33 419.247,1448.33 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="400.35,1210.28 419.247,1210.28 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="400.35,972.231 419.247,972.231 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="400.35,734.183 419.247,734.183 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="400.35,496.134 419.247,496.134 "></polyline>
<polyline clip-path="url(#clip410)" style="stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none" points="400.35,258.086 419.247,258.086 "></polyline>
<path clip-path="url(#clip410)" d="M348.085 1672.17 Q344.474 1672.17 342.646 1675.74 Q340.84 1679.28 340.84 1686.41 Q340.84 1693.52 342.646 1697.08 Q344.474 1700.62 348.085 1700.62 Q351.72 1700.62 353.525 1697.08 Q355.354 1693.52 355.354 1686.41 Q355.354 1679.28 353.525 1675.74 Q351.72 1672.17 348.085 1672.17 M348.085 1668.47 Q353.895 1668.47 356.951 1673.08 Q360.03 1677.66 360.03 1686.41 Q360.03 1695.14 356.951 1699.74 Q353.895 1704.33 348.085 1704.33 Q342.275 1704.33 339.196 1699.74 Q336.141 1695.14 336.141 1686.41 Q336.141 1677.66 339.196 1673.08 Q342.275 1668.47 348.085 1668.47 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M119.779 1468.12 L127.418 1468.12 L127.418 1441.75 L119.108 1443.42 L119.108 1439.16 L127.372 1437.49 L132.048 1437.49 L132.048 1468.12 L139.687 1468.12 L139.687 1472.05 L119.779 1472.05 L119.779 1468.12 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M149.131 1466.18 L154.015 1466.18 L154.015 1472.05 L149.131 1472.05 L149.131 1466.18 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M174.2 1440.57 Q170.589 1440.57 168.76 1444.14 Q166.955 1447.68 166.955 1454.81 Q166.955 1461.92 168.76 1465.48 Q170.589 1469.02 174.2 1469.02 Q177.834 1469.02 179.64 1465.48 Q181.469 1461.92 181.469 1454.81 Q181.469 1447.68 179.64 1444.14 Q177.834 1440.57 174.2 1440.57 M174.2 1436.87 Q180.01 1436.87 183.066 1441.48 Q186.145 1446.06 186.145 1454.81 Q186.145 1463.54 183.066 1468.14 Q180.01 1472.73 174.2 1472.73 Q168.39 1472.73 165.311 1468.14 Q162.256 1463.54 162.256 1454.81 Q162.256 1446.06 165.311 1441.48 Q168.39 1436.87 174.2 1436.87 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M222.533 1446.59 L211.955 1457.22 L222.533 1467.8 L219.779 1470.6 L209.154 1459.97 L198.529 1470.6 L195.797 1467.8 L206.353 1457.22 L195.797 1446.59 L198.529 1443.79 L209.154 1454.42 L219.779 1443.79 L222.533 1446.59 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M234.894 1468.12 L242.533 1468.12 L242.533 1441.75 L234.223 1443.42 L234.223 1439.16 L242.487 1437.49 L247.163 1437.49 L247.163 1468.12 L254.802 1468.12 L254.802 1472.05 L234.894 1472.05 L234.894 1468.12 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M274.246 1440.57 Q270.635 1440.57 268.806 1444.14 Q267.001 1447.68 267.001 1454.81 Q267.001 1461.92 268.806 1465.48 Q270.635 1469.02 274.246 1469.02 Q277.88 1469.02 279.686 1465.48 Q281.514 1461.92 281.514 1454.81 Q281.514 1447.68 279.686 1444.14 Q277.88 1440.57 274.246 1440.57 M274.246 1436.87 Q280.056 1436.87 283.112 1441.48 Q286.19 1446.06 286.19 1454.81 Q286.19 1463.54 283.112 1468.14 Q280.056 1472.73 274.246 1472.73 Q268.436 1472.73 265.357 1468.14 Q262.302 1463.54 262.302 1454.81 Q262.302 1446.06 265.357 1441.48 Q268.436 1436.87 274.246 1436.87 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M286.19 1430.97 L310.302 1430.97 L310.302 1434.17 L286.19 1434.17 L286.19 1430.97 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M319.16 1441.45 L325.367 1441.45 L325.367 1420.02 L318.615 1421.38 L318.615 1417.92 L325.329 1416.56 L329.129 1416.56 L329.129 1441.45 L335.335 1441.45 L335.335 1444.64 L319.16 1444.64 L319.16 1441.45 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M343.046 1416.56 L357.961 1416.56 L357.961 1419.76 L346.526 1419.76 L346.526 1426.65 Q347.353 1426.36 348.181 1426.23 Q349.008 1426.08 349.836 1426.08 Q354.538 1426.08 357.284 1428.66 Q360.03 1431.23 360.03 1435.64 Q360.03 1440.17 357.209 1442.69 Q354.387 1445.19 349.253 1445.19 Q347.485 1445.19 345.642 1444.89 Q343.817 1444.59 341.861 1443.99 L341.861 1440.17 Q343.554 1441.09 345.36 1441.54 Q347.165 1441.99 349.178 1441.99 Q352.431 1441.99 354.331 1440.28 Q356.231 1438.57 356.231 1435.64 Q356.231 1432.7 354.331 1430.99 Q352.431 1429.28 349.178 1429.28 Q347.654 1429.28 346.131 1429.62 Q344.626 1429.96 343.046 1430.67 L343.046 1416.56 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M122.997 1230.07 L139.316 1230.07 L139.316 1234.01 L117.372 1234.01 L117.372 1230.07 Q120.034 1227.32 124.617 1222.69 Q129.224 1218.03 130.404 1216.69 Q132.65 1214.17 133.529 1212.43 Q134.432 1210.67 134.432 1208.98 Q134.432 1206.23 132.488 1204.49 Q130.566 1202.76 127.464 1202.76 Q125.265 1202.76 122.812 1203.52 Q120.381 1204.28 117.603 1205.84 L117.603 1201.11 Q120.427 1199.98 122.881 1199.4 Q125.335 1198.82 127.372 1198.82 Q132.742 1198.82 135.937 1201.51 Q139.131 1204.19 139.131 1208.68 Q139.131 1210.81 138.321 1212.73 Q137.534 1214.63 135.427 1217.22 Q134.849 1217.9 131.747 1221.11 Q128.645 1224.31 122.997 1230.07 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M149.131 1228.13 L154.015 1228.13 L154.015 1234.01 L149.131 1234.01 L149.131 1228.13 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M174.2 1202.53 Q170.589 1202.53 168.76 1206.09 Q166.955 1209.63 166.955 1216.76 Q166.955 1223.87 168.76 1227.43 Q170.589 1230.97 174.2 1230.97 Q177.834 1230.97 179.64 1227.43 Q181.469 1223.87 181.469 1216.76 Q181.469 1209.63 179.64 1206.09 Q177.834 1202.53 174.2 1202.53 M174.2 1198.82 Q180.01 1198.82 183.066 1203.43 Q186.145 1208.01 186.145 1216.76 Q186.145 1225.49 183.066 1230.09 Q180.01 1234.68 174.2 1234.68 Q168.39 1234.68 165.311 1230.09 Q162.256 1225.49 162.256 1216.76 Q162.256 1208.01 165.311 1203.43 Q168.39 1198.82 174.2 1198.82 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M222.533 1208.54 L211.955 1219.17 L222.533 1229.75 L219.779 1232.55 L209.154 1221.92 L198.529 1232.55 L195.797 1229.75 L206.353 1219.17 L195.797 1208.54 L198.529 1205.74 L209.154 1216.37 L219.779 1205.74 L222.533 1208.54 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M234.894 1230.07 L242.533 1230.07 L242.533 1203.71 L234.223 1205.37 L234.223 1201.11 L242.487 1199.45 L247.163 1199.45 L247.163 1230.07 L254.802 1230.07 L254.802 1234.01 L234.894 1234.01 L234.894 1230.07 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M274.246 1202.53 Q270.635 1202.53 268.806 1206.09 Q267.001 1209.63 267.001 1216.76 Q267.001 1223.87 268.806 1227.43 Q270.635 1230.97 274.246 1230.97 Q277.88 1230.97 279.686 1227.43 Q281.514 1223.87 281.514 1216.76 Q281.514 1209.63 279.686 1206.09 Q277.88 1202.53 274.246 1202.53 M274.246 1198.82 Q280.056 1198.82 283.112 1203.43 Q286.19 1208.01 286.19 1216.76 Q286.19 1225.49 283.112 1230.09 Q280.056 1234.68 274.246 1234.68 Q268.436 1234.68 265.357 1230.09 Q262.302 1225.49 262.302 1216.76 Q262.302 1208.01 265.357 1203.43 Q268.436 1198.82 274.246 1198.82 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M286.19 1192.92 L310.302 1192.92 L310.302 1196.12 L286.19 1196.12 L286.19 1192.92 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M319.16 1203.4 L325.367 1203.4 L325.367 1181.98 L318.615 1183.33 L318.615 1179.87 L325.329 1178.52 L329.129 1178.52 L329.129 1203.4 L335.335 1203.4 L335.335 1206.6 L319.16 1206.6 L319.16 1203.4 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M343.046 1178.52 L357.961 1178.52 L357.961 1181.71 L346.526 1181.71 L346.526 1188.6 Q347.353 1188.31 348.181 1188.18 Q349.008 1188.03 349.836 1188.03 Q354.538 1188.03 357.284 1190.61 Q360.03 1193.19 360.03 1197.59 Q360.03 1202.12 357.209 1204.64 Q354.387 1207.14 349.253 1207.14 Q347.485 1207.14 345.642 1206.84 Q343.817 1206.54 341.861 1205.94 L341.861 1202.12 Q343.554 1203.04 345.36 1203.49 Q347.165 1203.94 349.178 1203.94 Q352.431 1203.94 354.331 1202.23 Q356.231 1200.52 356.231 1197.59 Q356.231 1194.65 354.331 1192.94 Q352.431 1191.23 349.178 1191.23 Q347.654 1191.23 346.131 1191.57 Q344.626 1191.91 343.046 1192.62 L343.046 1178.52 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M133.136 977.324 Q136.492 978.042 138.367 980.31 Q140.265 982.579 140.265 985.912 Q140.265 991.028 136.747 993.829 Q133.228 996.63 126.747 996.63 Q124.571 996.63 122.256 996.19 Q119.964 995.773 117.511 994.917 L117.511 990.403 Q119.455 991.537 121.77 992.116 Q124.085 992.694 126.608 992.694 Q131.006 992.694 133.298 990.958 Q135.612 989.222 135.612 985.912 Q135.612 982.857 133.46 981.144 Q131.33 979.407 127.511 979.407 L123.483 979.407 L123.483 975.565 L127.696 975.565 Q131.145 975.565 132.974 974.199 Q134.802 972.81 134.802 970.218 Q134.802 967.556 132.904 966.144 Q131.029 964.708 127.511 964.708 Q125.589 964.708 123.39 965.125 Q121.191 965.542 118.552 966.421 L118.552 962.255 Q121.214 961.514 123.529 961.144 Q125.867 960.773 127.927 960.773 Q133.251 960.773 136.353 963.204 Q139.455 965.611 139.455 969.732 Q139.455 972.602 137.812 974.593 Q136.168 976.56 133.136 977.324 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M149.131 990.079 L154.015 990.079 L154.015 995.958 L149.131 995.958 L149.131 990.079 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M174.2 964.477 Q170.589 964.477 168.76 968.042 Q166.955 971.583 166.955 978.713 Q166.955 985.819 168.76 989.384 Q170.589 992.926 174.2 992.926 Q177.834 992.926 179.64 989.384 Q181.469 985.819 181.469 978.713 Q181.469 971.583 179.64 968.042 Q177.834 964.477 174.2 964.477 M174.2 960.773 Q180.01 960.773 183.066 965.38 Q186.145 969.963 186.145 978.713 Q186.145 987.44 183.066 992.046 Q180.01 996.63 174.2 996.63 Q168.39 996.63 165.311 992.046 Q162.256 987.44 162.256 978.713 Q162.256 969.963 165.311 965.38 Q168.39 960.773 174.2 960.773 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M222.533 970.495 L211.955 981.12 L222.533 991.699 L219.779 994.5 L209.154 983.875 L198.529 994.5 L195.797 991.699 L206.353 981.12 L195.797 970.495 L198.529 967.695 L209.154 978.32 L219.779 967.695 L222.533 970.495 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M234.894 992.023 L242.533 992.023 L242.533 965.658 L234.223 967.324 L234.223 963.065 L242.487 961.398 L247.163 961.398 L247.163 992.023 L254.802 992.023 L254.802 995.958 L234.894 995.958 L234.894 992.023 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M274.246 964.477 Q270.635 964.477 268.806 968.042 Q267.001 971.583 267.001 978.713 Q267.001 985.819 268.806 989.384 Q270.635 992.926 274.246 992.926 Q277.88 992.926 279.686 989.384 Q281.514 985.819 281.514 978.713 Q281.514 971.583 279.686 968.042 Q277.88 964.477 274.246 964.477 M274.246 960.773 Q280.056 960.773 283.112 965.38 Q286.19 969.963 286.19 978.713 Q286.19 987.44 283.112 992.046 Q280.056 996.63 274.246 996.63 Q268.436 996.63 265.357 992.046 Q262.302 987.44 262.302 978.713 Q262.302 969.963 265.357 965.38 Q268.436 960.773 274.246 960.773 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M286.19 954.875 L310.302 954.875 L310.302 958.072 L286.19 958.072 L286.19 954.875 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M319.16 965.351 L325.367 965.351 L325.367 943.929 L318.615 945.283 L318.615 941.822 L325.329 940.468 L329.129 940.468 L329.129 965.351 L335.335 965.351 L335.335 968.548 L319.16 968.548 L319.16 965.351 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M343.046 940.468 L357.961 940.468 L357.961 943.665 L346.526 943.665 L346.526 950.549 Q347.353 950.267 348.181 950.135 Q349.008 949.985 349.836 949.985 Q354.538 949.985 357.284 952.561 Q360.03 955.138 360.03 959.539 Q360.03 964.072 357.209 966.592 Q354.387 969.093 349.253 969.093 Q347.485 969.093 345.642 968.792 Q343.817 968.491 341.861 967.89 L341.861 964.072 Q343.554 964.993 345.36 965.445 Q347.165 965.896 349.178 965.896 Q352.431 965.896 354.331 964.185 Q356.231 962.473 356.231 959.539 Q356.231 956.605 354.331 954.893 Q352.431 953.182 349.178 953.182 Q347.654 953.182 346.131 953.521 Q344.626 953.859 343.046 954.574 L343.046 940.468 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M131.816 727.424 L120.011 745.873 L131.816 745.873 L131.816 727.424 M130.589 723.35 L136.469 723.35 L136.469 745.873 L141.399 745.873 L141.399 749.762 L136.469 749.762 L136.469 757.91 L131.816 757.91 L131.816 749.762 L116.214 749.762 L116.214 745.248 L130.589 723.35 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M149.131 752.031 L154.015 752.031 L154.015 757.91 L149.131 757.91 L149.131 752.031 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M174.2 726.429 Q170.589 726.429 168.76 729.994 Q166.955 733.535 166.955 740.665 Q166.955 747.771 168.76 751.336 Q170.589 754.878 174.2 754.878 Q177.834 754.878 179.64 751.336 Q181.469 747.771 181.469 740.665 Q181.469 733.535 179.64 729.994 Q177.834 726.429 174.2 726.429 M174.2 722.725 Q180.01 722.725 183.066 727.332 Q186.145 731.915 186.145 740.665 Q186.145 749.392 183.066 753.998 Q180.01 758.581 174.2 758.581 Q168.39 758.581 165.311 753.998 Q162.256 749.392 162.256 740.665 Q162.256 731.915 165.311 727.332 Q168.39 722.725 174.2 722.725 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M222.533 732.447 L211.955 743.072 L222.533 753.651 L219.779 756.452 L209.154 745.827 L198.529 756.452 L195.797 753.651 L206.353 743.072 L195.797 732.447 L198.529 729.646 L209.154 740.271 L219.779 729.646 L222.533 732.447 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M234.894 753.975 L242.533 753.975 L242.533 727.609 L234.223 729.276 L234.223 725.017 L242.487 723.35 L247.163 723.35 L247.163 753.975 L254.802 753.975 L254.802 757.91 L234.894 757.91 L234.894 753.975 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M274.246 726.429 Q270.635 726.429 268.806 729.994 Q267.001 733.535 267.001 740.665 Q267.001 747.771 268.806 751.336 Q270.635 754.878 274.246 754.878 Q277.88 754.878 279.686 751.336 Q281.514 747.771 281.514 740.665 Q281.514 733.535 279.686 729.994 Q277.88 726.429 274.246 726.429 M274.246 722.725 Q280.056 722.725 283.112 727.332 Q286.19 731.915 286.19 740.665 Q286.19 749.392 283.112 753.998 Q280.056 758.581 274.246 758.581 Q268.436 758.581 265.357 753.998 Q262.302 749.392 262.302 740.665 Q262.302 731.915 265.357 727.332 Q268.436 722.725 274.246 722.725 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M286.19 716.826 L310.302 716.826 L310.302 720.024 L286.19 720.024 L286.19 716.826 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M319.16 727.302 L325.367 727.302 L325.367 705.88 L318.615 707.235 L318.615 703.774 L325.329 702.42 L329.129 702.42 L329.129 727.302 L335.335 727.302 L335.335 730.5 L319.16 730.5 L319.16 727.302 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M343.046 702.42 L357.961 702.42 L357.961 705.617 L346.526 705.617 L346.526 712.501 Q347.353 712.219 348.181 712.087 Q349.008 711.936 349.836 711.936 Q354.538 711.936 357.284 714.513 Q360.03 717.09 360.03 721.491 Q360.03 726.023 357.209 728.544 Q354.387 731.045 349.253 731.045 Q347.485 731.045 345.642 730.744 Q343.817 730.443 341.861 729.841 L341.861 726.023 Q343.554 726.945 345.36 727.396 Q347.165 727.848 349.178 727.848 Q352.431 727.848 354.331 726.136 Q356.231 724.425 356.231 721.491 Q356.231 718.557 354.331 716.845 Q352.431 715.134 349.178 715.134 Q347.654 715.134 346.131 715.472 Q344.626 715.811 343.046 716.526 L343.046 702.42 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M119.015 485.302 L137.372 485.302 L137.372 489.237 L123.298 489.237 L123.298 497.709 Q124.316 497.362 125.335 497.2 Q126.353 497.015 127.372 497.015 Q133.159 497.015 136.538 500.186 Q139.918 503.357 139.918 508.774 Q139.918 514.353 136.446 517.455 Q132.974 520.533 126.654 520.533 Q124.478 520.533 122.21 520.163 Q119.964 519.792 117.557 519.052 L117.557 514.353 Q119.64 515.487 121.863 516.043 Q124.085 516.598 126.562 516.598 Q130.566 516.598 132.904 514.492 Q135.242 512.385 135.242 508.774 Q135.242 505.163 132.904 503.056 Q130.566 500.95 126.562 500.95 Q124.687 500.95 122.812 501.367 Q120.96 501.783 119.015 502.663 L119.015 485.302 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M149.131 513.982 L154.015 513.982 L154.015 519.862 L149.131 519.862 L149.131 513.982 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M174.2 488.381 Q170.589 488.381 168.76 491.945 Q166.955 495.487 166.955 502.617 Q166.955 509.723 168.76 513.288 Q170.589 516.83 174.2 516.83 Q177.834 516.83 179.64 513.288 Q181.469 509.723 181.469 502.617 Q181.469 495.487 179.64 491.945 Q177.834 488.381 174.2 488.381 M174.2 484.677 Q180.01 484.677 183.066 489.283 Q186.145 493.867 186.145 502.617 Q186.145 511.343 183.066 515.95 Q180.01 520.533 174.2 520.533 Q168.39 520.533 165.311 515.95 Q162.256 511.343 162.256 502.617 Q162.256 493.867 165.311 489.283 Q168.39 484.677 174.2 484.677 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M222.533 494.399 L211.955 505.024 L222.533 515.603 L219.779 518.404 L209.154 507.779 L198.529 518.404 L195.797 515.603 L206.353 505.024 L195.797 494.399 L198.529 491.598 L209.154 502.223 L219.779 491.598 L222.533 494.399 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M234.894 515.927 L242.533 515.927 L242.533 489.561 L234.223 491.228 L234.223 486.969 L242.487 485.302 L247.163 485.302 L247.163 515.927 L254.802 515.927 L254.802 519.862 L234.894 519.862 L234.894 515.927 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M274.246 488.381 Q270.635 488.381 268.806 491.945 Q267.001 495.487 267.001 502.617 Q267.001 509.723 268.806 513.288 Q270.635 516.83 274.246 516.83 Q277.88 516.83 279.686 513.288 Q281.514 509.723 281.514 502.617 Q281.514 495.487 279.686 491.945 Q277.88 488.381 274.246 488.381 M274.246 484.677 Q280.056 484.677 283.112 489.283 Q286.19 493.867 286.19 502.617 Q286.19 511.343 283.112 515.95 Q280.056 520.533 274.246 520.533 Q268.436 520.533 265.357 515.95 Q262.302 511.343 262.302 502.617 Q262.302 493.867 265.357 489.283 Q268.436 484.677 274.246 484.677 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M286.19 478.778 L310.302 478.778 L310.302 481.976 L286.19 481.976 L286.19 478.778 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M319.16 489.254 L325.367 489.254 L325.367 467.832 L318.615 469.186 L318.615 465.726 L325.329 464.372 L329.129 464.372 L329.129 489.254 L335.335 489.254 L335.335 492.452 L319.16 492.452 L319.16 489.254 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M343.046 464.372 L357.961 464.372 L357.961 467.569 L346.526 467.569 L346.526 474.452 Q347.353 474.17 348.181 474.039 Q349.008 473.888 349.836 473.888 Q354.538 473.888 357.284 476.465 Q360.03 479.042 360.03 483.443 Q360.03 487.975 357.209 490.496 Q354.387 492.997 349.253 492.997 Q347.485 492.997 345.642 492.696 Q343.817 492.395 341.861 491.793 L341.861 487.975 Q343.554 488.897 345.36 489.348 Q347.165 489.8 349.178 489.8 Q352.431 489.8 354.331 488.088 Q356.231 486.377 356.231 483.443 Q356.231 480.509 354.331 478.797 Q352.431 477.086 349.178 477.086 Q347.654 477.086 346.131 477.424 Q344.626 477.763 343.046 478.477 L343.046 464.372 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M129.548 262.67 Q126.4 262.67 124.548 264.823 Q122.719 266.976 122.719 270.726 Q122.719 274.453 124.548 276.629 Q126.4 278.781 129.548 278.781 Q132.696 278.781 134.525 276.629 Q136.376 274.453 136.376 270.726 Q136.376 266.976 134.525 264.823 Q132.696 262.67 129.548 262.67 M138.83 248.018 L138.83 252.277 Q137.071 251.444 135.265 251.004 Q133.483 250.564 131.724 250.564 Q127.094 250.564 124.64 253.689 Q122.21 256.814 121.863 263.133 Q123.228 261.119 125.288 260.055 Q127.349 258.967 129.825 258.967 Q135.034 258.967 138.043 262.138 Q141.075 265.286 141.075 270.726 Q141.075 276.05 137.927 279.267 Q134.779 282.485 129.548 282.485 Q123.552 282.485 120.381 277.902 Q117.21 273.295 117.21 264.568 Q117.21 256.374 121.099 251.513 Q124.988 246.629 131.538 246.629 Q133.298 246.629 135.08 246.976 Q136.886 247.323 138.83 248.018 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M149.131 275.934 L154.015 275.934 L154.015 281.814 L149.131 281.814 L149.131 275.934 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M174.2 250.332 Q170.589 250.332 168.76 253.897 Q166.955 257.439 166.955 264.568 Q166.955 271.675 168.76 275.24 Q170.589 278.781 174.2 278.781 Q177.834 278.781 179.64 275.24 Q181.469 271.675 181.469 264.568 Q181.469 257.439 179.64 253.897 Q177.834 250.332 174.2 250.332 M174.2 246.629 Q180.01 246.629 183.066 251.235 Q186.145 255.819 186.145 264.568 Q186.145 273.295 183.066 277.902 Q180.01 282.485 174.2 282.485 Q168.39 282.485 165.311 277.902 Q162.256 273.295 162.256 264.568 Q162.256 255.819 165.311 251.235 Q168.39 246.629 174.2 246.629 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M222.533 256.351 L211.955 266.976 L222.533 277.554 L219.779 280.355 L209.154 269.73 L198.529 280.355 L195.797 277.554 L206.353 266.976 L195.797 256.351 L198.529 253.55 L209.154 264.175 L219.779 253.55 L222.533 256.351 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M234.894 277.879 L242.533 277.879 L242.533 251.513 L234.223 253.18 L234.223 248.92 L242.487 247.254 L247.163 247.254 L247.163 277.879 L254.802 277.879 L254.802 281.814 L234.894 281.814 L234.894 277.879 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M274.246 250.332 Q270.635 250.332 268.806 253.897 Q267.001 257.439 267.001 264.568 Q267.001 271.675 268.806 275.24 Q270.635 278.781 274.246 278.781 Q277.88 278.781 279.686 275.24 Q281.514 271.675 281.514 264.568 Q281.514 257.439 279.686 253.897 Q277.88 250.332 274.246 250.332 M274.246 246.629 Q280.056 246.629 283.112 251.235 Q286.19 255.819 286.19 264.568 Q286.19 273.295 283.112 277.902 Q280.056 282.485 274.246 282.485 Q268.436 282.485 265.357 277.902 Q262.302 273.295 262.302 264.568 Q262.302 255.819 265.357 251.235 Q268.436 246.629 274.246 246.629 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M286.19 240.73 L310.302 240.73 L310.302 243.927 L286.19 243.927 L286.19 240.73 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M319.16 251.206 L325.367 251.206 L325.367 229.784 L318.615 231.138 L318.615 227.677 L325.329 226.323 L329.129 226.323 L329.129 251.206 L335.335 251.206 L335.335 254.403 L319.16 254.403 L319.16 251.206 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M343.046 226.323 L357.961 226.323 L357.961 229.521 L346.526 229.521 L346.526 236.404 Q347.353 236.122 348.181 235.991 Q349.008 235.84 349.836 235.84 Q354.538 235.84 357.284 238.417 Q360.03 240.993 360.03 245.394 Q360.03 249.927 357.209 252.447 Q354.387 254.949 349.253 254.949 Q347.485 254.949 345.642 254.648 Q343.817 254.347 341.861 253.745 L341.861 249.927 Q343.554 250.849 345.36 251.3 Q347.165 251.751 349.178 251.751 Q352.431 251.751 354.331 250.04 Q356.231 248.328 356.231 245.394 Q356.231 242.46 354.331 240.749 Q352.431 239.037 349.178 239.037 Q347.654 239.037 346.131 239.376 Q344.626 239.714 343.046 240.429 L343.046 226.323 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M31.465 1162.51 Q30.8921 1163.5 30.6375 1164.68 Q30.351 1165.82 30.351 1167.22 Q30.351 1172.19 33.5975 1174.86 Q36.8122 1177.5 42.8596 1177.5 L61.6384 1177.5 L61.6384 1183.39 L25.9905 1183.39 L25.9905 1177.5 L31.5287 1177.5 Q28.2821 1175.66 26.7225 1172.7 Q25.1311 1169.74 25.1311 1165.5 Q25.1311 1164.9 25.2266 1164.17 Q25.2903 1163.44 25.4494 1162.54 L31.465 1162.51 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M42.3504 1127.31 L45.2149 1127.31 L45.2149 1154.24 Q51.2623 1153.85 54.4452 1150.61 Q57.5962 1147.33 57.5962 1141.51 Q57.5962 1138.13 56.7687 1134.98 Q55.9411 1131.8 54.2861 1128.68 L59.8242 1128.68 Q61.161 1131.83 61.8612 1135.14 Q62.5615 1138.45 62.5615 1141.86 Q62.5615 1150.39 57.5962 1155.38 Q52.631 1160.35 44.1646 1160.35 Q35.4117 1160.35 30.2873 1155.64 Q25.1311 1150.89 25.1311 1142.87 Q25.1311 1135.68 29.7781 1131.51 Q34.3932 1127.31 42.3504 1127.31 M40.6316 1133.17 Q35.8255 1133.23 32.9609 1135.87 Q30.0964 1138.48 30.0964 1142.81 Q30.0964 1147.71 32.8654 1150.67 Q35.6345 1153.6 40.6634 1154.05 L40.6316 1133.17 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M12.1132 1117.7 L12.1132 1111.84 L61.6384 1111.84 L61.6384 1117.7 L12.1132 1117.7 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M43.719 1083.39 Q43.719 1090.48 45.3422 1093.22 Q46.9655 1095.96 50.8804 1095.96 Q53.9996 1095.96 55.8457 1093.92 Q57.6599 1091.85 57.6599 1088.32 Q57.6599 1083.45 54.2224 1080.52 Q50.7531 1077.56 45.0239 1077.56 L43.719 1077.56 L43.719 1083.39 M41.3 1071.71 L61.6384 1071.71 L61.6384 1077.56 L56.2276 1077.56 Q59.4741 1079.57 61.0337 1082.56 Q62.5615 1085.55 62.5615 1089.88 Q62.5615 1095.35 59.5059 1098.6 Q56.4186 1101.82 51.2623 1101.82 Q45.2467 1101.82 42.1912 1097.8 Q39.1357 1093.76 39.1357 1085.77 L39.1357 1077.56 L38.5628 1077.56 Q34.5205 1077.56 32.3244 1080.24 Q30.0964 1082.88 30.0964 1087.68 Q30.0964 1090.74 30.8284 1093.64 Q31.5605 1096.53 33.0246 1099.21 L27.6137 1099.21 Q26.3724 1095.99 25.7677 1092.97 Q25.1311 1089.94 25.1311 1087.08 Q25.1311 1079.34 29.1415 1075.52 Q33.1519 1071.71 41.3 1071.71 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M15.869 1053.85 L25.9905 1053.85 L25.9905 1041.79 L30.542 1041.79 L30.542 1053.85 L49.8937 1053.85 Q54.2542 1053.85 55.4955 1052.67 Q56.7368 1051.46 56.7368 1047.8 L56.7368 1041.79 L61.6384 1041.79 L61.6384 1047.8 Q61.6384 1054.58 59.124 1057.16 Q56.5777 1059.74 49.8937 1059.74 L30.542 1059.74 L30.542 1064.03 L25.9905 1064.03 L25.9905 1059.74 L15.869 1059.74 L15.869 1053.85 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M25.9905 1034.08 L25.9905 1028.23 L61.6384 1028.23 L61.6384 1034.08 L25.9905 1034.08 M12.1132 1034.08 L12.1132 1028.23 L19.5293 1028.23 L19.5293 1034.08 L12.1132 1034.08 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M25.9905 1020.17 L25.9905 1013.97 L55.9093 1002.83 L25.9905 991.688 L25.9905 985.482 L61.6384 998.85 L61.6384 1006.81 L25.9905 1020.17 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M42.3504 946.906 L45.2149 946.906 L45.2149 973.833 Q51.2623 973.451 54.4452 970.204 Q57.5962 966.926 57.5962 961.101 Q57.5962 957.727 56.7687 954.576 Q55.9411 951.393 54.2861 948.274 L59.8242 948.274 Q61.161 951.425 61.8612 954.735 Q62.5615 958.046 62.5615 961.451 Q62.5615 969.981 57.5962 974.978 Q52.631 979.944 44.1646 979.944 Q35.4117 979.944 30.2873 975.233 Q25.1311 970.491 25.1311 962.47 Q25.1311 955.277 29.7781 951.107 Q34.3932 946.906 42.3504 946.906 M40.6316 952.762 Q35.8255 952.826 32.9609 955.468 Q30.0964 958.077 30.0964 962.406 Q30.0964 967.308 32.8654 970.268 Q35.6345 973.196 40.6634 973.642 L40.6316 952.762 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M31.4013 893.115 L12.1132 893.115 L12.1132 887.259 L61.6384 887.259 L61.6384 893.115 L56.2912 893.115 Q59.4741 894.961 61.0337 897.794 Q62.5615 900.595 62.5615 904.542 Q62.5615 911.003 57.4052 915.077 Q52.249 919.119 43.8463 919.119 Q35.4436 919.119 30.2873 915.077 Q25.1311 911.003 25.1311 904.542 Q25.1311 900.595 26.6907 897.794 Q28.2185 894.961 31.4013 893.115 M43.8463 913.072 Q50.3075 913.072 53.9996 910.43 Q57.6599 907.757 57.6599 903.11 Q57.6599 898.463 53.9996 895.789 Q50.3075 893.115 43.8463 893.115 Q37.3851 893.115 33.7248 895.789 Q30.0327 898.463 30.0327 903.11 Q30.0327 907.757 33.7248 910.43 Q37.3851 913.072 43.8463 913.072 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M25.9905 875.196 L25.9905 869.34 L61.6384 869.34 L61.6384 875.196 L25.9905 875.196 M12.1132 875.196 L12.1132 869.34 L19.5293 869.34 L19.5293 875.196 L12.1132 875.196 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M12.1132 839.039 L16.983 839.039 L16.983 844.641 Q16.983 847.792 18.2562 849.033 Q19.5293 850.242 22.8395 850.242 L25.9905 850.242 L25.9905 840.598 L30.542 840.598 L30.542 850.242 L61.6384 850.242 L61.6384 856.131 L30.542 856.131 L30.542 861.732 L25.9905 861.732 L25.9905 856.131 L23.5079 856.131 Q17.5559 856.131 14.8505 853.362 Q12.1132 850.593 12.1132 844.577 L12.1132 839.039 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M12.1132 816.09 L16.983 816.09 L16.983 821.692 Q16.983 824.843 18.2562 826.085 Q19.5293 827.294 22.8395 827.294 L25.9905 827.294 L25.9905 817.65 L30.542 817.65 L30.542 827.294 L61.6384 827.294 L61.6384 833.182 L30.542 833.182 L30.542 838.784 L25.9905 838.784 L25.9905 833.182 L23.5079 833.182 Q17.5559 833.182 14.8505 830.413 Q12.1132 827.644 12.1132 821.629 L12.1132 816.09 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M42.3504 780.697 L45.2149 780.697 L45.2149 807.624 Q51.2623 807.242 54.4452 803.996 Q57.5962 800.717 57.5962 794.893 Q57.5962 791.519 56.7687 788.368 Q55.9411 785.185 54.2861 782.066 L59.8242 782.066 Q61.161 785.217 61.8612 788.527 Q62.5615 791.837 62.5615 795.243 Q62.5615 803.773 57.5962 808.77 Q52.631 813.735 44.1646 813.735 Q35.4117 813.735 30.2873 809.024 Q25.1311 804.282 25.1311 796.261 Q25.1311 789.068 29.7781 784.898 Q34.3932 780.697 42.3504 780.697 M40.6316 786.553 Q35.8255 786.617 32.9609 789.259 Q30.0964 791.869 30.0964 796.198 Q30.0964 801.099 32.8654 804.059 Q35.6345 806.987 40.6634 807.433 L40.6316 786.553 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M31.465 750.428 Q30.8921 751.415 30.6375 752.592 Q30.351 753.738 30.351 755.139 Q30.351 760.104 33.5975 762.778 Q36.8122 765.419 42.8596 765.419 L61.6384 765.419 L61.6384 771.308 L25.9905 771.308 L25.9905 765.419 L31.5287 765.419 Q28.2821 763.573 26.7225 760.613 Q25.1311 757.653 25.1311 753.42 Q25.1311 752.815 25.2266 752.083 Q25.2903 751.351 25.4494 750.46 L31.465 750.428 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M42.3504 715.226 L45.2149 715.226 L45.2149 742.153 Q51.2623 741.771 54.4452 738.524 Q57.5962 735.246 57.5962 729.421 Q57.5962 726.047 56.7687 722.896 Q55.9411 719.714 54.2861 716.594 L59.8242 716.594 Q61.161 719.745 61.8612 723.056 Q62.5615 726.366 62.5615 729.771 Q62.5615 738.301 57.5962 743.299 Q52.631 748.264 44.1646 748.264 Q35.4117 748.264 30.2873 743.553 Q25.1311 738.811 25.1311 730.79 Q25.1311 723.597 29.7781 719.427 Q34.3932 715.226 42.3504 715.226 M40.6316 721.082 Q35.8255 721.146 32.9609 723.788 Q30.0964 726.398 30.0964 730.726 Q30.0964 735.628 32.8654 738.588 Q35.6345 741.516 40.6634 741.962 L40.6316 721.082 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M40.1224 675.981 L61.6384 675.981 L61.6384 681.838 L40.3133 681.838 Q35.2526 681.838 32.7381 683.811 Q30.2237 685.784 30.2237 689.731 Q30.2237 694.474 33.2474 697.211 Q36.2711 699.948 41.491 699.948 L61.6384 699.948 L61.6384 705.836 L25.9905 705.836 L25.9905 699.948 L31.5287 699.948 Q28.314 697.847 26.7225 695.015 Q25.1311 692.15 25.1311 688.426 Q25.1311 682.283 28.9505 679.132 Q32.7381 675.981 40.1224 675.981 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M27.3591 638.646 L32.8336 638.646 Q31.465 641.129 30.7966 643.643 Q30.0964 646.126 30.0964 648.672 Q30.0964 654.37 33.7248 657.521 Q37.3214 660.672 43.8463 660.672 Q50.3711 660.672 53.9996 657.521 Q57.5962 654.37 57.5962 648.672 Q57.5962 646.126 56.9278 643.643 Q56.2276 641.129 54.859 638.646 L60.2698 638.646 Q61.4156 641.097 61.9886 643.739 Q62.5615 646.349 62.5615 649.309 Q62.5615 657.361 57.5007 662.104 Q52.44 666.846 43.8463 666.846 Q35.1253 666.846 30.1282 662.072 Q25.1311 657.266 25.1311 648.927 Q25.1311 646.221 25.704 643.643 Q26.2451 641.065 27.3591 638.646 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><path clip-path="url(#clip410)" d="M42.3504 597.969 L45.2149 597.969 L45.2149 624.896 Q51.2623 624.514 54.4452 621.268 Q57.5962 617.99 57.5962 612.165 Q57.5962 608.791 56.7687 605.64 Q55.9411 602.457 54.2861 599.338 L59.8242 599.338 Q61.161 602.489 61.8612 605.799 Q62.5615 609.109 62.5615 612.515 Q62.5615 621.045 57.5962 626.042 Q52.631 631.007 44.1646 631.007 Q35.4117 631.007 30.2873 626.297 Q25.1311 621.554 25.1311 613.534 Q25.1311 606.34 29.7781 602.171 Q34.3932 597.969 42.3504 597.969 M40.6316 603.826 Q35.8255 603.89 32.9609 606.531 Q30.0964 609.141 30.0964 613.47 Q30.0964 618.372 32.8654 621.332 Q35.6345 624.26 40.6634 624.705 L40.6316 603.826 Z" fill="#000000" fill-rule="nonzero" fill-opacity="1"></path><circle clip-path="url(#clip412)" cx="463.757" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="474.378" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="485" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="495.621" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="506.242" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="516.863" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="527.484" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="538.105" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="548.726" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="559.347" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="569.968" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="580.589" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="591.21" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="601.831" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="612.452" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="623.073" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="633.694" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="644.315" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="654.936" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="665.558" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="676.179" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="686.8" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="697.421" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="708.042" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="718.663" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="729.284" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="739.905" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="750.526" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="761.147" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="771.768" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="782.389" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="793.01" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="803.631" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="814.252" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="824.873" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="835.494" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="846.116" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="856.737" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="867.358" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="877.979" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="888.6" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="899.221" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="909.842" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="920.463" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="931.084" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="941.705" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="952.326" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="962.947" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="973.568" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="984.189" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="994.81" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1005.43" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1016.05" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1026.67" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1037.29" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1047.92" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1058.54" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1069.16" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1079.78" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1090.4" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1101.02" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1111.64" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1122.26" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1132.88" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1143.51" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1154.13" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1164.75" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1175.37" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1185.99" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1196.61" cy="1686.38" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1207.23" cy="913.646" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1217.85" cy="1208.8" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1228.47" cy="1096.06" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1239.09" cy="1139.13" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1249.72" cy="1122.68" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1260.34" cy="1059.28" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1270.96" cy="1083.5" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1281.58" cy="1047.63" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1292.2" cy="1044.88" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1302.82" cy="1086.6" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1313.44" cy="1045.53" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1324.06" cy="1030.15" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1334.68" cy="1016.83" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1345.31" cy="998.189" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1355.93" cy="1005.31" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1366.55" cy="1002.59" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1377.17" cy="1026.04" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1387.79" cy="1003.23" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1398.41" cy="994.824" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1409.03" cy="976.876" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1419.65" cy="996.809" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1430.27" cy="973.031" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1440.89" cy="962.133" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1451.52" cy="966.296" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1462.14" cy="949.442" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1472.76" cy="918.146" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1483.38" cy="883.459" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1494" cy="911.121" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1504.62" cy="900.555" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1515.24" cy="882.57" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1525.86" cy="875.83" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1536.48" cy="861.582" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1547.11" cy="825.437" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1557.73" cy="826.392" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1568.35" cy="889.567" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1578.97" cy="806.531" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1589.59" cy="850.383" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1600.21" cy="818.634" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1610.83" cy="812.22" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1621.45" cy="837.587" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1632.07" cy="785.406" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1642.69" cy="805.338" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1653.32" cy="797.725" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1663.94" cy="787.258" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1674.56" cy="791.256" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1685.18" cy="748.86" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1695.8" cy="752.425" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1706.42" cy="719.842" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1717.04" cy="751.583" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1727.66" cy="751.384" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1738.28" cy="736.72" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1748.91" cy="742.321" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1759.53" cy="740.182" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1770.15" cy="727.08" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1780.77" cy="680.469" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1791.39" cy="666.373" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1802.01" cy="711.188" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1812.63" cy="677.824" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1823.25" cy="630.323" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1833.87" cy="673.289" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1844.5" cy="641.537" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1855.12" cy="634.703" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1865.74" cy="649.032" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1876.36" cy="629.073" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1886.98" cy="582.98" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1897.6" cy="622.719" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1908.22" cy="593.861" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1918.84" cy="604.884" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1929.46" cy="569.325" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1940.08" cy="582.907" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1950.71" cy="577.719" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1961.33" cy="559.966" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1971.95" cy="578.944" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1982.57" cy="541.544" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="1993.19" cy="537.194" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2003.81" cy="527.339" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2014.43" cy="474.161" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2025.05" cy="494.473" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2035.67" cy="530.215" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2046.3" cy="476.236" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2056.92" cy="463.623" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2067.54" cy="468.44" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2078.16" cy="479.293" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2088.78" cy="475.148" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2099.4" cy="457.338" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2110.02" cy="428.183" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2120.64" cy="439.319" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2131.26" cy="416.753" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2141.88" cy="402.737" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2152.51" cy="436.07" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2163.13" cy="371.461" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2173.75" cy="417.514" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2184.37" cy="426.343" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2194.99" cy="357.657" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2205.61" cy="383.893" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2216.23" cy="336.45" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2226.85" cy="339.153" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2237.47" cy="338.12" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2248.1" cy="338.515" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2258.72" cy="309.245" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2269.34" cy="320.425" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2279.96" cy="293.91" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2290.58" cy="304.038" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2301.2" cy="300.17" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2311.82" cy="280.642" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2322.44" cy="275.119" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2333.06" cy="293.275" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2343.68" cy="266.506" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2354.31" cy="276.731" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2364.93" cy="257.673" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2375.55" cy="227.494" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2386.17" cy="239.022" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2396.79" cy="234.619" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2407.41" cy="218.615" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2418.03" cy="224.728" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2428.65" cy="235.903" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2439.27" cy="214.935" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2449.9" cy="191.981" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2460.52" cy="162.476" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2471.14" cy="173.746" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2481.76" cy="149.95" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2492.38" cy="171.086" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2503" cy="148.122" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2513.62" cy="120.082" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2524.24" cy="142.168" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2534.86" cy="105.611" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2545.49" cy="136.954" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2556.11" cy="124.982" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2566.73" cy="103.001" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
<circle clip-path="url(#clip412)" cx="2577.35" cy="94.9858" r="14.4" fill="#009af9" fill-rule="evenodd" fill-opacity="1" stroke="#000000" stroke-opacity="1" stroke-width="3.84"></circle>
</svg>
</div>
</div>
<blockquote class="blockquote">
<p><strong>Figure 2.</strong> Relative difference between the Fibonacci numbers obtained using <code>fib_binet()</code> and those obtained using <code>fib_memo()</code>.</p>
</blockquote>


</section>

 ]]></description>
  <category>Julia</category>
  <guid>https://janhove.github.io/posts/2022-12-20-julia-fibonacci/</guid>
  <pubDate>Tue, 20 Dec 2022 00:00:00 GMT</pubDate>
  <media:content url="https://janhove.github.io/posts/2022-12-20-julia-fibonacci/image.png" medium="image" type="image/png" height="101" width="144"/>
</item>
<item>
  <title>In research, don’t do things you don’t see the point of</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2022-02-18-dont-do-things-you-dont-see-the-point-of/</link>
  <description><![CDATA[ 




<p>When I started reading quantitative research reports, I hadn’t taken any methods or statistics classes, so small wonder that I didn’t understand why certain background variables on the participants were collected, why it was reported how many of them were women and how many of them were men, and what all those numbers in the results sections meant. However, I was willing to assume that these reports had been written by some fairly intelligent people and that, by the Gricean <a href="https://en.wikipedia.org/wiki/Cooperative_principle#Maxim_of_relation_(relevance)">maxim of relevance</a>, these bits and bobs must be relevant — why else report them?</p>
<p>It’s now fifteen years later, and I still haven’t taken any methods or statistics classes. But, as you can tell from a quick glance at the blog archive, I’ve come round to the view that researchers often take actions that don’t actually help them to address their research questions and that much information that is almost routinely reported in research papers is irrelevant to the nominal goal of that research paper (i.e., answering its research questions). Part of the reason that researchers do things that don’t make much sense is that they have misunderstood what some statistical tool does. But I suspect that another part of the reason is that beginning researchers don’t quite see the point of some procedures they run and of some snippets of information they provide but nonetheless assume that <em>other</em> researchers do understand why these are important. From my own experience and discussions with former students, I think that there’s a vicious circle at play:</p>
<ol type="1">
<li>Students read articles with lots of numbers and procedures they don’t really understand or see the point of.<br>
</li>
<li>They reasonably but often incorrectly assume that these ubiquitous numbers and procedures must be integral to the research report.<br>
</li>
<li>As students become researchers, they still haven’t quite understood whether or why all those numbers and procedures are relevant. But they assume that they are relevant. So they’d better also include them in their own reports, or they’d be betraying their own ignorance. Luckily, even if you don’t know what p-values, correlation coefficients and reliability coefficients actually express, computing them is a piece of cake.</li>
<li>During peer review, you’re more likely to be chastised for not including some piece of information than for including a couple of irrelevant numbers. So beginning researchers may rarely be forced to consider the added value of their go-to procedures and of the information they routinely provide.</li>
<li>A new cohort of students reads the published research, see 1).</li>
</ol>
<p>It’s not that the beginning researchers in this scenario have misunderstood the tools they use — they have no conception of what these tools do, let alone a false one. All that is required for them to run superfluous procedures and include irrelevant information in their reports is that they think that other people see the relevance of what they’re doing — even if they themselves do not.</p>
<p>Now, it’s hard to stop using tools you’ve misunderstood the purpose of since you won’t know that you’ve misunderstood that purpose. But if you’re a young scholar and you want to run some analysis or report some numbers that are commonly run or reported in your line of work, first ask yourself and your colleagues how running this analysis or reporting these numbers would help you or readers of your work <strong>help answer your study’s research questions or make the answers easier to understand</strong>. Risk appearing ignorant and don’t cram your research reports with analyses and numbers you don’t see the added value of.</p>
<p>By the same token, if a young scholar asks you which statistical test they should use, first ask them why they think they need a test at all and what exactly it is they want to test. Similarly, if a novice asks you how they can run this or that analysis, ask them how they think running such an analysis would help them address their research question. Even if the added value of such an analysis is clear to you, it may not be clear to them.</p>
<p><strong>Edit (February 21, 2022)</strong>: Also see Daniël Lakens’ blog post <a href="https://daniellakens.blogspot.com/2019/03/the-new-heuristics.html"><em>The New Heuristics</em></a>, where he proposes researchers should adhere to the adage <em>justify everything</em>.</p>



 ]]></description>
  <category>simplicity</category>
  <category>silly tests</category>
  <category>research questions</category>
  <guid>https://janhove.github.io/posts/2022-02-18-dont-do-things-you-dont-see-the-point-of/</guid>
  <pubDate>Fri, 18 Feb 2022 00:00:00 GMT</pubDate>
</item>
<item>
  <title>An R function for computing Levenshtein distances between texts using the word as the unit of comparison</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2022-02-17-levenshtein/</link>
  <description><![CDATA[ 




<p>For a new research project, we needed a way to tabulate the changes that were made to a text when correcting it. Since we couldn’t find a suitable tool, I wrote an R function that uses the Levenshtein algorithm to determine both the smallest number of words that need to be changed to transform one version of a text into another and what these changes are.</p>
<p>You can download the <code>obtain_edits()</code> function from https://janhove.github.io/RCode/obtainEdits.R or source it directly:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://janhove.github.io/RCode/obtainEdits.R"</span>)</span></code></pre></div></div>
</div>
<p>The function recognises words that were deleted or inserted, words that were substituted for other words, and cases where one word was split into two words or where two words were merged to one word. All these changes count as one operation. The algorithm determines both the smallest number of operations needed to transform one version of the text into the other and outputs a data frame that lists what these operations are.</p>
<p>Here’s an example:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">original  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Check howmany changes need be made in order to change the first tekst in to the second one."</span></span>
<span id="cb2-2">corrected <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Check how many changes need to be made in order to change the first text into the second one."</span></span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">obtain_edits</span>(original, corrected)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[[1]]
[1] 4

[[2]]
  change_position  change_type change_from change_to
1              14       merger       in to      into
2              13 substitution       tekst      text
3               5    insertion                    to
4               2        split     howmany  how many</code></pre>
</div>
</div>
<p>Note that while the minimal operation count is uniquely determined, the list of changes that were made isn’t. Consider this example:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">textA <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"first secondthird"</span></span>
<span id="cb4-2">textB <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"second third"</span></span>
<span id="cb4-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">obtain_edits</span>(textA, textB)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[[1]]
[1] 2

[[2]]
  change_position change_type change_from    change_to
1               2       split secondthird second third
2               1    deletion       first             </code></pre>
</div>
</div>
<p>The algorithm identifies the difference from <code>textA</code> to <code>textB</code> as a matter of deleting ‘first’ and splitting up ‘secondthird’. But we could also consider it a matter of substituting ‘second’ for ‘first’ and ‘third’ for ‘secondthird’.</p>
<p>Nothing about stats or research design in this post, but perhaps this function is useful to someone somewhere!</p>



 ]]></description>
  <category>R</category>
  <guid>https://janhove.github.io/posts/2022-02-17-levenshtein/</guid>
  <pubDate>Thu, 17 Feb 2022 00:00:00 GMT</pubDate>
</item>
<item>
  <title>The consequences of controlling for a post-treatment variable</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2021-06-29-posttreatment/</link>
  <description><![CDATA[ 




<p>Let’s say you want to find out if a pedagogical intervention boosts learners’ conversational skills in L2 French. You’ve learnt that including a well-chosen control variable in your analysis can work <a href="../2017-10-24-increasing-power-precision">wonders</a> in terms of statistical power and precision, so you decide to administer a French vocabulary test to your participants in order to include their score on this test in your analyses as a covariate. But if you administer the vocabulary test <em>after</em> the intervention, it’s possible that the vocabulary scores are themselves affected by the intervention as well. If this is indeed the case, you may end up doing more harm than good. In this blog post, I will take a closer look at five general cases where controlling for such a ‘post-treatment’ variable is harmful.</p>
<p>In the following, <code>x</code> and <code>y</code> refer to the independent and dependent variable of interest, respectively, i.e., <code>x</code> would correspond to the intervention and <code>y</code> to the L2 French conversational skills in our example. <code>z</code> refers to the post-treatment variable, i.e., the French vocabulary scores in our example. <code>x</code> is a binary variable, <code>y</code> and <code>z</code> are continuous. Since <code>z</code> is a post-treatment variable, it’s possible that it is itself influenced directly or indirectly by <code>x</code>. In the five cases examined below, this is indeed the case.</p>
<p>I’ve included all R code as I think running simulations like the ones below are a useful way to learn research design and statistics. If you’re just interested in the upshot, just ignore the code snippets :)</p>
<section id="case-1-x-affects-both-y-and-z-y-and-z-dont-affect-each-other." class="level2">
<h2 class="anchored" data-anchor-id="case-1-x-affects-both-y-and-z-y-and-z-dont-affect-each-other.">Case 1: <code>x</code> affects both <code>y</code> and <code>z</code>; <code>y</code> and <code>z</code> don’t affect each other.</h2>
<p>In the first case, <code>x</code> affects both <code>y</code> and <code>z</code>, but <code>z</code> and <code>y</code> don’t influence each other.</p>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-2-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 1.1.</strong> The causal links between <code>x</code>, <code>y</code> and <code>z</code> in Case 1.</figcaption>
</figure>
</div>
</div>
</div>
<p>In this case, controlling for <code>z</code> doesn’t bias the estimate for the causal influence of <code>x</code> on <code>y</code>. It does, however, reduce the precision of these estimates. To appreciate this, let’s simulate some data. The function <code>case1()</code> defined in the next code snippet generates a dataset corersponding to Case 1. The parameter <code>beta_xy</code> specifies the coefficient of the influence of <code>x</code> on <code>y</code>; the goal of the analysis is to estimate the value of this parameter from the data. The parameter <code>beta_xz</code> similarly specifies the coefficient of the influence of <code>x</code> on <code>z</code>. Estimating the latter coefficient isn’t a goal of the analysis, since <code>z</code> is merely a control variable.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">case1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(n_per_group, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_xy =</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;">beta_xz =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>) {</span>
<span id="cb1-2">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create x (n_per_group 0s and n_per_group 1s)</span></span>
<span id="cb1-3">  x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> n_per_group)</span>
<span id="cb1-4">  </span>
<span id="cb1-5">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># x affects y; 'rnorm' just adds some random noise to the observations.</span></span>
<span id="cb1-6">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># In a DAG, this noise corresponds to the influence of other variables that</span></span>
<span id="cb1-7">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># didn't need to be plotted.</span></span>
<span id="cb1-8">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> beta_xy<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_per_group)</span>
<span id="cb1-9">  </span>
<span id="cb1-10">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># x affects z</span></span>
<span id="cb1-11">  z <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> beta_xz<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_per_group)</span>
<span id="cb1-12">  </span>
<span id="cb1-13">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create data frame</span></span>
<span id="cb1-14">  dfr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>(x), y, z)</span>
<span id="cb1-15">  </span>
<span id="cb1-16">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add info: z above or below median?</span></span>
<span id="cb1-17">  dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z_split <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"above"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"below"</span>))</span>
<span id="cb1-18">  </span>
<span id="cb1-19">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Return data frame</span></span>
<span id="cb1-20">  dfr</span>
<span id="cb1-21">}</span></code></pre></div></div>
</div>
<p>Use this function to create a dataset with 100 participants per group:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">df_case1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case1</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span>
<span id="cb2-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Type 'df_case1' to inspect.</span></span></code></pre></div></div>
</div>
<p>A graphical analysis that doesn’t take the control variable <code>z</code> into account reveals a roughly one-point difference between the two conditions, which is as it should be.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_case1,</span>
<span id="cb3-3">       <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> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</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="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">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;">width =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-5-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 1.2.</strong> Graphical analysis without the covariate for Case 1.</figcaption>
</figure>
</div>
</div>
</div>
<p>A linear model is able to retrieve the <code>beta_xy</code> coefficient, which was set at 1, well enough (<img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta_%7Bxy%7D%7D%20=%201.03%20%5Cpm%200.13">).</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x, df_case1))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficient</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)  -0.0161      0.092  -0.175 8.61e-01
x1            1.0349      0.130   7.951 1.38e-13</code></pre>
</div>
</div>
<p>Alternatively, we could analyse these data while taking the control variable into account. The graphical analysis in Figure 3 achieves this by splitting up the control variable at its median and plotting the two subset separately. This is statistically suboptimal, but it makes the visualisation easier to grok. Here we also find a roughly one-point difference between the two conditions in each panel, which suggests that controlling for <code>z</code> won’t induce any bias.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_case1,</span>
<span id="cb6-2">       <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> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-3">  <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;">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="cb6-4">  <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_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.2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-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> z_split)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-7-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 1.3.</strong> Graphical analysis with the covariate (median split) for Case 1.</figcaption>
</figure>
</div>
</div>
</div>
<p>The linear model is again able to retrieve the coefficient of interest well enough (<img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta_%7Bxy%7D%7D%20=%201.04%20%5Cpm%200.16">), though with a slightly wider standard error.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> z, df_case1))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficient</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept) -0.01615     0.0923 -0.1750 8.61e-01
x1           1.04147     0.1632  6.3826 1.22e-09
z           -0.00409     0.0613 -0.0667 9.47e-01</code></pre>
</div>
</div>
<p>Of course, it’s difficult to draw any firm conclusions about the analysis of a single simulated dataset. To see that in this general case, the coefficient of interest is indeed estimated without bias but with decreased precision, let’s generate 5,000 such datasets and analyse them with and without taking the control variable into account. The function <code>sim_case1()</code> defined below runs these analyses; the ggplot call plots the estimates for the <img src="https://latex.codecogs.com/png.latex?%5Cbeta_%7Bxy%7D"> parameter. As the caption to Figure 4 explains, this simulation confirms what we observed above.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Another function. This one takes the function case1(),</span></span>
<span id="cb9-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># runs it nruns (here: 1000) times and extracts estimates</span></span>
<span id="cb9-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># from two analyses per generated dataset.</span></span>
<span id="cb9-4">sim_case1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nruns =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</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;">beta_xy =</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;">beta_xz =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>) {</span>
<span id="cb9-5">  est_without <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"double"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> nruns)</span>
<span id="cb9-6">  est_with <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"double"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> nruns)</span>
<span id="cb9-7">  </span>
<span id="cb9-8">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>nruns) {</span>
<span id="cb9-9">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate data</span></span>
<span id="cb9-10">    d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case1</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</span> n_per_group, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_xy =</span> beta_xy, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_xz =</span> beta_xz)</span>
<span id="cb9-11">    </span>
<span id="cb9-12">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Analyse (in regression model) without covariate and extract estimate</span></span>
<span id="cb9-13">    est_without[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d))[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]]</span>
<span id="cb9-14">    </span>
<span id="cb9-15">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Analyse with covariate, extract estimate</span></span>
<span id="cb9-16">    est_with[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> z, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d))[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]]</span>
<span id="cb9-17">  }</span>
<span id="cb9-18">  </span>
<span id="cb9-19">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Output data frame with results</span></span>
<span id="cb9-20">  results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb9-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simulation =</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>nruns, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb9-22">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">covariate =</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;">"with covariate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"without covariate"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> nruns),</span>
<span id="cb9-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(est_with, est_without)</span>
<span id="cb9-24">  )</span>
<span id="cb9-25">}</span>
<span id="cb9-26"></span>
<span id="cb9-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Run function and plot results</span></span>
<span id="cb9-28">results_sim_case1 <span class="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_case1</span>()</span>
<span id="cb9-29"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> results_sim_case1,</span>
<span id="cb9-30">       <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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-31">  <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;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lightgrey"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-33">  <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> covariate)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-9-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 1.4.</strong> In Case 1, the distribution of the parameter estimates is centred around the correct value both when the control variable is taken into account and when it isn’t. The distribution is wider when taking the control variable into account, however, i.e., the estimates are less precise when taking the control variable into account than when not taking it into account.</figcaption>
</figure>
</div>
</div>
</div>
<p>The estimate for the <img src="https://latex.codecogs.com/png.latex?%5Cbeta_%7Bxy%7D"> parameter is unbiased in both analyses, but the analysis with the covariate offers <em>less</em> rather than more precision: The standard deviation of the distribution of parameter estimates increases from 0.14 to 0.18:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">results_sim_case1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(covariate) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(estimate),</span>
<span id="cb10-4">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(estimate))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 2 × 3
  covariate         mean_est sd_est
  &lt;chr&gt;                &lt;dbl&gt;  &lt;dbl&gt;
1 with covariate       0.999  0.177
2 without covariate    0.998  0.141</code></pre>
</div>
</div>
</section>
<section id="case-2-x-affects-y-which-in-turn-affects-z." class="level2">
<h2 class="anchored" data-anchor-id="case-2-x-affects-y-which-in-turn-affects-z.">Case 2: <code>x</code> affects <code>y</code>, which in turn affects <code>z</code>.</h2>
<p>In the second case, <code>x</code> affects <code>y</code> directly, and <code>y</code> in turns affects <code>z</code>.</p>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-11-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 2.1.</strong> The causal links between <code>x</code>, <code>y</code> and <code>z</code> in Case 2.</figcaption>
</figure>
</div>
</div>
</div>
<p>This time, controlling for <code>z</code> biases the estimates for the <img src="https://latex.codecogs.com/png.latex?%5Cbeta_%7Bxy%7D"> parameter. To see this, let’s again simulate and analyse some data.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">case2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(n_per_group, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_xy =</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;">beta_yz =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>) {</span>
<span id="cb12-2">  x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> n_per_group)</span>
<span id="cb12-3">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> beta_xy<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_per_group)</span>
<span id="cb12-4">  </span>
<span id="cb12-5">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># y affects z</span></span>
<span id="cb12-6">  z <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> beta_yz<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_per_group)</span>
<span id="cb12-7">  </span>
<span id="cb12-8">  dfr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>(x), y, z)</span>
<span id="cb12-9">  dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z_split <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"above"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"below"</span>))</span>
<span id="cb12-10">  </span>
<span id="cb12-11">  dfr</span>
<span id="cb12-12">}</span>
<span id="cb12-13"></span>
<span id="cb12-14">df_case2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case2</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span></code></pre></div></div>
</div>
<p>When the data are analyses without taking the control variable into account, we obtain the following result:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_case2,</span>
<span id="cb13-2">       <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> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-3">  <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;">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="cb13-4">  <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_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.2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-13-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 2.2.</strong> Graphical analysis without the covariate for Case 2.</figcaption>
</figure>
</div>
</div>
</div>
<p>This isn’t quite as close to a one-point difference as in the previous example, but as we’ll see below that’s merely due to the randomness inherent in these simulations. The linear model yields a parameter estimate of <img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta_%7Bxy%7D%7D%20=%200.76%20%5Cpm%200.14">.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x, df_case2))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficient</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)    0.248     0.0958    2.59 1.02e-02
x1             0.755     0.1354    5.57 8.06e-08</code></pre>
</div>
</div>
<p>When we take the control variable into account, however, the difference between the two groups defined by <code>x</code> becomes smaller:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_case2,</span>
<span id="cb16-2">       <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> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb16-3">  <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;">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="cb16-4">  <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_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.2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</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;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> z_split)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-15-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 2.3.</strong> Graphical analysis with the covariate for Case 2.</figcaption>
</figure>
</div>
</div>
</div>
<p>The linear model now yields a parameter estimate of <img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta_%7Bxy%7D%7D%20=%200.18%20%5Cpm%200.08">, which is considerably farther from the actual parameter value of 1.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> z, df_case2))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficient</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)   0.0479     0.0531    0.90 3.69e-01
x1            0.1790     0.0787    2.28 2.39e-02
z             0.4717     0.0218   21.59 7.87e-54</code></pre>
</div>
</div>
<p>The larger-scale simulation shows that the analysis with the covariate is indeed biased if you want to estimate the causal influence of <code>x</code> on <code>y</code>.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Change beta_xz to beta_xy compared to the previous case</span></span>
<span id="cb19-2">sim_case2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nruns =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</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;">beta_xy =</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;">beta_yz =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>) {</span>
<span id="cb19-3">  est_without <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"double"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> nruns)</span>
<span id="cb19-4">  est_with <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"double"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> nruns)</span>
<span id="cb19-5">  </span>
<span id="cb19-6">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>nruns) {</span>
<span id="cb19-7">    d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case2</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</span> n_per_group, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_xy =</span> beta_xy, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_yz =</span> beta_yz)</span>
<span id="cb19-8">    est_without[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d))[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]]</span>
<span id="cb19-9">    est_with[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> z, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d))[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]]</span>
<span id="cb19-10">  }</span>
<span id="cb19-11">  </span>
<span id="cb19-12">  results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb19-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simulation =</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>nruns, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb19-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">covariate =</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;">"with covariate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"without covariate"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> nruns),</span>
<span id="cb19-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(est_with, est_without)</span>
<span id="cb19-16">  )</span>
<span id="cb19-17">}</span>
<span id="cb19-18"></span>
<span id="cb19-19">results_sim_case2 <span class="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_case2</span>()</span>
<span id="cb19-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> results_sim_case2,</span>
<span id="cb19-21">       <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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-22">  <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;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lightgrey"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb19-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> covariate)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-17-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 2.4.</strong> In Case 2, the distribution of the parameter estimates is centred around the correct value both when the control variable isn’t taken into account but it is strongly biased when this control variable <em>is</em> taken into account, i.e., the analysis with the covariate yields biased estimates.</figcaption>
</figure>
</div>
</div>
</div>
<p>The fact that the distribution of the parameter estimates is narrower when taking the covariate into account is completely immaterial, since these estimates are estimating the wrong quantity.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1">results_sim_case2 <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;">group_by</span>(covariate) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(estimate),</span>
<span id="cb20-4">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(estimate))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 2 × 3
  covariate         mean_est sd_est
  &lt;chr&gt;                &lt;dbl&gt;  &lt;dbl&gt;
1 with covariate       0.310 0.0856
2 without covariate    1.00  0.141 </code></pre>
</div>
</div>
</section>
<section id="case-3-x-and-y-both-affect-z.-x-also-affects-y." class="level2">
<h2 class="anchored" data-anchor-id="case-3-x-and-y-both-affect-z.-x-also-affects-y.">Case 3: <code>x</code> and <code>y</code> both affect <code>z</code>. <code>x</code> also affects <code>y</code>.</h2>
<p>Now <code>z</code> is affected by both <code>x</code> and <code>y</code>. <code>x</code> still affects <code>y</code>, though. Taking the covariate into account again yields biased estimates.</p>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-19-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 3.1.</strong> The causal links between <code>x</code>, <code>y</code> and <code>z</code> in Case 3.</figcaption>
</figure>
</div>
</div>
</div>
<p>Same procedure as last year, James.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1">case3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(n_per_group, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_xy =</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;">beta_xz =</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;">beta_yz =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>) {</span>
<span id="cb22-2">  x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> n_per_group)</span>
<span id="cb22-3">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> beta_xy<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_per_group)</span>
<span id="cb22-4">  </span>
<span id="cb22-5">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># x and y affect z</span></span>
<span id="cb22-6">  z <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> beta_xz<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> beta_yz<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_per_group)</span>
<span id="cb22-7">  </span>
<span id="cb22-8">  dfr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>(x), y, z)</span>
<span id="cb22-9">  dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z_split <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"above"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"below"</span>))</span>
<span id="cb22-10"></span>
<span id="cb22-11">  dfr</span>
<span id="cb22-12">}</span>
<span id="cb22-13"></span>
<span id="cb22-14">df_case3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case3</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_case3,</span>
<span id="cb23-2">       <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> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb23-3">  <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;">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="cb23-4">  <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_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.2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-21-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 3.2.</strong> Graphical analysis without the covariate for Case 3.</figcaption>
</figure>
</div>
</div>
</div>
<p>Again, the analysis without the control variable yields a reasonably accurate estimate of the true parameter value of 1 (<img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta_%7Bxy%7D%7D%20=%201.07%20%5Cpm%200.15">).</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x, df_case3))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficient</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)  -0.0817      0.105  -0.778 4.37e-01
x1            1.0687      0.148   7.197 1.25e-11</code></pre>
</div>
</div>
<p>When we take the control variable into account, however, the difference between the two groups defined by <code>x</code> becomes smaller:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_case3,</span>
<span id="cb26-2">       <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> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb26-3">  <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;">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="cb26-4">  <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_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.2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb26-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> z_split)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-23-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 3.3.</strong> Graphical analysis with the covariate for Case 3.</figcaption>
</figure>
</div>
</div>
</div>
<p>The linear model now yields a parameter estimate of <img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta_%7Bxy%7D%7D%20=%20-0.31%20%5Cpm%200.11">, which is considerably farther from the actual parameter value of 1 and even has the wrong sign.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> z, df_case3))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficient</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)   0.0038     0.0594  0.0639 9.49e-01
x1           -0.3067     0.1071 -2.8631 4.65e-03
z             0.4614     0.0224 20.6083 4.71e-51</code></pre>
</div>
</div>
<p>For the sake of completeness, let’s run this simulation 5,000 times, too.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1">sim_case3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nruns =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</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;">beta_xy =</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;">beta_xz =</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;">beta_yz =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>) {</span>
<span id="cb29-2">  est_without <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"double"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> nruns)</span>
<span id="cb29-3">  est_with <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"double"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> nruns)</span>
<span id="cb29-4">  </span>
<span id="cb29-5">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>nruns) {</span>
<span id="cb29-6">    d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case3</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</span> n_per_group, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_xy =</span> beta_xy, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_xz =</span> beta_xz, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_yz =</span> beta_yz)</span>
<span id="cb29-7">    est_without[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d))[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]]</span>
<span id="cb29-8">    est_with[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> z, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d))[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]]</span>
<span id="cb29-9">  }</span>
<span id="cb29-10"></span>
<span id="cb29-11">  results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb29-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simulation =</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>nruns, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb29-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">covariate =</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;">"with covariate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"without covariate"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> nruns),</span>
<span id="cb29-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(est_with, est_without)</span>
<span id="cb29-15">  )</span>
<span id="cb29-16">}</span>
<span id="cb29-17"></span>
<span id="cb29-18">results_sim_case3 <span class="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_case3</span>()</span>
<span id="cb29-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> results_sim_case3,</span>
<span id="cb29-20">       <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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-21">  <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;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lightgrey"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb29-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> covariate)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-25-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 3.4.</strong> In Case 3, too, the distribution of the parameter estimates is centred around the correct value when the control variable isn’t taken into account but it is strongly biased when this control variable <em>is</em> taken into account, i.e., the analysis with the covariate yields biased estimates.</figcaption>
</figure>
</div>
</div>
</div>
<p>The fact that the distribution of the parameter estimates is narrower when taking the covariate into account is completely immaterial, since these estimates are estimating the wrong quantity.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1">results_sim_case3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(covariate) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(estimate),</span>
<span id="cb30-4">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(estimate))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 2 × 3
  covariate         mean_est sd_est
  &lt;chr&gt;                &lt;dbl&gt;  &lt;dbl&gt;
1 with covariate      -0.382  0.104
2 without covariate    1.00   0.144</code></pre>
</div>
</div>
</section>
<section id="case-4-x-affects-z-both-x-and-z-influence-y." class="level2">
<h2 class="anchored" data-anchor-id="case-4-x-affects-z-both-x-and-z-influence-y.">Case 4: <code>x</code> affects <code>z</code>; both <code>x</code> and <code>z</code> influence <code>y</code>.</h2>
<p>That is, <code>x</code> influences both <code>y</code> and <code>z</code>, but <code>z</code> also influences <code>y</code>. Let <img src="https://latex.codecogs.com/png.latex?%5Cbeta_%7Bxy%7D"> be the direct effect of <code>x</code> on <code>y</code>, <img src="https://latex.codecogs.com/png.latex?%5Cbeta_%7Bxz%7D"> the effect of <code>x</code> on <code>z</code> and <img src="https://latex.codecogs.com/png.latex?%5Cbeta_%7Bzy%7D"> the effect of <code>z</code> on <code>y</code>. Then the <em>total</em> effect of <code>x</code> on <code>y</code> is <img src="https://latex.codecogs.com/png.latex?%5Cbeta_%7Bxy%7D%20+%20%5Cbeta_%7Bxz%7D%5Ctimes%5Cbeta_%7Bzy%7D">.</p>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-27-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 4.1.</strong> The causal links between <code>x</code>, <code>y</code> and <code>z</code> in Case 4.</figcaption>
</figure>
</div>
</div>
</div>
<p>Using the defaults in the following function, the total effect of <code>x</code> on <code>y</code> is <img src="https://latex.codecogs.com/png.latex?1%20+%201.5%5Ctimes%200.5%20=%201.75">. If this doesn’t make immediate sense, consider what a change of one unit in <code>x</code> causes downstream: A one-unit increase in <code>x</code> directly increases <code>y</code> by 1. It also increases <code>z</code> by 1.5. But a one-unit increase <em>in <code>z</code></em> causes an increase of 0.5 in <code>y</code> as well, so a 1.5-unit increase in <code>z</code> causes an additional increase of 0.75 in <code>y</code>. So in total, a one-unit increase in <code>x</code> causes a 1.75-point increase in <code>y</code>.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1">case4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(n_per_group, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_xy =</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;">beta_xz =</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;">beta_zy =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) {</span>
<span id="cb32-2">  x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> n_per_group)</span>
<span id="cb32-3">  </span>
<span id="cb32-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># x affects z</span></span>
<span id="cb32-5">  z <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> beta_xz<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_per_group)</span>
<span id="cb32-6">  </span>
<span id="cb32-7">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># x and z affect y</span></span>
<span id="cb32-8">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> beta_xy<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> beta_zy<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_per_group)</span>
<span id="cb32-9">  </span>
<span id="cb32-10">  dfr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>(x), y, z)</span>
<span id="cb32-11">  </span>
<span id="cb32-12">  dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z_split <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">median</span>(dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"above"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"below"</span>))</span>
<span id="cb32-13">  </span>
<span id="cb32-14">  dfr</span>
<span id="cb32-15">}</span>
<span id="cb32-16"></span>
<span id="cb32-17">df_case4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case4</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_case4,</span>
<span id="cb33-2">       <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> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-3">  <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;">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="cb33-4">  <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_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.2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-29-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 4.2.</strong> Graphical analysis without the covariate for Case 4.</figcaption>
</figure>
</div>
</div>
</div>
<p>Again, the analysis without the control variable yields a reasonably accurate estimate of the true <em>total</em> influence of <code>x</code> on <code>y</code> of 1.75 (!) (<img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta_%7Bxy%7D%7D%20=%201.67%20%5Cpm%200.16">).</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x, df_case4))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficient</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)   0.0802      0.115   0.695 4.88e-01
x1            1.6744      0.163  10.263 4.36e-20</code></pre>
</div>
</div>
<p>When we take the control variable into account, however, the difference between the two groups defined by <code>x</code> becomes smaller:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_case4,</span>
<span id="cb36-2">       <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> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb36-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</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="cb36-4">  <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_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.2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb36-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> z_split)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-31-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 4.3.</strong> Graphical analysis with the covariate for Case 4.</figcaption>
</figure>
</div>
</div>
</div>
<p>The linear model now yields a parameter estimate of <img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta_%7Bxy%7D%7D%20=%201.11%20%5Cpm%200.17">. This analysis correctly estimates the <em>direct</em> effect of <code>x</code> on <code>y</code> (i.e., without the additional causal link between <code>x</code> on <code>y</code> through <code>z</code>). This may be interesting in its own right, but the analysis addresses a question different from `<code>What's the causal influence of</code>x<code>on</code>y`?’’</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb37" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> z, df_case4))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficient</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)  -0.0451     0.1073  -0.421 6.75e-01
x1            1.1054     0.1742   6.346 1.49e-09
z             0.4853     0.0768   6.321 1.70e-09</code></pre>
</div>
</div>
<p>For the sake of completeness, let’s run this simulation 5,000 times, too.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1">sim_case4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nruns =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</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;">beta_xy =</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;">beta_xz =</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;">beta_zy =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>) {</span>
<span id="cb39-2">  est_without <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"double"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> nruns)</span>
<span id="cb39-3">  est_with <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"double"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> nruns)</span>
<span id="cb39-4">  </span>
<span id="cb39-5">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>nruns) {</span>
<span id="cb39-6">    d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case4</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</span> n_per_group, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_xy =</span> beta_xy, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_xz =</span> beta_xz, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_zy =</span> beta_zy)</span>
<span id="cb39-7">    est_without[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d))[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]]</span>
<span id="cb39-8">    est_with[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> z, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d))[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]]</span>
<span id="cb39-9">  }</span>
<span id="cb39-10">  </span>
<span id="cb39-11">  results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb39-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simulation =</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>nruns, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb39-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">covariate =</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;">"with covariate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"without covariate"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> nruns),</span>
<span id="cb39-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(est_with, est_without)</span>
<span id="cb39-15">  )</span>
<span id="cb39-16">}</span>
<span id="cb39-17"></span>
<span id="cb39-18">results_sim_case4 <span class="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_case4</span>()</span>
<span id="cb39-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> results_sim_case4,</span>
<span id="cb39-20">       <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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb39-21">  <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;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lightgrey"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb39-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.75</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb39-23">  <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> covariate)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-33-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 4.4.</strong> In Case 4, the analysis without the covariate correctly estimates the <em>total</em> causal influence that <code>x</code> has on <code>y</code>, while the analysis with the covariate correctly estimates the <em>direct</em> causal effect of <code>x</code> on <code>y</code>. Either may be relevant, but you have to know which!</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1">results_sim_case4 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb40-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(covariate) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb40-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(estimate),</span>
<span id="cb40-4">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(estimate))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 2 × 3
  covariate         mean_est sd_est
  &lt;chr&gt;                &lt;dbl&gt;  &lt;dbl&gt;
1 with covariate        1.00  0.178
2 without covariate     1.75  0.158</code></pre>
</div>
</div>
</section>
<section id="case-5-x-and-z-affect-y-x-and-z-dont-affect-each-other." class="level2">
<h2 class="anchored" data-anchor-id="case-5-x-and-z-affect-y-x-and-z-dont-affect-each-other.">Case 5: <code>x</code> and <code>z</code> affect <code>y</code>; <code>x</code> and <code>z</code> don’t affect each other.</h2>
<p>In the final general case, <code>x</code> and <code>z</code> both affect <code>y</code>, but <code>x</code> and <code>z</code> don’t affect each other. That is, <code>z</code> isn’t affected by the intervention in any way and so functions like a pre-treatment control variable would. The result is an increase in statistical precision. This is the only of the five cases examined in which the control variable has added value for the purposes of estimated the causal influence of <code>x</code> on <code>y</code>.</p>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-35-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 5.1.</strong> The causal links between <code>x</code>, <code>y</code> and <code>z</code> in Case 5.</figcaption>
</figure>
</div>
</div>
</div>
<p>Using the defaults in the following function, the total effect of <code>x</code> on <code>y</code> is <img src="https://latex.codecogs.com/png.latex?1%20+%201.5%5Ctimes%200.5%20=%201.75">. If this doesn’t make immediate sense, consider what a change of one unit in <code>x</code> causes downstream: A one-unit increase in <code>x</code> directly increases <code>y</code> by 1. It also increases <code>z</code> by 1.5. But a one-unit increase <em>in <code>z</code></em> causes an increase of 0.5 in <code>y</code> as well, so a 1.5-unit increase in <code>z</code> causes an additional increase of 0.75 in <code>y</code>. So in total, a one-unit increase in <code>x</code> causes a 1.75-point increase in <code>y</code>.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb42" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1">case5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(n_per_group, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_xy =</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;">beta_zy =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>) {</span>
<span id="cb42-2">  x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> n_per_group)</span>
<span id="cb42-3">  </span>
<span id="cb42-4">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create z</span></span>
<span id="cb42-5">  z <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_per_group)</span>
<span id="cb42-6">  </span>
<span id="cb42-7">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># x and z affect y</span></span>
<span id="cb42-8">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> beta_xy<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> beta_zy<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n_per_group)</span>
<span id="cb42-9">  </span>
<span id="cb42-10">  dfr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.factor</span>(x), y, z)</span>
<span id="cb42-11">  dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z_split <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(dfr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>z), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"above"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"below"</span>))</span>
<span id="cb42-12">  </span>
<span id="cb42-13">  dfr</span>
<span id="cb42-14">}</span>
<span id="cb42-15"></span>
<span id="cb42-16">df_case5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case5</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb43" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb43-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_case5,</span>
<span id="cb43-2">       <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> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y)) <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_boxplot</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="cb43-4">  <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_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.2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-37-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 5.2.</strong> Graphical analysis without the covariate for Case 5.</figcaption>
</figure>
</div>
</div>
</div>
<p>Again, the analysis without the control variable yields an estimate within one standard error of the true parameter value of 1 (<img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta_%7Bxy%7D%7D%20=%200.76%20%5Cpm%200.24">).</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb44" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb44-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x, df_case5))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficient</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)  0.00417      0.172  0.0242   0.9807
x1           0.75596      0.244  3.1027   0.0022</code></pre>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb46" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb46-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_case5,</span>
<span id="cb46-2">       <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> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb46-3">  <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;">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="cb46-4">  <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_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.2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb46-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> z_split)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-39-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 5.3.</strong> Graphical analysis with the covariate for Case 5.</figcaption>
</figure>
</div>
</div>
</div>
<p>The linear model now yields a parameter estimate of <img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta_%7Bxy%7D%7D%20=%201.08%20%5Cpm%200.15">, with is also a reasonable estimate but with a smaller standard error.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb47" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb47-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> z, df_case5))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficient</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)  -0.0376     0.1027  -0.366 7.15e-01
x1            1.0823     0.1462   7.402 3.80e-12
z             1.4193     0.0748  18.986 2.23e-46</code></pre>
</div>
</div>
<p>For the sake of completeness, let’s run this simulation 5,000 times, too.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb49" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb49-1">sim_case5 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nruns =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</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;">beta_xy =</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;">beta_zy =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>) {</span>
<span id="cb49-2">  est_without <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"double"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> nruns)</span>
<span id="cb49-3">  est_with <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"double"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> nruns)</span>
<span id="cb49-4">  </span>
<span id="cb49-5">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>nruns) {</span>
<span id="cb49-6">    d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">case5</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n_per_group =</span> n_per_group, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_xy =</span> beta_xy, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta_zy =</span> beta_zy)</span>
<span id="cb49-7">    est_without[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d))[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]]</span>
<span id="cb49-8">    est_with[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> z, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d))[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]]</span>
<span id="cb49-9">  }</span>
<span id="cb49-10"></span>
<span id="cb49-11">  results <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb49-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simulation =</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>nruns, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb49-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">covariate =</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;">"with covariate"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"without covariate"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> nruns),</span>
<span id="cb49-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(est_with, est_without)</span>
<span id="cb49-15">  )</span>
<span id="cb49-16">}</span>
<span id="cb49-17"></span>
<span id="cb49-18">results_sim_case5 <span class="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_case5</span>()</span>
<span id="cb49-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> results_sim_case5,</span>
<span id="cb49-20">       <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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb49-21">  <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;">fill =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lightgrey"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bins =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb49-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb49-23">  <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> covariate)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2021-06-29-posttreatment/index_files/figure-html/unnamed-chunk-41-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 5.4.</strong> In Case 5, both analyses are centred around the correct value, i.e., both are unbiased. The analysis with the control variable yields a narrower distribution of estimates, however, i.e., it is more precise.</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb50" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb50-1">results_sim_case5 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb50-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(covariate) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb50-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean_est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(estimate),</span>
<span id="cb50-4">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd_est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(estimate))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 2 × 3
  covariate         mean_est sd_est
  &lt;chr&gt;                &lt;dbl&gt;  &lt;dbl&gt;
1 with covariate       1.00   0.138
2 without covariate    0.999  0.250</code></pre>
</div>
</div>
</section>
<section id="conclusion" class="level2">
<h2 class="anchored" data-anchor-id="conclusion">Conclusion</h2>
<p>When a control variable is collected <em>after</em> the intervention took place, it is possible that it is directly or indirectly affected by the intervention. If this is indeed the case, including the control variable in the analysis may yield biased estimates or decrease rather than increase the precision of the estimates. In designed experiments, the solution to this problem is evident: collect the control variable before the intervention takes place. If this isn’t possible, you had better be pretty sure that the control variable isn’t a post-treatment variable. More generally, throwing predictor variables into a statistical model in the hopes that this will improve the analysis is a dreadful idea.</p>
<!-- ## Reference -->
<!-- Zimmerman, Donald W. 1998. [Invalidation of parametric and nonparametric statistical tests by concurrent violation of two assumptions](https://doi.org/10.1080/00220979809598344). _Journal of Experimental Education_ 67(1). 55-68. -->
</section>
<section id="software-versions" class="level2">
<h2 class="anchored" data-anchor-id="software-versions">Software versions</h2>
<p>Please note that I reran the code on this page on August 6, 2023.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb52" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb52-1">devtools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">session_info</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.1 (2025-06-13)
 os       Ubuntu 22.04.5 LTS
 system   x86_64, linux-gnu
 ui       X11
 language en_US
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Zurich
 date     2025-09-24
 pandoc   2.12 @ /home/jan/miniconda3/bin/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────
 package        * version  date (UTC) lib source
 abind            1.4-8    2024-09-12 [1] CRAN (R 4.5.1)
 backports        1.5.0    2024-05-23 [1] CRAN (R 4.5.1)
 boot             1.3-31   2024-08-28 [4] CRAN (R 4.4.2)
 cachem           1.1.0    2024-05-16 [1] CRAN (R 4.5.1)
 callr            3.7.6    2024-03-25 [1] CRAN (R 4.5.1)
 checkmate        2.3.3    2025-08-18 [1] CRAN (R 4.5.1)
 cli              3.6.5    2025-04-23 [1] CRAN (R 4.5.1)
 cmdstanr       * 0.9.0    2025-03-30 [1] https://stan-dev.r-universe.dev (R 4.5.1)
 coda             0.19-4.1 2024-01-31 [1] CRAN (R 4.5.1)
 crayon           1.5.1    2022-03-26 [2] CRAN (R 4.2.0)
 curl             6.4.0    2025-06-22 [1] CRAN (R 4.5.1)
 dagitty        * 0.3-4    2023-12-07 [1] CRAN (R 4.5.1)
 devtools         2.4.5    2022-10-11 [1] CRAN (R 4.5.1)
 digest           0.6.37   2024-08-19 [1] CRAN (R 4.5.1)
 distributional   0.5.0    2024-09-17 [1] CRAN (R 4.5.1)
 dplyr          * 1.1.4    2023-11-17 [1] CRAN (R 4.5.1)
 ellipsis         0.3.2    2021-04-29 [2] CRAN (R 4.2.0)
 evaluate         1.0.4    2025-06-18 [1] CRAN (R 4.5.1)
 farver           2.1.2    2024-05-13 [1] CRAN (R 4.5.1)
 fastmap          1.2.0    2024-05-15 [1] CRAN (R 4.5.1)
 forcats        * 1.0.0    2023-01-29 [1] CRAN (R 4.5.1)
 fs               1.5.2    2021-12-08 [2] CRAN (R 4.2.0)
 generics         0.1.4    2025-05-09 [1] CRAN (R 4.5.1)
 ggplot2        * 3.5.2    2025-04-09 [1] CRAN (R 4.5.1)
 glue             1.6.2    2022-02-24 [2] CRAN (R 4.2.0)
 gtable           0.3.6    2024-10-25 [1] CRAN (R 4.5.1)
 hms              1.1.3    2023-03-21 [1] CRAN (R 4.5.1)
 htmltools        0.5.8.1  2024-04-04 [1] CRAN (R 4.5.1)
 htmlwidgets      1.6.4    2023-12-06 [1] CRAN (R 4.5.1)
 httpuv           1.6.16   2025-04-16 [1] CRAN (R 4.5.1)
 jsonlite         2.0.0    2025-03-27 [1] CRAN (R 4.5.1)
 knitr            1.50     2025-03-16 [1] CRAN (R 4.5.1)
 labeling         0.4.3    2023-08-29 [1] CRAN (R 4.5.1)
 later            1.4.2    2025-04-08 [1] CRAN (R 4.5.1)
 lattice          0.22-5   2023-10-24 [4] CRAN (R 4.3.1)
 lifecycle        1.0.4    2023-11-07 [1] CRAN (R 4.5.1)
 loo              2.8.0    2024-07-03 [1] CRAN (R 4.5.1)
 lubridate      * 1.9.4    2024-12-08 [1] CRAN (R 4.5.1)
 magrittr         2.0.3    2022-03-30 [1] CRAN (R 4.5.1)
 MASS             7.3-65   2025-02-28 [4] CRAN (R 4.4.3)
 matrixStats      1.5.0    2025-01-07 [1] CRAN (R 4.5.1)
 memoise          2.0.1    2021-11-26 [2] CRAN (R 4.2.0)
 mime             0.10     2021-02-13 [2] CRAN (R 4.0.2)
 miniUI           0.1.2    2025-04-17 [1] CRAN (R 4.5.1)
 mvtnorm          1.3-3    2025-01-10 [1] CRAN (R 4.5.1)
 pillar           1.10.2   2025-04-05 [1] CRAN (R 4.5.1)
 pkgbuild         1.3.1    2021-12-20 [2] CRAN (R 4.2.0)
 pkgconfig        2.0.3    2019-09-22 [2] CRAN (R 4.2.0)
 pkgload          1.4.0    2024-06-28 [1] CRAN (R 4.5.1)
 posterior      * 1.6.1    2025-02-27 [1] CRAN (R 4.5.1)
 prettyunits      1.1.1    2020-01-24 [2] CRAN (R 4.2.0)
 processx         3.8.6    2025-02-21 [1] CRAN (R 4.5.1)
 profvis          0.4.0    2024-09-20 [1] CRAN (R 4.5.1)
 promises         1.3.3    2025-05-29 [1] CRAN (R 4.5.1)
 ps               1.9.1    2025-04-12 [1] CRAN (R 4.5.1)
 purrr          * 1.0.4    2025-02-05 [1] CRAN (R 4.5.1)
 R6               2.5.1    2021-08-19 [2] CRAN (R 4.2.0)
 RColorBrewer     1.1-3    2022-04-03 [1] CRAN (R 4.5.1)
 Rcpp             1.0.14   2025-01-12 [1] CRAN (R 4.5.1)
 readr          * 2.1.5    2024-01-10 [1] CRAN (R 4.5.1)
 remotes          2.4.2    2021-11-30 [2] CRAN (R 4.2.0)
 rethinking     * 2.42     2025-09-24 [1] Github (rmcelreath/rethinking@ac1b3b2)
 rlang            1.1.6    2025-04-11 [1] CRAN (R 4.5.1)
 rmarkdown        2.29     2024-11-04 [1] CRAN (R 4.5.1)
 rstudioapi       0.17.1   2024-10-22 [1] CRAN (R 4.5.1)
 scales           1.4.0    2025-04-24 [1] CRAN (R 4.5.1)
 sessioninfo      1.2.2    2021-12-06 [2] CRAN (R 4.2.0)
 shape            1.4.6.1  2024-02-23 [1] CRAN (R 4.5.1)
 shiny            1.10.0   2024-12-14 [1] CRAN (R 4.5.1)
 stringi          1.7.6    2021-11-29 [2] CRAN (R 4.2.0)
 stringr        * 1.5.1    2023-11-14 [1] CRAN (R 4.5.1)
 tensorA          0.36.2.1 2023-12-13 [1] CRAN (R 4.5.1)
 tibble         * 3.3.0    2025-06-08 [1] CRAN (R 4.5.1)
 tidyr          * 1.3.1    2024-01-24 [1] CRAN (R 4.5.1)
 tidyselect       1.2.1    2024-03-11 [1] CRAN (R 4.5.1)
 tidyverse      * 2.0.0    2023-02-22 [1] CRAN (R 4.5.1)
 timechange       0.3.0    2024-01-18 [1] CRAN (R 4.5.1)
 tzdb             0.5.0    2025-03-15 [1] CRAN (R 4.5.1)
 urlchecker       1.0.1    2021-11-30 [1] CRAN (R 4.5.1)
 usethis          3.1.0    2024-11-26 [1] CRAN (R 4.5.1)
 utf8             1.2.2    2021-07-24 [2] CRAN (R 4.2.0)
 V8               6.0.4    2025-06-04 [1] CRAN (R 4.5.1)
 vctrs            0.6.5    2023-12-01 [1] CRAN (R 4.5.1)
 withr            3.0.2    2024-10-28 [1] CRAN (R 4.5.1)
 xfun             0.52     2025-04-02 [1] CRAN (R 4.5.1)
 xtable           1.8-4    2019-04-21 [1] CRAN (R 4.5.1)
 yaml             2.3.5    2022-02-21 [2] CRAN (R 4.2.0)

 [1] /home/jan/R/x86_64-pc-linux-gnu-library/4.5
 [2] /usr/local/lib/R/site-library
 [3] /usr/lib/R/site-library
 [4] /usr/lib/R/library

──────────────────────────────────────────────────────────────────────────────</code></pre>
</div>
</div>


</section>

 ]]></description>
  <category>R</category>
  <category>multiple regression</category>
  <guid>https://janhove.github.io/posts/2021-06-29-posttreatment/</guid>
  <pubDate>Tue, 29 Jun 2021 00:00:00 GMT</pubDate>
  <media:content url="https://janhove.github.io/posts/2021-06-29-posttreatment/image.png" medium="image" type="image/png" height="115" width="144"/>
</item>
<item>
  <title>Quantitative methodology: An introduction</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2020-12-16-quant-meth/</link>
  <description><![CDATA[ 




<p>I’ve taught my last class for the semester and I thought I’d make available the booklet that I wrote for teaching my class on quantitative methodology. You can download it <a href="../../QuantitativeMethodology.pdf">here</a>.</p>
<p>It contains seven reading assignments (mostly empirical studies that serve as examples) and ten chapters with lectures:</p>
<ol type="1">
<li>Association and causality.</li>
<li>Constructing a control group.</li>
<li>Alternative explanations.</li>
<li>Inferential statistics 101. (The course is not a statistics course, but there’s no avoiding talking about p-values given their omnipresence.)</li>
<li>Increasing precision.</li>
<li>Pedagogical interventions.</li>
<li>Within-subjects experiments.</li>
<li>Quasi-experiments and correlational studies.</li>
<li>Constructs and indicators.</li>
<li>Questionable research practices.</li>
</ol>
<p>I’ve also included two appendices:</p>
<ul>
<li>Reading difficult results sections.</li>
<li>Reporting research transparently.</li>
</ul>
<p>Hopefully some of you find it useful, and feel free to let me know what you think.</p>



 ]]></description>
  <category>research design</category>
  <category>teaching materials</category>
  <guid>https://janhove.github.io/posts/2020-12-16-quant-meth/</guid>
  <pubDate>Wed, 16 Dec 2020 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Capitalising on covariates in cluster-randomised experiments</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2020-09-02-cluster-covar-sim/</link>
  <description><![CDATA[ 




<p>In cluster-randomised experiments, participants are assigned to the conditions randomly but not on an individual basis. Instead, entire batches (‘clusters’) of participants are assigned in such a way that each participant in the same cluster is assigned to the same condition. A typical example would be an educational experiment in which all pupils in the same class get assigned to the same experimental condition. Crucially, the analysis should take into account the fact that the random assignment took place at the cluster level rather than at the individual level.</p>
<p>Also typically in educational experiments, researchers have some information about the participants’ performance before the intervention took place. This information can come in the form of a covariate, for instance the participants’ performance on a pretest or some self-assessment of their skills. Even in experiments that use random assignment, including such covariates in the analysis is useful as they help to reduce the error variance. Lots of different methods for including covariates in the analysis of cluster-randomised experiments are discussed in the literature, but I couldn’t find any discussion about the merits and drawbacks of these different methods.</p>
<p>In order to provide such discussion, I ran a series of simulations to compare 25 (!) different ways of including a covariate in the analysis of a cluster-randomised experiment in terms of their Type-I error and their power. The <strong>article</strong> outlining these simulations and the findings is available from <a href="https://doi.org/10.31234/osf.io/ef4zc">PsyArXiv</a>; the <strong>R code</strong> used for the simulations as well as its output is available from the <a href="https://osf.io/wzjra/">Open Science Framework</a>. In the remainder of this post, I’ll discuss how these simulations may be useful to you if you’re planning to run a cluster-randomised experiment.</p>
<section id="so-whats-the-upshot" class="level2">
<h2 class="anchored" data-anchor-id="so-whats-the-upshot">So what’s the upshot?</h2>
<p>Please read pages 1–3 and pages 40–42 of the <a href="https://doi.org/10.31234/osf.io/ef4zc">article</a> :)</p>
</section>
<section id="i-know-of-some-analytical-method-that-you-didnt-consider." class="level2">
<h2 class="anchored" data-anchor-id="i-know-of-some-analytical-method-that-you-didnt-consider.">I know of some analytical method that you didn’t consider.</h2>
<p>Ah, interesting! It took a long time to run these simulations (about 36 hours), during which I couldn’t use my computer for anything else, so I’m not exactly gung-ho about rerunning them just to include one additional analytic method.</p>
<p>But here’s what you can do. Go to the <a href="https://osf.io/wzjra/">OSF page</a> and download the files <code>functions/generate_clustered_data.R</code> and <code>scripts/additional_simulations.Rmd</code>. The latter file contains some smaller-scale simulations that don’t take as long to run. Adapt the simulations there and check if the analytical method you know of has an acceptable Type-I error rate for a variety of parameter settings. (Two examples are available, but if you can’t make sense of them, let me know.) If its Type-I error rate is acceptable, run another batch of simulations to assess its power and compare it to the power for the best-performing methods in my simulation.</p>
<p>If your method compares well to these best-performing methods in terms of both its Type-I error rate and its power, drop me a line, and perhaps I’ll get round to rerunning the large-scale simulations. Better still, download the other functions and scripts, include your method in <code>functions/analyse_clustered_data.R</code>, and adjust the other files accordingly. Then run the simulation yourself :)</p>
</section>
<section id="i-dont-think-your-parameter-choices-are-relevant-for-my-study." class="level2">
<h2 class="anchored" data-anchor-id="i-dont-think-your-parameter-choices-are-relevant-for-my-study.">I don’t think your parameter choices are relevant for my study.</h2>
<p>Perhaps your study will feature clusters that vary more strongly in size than was the case in my simulations. Or perhaps you suspect that the intracluster correlation will be quite different from the ones that I considered. Or perhaps etc., etc., etc. It’d be better if the results of the simulations were more directly relevant to what you suspect your study will look like.</p>
<p>But here’s the beauty. You can go to the <a href="https://osf.io/wzjra/">OSF page</a>, download all the functions and scripts, and tailor the simulation parameters to your liking. In <code>script/simulation_type_I_error.R</code> and <code>script/simulation_power.R</code>, you can change the cluster sizes, the number of clusters, the strength of the covariate, the ICC, the effect, and the randomisation scheme. Then run these scripts and figure out which analysis method will likely retain its nominal Type-I error while maximising power.</p>
</section>
<section id="when-generating-the-data-youre-making-some-assumptions-im-not-willing-to-make." class="level2">
<h2 class="anchored" data-anchor-id="when-generating-the-data-youre-making-some-assumptions-im-not-willing-to-make.">When generating the data, you’re making some assumptions I’m not willing to make.</h2>
<p>The assumptions are outlined in the article on pp.&nbsp;23–24, and they are made more explicit in the function that generates the data (<code>functions/generate_clustered_data.R</code>). Perhaps they’re unrealistic. For instance, the data are all drawn from normal distributions, the covariate is linearly related to the outcome, etc. If you want to revise these assumptions, you’ll have to edit this function. (Test the function extensively afterwards!) Then re-run the simulations, with the simulation parameters tailored to your study.</p>
</section>
<section id="which-journal-will-this-article-be-published-in" class="level2">
<h2 class="anchored" data-anchor-id="which-journal-will-this-article-be-published-in">Which journal will this article be published in?</h2>
<p>At the moment, I don’t intend to submit this article to any journal. The main reason is that anyone who may be interested in it already has free access to it. If anyone has any feedback, I’d be happy to hear it, but I don’t currently feel like jumping through a series of hoops in some drawn-out reviewing process.</p>


</section>

 ]]></description>
  <category>R</category>
  <category>power</category>
  <category>significance</category>
  <category>design features</category>
  <category>cluster-randomised experiments</category>
  <category>preprint</category>
  <guid>https://janhove.github.io/posts/2020-09-02-cluster-covar-sim/</guid>
  <pubDate>Wed, 02 Sep 2020 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Tutorial: Visualising statistical uncertainty using model-based graphs</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2020-06-29-visualise-uncertainty/</link>
  <description><![CDATA[ 




<p>I wrote a tutorial about visualising the statistical uncertainty in statistical models for a conference that took place a couple of months ago, and I’ve just realised that I’ve never advertised this tutorial in this blog. You can find the tutorial here: <a href="https://janhove.github.io/visualise_uncertainty">Visualising statistical uncertainty using model-based graphs</a>.</p>
<p>Contents:</p>
<ol type="1">
<li>Why plot models, and why visualise uncertainty?</li>
<li>The principle: An example with simple linear regression
<ul>
<li>Step 1: Fit the model</li>
<li>Step 2: Compute the conditional means and confidence intervals</li>
<li>Step 3: Plot!</li>
</ul></li>
<li>Predictions about individual cases vs.&nbsp;conditional means</li>
<li>More examples
<ul>
<li>Several continuous predictors</li>
<li>Dealing with categorical predictors</li>
<li>t-tests are models, too</li>
<li>Dealing with interactions</li>
<li>Ordinary logistic regression</li>
<li>Mixed-effects models</li>
<li>Logistic mixed effects models</li>
</ul></li>
<li>Caveats
<ul>
<li>Other things may not be equal</li>
<li>Your model may be misspecified</li>
<li>Other models may yield different pictures</li>
</ul></li>
</ol>



 ]]></description>
  <category>R</category>
  <category>graphs</category>
  <category>logistic regression</category>
  <category>mixed-effects models</category>
  <category>multiple regression</category>
  <category>Bayesian statistics</category>
  <category>brms</category>
  <guid>https://janhove.github.io/posts/2020-06-29-visualise-uncertainty/</guid>
  <pubDate>Mon, 29 Jun 2020 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Interpreting regression models: a reading list</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2020-06-12-stats-course/</link>
  <description><![CDATA[ 




<p>Last semester I taught a class for PhD students and collaborators that focused on how the output of regression models is to be interpreted. Most participants had at least some experience with fitting regression models, but I had noticed that they were often unsure about the precise <em>statistical</em> interpretation of the output of these models (e.g., <em>What does this parameter estimate of 1.2 correspond to in the data?</em>). Moreover, they were usually a bit too eager to move from the model output to a <em>subject-matter</em> interpretation (e.g., <em>What does this parameter estimate of 1.2 tell me about language learning?</em>). I suspect that the same goes for many applied linguists, and social scientists more generally, so below I provide an overview of the course contents as well as the reading list.</p>
<!--more-->
<section id="course-content" class="level2">
<h2 class="anchored" data-anchor-id="course-content">Course content</h2>
<section id="week-1-uses-of-statistical-models-description-vs.-prediction-vs.-inference" class="level3">
<h3 class="anchored" data-anchor-id="week-1-uses-of-statistical-models-description-vs.-prediction-vs.-inference">Week 1: Uses of statistical models: Description vs.&nbsp;prediction vs.&nbsp;inference</h3>
<p>Regression models have three main uses. The first is to describe the data at hand. The difficulty here mostly consists in figuring out what aspects of the data the parameter estimates reflect. Weeks 6, 7, 8 and 11 are devoted to statistical interpretation of model parameters and how variables can be recoded so that the model output aligns more closely with the research questions.</p>
<p>However, the main use of regression models in the social sciences is to draw inferences, usually causal ones. Moving from a descriptive to causal interpretation of a statistical model requires making additional assumptions. Weeks 2 through 5 are devoted to a tool (directed acyclic graphs) that allows you to make explicit the assumptions you’re willing to make about the causal relationships between your variables and that allows you to derive from these assumptions any further permissible causal claims. Another type of inference is the move from observable quantities (e.g., test scores) to unobervables (e.g., language skills). Weeks 10 and 11 are devoted to this topic.</p>
<p>The third use is to use the model to make predictions about new data. This week’s text (Shmueli 2010) explains why a model that has been optimised for making predictions about new data may be all but worthless for inference, and why a model that has been optimised for inference may not yield the best possible predictions. The take-home points are that when planning a research project, you need to be crystal-clear what its main goal is (e.g., causal inference or prediction) and that you should be careful not to assume that a model selected for its predictive power is best-suited for drawing causal conclusions.</p>
<ul>
<li>Text: Shmueli (2010).</li>
<li>Further reading: Breiman (2001); Yarkoni and Westfall (2017).</li>
</ul>
</section>
<section id="week-2-causal-inferences-from-observational-data-i" class="level3">
<h3 class="anchored" data-anchor-id="week-2-causal-inferences-from-observational-data-i">Week 2: Causal inferences from observational data (I)</h3>
<p>The texts for weeks 2 through 5 introduce directed acyclic graphs (DAGs) and go through numerous examples for them. DAGs are useful for identifying the variables that you should control for and the ones you should <em>not</em> control for if you want to estimate some causal relationship in your data. (Some researchers seem to assume that the more variables you control for, the better, but controlling for the wrong variables can mess up your inferences entirely.) This, of course, is most useful when you’re still planning your research project, because otherwise you may find that you need to control for a variable that you didn’t collect, or that you controlled (on purpose or by accident) for a variable you shouldn’t have controlled for.</p>
<ul>
<li>Text: McElreath (2020), Chapter 5.</li>
</ul>
</section>
<section id="week-3-causal-inferences-from-observational-data-ii" class="level3">
<h3 class="anchored" data-anchor-id="week-3-causal-inferences-from-observational-data-ii">Week 3: Causal inferences from observational data (II)</h3>
<ul>
<li>Text: McElreath (2020), Chapter 6.</li>
</ul>
</section>
<section id="week-4-causal-inferences-from-observational-data-iii" class="level3">
<h3 class="anchored" data-anchor-id="week-4-causal-inferences-from-observational-data-iii">Week 4: Causal inferences from observational data (III)</h3>
<ul>
<li>Text: Rohrer (2018).</li>
</ul>
</section>
<section id="week-5-causal-inferences-from-observational-data-iv" class="level3">
<h3 class="anchored" data-anchor-id="week-5-causal-inferences-from-observational-data-iv">Week 5: Causal inferences from observational data (IV)</h3>
<ul>
<li>No obligatory reading.</li>
<li>Further reading: Elwert (2013).</li>
</ul>
</section>
<section id="week-6-understanding-parameter-estimates-i" class="level3">
<h3 class="anchored" data-anchor-id="week-6-understanding-parameter-estimates-i">Week 6: Understanding parameter estimates (I)</h3>
<p>Leaving causal interpretations aside, what do all those numbers in the output of a regression model actually express? DeBruine and Barr (2019) explain how you can analyse simulated datasets to learn which parameter estimates in the simulation correspond to which parameter settings in the simulation set-up.</p>
<p>A related point that I highlighted in class was that the random effect estimates as well as the BLUPs in mixed-effects models should always be interpreted conditionally on the fixed effects in the model. This is true of all estimates in regression models, but people tend to have more difficulties in interpreting random effects and BLUPS. Another point was that you can also gain a better understanding of what the model parameters express by <em>first</em> fitting the model on your data and <em>then</em> having this model predict new data. By figuring out how the model came up with these predictions, you learn what each parameter estimate literally means.</p>
<ul>
<li>Text: DeBruine and Barr (2019).</li>
</ul>
</section>
<section id="week-7-understanding-parameter-estimates-ii" class="level3">
<h3 class="anchored" data-anchor-id="week-7-understanding-parameter-estimates-ii">Week 7: Understanding parameter estimates (II)</h3>
<p>Weeks 7 and 8 were devoted to contrast coding, i.e., how you can recode non-numeric predictors such that the model’s output aligns more closely with what you want to know. I’ve recently <a href="../2020-05-05-contrast-coding">blogged</a> about contrast coding, and I was surprised I didn’t learn about this useful technique until 2020 (of all years).</p>
<ul>
<li>Text: Schad et al.&nbsp;(2020), up to and including the section <em>What makes a good set of contrasts?</em></li>
</ul>
</section>
<section id="week-8-understanding-parameter-estimates-iii" class="level3">
<h3 class="anchored" data-anchor-id="week-8-understanding-parameter-estimates-iii">Week 8: Understanding parameter estimates (III)</h3>
<ul>
<li>No obligatory reading.</li>
<li>Further reading: Schad et al.&nbsp;(2020), from the section <em>A closer look at hypothesis and contrast matrices</em>.</li>
</ul>
</section>
<section id="week-9-consequences-of-measurement-error-i" class="level3">
<h3 class="anchored" data-anchor-id="week-9-consequences-of-measurement-error-i">Week 9: Consequences of measurement error (I)</h3>
<p>The measured variables included in a model are often but approximations of what is actually of interest. For instance, you may be interested in the learners’ L2 skills, but what you’ve measured is their performance on an L2 test. The test results will only approximately reflect the learners’ true skills. Interpreting the output of a model, which may be valid at the level of the observed variables, in terms of such unobserved but inferred constructs is fraught with difficulties that researchers and consumers of research need to be aware of.</p>
<p>The reading for week 9 deals with some consequences of measurement error on a predictor variable. The reading of week 10 doesn’t strictly deal with measurement error but with the mapping of the observed outcome variable on the unobserved construct of interest and how it affects the interpretation of interactions.</p>
<ul>
<li>Text: Westfall and Yarkoni (2016).</li>
<li>Further reading: Berthele and Vanhove (2020).</li>
</ul>
</section>
<section id="week-10-consequences-of-measurement-error-ii" class="level3">
<h3 class="anchored" data-anchor-id="week-10-consequences-of-measurement-error-ii">Week 10: Consequences of measurement error (II)</h3>
<ul>
<li>Text: Wagenmakers et al.&nbsp;(2012).</li>
<li>Further reading: Wagenmakers (2015).</li>
</ul>
</section>
<section id="week-11-understanding-parameter-estimates-iv" class="level3">
<h3 class="anchored" data-anchor-id="week-11-understanding-parameter-estimates-iv">Week 11: Understanding parameter estimates (IV)</h3>
<p>Logistic regression models can be difficult to understand, and the linear probability model (i.e., ordinary linear regression) isn’t to be dismissed out of hand when working with binary data. A related blog post is <a href="../2019-08-07-interactions-logistic"><em>Interactions in logistic regression models</em></a>.</p>
<ul>
<li>Text: Huang (2019).</li>
</ul>
</section>
<section id="week-12-translating-verbal-research-questions-into-quantitative-hypotheses" class="level3">
<h3 class="anchored" data-anchor-id="week-12-translating-verbal-research-questions-into-quantitative-hypotheses">Week 12: Translating verbal research questions into quantitative hypotheses</h3>
<p>In week 12 I went through some examples of verbal research questions or hypotheses that at first blush seem pretty well delineated. On closer inspection, however, it becomes clear that radically different patterns in the data would yield the same answer to these questions, and that the research questions or hypotheses were, in fact, underspecified. Drawing several possible data patterns and interpreting them in light of your literal research question or hypothesis can help you rephrase that question or hypothesis less ambiguously.</p>
<p>No texts.</p>
</section>
<section id="week-13-ascension-no-class" class="level3">
<h3 class="anchored" data-anchor-id="week-13-ascension-no-class">Week 13: Ascension (no class)</h3>
</section>
<section id="week-14-take-home-points-working-reproducibly" class="level3">
<h3 class="anchored" data-anchor-id="week-14-take-home-points-working-reproducibly">Week 14: Take-home points + working reproducibly</h3>
<p>For the last week, I stressed the following take-home points from this course:</p>
<ul>
<li>Be crystal-clear about the main aim of your statistical model: Describing the data, predicting new data, or drawing inferences about causality or unobserved phenomena? Plan accordingly by identifying the factors that must be controlled for and those that mustn’t be controlled for.</li>
<li>Anticipate the consequences of measurement error. If measurement error could mess up the interpretation of the results, try to collect several indictators of the constructs of interest and adopt a latent variable approach.</li>
<li>Outline <em>precisely</em> how you’d interpret the possible patterns in the data in terms of your research question.</li>
<li>If a regression model is necessary, recode your predictors so that you can interpret the parameter estimates directly in terms of your research question.</li>
<li>Analyse simulated data if you’re unsure what the model’s parameter estimates correspond to.</li>
<li>Keep in mind that parameter estimates are always to be interpreted conditionally on the other predictors in the model. I suspect that lots of counterintuitive findings stem from researchers interpreting their parameter estimates unconditionally.</li>
</ul>
<p>I also showed how you can make your analyses reproducible by working with <a href="https://r4ds.had.co.nz/workflow-projects.html">RStudio projects</a>, the <a href="https://cran.r-project.org/web/packages/here/index.html">here package</a>, and R Markdown.</p>
<p>No texts.</p>
</section>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<p>Berthele, Raphael and Jan Vanhove. 2020. <a href="https://doi.org/10.1080/13670050.2017.1385590">What would disprove interdependence? Lessons learned from a study on biliteracy in Portuguese heritage language speakers in Switzerland</a>. <em>International Journal of Bilingual Education and Bilingualism</em> 23(5). 550-566.</p>
<p>Breiman, Leo. 2001. Statistical modeling: The two cultures. <em>Statistical Science</em> 16. 199-215.</p>
<p>DeBruine, Lisa M. &amp; Dale J. Barr. 2019. <a href="https://doi.org/10.31234/osf.io/xp5cy">Understanding mixed effects models through data simulation</a>. PsyArXiv.</p>
<p>Elwert, Felix. 2013. Graphical causal models. In S. L. Morgan (ed.), <em>Handbook of Causal Analysis for Social Research</em>, pp.&nbsp;245-273. Dordrecht, The Netherlands: Springer.</p>
<p>Huang, Francis L. 2019. <a href="https://doi.org/10.1080/00220973.2019.1699769">Alternatives to logistic regression models in experimental studies</a>. <em>Journal of Experimental Education</em>.</p>
<p>McElreath, Richard. 2020. <em>Statistical rethinking: A Bayesian course with examples in R and Stan</em>, 2nd edn. Boca Raton, FL: CRC Press.</p>
<p>Rohrer, Julia. 2018. <a href="https://doi.org/10.1177%2F2515245917745629">Thinking clearly about correlations and causation: Graphical causal models for observational data</a>. <em>Advances in Methods and Practices in Psychological Science</em> 1(1). 27-42.</p>
<p>Schad, Daniel J., Shravan Vasishth, Sven Hohenstein and Reinhold Kliegl. 2020. <a href="https://doi.org/10.1016/j.jml.2019.104038">How to capitalize on a priori contrasts in linear (mixed) models: A tutorial</a>. <em>Journal of Memory and Language</em> 110.</p>
<p>Shmueli, Galit. 2010. <a href="https://www.stat.berkeley.edu/~aldous/157/Papers/shmueli.pdf">To explain or to predict?</a> <em>Statistical Science</em> 25. 289-310.</p>
<p>Wagenmakers, Eric-Jan.&nbsp;2015. <a href="https://doi.org/10.1016/j.cortex.2015.07.031">A quartet of interactions</a>. <em>Cortex</em> 73. 334-335.</p>
<p>Wagenmakers, Eric-Jan, Angelos-Miltiadis Krypotos, Amy H. Criss and Geoff Iverson. 2012. <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3267935/">On the interpretation of removable interactions: A survey of the field 33 years after Lotus</a>. <em>Memory &amp; Cognition</em> 40. 145-160.</p>
<p>Westfall, Jacob and Tal Yarkoni. 2016. <a href="https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0152719">Statistically controlling for confounding constructs is harder than you think</a>. <em>PLoS ONE</em> 11(3). e0152719.</p>
<p>Yarkoni, Tal and Jacob Westfall. 2017. <a href="http://jakewestfall.org/publications/Yarkoni_Westfall_choosing_prediction.pdf">Choosing prediction over explanation in psychology: Lessons from machine learning</a>. <em>Perspectives on Psychological Science</em> 12. 1100-1122.</p>


</section>

 ]]></description>
  <category>measurement error</category>
  <category>logistic regression</category>
  <category>correlational studies</category>
  <category>mixed-effects models</category>
  <category>multiple regression</category>
  <category>predictive modelling</category>
  <category>research questions</category>
  <category>contrast coding</category>
  <category>reliability</category>
  <guid>https://janhove.github.io/posts/2020-06-12-stats-course/</guid>
  <pubDate>Fri, 12 Jun 2020 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Tutorial: Obtaining directly interpretable regression coefficients by recoding categorical predictors</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2020-05-05-contrast-coding/</link>
  <description><![CDATA[ 




<p>The output of regression models is often difficult to parse, especially when categorical predictors and interactions between them are being modelled. The goal of this tutorial is to show you how you can obtain estimated coefficients that you can interpret directly in terms of your research question. I’ve learnt about this technique thanks to Schad et al.&nbsp;(2020), and I refer to them for a more detailed discussion. What I will do is go through three examples of increasing complexity that should enable you to apply the technique in your own analyses.</p>
<!--more-->
<section id="example-1-no-interactions-no-random-effects" class="level2">
<h2 class="anchored" data-anchor-id="example-1-no-interactions-no-random-effects">Example 1: No interactions, no random effects</h2>
<p>Let’s start off nice but not too easy by analysing an experiment with three conditions and only one observation per participant.</p>
<p>This dataset we’ll work with comes from a study by Vanhove (2019) and is available <a href="http://homeweb.unifr.ch/VanhoveJ/Pub/Data/Vanhove2018.csv">here</a>. The details hardly matter, but there were three experimental conditions: <code>information</code>, <code>no information</code> and <code>strategy</code>. The <code>no information</code> condition serves as the baseline control condition, and the <code>information</code> and <code>strategy</code> conditions serve as the treatment conditions. The expectation was that the treatment conditions would outperform the control condition on the outcome variable (here: <code>ProportionCongruent</code>), and I was also interested in seeing if the <code>strategy</code> condition outperformed the <code>information</code> condition.</p>
<p>The condition means already show that the participants in the <code>information</code> condition did not in fact outperform those in the <code>no information</code> condition, but neither that nor the small sample size should keep us from using these data for our example.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read.csv</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"http://homeweb.unifr.ch/VanhoveJ/Pub/Data/Vanhove2018.csv"</span>)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Condition)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>
   information no information       strategy 
            15             14             16 </code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tapply</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ProportionCongruent, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Condition, mean)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>   information no information       strategy 
         0.517          0.554          0.627 </code></pre>
</div>
</div>
<p>If we fit the model directly, R will apply the default coding scheme to the categorical predictor (viz., treatment coding):</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># The newest version of R doesn't recode strings as factors automatically,</span></span>
<span id="cb5-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># so code Condition as a factor for good measure.</span></span>
<span id="cb5-3">d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Condition <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Condition)</span>
<span id="cb5-4">m_default <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(ProportionCongruent <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Condition, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d)</span>
<span id="cb5-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(m_default)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>                        Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)               0.5172     0.0512  10.101 8.31e-13
Conditionno information   0.0369     0.0737   0.501 6.19e-01
Conditionstrategy         0.1099     0.0713   1.542 1.31e-01</code></pre>
</div>
</div>
<p>By default, the <code>information</code> condition is chosen as the reference level because it’s first in the alphabet. That is, the 0.52 is the estimated mean for the <code>information</code> condition. The second estimate (0.04) is the difference between the mean for the <code>no information</code> condition and that of the reference level (<code>information</code>). Similarly, the third estimate (0.11) is the difference between the mean for the <code>strategy</code> condition and that of the reference level (<code>information</code>). These estimates are all correct, and they’re fairly easy to interpret once you’ve figured out what the reference level is. But if we want to, we can obtain estimated coefficients that map more directly onto the research questions by recoding the <code>Condition</code> variable manually.</p>
<p><code>Condition</code> has three levels, and this means that we can obtain at most three estimated coefficients for it. It’s also possible to obtain fewer than the maximum, but this is not something I will go into here.</p>
<p>The first step is to <strong>write out what you want the model’s intercept to represent</strong> as a null hypothesis. In this example, it makes sense that the intercept should the mean performance in the <code>no information</code> condition. Written as a null hypothesis, this becomes <img src="https://latex.codecogs.com/png.latex?%5Cmu_%7B%5Ctextrm%7Bno%20info%7D%7D%20=%200">. This null hypothesis is a bit silly, but that’s not important here, just go with it; the equation is easy enough. Then, <strong>rearrange the equation such that the right-hand side reads 0.</strong> This is already the case here. Finally, <strong>add the factor’s remaining levels to the left-hand side of the equation, but multiplied by 0</strong>. You’re just adding 0s to the left-hand side of the equation, which doesn’t affect it. For clarity, I’ve made it clear that <img src="https://latex.codecogs.com/png.latex?%5Cmu_%7B%5Ctextrm%7Bno%20info%7D%7D%20=%201%5Cmu_%7B%5Ctextrm%7Bno%20info%7D%7D">. The result looks like this:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_%7B%5Ctextrm%7Bno%20info%7D%7D%20=%200%20%5C%5C%20%5CLeftrightarrow%200%5Cmu_%7B%5Ctextrm%7Binfo%7D%7D%20+%201%5Cmu_%7B%5Ctextrm%7Bno%20info%7D%7D%20+%200%5Cmu_%7B%5Ctextrm%7Bstrategy%7D%7D%20=%200%0A"></p>
<p>Make sure that in the rearranged equation, the levels appear <em>in the same order</em> as they do in R. You can check the order of the levels using <code>levels()</code>. By default, the order is alphabetical. You can change the order of the factor levels, but then you’ll also need to change the order in which the coefficients appear in the rearranged equation:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Condition)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "information"    "no information" "strategy"      </code></pre>
</div>
</div>
<p>The second step is to <strong>write out null hypotheses for the comparisons that you want the remaining coefficients to estimate</strong>. For the sake of the exercise, let’s say that I want the first remaining coefficient to estimate the difference between the mean of the control group (<img src="https://latex.codecogs.com/png.latex?%5Cmu_%7B%5Ctextrm%7Bno%20info%7D%7D">) and the <em>mean of the means</em> of the two other groups (i.e., <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B2%7D(%5Cmu_%7B%5Ctextrm%7Binfo%7D%7D%20+%20%5Cmu_%7B%5Ctextrm%7Bstrategy%7D%7D)">). First write this as a null hypothesis:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B1%7D%7B2%7D(%5Cmu_%7B%5Ctextrm%7Binfo%7D%7D%20+%20%5Cmu_%7B%5Ctextrm%7Bstrategy%7D%7D)%20=%20%5Cmu_%7B%5Ctextrm%7Bno%20info%7D%7D%0A"></p>
<p>Note that I write the ‘focus’ of the comparison on the left-hand side and what it’s being compared to on the right-hand side. This will make the signs of the coefficients we later get easier to interpret. Then, bring all <img src="https://latex.codecogs.com/png.latex?%5Cmu"> terms to the left-hand side:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B1%7D%7B2%7D(%5Cmu_%7B%5Ctextrm%7Binfo%7D%7D%20+%20%5Cmu_%7B%5Ctextrm%7Bstrategy%7D%7D)%20=%20%5Cmu_%7B%5Ctextrm%7Bno%20info%7D%7D%20%5C%5C%20%5CLeftrightarrow%20%5Cfrac%7B1%7D%7B2%7D%5Cmu_%7B%5Ctextrm%7Binfo%7D%7D%20+%20-1%5Cmu_%7B%5Ctextrm%7Bno%20info%7D%7D%20+%20%5Cfrac%7B1%7D%7B2%7D%5Cmu_%7B%5Ctextrm%7Bstrategy%7D%7D%20=%200%0A"></p>
<p>Do not multiply any terms in the equation, i.e., do <em>not</em> write <img src="https://latex.codecogs.com/png.latex?1%5Cmu_%7B%5Crm%7Binfo%7D%7D%20+%20-2%5Cmu_%7B%5Crm%7Bno%5C%20info%7D%7D%20+%201%5Cmu_%7B%5Crm%7Bstrategy%7D%7D%20=%200"> so that you don’t have to work with fractions. The hypotheses you’ll test will be the same, but the output will be more confusing than if you just rearrange the coefficients but keep the fractions.</p>
<p>For the final coefficient, let’s say that I want to estimate the difference in means between the <code>info</code> and <code>strategy</code> condition. Again, start from the corresponding null hypothesis (i.e., that these means are the same), and then bring all <img src="https://latex.codecogs.com/png.latex?%5Cmu">s to the left-hand side while adding the missing factor levels:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_%7B%5Ctextrm%7Bstrategy%7D%7D%20=%20%5Cmu_%7B%5Ctextrm%7Binfo%7D%7D%20%5C%5C%5CLeftrightarrow%20-1%5Cmu_%7B%5Ctextrm%7Binfo%7D%7D%20+%200%5Cmu_%7B%5Ctextrm%7Bno%20info%7D%7D%20+%201%5Cmu_%7B%5Ctextrm%7Bstrategy%7D%7D%20=%200%0A"></p>
<p>The third step is to put the coefficients of the rearranged equations into a <strong>hypothesis matrix</strong>. As you can see, each line in this matrix contains the coefficients belonging to the <img src="https://latex.codecogs.com/png.latex?%5Cmu"> terms in the three equations above:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">Hm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(</span>
<span id="cb9-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">H00 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">info =</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;">no_info =</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;">strategy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb9-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">H01 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">info =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">no_info =</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="at" style="color: #657422;
background-color: null;
font-style: inherit;">strategy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb9-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">H02 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">info =</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="at" style="color: #657422;
background-color: null;
font-style: inherit;">no_info =</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;">strategy =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb9-5">)</span></code></pre></div></div>
</div>
<p>Fourth, convert this hypothesis matrix into a <strong>contrast matrix</strong> using the <code>ginv2()</code> function that Schad et al.&nbsp;(2020) provide:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">ginv2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) {</span>
<span id="cb10-2">    MASS<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fractions</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">provideDimnames</span>(MASS<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ginv</span>(x), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dimnames</span>(x)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]))</span>
<span id="cb10-3">}</span>
<span id="cb10-4"></span>
<span id="cb10-5">Cm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ginv2</span>(Hm)</span></code></pre></div></div>
</div>
<p>Fifth, apply this contrast matrix, minus the first column (hence <code>-1</code>), as the coding scheme for <code>Condition</code>:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contrasts</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Condition) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> Cm[, <span 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></code></pre></div></div>
</div>
<p>And finally, fit the model:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">m_manual <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(ProportionCongruent <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Condition, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d)</span>
<span id="cb12-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(m_manual)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>             Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)     0.554     0.0530  10.455 2.92e-13
ConditionH01    0.018     0.0639   0.282 7.79e-01
ConditionH02    0.110     0.0713   1.542 1.31e-01</code></pre>
</div>
</div>
<p>You can check this yourselves, but the intercept now shows the mean of the <code>no information</code> condition, the first term (<code>ConditionH01</code>) estimates the difference between the <code>no information</code> mean and the mean of the means of the other two condidition, and the second term (<code>ConditionH02</code>) estimates the difference between the <code>strategy</code> mean and the <code>information</code> mean.</p>
</section>
<section id="example-2-no-interactions-but-random-effects" class="level2">
<h2 class="anchored" data-anchor-id="example-2-no-interactions-but-random-effects">Example 2: No interactions, but random effects</h2>
<p>For the second and third example, I’ll use data from Pestana et al.&nbsp;(2018), who measured the Portuguese reading skills of Portuguese children in Portugal, French-speaking Switzerland, and German-speaking Switzerland at three points in time. The data are available as part of the <a href="https://github.com/janhove/helascot"><code>helascot</code> package</a>.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(helascot)</span>
<span id="cb14-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb14-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(lme4)</span>
<span id="cb14-4"></span>
<span id="cb14-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Combine data and only retain Portuguese test data</span></span>
<span id="cb14-6">d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> skills <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb14-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(background, <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;">"Subject"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb14-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(LanguageTested <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;">"Portuguese"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb14-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(Reading))</span>
<span id="cb14-10"></span>
<span id="cb14-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Code Time and LanguageGroup as factors</span></span>
<span id="cb14-12">d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Time <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Time)</span>
<span id="cb14-13">d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>LanguageGroup <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>LanguageGroup)</span>
<span id="cb14-14"></span>
<span id="cb14-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Draw graph</span></span>
<span id="cb14-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d,</span>
<span id="cb14-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> Time, </span>
<span id="cb14-18">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> Reading,</span>
<span id="cb14-19">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> LanguageGroup)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb14-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>()</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-05-05-contrast-coding/index_files/figure-html/unnamed-chunk-9-1.svg" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
<p>There are up to three observations per child (Time 1, 2 and 3), and the children are clustered in classes. We will take this into account during the analysis using random effects by child and by class.</p>
<p>For the sake of this example, let’s say we’re interested in estimating the development of reading skills through time. The following model estimates the effect of <code>Time</code> and allows for this effect to vary between classes. Since there is only one data point per <code>Subject</code> per <code>Time</code>, no by-subject random slope for <code>Time</code> was estimated.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1">m_default <span class="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>(Reading <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Time <span 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>Time<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span>Class) <span 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>Subject), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d)</span>
<span id="cb15-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(m_default)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value
(Intercept)    0.532     0.0239   22.25
Time2          0.104     0.0111    9.38
Time3          0.194     0.0161   12.08</code></pre>
</div>
</div>
<p>When using R’s default coding, the <code>(Intercept)</code> represents the average reading skill score at Time 1, the next coefficient estimates the different in reading skill scores between Time 2 and Time 1, and the third coefficient estimates the difference between Time 3 and Time 1. This is fine, but let’s say we wanted to estimate the difference between Time 3 and Time 2 directly. We can obtain this estimate by coding the predictors ourselves.</p>
<p>In the equations below, the <img src="https://latex.codecogs.com/png.latex?%5Cmu">’s are in the same order as R knows them:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Time)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "1" "2" "3"</code></pre>
</div>
</div>
<p>The average performance at Time 1 is a reasonable choice for the intercept, so let’s stick with that. The silly null hypothesis is that <img src="https://latex.codecogs.com/png.latex?%5Cmu_%7BT1%7D%20=%200">, which we can elaborate with <img src="https://latex.codecogs.com/png.latex?%5Cmu_%7BT2%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Cmu_%7BT3%7D"> as follows:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_%7BT1%7D%20=%200%20%5C%5C%20%5CLeftrightarrow%201%5Cmu_%7BT1%7D%20+%200%5Cmu_%7BT2%7D%20+%200%5Cmu_%7BT3%7D%20=%200%0A"></p>
<p>If we want the next coefficient to estimate the difference between the average reading skill scores at Time 2 and Time 1, we need the null hypothesis that these average reading skill scores are the same, i.e., <img src="https://latex.codecogs.com/png.latex?%5Cmu_%7BT2%7D%20=%20%5Cmu_%7BT1%7D">. (Remember to put the ‘focus’ of the comparison on the left.) From there:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_%7BT2%7D%20=%20%5Cmu_%7BT1%7D%20%5C%5C%20%5CLeftrightarrow%20-1%5Cmu_%7BT1%7D%20+%201%5Cmu_%7BT2%7D%20+%200%5Cmu_%7BT3%7D%20=%200%0A"></p>
<p>Similarly, if we want the third coefficient to estimate the difference between the average reading skill scores at Time 3 and Time 2, we need the null hypothesis that these average reading skill scores are the same, i.e., <img src="https://latex.codecogs.com/png.latex?%5Cmu_%7BT3%7D%20=%20%5Cmu_%7BT2%7D">:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_%7BT3%7D%20=%20%5Cmu_%7BT2%7D%20%5C%5C%20%5CLeftrightarrow%200%5Cmu_%7BT1%7D%20+%20-1%5Cmu_%7BT2%7D%20+%201%5Cmu_%7BT3%7D%20=%200%0A"></p>
<p>Put the coefficients in the hypothesis matrix, convert this hypothesis matrix to a contrast matrix, apply this contrast matrix to the factor <code>Time</code>, and refit the model.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Put coefficients in hypothesis matrix</span></span>
<span id="cb19-2">Hm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">H00 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">T1 =</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;">T2 =</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;">T3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb19-3">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">H01 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">T1 =</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="at" style="color: #657422;
background-color: null;
font-style: inherit;">T2 =</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;">T3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb19-4">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">H02 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">T1 =</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;">T2 =</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="at" style="color: #657422;
background-color: null;
font-style: inherit;">T3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb19-5"></span>
<span id="cb19-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Convert to contrast matrix</span></span>
<span id="cb19-7">Cm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ginv2</span>(Hm)</span>
<span id="cb19-8"></span>
<span id="cb19-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># I'm going to copy Time so we can reuse it in example 3:</span></span>
<span id="cb19-10">d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Time2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Time</span>
<span id="cb19-11"></span>
<span id="cb19-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Apply contrast matrix to factor</span></span>
<span id="cb19-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contrasts</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Time2) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> Cm[, <span 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="cb19-14"></span>
<span id="cb19-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Refit model</span></span>
<span id="cb19-16">m_manual <span class="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>(Reading <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Time2 <span 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>Time2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span>Class) <span 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>Subject), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d)</span>
<span id="cb19-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(m_manual)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value
(Intercept)   0.5317     0.0239   22.25
Time2H01      0.1040     0.0111    9.38
Time2H02      0.0904     0.0137    6.59</code></pre>
</div>
</div>
<p>As you can see, the third coefficient now estimates the difference between the average reading skill score at T3 and at T2. Compared to manually computing this difference from the first model’s output, the main advantage of coding the predictors yourself is that you also obtain a measure of the uncertainty about the estimate of interest (e.g., the standard error, or a confidence interval).</p>
</section>
<section id="example-3-interactions-and-random-effects" class="level2">
<h2 class="anchored" data-anchor-id="example-3-interactions-and-random-effects">Example 3: Interactions and random effects</h2>
<p>Finally, let’s take a look at interactions. Still working with the dataset from the second example, we can fit a model that contains an interaction between <code>Time</code> and <code>LanguageGroup</code>, i.e., that allows the effect of <code>Time</code> to differ between the three language groups. Since <code>Time</code> varies within <code>Class</code>, but <code>LanguageGroup</code> doesn’t, we can’t estimate a by-class random slope for <code>Language Group</code>. I’m going to ignore the warning about the singular fit here, because it isn’t related to the topic of the tutorial and I don’t have too many other datasets where interactions need to be modelled.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1">m_default <span class="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>(Reading <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Time<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>LanguageGroup <span 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>Time<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span>Class) <span 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>Subject), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>boundary (singular) fit: see help('isSingular')</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(m_default)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>                                            Estimate Std. Error t value
(Intercept)                                   0.5422     0.0233  23.282
Time2                                         0.1159     0.0198   5.850
Time3                                         0.1915     0.0279   6.859
LanguageGroupBilingual group German          -0.0893     0.0316  -2.822
LanguageGroupControl group Portuguese         0.1316     0.0373   3.532
Time2:LanguageGroupBilingual group German    -0.0196     0.0272  -0.720
Time3:LanguageGroupBilingual group German     0.0164     0.0373   0.440
Time2:LanguageGroupControl group Portuguese  -0.0121     0.0309  -0.390
Time3:LanguageGroupControl group Portuguese  -0.0287     0.0451  -0.636</code></pre>
</div>
</div>
<p>I’m not going to go over the interpretation of all of these coefficients; the point is that they’re not too informative, but that we can obtain more useful estimates by recoding the predictors. To do that, I prefer to <strong>combine the combinations of the factors involved in the interaction into a single variable</strong>, which I’ll call <code>Cell</code>:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Combine combinations of Time and Language group into 1 factor</span></span>
<span id="cb25-2">d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Cell <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Time, d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>LanguageGroup))</span>
<span id="cb25-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Cell)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>
  1 Bilingual group French   1 Bilingual group German 
                       104                        104 
1 Control group Portuguese   2 Bilingual group French 
                        74                        105 
  2 Bilingual group German 2 Control group Portuguese 
                        97                         75 
  3 Bilingual group French   3 Bilingual group German 
                       105                         93 
3 Control group Portuguese 
                        69 </code></pre>
</div>
</div>
<p>We will eventually need to refer to these cells in the same order as they’re known in R:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Order of the factor levels</span></span>
<span id="cb27-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Cell)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "1 Bilingual group French"   "1 Bilingual group German"  
[3] "1 Control group Portuguese" "2 Bilingual group French"  
[5] "2 Bilingual group German"   "2 Control group Portuguese"
[7] "3 Bilingual group French"   "3 Bilingual group German"  
[9] "3 Control group Portuguese"</code></pre>
</div>
</div>
<p>Let’s think about what we want our estimates to mean. I think it would make sense for the intercept to represent the mean reading skill score at Time 1 across the three language groups. Then, I’d like for the next coefficients to express the average progress (across language groups) from Time 1 to Time 2 and from Time 2 to Time 3. Next, I’d like to know, at each time point, what the average difference between the Portuguese and the bilingual (Swiss) children is, and what the average difference between the Portuguese-French and the Portuguese-German bilinguals is.</p>
<p>Now, in what follows, you’re going to see some fairly long equations. They may look daunting, but they’re really easy: like before, we’re going to express what we want the coefficients to mean as null hypotheses. It’s just that this time we have to include nine <img src="https://latex.codecogs.com/png.latex?%5Cmu">’s per equation.</p>
<ol type="1">
<li>The intercept represents the grand mean of the Time 1 cells. The silly corresponding null hypothesis is that this grand mean is 0: <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B3%7D(%5Cmu_%7B1,F%7D%20+%20%5Cmu_%7B1,G%7D%20+%20%5Cmu_%7B1,P%7D)%20=%200">.</li>
</ol>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B1%7D%7B3%7D(%5Cmu_%7B1,F%7D%20+%20%5Cmu_%7B1,G%7D%20+%20%5Cmu_%7B1,P%7D)%20=%200%20%5C%5C%5CLeftrightarrow%20%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B1,F%7D%20+%20%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B1,G%7D%20+%20%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B1,P%7D%20+%200%5Cmu_%7B2,F%7D%20+%200%5Cmu_%7B2,G%7D%20+%200%5Cmu_%7B2,P%7D%20+%200%5Cmu_%7B3,F%7D%20+%200%5Cmu_%7B3,G%7D%20+%200%5Cmu_%7B3,P%7D%20=%200%0A"></p>
<ol start="2" type="1">
<li>The next term represents the difference between the grand mean of the Time 2 cells and that of the Time 1 cells:</li>
</ol>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B1%7D%7B3%7D(%5Cmu_%7B2,F%7D%20+%20%5Cmu_%7B2,G%7D%20+%20%5Cmu_%7B2,P%7D)%20=%20%5Cfrac%7B1%7D%7B3%7D(%5Cmu_%7B1,F%7D%20+%20%5Cmu_%7B1,G%7D%20+%20%5Cmu_%7B1,P%7D)%20%5C%5C%5CLeftrightarrow%20-%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B1,F%7D%20+%20-%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B1,G%7D%20+%20-%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B1,P%7D%20+%20%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B2,F%7D%20+%20%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B2,G%7D%20+%20%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B2,P%7D%20+%200%5Cmu_%7B3,F%7D%20+%200%5Cmu_%7B3,G%7D%20+%200%5Cmu_%7B3,P%7D%20=%200%0A"></p>
<ol start="3" type="1">
<li>The third term represents the difference between the grand mean of the Time 3 cells and that of the Time 2 cells:</li>
</ol>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B1%7D%7B3%7D(%5Cmu_%7B3,F%7D%20+%20%5Cmu_%7B3,G%7D%20+%20%5Cmu_%7B3,P%7D)%20=%20%5Cfrac%7B1%7D%7B3%7D(%5Cmu_%7B2,F%7D%20+%20%5Cmu_%7B2,G%7D%20+%20%5Cmu_%7B2,P%7D)%20%5C%5C%5CLeftrightarrow%200%5Cmu_%7B1,F%7D%20+%200%5Cmu_%7B1,G%7D%20+%200%5Cmu_%7B1,P%7D%20+%20-%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B2,F%7D%20+%20-%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B2,G%7D%20+%20-%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B2,P%7D%20+%20%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B3,F%7D%20+%20%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B3,G%7D%20+%20%5Cfrac%7B1%7D%7B3%7D%5Cmu_%7B3,P%7D%20=%200%0A"></p>
<p>Now for comparisons between the language groups at each point in time. For each time, I want a term testing if the Portuguese on the one hand and the French- and German-speaking pupils on the other hand perform the same as well as one if the French- and German-speaking pupils differ amongst themselves.</p>
<ol start="4" type="1">
<li>The fourth term represents the difference between the mean of the Portuguese scores at Time 1 and the grand mean of the two bilingual groups’ performance at Time 1:</li>
</ol>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_%7B1,P%7D%20=%20%5Cfrac%7B1%7D%7B2%7D(%5Cmu_%7B1,F%7D%20+%20%5Cmu_%7B1,G%7D)%20%5C%5C%5CLeftrightarrow%20-%5Cfrac%7B1%7D%7B2%7D%5Cmu_%7B1,F%7D%20+%20-%5Cfrac%7B1%7D%7B2%7D%5Cmu_%7B1,G%7D%20+%201%5Cmu_%7B1,P%7D%20+%200%5Cmu_%7B2,F%7D%20+%200%5Cmu_%7B2,G%7D%20+%200%5Cmu_%7B2,P%7D%20+%200%5Cmu_%7B3,F%7D%20+%200%5Cmu_%7B3,G%7D%20+%200%5Cmu_%7B3,P%7D%20=%200%0A"></p>
<ol start="5" type="1">
<li>The fifth term represents the difference between the two bilingual groups at Time 1:</li>
</ol>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_%7B1,F%7D%20=%5Cmu_%7B1,G%7D%20%5C%5C%5CLeftrightarrow%201%5Cmu_%7B1,F%7D%20+%20-1%5Cmu_%7B1,G%7D%20+%200%5Cmu_%7B1,P%7D%20+%200%5Cmu_%7B2,F%7D%20+%200%5Cmu_%7B2,G%7D%20+%200%5Cmu_%7B2,P%7D%20+%200%5Cmu_%7B3,F%7D%20+%200%5Cmu_%7B3,G%7D%20+%200%5Cmu_%7B3,P%7D%20=%200%0A"></p>
<ol start="6" type="1">
<li>Same as the fourth term, but for Time 2.</li>
</ol>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_%7B2,P%7D%20=%20%5Cfrac%7B1%7D%7B2%7D(%5Cmu_%7B2,F%7D%20+%20%5Cmu_%7B2,G%7D)%20%5C%5C%5CLeftrightarrow%200%5Cmu_%7B1,F%7D%20+%200%5Cmu_%7B1,G%7D%20+%200%5Cmu_%7B1,P%7D%20+%20-%5Cfrac%7B1%7D%7B2%7D%5Cmu_%7B2,F%7D%20+%20-%5Cfrac%7B1%7D%7B2%7D%5Cmu_%7B2,G%7D%20+%201%5Cmu_%7B2,P%7D%20+%200%5Cmu_%7B3,F%7D%20+%200%5Cmu_%7B3,G%7D%20+%200%5Cmu_%7B3,P%7D%20=%200%0A"></p>
<ol start="7" type="1">
<li>Same as the fifth term, but for Time 2.</li>
</ol>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_%7B2,F%7D%20=%5Cmu_%7B2,G%7D%20%5C%5C%5CLeftrightarrow%200%5Cmu_%7B1,F%7D%20+%200%5Cmu_%7B1,G%7D%20+%200%5Cmu_%7B1,P%7D%20+%201%5Cmu_%7B2,F%7D%20+%20-1%5Cmu_%7B2,G%7D%20+%200%5Cmu_%7B2,P%7D%20+%200%5Cmu_%7B3,F%7D%20+%200%5Cmu_%7B3,G%7D%20+%200%5Cmu_%7B3,P%7D%20=%200%0A"></p>
<ol start="8" type="1">
<li>Same as the fourth and sixth terms, but for Time 3.</li>
</ol>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_%7B3,P%7D%20=%20%5Cfrac%7B1%7D%7B2%7D(%5Cmu_%7B3,F%7D%20+%20%5Cmu_%7B3,G%7D)%20%5C%5C%5CLeftrightarrow%200%5Cmu_%7B1,F%7D%20+%200%5Cmu_%7B1,G%7D%20+%200%5Cmu_%7B1,P%7D%20+%200%5Cmu_%7B2,F%7D%20+%200%5Cmu_%7B2,G%7D%20+%200%5Cmu_%7B2,P%7D%20+%20-%5Cfrac%7B1%7D%7B2%7D%5Cmu_%7B3,F%7D%20+%20-%5Cfrac%7B1%7D%7B2%7D%5Cmu_%7B3,G%7D%20+%201%5Cmu_%7B3,P%7D%20=%200%0A"></p>
<ol start="9" type="1">
<li>Same as the fifth and seventh terms, but for Time 3.</li>
</ol>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_%7B3,F%7D%20=%5Cmu_%7B3,G%7D%20%5C%5C%5CLeftrightarrow%200%5Cmu_%7B1,F%7D%20+%200%5Cmu_%7B1,G%7D%20+%200%5Cmu_%7B1,P%7D%20+%200%5Cmu_%7B2,F%7D%20+%200%5Cmu_%7B2,G%7D%20+%200%5Cmu_%7B2,P%7D%20+%201%5Cmu_%7B3,F%7D%20+%20-1%5Cmu_%7B3,G%7D%20+%200%5Cmu_%7B3,P%7D%20=%200%0A"></p>
<p>Put all of these coefficients into a large hypothesis matrix and convert it to a contrast matrix:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1">Hm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">GM_T1     =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F1 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">G1 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">P1 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,  </span>
<span id="cb29-2">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F2 =</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;">G2 =</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;">P2 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,    </span>
<span id="cb29-3">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F3 =</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;">G3 =</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;">P3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb29-4">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">T2vT1     =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F1 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">G1 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">P1 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, </span>
<span id="cb29-5">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F2 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">G2 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">P2 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,  </span>
<span id="cb29-6">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F3 =</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;">G3 =</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;">P3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb29-7">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">T3vT2     =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F1 =</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;">G1 =</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;">P1 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,    </span>
<span id="cb29-8">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F2 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">G2 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">P2 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, </span>
<span id="cb29-9">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">G3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">P3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb29-10">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">T1_PtvsBi =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F1 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">G1 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">P1 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,    </span>
<span id="cb29-11">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F2 =</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;">G2 =</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;">P2 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,    </span>
<span id="cb29-12">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F3 =</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;">G3 =</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;">P3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb29-13">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">T1_FrvsGe =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F1 =</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;">G1 =</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="at" style="color: #657422;
background-color: null;
font-style: inherit;">P1 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,    </span>
<span id="cb29-14">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F2 =</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;">G2 =</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;">P2 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,    </span>
<span id="cb29-15">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F3 =</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;">G3 =</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;">P3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb29-16">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">T2_PtvsBi =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F1 =</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;">G1 =</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;">P1 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,    </span>
<span id="cb29-17">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F2 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">G2 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">P2 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,    </span>
<span id="cb29-18">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F3 =</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;">G3 =</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;">P3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb29-19">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">T2_FrvsGe =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F1 =</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;">G1 =</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;">P1 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,    </span>
<span id="cb29-20">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F2 =</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;">G2 =</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="at" style="color: #657422;
background-color: null;
font-style: inherit;">P2 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,    </span>
<span id="cb29-21">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F3 =</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;">G3 =</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;">P3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>),</span>
<span id="cb29-22">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">T3_PtvsBi =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F1 =</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;">G1 =</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;">P1 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,    </span>
<span id="cb29-23">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F2 =</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;">G2 =</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;">P2 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,    </span>
<span id="cb29-24">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F3 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">G3 =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">P3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb29-25">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">T3_FrvsGe =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F1 =</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;">G1 =</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;">P1 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,    </span>
<span id="cb29-26">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F2 =</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;">G2 =</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;">P2 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,    </span>
<span id="cb29-27">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">F3 =</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;">G3 =</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="at" style="color: #657422;
background-color: null;
font-style: inherit;">P3 =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))</span>
<span id="cb29-28">Cm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ginv2</span>(Hm)</span></code></pre></div></div>
</div>
<p>Apply the contrasts to the <code>Cell</code> variable and fit the model:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contrasts</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Cell) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> Cm[, <span 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="cb30-2">m_manual <span class="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>(Reading <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Cell <span 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>Class) <span 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>Subject), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d)</span>
<span id="cb30-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(m_manual)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>              Estimate Std. Error t value
(Intercept)     0.5586    0.01200   46.56
CellT2vT1       0.1032    0.00975   10.58
CellT3vT2       0.0812    0.00992    8.19
CellT1_PtvsBi   0.1758    0.02725    6.45
CellT1_FrvsGe   0.0818    0.02715    3.01
CellT2_PtvsBi   0.1763    0.02723    6.48
CellT2_FrvsGe   0.1052    0.02733    3.85
CellT3_PtvsBi   0.1412    0.02765    5.11
CellT3_FrvsGe   0.0794    0.02748    2.89</code></pre>
</div>
</div>
<p>The coefficients mean exactly what it says on the tin. There is just one problem: I didn’t include a random slope that capture the varying effect of <code>Time</code> by <code>Class</code> yet. Adding a by-class random slope for <code>Cell</code> wouldn’t work: you’d end up estimating an enormous matrix of random effects since <code>Cell</code> has nine levels. Instead, we’ll have to first refit the model using the dummy variables in the contrast matrix of <code>Cell</code> as separate variables:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add the dummy variables in the contrast matrix of Cell</span></span>
<span id="cb32-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># to the dataset as separate variables</span></span>
<span id="cb32-3">contrast_matrix <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(Cm[, <span 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="cb32-4">                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Cell =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Cell))</span>
<span id="cb32-5">d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">merge</span>(d, contrast_matrix, <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;">"Cell"</span>)</span>
<span id="cb32-6"></span>
<span id="cb32-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Refit the model using these separate dummy variables</span></span>
<span id="cb32-8">m_manual <span class="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>(Reading <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> T2vT1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> T3vT2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-9">                   T1_PtvsBi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> T1_FrvsGe <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-10">                   T2_PtvsBi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> T2_FrvsGe <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-11">                   T3_PtvsBi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> T3_FrvsGe <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-12">                   (<span class="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>Class) <span 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>Subject), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d)</span>
<span id="cb32-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(m_manual)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value
(Intercept)   0.5586    0.01200   46.56
T2vT1         0.1032    0.00975   10.58
T3vT2         0.0812    0.00992    8.19
T1_PtvsBi     0.1758    0.02725    6.45
T1_FrvsGe     0.0818    0.02715    3.01
T2_PtvsBi     0.1763    0.02723    6.48
T2_FrvsGe     0.1052    0.02733    3.85
T3_PtvsBi     0.1412    0.02765    5.11
T3_FrvsGe     0.0794    0.02748    2.89</code></pre>
</div>
</div>
<p>The output is exactly the same as above. Now we need to think about which of these estimates can actually vary by <code>Class</code>. If you think about the way we coded these predictors, <code>T2vsT1</code> and <code>T3vT2</code> capture the effect of <code>Time</code>, whereas the other predictors capture the effects of <code>LanguageGroup</code> at different times. The effect of <code>Time</code> can vary according to <code>Class</code>, but the effects of <code>LanguageGroup</code> can’t (each <code>Class</code> belonged to only one <code>LanguageGroup</code>). So if we want random slopes of <code>Time</code> by <code>Class</code>, we need to let the effects of <code>T2vT1</code> and <code>T3vT2</code> vary by class:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1">m_manual <span class="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>(Reading <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> T2vT1 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> T3vT2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb34-2">                   T1_PtvsBi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> T1_FrvsGe <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb34-3">                   T2_PtvsBi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> T2_FrvsGe <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb34-4">                   T3_PtvsBi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> T3_FrvsGe <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb34-5">                   (<span class="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>T2vT1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>T3vT2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span>Class) <span 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>Subject), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>boundary (singular) fit: see help('isSingular')</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(m_manual)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value
(Intercept)   0.5563     0.0143   38.84
T2vT1         0.1054     0.0120    8.77
T3vT2         0.0820     0.0142    5.79
T1_PtvsBi     0.1762     0.0331    5.32
T1_FrvsGe     0.0893     0.0316    2.82
T2_PtvsBi     0.1740     0.0315    5.52
T2_FrvsGe     0.1088     0.0306    3.55
T3_PtvsBi     0.1393     0.0275    5.07
T3_FrvsGe     0.0729     0.0272    2.68</code></pre>
</div>
</div>
<p>The warning isn’t relevant to the purposes of this tutorial. As a sanity check, we can compare the predictions of <code>m_manual</code> and <code>m_default</code> to confirm that <code>m_manual</code> is the same model as <code>m_default</code>, just with parameter estimates that are easier to interpret:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb38" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb38-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># (I don't know why I need to specify 'newdata'...)</span></span>
<span id="cb38-2">d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>predict_default <span class="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>(m_default, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">newdata =</span> d)</span>
<span id="cb38-3">d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>predict_manual <span class="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>(m_manual, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">newdata =</span> d)</span>
<span id="cb38-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(predict_manual <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> predict_default, d)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-05-05-contrast-coding/index_files/figure-html/unnamed-chunk-20-1.svg" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
<p>Both models make the same predictions, and the predictions align reasonably well with the data observed:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb39" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d,</span>
<span id="cb39-2">       <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> Time, </span>
<span id="cb39-3">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> predict_manual,</span>
<span id="cb39-4">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> LanguageGroup)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb39-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb39-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Model predictions"</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-05-05-contrast-coding/index_files/figure-html/unnamed-chunk-21-1.svg" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="what-if-it-doesnt-work" class="level2">
<h2 class="anchored" data-anchor-id="what-if-it-doesnt-work">What if it doesn’t work?</h2>
<p>If, having specified your own hypothesis matrix, some lines in the regression output contain <code>NA</code>, the reason is probably that some of the rows in your hypothesis matrix are combinations of some of the other rows. In essence, you’re asking the model to answer the same question twice, so it only answers it once. Reformulating the hypotheses will usually work.</p>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<p>Berthele, Raphael and Amelia Lambelet (eds.). 2018. <em>Heritage and school language literacy development in migrant children: Interdependence or independence?</em> Multilingual Matters.</p>
<p>Pestana, Carlos, Amelia Lambelet and Jan Vanhove. 2018. Reading comprehension development in Portuguese heritage speakers in Switzerland (HELASCOT project). In Raphael Berthele and Amelia Lambelet (Eds.), <em>Heritage language and school language literacy development in migrant children: Interdependence or independence?</em> (pp.&nbsp;58-82). Bristol, UK: Multilingual Matters. <a href="http://doi.org/10.21832/BERTHE9047" class="uri">http://doi.org/10.21832/BERTHE9047</a></p>
<p>Schad, Daniel J., Shravan Vasishth, Sven Hohenstein and Reinhold Kliegl. 2020. How to capitalize on a priori contrasts in linear (mixed) models: A tutorial. <em>Journal of Memory and Language</em> 110. <a href="https://doi.org/10.1016/j.jml.2019.104038" class="uri">https://doi.org/10.1016/j.jml.2019.104038</a></p>
<p>Vanhove, Jan.&nbsp;2019. Metalinguistic knowledge about the native language and language transfer in gender assignment. <em>Studies in Second Language Learning and Teaching</em> 9(2). 397-419. <a href="https://doi.org/10.14746/ssllt.2019.9.2.7" class="uri">https://doi.org/10.14746/ssllt.2019.9.2.7</a></p>
</section>
<section id="software-versions" class="level2">
<h2 class="anchored" data-anchor-id="software-versions">Software versions</h2>
<p>Please note that I reran the code on this page on August 6, 2023.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb40" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb40-1">devtools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">session_info</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.1 (2025-06-13)
 os       Ubuntu 22.04.5 LTS
 system   x86_64, linux-gnu
 ui       X11
 language en_US
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Zurich
 date     2025-09-24
 pandoc   2.12 @ /home/jan/miniconda3/bin/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────
 package      * version date (UTC) lib source
 boot           1.3-31  2024-08-28 [4] CRAN (R 4.4.2)
 cachem         1.1.0   2024-05-16 [1] CRAN (R 4.5.1)
 callr          3.7.6   2024-03-25 [1] CRAN (R 4.5.1)
 cli            3.6.5   2025-04-23 [1] CRAN (R 4.5.1)
 crayon         1.5.1   2022-03-26 [2] CRAN (R 4.2.0)
 devtools       2.4.5   2022-10-11 [1] CRAN (R 4.5.1)
 digest         0.6.37  2024-08-19 [1] CRAN (R 4.5.1)
 dplyr        * 1.1.4   2023-11-17 [1] CRAN (R 4.5.1)
 ellipsis       0.3.2   2021-04-29 [2] CRAN (R 4.2.0)
 evaluate       1.0.4   2025-06-18 [1] CRAN (R 4.5.1)
 farver         2.1.2   2024-05-13 [1] CRAN (R 4.5.1)
 fastmap        1.2.0   2024-05-15 [1] CRAN (R 4.5.1)
 forcats      * 1.0.0   2023-01-29 [1] CRAN (R 4.5.1)
 fs             1.5.2   2021-12-08 [2] CRAN (R 4.2.0)
 generics       0.1.4   2025-05-09 [1] CRAN (R 4.5.1)
 ggplot2      * 3.5.2   2025-04-09 [1] CRAN (R 4.5.1)
 glue           1.6.2   2022-02-24 [2] CRAN (R 4.2.0)
 gtable         0.3.6   2024-10-25 [1] CRAN (R 4.5.1)
 helascot     * 1.0.0   2025-09-24 [1] Github (janhove/helascot@4cf3c1b)
 hms            1.1.3   2023-03-21 [1] CRAN (R 4.5.1)
 htmltools      0.5.8.1 2024-04-04 [1] CRAN (R 4.5.1)
 htmlwidgets    1.6.4   2023-12-06 [1] CRAN (R 4.5.1)
 httpuv         1.6.16  2025-04-16 [1] CRAN (R 4.5.1)
 jsonlite       2.0.0   2025-03-27 [1] CRAN (R 4.5.1)
 knitr          1.50    2025-03-16 [1] CRAN (R 4.5.1)
 labeling       0.4.3   2023-08-29 [1] CRAN (R 4.5.1)
 later          1.4.2   2025-04-08 [1] CRAN (R 4.5.1)
 lattice        0.22-5  2023-10-24 [4] CRAN (R 4.3.1)
 lifecycle      1.0.4   2023-11-07 [1] CRAN (R 4.5.1)
 lme4         * 1.1-37  2025-03-26 [1] CRAN (R 4.5.1)
 lubridate    * 1.9.4   2024-12-08 [1] CRAN (R 4.5.1)
 magrittr       2.0.3   2022-03-30 [1] CRAN (R 4.5.1)
 MASS           7.3-65  2025-02-28 [4] CRAN (R 4.4.3)
 Matrix       * 1.7-3   2025-03-11 [4] CRAN (R 4.4.3)
 memoise        2.0.1   2021-11-26 [2] CRAN (R 4.2.0)
 mime           0.10    2021-02-13 [2] CRAN (R 4.0.2)
 miniUI         0.1.2   2025-04-17 [1] CRAN (R 4.5.1)
 minqa          1.2.8   2024-08-17 [1] CRAN (R 4.5.1)
 nlme           3.1-168 2025-03-31 [4] CRAN (R 4.4.3)
 nloptr         2.2.1   2025-03-17 [1] CRAN (R 4.5.1)
 pillar         1.10.2  2025-04-05 [1] CRAN (R 4.5.1)
 pkgbuild       1.3.1   2021-12-20 [2] CRAN (R 4.2.0)
 pkgconfig      2.0.3   2019-09-22 [2] CRAN (R 4.2.0)
 pkgload        1.4.0   2024-06-28 [1] CRAN (R 4.5.1)
 prettyunits    1.1.1   2020-01-24 [2] CRAN (R 4.2.0)
 processx       3.8.6   2025-02-21 [1] CRAN (R 4.5.1)
 profvis        0.4.0   2024-09-20 [1] CRAN (R 4.5.1)
 promises       1.3.3   2025-05-29 [1] CRAN (R 4.5.1)
 ps             1.9.1   2025-04-12 [1] CRAN (R 4.5.1)
 purrr        * 1.0.4   2025-02-05 [1] CRAN (R 4.5.1)
 R6             2.5.1   2021-08-19 [2] CRAN (R 4.2.0)
 rbibutils      2.3     2024-10-04 [1] CRAN (R 4.5.1)
 RColorBrewer   1.1-3   2022-04-03 [1] CRAN (R 4.5.1)
 Rcpp           1.0.14  2025-01-12 [1] CRAN (R 4.5.1)
 Rdpack         2.6.4   2025-04-09 [1] CRAN (R 4.5.1)
 readr        * 2.1.5   2024-01-10 [1] CRAN (R 4.5.1)
 reformulas     0.4.1   2025-04-30 [1] CRAN (R 4.5.1)
 remotes        2.4.2   2021-11-30 [2] CRAN (R 4.2.0)
 rlang          1.1.6   2025-04-11 [1] CRAN (R 4.5.1)
 rmarkdown      2.29    2024-11-04 [1] CRAN (R 4.5.1)
 rstudioapi     0.17.1  2024-10-22 [1] CRAN (R 4.5.1)
 scales         1.4.0   2025-04-24 [1] CRAN (R 4.5.1)
 sessioninfo    1.2.2   2021-12-06 [2] CRAN (R 4.2.0)
 shiny          1.10.0  2024-12-14 [1] CRAN (R 4.5.1)
 stringi        1.7.6   2021-11-29 [2] CRAN (R 4.2.0)
 stringr      * 1.5.1   2023-11-14 [1] CRAN (R 4.5.1)
 tibble       * 3.3.0   2025-06-08 [1] CRAN (R 4.5.1)
 tidyr        * 1.3.1   2024-01-24 [1] CRAN (R 4.5.1)
 tidyselect     1.2.1   2024-03-11 [1] CRAN (R 4.5.1)
 tidyverse    * 2.0.0   2023-02-22 [1] CRAN (R 4.5.1)
 timechange     0.3.0   2024-01-18 [1] CRAN (R 4.5.1)
 tzdb           0.5.0   2025-03-15 [1] CRAN (R 4.5.1)
 urlchecker     1.0.1   2021-11-30 [1] CRAN (R 4.5.1)
 usethis        3.1.0   2024-11-26 [1] CRAN (R 4.5.1)
 vctrs          0.6.5   2023-12-01 [1] CRAN (R 4.5.1)
 withr          3.0.2   2024-10-28 [1] CRAN (R 4.5.1)
 xfun           0.52    2025-04-02 [1] CRAN (R 4.5.1)
 xtable         1.8-4   2019-04-21 [1] CRAN (R 4.5.1)
 yaml           2.3.5   2022-02-21 [2] CRAN (R 4.2.0)

 [1] /home/jan/R/x86_64-pc-linux-gnu-library/4.5
 [2] /usr/local/lib/R/site-library
 [3] /usr/lib/R/site-library
 [4] /usr/lib/R/library

──────────────────────────────────────────────────────────────────────────────</code></pre>
</div>
</div>


</section>

 ]]></description>
  <category>R</category>
  <category>contrast coding</category>
  <category>mixed-effects models</category>
  <category>multiple regression</category>
  <category>tutorial</category>
  <category>research questions</category>
  <guid>https://janhove.github.io/posts/2020-05-05-contrast-coding/</guid>
  <pubDate>Sat, 23 May 2020 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Nonparametric tests aren’t a silver bullet when parametric assumptions are violated</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2020-05-23-nonparametric/</link>
  <description><![CDATA[ 




<p>Some researchers adhere to a simple strategy when comparing data from two or more groups: when they think that the data in the groups are normally distributed, they run a parametric test (<img src="https://latex.codecogs.com/png.latex?t">-test or ANOVA); when they suspect that the data are not normally distributed, they run a nonparametric test (e.g., Mann–Whitney or Kruskal–Wallis). Rather than follow such an automated approach to analysing data, I think researchers ought to consider the following points:</p>
<ul>
<li>The <img src="https://latex.codecogs.com/png.latex?t">-test and ANOVA compare <em>means</em>; the Mann–Whitney and Kruskal–Wallis don’t.</li>
<li>The Mann–Whitney and Kruskal–Wallis do <em>not</em> in general compare medians, either. I’ll illustrate these first two points in this blog post.</li>
<li>The main problem with parametric tests when you have nonnormal data is that these tests compare means, but that these means don’t necessarily capture a relevant aspect of the data. But even if the data aren’t normally distributed, comparing means can sometimes be reasonable, depending on what the data look like and what it is you’re actually interested in. And if you <em>do</em> want to compare means, parametric tests or bootstrapping are more sensible than running a nonparametric test. See also my blog post <a href="../2019-04-11-assumptions-relevance"><em>Before worrying about model assumptions, think about model relevance</em></a>.</li>
<li>If you want to compare medians, look into bootstrapping or quantile regression.</li>
<li>Above all, make sure that you know you’re comparing when you run a test and that this comparison makes sense in light of the data <em>and your research question</em>.</li>
</ul>
<p>In this blog post, I’ll share the results of some simulations that demonstrate that the Mann–Whitney (a) picks up on differences in the variance between two distributions, even if they have the same mean and median; (b) picks up on differences in the median between two distributions, even if they have the same mean and variance; and (c) picks up on differences in the mean between two distributions, even if they have the same median and variance. These points aren’t new (see Zimmerman 1998), but since the automated strategy (‘parametric when normal, otherwise nonparemetric’) is pretty widespread, they bear repeating.</p>
<section id="same-mean-same-median-different-variance" class="level2">
<h2 class="anchored" data-anchor-id="same-mean-same-median-different-variance">Same mean, same median, different variance</h2>
<p>The first simulation demonstrates the Mann–Whitney’s sensitivity to differences in the variance. I simulated samples from a uniform distribution going from <img src="https://latex.codecogs.com/png.latex?-%5Csqrt%7B3%7D"> to <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B3%7D"> as well as from a uniform distribution going from <img src="https://latex.codecogs.com/png.latex?-3%5Csqrt%7B3%7D"> to <img src="https://latex.codecogs.com/png.latex?3%5Csqrt%7B3%7D">. Both distributions have a mean and median of 0, but the standard deviation of the first is 1 and that of the second is 3. I compared these samples using a Mann–Whitney and recorded the <img src="https://latex.codecogs.com/png.latex?p">-value. I generated samples of both 50 and 500 observations and repeated this process 10,000 times. You can reproduce this simulation using the code below.</p>
<p><strong>Figure 1</strong> shows the distribution of the <img src="https://latex.codecogs.com/png.latex?p">-values. Even though the distributions’ means and medians are the same, the Mann–Whitney returns significance (<img src="https://latex.codecogs.com/png.latex?p%20%3C%200.05">) in about 7% of the comparisons for the smaller samples and 8% for the larger samples. If the test were sensitive only to differences in the mean or median, if should return significance in only 5% of the comparisons.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Load package for plotting</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb1-3"></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set number of simulation runs</span></span>
<span id="cb1-5">n_sim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span></span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Draw a sample of 50 observations from two uniform distributions with the same </span></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># mean and median but with different variances/standard deviations.</span></span>
<span id="cb1-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Run the Mann-Whitney on them (wilcox.test()).</span></span>
<span id="cb1-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Repeat this n_sim times.</span></span>
<span id="cb1-11">pvals_50 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">replicate</span>(n_sim, {</span>
<span id="cb1-12">  x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</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;">min =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</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;">3</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span>
<span id="cb1-13">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</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;">min =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span>
<span id="cb1-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">wilcox.test</span>(x, y)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value</span>
<span id="cb1-15">})</span>
<span id="cb1-16"></span>
<span id="cb1-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Same but with samples of 500 observations.</span></span>
<span id="cb1-18">pvals_500 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">replicate</span>(n_sim, {</span>
<span id="cb1-19">  x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</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;">3</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span>
<span id="cb1-20">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">runif</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span>
<span id="cb1-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">wilcox.test</span>(x, y)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value</span>
<span id="cb1-22">})</span>
<span id="cb1-23"></span>
<span id="cb1-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Put in data frame</span></span>
<span id="cb1-25">d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb1-26">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(pvals_50, pvals_500),</span>
<span id="cb1-27">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</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;">50</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> n_sim)</span>
<span id="cb1-28">)</span>
<span id="cb1-29"></span>
<span id="cb1-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot</span></span>
<span id="cb1-31"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> d,</span>
<span id="cb1-32">       <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> p,</span>
<span id="cb1-33">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> (p <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_histogram</span>(</span>
<span id="cb1-35">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>),</span>
<span id="cb1-36">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey20"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey70"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-38">  <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> n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-39">  <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> n_sim<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-40">  <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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb1-42">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb1-43">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Same mean, same median, different variance"</span>,</span>
<span id="cb1-44">    <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 for two sample sizes (50 vs. 500 observations per group):</span></span>
<span id="cb1-45"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    uniform distribution from -sqrt(3) to sqrt(3)</span></span>
<span id="cb1-46"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    vs. uniform distribution from -3*sqrt(3) to 3*sqrt(3)"</span></span>
<span id="cb1-47">  )</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-05-23-nonparametric/index_files/figure-html/unnamed-chunk-2-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 1.</strong></figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="same-mean-different-median-same-variance" class="level2">
<h2 class="anchored" data-anchor-id="same-mean-different-median-same-variance">Same mean, different median, same variance</h2>
<p>The second simulation demonstrates that the Mann–Whitney does not compare means. The simulation set-up was the same as before, but the samples were drawn from different distributions. The first sample was drawn from a log-normal distribution with mean <img src="https://latex.codecogs.com/png.latex?%5Cexp%7B(%5Cln%7B10%7D%20+%20%5Cfrac%7B1%7D%7B2%7D)%7D%20%5Capprox%2016.5">, median 10 and standard deviation <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B(%5Cexp%7B(1)%7D-1)%5Cexp%7B(2%5Cln%7B10%7D+1)%7D%7D%20%5Capprox%2021.6">. The second sample was drawn from a normal distribution with the same mean (i.e., about 16.5) and the same standard deviation (i.e., about 21.6), but with a different median (viz., 16.5 rather than 10).</p>
<p><strong>Figure 2</strong> shows that the Mann–Whitney returned significance for 12% of the comparisons of the smaller samples and 92% of the comparisons for the larger samples. So the Mann–Whitney does <em>not</em> test for differences in the mean; otherwise only 5% of the comparisons should have been significant (since the means of the distributions are the same).</p>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-05-23-nonparametric/index_files/figure-html/unnamed-chunk-4-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 2.</strong></figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="different-mean-same-median-same-variance" class="level2">
<h2 class="anchored" data-anchor-id="different-mean-same-median-same-variance">Different mean, same median, same variance</h2>
<p>The last simulation demonstrates that the Mann–Whitney does not compare medians, either. The first sample was again drawn from a log-normal distribution with mean <img src="https://latex.codecogs.com/png.latex?%5Cexp%7B(%5Cln%7B10%7D%20+%20%5Cfrac%7B1%7D%7B2%7D)%7D%20%5Capprox%2016.5">, median 10 and standard deviation <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B(%5Cexp%7B(1)%7D-1)%5Cexp%7B(2%5Cln%7B10%7D+1)%7D%7D%20%5Capprox%2021.6">. The second sample was now drawn from a normal distribution with the same median (i.e., 10) and the same standard deviation (i.e., about 21.6), but with a different mean (viz., 10 rather than 16.5).</p>
<p><strong>Figure 3</strong> shows that the Mann–Whitney returned significance for 20% of the comparisons of the smaller samples and 91% of the comparisons for the larger samples. So the Mann–Whitney does <em>not</em> test for differences in the median; otherwise only 5% of the comparisons should have been significant (since the medians of the distributions are the same).</p>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-05-23-nonparametric/index_files/figure-html/unnamed-chunk-5-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 3.</strong></figcaption>
</figure>
</div>
</div>
</div>
</section>
<section id="nonparametric-tests-make-assumptions-too" class="level2">
<h2 class="anchored" data-anchor-id="nonparametric-tests-make-assumptions-too">Nonparametric tests make assumptions, too</h2>
<p>Many researchers think that nonparametric tests don’t make any assumptions about the distributions from which the data were drawn. This belief is half-true (i.e., wrong): Nonparametric tests such as the Mann–Whitney don’t assume that the data were drawn from a <em>specific</em> distribution (e.g., from a normal distribution). However, they do assume that the data in the different groups being compared were drawn from the <em>same</em> distribution (but for a shift in the location of this distribution). If researchers run nonparametric tests because they are worried about violating the assumptions of parametric tests, I suggest they worry about the assumptions of their nonparametric tests, too.</p>
<p>But a better solution in my view is to them to consider more carefully what they actually want to compare. If it is really the means that are of interest, parametric tests are often okay, and their results can be double-checked using the bootstrap if needed. Permutation tests would be an alternative. If it is the medians that are of interest, quantile regression, bootstrapping, or permutation tests may be useful. If another measure of the data’s central tendency is of interest, robust regression may be useful. A discussion of these techniques is beyond the scope of this blog post, whose aims merely were to alert researchers to the fact that nonparametric tests aren’t a silver bullet when parametric assumptions are violated and that nonparametric tests aren’t just sensitive to differences in the mean or median.</p>
</section>
<section id="reference" class="level2">
<h2 class="anchored" data-anchor-id="reference">Reference</h2>
<p>Zimmerman, Donald W. 1998. <a href="https://doi.org/10.1080/00220979809598344">Invalidation of parametric and nonparametric statistical tests by concurrent violation of two assumptions</a>. <em>Journal of Experimental Education</em> 67(1). 55-68.</p>
</section>
<section id="software-versions" class="level2">
<h2 class="anchored" data-anchor-id="software-versions">Software versions</h2>
<p>Please note that I reran the code on this page on August 6, 2023.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">devtools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">session_info</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.1 (2025-06-13)
 os       Ubuntu 22.04.5 LTS
 system   x86_64, linux-gnu
 ui       X11
 language en_US
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Zurich
 date     2025-09-24
 pandoc   2.12 @ /home/jan/miniconda3/bin/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────
 package      * version date (UTC) lib source
 cachem         1.1.0   2024-05-16 [1] CRAN (R 4.5.1)
 callr          3.7.6   2024-03-25 [1] CRAN (R 4.5.1)
 cli            3.6.5   2025-04-23 [1] CRAN (R 4.5.1)
 crayon         1.5.1   2022-03-26 [2] CRAN (R 4.2.0)
 devtools       2.4.5   2022-10-11 [1] CRAN (R 4.5.1)
 digest         0.6.37  2024-08-19 [1] CRAN (R 4.5.1)
 dplyr        * 1.1.4   2023-11-17 [1] CRAN (R 4.5.1)
 ellipsis       0.3.2   2021-04-29 [2] CRAN (R 4.2.0)
 evaluate       1.0.4   2025-06-18 [1] CRAN (R 4.5.1)
 farver         2.1.2   2024-05-13 [1] CRAN (R 4.5.1)
 fastmap        1.2.0   2024-05-15 [1] CRAN (R 4.5.1)
 forcats      * 1.0.0   2023-01-29 [1] CRAN (R 4.5.1)
 fs             1.5.2   2021-12-08 [2] CRAN (R 4.2.0)
 generics       0.1.4   2025-05-09 [1] CRAN (R 4.5.1)
 ggplot2      * 3.5.2   2025-04-09 [1] CRAN (R 4.5.1)
 glue           1.6.2   2022-02-24 [2] CRAN (R 4.2.0)
 gtable         0.3.6   2024-10-25 [1] CRAN (R 4.5.1)
 hms            1.1.3   2023-03-21 [1] CRAN (R 4.5.1)
 htmltools      0.5.8.1 2024-04-04 [1] CRAN (R 4.5.1)
 htmlwidgets    1.6.4   2023-12-06 [1] CRAN (R 4.5.1)
 httpuv         1.6.16  2025-04-16 [1] CRAN (R 4.5.1)
 jsonlite       2.0.0   2025-03-27 [1] CRAN (R 4.5.1)
 knitr          1.50    2025-03-16 [1] CRAN (R 4.5.1)
 labeling       0.4.3   2023-08-29 [1] CRAN (R 4.5.1)
 later          1.4.2   2025-04-08 [1] CRAN (R 4.5.1)
 lifecycle      1.0.4   2023-11-07 [1] CRAN (R 4.5.1)
 lubridate    * 1.9.4   2024-12-08 [1] CRAN (R 4.5.1)
 magrittr       2.0.3   2022-03-30 [1] CRAN (R 4.5.1)
 memoise        2.0.1   2021-11-26 [2] CRAN (R 4.2.0)
 mime           0.10    2021-02-13 [2] CRAN (R 4.0.2)
 miniUI         0.1.2   2025-04-17 [1] CRAN (R 4.5.1)
 pillar         1.10.2  2025-04-05 [1] CRAN (R 4.5.1)
 pkgbuild       1.3.1   2021-12-20 [2] CRAN (R 4.2.0)
 pkgconfig      2.0.3   2019-09-22 [2] CRAN (R 4.2.0)
 pkgload        1.4.0   2024-06-28 [1] CRAN (R 4.5.1)
 prettyunits    1.1.1   2020-01-24 [2] CRAN (R 4.2.0)
 processx       3.8.6   2025-02-21 [1] CRAN (R 4.5.1)
 profvis        0.4.0   2024-09-20 [1] CRAN (R 4.5.1)
 promises       1.3.3   2025-05-29 [1] CRAN (R 4.5.1)
 ps             1.9.1   2025-04-12 [1] CRAN (R 4.5.1)
 purrr        * 1.0.4   2025-02-05 [1] CRAN (R 4.5.1)
 R6             2.5.1   2021-08-19 [2] CRAN (R 4.2.0)
 RColorBrewer   1.1-3   2022-04-03 [1] CRAN (R 4.5.1)
 Rcpp           1.0.14  2025-01-12 [1] CRAN (R 4.5.1)
 readr        * 2.1.5   2024-01-10 [1] CRAN (R 4.5.1)
 remotes        2.4.2   2021-11-30 [2] CRAN (R 4.2.0)
 rlang          1.1.6   2025-04-11 [1] CRAN (R 4.5.1)
 rmarkdown      2.29    2024-11-04 [1] CRAN (R 4.5.1)
 rstudioapi     0.17.1  2024-10-22 [1] CRAN (R 4.5.1)
 scales         1.4.0   2025-04-24 [1] CRAN (R 4.5.1)
 sessioninfo    1.2.2   2021-12-06 [2] CRAN (R 4.2.0)
 shiny          1.10.0  2024-12-14 [1] CRAN (R 4.5.1)
 stringi        1.7.6   2021-11-29 [2] CRAN (R 4.2.0)
 stringr      * 1.5.1   2023-11-14 [1] CRAN (R 4.5.1)
 tibble       * 3.3.0   2025-06-08 [1] CRAN (R 4.5.1)
 tidyr        * 1.3.1   2024-01-24 [1] CRAN (R 4.5.1)
 tidyselect     1.2.1   2024-03-11 [1] CRAN (R 4.5.1)
 tidyverse    * 2.0.0   2023-02-22 [1] CRAN (R 4.5.1)
 timechange     0.3.0   2024-01-18 [1] CRAN (R 4.5.1)
 tzdb           0.5.0   2025-03-15 [1] CRAN (R 4.5.1)
 urlchecker     1.0.1   2021-11-30 [1] CRAN (R 4.5.1)
 usethis        3.1.0   2024-11-26 [1] CRAN (R 4.5.1)
 vctrs          0.6.5   2023-12-01 [1] CRAN (R 4.5.1)
 withr          3.0.2   2024-10-28 [1] CRAN (R 4.5.1)
 xfun           0.52    2025-04-02 [1] CRAN (R 4.5.1)
 xtable         1.8-4   2019-04-21 [1] CRAN (R 4.5.1)
 yaml           2.3.5   2022-02-21 [2] CRAN (R 4.2.0)

 [1] /home/jan/R/x86_64-pc-linux-gnu-library/4.5
 [2] /usr/local/lib/R/site-library
 [3] /usr/lib/R/site-library
 [4] /usr/lib/R/library

──────────────────────────────────────────────────────────────────────────────</code></pre>
</div>
</div>


</section>

 ]]></description>
  <category>R</category>
  <category>power</category>
  <category>significance</category>
  <category>simplicity</category>
  <category>assumptions</category>
  <category>nonparametric tests</category>
  <guid>https://janhove.github.io/posts/2020-05-23-nonparametric/</guid>
  <pubDate>Sat, 23 May 2020 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Baby steps in Bayes: Incorporating reliability estimates in regression models</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2020-02-18-measurement-error/</link>
  <description><![CDATA[ 




<p>Researchers sometimes calculate reliability indices such as Cronbach’s <img src="https://latex.codecogs.com/png.latex?%5Calpha"> or Revelle’s <img src="https://latex.codecogs.com/png.latex?%5Comega_T">, but their statistical models rarely take these reliability indices into account. Here I want to show you how you can incorporate information about the reliability about your measurements in a statistical model so as to obtain more honest and more readily interpretable parameter estimates.</p>
<section id="reliability-and-measurement-error" class="level2">
<h2 class="anchored" data-anchor-id="reliability-and-measurement-error">Reliability and measurement error</h2>
<p>This blog post is the sequel to the <a href="../2020-01-21-statistical-control-measurement-error">previous</a> one, where I demonstrated how imperfectly measured control variables undercorrect for the actual confounding in observational studies (also see Berthele &amp; Vanhove 2017; Brunner &amp; Austin 2009; Westfall &amp; Yarkoni 2016). A model that doesn’t account for measurement error on the confounding variable—and hence implicitly assumes that the confound was measured perfectly—may confidently conclude that the variable of actual interest is related to the outcome even when taking into account the confound. From such a finding, researchers typically infer that the variable of actual interest is causally related to the outcome even in absence of the confound. But once this measurement error is duly accounted for, you may find that the evidence for a causal link between the variable of interest and the outcome is more tenuous than originally believed.</p>
<p>So especially in observational studies, where confounds abound, it behooves researchers to account for the measurement error in their variables so that they don’t draw unwarranted conclusions from their data too often. The amount of measurement error on your variables is usually unknown. But if you’ve calculated some reliability estimate such as Cronbach’s <img src="https://latex.codecogs.com/png.latex?%5Calpha"> for your variables, you can use this to obtain an estimate of the amount of measurement error.</p>
<p>To elaborate, in classical test theory, the reliability <img src="https://latex.codecogs.com/png.latex?%5Crho_%7BXX'%7D"> of a measure is equal to the ratio of the variance of the (error-free) true scores to the variance of the observed scores. The latter is the sum of the variance of the true scores and the error variance:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Crho_%7BXX'%7D%20=%20%5Cfrac%7B%5Ctextrm%7Btrue%20score%20variance%7D%7D%7B%5Ctextrm%7Btrue%20score%20variance%7D%20+%20%5Ctextrm%7Bmeasurement%20error%20variance%7D%7D%20=%20%5Cfrac%7B%5Csigma%5E2_T%7D%7B%5Csigma%5E2_T%20+%20%5Csigma%5E2_E%7D.%0A"></p>
<p>Rearranging, we get</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Csigma%5E2_E%20=%20%5Csigma%5E2_T%5Cleft(%5Cfrac%7B1%7D%7B%5Crho_%7BXX'%7D%7D-1%5Cright).%0A"></p>
<p>None of these values are known, but they can be estimated based on the sample. Specifically, <img src="https://latex.codecogs.com/png.latex?%5Crho_%7BXX'%7D"> can be estimated by a reliability index such as Cronbach’s <img src="https://latex.codecogs.com/png.latex?%5Calpha"> and the sum <img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2_T%20+%20%5Csigma%5E2_E"> can be estimated by computing the variable’s sample variance.</p>
</section>
<section id="a-simulated-example" class="level2">
<h2 class="anchored" data-anchor-id="a-simulated-example">A simulated example</h2>
<p>Let’s first deal with a simulated dataset. The main advantage of analysing simulated data is that you check that what comes out of the model corresponds to what went into the data. In preparing this blog post, I was able to detect an arithmetic error in my model code in this way as one parameter was consistently underestimated. Had I applied the model immediately to the real data set, I wouldn’t have noticed anything wrong. But we’ll deal with real data afterwards.</p>
<p><strong>Update (2023-08-06):</strong> When converting this blog from Jekyll/Bootstrap to Quarto, I noticed that the original code used in this blog post, which involved the R package <code>rstan</code> has started to run very slowly. In the present version, I use <code>cmdstanr</code> instead.</p>
<p>Run these commands to follow along:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cmdstanr)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for fitting Bayesian models, v. 2.32.2</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(posterior) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for working with posterior distributions</span></span>
<span id="cb1-3"></span>
<span id="cb1-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># For drawing scatterplot matrices</span></span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://janhove.github.io/RCode/scatterplot_matrix.R"</span>)</span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set random seed for reproducibility</span></span>
<span id="cb1-8"><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;">2020-02-13</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mersenne-Twister"</span>)</span></code></pre></div></div>
</div>
<section id="generating-the-construct-scores" class="level3">
<h3 class="anchored" data-anchor-id="generating-the-construct-scores">Generating the construct scores</h3>
<p>The scenario we’re going to simulate is one in which you have two correlated predictor variables (<code>A</code> and <code>B</code>) and one outcome variable (<code>Z</code>). Unbeknownst to the analyst, <code>Z</code> is causally affected by <code>A</code> but not by <code>B</code>. Moreover, the three variables are measured with some degree of error, but we’ll come to that later. Figure 1 depicts the scenario for which we’re going to simulate data.</p>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-02-18-measurement-error/index_files/figure-html/unnamed-chunk-3-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 1.</strong> Graphical causal model for the simulated data. A set of unobserved factors <img src="https://latex.codecogs.com/png.latex?U"> gives rise to a correlation between <code>A</code> and <code>B</code>. Even though only <code>A</code> causally affects <code>Z</code>, an association between <code>B</code> and <code>Z</code> will be found unless <code>A</code> is controlled for.</figcaption>
</figure>
</div>
</div>
</div>
<p>The first thing we need are two correlated predictor variables. I’m going to generate these from a bivariate normal distribution. <code>A</code> has a mean of 3 units and a standard deviation of 1.5 units, and <code>B</code> has mean -4 and standard deviation 0.8 units. The correlation between them is <img src="https://latex.codecogs.com/png.latex?%5Crho%20=%200.73">. To generate a sample from this bivariate normal distribution, you need to construct the variance-covariance matrix from the standard deviations and correlation, which I do in the code below:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate correlated constructs</span></span>
<span id="cb2-2">n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span></span>
<span id="cb2-3">rho <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.73</span></span>
<span id="cb2-4">mean_A <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;">3</span></span>
<span id="cb2-5">mean_B <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb2-6">sd_A <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span></span>
<span id="cb2-7">sd_B <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span></span>
<span id="cb2-8"></span>
<span id="cb2-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Given the correlation and the standard deviations,</span></span>
<span id="cb2-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># construct the variance-covariance matrix for the constructs like so:</span></span>
<span id="cb2-11">latent_covariance_matrix <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(sd_A, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, sd_B)) <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;">rbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, rho), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(rho, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%*%</span></span>
<span id="cb2-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(sd_A, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, sd_B))</span>
<span id="cb2-14"></span>
<span id="cb2-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Draw data from the multivariate normal distribution:</span></span>
<span id="cb2-16">constructs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MASS<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mvrnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(mean_A, mean_B),</span>
<span id="cb2-17">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Sigma =</span> latent_covariance_matrix)</span>
<span id="cb2-18"></span>
<span id="cb2-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Extract variables from object</span></span>
<span id="cb2-20">A <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> constructs[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb2-21">B <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> constructs[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]</span></code></pre></div></div>
</div>
<p>Next, we need to generate the outcome. In this simulation, <code>Z</code> depends linearly on <code>A</code> but not on <code>B</code> (hence ‘<img src="https://latex.codecogs.com/png.latex?0%20%5Ctimes%20B_i">’).</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AZ_i%20=%202%20+%200.7%20%5Ctimes%20A_i%20+%200%20%5Ctimes%20B_i%20+%20%5Cvarepsilon_i.%0A"></p>
<p>The error term <img src="https://latex.codecogs.com/png.latex?%5Cvarepsilon"> is drawn from a normal distribution with standard deviation 1.3. Importantly, this error term does <em>not</em> express the measurement error on <code>Z</code>; it is the part of the true score variance in <code>Z</code> that isn’t related to either <code>A</code> or <code>B</code>:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cvarepsilon_i%20%5Csim%20%5Ctextrm%7BNormal%7D(0,%201.3).%0A"></p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create Z</span></span>
<span id="cb3-2">intercept <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb3-3">slope_A <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span></span>
<span id="cb3-4">slope_B <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb3-5">sigma_Z.AB <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span></span>
<span id="cb3-6">Z <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> intercept <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> slope_A<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>A <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> slope_B<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>B <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> sigma_Z.AB)</span></code></pre></div></div>
</div>
<p>Even though <code>B</code> isn’t causally related to <code>Z</code>, we find that <code>B</code> and <code>Z</code> are correlated thanks to <code>B</code>’s correlation to <code>A</code>.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scatterplot_matrix</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(Z, A, B))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-02-18-measurement-error/index_files/figure-html/unnamed-chunk-6-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 2.</strong> <code>B</code> is causally unrelated to <code>Z</code>, but these two variables are still correlated because <code>B</code> correlates with <code>A</code> and <code>A</code> and <code>Z</code> are causally related.</figcaption>
</figure>
</div>
</div>
</div>
<p>A multiple regression model is able to tease apart the effects of <code>A</code> and <code>B</code> on <code>Z</code>:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> A <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> B))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)   2.1224     0.7130   2.977 3.15e-03
A             0.6876     0.0706   9.742 1.22e-19
B             0.0196     0.1340   0.146 8.84e-01</code></pre>
</div>
</div>
<p>The confound <code>A</code> is significantly related to <code>Z</code> and its estimated regression parameter is close to its true value of 0.70 (<img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta%7D_A%20=%200.69%20%5Cpm%200.07">). The variable of interest <code>B</code>, by contrast, isn’t significantly related to <code>Z</code> when <code>A</code> has been accounted for (<img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta%7D_B%20=%200.02%20%5Cpm%200.13">). This is all as it should be.</p>
</section>
<section id="adding-measurement-error" class="level3">
<h3 class="anchored" data-anchor-id="adding-measurement-error">Adding measurement error</h3>
<p>Now let’s add measurement error to all variables. The <code>A</code> values that we actually observe will then be distorted versions of the true <code>A</code> values:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctextrm%7Bobserved%20%7D%20A_i%20=%20%5Ctextrm%7Btrue%20%7D%20A_i%20+%20%5Cvarepsilon_%7BAi%7D.%0A"></p>
<p>The ‘noise’ <img src="https://latex.codecogs.com/png.latex?%5Cvarepsilon_%7BA%7D"> is commonly assumed to be normally distributed:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cvarepsilon_%7BAi%7D%20%5Csim%20%5Ctextrm%7BNormal%7D(0,%20%5Ctau_A).%0A"></p>
<p>That said, you can easily imagine situations where the noise likely has a different distribution. For instance, when measurements are measured to the nearest integer (e.g., body weights in kilograms), the noise is likely uniformly distributed (e.g., a reported body weight of 66 kg means that the true body weight lies between 65.5 and 66.5 kg).</p>
<p>To make the link with the analysis more transparant, I will express the amount of noise in terms of the variables’ reliabilities. For the confound <code>A</code>, I set the reliability at 0.70. Since <code>A</code>’s standard deviation was 1.5 units, this means that the standard deviation of the noise is <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B1.5%5E2%5Cleft(%5Cfrac%7B1%7D%7B0.70%7D%20-%201%5Cright)%7D%20=%200.98"> units. I set the reliability for <code>B</code>, the variable of actual interest at 0.90. Its standard deviation is 0.8, so the standard deviation of the noise is <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B0.8%5E2%5Cleft(%5Cfrac%7B1%7D%7B0.90%7D%20-%201%5Cright)%7D%20=%200.27"> units.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add measurement error on A and B</span></span>
<span id="cb7-2">obs_A <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> A <span 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="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(sd_A<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.70</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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># reliability 0.70</span></span>
<span id="cb7-3">obs_B <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</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;">rnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(sd_B<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.90</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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># reliability 0.90</span></span></code></pre></div></div>
</div>
<p>The same logic applies to adding measurement noise to <code>Z</code>. The difficulty here lies in obtaining the population standard deviation (or variance) of <code>Z</code>. I don’t want to just plug in <code>Z</code>’s sample standard deviation since I want to have exact knowledge of the population parameters. While we specified a <code>sigma_Z.AB</code> above, this is <em>not</em> the total population standard deviation of <code>Z</code>: it’s the population standard deviation of <code>Z</code> once <code>Z</code> has been controlled for <code>A</code> and <code>B</code>. To obtain the <em>total</em> standard deviation of <code>Z</code> (here admittedly confusingly labelled <img src="https://latex.codecogs.com/png.latex?%5Csigma_Z">), we need to add in the variance in <code>Z</code> due to <code>A</code> and <code>B</code>:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Csigma_Z%20=%20%5Csqrt%7B(%5Cbeta_A%5Csigma_A)%5E2%20+%20(%5Cbeta_B%5Csigma_B)%5E2%20+%202%5Cbeta_A%5Cbeta_B%5Csigma_A%5Csigma_B%5Crho_%7BAB%7D%20+%20%5Csigma_%7BZ.AB%7D%5E2%7D.%0A"></p>
<p>Since <img src="https://latex.codecogs.com/png.latex?%5Cbeta_B%20=%200">, this simplifies to <img src="https://latex.codecogs.com/png.latex?%5Csigma_Z%20=%20%5Csqrt%7B(%5Cbeta_A%5Csigma_A)%5E2%20+%20%5Csigma_%7BZ.AB%7D%5E2%7D">, but if you want to simulate your own datasets, the full formula may be useful.</p>
<p>The population standard deviation of <code>Z</code> is thus <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B(0.7%20%5Ctimes%201.5)%5E2%20+%201.3%5E2%7D%20=%201.67">. Setting <code>Z</code>’s reliability to 0.70, we find that the standard deviation of the noise is <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B1.67%5E2%5Cleft(%5Cfrac%7B1%7D%7B0.70%7D%20-%201%5Cright)%7D%20=%201.09">.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Measurement error on Z</span></span>
<span id="cb8-2">sd_Z <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>((slope_A<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>sd_A)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>slope_B)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(slope_A <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> slope_B <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> latent_covariance_matrix[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sigma_Z.AB<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb8-3">obs_Z <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(sd_Z<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.70</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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># reliability 0.70</span></span></code></pre></div></div>
</div>
<p>Figure 3 shows the causal diagram for the actually observed simulated data.</p>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-02-18-measurement-error/index_files/figure-html/unnamed-chunk-10-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 3.</strong> Graphical causal model for the simulated data. <code>A</code>, <code>B</code> and <code>Z</code> are now unobserved (latent) variables, but so-called ‘descendants’ of them were measured. These reflect their latent constructs imperfectly. Crucially, controlling for <code>obs_A</code> will <em>not</em> entirely control for the confound: the path between <code>obs_B</code> and <code>obs_Z</code> stays open.</figcaption>
</figure>
</div>
</div>
</div>
<p>As Figure 4 shows, the observed variables are all correlated with each other.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scatterplot_matrix</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(obs_Z, obs_A, obs_B))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-02-18-measurement-error/index_files/figure-html/unnamed-chunk-11-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 4.</strong></figcaption>
</figure>
</div>
</div>
</div>
<p>Crucially, controlling for <code>obs_A</code> in a regression model doesn’t entirely eradicate the confound and we find that <code>obs_B</code> is significantly related to <code>obs_Z</code> even after controlling for <code>obs_A</code> (<img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta%7D_%7BB_%7B%5Ctextrm%7Bobs%7D%7D%7D%20=%200.40%20%5Cpm%200.15">). Moreover, the regression model on the observed variables underestimates the strength of the relationship between the true construct scores (<img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta%7D_%7BA_%7B%5Ctextrm%7Bobs%7D%7D%7D%20=%200.40%20%5Cpm%200.07">, whereas <img src="https://latex.codecogs.com/png.latex?%5Cbeta_A%20=%200.7">).</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(obs_Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> obs_A <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> obs_B))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)    4.498     0.7588    5.93 8.49e-09
obs_A          0.402     0.0737    5.45 1.05e-07
obs_B          0.404     0.1470    2.75 6.41e-03</code></pre>
</div>
</div>
</section>
<section id="statistical-model" class="level3">
<h3 class="anchored" data-anchor-id="statistical-model">Statistical model</h3>
<p>The statistical model, written below in Stan code, corresponds to the data generating mechanism above and tries to infer its parameters from the observed data and some prior information.</p>
<p>The <code>data</code> block specifies the input that the model should handle. I think this is self-explanatory. Note that the latent variable scores <code>A</code>, <code>B</code> and <code>Z</code> aren’t part of the input as we wouldn’t have directly observed these.</p>
<p>The <code>parameters</code> block first defines the parameters needed for the regression model with the unobserved latent variables (the one we used to generate <code>Z</code>). It then defines the parameters needed to generate the true variables scores for <code>A</code> and <code>B</code> as well as the parameters needed to generate the observed scores from the true scores (viz., the true scores themselves and the reliabilities). Note that it is crucial to allow the model to estimate a correlation between <code>A</code> and <code>B</code>, otherwise it won’t ‘know’ that <code>A</code> confounds the <code>B</code>-<code>Z</code> relationship.</p>
<p>The <code>transformed parameters</code> block contains, well, transformations of these parameters. For instance, the standard deviations of <code>A</code> and <code>B</code> and the correlation between <code>A</code> and <code>B</code> are used to generate a variance-covariance matrix. Moreover, the standard deviations of the measurement noise are computed using the latent variables’ standard deviation and their reliabilities.</p>
<p>The <code>model</code> block, finally, specifies how we think the observed data and the (transformed or untransformed) parameters fit together and what plausible a priori values for the (transformed or untransformed) parameters are. These prior distributions are pretty abstract in this example: we generated context-free data ourselves, so it’s not clear what motivates these priors. The real example to follow will hopefully make more sense in this respect. You’ll notice that I’ve also specified a prior for the reliabilities. The reason is that you typically don’t know the reliability of an observed variable with perfect precision but that you have sample estimate with some inherent uncertainty. The priors reflect this uncertainty. Again, this will become clearer in the real example to follow.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">meas_error_code <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span></span>
<span id="cb12-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">data {</span></span>
<span id="cb12-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Number of observations</span></span>
<span id="cb12-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int&lt;lower = 1&gt; N;</span></span>
<span id="cb12-5"></span>
<span id="cb12-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Observed outcome</span></span>
<span id="cb12-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] obs_Z;</span></span>
<span id="cb12-8"></span>
<span id="cb12-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Observed predictors</span></span>
<span id="cb12-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] obs_A;</span></span>
<span id="cb12-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] obs_B;</span></span>
<span id="cb12-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb12-13"></span>
<span id="cb12-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">parameters {</span></span>
<span id="cb12-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Parameters for regression</span></span>
<span id="cb12-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real intercept;</span></span>
<span id="cb12-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real slope_A;</span></span>
<span id="cb12-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real slope_B;</span></span>
<span id="cb12-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma;</span></span>
<span id="cb12-20"></span>
<span id="cb12-21"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Latent predictors (= constructs):</span></span>
<span id="cb12-22"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // standard deviations and means</span></span>
<span id="cb12-23"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma_lat_A;</span></span>
<span id="cb12-24"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma_lat_B;</span></span>
<span id="cb12-25"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  row_vector[2] latent_means;</span></span>
<span id="cb12-26"></span>
<span id="cb12-27"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Correlation between latent predictors</span></span>
<span id="cb12-28"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = -1, upper = 1&gt; latent_rho;</span></span>
<span id="cb12-29"></span>
<span id="cb12-30"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Latent variables (true scores)</span></span>
<span id="cb12-31"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  matrix[N, 2] latent_predictors;</span></span>
<span id="cb12-32"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] lat_Z; // latent outcome</span></span>
<span id="cb12-33"></span>
<span id="cb12-34"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Unknown but estimated reliabilities</span></span>
<span id="cb12-35"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0, upper = 1&gt; reliability_A;</span></span>
<span id="cb12-36"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0, upper = 1&gt; reliability_B;</span></span>
<span id="cb12-37"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0, upper = 1&gt; reliability_Z;</span></span>
<span id="cb12-38"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb12-39"></span>
<span id="cb12-40"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">transformed parameters {</span></span>
<span id="cb12-41"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] mu_Z;  // conditional mean of outcome</span></span>
<span id="cb12-42"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] lat_A; // latent variables, separated out</span></span>
<span id="cb12-43"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] lat_B;</span></span>
<span id="cb12-44"></span>
<span id="cb12-45"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real error_A; // standard error of measurement</span></span>
<span id="cb12-46"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real error_B;</span></span>
<span id="cb12-47"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real error_Z;</span></span>
<span id="cb12-48"></span>
<span id="cb12-49"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // standard deviations of latent predictors, in matrix form</span></span>
<span id="cb12-50"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  matrix[2, 2] sigma_lat;</span></span>
<span id="cb12-51"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // correlation and covariance matrix for latent predictors</span></span>
<span id="cb12-52"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cov_matrix[2] latent_cor;</span></span>
<span id="cb12-53"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cov_matrix[2] latent_cov;</span></span>
<span id="cb12-54"></span>
<span id="cb12-55"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // standard deviation of latent outcome</span></span>
<span id="cb12-56"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma_lat_Z;</span></span>
<span id="cb12-57"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat_Z = sd(lat_Z);</span></span>
<span id="cb12-58"></span>
<span id="cb12-59"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Express measurement error in terms of</span></span>
<span id="cb12-60"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // standard deviation of constructs and reliability</span></span>
<span id="cb12-61"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  error_A = sqrt(sigma_lat_A^2*(1/reliability_A - 1));</span></span>
<span id="cb12-62"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  error_B = sqrt(sigma_lat_B^2*(1/reliability_B - 1));</span></span>
<span id="cb12-63"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  error_Z = sqrt(sigma_lat_Z^2*(1/reliability_Z - 1));</span></span>
<span id="cb12-64"></span>
<span id="cb12-65"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Define diagonal matrix with standard errors of latent variables</span></span>
<span id="cb12-66"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[1, 1] = sigma_lat_A;</span></span>
<span id="cb12-67"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[2, 2] = sigma_lat_B;</span></span>
<span id="cb12-68"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[1, 2] = 0;</span></span>
<span id="cb12-69"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[2, 1] = 0;</span></span>
<span id="cb12-70"></span>
<span id="cb12-71"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Define correlation matrix for latent variables</span></span>
<span id="cb12-72"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[1, 1] = 1;</span></span>
<span id="cb12-73"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[2, 2] = 1;</span></span>
<span id="cb12-74"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[1, 2] = latent_rho;</span></span>
<span id="cb12-75"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[2, 1] = latent_rho;</span></span>
<span id="cb12-76"></span>
<span id="cb12-77"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Compute covariance matrix for latent variables</span></span>
<span id="cb12-78"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cov = sigma_lat * latent_cor * sigma_lat;</span></span>
<span id="cb12-79"></span>
<span id="cb12-80"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Extract latent variables from matrix</span></span>
<span id="cb12-81"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  lat_A = latent_predictors[, 1];</span></span>
<span id="cb12-82"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  lat_B = latent_predictors[, 2];</span></span>
<span id="cb12-83"></span>
<span id="cb12-84"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Regression model for conditional mean of Z</span></span>
<span id="cb12-85"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  mu_Z = intercept + slope_A*lat_A + slope_B*lat_B;</span></span>
<span id="cb12-86"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb12-87"></span>
<span id="cb12-88"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">model {</span></span>
<span id="cb12-89"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Priors for regression parameters</span></span>
<span id="cb12-90"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  intercept ~ normal(0, 2);</span></span>
<span id="cb12-91"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  slope_A ~ normal(0, 2);</span></span>
<span id="cb12-92"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  slope_B ~ normal(0, 2);</span></span>
<span id="cb12-93"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma ~ normal(0, 2);</span></span>
<span id="cb12-94"></span>
<span id="cb12-95"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior for latent standard deviations</span></span>
<span id="cb12-96"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat_A ~ normal(0, 2);</span></span>
<span id="cb12-97"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat_B ~ normal(0, 2);</span></span>
<span id="cb12-98"></span>
<span id="cb12-99"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior for latent means</span></span>
<span id="cb12-100"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_means ~ normal(0, 3);</span></span>
<span id="cb12-101"></span>
<span id="cb12-102"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior expectation for correlation between latent variables.</span></span>
<span id="cb12-103"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Tend towards positive correlation, but pretty vague.</span></span>
<span id="cb12-104"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_rho ~ normal(0.4, 0.3);</span></span>
<span id="cb12-105"></span>
<span id="cb12-106"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior for reliabilities.</span></span>
<span id="cb12-107"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // These are estimated with some uncertainty, i.e.,</span></span>
<span id="cb12-108"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // they are not point values but distributions.</span></span>
<span id="cb12-109"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  reliability_A ~ beta(70, 30);</span></span>
<span id="cb12-110"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  reliability_B ~ beta(90, 10);</span></span>
<span id="cb12-111"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  reliability_Z ~ beta(70, 30);</span></span>
<span id="cb12-112"></span>
<span id="cb12-113"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Distribution of latent variable</span></span>
<span id="cb12-114"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  for (i in 1:N) {</span></span>
<span id="cb12-115"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    latent_predictors[i, ] ~ multi_normal(latent_means, latent_cov);</span></span>
<span id="cb12-116"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb12-117"></span>
<span id="cb12-118"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Generate latent outcome</span></span>
<span id="cb12-119"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  lat_Z ~ normal(mu_Z, sigma);</span></span>
<span id="cb12-120"></span>
<span id="cb12-121"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Add noise to latent variables</span></span>
<span id="cb12-122"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  obs_A ~ normal(lat_A, error_A);</span></span>
<span id="cb12-123"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  obs_B ~ normal(lat_B, error_B);</span></span>
<span id="cb12-124"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  obs_Z ~ normal(lat_Z, error_Z);</span></span>
<span id="cb12-125"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb12-126"></span>
<span id="cb12-127"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span></span></code></pre></div></div>
</div>
<p>Put the data in a list and fit the model:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">data_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb13-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">obs_Z =</span> obs_Z,</span>
<span id="cb13-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">obs_A =</span> obs_A,</span>
<span id="cb13-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">obs_B =</span> obs_B,</span>
<span id="cb13-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">N =</span> n</span>
<span id="cb13-6">)</span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">meas_error_model <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cmdstan_model</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_stan_file</span>(meas_error_code))</span>
<span id="cb14-2">model_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> meas_error_model<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(</span>
<span id="cb14-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> data_list</span>
<span id="cb14-4">  , <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="cb14-5">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">chains =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb14-6">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parallel_chains =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb14-7">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter_warmup =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span></span>
<span id="cb14-8">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter_sampling =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span></span>
<span id="cb14-9">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span></span>
<span id="cb14-10">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_treedepth =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span></span>
<span id="cb14-11">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">adapt_delta =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.99</span></span>
<span id="cb14-12">)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Running MCMC with 4 parallel chains...

Chain 1 Iteration:    1 / 2000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 2 Iteration:    1 / 2000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 3 Iteration:    1 / 2000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 4 Iteration:    1 / 2000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 2 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 1 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 3 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 4 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 2 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 2 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 1 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 1 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 3 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 3 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 2 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 4 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 4 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 3 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 2 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 2 finished in 393.6 seconds.
Chain 1 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 3 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 3 finished in 452.6 seconds.
Chain 4 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 1 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 1 finished in 547.0 seconds.
Chain 4 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 4 finished in 565.3 seconds.

All 4 chains finished successfully.
Mean chain execution time: 489.7 seconds.
Total execution time: 565.7 seconds.</code></pre>
</div>
</div>
</section>
<section id="results" class="level3">
<h3 class="anchored" data-anchor-id="results">Results</h3>
<!-- ```{r, echo = FALSE} -->
<!-- meas_error_model <- readRDS("measurement_error_model.rds") -->
<!-- ``` -->
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1">model_fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(</span>
<span id="cb20-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"intercept"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope_A"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope_B"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma"</span></span>
<span id="cb20-3">                ,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma_lat_A"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma_lat_B"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma_lat_Z"</span></span>
<span id="cb20-4">                ,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"latent_means"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"latent_rho"</span></span>
<span id="cb20-5">                , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reliability_A"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reliability_B"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reliability_Z"</span></span>
<span id="cb20-6">                ,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"error_A"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"error_B"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"error_Z"</span>)</span>
<span id="cb20-7">  , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sd"</span></span>
<span id="cb20-8">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">extra_quantiles =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>posterior<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile2</span>(., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</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.025</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>))</span>
<span id="cb20-9">  , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rhat"</span></span>
<span id="cb20-10">)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 16 × 6
   variable          mean     sd   q2.5  q97.5  rhat
   &lt;chr&gt;            &lt;dbl&gt;  &lt;dbl&gt;  &lt;dbl&gt;  &lt;dbl&gt; &lt;dbl&gt;
 1 intercept        0.625 1.50   -2.45   3.38   1.01
 2 slope_A          0.870 0.168   0.564  1.22   1.01
 3 slope_B         -0.202 0.256  -0.732  0.274  1.01
 4 sigma            1.18  0.120   0.933  1.40   1.00
 5 sigma_lat_A      1.39  0.0708  1.26   1.53   1.00
 6 sigma_lat_B      0.796 0.0348  0.729  0.868  1.00
 7 sigma_lat_Z      1.60  0.0683  1.46   1.73   1.00
 8 latent_means[1]  3.07  0.0970  2.87   3.25   1.00
 9 latent_means[2] -4.02  0.0474 -4.11  -3.93   1.00
10 latent_rho       0.782 0.0482  0.684  0.871  1.01
11 reliability_A    0.692 0.0413  0.614  0.772  1.01
12 reliability_B    0.900 0.0298  0.833  0.950  1.01
13 reliability_Z    0.701 0.0449  0.609  0.784  1.00
14 error_A          0.927 0.0717  0.784  1.06   1.01
15 error_B          0.263 0.0408  0.186  0.346  1.01
16 error_Z          1.04  0.0848  0.876  1.21   1.00</code></pre>
</div>
</div>
<p>The model recovers the true parameter values pretty well (Table 1) and, on the basis of this model, you wouldn’t erroneously conclude that <code>B</code> is causally related to <code>Z</code> (see the parameter estimate for <code>slope_B</code>).</p>
<table class="caption-top table">
<caption><strong>Table 1.</strong> Comparison of the true parameter values and their estimates. Parameters prefixed with ‘*’ are transformations of other parameters. The estimated reliability parameters aren’t really estimated from the data: they just reflect the prior distributions put on them.</caption>
<thead>
<tr class="header">
<th>Parameter</th>
<th style="text-align: right;">True value</th>
<th style="text-align: right;">Estimate</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>intercept</td>
<td style="text-align: right;">2.00</td>
<td style="text-align: right;">0.65 ± 1.53</td>
</tr>
<tr class="even">
<td>slope_A</td>
<td style="text-align: right;">0.70</td>
<td style="text-align: right;">0.87 ± 0.17</td>
</tr>
<tr class="odd">
<td>slope_B</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">-0.20 ± 0.25</td>
</tr>
<tr class="even">
<td>sigma_Z.AB</td>
<td style="text-align: right;">1.30</td>
<td style="text-align: right;">1.17 ± 0.13</td>
</tr>
<tr class="odd">
<td>sd_A</td>
<td style="text-align: right;">1.50</td>
<td style="text-align: right;">1.40 ± 0.07</td>
</tr>
<tr class="even">
<td>sd_B</td>
<td style="text-align: right;">0.80</td>
<td style="text-align: right;">0.80 ± 0.04</td>
</tr>
<tr class="odd">
<td>mean_A</td>
<td style="text-align: right;">3.00</td>
<td style="text-align: right;">3.07 ± 0.10</td>
</tr>
<tr class="even">
<td>mean_B</td>
<td style="text-align: right;">-4.00</td>
<td style="text-align: right;">-4.02 ± 0.05</td>
</tr>
<tr class="odd">
<td>rho</td>
<td style="text-align: right;">0.73</td>
<td style="text-align: right;">0.78 ± 0.05</td>
</tr>
<tr class="even">
<td>reliability_A</td>
<td style="text-align: right;">0.70</td>
<td style="text-align: right;">0.69 ± 0.04</td>
</tr>
<tr class="odd">
<td>reliability_B</td>
<td style="text-align: right;">0.90</td>
<td style="text-align: right;">0.90 ± 0.03</td>
</tr>
<tr class="even">
<td>reliability_Z</td>
<td style="text-align: right;">0.70</td>
<td style="text-align: right;">0.70 ± 0.05</td>
</tr>
<tr class="odd">
<td>*sd_Z</td>
<td style="text-align: right;">1.67</td>
<td style="text-align: right;">1.59 ± 0.07</td>
</tr>
<tr class="even">
<td>*error_A</td>
<td style="text-align: right;">0.98</td>
<td style="text-align: right;">0.93 ± 0.07</td>
</tr>
<tr class="odd">
<td>*error_B</td>
<td style="text-align: right;">0.27</td>
<td style="text-align: right;">0.26 ± 0.04</td>
</tr>
<tr class="even">
<td>*error_Z</td>
<td style="text-align: right;">1.09</td>
<td style="text-align: right;">1.04 ± 0.09</td>
</tr>
</tbody>
</table>
<p>In the previous blog post, I’ve shown that such a model also estimates the latent true variable scores and that these estimates correspond more closely to the actual true variable scores than do the observed variable scores. I’ll skip this step here.</p>
</section>
</section>
<section id="real-life-example-interdependence" class="level2">
<h2 class="anchored" data-anchor-id="real-life-example-interdependence">Real-life example: Interdependence</h2>
<p>Satisfied that our model can recover the actual parameter values in scenarios such as those depicted in Figure 3, we now turn to a real-life example of such a situation. The example was already described in the previous blog post; here I’ll just draw the causal model that assumes that reflects the null hypothesis that a child’s Portuguese skills at T2 (<code>PT.T2</code>) don’t contribute to their French skills at T3 (<code>FR.T3</code>), but that due to common factors such as intelligence, form on the day etc. (<img src="https://latex.codecogs.com/png.latex?U">), French skills and Portuguese skills at T2 are correlated across children. What is observed are test scores, not the children’s actual skills.</p>
<div class="cell">
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-02-18-measurement-error/index_files/figure-html/unnamed-chunk-17-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 5</strong></figcaption>
</figure>
</div>
</div>
</div>
<section id="data" class="level3">
<h3 class="anchored" data-anchor-id="data">Data</h3>
<p>The command below is pig-ugly, but allows you to easily read in the data.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1">skills <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">structure</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb22-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Subject =</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_PLF_1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_10"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_12"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_13"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_14"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_15"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_16"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_17"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_19"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_3"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_4"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_7"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_8"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_9"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA_PLF_11"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA_PLF_12"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA_PLF_13"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA_PLF_6"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA_PLF_7"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA_PLF_8"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_10"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_11"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_13"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_14"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_15"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_16"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_17"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_18"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_19"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_20"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_21"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_22"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_24"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_25"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_26"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_4"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_6"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_8"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_9"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AE_PLF_1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AE_PLF_2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AE_PLF_4"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AE_PLF_5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AE_PLF_6"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C_PLF_1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C_PLF_16"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C_PLF_19"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C_PLF_30"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_3"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_4"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_6"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_7"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_8"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_12"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_15"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_16"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_17"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_18"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_20"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_24"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_25"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_26"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_27"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_28"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_29"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_3"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_31"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_32"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_33"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_34"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_36"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_4"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_6"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_7"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_8"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_9"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_3"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_4"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_6"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_7"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_8"</span>)</span>
<span id="cb22-3">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FR_T2 =</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.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2631578947</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2631578947</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>)</span>
<span id="cb22-4">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PT_T2 =</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.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2631578947</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0526315789</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>)</span>
<span id="cb22-5">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FR_T3 =</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.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2631578947</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>)</span>
<span id="cb22-6">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PT_T3 =</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.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2105263158</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>)</span>
<span id="cb22-7">  )</span>
<span id="cb22-8">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</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 class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">91</span>L)</span>
<span id="cb22-9">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">class =</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;">"tbl_df"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tbl"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data.frame"</span>)</span>
<span id="cb22-10">)</span></code></pre></div></div>
</div>
</section>
<section id="statistical-model-1" class="level3">
<h3 class="anchored" data-anchor-id="statistical-model-1">Statistical model</h3>
<p>The only thing that’s changed in the statistical model compared to the example with the simulated data is that I’ve renamed the parameters and that the prior distributions are better motivated. Let’s consider each prior distribution in turn:</p>
<ul>
<li><code>intercept ~ normal(0.2, 0.1);</code>: The intercept is the average true French skill score at T3 for children whose true French and Portuguese skill scores at T2 are 0. This is the lowest possible score (the theoretical range of the data is [0, 1]), so we’d expect such children to perform poorly at T3, too. A <code>normal(0.2, 0.1)</code> distribution puts 95% probability on such children having a true French score at T3 between 0 and 0.4.</li>
<li><code>slope_FR ~ normal(0.5, 0.25);</code>: This parameter expresses the difference between the average true French skill score at T3 for children with a true French skill score of 1 at T2 (the theoretical maximum) vs.&nbsp;those with a true French skill score of 0 at T2 (the theoretical minimum). This is obviously some value between -1 and 1, and presumably it’s going to be positive. A <code>normal(0.5, 0.25)</code> puts 95% probability on this difference lying between 0 and 1, which I think is reasonable.</li>
<li><code>slope_PT ~ normal(0, 0.25);</code>: The slope for Portuguese is bound to be smaller than the one for French. Moreover, it’s not a given that it will be appreciably different from zero. Hence a prior centred on 0 that still gives the data a chance to pull the estimate in either direction.</li>
<li><code>sigma ~ normal(0.15, 0.08);</code>: If neither of the T2 variables predicts T3, uncertainty is highest when the mean T3 score is 0.5. Since these scores are bounded between 0 and 1, the standard deviation could not be much higher than 0.20. But French T2 is bound to be a predictor, so let us choose a slightly lower value (0.15).</li>
<li><code>latent_means ~ normal(0.5, 0.1);</code>: These are the prior expectations for the true score means of the T2 variables. 0.5 lies in the middle of the scale; the <code>normal(0.5, 0.1)</code> prior puts 95% probability on these means to lie between 0.3 and 0.7.</li>
<li><code>sigma_lat_FR_T2 ~ normal(0, 0.25);</code>, <code>sigma_lat_FR_T2 ~ normal(0, 0.25);</code>: The standard deviations of the latent T2 variables. If these truncated normal distributions put a 95% probability of the latent standard deviations to be lower than 0.50.</li>
<li><code>latent_rho ~ normal(0.4, 0.3);</code>: The a priori expected correlation between the latent variables <code>A</code> and <code>B</code>. These are bound to be positively correlated.</li>
<li><code>reliability_FR_T2 ~ beta(100, 100*0.27/0.73);</code> The prior distribution for the reliability of the French T2 variable. Cronbach’s <img src="https://latex.codecogs.com/png.latex?%5Calpha"> for this variable was 0.73 (95% CI: [0.65, 0.78]). This roughly corresponds to a <code>beta(100, 100*0.27/0.73)</code> distribution:</li>
</ul>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qbeta</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.025</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</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.27</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.73</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.653 0.801</code></pre>
</div>
</div>
<ul>
<li><code>reliability_PT_T2 ~ beta(120, 120*0.21/0.79);</code> Similarly, Cronbach’s <img src="https://latex.codecogs.com/png.latex?%5Calpha"> for the Portuguese T2 variable was 0.79 (95% CI: [0.72, 0.84]), which roughly corresponds to a <code>beta(120, 120*0.21/0.79)</code> distribution:</li>
</ul>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qbeta</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.025</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>), <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">120</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">120</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.21</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.79</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.722 0.851</code></pre>
</div>
</div>
<ul>
<li><code>reliability_FR_T3 ~ beta(73, 27);</code>: The estimated reliability for the French T3 data was similar to that of the T2 data, so I used the same prior.</li>
</ul>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1">interdependence_code <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span></span>
<span id="cb27-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">data {</span></span>
<span id="cb27-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Number of observations</span></span>
<span id="cb27-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int&lt;lower = 1&gt; N;</span></span>
<span id="cb27-5"></span>
<span id="cb27-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Observed outcome</span></span>
<span id="cb27-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] FR_T3;</span></span>
<span id="cb27-8"></span>
<span id="cb27-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Observed predictors</span></span>
<span id="cb27-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] FR_T2;</span></span>
<span id="cb27-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] PT_T2;</span></span>
<span id="cb27-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb27-13"></span>
<span id="cb27-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">parameters {</span></span>
<span id="cb27-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Parameters for regression</span></span>
<span id="cb27-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real intercept;</span></span>
<span id="cb27-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real slope_FR;</span></span>
<span id="cb27-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real slope_PT;</span></span>
<span id="cb27-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma;</span></span>
<span id="cb27-20"></span>
<span id="cb27-21"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // standard deviations of latent predictors (= constructs)</span></span>
<span id="cb27-22"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma_lat_FR_T2;</span></span>
<span id="cb27-23"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma_lat_PT_T2;</span></span>
<span id="cb27-24"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb27-25"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Means of latent predictors</span></span>
<span id="cb27-26"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  row_vector[2] latent_means;</span></span>
<span id="cb27-27"></span>
<span id="cb27-28"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Unknown correlation between latent predictors</span></span>
<span id="cb27-29"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = -1, upper = 1&gt; latent_rho;</span></span>
<span id="cb27-30"></span>
<span id="cb27-31"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Latent variables</span></span>
<span id="cb27-32"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  matrix[N, 2] latent_predictors;</span></span>
<span id="cb27-33"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] lat_FR_T3; // latent outcome</span></span>
<span id="cb27-34"></span>
<span id="cb27-35"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Unknown but estimated reliabilities</span></span>
<span id="cb27-36"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0, upper = 1&gt; reliability_FR_T2;</span></span>
<span id="cb27-37"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0, upper = 1&gt; reliability_PT_T2;</span></span>
<span id="cb27-38"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0, upper = 1&gt; reliability_FR_T3;</span></span>
<span id="cb27-39"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb27-40"></span>
<span id="cb27-41"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">transformed parameters {</span></span>
<span id="cb27-42"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] mu_FR_T3;  // conditional mean of outcome</span></span>
<span id="cb27-43"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] lat_FR_T2; // latent variables, separated out</span></span>
<span id="cb27-44"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] lat_PT_T2;</span></span>
<span id="cb27-45"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real error_FR_T2; // standard error of measurement</span></span>
<span id="cb27-46"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real error_PT_T2;</span></span>
<span id="cb27-47"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real error_FR_T3;</span></span>
<span id="cb27-48"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb27-49"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // standard deviations of latent predictors, in matrix form</span></span>
<span id="cb27-50"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  matrix[2, 2] sigma_lat;</span></span>
<span id="cb27-51"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb27-52"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // correlation and covariance matrix for latent predictors</span></span>
<span id="cb27-53"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cov_matrix[2] latent_cor;</span></span>
<span id="cb27-54"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cov_matrix[2] latent_cov;</span></span>
<span id="cb27-55"></span>
<span id="cb27-56"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // standard deviation of latent outcome</span></span>
<span id="cb27-57"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma_lat_FR_T3;</span></span>
<span id="cb27-58"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat_FR_T3 = sd(lat_FR_T3);</span></span>
<span id="cb27-59"></span>
<span id="cb27-60"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Express measurement error in terms of</span></span>
<span id="cb27-61"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // standard deviation of constructs and reliability</span></span>
<span id="cb27-62"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  error_FR_T2 = sqrt(sigma_lat_FR_T2^2*(1/reliability_FR_T2 - 1));</span></span>
<span id="cb27-63"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  error_PT_T2 = sqrt(sigma_lat_PT_T2^2*(1/reliability_PT_T2 - 1));</span></span>
<span id="cb27-64"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  error_FR_T3 = sqrt(sigma_lat_FR_T3^2*(1/reliability_FR_T3 - 1));</span></span>
<span id="cb27-65"></span>
<span id="cb27-66"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Define diagonal matrix with standard errors of latent variables</span></span>
<span id="cb27-67"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[1, 1] = sigma_lat_FR_T2;</span></span>
<span id="cb27-68"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[2, 2] = sigma_lat_PT_T2;</span></span>
<span id="cb27-69"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[1, 2] = 0;</span></span>
<span id="cb27-70"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[2, 1] = 0;</span></span>
<span id="cb27-71"></span>
<span id="cb27-72"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Define correlation matrix for latent variables</span></span>
<span id="cb27-73"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[1, 1] = 1;</span></span>
<span id="cb27-74"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[2, 2] = 1;</span></span>
<span id="cb27-75"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[1, 2] = latent_rho;</span></span>
<span id="cb27-76"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[2, 1] = latent_rho;</span></span>
<span id="cb27-77"></span>
<span id="cb27-78"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Compute covariance matrix for latent variables</span></span>
<span id="cb27-79"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cov = sigma_lat * latent_cor * sigma_lat;</span></span>
<span id="cb27-80"></span>
<span id="cb27-81"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Extract latent variables from matrix</span></span>
<span id="cb27-82"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  lat_FR_T2 = latent_predictors[, 1];</span></span>
<span id="cb27-83"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  lat_PT_T2 = latent_predictors[, 2];</span></span>
<span id="cb27-84"></span>
<span id="cb27-85"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Regression model for conditional mean of Z</span></span>
<span id="cb27-86"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  mu_FR_T3 = intercept + slope_FR*lat_FR_T2 + slope_PT*lat_PT_T2;</span></span>
<span id="cb27-87"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb27-88"></span>
<span id="cb27-89"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">model { </span></span>
<span id="cb27-90"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Priors for regression parameters </span></span>
<span id="cb27-91"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  intercept ~ normal(0.2, 0.1); </span></span>
<span id="cb27-92"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  slope_FR ~ normal(0.5, 0.25); </span></span>
<span id="cb27-93"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  slope_PT ~ normal(0, 0.25); </span></span>
<span id="cb27-94"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma ~ normal(0.15, 0.08); </span></span>
<span id="cb27-95"></span>
<span id="cb27-96"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior for latent means </span></span>
<span id="cb27-97"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_means ~ normal(0.5, 0.1); </span></span>
<span id="cb27-98"></span>
<span id="cb27-99"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior for latent standard deviations </span></span>
<span id="cb27-100"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat_FR_T2 ~ normal(0, 0.25); </span></span>
<span id="cb27-101"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat_PT_T2 ~ normal(0, 0.25); </span></span>
<span id="cb27-102"></span>
<span id="cb27-103"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior expectation for correlation between latent variables. </span></span>
<span id="cb27-104"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_rho ~ normal(0.4, 0.3); </span></span>
<span id="cb27-105"></span>
<span id="cb27-106"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior for reliabilities. </span></span>
<span id="cb27-107"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // These are estimated with some uncertainty, i.e., </span></span>
<span id="cb27-108"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // they are not point values but distributions. </span></span>
<span id="cb27-109"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  reliability_FR_T2 ~ beta(100, 100*0.27/0.73); </span></span>
<span id="cb27-110"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  reliability_PT_T2 ~ beta(120, 120*0.21/0.79); </span></span>
<span id="cb27-111"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  reliability_FR_T3 ~ beta(100, 100*0.27/0.73); </span></span>
<span id="cb27-112"></span>
<span id="cb27-113"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Distribution of latent variable </span></span>
<span id="cb27-114"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  for (i in 1:N) { </span></span>
<span id="cb27-115"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    latent_predictors[i, ] ~ multi_normal(latent_means, latent_cov); </span></span>
<span id="cb27-116"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  } </span></span>
<span id="cb27-117"></span>
<span id="cb27-118"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Generate latent outcome </span></span>
<span id="cb27-119"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  lat_FR_T3 ~ normal(mu_FR_T3, sigma); </span></span>
<span id="cb27-120"></span>
<span id="cb27-121"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Measurement model </span></span>
<span id="cb27-122"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  FR_T2 ~ normal(lat_FR_T2, error_FR_T2); </span></span>
<span id="cb27-123"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  PT_T2 ~ normal(lat_PT_T2, error_PT_T2); </span></span>
<span id="cb27-124"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  FR_T3 ~ normal(lat_FR_T3, error_FR_T3); </span></span>
<span id="cb27-125"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">} </span></span>
<span id="cb27-126"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span> </span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1">data_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb28-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FR_T2 =</span> skills<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FR_T2,</span>
<span id="cb28-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PT_T2 =</span> skills<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PT_T2,</span>
<span id="cb28-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FR_T3 =</span> skills<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FR_T3,</span>
<span id="cb28-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">N =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(skills<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FR_T3)</span>
<span id="cb28-6">)</span>
<span id="cb28-7"></span>
<span id="cb28-8">interdependence_model <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cmdstan_model</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_stan_file</span>(interdependence_code))</span>
<span id="cb28-9">interdependence_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> interdependence_model<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(</span>
<span id="cb28-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> data_list</span>
<span id="cb28-11">  , <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;">42</span></span>
<span id="cb28-12">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">chains =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb28-13">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parallel_chains =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb28-14">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter_warmup =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2000</span></span>
<span id="cb28-15">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter_sampling =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6000</span></span>
<span id="cb28-16">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span></span>
<span id="cb28-17">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_treedepth =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span></span>
<span id="cb28-18">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">adapt_delta =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9999</span></span>
<span id="cb28-19">)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Running MCMC with 4 parallel chains...

Chain 1 Iteration:    1 / 8000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 2 Iteration:    1 / 8000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 3 Iteration:    1 / 8000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 4 Iteration:    1 / 8000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 2 Iteration: 1000 / 8000 [ 12%]  (Warmup) 
Chain 4 Iteration: 1000 / 8000 [ 12%]  (Warmup) 
Chain 3 Iteration: 1000 / 8000 [ 12%]  (Warmup) 
Chain 1 Iteration: 1000 / 8000 [ 12%]  (Warmup) 
Chain 2 Iteration: 2000 / 8000 [ 25%]  (Warmup) 
Chain 2 Iteration: 2001 / 8000 [ 25%]  (Sampling) 
Chain 3 Iteration: 2000 / 8000 [ 25%]  (Warmup) 
Chain 3 Iteration: 2001 / 8000 [ 25%]  (Sampling) 
Chain 1 Iteration: 2000 / 8000 [ 25%]  (Warmup) 
Chain 1 Iteration: 2001 / 8000 [ 25%]  (Sampling) 
Chain 4 Iteration: 2000 / 8000 [ 25%]  (Warmup) 
Chain 4 Iteration: 2001 / 8000 [ 25%]  (Sampling) 
Chain 3 Iteration: 3000 / 8000 [ 37%]  (Sampling) 
Chain 1 Iteration: 3000 / 8000 [ 37%]  (Sampling) 
Chain 2 Iteration: 3000 / 8000 [ 37%]  (Sampling) 
Chain 3 Iteration: 4000 / 8000 [ 50%]  (Sampling) 
Chain 1 Iteration: 4000 / 8000 [ 50%]  (Sampling) 
Chain 3 Iteration: 5000 / 8000 [ 62%]  (Sampling) 
Chain 2 Iteration: 4000 / 8000 [ 50%]  (Sampling) 
Chain 1 Iteration: 5000 / 8000 [ 62%]  (Sampling) 
Chain 3 Iteration: 6000 / 8000 [ 75%]  (Sampling) 
Chain 4 Iteration: 3000 / 8000 [ 37%]  (Sampling) 
Chain 3 Iteration: 7000 / 8000 [ 87%]  (Sampling) 
Chain 1 Iteration: 6000 / 8000 [ 75%]  (Sampling) 
Chain 2 Iteration: 5000 / 8000 [ 62%]  (Sampling) 
Chain 3 Iteration: 8000 / 8000 [100%]  (Sampling) 
Chain 3 finished in 484.7 seconds.
Chain 1 Iteration: 7000 / 8000 [ 87%]  (Sampling) 
Chain 1 Iteration: 8000 / 8000 [100%]  (Sampling) 
Chain 1 finished in 539.1 seconds.
Chain 2 Iteration: 6000 / 8000 [ 75%]  (Sampling) 
Chain 4 Iteration: 4000 / 8000 [ 50%]  (Sampling) 
Chain 2 Iteration: 7000 / 8000 [ 87%]  (Sampling) 
Chain 2 Iteration: 8000 / 8000 [100%]  (Sampling) 
Chain 2 finished in 673.1 seconds.
Chain 4 Iteration: 5000 / 8000 [ 62%]  (Sampling) 
Chain 4 Iteration: 6000 / 8000 [ 75%]  (Sampling) 
Chain 4 Iteration: 7000 / 8000 [ 87%]  (Sampling) 
Chain 4 Iteration: 8000 / 8000 [100%]  (Sampling) 
Chain 4 finished in 963.9 seconds.

All 4 chains finished successfully.
Mean chain execution time: 665.2 seconds.
Total execution time: 964.1 seconds.</code></pre>
</div>
</div>
</section>
<section id="results-1" class="level3">
<h3 class="anchored" data-anchor-id="results-1">Results</h3>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1">interdependence_fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(</span>
<span id="cb34-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"intercept"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope_FR"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope_PT"</span></span>
<span id="cb34-3">                , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"latent_rho"</span>)</span>
<span id="cb34-4">  , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sd"</span></span>
<span id="cb34-5">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">extra_quantiles =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>posterior<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile2</span>(., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</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.025</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>))</span>
<span id="cb34-6">  , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rhat"</span></span>
<span id="cb34-7">)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 5 × 6
  variable     mean     sd    q2.5 q97.5  rhat
  &lt;chr&gt;       &lt;dbl&gt;  &lt;dbl&gt;   &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
1 intercept  0.190  0.0530  0.0850 0.294  1.00
2 slope_FR   0.710  0.154   0.411  1.02   1.00
3 slope_PT   0.109  0.138  -0.167  0.377  1.00
4 sigma      0.0732 0.0177  0.0357 0.106  1.00
5 latent_rho 0.813  0.0779  0.645  0.951  1.00</code></pre>
</div>
</div>
<p>Unsurprisingly, the model confidently finds a link between French skills at T2 and at T3, even on the level of the unobserved true scores (<img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta%7D_%7B%5Ctextrm%7BFrench%7D%7D%20=%200.71%20%5Cpm%200.15">). But more importantly, the evidence for an additional effect of Portuguese skills at T2 on French skills at T3 is flimsy (<img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Cbeta%7D_%7B%5Ctextrm%7BPortuguese%7D%7D%20=%200.11%20%5Cpm%200.14">). The latent T2 variables are estimated to correlate strongly at <img src="https://latex.codecogs.com/png.latex?%5Cwidehat%7B%5Crho%7D%20=%200.81%20%5Cpm%200.08">. These results don’t change much when a flat prior on <img src="https://latex.codecogs.com/png.latex?%5Crho"> is specified (this can be accomplished by not specifying any prior at all for <img src="https://latex.codecogs.com/png.latex?%5Crho">). Compared to the model in the previous blog post (Table 2), little has changed. The only appreciable difference is that the estimate for <code>sigma</code> is lower. The reason is that, unlike the previous model, the current model partitions the variance in the French T3 scores into true score variance and measurement error variance. In this model, <code>sigma</code> captures the true score variance that isn’t accounted for by T2 skills, whereas in the previous model, <code>sigma</code> captured the <em>total</em> variance that wasn’t accounted for by T2 skills. But other than that, the current model doesn’t represent a huge change from the previous one.</p>
<table class="caption-top table">
<caption><strong>Table 2.</strong> Comparison of parameter estimates between the model fitted in this blog post and the model fitted in the previous one. In the previous model, the outcome was assumed to be perfectly reliable.</caption>
<thead>
<tr class="header">
<th>Parameter</th>
<th style="text-align: right;">Current estimate</th>
<th style="text-align: right;">Previous estimate</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>intercept</td>
<td style="text-align: right;">0.19 ± 0.05</td>
<td style="text-align: right;">0.19 ± 0.05</td>
</tr>
<tr class="even">
<td>slope_FR</td>
<td style="text-align: right;">0.71 ± 0.15</td>
<td style="text-align: right;">0.71 ± 0.16</td>
</tr>
<tr class="odd">
<td>slope_PT</td>
<td style="text-align: right;">0.11 ± 0.14</td>
<td style="text-align: right;">0.10 ± 0.14</td>
</tr>
<tr class="even">
<td>sigma</td>
<td style="text-align: right;">0.07 ± 0.02</td>
<td style="text-align: right;">0.12 ± 0.01</td>
</tr>
<tr class="odd">
<td>latent_rho</td>
<td style="text-align: right;">0.81 ± 0.08</td>
<td style="text-align: right;">0.81 ± 0.08</td>
</tr>
</tbody>
</table>
<p>A couple of things still remain to be done. First, the French test at T3 was the same as the one at T2 so it’s likely that the measurement errors on both scores won’t be completely independent of one another. I’d like to find out how correlated measurement errors affect the parameter estimates. Second, I’d like to get started with prior and posterior predictive checks: the former to check if the priors give rise to largely possible data patterns, and the latter to check if the full model tends to generate data sets similar to the one actually observed.</p>
</section>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<p>Berthele, Raphael and Jan Vanhove. 2017. <a href="https://doi.org/10.1080/13670050.2017.1385590">What would disprove interdependence? Lessons learned from a study on biliteracy in Portuguese heritage language speakers in Switzerland.</a> <em>International Journal of Bilingual Education and Bilingualism</em>.</p>
<p>Brunner, Jerry and Peter C. Austin. 2009. <a href="https://doi.org/10.1002/cjs.10004">Inflation of Type I error rate in multiple regression when independent variables are measured with error.</a> <em>Canadian Journal of Statistics</em> 37(1). 33–46.</p>
<p>Westfall, Jacob and Tal Yarkoni. 2016. <a href="https://doi.org/10.1371/journal.pone.0152719">Statistically controlling for confounding constructs is harder than you think.</a>. <em>PLOS ONE</em> 11(3). e0152719.</p>
</section>
<section id="software-versions" class="level2">
<h2 class="anchored" data-anchor-id="software-versions">Software versions</h2>
<p>Please note that I reran the code on this page on August 6, 2023.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1">devtools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">session_info</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.1 (2025-06-13)
 os       Ubuntu 22.04.5 LTS
 system   x86_64, linux-gnu
 ui       X11
 language en_US
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Zurich
 date     2025-10-09
 pandoc   2.12 @ /home/jan/miniconda3/bin/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────
 package        * version  date (UTC) lib source
 abind            1.4-8    2024-09-12 [1] CRAN (R 4.5.1)
 backports        1.5.0    2024-05-23 [1] CRAN (R 4.5.1)
 boot             1.3-32   2025-08-29 [4] CRAN (R 4.5.1)
 cachem           1.1.0    2024-05-16 [1] CRAN (R 4.5.1)
 callr            3.7.6    2024-03-25 [1] CRAN (R 4.5.1)
 checkmate        2.3.3    2025-08-18 [1] CRAN (R 4.5.1)
 cli              3.6.5    2025-04-23 [1] CRAN (R 4.5.1)
 cmdstanr       * 0.9.0    2025-03-30 [1] https://stan-dev.r-universe.dev (R 4.5.1)
 coda             0.19-4.1 2024-01-31 [1] CRAN (R 4.5.1)
 codetools        0.2-19   2023-02-01 [4] CRAN (R 4.2.2)
 crayon           1.5.1    2022-03-26 [2] CRAN (R 4.2.0)
 curl             6.4.0    2025-06-22 [1] CRAN (R 4.5.1)
 dagitty        * 0.3-4    2023-12-07 [1] CRAN (R 4.5.1)
 data.table       1.17.6   2025-06-17 [1] CRAN (R 4.5.1)
 devtools         2.4.5    2022-10-11 [1] CRAN (R 4.5.1)
 digest           0.6.37   2024-08-19 [1] CRAN (R 4.5.1)
 distributional   0.5.0    2024-09-17 [1] CRAN (R 4.5.1)
 ellipsis         0.3.2    2021-04-29 [2] CRAN (R 4.2.0)
 evaluate         1.0.4    2025-06-18 [1] CRAN (R 4.5.1)
 fastmap          1.2.0    2024-05-15 [1] CRAN (R 4.5.1)
 fs               1.5.2    2021-12-08 [2] CRAN (R 4.2.0)
 generics         0.1.4    2025-05-09 [1] CRAN (R 4.5.1)
 glue             1.6.2    2022-02-24 [2] CRAN (R 4.2.0)
 htmltools        0.5.8.1  2024-04-04 [1] CRAN (R 4.5.1)
 htmlwidgets      1.6.4    2023-12-06 [1] CRAN (R 4.5.1)
 httpuv           1.6.16   2025-04-16 [1] CRAN (R 4.5.1)
 jsonlite         2.0.0    2025-03-27 [1] CRAN (R 4.5.1)
 knitr            1.50     2025-03-16 [1] CRAN (R 4.5.1)
 later            1.4.2    2025-04-08 [1] CRAN (R 4.5.1)
 lattice          0.22-5   2023-10-24 [4] CRAN (R 4.3.1)
 lifecycle        1.0.4    2023-11-07 [1] CRAN (R 4.5.1)
 loo              2.8.0    2024-07-03 [1] CRAN (R 4.5.1)
 magrittr         2.0.3    2022-03-30 [1] CRAN (R 4.5.1)
 MASS             7.3-65   2025-02-28 [4] CRAN (R 4.4.3)
 matrixStats      1.5.0    2025-01-07 [1] CRAN (R 4.5.1)
 memoise          2.0.1    2021-11-26 [2] CRAN (R 4.2.0)
 mime             0.10     2021-02-13 [2] CRAN (R 4.0.2)
 miniUI           0.1.2    2025-04-17 [1] CRAN (R 4.5.1)
 mvtnorm          1.3-3    2025-01-10 [1] CRAN (R 4.5.1)
 pillar           1.10.2   2025-04-05 [1] CRAN (R 4.5.1)
 pkgbuild         1.3.1    2021-12-20 [2] CRAN (R 4.2.0)
 pkgconfig        2.0.3    2019-09-22 [2] CRAN (R 4.2.0)
 pkgload          1.4.0    2024-06-28 [1] CRAN (R 4.5.1)
 posterior      * 1.6.1    2025-02-27 [1] CRAN (R 4.5.1)
 prettyunits      1.1.1    2020-01-24 [2] CRAN (R 4.2.0)
 processx         3.8.6    2025-02-21 [1] CRAN (R 4.5.1)
 profvis          0.4.0    2024-09-20 [1] CRAN (R 4.5.1)
 promises         1.3.3    2025-05-29 [1] CRAN (R 4.5.1)
 ps               1.9.1    2025-04-12 [1] CRAN (R 4.5.1)
 purrr            1.0.4    2025-02-05 [1] CRAN (R 4.5.1)
 R6               2.5.1    2021-08-19 [2] CRAN (R 4.2.0)
 Rcpp             1.0.14   2025-01-12 [1] CRAN (R 4.5.1)
 remotes          2.4.2    2021-11-30 [2] CRAN (R 4.2.0)
 rethinking       2.42     2025-09-24 [1] Github (rmcelreath/rethinking@ac1b3b2)
 rlang            1.1.6    2025-04-11 [1] CRAN (R 4.5.1)
 rmarkdown        2.29     2024-11-04 [1] CRAN (R 4.5.1)
 rstudioapi       0.17.1   2024-10-22 [1] CRAN (R 4.5.1)
 sessioninfo      1.2.2    2021-12-06 [2] CRAN (R 4.2.0)
 shape            1.4.6.1  2024-02-23 [1] CRAN (R 4.5.1)
 shiny            1.10.0   2024-12-14 [1] CRAN (R 4.5.1)
 tensorA          0.36.2.1 2023-12-13 [1] CRAN (R 4.5.1)
 tibble           3.3.0    2025-06-08 [1] CRAN (R 4.5.1)
 urlchecker       1.0.1    2021-11-30 [1] CRAN (R 4.5.1)
 usethis          3.1.0    2024-11-26 [1] CRAN (R 4.5.1)
 utf8             1.2.2    2021-07-24 [2] CRAN (R 4.2.0)
 V8               6.0.4    2025-06-04 [1] CRAN (R 4.5.1)
 vctrs            0.6.5    2023-12-01 [1] CRAN (R 4.5.1)
 withr            3.0.2    2024-10-28 [1] CRAN (R 4.5.1)
 xfun             0.52     2025-04-02 [1] CRAN (R 4.5.1)
 xtable           1.8-4    2019-04-21 [1] CRAN (R 4.5.1)
 yaml             2.3.5    2022-02-21 [2] CRAN (R 4.2.0)

 [1] /home/jan/R/x86_64-pc-linux-gnu-library/4.5
 [2] /usr/local/lib/R/site-library
 [3] /usr/lib/R/site-library
 [4] /usr/lib/R/library

──────────────────────────────────────────────────────────────────────────────</code></pre>
</div>
</div>


</section>

 ]]></description>
  <category>R</category>
  <category>Stan</category>
  <category>Bayesian statistics</category>
  <category>measurement error</category>
  <category>correlational studies</category>
  <category>reliability</category>
  <guid>https://janhove.github.io/posts/2020-02-18-measurement-error/</guid>
  <pubDate>Tue, 18 Feb 2020 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Baby steps in Bayes: Accounting for measurement error on a control variable</title>
  <dc:creator>Jan Vanhove</dc:creator>
  <link>https://janhove.github.io/posts/2020-01-21-statistical-control-measurement-error/</link>
  <description><![CDATA[ 




<p>In observational studies, it is customary to account for confounding variables by including measurements of them in the statistical model. This practice is referred to as <em>statistically controlling</em> for the confounding variables. An underappreciated problem is that if the confounding variables were measured imperfectly, then statistical control will be imperfect as well, and the confound won’t be eradicated entirely (see Berthele &amp; Vanhove 2017; Brunner &amp; Austin 2009; Westfall &amp; Yarkoni 2016) (see also <a href="../2015-08-24-caveats-confounds-correlational-designs"><em>Controlling for confounding variables in correlational research: Four caveats</em></a>).</p>
<p>This blog post details my efforts to specify a Bayesian model in which the measurement error on the confounding variable was taken into account. The ultimate aim was to obtain more honest estimates of the impact of the confounding variable and the variable of actual interest on the outcome. First, I’ll discuss a simulated example to demonstrate the consequences of measurement error on statistical control and what a model needs to do to appropriately take measurement error into account. Then I apply the insights gained on a real-life study in applied linguistics.</p>
<p>I will preface all of this with the disclaimer that I don’t consider myself an expert in the techniques discussed below; one reason for writing this blog is to solicit feedback from readers more knowledgeable than I am.</p>
<section id="preliminaries" class="level2">
<h2 class="anchored" data-anchor-id="preliminaries">Preliminaries</h2>
<p><strong>Update (2023-08-06):</strong> When converting this blog from Jekyll/Bootstrap to Quarto, I noticed that the original code used in this blog post, which involved the R package <code>rstan</code> has started to run very slowly. In the present version, I use <code>cmdstanr</code> instead.</p>
<p>If you want to follow along, you need the following R packages/settings:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(cmdstanr)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for fitting Bayesian models, v. 2.32.2</span></span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(posterior) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for working with posterior distributions</span></span>
<span id="cb1-5"></span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># For drawing scatterplot matrices</span></span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">source</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://janhove.github.io/RCode/scatterplot_matrix.R"</span>)</span>
<span id="cb1-8"></span>
<span id="cb1-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Set random seed for reproducibility</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;">2020-01-21</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">kind =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mersenne-Twister"</span>)</span></code></pre></div></div>
</div>
<p>You’ll also need the <code>MASS</code> package, but you don’t need to load it.</p>
</section>
<section id="demonstration-measurement-error-messes-up-statistical-control" class="level2">
<h2 class="anchored" data-anchor-id="demonstration-measurement-error-messes-up-statistical-control">Demonstration: Measurement error messes up statistical control</h2>
<p>Let’s first illustrate the problem that measurement error causes for statistical control using simulated data. That way, we know what goes into the data and what we hope a model should take out of it.</p>
<p>The scenario I want to focus on is the following. You are pretty sure that a given construct <code>A</code> causally affects a variable <code>Z</code>. You are, however, interested in finding out if another construct <code>B</code> also affects <code>Z</code>. You can’t manipulate any of the variables, so you have to make do with an observational study. Unfortunately, <code>A</code> and <code>B</code> are likely to be correlated. Let’s simulate some data to make this more concrete:</p>
<ul>
<li>500 datapoints (<code>n</code>)</li>
<li>Constructs <code>A</code> and <code>B</code> are correlated at <img src="https://latex.codecogs.com/png.latex?%5Crho%20=%200.73">.</li>
<li>Constructs <code>A</code> and <code>B</code> are normally distributed with standard deviations of 1.5 (<code>sd_A</code>) and 0.8 (<code>sd_B</code>), respectively. The means of these normal distributions are 3 and -4, respectively.</li>
</ul>
<p>The numbers in the list above aren’t special; I just wanted to make sure the model I will specify further down below isn’t restricted to assuming that the constructs are distributed normally with mean 0 and standard deviation 1.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate correlated constructs</span></span>
<span id="cb2-2">n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span></span>
<span id="cb2-3">rho <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.73</span></span>
<span id="cb2-4">sd_A <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span></span>
<span id="cb2-5">sd_B <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span></span>
<span id="cb2-6"></span>
<span id="cb2-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Given the correlation and the standard deviations,</span></span>
<span id="cb2-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># construct the covariance matrix for the constructs like so:</span></span>
<span id="cb2-9">latent_covariance_matrix <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(sd_A, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, sd_B)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%*%</span> </span>
<span id="cb2-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, rho), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(rho, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%*%</span> </span>
<span id="cb2-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(sd_A, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, sd_B))</span>
<span id="cb2-12"></span>
<span id="cb2-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Draw data from the multivariate normal distribution:</span></span>
<span id="cb2-14">constructs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> MASS<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mvrnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb2-15">                            , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Sigma =</span> latent_covariance_matrix)</span>
<span id="cb2-16">A <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> constructs[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb2-17">B <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> constructs[, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]</span></code></pre></div></div>
</div>
<p>For the purposes of this simulation, I’ll generate data for <code>Z</code> that are affected by <code>A</code> but not by <code>B</code>:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># A influences Z, B doesn't</span></span>
<span id="cb3-2">Z <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>A <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>)</span></code></pre></div></div>
</div>
<p>As <strong>Figure 1</strong> shows, <code>B</code> and <code>Z</code> are correlated, even though neither influences the other. This is because of their link with <code>A</code>.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scatterplot_matrix</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(Z, A, B))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-01-21-statistical-control-measurement-error/index_files/figure-html/unnamed-chunk-5-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 1.</strong> Even though variable <code>Z</code> isn’t causally affected by construct <code>B</code>, there exists a considerable correlation between <code>B</code> and <code>Z</code>. This correlation exists because <code>Z</code> is causally affected by construct <code>A</code>, which is correlated with <code>B</code>.</figcaption>
</figure>
</div>
</div>
</div>
<p>In situations such as these, researchers typically include both <code>A</code> and <code>B</code> as predictors in a model with <code>Z</code> as the outcome. And this works: we find a significant relationship between <code>A</code> and <code>Z</code>, but not between <code>B</code> and <code>Z</code>. Moreover, all estimated parameters are in the vicinity of their true values, as specified in the simulation.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> A <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> B))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)    2.881     0.5439    5.30 1.78e-07
A              0.609     0.0546   11.14 6.93e-26
B              0.146     0.1025    1.43 1.54e-01</code></pre>
</div>
</div>
<p>But in real life, the situation is more complicated. When researchers “statistically control” for a possible confound, they’re usually interested in controlling for the confounding <em>construct</em> rather than for any one <em>measurement</em> of this construct. For instance, when teasing apart the influences of L2 vocabulary knowledge and L2 morphosyntactic knowledge on L2 speaking fluency, researchers don’t actually want to control for the learners performance on this or that vocabulary test: they want to control for L2 vocabulary knowledge itself. One would hope that the vocabulary test gives a good indication of the learners’ vocabulary knowledge, but it’s understood that their performance will be affected by other factors as well (e.g., form on the day, luck with guessing, luck with the words occurring in the test etc.).</p>
<p>So let’s add some noise (measurement error) to constructs <code>A</code> and <code>B</code>. Here I express the measurement error in terms of the reliability of the instruments used to measure the constructs: If <img src="https://latex.codecogs.com/png.latex?%5Csigma_A"> is the standard deviation of the unobserved construct scores and <img src="https://latex.codecogs.com/png.latex?r_%7BAA'%7D"> is the reliability of the measurement instrument, then the standard deviation of the measurement error is <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B%5Cfrac%7B%5Csigma_A%5E2%7D%7Br_%7BAA'%7D%7D%20-%20%5Csigma_A%5E2%7D">. For the purposes of this demonstration, I’m going to specify that construct <code>A</code> was measured with ‘okay’ reliability (0.70), whereas construct <code>B</code> was measured with exceptional reliability (0.95):</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">obs_A <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> A <span 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="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(sd_A<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.70</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> sd_A<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb7-2">obs_B <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</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;">rnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(sd_B<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> sd_B<span 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></code></pre></div></div>
</div>
<p>Crucially, if we include the observed values <code>obs_A</code> and <code>obs_B</code> as predictors in a model with <code>Z</code> as the outcome, we find that the parameter for <code>obs_B</code> is significant—even though there is no causal link between <code>B</code> and <code>Z</code>:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> obs_A <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> obs_B))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)    4.842     0.4557   10.63 6.68e-24
obs_A          0.364     0.0418    8.71 4.36e-17
obs_B          0.456     0.0911    5.01 7.66e-07</code></pre>
</div>
</div>
<p>Descriptively, this is perfectly fine: You do indeed now know more about <code>Z</code> if you take into account <code>obs_B</code> in addition to <code>obs_A</code>. But you take this to interpret that the <em>construct</em> of <code>B</code> can explain variation in <code>Z</code> over and beyond that which can be explained by the construct of <code>A</code>, this would be a mistake.</p>
<p>Conceptually, what has happened is that since <code>obs_A</code> imperfectly reflects construct <code>A</code>, including <code>obs_A</code> in the model control for construct <code>A</code> imperfectly.</p>
</section>
<section id="fitting-a-model-that-takes-measurement-into-account" class="level2">
<h2 class="anchored" data-anchor-id="fitting-a-model-that-takes-measurement-into-account">Fitting a model that takes measurement into account</h2>
<p>Below is the Stan code I used for fitting the simulated data. The model takes as its input the three observed variables (<code>obs_A</code>, <code>obs_B</code> and <code>Z</code>). Information about the reliability of <code>obs_A</code> and <code>obs_B</code> is also provided in the form of a prior distribution on <code>reliability_A</code> and <code>reliability_B</code>. Specifically, it’s assumed that the reliability coefficient for <code>obs_A</code> is drawn from a <code>beta(30, 10)</code>-distribution. This assigns a 95% probability to the reliability coefficient lying between roughly 0.61 and 0.87. <code>obs_B</code> is assumed to be measured more reliably, as encoded by a <code>beta(95, 5)</code>-distribution, which assigns a 95% probability to the reliability coefficient lying between 0.90 and 0.98.</p>
<p>Importantly, as I <a href="https://homeweb.unifr.ch/VanhoveJ/Pub/statistical_control.html">noted</a> in some earlier explorations, the model has to take into account the possibility that the constructs of <code>A</code> and <code>B</code> are correlated. I specified a prior vaguely expecting a positive correlation but that wouldn’t find correlations close to or below zero to be too surprising either. Priors on the other parameters are pretty vague; I find it difficult to come up with reasonable priors in context-free examples.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">meas_error_code <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span></span>
<span id="cb10-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">data { </span></span>
<span id="cb10-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Number of observations</span></span>
<span id="cb10-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int&lt;lower = 1&gt; N;      </span></span>
<span id="cb10-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Observed outcome</span></span>
<span id="cb10-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] Z;         </span></span>
<span id="cb10-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Observed predictors</span></span>
<span id="cb10-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] obs_A;</span></span>
<span id="cb10-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] obs_B;</span></span>
<span id="cb10-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb10-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">parameters {</span></span>
<span id="cb10-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Parameters for regression</span></span>
<span id="cb10-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real intercept;  </span></span>
<span id="cb10-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real slope_A;</span></span>
<span id="cb10-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real slope_B;</span></span>
<span id="cb10-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma; </span></span>
<span id="cb10-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // standard deviations of latent variables (= constructs)</span></span>
<span id="cb10-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma_lat_A; </span></span>
<span id="cb10-20"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma_lat_B;</span></span>
<span id="cb10-21"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-22"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Unknown but estimated reliabilities</span></span>
<span id="cb10-23"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0, upper = 1&gt; reliability_A;</span></span>
<span id="cb10-24"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0, upper = 1&gt; reliability_B;</span></span>
<span id="cb10-25"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-26"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Means of latent predictors</span></span>
<span id="cb10-27"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  row_vector[2] latent_means;</span></span>
<span id="cb10-28"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-29"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Unknown correlation between latent predictors</span></span>
<span id="cb10-30"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = -1, upper = 1&gt; latent_rho;</span></span>
<span id="cb10-31"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-32"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Latent variables</span></span>
<span id="cb10-33"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  matrix[N, 2] latent_variables;</span></span>
<span id="cb10-34"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">} </span></span>
<span id="cb10-35"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">transformed parameters {</span></span>
<span id="cb10-36"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] mu_Z;  // conditional mean of outcome</span></span>
<span id="cb10-37"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] lat_A; // latent variables, separated out</span></span>
<span id="cb10-38"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] lat_B;</span></span>
<span id="cb10-39"></span>
<span id="cb10-40"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real error_A; // standard error of measurement</span></span>
<span id="cb10-41"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real error_B;</span></span>
<span id="cb10-42"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb10-43"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // standard deviations of latent variables, in matrix form</span></span>
<span id="cb10-44"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  matrix[2, 2] sigma_lat; </span></span>
<span id="cb10-45"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // correlation and covariance matrix for latent variables </span></span>
<span id="cb10-46"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cov_matrix[2] latent_cor; </span></span>
<span id="cb10-47"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cov_matrix[2] latent_cov;</span></span>
<span id="cb10-48"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-49"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Standardised slopes for A and B</span></span>
<span id="cb10-50"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real slope_A_std;</span></span>
<span id="cb10-51"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real slope_B_std;</span></span>
<span id="cb10-52"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-53"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Express measurement error in terms of </span></span>
<span id="cb10-54"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // standard deviation of constructs and reliability</span></span>
<span id="cb10-55"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  error_A = sqrt(sigma_lat_A^2/reliability_A - sigma_lat_A^2);</span></span>
<span id="cb10-56"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  error_B = sqrt(sigma_lat_B^2/reliability_B - sigma_lat_B^2);</span></span>
<span id="cb10-57"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-58"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Define diagonal matrix with standard errors of latent variables</span></span>
<span id="cb10-59"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[1, 1] = sigma_lat_A;</span></span>
<span id="cb10-60"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[2, 2] = sigma_lat_B;</span></span>
<span id="cb10-61"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[1, 2] = 0;</span></span>
<span id="cb10-62"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[2, 1] = 0;</span></span>
<span id="cb10-63"></span>
<span id="cb10-64"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Define correlation matrix for latent variables</span></span>
<span id="cb10-65"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[1, 1] = 1;</span></span>
<span id="cb10-66"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[2, 2] = 1;</span></span>
<span id="cb10-67"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[1, 2] = latent_rho;</span></span>
<span id="cb10-68"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[2, 1] = latent_rho;</span></span>
<span id="cb10-69"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-70"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Compute covariance matrix for latent variables</span></span>
<span id="cb10-71"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cov = sigma_lat * latent_cor * sigma_lat;</span></span>
<span id="cb10-72"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-73"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Extract latent variables from matrix</span></span>
<span id="cb10-74"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  lat_A = latent_variables[, 1];</span></span>
<span id="cb10-75"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  lat_B = latent_variables[, 2];</span></span>
<span id="cb10-76"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-77"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Regression model</span></span>
<span id="cb10-78"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  mu_Z = intercept + slope_A*lat_A + slope_B*lat_B;</span></span>
<span id="cb10-79"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-80"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Standardised regression parameters</span></span>
<span id="cb10-81"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  slope_A_std = slope_A * sigma_lat_A;</span></span>
<span id="cb10-82"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  slope_B_std = slope_B * sigma_lat_B;</span></span>
<span id="cb10-83"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb10-84"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">model {</span></span>
<span id="cb10-85"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Priors for regression parameters</span></span>
<span id="cb10-86"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  intercept ~ normal(0, 2);</span></span>
<span id="cb10-87"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  slope_A ~ normal(0, 2);</span></span>
<span id="cb10-88"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  slope_B ~ normal(0, 2);</span></span>
<span id="cb10-89"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma ~ normal(0, 2);</span></span>
<span id="cb10-90"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-91"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior for reliabilities</span></span>
<span id="cb10-92"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  reliability_A ~ beta(30, 10); // assume this has been estimated using some metric to be </span></span>
<span id="cb10-93"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                                // roughly 0.78, but with considerable uncertainty</span></span>
<span id="cb10-94"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  reliability_B ~ beta(95, 5); // assume this has been estimated using exceptional reliability</span></span>
<span id="cb10-95"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-96"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior for latent means</span></span>
<span id="cb10-97"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_means ~ normal(0, 3);</span></span>
<span id="cb10-98"></span>
<span id="cb10-99"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior for latent standard deviations</span></span>
<span id="cb10-100"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat_A ~ normal(0, 2);</span></span>
<span id="cb10-101"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat_B ~ normal(0, 2);</span></span>
<span id="cb10-102"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-103"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior expectation for correlation between latent variables:</span></span>
<span id="cb10-104"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // tend towards positive rho</span></span>
<span id="cb10-105"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_rho ~ normal(0.4, 0.3);</span></span>
<span id="cb10-106"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-107"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Distribution of latent variable</span></span>
<span id="cb10-108"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  for (i in 1:N) {</span></span>
<span id="cb10-109"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    latent_variables[i, ] ~ multi_normal(latent_means, latent_cov);</span></span>
<span id="cb10-110"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb10-111"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-112"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Measurement model</span></span>
<span id="cb10-113"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  obs_A ~ normal(lat_A, error_A);</span></span>
<span id="cb10-114"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  obs_B ~ normal(lat_B, error_B);</span></span>
<span id="cb10-115"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb10-116"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Generate outcome</span></span>
<span id="cb10-117"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  Z ~ normal(mu_Z, sigma);</span></span>
<span id="cb10-118"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb10-119"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span></span></code></pre></div></div>
</div>
<p>Let’s put the data into a Stan-friendly list and fit the model:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">data_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb11-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Z =</span> Z,</span>
<span id="cb11-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">obs_A =</span> obs_A,</span>
<span id="cb11-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">obs_B =</span> obs_B,</span>
<span id="cb11-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">N =</span> n</span>
<span id="cb11-6">)</span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">meas_error_model <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cmdstan_model</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_stan_file</span>(meas_error_code))</span>
<span id="cb12-2">model_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> meas_error_model<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(</span>
<span id="cb12-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> data_list</span>
<span id="cb12-4">  , <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="cb12-5">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">chains =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb12-6">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parallel_chains =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb12-7">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter_warmup =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2000</span></span>
<span id="cb12-8">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter_sampling =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2000</span></span>
<span id="cb12-9">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span></span>
<span id="cb12-10">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_treedepth =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span></span>
<span id="cb12-11">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">adapt_delta =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span></span>
<span id="cb12-12">)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Running MCMC with 4 parallel chains...

Chain 1 Iteration:    1 / 4000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 2 Iteration:    1 / 4000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 3 Iteration:    1 / 4000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 4 Iteration:    1 / 4000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 3 Iteration:  500 / 4000 [ 12%]  (Warmup) 
Chain 4 Iteration:  500 / 4000 [ 12%]  (Warmup) 
Chain 2 Iteration:  500 / 4000 [ 12%]  (Warmup) 
Chain 1 Iteration:  500 / 4000 [ 12%]  (Warmup) 
Chain 4 Iteration: 1000 / 4000 [ 25%]  (Warmup) 
Chain 3 Iteration: 1000 / 4000 [ 25%]  (Warmup) 
Chain 2 Iteration: 1000 / 4000 [ 25%]  (Warmup) 
Chain 1 Iteration: 1000 / 4000 [ 25%]  (Warmup) 
Chain 4 Iteration: 1500 / 4000 [ 37%]  (Warmup) 
Chain 2 Iteration: 1500 / 4000 [ 37%]  (Warmup) 
Chain 3 Iteration: 1500 / 4000 [ 37%]  (Warmup) 
Chain 4 Iteration: 2000 / 4000 [ 50%]  (Warmup) 
Chain 4 Iteration: 2001 / 4000 [ 50%]  (Sampling) 
Chain 2 Iteration: 2000 / 4000 [ 50%]  (Warmup) 
Chain 2 Iteration: 2001 / 4000 [ 50%]  (Sampling) 
Chain 1 Iteration: 1500 / 4000 [ 37%]  (Warmup) 
Chain 3 Iteration: 2000 / 4000 [ 50%]  (Warmup) 
Chain 3 Iteration: 2001 / 4000 [ 50%]  (Sampling) 
Chain 4 Iteration: 2500 / 4000 [ 62%]  (Sampling) 
Chain 1 Iteration: 2000 / 4000 [ 50%]  (Warmup) 
Chain 1 Iteration: 2001 / 4000 [ 50%]  (Sampling) 
Chain 2 Iteration: 2500 / 4000 [ 62%]  (Sampling) 
Chain 3 Iteration: 2500 / 4000 [ 62%]  (Sampling) 
Chain 4 Iteration: 3000 / 4000 [ 75%]  (Sampling) 
Chain 2 Iteration: 3000 / 4000 [ 75%]  (Sampling) 
Chain 1 Iteration: 2500 / 4000 [ 62%]  (Sampling) 
Chain 3 Iteration: 3000 / 4000 [ 75%]  (Sampling) 
Chain 4 Iteration: 3500 / 4000 [ 87%]  (Sampling) 
Chain 2 Iteration: 3500 / 4000 [ 87%]  (Sampling) 
Chain 1 Iteration: 3000 / 4000 [ 75%]  (Sampling) 
Chain 3 Iteration: 3500 / 4000 [ 87%]  (Sampling) 
Chain 2 Iteration: 4000 / 4000 [100%]  (Sampling) 
Chain 2 finished in 466.7 seconds.
Chain 4 Iteration: 4000 / 4000 [100%]  (Sampling) 
Chain 4 finished in 467.0 seconds.
Chain 1 Iteration: 3500 / 4000 [ 87%]  (Sampling) 
Chain 3 Iteration: 4000 / 4000 [100%]  (Sampling) 
Chain 3 finished in 513.9 seconds.
Chain 1 Iteration: 4000 / 4000 [100%]  (Sampling) 
Chain 1 finished in 556.4 seconds.

All 4 chains finished successfully.
Mean chain execution time: 501.0 seconds.
Total execution time: 556.5 seconds.</code></pre>
</div>
</div>
<p>I’ve turn off warning notifications for this blog post, but I did receive this one:</p>
<blockquote class="blockquote">
<p>Warning: 4 of 4 chains had an E-BFMI less than 0.2. See https://mc-stan.org/misc/warnings for details.</p>
</blockquote>
<p>The mc-stan website does indeed contain some advice, but I’m going to ignore this warning for the time being and get on with the blog post.</p>
<p>That said, all estimated parameters are pretty much on the money. Importantly, include the estimated slope for the <code>B</code> construct (<code>slope_B</code>: -0.09, with a 95% credible interval of [-0.66, 0.33]). Notice, too, that the model was able to figure out the correlation between the latent constructs <code>A</code> and <code>B</code> (<code>latent_rho</code>).</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1">model_fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(</span>
<span id="cb18-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"intercept"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope_A"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope_B"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma"</span></span>
<span id="cb18-3">                ,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma_lat_A"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma_lat_B"</span></span>
<span id="cb18-4">                , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"latent_means"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"latent_rho"</span></span>
<span id="cb18-5">                , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope_A_std"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope_B_std"</span></span>
<span id="cb18-6">                , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reliability_A"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reliability_B"</span>)</span>
<span id="cb18-7">  , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sd"</span></span>
<span id="cb18-8">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">extra_quantiles =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>posterior<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile2</span>(., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</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.025</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>))</span>
<span id="cb18-9">  , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rhat"</span></span>
<span id="cb18-10">)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 13 × 6
   variable           mean     sd   q2.5  q97.5  rhat
   &lt;chr&gt;             &lt;dbl&gt;  &lt;dbl&gt;  &lt;dbl&gt;  &lt;dbl&gt; &lt;dbl&gt;
 1 intercept        1.51   1.46   -1.72   3.91   1.01
 2 slope_A          0.753  0.166   0.483  1.12   1.01
 3 slope_B         -0.0946 0.248  -0.639  0.317  1.01
 4 sigma            1.22   0.0674  1.08   1.34   1.01
 5 sigma_lat_A      1.56   0.0840  1.40   1.73   1.01
 6 sigma_lat_B      0.828  0.0282  0.774  0.885  1.00
 7 latent_means[1]  2.90   0.0837  2.74   3.07   1.00
 8 latent_means[2] -4.01   0.0383 -4.08  -3.93   1.00
 9 latent_rho       0.770  0.0441  0.681  0.851  1.01
10 slope_A_std      1.17   0.223   0.794  1.66   1.01
11 slope_B_std     -0.0787 0.206  -0.536  0.264  1.01
12 reliability_A    0.713  0.0603  0.600  0.835  1.02
13 reliability_B    0.951  0.0229  0.899  0.985  1.04</code></pre>
</div>
</div>
<p>To get some sense of what the model is doing, I’m going to extract the posterior distributions for the latent construct scores. These are the model’s guesses of which scores the simulated participants would have had if there had been no measurement error. These guesses are based on the information we’ve fed the model, including the observed variables, the relationships among them, and their probable reliability. I’m just going to work with the means of these posterior distributions, but there can be substantial uncertainty about the model’s guesses.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1">est_lat_A <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> model_fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draws</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lat_A"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"draws_matrix"</span>)</span>
<span id="cb20-2">est_lat_B <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> model_fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draws</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lat_B"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"draws_matrix"</span>)</span>
<span id="cb20-3"></span>
<span id="cb20-4"></span>
<span id="cb20-5">df_variables <span class="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="cb20-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Z =</span> Z,</span>
<span id="cb20-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">obs_A =</span> obs_A,</span>
<span id="cb20-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">obs_B =</span> obs_B,</span>
<span id="cb20-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est_A =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(est_lat_A, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, mean),</span>
<span id="cb20-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est_B =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(est_lat_B, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, mean)</span>
<span id="cb20-11">)</span></code></pre></div></div>
</div>
<p><strong>Figure 2</strong> shows the relationships among the three variables and shows <em>shrinkage</em> at work. For the variables about whose actual values there is uncertainty (viz., A and B), the model reckons that extreme values are caused by a combination of skill (or lack thereof) as well as good (or bad) luck. Accordingly, it adjusts these values towards the bulk of the data. In doing so, it takes into account both the correlation that we ‘expected’ between A and B as well as the possible relationship between A and B on the one hand and Z on the other. For A, the adjustments are fairly large because this variable was assumed to be measured with considerable error. For B, the adjustments are smaller. Z, finally, was assumed to be measured without error and so no adjustments are required.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">par</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mfrow =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb21-2"></span>
<span id="cb21-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Z vs. A</span></span>
<span id="cb21-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> obs_A, df_variables, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb21-5">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z"</span>)</span>
<span id="cb21-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">points</span>(Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> est_A, df_variables, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)</span>
<span id="cb21-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrows</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x0 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>obs_A, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x1 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>est_A,</span>
<span id="cb21-8">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Z,</span>
<span id="cb21-9">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey80"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb21-10"></span>
<span id="cb21-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Z vs. B</span></span>
<span id="cb21-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> obs_B, df_variables, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb21-13">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"B"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z"</span>)</span>
<span id="cb21-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">points</span>(Z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> est_B, df_variables, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)</span>
<span id="cb21-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrows</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x0 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>obs_B, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x1 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>est_B,</span>
<span id="cb21-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Z,</span>
<span id="cb21-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey80"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb21-18"></span>
<span id="cb21-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># B vs. A</span></span>
<span id="cb21-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(obs_B <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> obs_A, df_variables, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb21-21">     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"B"</span>)</span>
<span id="cb21-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">points</span>(est_B <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> est_A, df_variables, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)</span>
<span id="cb21-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrows</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x0 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>obs_A, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x1 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>est_A,</span>
<span id="cb21-24">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>obs_B, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y1 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>est_B,</span>
<span id="cb21-25">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey80"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb21-26"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">par</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mfrow =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-01-21-statistical-control-measurement-error/index_files/figure-html/unnamed-chunk-14-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 2.</strong> The relationships among the three variables. The empty circles represent the variables as they were observed. The black circles represent, for each observation, the mean of the model’s guesses as to what the value would have been if there hadn’t been any measurement error.</figcaption>
</figure>
</div>
</div>
</div>
<p>In statistics at least, shrinkage is generally a good thing: The shrunken values (i.e., the model’s guesses) lie, on average, closer to the true but unobserved values than the observed values do. This is clearly the case for variable A:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(A <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> obs_A))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.724</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(A <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>est_A))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.514</code></pre>
</div>
</div>
<p>For variable B, the difference is negligible seeing as this variable was measured with exceptional reliability:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(B <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> obs_B))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.149</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abs</span>(B <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>est_B))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 0.146</code></pre>
</div>
</div>
</section>
<section id="a-real-life-example-linguistic-interdependence" class="level2">
<h2 class="anchored" data-anchor-id="a-real-life-example-linguistic-interdependence">A real-life example: Linguistic interdependence</h2>
<p>For the simulated data, the model seemed to work okay, so let’s turn to a real-life example. I’ll skip the theoretical background, but several studies in applied linguistics have tried to find out if knowledge in a ‘heritage language’ contributes to the development of the societal language (For more information about such research, see Berthele &amp; Lambelet (2017), Vanhove &amp; Berthele (2017) and Berthele &amp; Vanhove (2017)). In a typical research design, researchers collect data on a group of pupils’ language skills in their heritage language as well as in their societal languages at the beginning of the school year. Then, at the end of the school year, they collect similar data. Unsurprisingly, pupils with relatively good societal language skills at the beginning of the year are still relatively good at the end. But what is sometimes also observed is that heritage language proficiency at the first data collection is a predictor of societal language proficiency at the second data collection, even after taking into account societal language proficiency at the first data collection.</p>
<p>It’s tempting but premature to interpret such findings as evidence for a beneficial effect of heritage language skills on the development of societal language proficiency. The reason is that (a) societal and heritage language proficiency are bound to be correlated at the first data collection due to factors such as intelligence, testwiseness, form on the day etc., and (b) language proficiency is invariably measured with error. This is true of heritage language proficiency, but most importantly, it’s true of the variable that is “statistically controlled for”, i.e., societal language proficiency. Consequently, it’s likely that an off-the-shelf statistical model undercorrects for the role of societal language proficiency and overestimates the role of heritage language profiency.</p>
<p>So let’s fit a model that takes measurement error into account.</p>
<section id="data-and-question" class="level3">
<h3 class="anchored" data-anchor-id="data-and-question">Data and question</h3>
<p>The data we’re going to analyse are a subset of those analysed by Vanhove &amp; Berthele (2017) and Berthele &amp; Vanhove (2017). We have data on 91 pupils with French as their societal language and Portuguese as their heritage language. The study consisted of three data collections (and many more pupils), but we’re just going to analyse the reading proficiency data collected during waves 2 and 3 here.</p>
<p>The full datasets are are available as an R package from https://github.com/janhove/helascot, but copy-paste the command below into R to work with the reduced dataset we’ll work with here.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1">skills <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">structure</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb30-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Subject =</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_PLF_1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_10"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_12"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_13"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_14"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_15"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_16"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_17"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_19"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_3"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_4"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_7"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_8"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A_PLF_9"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA_PLF_11"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA_PLF_12"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA_PLF_13"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA_PLF_6"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA_PLF_7"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AA_PLF_8"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_10"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_11"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_13"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_14"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_15"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_16"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_17"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_18"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_19"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_20"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_21"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_22"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_24"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_25"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_26"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_4"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_6"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_8"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AD_PLF_9"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AE_PLF_1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AE_PLF_2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AE_PLF_4"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AE_PLF_5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"AE_PLF_6"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C_PLF_1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C_PLF_16"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C_PLF_19"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"C_PLF_30"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_3"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_4"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_6"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_7"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"D_PLF_8"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_12"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_15"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_16"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_17"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_18"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_20"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_24"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_25"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_26"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_27"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_28"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_29"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_3"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_31"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_32"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_33"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_34"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_36"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_4"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_6"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_7"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_8"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y_PNF_9"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_2"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_3"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_4"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_6"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_7"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Z_PLF_8"</span>)</span>
<span id="cb30-3">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FR_T2 =</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.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2631578947</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2631578947</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>)</span>
<span id="cb30-4">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PT_T2 =</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.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2631578947</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0526315789</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>)</span>
<span id="cb30-5">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FR_T3 =</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.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2631578947</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>)</span>
<span id="cb30-6">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PT_T3 =</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.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3684210526</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3157894737</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4736842105</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2105263158</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7368421053</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4210526316</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6315789474</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9473684211</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5789473684</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5263157895</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7894736842</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6842105263</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8421052632</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8947368421</span>)</span>
<span id="cb30-7">  )</span>
<span id="cb30-8">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row.names =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</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 class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">91</span>L)</span>
<span id="cb30-9">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">class =</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;">"tbl_df"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tbl"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data.frame"</span>)</span>
<span id="cb30-10">)</span></code></pre></div></div>
</div>
<p>We’re going to fit the French reading scores at the third data collection (<code>FR_T3</code>) in terms of the French and Portuguese reading scores at the second data collection (<code>FR_T2</code> and <code>PT_T2</code>). <strong>Figure 3</strong> shows the observed variables. Note that all values are bounded between 0 and 1, where 1 was the highest possible result.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scatterplot_matrix</span>(skills <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>(FR_T3, FR_T2, PT_T2))</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-01-21-statistical-control-measurement-error/index_files/figure-html/unnamed-chunk-18-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 3.</strong> The relationships between the French proficiency scores at T3, the French proficiency scores at T2 and the Portuguese profiency scores at T2.</figcaption>
</figure>
</div>
</div>
</div>
<p>Fitting an off-the-shelf regression model, we find that <code>PT_T2</code> is significantly related to <code>FR_T3</code>, even when accounting for <code>FR_T2</code>.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(FR_T3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> FR_T2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> PT_T2, skills))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>coefficients</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>            Estimate Std. Error t value Pr(&gt;|t|)
(Intercept)    0.266     0.0520    5.11 1.84e-06
FR_T2          0.506     0.0990    5.11 1.84e-06
PT_T2          0.196     0.0868    2.26 2.60e-02</code></pre>
</div>
</div>
<p>Lastly, as reported by Pestana et al.&nbsp;(2017), the reliability of the French reading test at T2 was estimated to be 0.73, with a 95% confidence interval of [0.65, 0.78]. For Portuguese at T2, the reliability was estimated to be 0.79, with a 95% confidence interval of [0.72, 0.84]. This is information we can feed to the model. (For French at T3, the estimated reliability coefficient was 0.73, 95% CI: [0.65, 0.79], but for now, we’re not going to model the measurement error on the outcome variable.)</p>
</section>
<section id="model" class="level3">
<h3 class="anchored" data-anchor-id="model">Model</h3>
<p>The model specified below is essentially the same as the model for the simulated example, but with more informed priors.</p>
<p>The reliability estimates for the French T2 and Portuguese T2 variables were incorporated by means of prior distributions.</p>
<ul>
<li>For French T2, I put a <code>beta(73, 27)</code> prior on the reliability coefficient, which assigns a 95% probability of the reliablity coefficient lying between 0.64 and 0.81. This doesn’t exactly correspond to the estimated reliability coefficient’s confidence interval, but I think it’s close enough.</li>
<li>For Portuguese T2, I put a <code>beta(79, 21)</code> prior on the reliability coefficient, which assigns a 95% probability of the reliablity coefficient lying between 0.71 and 0.86.</li>
</ul>
<p>Other prior distributions reflect the fact that the predictor and the outcome data were restricted to the [0, 1] range and some common knowledge. The rationale for them is explained in the comments sprinkled throughout the code.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1">interdependence_code <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span></span>
<span id="cb34-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">data { </span></span>
<span id="cb34-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Number of observations</span></span>
<span id="cb34-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int&lt;lower = 1&gt; N;      </span></span>
<span id="cb34-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Observed outcome</span></span>
<span id="cb34-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] FR_T3;         </span></span>
<span id="cb34-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Observed predictors</span></span>
<span id="cb34-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] FR_T2;</span></span>
<span id="cb34-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] PT_T2;</span></span>
<span id="cb34-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb34-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">parameters {</span></span>
<span id="cb34-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Parameters for regression</span></span>
<span id="cb34-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real intercept;  </span></span>
<span id="cb34-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real slope_FR;</span></span>
<span id="cb34-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real slope_PT;</span></span>
<span id="cb34-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma; </span></span>
<span id="cb34-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // standard deviations of latent variables</span></span>
<span id="cb34-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma_lat_FR_T2; </span></span>
<span id="cb34-20"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0&gt; sigma_lat_PT_T2;</span></span>
<span id="cb34-21"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-22"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Unknown but estimated reliabilities</span></span>
<span id="cb34-23"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0, upper = 1&gt; reliability_FR_T2;</span></span>
<span id="cb34-24"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = 0, upper = 1&gt; reliability_PT_T2;</span></span>
<span id="cb34-25"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-26"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Means of latent predictors</span></span>
<span id="cb34-27"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  row_vector[2] latent_means;</span></span>
<span id="cb34-28"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-29"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Unknown correlation between latent predictors</span></span>
<span id="cb34-30"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real&lt;lower = -1, upper = 1&gt; latent_rho;</span></span>
<span id="cb34-31"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-32"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Latent variables</span></span>
<span id="cb34-33"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  matrix[N, 2] latent_variables;</span></span>
<span id="cb34-34"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">} </span></span>
<span id="cb34-35"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">transformed parameters {</span></span>
<span id="cb34-36"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] mu_FR_T3;  // conditional mean of outcome</span></span>
<span id="cb34-37"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] lat_FR_T2; // latent variables, separated out</span></span>
<span id="cb34-38"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[N] lat_PT_T2;</span></span>
<span id="cb34-39"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real error_FR_T2; // standard error of measurement</span></span>
<span id="cb34-40"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real error_PT_T2;</span></span>
<span id="cb34-41"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  matrix[2, 2] sigma_lat; // standard deviations of latent variables, in matrix form</span></span>
<span id="cb34-42"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cov_matrix[2] latent_cor; // correlation and covariance matrix for latent variables </span></span>
<span id="cb34-43"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cov_matrix[2] latent_cov;</span></span>
<span id="cb34-44"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real slope_FR_std;</span></span>
<span id="cb34-45"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real slope_PT_std;</span></span>
<span id="cb34-46"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-47"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Express measurement error in terms of </span></span>
<span id="cb34-48"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // standard deviation of constructs and reliability</span></span>
<span id="cb34-49"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  error_FR_T2 = sqrt(sigma_lat_FR_T2^2/reliability_FR_T2 - sigma_lat_FR_T2^2);</span></span>
<span id="cb34-50"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  error_PT_T2 = sqrt(sigma_lat_PT_T2^2/reliability_PT_T2 - sigma_lat_PT_T2^2);</span></span>
<span id="cb34-51"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-52"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Define diagonal matrix with standard errors of latent variables</span></span>
<span id="cb34-53"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[1, 1] = sigma_lat_FR_T2;</span></span>
<span id="cb34-54"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[2, 2] = sigma_lat_PT_T2;</span></span>
<span id="cb34-55"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[1, 2] = 0;</span></span>
<span id="cb34-56"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma_lat[2, 1] = 0;</span></span>
<span id="cb34-57"></span>
<span id="cb34-58"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Define correlation matrix for latent variables</span></span>
<span id="cb34-59"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[1, 1] = 1;</span></span>
<span id="cb34-60"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[2, 2] = 1;</span></span>
<span id="cb34-61"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[1, 2] = latent_rho;</span></span>
<span id="cb34-62"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cor[2, 1] = latent_rho;</span></span>
<span id="cb34-63"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-64"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Compute covariance matrix for latent variables</span></span>
<span id="cb34-65"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_cov = sigma_lat * latent_cor * sigma_lat;</span></span>
<span id="cb34-66"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-67"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Extract latent variables from matrix</span></span>
<span id="cb34-68"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  lat_FR_T2 = latent_variables[, 1];</span></span>
<span id="cb34-69"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  lat_PT_T2 = latent_variables[, 2];</span></span>
<span id="cb34-70"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-71"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Regression model</span></span>
<span id="cb34-72"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  mu_FR_T3 = intercept + slope_FR*lat_FR_T2 + slope_PT*lat_PT_T2;</span></span>
<span id="cb34-73"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-74"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Standardised regression parameters</span></span>
<span id="cb34-75"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  slope_FR_std = slope_FR * sigma_lat_FR_T2;</span></span>
<span id="cb34-76"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  slope_PT_std = slope_PT * sigma_lat_PT_T2;</span></span>
<span id="cb34-77"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb34-78"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">model {</span></span>
<span id="cb34-79"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Priors for regression parameters; these essentially</span></span>
<span id="cb34-80"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // reflect the fact that the data lie in the [0, 1] interval.</span></span>
<span id="cb34-81"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // The intercept is for FR_T2 and PT_T2 = 0, so a pupil with</span></span>
<span id="cb34-82"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // poor scores at T2. So probably pretty low.</span></span>
<span id="cb34-83"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  intercept ~ normal(0.20, 0.10);</span></span>
<span id="cb34-84"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // French at T2 is bound to positively predict French at T3,</span></span>
<span id="cb34-85"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // but the slope can at most be 1 (bounded data).</span></span>
<span id="cb34-86"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  slope_FR ~ normal(0.50, 0.25);</span></span>
<span id="cb34-87"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Portuguese at T2 is not necessarily a positive predictor of</span></span>
<span id="cb34-88"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // French at T3, given French at T2. So centre around 0.</span></span>
<span id="cb34-89"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  slope_PT ~ normal(0, 0.25);</span></span>
<span id="cb34-90"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // If neither of the T2 variables predicts T3, uncertainty</span></span>
<span id="cb34-91"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // is highest when the mean T3 score is 0.5. Since these scores</span></span>
<span id="cb34-92"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // are bounded between 0 and 1, the standard deviation could not </span></span>
<span id="cb34-93"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // be much higher than 0.20. But French T2 is bound to be a predictor,</span></span>
<span id="cb34-94"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // so let us choose a slighlty lower value.</span></span>
<span id="cb34-95"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  sigma ~ normal(0.15, 0.08);</span></span>
<span id="cb34-96"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-97"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior reliabilities</span></span>
<span id="cb34-98"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  reliability_FR_T2 ~ beta(73, 27); // alpha = 0.73, 95% CI [0.65, 0.78], </span></span>
<span id="cb34-99"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">                                    // which is roughly beta(73, 27)</span></span>
<span id="cb34-100"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  reliability_PT_T2 ~ beta(79, 21);  // alpha = 0.79, 95% CI [0.72, 0.84]</span></span>
<span id="cb34-101"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-102"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior expectation for latent means, viz., the means</span></span>
<span id="cb34-103"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // for French and Portuguese T2. These are going to be in the 0.4-0.6</span></span>
<span id="cb34-104"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // range.</span></span>
<span id="cb34-105"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_means ~ normal(0.50, 0.10);</span></span>
<span id="cb34-106"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-107"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Prior expectation for correlation between latent variables:</span></span>
<span id="cb34-108"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // tend towards positive rho; pretty vague;</span></span>
<span id="cb34-109"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  latent_rho ~ normal(0.4, 0.3);</span></span>
<span id="cb34-110"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-111"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Distribution of latent variable</span></span>
<span id="cb34-112"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  for (i in 1:N) {</span></span>
<span id="cb34-113"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    latent_variables[i, ] ~ multi_normal(latent_means, latent_cov);</span></span>
<span id="cb34-114"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb34-115"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-116"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Measurement model</span></span>
<span id="cb34-117"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  FR_T2 ~ normal(lat_FR_T2, error_FR_T2);</span></span>
<span id="cb34-118"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  PT_T2 ~ normal(lat_PT_T2, error_PT_T2);</span></span>
<span id="cb34-119"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span></span>
<span id="cb34-120"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  // Generate outcome</span></span>
<span id="cb34-121"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  FR_T3 ~ normal(mu_FR_T3, sigma);</span></span>
<span id="cb34-122"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb34-123"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span></span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1">data_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb35-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FR_T2 =</span> skills<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FR_T2,</span>
<span id="cb35-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PT_T2 =</span> skills<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PT_T2,</span>
<span id="cb35-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FR_T3 =</span> skills<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FR_T3,</span>
<span id="cb35-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">N =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(skills)</span>
<span id="cb35-6">)</span></code></pre></div></div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1">interdependence_model <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cmdstan_model</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_stan_file</span>(interdependence_code))</span>
<span id="cb36-2">interdependence_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> interdependence_model<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(</span>
<span id="cb36-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> data_list</span>
<span id="cb36-4">  , <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;">42</span></span>
<span id="cb36-5">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">chains =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb36-6">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parallel_chains =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb36-7">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter_warmup =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2000</span></span>
<span id="cb36-8">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter_sampling =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6000</span></span>
<span id="cb36-9">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refresh =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span></span>
<span id="cb36-10">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max_treedepth =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span></span>
<span id="cb36-11">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">adapt_delta =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.99</span></span>
<span id="cb36-12">)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Running MCMC with 4 parallel chains...

Chain 1 Iteration:    1 / 8000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 2 Iteration:    1 / 8000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 3 Iteration:    1 / 8000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 4 Iteration:    1 / 8000 [  0%]  (Warmup) </code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>Chain 1 Iteration: 1000 / 8000 [ 12%]  (Warmup) 
Chain 2 Iteration: 1000 / 8000 [ 12%]  (Warmup) 
Chain 3 Iteration: 1000 / 8000 [ 12%]  (Warmup) 
Chain 4 Iteration: 1000 / 8000 [ 12%]  (Warmup) 
Chain 1 Iteration: 2000 / 8000 [ 25%]  (Warmup) 
Chain 1 Iteration: 2001 / 8000 [ 25%]  (Sampling) 
Chain 2 Iteration: 2000 / 8000 [ 25%]  (Warmup) 
Chain 2 Iteration: 2001 / 8000 [ 25%]  (Sampling) 
Chain 3 Iteration: 2000 / 8000 [ 25%]  (Warmup) 
Chain 3 Iteration: 2001 / 8000 [ 25%]  (Sampling) 
Chain 4 Iteration: 2000 / 8000 [ 25%]  (Warmup) 
Chain 4 Iteration: 2001 / 8000 [ 25%]  (Sampling) 
Chain 1 Iteration: 3000 / 8000 [ 37%]  (Sampling) 
Chain 3 Iteration: 3000 / 8000 [ 37%]  (Sampling) 
Chain 2 Iteration: 3000 / 8000 [ 37%]  (Sampling) 
Chain 4 Iteration: 3000 / 8000 [ 37%]  (Sampling) 
Chain 1 Iteration: 4000 / 8000 [ 50%]  (Sampling) 
Chain 3 Iteration: 4000 / 8000 [ 50%]  (Sampling) 
Chain 2 Iteration: 4000 / 8000 [ 50%]  (Sampling) 
Chain 4 Iteration: 4000 / 8000 [ 50%]  (Sampling) 
Chain 3 Iteration: 5000 / 8000 [ 62%]  (Sampling) 
Chain 1 Iteration: 5000 / 8000 [ 62%]  (Sampling) 
Chain 2 Iteration: 5000 / 8000 [ 62%]  (Sampling) 
Chain 4 Iteration: 5000 / 8000 [ 62%]  (Sampling) 
Chain 3 Iteration: 6000 / 8000 [ 75%]  (Sampling) 
Chain 1 Iteration: 6000 / 8000 [ 75%]  (Sampling) 
Chain 2 Iteration: 6000 / 8000 [ 75%]  (Sampling) 
Chain 4 Iteration: 6000 / 8000 [ 75%]  (Sampling) 
Chain 3 Iteration: 7000 / 8000 [ 87%]  (Sampling) 
Chain 1 Iteration: 7000 / 8000 [ 87%]  (Sampling) 
Chain 2 Iteration: 7000 / 8000 [ 87%]  (Sampling) 
Chain 4 Iteration: 7000 / 8000 [ 87%]  (Sampling) 
Chain 3 Iteration: 8000 / 8000 [100%]  (Sampling) 
Chain 3 finished in 128.0 seconds.
Chain 1 Iteration: 8000 / 8000 [100%]  (Sampling) 
Chain 1 finished in 131.4 seconds.
Chain 2 Iteration: 8000 / 8000 [100%]  (Sampling) 
Chain 2 finished in 134.1 seconds.
Chain 4 Iteration: 8000 / 8000 [100%]  (Sampling) 
Chain 4 finished in 135.0 seconds.

All 4 chains finished successfully.
Mean chain execution time: 132.1 seconds.
Total execution time: 135.1 seconds.</code></pre>
</div>
</div>
<p>After tweaking the <code>adapt_delta</code> and <code>max_treedepth</code> parameters and letting the model run for a sufficient number of iterations, it converged without errors or warnings.</p>
</section>
<section id="results" class="level3">
<h3 class="anchored" data-anchor-id="results">Results</h3>
<p>Compared to the off-the-shelf <code>lm()</code> model, the model that takes measurement errors and correlated predictors into account estimates the parameter for <code>FR_T2</code> to be higher and that of <code>PT_T2</code> to be lower. It is also more uncertain about these parameters than the off-the-shelf model, I think appropriately so. The slope for <code>PT_T2</code>, which is the important bit, is now estimated to be 0.10, with a 95% credible interval of [-0.17, 0.38]. So when you take measurement error into account, you find that there is less evidence for a beneficial effect of heritage language proficiency on the development of societal language proficiency that you could otherwise have thought. Moreover, the model estimates that the correlation between <code>FR_T2</code> and <code>PT_T2</code> is in the vicinity of 0.81 rather than 0.67, once measurement error has been accounted for.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb42" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb42-1">interdependence_fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(</span>
<span id="cb42-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">variables =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"intercept"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope_FR"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"slope_PT"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma"</span></span>
<span id="cb42-3">                , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma_lat_FR_T2"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma_lat_PT_T2"</span></span>
<span id="cb42-4">                , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"latent_means"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"latent_rho"</span></span>
<span id="cb42-5">                , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reliability_FR_T2"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reliability_PT_T2"</span>)</span>
<span id="cb42-6">  , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mean"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sd"</span></span>
<span id="cb42-7">  , <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">extra_quantiles =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>posterior<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile2</span>(., <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">probs =</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.025</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>))</span>
<span id="cb42-8">  , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rhat"</span></span>
<span id="cb42-9">)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 11 × 6
   variable           mean     sd    q2.5 q97.5  rhat
   &lt;chr&gt;             &lt;dbl&gt;  &lt;dbl&gt;   &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
 1 intercept         0.191 0.0528  0.0861 0.295  1.00
 2 slope_FR          0.710 0.156   0.408  1.02   1.00
 3 slope_PT          0.106 0.139  -0.171  0.378  1.00
 4 sigma             0.116 0.0114  0.0942 0.139  1.00
 5 sigma_lat_FR_T2   0.155 0.0122  0.133  0.181  1.00
 6 sigma_lat_PT_T2   0.182 0.0142  0.156  0.212  1.00
 7 latent_means[1]   0.653 0.0185  0.616  0.689  1.00
 8 latent_means[2]   0.642 0.0210  0.601  0.683  1.00
 9 latent_rho        0.813 0.0782  0.645  0.952  1.00
10 reliability_FR_T2 0.749 0.0392  0.668  0.823  1.00
11 reliability_PT_T2 0.791 0.0402  0.707  0.864  1.00</code></pre>
</div>
</div>
<p>Considerable shrinkage is observed for both predictors (<strong>Figure 4</strong>); keep in mind that we didn’t account for measurement error on the outcome. The plots in the top row shows how predictor values that are pretty low given a certain outcome value are shifted toward the right and how predictor values that are pretty high given a certain outcome value get shifted toward the left. The plot in the bottom row additionally shows that the model has learnt, among other things, that if a participant has a high <code>PT_T2</code> score but a low <code>FR_T2</code> score, that the former is probably an overestimate and the latter is likely an underestimate. So it adjusts both values towards the centre.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb44" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb44-1">lat_FR_T2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> interdependence_fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draws</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lat_FR_T2"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"draws_matrix"</span>)</span>
<span id="cb44-2">lat_PT_T2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> interdependence_fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">draws</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lat_PT_T2"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"draws_matrix"</span>)</span>
<span id="cb44-3"></span>
<span id="cb44-4">df_variables <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb44-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FR_T3 =</span> skills<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FR_T3,</span>
<span id="cb44-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">FR_T2 =</span> skills<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FR_T2,</span>
<span id="cb44-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">PT_T2 =</span> skills<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PT_T2,</span>
<span id="cb44-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est_FR_T2 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(lat_FR_T2, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, mean),</span>
<span id="cb44-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est_PT_T2 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(lat_PT_T2, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, mean)</span>
<span id="cb44-10">)</span>
<span id="cb44-11"></span>
<span id="cb44-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">par</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mfrow =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb44-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(FR_T3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> FR_T2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_variables, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb44-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">points</span>(FR_T3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> est_FR_T2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_variables, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)</span>
<span id="cb44-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrows</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x0 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FR_T2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x1 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>est_FR_T2,</span>
<span id="cb44-16">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FR_T3, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y1 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FR_T3,</span>
<span id="cb44-17">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey60"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb44-18"></span>
<span id="cb44-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(FR_T3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> PT_T2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_variables, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb44-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">points</span>(FR_T3 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> est_PT_T2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_variables, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)</span>
<span id="cb44-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrows</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x0 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PT_T2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x1 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>est_PT_T2,</span>
<span id="cb44-22">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FR_T3, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y1 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FR_T3,</span>
<span id="cb44-23">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey60"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb44-24"></span>
<span id="cb44-25"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(PT_T2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> FR_T2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_variables, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb44-26"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">points</span>(est_PT_T2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> est_FR_T2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> df_variables, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)</span>
<span id="cb44-27"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrows</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x0 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>FR_T2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x1 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>est_FR_T2,</span>
<span id="cb44-28">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y0 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>PT_T2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y1 =</span> df_variables<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>est_PT_T2,</span>
<span id="cb44-29">       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey60"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span></code></pre></div></div>
<div class="cell-output-display">
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://janhove.github.io/posts/2020-01-21-statistical-control-measurement-error/index_files/figure-html/unnamed-chunk-24-1.svg" class="img-fluid figure-img"></p>
<figcaption><strong>Figure 4.</strong> Relationships among the predictors and the outcome. The empty circles represent the variables as they were observed. The black circles represent, for each observation, the mean of the model’s guesses as to what the value would have been if there hadn’t been any measurement error.</figcaption>
</figure>
</div>
</div>
</div>
</section>
</section>
<section id="caveats" class="level2">
<h2 class="anchored" data-anchor-id="caveats">Caveats</h2>
<ul>
<li>I’m just trying to figure out this stuff, so this blog posts comes with absolutely no warranties.</li>
<li>We only took into account <em>reliability</em> and we took <em>validity</em> for granted. In the real-life example, this means that we acknowledged that the French reading test measured French reading proficiency imperfectly — but we did assume that it, deep down, measured French reading proficiency. You can easily imagine a test that measures something highly reliably, but that still doesn’t reflect what it’s supposed to measure well. (For instance, a highly reliable trivia quiz about the Belgian national football team under the reign of Georges Leekens that’s used to represent general intelligence.) Taking measurement error (in terms of unreliability) into account doesn’t fix possible validity problems.</li>
</ul>
</section>
<section id="software-versions" class="level2">
<h2 class="anchored" data-anchor-id="software-versions">Software versions</h2>
<p>Please note that I reran the code on this page on August 6, 2023.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><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">devtools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">session_info</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.5.1 (2025-06-13)
 os       Ubuntu 22.04.5 LTS
 system   x86_64, linux-gnu
 ui       X11
 language en_US
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Zurich
 date     2025-10-09
 pandoc   2.12 @ /home/jan/miniconda3/bin/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────
 package        * version  date (UTC) lib source
 abind            1.4-8    2024-09-12 [1] CRAN (R 4.5.1)
 backports        1.5.0    2024-05-23 [1] CRAN (R 4.5.1)
 cachem           1.1.0    2024-05-16 [1] CRAN (R 4.5.1)
 callr            3.7.6    2024-03-25 [1] CRAN (R 4.5.1)
 checkmate        2.3.3    2025-08-18 [1] CRAN (R 4.5.1)
 cli              3.6.5    2025-04-23 [1] CRAN (R 4.5.1)
 cmdstanr       * 0.9.0    2025-03-30 [1] https://stan-dev.r-universe.dev (R 4.5.1)
 crayon           1.5.1    2022-03-26 [2] CRAN (R 4.2.0)
 data.table       1.17.6   2025-06-17 [1] CRAN (R 4.5.1)
 devtools         2.4.5    2022-10-11 [1] CRAN (R 4.5.1)
 digest           0.6.37   2024-08-19 [1] CRAN (R 4.5.1)
 distributional   0.5.0    2024-09-17 [1] CRAN (R 4.5.1)
 dplyr          * 1.1.4    2023-11-17 [1] CRAN (R 4.5.1)
 ellipsis         0.3.2    2021-04-29 [2] CRAN (R 4.2.0)
 evaluate         1.0.4    2025-06-18 [1] CRAN (R 4.5.1)
 farver           2.1.2    2024-05-13 [1] CRAN (R 4.5.1)
 fastmap          1.2.0    2024-05-15 [1] CRAN (R 4.5.1)
 forcats        * 1.0.0    2023-01-29 [1] CRAN (R 4.5.1)
 fs               1.5.2    2021-12-08 [2] CRAN (R 4.2.0)
 generics         0.1.4    2025-05-09 [1] CRAN (R 4.5.1)
 ggplot2        * 3.5.2    2025-04-09 [1] CRAN (R 4.5.1)
 glue             1.6.2    2022-02-24 [2] CRAN (R 4.2.0)
 gtable           0.3.6    2024-10-25 [1] CRAN (R 4.5.1)
 hms              1.1.3    2023-03-21 [1] CRAN (R 4.5.1)
 htmltools        0.5.8.1  2024-04-04 [1] CRAN (R 4.5.1)
 htmlwidgets      1.6.4    2023-12-06 [1] CRAN (R 4.5.1)
 httpuv           1.6.16   2025-04-16 [1] CRAN (R 4.5.1)
 jsonlite         2.0.0    2025-03-27 [1] CRAN (R 4.5.1)
 knitr            1.50     2025-03-16 [1] CRAN (R 4.5.1)
 later            1.4.2    2025-04-08 [1] CRAN (R 4.5.1)
 lifecycle        1.0.4    2023-11-07 [1] CRAN (R 4.5.1)
 lubridate      * 1.9.4    2024-12-08 [1] CRAN (R 4.5.1)
 magrittr         2.0.3    2022-03-30 [1] CRAN (R 4.5.1)
 MASS             7.3-65   2025-02-28 [4] CRAN (R 4.4.3)
 matrixStats      1.5.0    2025-01-07 [1] CRAN (R 4.5.1)
 memoise          2.0.1    2021-11-26 [2] CRAN (R 4.2.0)
 mime             0.10     2021-02-13 [2] CRAN (R 4.0.2)
 miniUI           0.1.2    2025-04-17 [1] CRAN (R 4.5.1)
 pillar           1.10.2   2025-04-05 [1] CRAN (R 4.5.1)
 pkgbuild         1.3.1    2021-12-20 [2] CRAN (R 4.2.0)
 pkgconfig        2.0.3    2019-09-22 [2] CRAN (R 4.2.0)
 pkgload          1.4.0    2024-06-28 [1] CRAN (R 4.5.1)
 posterior      * 1.6.1    2025-02-27 [1] CRAN (R 4.5.1)
 prettyunits      1.1.1    2020-01-24 [2] CRAN (R 4.2.0)
 processx         3.8.6    2025-02-21 [1] CRAN (R 4.5.1)
 profvis          0.4.0    2024-09-20 [1] CRAN (R 4.5.1)
 promises         1.3.3    2025-05-29 [1] CRAN (R 4.5.1)
 ps               1.9.1    2025-04-12 [1] CRAN (R 4.5.1)
 purrr          * 1.0.4    2025-02-05 [1] CRAN (R 4.5.1)
 R6               2.5.1    2021-08-19 [2] CRAN (R 4.2.0)
 RColorBrewer     1.1-3    2022-04-03 [1] CRAN (R 4.5.1)
 Rcpp             1.0.14   2025-01-12 [1] CRAN (R 4.5.1)
 readr          * 2.1.5    2024-01-10 [1] CRAN (R 4.5.1)
 remotes          2.4.2    2021-11-30 [2] CRAN (R 4.2.0)
 rlang            1.1.6    2025-04-11 [1] CRAN (R 4.5.1)
 rmarkdown        2.29     2024-11-04 [1] CRAN (R 4.5.1)
 rstudioapi       0.17.1   2024-10-22 [1] CRAN (R 4.5.1)
 scales           1.4.0    2025-04-24 [1] CRAN (R 4.5.1)
 sessioninfo      1.2.2    2021-12-06 [2] CRAN (R 4.2.0)
 shiny            1.10.0   2024-12-14 [1] CRAN (R 4.5.1)
 stringi          1.7.6    2021-11-29 [2] CRAN (R 4.2.0)
 stringr        * 1.5.1    2023-11-14 [1] CRAN (R 4.5.1)
 tensorA          0.36.2.1 2023-12-13 [1] CRAN (R 4.5.1)
 tibble         * 3.3.0    2025-06-08 [1] CRAN (R 4.5.1)
 tidyr          * 1.3.1    2024-01-24 [1] CRAN (R 4.5.1)
 tidyselect       1.2.1    2024-03-11 [1] CRAN (R 4.5.1)
 tidyverse      * 2.0.0    2023-02-22 [1] CRAN (R 4.5.1)
 timechange       0.3.0    2024-01-18 [1] CRAN (R 4.5.1)
 tzdb             0.5.0    2025-03-15 [1] CRAN (R 4.5.1)
 urlchecker       1.0.1    2021-11-30 [1] CRAN (R 4.5.1)
 usethis          3.1.0    2024-11-26 [1] CRAN (R 4.5.1)
 utf8             1.2.2    2021-07-24 [2] CRAN (R 4.2.0)
 vctrs            0.6.5    2023-12-01 [1] CRAN (R 4.5.1)
 withr            3.0.2    2024-10-28 [1] CRAN (R 4.5.1)
 xfun             0.52     2025-04-02 [1] CRAN (R 4.5.1)
 xtable           1.8-4    2019-04-21 [1] CRAN (R 4.5.1)
 yaml             2.3.5    2022-02-21 [2] CRAN (R 4.2.0)

 [1] /home/jan/R/x86_64-pc-linux-gnu-library/4.5
 [2] /usr/local/lib/R/site-library
 [3] /usr/lib/R/site-library
 [4] /usr/lib/R/library

──────────────────────────────────────────────────────────────────────────────</code></pre>
</div>
</div>


</section>

 ]]></description>
  <category>R</category>
  <category>Stan</category>
  <category>Bayesian statistics</category>
  <category>measurement error</category>
  <category>correlational studies</category>
  <guid>https://janhove.github.io/posts/2020-01-21-statistical-control-measurement-error/</guid>
  <pubDate>Tue, 21 Jan 2020 00:00:00 GMT</pubDate>
</item>
</channel>
</rss>
