<?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>posts</title>
<link>https://jepusto.netlify.app/posts/</link>
<atom:link href="https://jepusto.netlify.app/posts/index.xml" rel="self" type="application/rss+xml"/>
<description>Education Statistics and Meta-Analysis</description>
<generator>quarto-1.8.27</generator>
<lastBuildDate>Sun, 08 Mar 2026 00:00:00 GMT</lastBuildDate>
<item>
  <title>p-uniform* is a three-parameter selection model</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/p-uniform-star/</link>
  <description><![CDATA[ 





<p><a href="http://robbievanaert.com/">Robbie van Aert</a> and <a href="https://www.tilburguniversity.edu/staff/m-a-l-m-vanassen">Marcel van Assen</a> have a new article out on a method for estimating average effect size in meta-analyses subject to publication bias, called p-uniform*. The method has been around for a while <span class="citation" data-cites="VanAert2018correcting">(the first version of their paper is from 2018, van Aert &amp; van Assen, 2018)</span> and has been cited hundreds of times. The recent appearance of the peer-reviewed article prompted me to take a closer look.</p>
<p>The authors frame the p-uniform* method as a generalization of an earlier proposal of theirs, called p-uniform, which was limited in that it applies only to meta-analytic data where all effect size estimates are statistically significant at the conventional <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20.05"> level. The new method improves upon p-uniform by using all of the data (including effect size estimates that are not statistically significant) and by allowing for heterogeneity in the distribution of effect size parameters from different samples. The authors contrast p-uniform* with the well-known three-parameter selection model (3PSM), which is a special case of the <a href="../..\posts/step-function-selection-models/">step-function selection model</a> introduced by <span class="citation" data-cites="hedges1992modeling">Hedges (1992)</span>. They note that both methods can be understood as selection models, in that they are based upon explicit assumptions about the process that determines whether an effect size estimate from a study is reported and available for meta-analysis. Further, they argue that the new p-uniform* method is preferable to the 3PSM because it does not involve estimation of a selection weight parameter, and thus is more parsimonious:</p>
<blockquote class="blockquote">
<p>P-uniform* has the advantage over 3PSM that the weight in the selection model does not need to be estimated. These weights are known to be imprecisely estimated in more complex selection models than the selection model of 3PSM where multiple weights need to be estimated (Hedges &amp; Vevea, 1996, 2005; Vevea &amp; Woods, 2005). P-uniform* only assumes that these weights are the same for the statistically significant and the same for the nonsignificant primary studies’ effect sizes, without requiring estimation of the weights. This makes p-uniform* a more parsimonious model than 3PSM with similar statistical properties as shown in our simulation studies <span class="citation" data-cites="vanAert2026correcting">(van Aert &amp; van Assen, 2026, p. 15)</span>.</p>
</blockquote>
<p>In this post, I offer a different interpretation of p-uniform*. Rather than being a more parsimonious model than the 3PSM, I think it is useful to understand p-uniform* as <em>a different estimator</em> of the average effect size and heterogeneity parameters in the 3PSM. I will demonstrate that the maximum likelihood estimator of p-uniform* is <em>exactly</em> equivalent to the maximum likelihood estimator of 3PSM under the (admittedly artificial) condition that all effect sizes in the meta-analytic data have the same sampling variance. Outside of this condition, the methods are not exactly equivalent but will tend to produce very similar point estimates of average effect size and between-study heterogeneity because both are based on unbiased estimating equations. However, confidence intervals produced by each method will differ except when based on the same method of construction and when all effect sizes have the same sampling variance.</p>
<section id="notation" class="level1">
<h1>Notation</h1>
<p>My discussion is necessarily going to get a bit technical. Consider a meta-analysis that includes <img src="https://latex.codecogs.com/png.latex?k"> independent effect size estimates, where <img src="https://latex.codecogs.com/png.latex?t_i"> and <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> denote the observed effect size estimate and corresponding standard error from study <img src="https://latex.codecogs.com/png.latex?i%20=%201,...,k">. Let’s say that statistical significance is defined based on the level <img src="https://latex.codecogs.com/png.latex?2%20%5Ctimes%20%5Calpha"> (which will usually be .05, so <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20.025">). I will assume that the effect sizes are defined so that positive effects are what would be theoretically expected, and I will call an effect size estimate <em>affirmative</em> if it is statistically significant and in the expected direction. Let <img src="https://latex.codecogs.com/png.latex?a_i"> be an indicator for whether effect size estimate <img src="https://latex.codecogs.com/png.latex?i"> is affirmative, so <img src="https://latex.codecogs.com/png.latex?a_i%20=%20I%5Cleft(%5Cfrac%7Bt_i%7D%7B%5Csigma_i%7D%20%3E%20%5CPhi%5E%7B-1%7D(1%20-%20%5Calpha)%5Cright)">, where <img src="https://latex.codecogs.com/png.latex?%5CPhi%5E%7B-1%7D()"> is the standard normal quantile function. I will also use <img src="https://latex.codecogs.com/png.latex?%5CPhi()"> to denote the cumulative function and <img src="https://latex.codecogs.com/png.latex?%5Cphi()"> to denote the density function of the standard normal distribution.</p>
</section>
<section id="the-three-parameter-selection-model" class="level1">
<h1>The three-parameter selection model</h1>
<p>Before considering how p-uniform* relates to the 3PSM, let me explain the latter model. The three-parameter selection model makes two sets of assumptions. First, it is assumed that if we could observe every effect size estimate ever produced, then those effect size estimates would follow a conventional random effects model with mean <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and between-study standard deviation <img src="https://latex.codecogs.com/png.latex?%5Ctau">. Second, it is assumed that the probability of observing a given estimate depends only on its sign and statistical significance. Specifically, the probability of observing a non-affirmative estimate differs from the probability of observing an affirmative estimate by a factor of <img src="https://latex.codecogs.com/png.latex?%5Clambda%20%3E%200">. If <img src="https://latex.codecogs.com/png.latex?%5Clambda%20%3C%201">, then there is selection in favor of affirmative (statistically significant) results, which produces upward bias in average effect size estimates from conventional meta-analytic methods. These assumptions are essentially identical to those of p-uniform*.<sup>1</sup></p>
<p>Under these assumptions, the distribution of an observed effect size estimate is what I call a “piece-wise normal” distribution, with density <span id="eq-observed-effect-density"><img src="https://latex.codecogs.com/png.latex?%0Ad_T(T%20=%20t_i,%20A%20=%20a_i%20%7C%20%5Csigma_i)%20=%20%5Cfrac%7B%20%5Clambda%5E%7B1%20-%20a_i%7D%7D%7B1%20-%20(1%20-%20%5Clambda)%5Cbeta_i%7D%20%5Ctimes%20%5Cfrac%7B1%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%7D%5Cphi%5Cleft(%5Cfrac%7Bt%20-%20%5Cmu%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%7D%5Cright),%0A%5Ctag%7B1%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%5Cbeta_i%20=%20%5CPhi%5Cleft(%5Cfrac%7B%5Csigma_i%20%5CPhi%5E%7B-1%7D(1%20-%20%5Calpha)%20-%20%5Cmu%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%7D%5Cright)">. Note that <img src="https://latex.codecogs.com/png.latex?%5Cbeta_i"> depends on <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau"> but not on <img src="https://latex.codecogs.com/png.latex?%5Clambda">. From the density, the log-likelihood of the 3PSM given the observed effect size estimates is <span id="eq-3PSM-log-lik"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathcal%7Bl%7D(%5Cmu,%20%5Ctau,%20%5Clambda)%20&amp;=%20%5Csum_%7Bi=1%7D%5Ek%20%5Clog%20d_T(T%20=%20t_i,%20A%20=%20a_i%20%7C%20%5Csigma_i)%20%5C%5C%0A&amp;=%20-%20%5Cfrac%7B1%7D%7B2%7D%20%5Csum_%7Bi=1%7D%5Ek%5Cleft(%5Cfrac%7B(t_i%20-%20%5Cmu)%5E2%7D%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%20+%20%5Clog%5Cleft(%5Ctau%5E2%20+%20%5Csigma_i%5E2%5Cright)%5Cright)%20%5C%5C%0A&amp;%20%5Cqquad%20%5Cqquad%20%5Cqquad%20+%20k_N%20%5Clog%20%5Clambda%20-%20%5Csum_%7Bi=1%7D%5Ek%20%5Clog%5Cleft(1%20-%20(1%20-%20%5Clambda)%20%5Cbeta_i%5Cright)%0A%5Cend%7Baligned%7D%0A%5Ctag%7B2%7D"></span> where <img src="https://latex.codecogs.com/png.latex?k_N%20=%20%5Csum_%7Bi=1%7D%5Ek%20(1%20-%20a_i)"> is the number of non-affirmative effect size estimates observed. The maximum likelihood estimators <img src="https://latex.codecogs.com/png.latex?%5Chat%5Cmu">, <img src="https://latex.codecogs.com/png.latex?%5Chat%5Ctau">, <img src="https://latex.codecogs.com/png.latex?%5Chat%5Clambda"> are the values that maximize <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7Bl%7D(%5Cmu,%20%5Ctau,%20%5Clambda)">.</p>
<p>One way to compute maximum likelihood estimators is by <em>profiling</em> in one or more of the variables. For instance, we can consider the profile log-likelihood of <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau">, which is the log-likelihood function for given values of <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau">, but maximized over <img src="https://latex.codecogs.com/png.latex?%5Clambda">. With profiling, the maximum likelihood estimator of <img src="https://latex.codecogs.com/png.latex?%5Clambda"> is treated as a function of <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Clambda">, as <img src="https://latex.codecogs.com/png.latex?%0A%5Chat%5Clambda(%5Cmu,%20%5Ctau)%20=%20%5Carg%20%5Cmax_%7B%5Clambda%20%3E%200%7D%20%5C%20%5Cmathcal%7Bl%7D(%5Cmu,%20%5Ctau,%20%5Clambda).%0A"> The profile log-likelihood is then <span id="eq-profile-log-likelihood"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%7Bl%7D_P(%5Cmu,%20%5Ctau)%20=%20%5Cmathcal%7Bl%7D(%5Cmu,%20%5Ctau,%20%5Chat%5Clambda(%5Cmu,%20%5Ctau))%0A%5Ctag%7B3%7D"></span> and the maximum likelihood estimators <img src="https://latex.codecogs.com/png.latex?%5Chat%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Chat%5Ctau"> are the values that maximize <img src="https://latex.codecogs.com/png.latex?l_P(%5Cmu,%20%5Ctau)">, with <img src="https://latex.codecogs.com/png.latex?%5Chat%5Clambda%20=%20%5Chat%5Clambda(%5Chat%5Cmu,%20%5Chat%5Ctau)">. The end result is the same as maximizing the whole log-likelihood all at once—it’s just that in some cases, it’s easier to maximize in pieces (especially if there is a simple way to compute <img src="https://latex.codecogs.com/png.latex?%5Chat%5Clambda(%5Cmu,%20%5Ctau)">).</p>
<p>For the three-parameter selection model, the maximum likelihood estimator of <img src="https://latex.codecogs.com/png.latex?%5Clambda"> can also be defined as the solution to the score equation (the derivative of <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7Bl%7D(%5Cmu,%5Ctau,%5Clambda)"> with respect to <img src="https://latex.codecogs.com/png.latex?%5Clambda">) <span id="eq-lambda-score-equation"><img src="https://latex.codecogs.com/png.latex?%0Ak_A%20=%20%5Csum_%7Bi=1%7D%5Ek%20%5Cfrac%7B1%20-%20%5Cbeta_i%7D%7B1%20-%20(1%20-%20%5Clambda)%20%5Cbeta_i%7D.%0A%5Ctag%7B4%7D"></span> The quantity on the left is the observed number of affirmative effects, equal to <img src="https://latex.codecogs.com/png.latex?k_A%20=%20k%20-%20k_N%20=%20%5Csum_%7Bi=1%7D%5Ek%20a_i">. The quantity on the right is the expected number of affirmative results in the observed sample based on the three-parameter selection model. Equation&nbsp;4 does not have a closed-form solution except in some simple special cases, but it can be solved readily with numerical algorithms.</p>
</section>
<section id="p-uniform" class="level1">
<h1>p-uniform*</h1>
<p>Now let me consider van Aert and van Assen’s proposed method, p-uniform*. The method is an estimator of <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau">, but defined by a different objective function that involves truncated normal distributions <span class="citation" data-cites="vanAert2026correcting">(Equation 3 of van Aert &amp; van Assen, 2026)</span>. For the affirmative effects, the objective function involves the density of each effect size estimate, given that it is affirmative; for the non-affirmative effects, it involves the density of each effect size estimate, given that it is not affirmative. Taking the log of their objective function <span class="citation" data-cites="vanAert2026correcting">(Equation 4 of van Aert &amp; van Assen, 2026)</span> gives <span id="eq-pUs-objective"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathcal%7Bu%7D(%5Cmu,%20%5Ctau)%20&amp;=%20-%20%5Cfrac%7B1%7D%7B2%7D%20%5Csum_%7Bi=1%7D%5Ek%5Cleft(%5Cfrac%7B(t_i%20-%20%5Cmu)%5E2%7D%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%20+%20%5Clog%5Cleft(%5Ctau%5E2%20+%20%5Csigma_i%5E2%5Cright)%5Cright)%20%5C%5C%0A&amp;%20%5Cqquad%20%5Cqquad%20%5Cqquad%20-%20%5Csum_%7Bi=1%7D%5Ek%20%5Cleft%5B(1%20-%20a_i)%20%5Clog%20%5Cbeta_i%20+%20a_i%20%5Clog(1%20-%20%5Cbeta_i)%20%5Cright%5D.%0A%5Cend%7Baligned%7D%0A%5Ctag%7B5%7D"></span> The p-uniform estimators <img src="https://latex.codecogs.com/png.latex?%5Cddot%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Cddot%5Ctau"> are the quantities that maximize <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7Bu%7D(%5Cmu,%20%5Ctau)">.</p>
<p>The objective function <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7Bu%7D(%5Cmu,%20%5Ctau)"> can be derived directly from the three-parameter selection model. The truncated densities are the <em>conditional</em> densities of the effect size estimates, given their affirmative or non-affirmative status. Thus, <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7Bu%7D(%5Cmu,%20%5Ctau)%20=%20%5Csum_%7Bi=1%7D%5Ek%20%5Clog%20d_T(T%20=%20t_i%20%7C%20A%20=%20a_i,%20%5Csigma_i)">, whereas the 3PSM log-likelihood uses the <em>unconditional</em> density of the observed effect size estimates. The p-uniform* method is essentially the maximum likelihood estimator of <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau">, conditional on whether each of the effects are affirmative (i.e., conditional on <img src="https://latex.codecogs.com/png.latex?A_1%20=%20a_1,...,A_k%20=%20a_k">. Conditioning removes all of the information in the likelihood that relates to the selection parameter <img src="https://latex.codecogs.com/png.latex?%5Clambda">, so this parameter does not appear in <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7Bu%7D(%5Cmu,%20%5Ctau)">.</p>
<p>Using conditional distributions for inference is warranted when the conditioning information is an ancillary statistic that carries no information about the model parameters <span class="citation" data-cites="Ghosh2010ancillary">(Ghosh et al., 2010)</span>. However, the statistical significance of the effect size estimates are not ancillary for the average effect size and heterogeneity parameters of the 3PSM. <span class="citation" data-cites="vanAert2026correcting">van Aert &amp; van Assen (2026)</span> offer no justification for basing inferences about these parameters on the conditional distribution. It is not obvious to me that confidence intervals based on the conditional distribution would be valid—even asymptotically as <img src="https://latex.codecogs.com/png.latex?k"> increases (except under conditions where the p-uniform* objective function coincides with the 3PSM log-likelihood).</p>
</section>
<section id="equal-standard-errors" class="level1">
<h1>Equal standard errors</h1>
<p>The main simulations reported in <span class="citation" data-cites="vanAert2026correcting">van Aert &amp; van Assen (2026)</span> are based on a data-generating process where all the effect size estimates have equal standard errors, so <img src="https://latex.codecogs.com/png.latex?%5Csigma_1%20=%20%5Csigma_2%20=%20%5Ccdots%20=%20%5Csigma">. This is a fairly artificial scenario that does not arise frequently in real meta-analysis, as far as I know. However, it is nonetheless a useful case to consider because it makes the math much easier and cleaner.</p>
<p>In this scenario with equal standard errors, the estimators of <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau"> from p-uniform* are exactly equal to the corresponding maximum likelihood estimators from the 3PSM. To see this, observe that when all <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> are equal, then all the <img src="https://latex.codecogs.com/png.latex?%5Cbeta_i">’s become constant, with <img src="https://latex.codecogs.com/png.latex?%5Cbeta_i%20=%20%5Cbeta%20=%20%5CPhi%5Cleft(%5Cfrac%7B%5Csigma%20%5CPhi%5E%7B-1%7D(1%20-%20%5Calpha)%20-%20%5Cmu%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma%5E2%7D%7D%5Cright)"> for <img src="https://latex.codecogs.com/png.latex?i%20=%201,...,k">. The maximum likelihood estimator of <img src="https://latex.codecogs.com/png.latex?%5Clambda"> (Equation&nbsp;4) simplifies to <img src="https://latex.codecogs.com/png.latex?%0A%5Chat%5Clambda(%5Cmu,%20%5Ctau)%20=%20%5Cfrac%7Bk_N%20(1%20-%20%5Cbeta)%7D%7Bk_A%20%5Cbeta%7D.%0A"> The difference between the profile log-likelihood of the 3PSM (Equation&nbsp;3) and the objective function of p-uniform* (Equation&nbsp;5) can then be written as <span id="eq-diff-SEeq"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathcal%7Bl%7D_P(%5Cmu,%20%5Ctau)%20-%20%5Cmathcal%7Bu%7D(%5Cmu,%20%5Ctau)%20&amp;=%20k_N%20%5Clog%20%5Chat%5Clambda%20-%20k%20%5Clog%5Cleft(1%20-%20%5Cbeta%20+%20%5Chat%5Clambda%20%5Cbeta%5Cright)%20%5C%5C%0A&amp;%20%5Cqquad%20%5Cqquad%20+%20k_N%20%5Clog(%5Cbeta)%20+%20k_A%20%5Clog(1%20-%20%5Cbeta)%20%5C%5C%0A&amp;=%20k_N%20%5Clog%20k_N%20-%20k_N%20%5Clog%20k_A%20%5C%5C%0A&amp;%20%5Cqquad%20%20+%20k_N%20%5Clog(1%20-%20%5Cbeta)%20-%20k_N%20%5Clog(%5Cbeta)%20%5C%5C%0A&amp;%20%5Cqquad%20%5Cqquad%20-%20k%20%5Clog%20k%20-%20k%20%5Clog(1%20-%20%5Cbeta)%20+%20k%20%5Clog(k_A)%20%5C%5C%0A&amp;%20%5Cqquad%20%5Cqquad%20%5Cqquad%20+%20k_N%20%5Clog(%5Cbeta)%20+%20k_A%20%5Clog(1%20-%20%5Cbeta)%20%5C%5C%0A&amp;=%20k_N%20%5Clog%20k_N%20+%20k_A%20%5Clog%20k_A%20-%20k%20%5Clog%20k.%0A%5Cend%7Baligned%7D%0A%5Ctag%7B6%7D"></span> The difference between the objective functions of the 3PSM and p-uniform* is a <em>constant</em> that does not depend on the model parameters. Consequently, the maxima of the functions must be equal, and the profile likelihood confidence intervals for <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau"> must be identical.</p>
<p>Several implications follow from this. First, the equivalence of the p-uniform* and 3PSM estimators explains why the performance of the point estimators for <img src="https://latex.codecogs.com/png.latex?%5Cmu"> is so similar (in terms of bias and root mean-squared error) in the main simulations of <span class="citation" data-cites="vanAert2026correcting">van Aert &amp; van Assen (2026)</span> Second, the equivalence of the estimators runs counter to van Aert and van Assen’s argument that p-uniform* is more parsimonious and has fewer limitations. If the estimators are the same, then clearly one cannot have advantages over the other. Third, <span class="citation" data-cites="vanAert2026correcting">van Aert &amp; van Assen (2026)</span> reported differences between p-uniform* and 3PSM in the performance of the confidence intervals for <img src="https://latex.codecogs.com/png.latex?%5Cmu"> in the main simulations. However, given the equivalence of the objective functions, differences in the behavior of the confidence intervals must be attributable to differences in how they are constructed (profile likelihood confidence intervals for p-uniform* but Wald-type confidence intervals for the 3PSM), rather than differences between the models.</p>
</section>
<section id="varying-standard-errors" class="level1">
<h1>Varying standard errors</h1>
<p>Except when the standard errors are all equal, the objective function of p-uniform* is not exactly identical to the profile log-likelihood of the 3PSM. However, objective function of p-uniform* produces unbiased estimating equations for <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau">. To see this, observe that another way to express the p-uniform* estimator is as the solution to the system of equations that set the derivative of <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7Bu%7D(%5Cmu,%20%5Ctau)"> with respect to the parameters equal to zero. For p-uniform*, these derivatives are <span id="eq-pUs-scores"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cfrac%7B%5Cpartial%20%5Cmathcal%7Bu%7D%7D%7B%5Cpartial%20%5Cmu%7D%20&amp;=%20%20%5Csum_%7Bi=1%7D%5Ek%20%5Cleft%5B%20%5Cfrac%7B(T_i%20-%20%5Cmu)%7D%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%20+%20%5Cfrac%7B%5Cphi(c_i)%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%7D%5Cleft(%5Cfrac%7B1%20-%20%5Cbeta_i%20-%20A_i%7D%7B%5Cbeta_i%20(1%20-%20%5Cbeta_i)%7D%5Cright)%20%5Cright%5D%20%5C%5C%0A%5Cfrac%7B%5Cpartial%20%5Cmathcal%7Bu%7D%7D%7B%5Cpartial%20%5Ctau%5E2%7D%20&amp;=%20%20%5Cfrac%7B1%7D%7B2%7D%20%5Csum_%7Bi=1%7D%5Ek%20%5Cleft%5B%20%5Cleft(%5Cfrac%7B(T_i%20-%20%5Cmu)%5E2%20-%20%5Cleft(%5Ctau%5E2%20+%20%5Csigma_i%5E2%5Cright)%7D%7B%5Cleft(%5Ctau%5E2%20+%20%5Csigma_i%5E2%5Cright)%5E2%7D%5Cright)%20+%20%5Cfrac%7Bc_i%20%5Cphi(c_i)%7D%7B(%5Ctau%5E2%20+%20%5Csigma_i%5E2)%7D%20%5Cleft(%5Cfrac%7B1%20-%20%5Cbeta_i%20-%20A_i%7D%7B%5Cbeta_i%20(1%20-%20%5Cbeta_i)%7D%5Cright)%5Cright%5D%0A%5Cend%7Baligned%7D%0A%5Ctag%7B7%7D"></span> where <img src="https://latex.codecogs.com/png.latex?c_i%20=%20%5Cfrac%7B%5Csigma_i%20%5CPhi%5E%7B-1%7D(1%20-%20%5Calpha)%20-%20%5Cmu%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%7D">.</p>
<p><a href="../..\posts/step-function-selection-models/">My previous post</a> gave expressions for the mean and variance of an observed effect size estimate under the step-function selection model. For the case of a single-step model, these results imply that <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathbb%7BE%7D(T_i%20-%20%5Cmu)%20&amp;=%20%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%20%5Ctimes%20%5Cfrac%7B(1%20-%20%5Clambda)%20%5Cphi(c_i)%7D%7B1%20-%20(1%20-%20%5Clambda)%20%5Cbeta_i%7D%20%5C%5C%0A%5Cmathbb%7BE%7D%5Cleft%5B(T_i%20-%20%5Cmu)%5E2%5Cright%5D%20&amp;=%20%5Cleft(%5Ctau%5E2%20+%20%5Csigma_i%5E2%5Cright)%20%5Ctimes%20%5Cleft(1%20+%20%5Cfrac%7B(1%20-%20%5Clambda)%20c_i%20%5Cphi(c_i)%7D%7B1%20-%20(1%20-%20%5Clambda)%20%5Cbeta_i%7D%5Cright).%0A%5Cend%7Baligned%7D%0A"> Furthermore, <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BE%7D(A_i)%20=%20%5Cfrac%7B1%20-%20%5Cbeta_i%7D%7B1%20-%20(1%20-%20%5Clambda)%5Cbeta_i%7D.%0A"> Substituting these expressions into the expectations of Equation&nbsp;7 leads to <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathbb%7BE%7D%5Cleft(%5Cfrac%7B%5Cpartial%20%5Cmathcal%7Bu%7D%7D%7B%5Cpartial%20%5Cmu%7D%5Cright)%20&amp;=%20%20%5Csum_%7Bi=1%7D%5Ek%20%5Cleft%5B%20%5Cfrac%7B%5Cmathbb%7BE%7D(T_i%20-%20%5Cmu)%7D%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%20+%20%5Cfrac%7B%5Cphi(c_i)%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%7D%5Cleft(%5Cfrac%7B1%20-%20%5Cbeta_i%20-%20%5Cmathbb%7BE%7D(A_i)%7D%7B%5Cbeta_i%20(1%20-%20%5Cbeta_i)%7D%5Cright)%20%5Cright%5D%20%5C%5C%0A&amp;=%20%5Csum_%7Bi=1%7D%5Ek%20%5Cfrac%7B%5Cphi(c_i)%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%7D%5Cleft%5B%20%5Cfrac%7B1%20-%20%5Clambda%7D%7B1%20-%20(1%20-%20%5Clambda)%20%5Cbeta_i%7D%20-%20%5Cfrac%7B1%20-%20%5Clambda%7D%7B%5Cleft(1%20-%20(1%20-%20%5Clambda)%5Cbeta_i%5Cright)%7D%20%5Cright%5D%20%5C%5C%0A&amp;=%200%0A%5Cend%7Baligned%7D%0A"> and <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathbb%7BE%7D%5Cleft(%5Cfrac%7B%5Cpartial%20%5Cmathcal%7Bu%7D%7D%7B%5Cpartial%20%5Ctau%5E2%7D%20%5Cright)%20&amp;=%20%20%5Cfrac%7B1%7D%7B2%7D%20%5Csum_%7Bi=1%7D%5Ek%20%5Cleft%5B%20%5Cleft(%5Cfrac%7B%5Cmathbb%7BE%7D%5Cleft%5B(T_i%20-%20%5Cmu)%5E2%5Cright%5D%20-%20%5Cleft(%5Ctau%5E2%20+%20%5Csigma_i%5E2%5Cright)%7D%7B%5Cleft(%5Ctau%5E2%20+%20%5Csigma_i%5E2%5Cright)%5E2%7D%5Cright)%20+%20%5Cfrac%7Bc_i%20%5Cphi(c_i)%7D%7B(%5Ctau%5E2%20+%20%5Csigma_i%5E2)%7D%20%5Cleft(%5Cfrac%7B1%20-%20%5Cbeta_i%20-%20%5Cmathbb%7BE%7D(A_i)%7D%7B%5Cbeta_i%20(1%20-%20%5Cbeta_i)%7D%5Cright)%5Cright%5D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B2%7D%20%5Csum_%7Bi=1%7D%5Ek%20%5Cfrac%7B1%7D%7B(%5Ctau%5E2%20+%20%5Csigma_i%5E2)%7D%20%5Cleft%5B1%20+%20%5Cfrac%7B(1%20-%20%5Clambda)c_i%20%5Cphi(c_i)%20%7D%7B1%20-%20(1%20-%20%5Clambda)%20%5Cbeta_i%7D%20-%201%20-%20%5Cfrac%7Bc_i%20%5Cphi(c_i)%20(1%20-%20%5Clambda)%7D%7B%5Cleft(1%20-%20(1%20-%20%5Clambda)%5Cbeta_i%5Cright)%7D%5Cright%5D%20%5C%5C%0A&amp;=%200.%0A%5Cend%7Baligned%7D%0A"> Thus, the p-uniform* estimator is based on unbiased estimating equations for <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau">.</p>
<p>How different is the p-uniform* estimator from the 3PSM maximum likelihood estimator in this case of unequal variances? The degree of potential discrepancy depends on how different the objective functions are. Allowing for unequal variances <span id="eq-diff-SE-varying"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathcal%7Bl%7D_P(%5Cmu,%20%5Ctau)%20-%20%5Cmathcal%7Bu%7D(%5Cmu,%20%5Ctau)%20&amp;=%20k_N%20%5Clog%20%5Chat%5Clambda%20-%20%5Csum_%7Bi=1%7D%5Ek%20%5Clog%5Cleft(1%20-%20(1%20-%20%5Chat%5Clambda)%20%5Cbeta_i%5Cright)%20%5C%5C%0A&amp;%20%5Cqquad%20%5Cqquad%20+%20%5Csum_%7Bi=1%7D%5Ek%20(1%20-%20A_i)%20%5Clog(%5Cbeta_i)%20+%20%5Csum_%7Bi=1%7D%5Ek%20A_i%20%5Clog(1%20-%20%5Cbeta_i)%20%5C%5C%0A&amp;=%20%5Csum_%7Bi=1%7D%5Ek%20(1%20-%20A_i)%20%5Clog%20%5Cleft(%5Chat%5Clambda%20%5Cbeta_i%5Cright)%20+%20%5Csum_%7Bi=1%7D%5Ek%20A_i%20%5Clog(1%20-%20%5Cbeta_i)%20%5C%5C%0A&amp;%20%5Cqquad%20%5Cqquad%20%20-%20%5Csum_%7Bi=1%7D%5Ek%20%5Clog%5Cleft(1%20-%20(1%20-%20%5Chat%5Clambda)%20%5Cbeta_i%5Cright)%20%5C%5C%0A&amp;=%20%5Csum_%7Bi=1%7D%5Ek%20(1%20-%20A_i)%20%5Clog%20%5Cleft(1%20-%20%5Chat%5Cpi_i%5Cright)%20+%20%5Csum_%7Bi=1%7D%5Ek%20A_i%20%5Clog(%5Chat%5Cpi_i),%0A%5Cend%7Baligned%7D%0A%5Ctag%7B8%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%5Chat%5Cpi_i%20=%20%5Cfrac%7B1%20-%20%5Cbeta_i%7D%7B1%20-%20(1%20-%20%5Cbeta_i)%20%5Chat%5Clambda%7D"> is the probability of observing an affirmative result under the three-parameter selection model. The estimated selection parameter is defined by the constraint that <img src="https://latex.codecogs.com/png.latex?k_A%20=%20%5Csum_%7Bi=1%7D%5Ek%20%5Chat%5Cpi_i">. Letting <img src="https://latex.codecogs.com/png.latex?%5Cbar%5Comega_N%20=%20%5Cfrac%7B1%7D%7Bk_N%7D%5Csum_%7Bi=1%7D%5Ek%20(1%20-%20A_i)%5Clog(1%20-%20%5Chat%5Cpi_i)"> and <img src="https://latex.codecogs.com/png.latex?%5Cbar%5Comega_A%20=%20%5Cfrac%7B1%7D%7Bk_A%7D%5Csum_%7Bi=1%7D%5Ek%20A_i%5Clog(%5Chat%5Cpi_i)">, Equation&nbsp;8 can be written as <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%7Bl%7D_P(%5Cmu,%20%5Ctau)%20-%20%5Cmathcal%7Bl%7D_U(%5Cmu,%20%5Ctau)%20=%20k_N%20%5Cbar%5Comega_A%20+%20k_A%5Cbar%5Comega_A,%0A"> with the constraint that <img src="https://latex.codecogs.com/png.latex?k_A%20(1%20-%20%5Cbar%5Cpi_A)%20=%20k_N%20%5Cbar%5Cpi_N">, where <img src="https://latex.codecogs.com/png.latex?%5Cbar%5Cpi_N"> and <img src="https://latex.codecogs.com/png.latex?%5Cbar%5Cpi_A"> are the average probabilities among the non-affirmative and affirmative effects.</p>
<p>van Aert and van Assen argue that p-uniform* is advantageous because it does not entail estimation of the selection weight <img src="https://latex.codecogs.com/png.latex?%5Clambda">. However, one could also take this as a deficiency, insofar as the p-uniform* estimator does not yield information about the strength of selection—a substantively interesting parameter that quantifies the severity of publication bias. This deficiency could be remedied by borrowing the estimator of <img src="https://latex.codecogs.com/png.latex?%5Clambda"> from the step-function model, as <img src="https://latex.codecogs.com/png.latex?%5Cddot%5Clambda%20=%20%5Chat%5Clambda(%5Cddot%5Cmu,%20%5Cddot%5Ctau)">. This estimator can be computed by solving Equation&nbsp;4 for <img src="https://latex.codecogs.com/png.latex?%5Clambda"> with <img src="https://latex.codecogs.com/png.latex?%5Cbeta_i"> evaluated at <img src="https://latex.codecogs.com/png.latex?%5Cddot%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Cddot%5Ctau">.</p>
<p>Like the 3PSM MLE, p-uniform* can be defined by a set of unbiased estimating equations. Although this property is not sufficient to ensure that p-uniform* estimator will work well, it does suggest that p-uniform* might have biases similar to those of the 3PSM MLE. Furthermore, sandwich variance estimators or non-parametric bootstrapping might be useful for assessing uncertainty in model parameter estimates generated with p-uniform* <span class="citation" data-cites="pustejovsky2025estimation">(as we examine for MLEs in Pustejovsky et al., 2025)</span>. However, it seems unlikely that p-uniform* would be more efficient than the MLE of the 3PSM under the model’s assumptions—maximum likelihood estimation is usually pretty hard to improve upon, at least for low-dimensional problems. Does p-uniform* have some robustness advantage that maximum likelihood lacks? In my view, there needs to be more thorough examination of the properties of p-uniform* (be it through theoretical analysis or simulation under varied, realistic data-generating processes) before it can be recommended for conducting meta-analyses of real data.</p>
</section>
<section id="references" class="level1">



<!-- -->


</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" data-line-spacing="2">
<div id="ref-Ghosh2010ancillary" class="csl-entry">
Ghosh, M., Reid, N., &amp; Fraser, D. A. S. (2010). Ancillary statistics: A review. <em>Statistica Sinica</em>, <em>20</em>(4), 1309–1332. <a href="http://www.jstor.org/stable/24309506">http://www.jstor.org/stable/24309506</a>
</div>
<div id="ref-hedges1992modeling" class="csl-entry">
Hedges, L. V. (1992). Modeling publication selection effects in meta-analysis. <em>Statistical Science</em>, <em>7</em>(2), 246–255. <a href="https://doi.org/10.1214/ss/1177011364">https://doi.org/10.1214/ss/1177011364</a>
</div>
<div id="ref-pustejovsky2025estimation" class="csl-entry">
Pustejovsky, J. E., Citkowicz, M., &amp; Joshi, M. (2025). <em>Estimation and Inference for Step-Function Selection Models in Meta-Analysis with Dependent Effects</em>. <a href="https://doi.org/10.31222/osf.io/qg5x6_v1">https://doi.org/10.31222/osf.io/qg5x6_v1</a>
</div>
<div id="ref-VanAert2018correcting" class="csl-entry">
van Aert, R. C. M., &amp; van Assen, M. A. L. M. (2018, October 2). <em>Correcting for publication bias in a meta-analysis with the p-uniform* method</em>. <a href="https://doi.org/10.31222/osf.io/zqjr9">https://doi.org/10.31222/osf.io/zqjr9</a>
</div>
<div id="ref-vanAert2026correcting" class="csl-entry">
van Aert, R. C. M., &amp; van Assen, M. A. L. M. (2026). Correcting for publication bias in a meta-analysis with the p-uniform* method. <em>Psychonomic Bulletin &amp; Review</em>, <em>33</em>(3), 102. <a href="https://doi.org/10.3758/s13423-025-02812-4">https://doi.org/10.3758/s13423-025-02812-4</a>
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>The p-uniform* method does not explicitly define the <img src="https://latex.codecogs.com/png.latex?%5Clambda">, but it is implicit in the assumption that the “weights are the same for the statistically significant and the same for the nonsignificant primary studies’ effect sizes.” Although the weights are constant conditional on whether the effects are affirmative, they are allowed to differ between affirmative and non-affirmative effect sizes, and <img src="https://latex.codecogs.com/png.latex?%5Clambda"> is the ratio of the weights for non-affirmative effects to the weights for affirmative ones.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>meta-analysis</category>
  <category>selective reporting</category>
  <category>estimation</category>
  <guid>https://jepusto.netlify.app/posts/p-uniform-star/</guid>
  <pubDate>Sun, 08 Mar 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Notes on regression adjustment for selectively reported results in meta-analysis</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/Regression-adjustment-for-selective-reporting/</link>
  <description><![CDATA[ 





<p>Several of the most prominent methods for investigating selective reporting bias in meta-analyis take the form of simple linear regressions, estimated by weighted least squares. Methods of this form include the Precision Effect Test (PET) and Precision Effect Estimator with Standard Error (PEESE) adjustments proposed by <span class="citation" data-cites="stanley2008metaregression">Stanley (2008)</span> and <span class="citation" data-cites="stanley2014metaregression">Stanley &amp; Doucouliagos (2014)</span> as well as the endogenous kink (EK) meta-regression proposed by <span class="citation" data-cites="bom2019kinked">Bom &amp; Rachinger (2019)</span>. These methods are widely used (PET and PEESE especially) and have been studied pretty extensively using Monte Carlo simulations <span class="citation" data-cites="bramley2021examining carter2019correcting hong2021using mcshane2016adjusting moreno2009assessment stanley2017limitations">(e.g., Bramley et al., 2021; Carter et al., 2019; Hong &amp; Reed, 2021; McShane et al., 2016; Moreno et al., 2009; Stanley, 2017)</span>. By my read, the simulation evidence is mixed: these regression adjustments seem to be less biased than regular random effects models but they are pretty crude corrections for the bias created by selective reporting, and they don’t always work very well. In this post, I want to look at how the methods work <em>analytically</em>. I’ll derive expressions for their bias and accuracy and consider how one might use these expressions to say something about the conditions under which regression adjustment might be expected to perform reasonably well.</p>
<section id="regression-adjustments-for-publication-bias" class="level2">
<h2 class="anchored" data-anchor-id="regression-adjustments-for-publication-bias">Regression adjustments for publication bias</h2>
<p>For a meta-analysis of <img src="https://latex.codecogs.com/png.latex?K"> studies, let <img src="https://latex.codecogs.com/png.latex?T_i"> be an effect size estimates and <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> be its standard error for <img src="https://latex.codecogs.com/png.latex?i%20=%201,...,K">.<sup>1</sup> Many bias adjustment methods for this context involve the regression <span id="eq-linear-regression"><img src="https://latex.codecogs.com/png.latex?%0AT_i%20=%20%5Calpha%20+%20%5Cbeta%20%5C%20x_i%20+%20%5Cepsilon_i,%0A%5Ctag%7B1%7D"></span> where <img src="https://latex.codecogs.com/png.latex?x_i"> is a predictor that is related to the precision of the effect size estimate and <img src="https://latex.codecogs.com/png.latex?%5Cepsilon_i"> is a residual error. Equation&nbsp;1 is estimated by some form of weighted least squares with weights <img src="https://latex.codecogs.com/png.latex?w_i">, which might be the inverses of the sampling variances, <img src="https://latex.codecogs.com/png.latex?w_i%20=%20%5Csigma_i%5E%7B-2%7D"> (i.e., fixed effects weights) or the inverses of the total residual variance <img src="https://latex.codecogs.com/png.latex?w_i%20=%20%5Cleft(%5Chat%5Ctau%5E2%20+%20%5Csigma_i%5E2%5Cright)%5E%7B-1%7D">, where <img src="https://latex.codecogs.com/png.latex?%5Chat%5Ctau%5E2"> is an estimate of between-study variance in the effect size parameters.</p>
<p>The intuition behind this sort of estimator is that selective reporting on the basis of statistical significance tends to produce larger biases for smaller primary studies (which have larger standard errors), leading to what looks like “small-study” effects. PET, PEESE, and EK adjust for the small-study effects using some form of linear regression, treating the estimate of the intercept <img src="https://latex.codecogs.com/png.latex?%5Calpha"> in Equation&nbsp;1 as the average effect size in a population of infinitely large studies (so that their standard errors are <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%20=%200">).<sup>2</sup> The main difference between the methods is in the predictor used to extrapolate to this hypothetical population:</p>
<ul>
<li>PET uses <img src="https://latex.codecogs.com/png.latex?x_i%20=%20%5Csigma_i">,</li>
<li>PEESE uses <img src="https://latex.codecogs.com/png.latex?x_i%20=%20%5Csigma_i%5E2">, and</li>
<li>EK uses <img src="https://latex.codecogs.com/png.latex?x_i%20=%20(%5Csigma_i%20-%20c)%20%5Ctimes%20I(%5Csigma_i%20%3E%20c)">, where <img src="https://latex.codecogs.com/png.latex?c"> is the so-called “kink” of the meta-regression.<sup>3</sup></li>
</ul>
<p>For now, let’s work with the generic predictors <img src="https://latex.codecogs.com/png.latex?x_1,...,x_K">. Basic results from linear regression tell us that the estimator of the intercept of a linear regression fitted by weighted least squares has the form <span id="eq-alpha-hat"><img src="https://latex.codecogs.com/png.latex?%0A%5Chat%5Calpha%20=%20%5Csum_%7Bi=1%7D%5EK%20%5Cleft%5B%20%5Cfrac%7Bw_i%7D%7BW%7D%20-%20%5Cfrac%7B%5Cbar%7Bx%7D%20w_i%20(x_i%20-%20%5Cbar%7Bx%7D)%7D%7BSS_x%7D%20%5Cright%5D%20T_i,%0A%5Ctag%7B2%7D"></span> where <img src="https://latex.codecogs.com/png.latex?W%20=%20%5Csum_%7Bi=1%7D%5EK%20w_i">, <img src="https://latex.codecogs.com/png.latex?%5Cbar%7Bx%7D%20=%20%5Cfrac%7B1%7D%7BW%7D%20%5Csum_%7Bi=1%7D%5EK%20w_i%20x_i">, and <img src="https://latex.codecogs.com/png.latex?SS_x%20=%20%5Csum_%7Bi=1%7D%5EK%20w_i%20(x_i%20-%20%5Cbar%7Bx%7D)%5E2">. Denoting the full vector of standard errors as <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%5Csigma%20=%20%5Cleft(%5Csigma_1,...,%5Csigma_K%5Cright)'"> and observing that the predictors are all functions of the standard errors, the conditional expectation and conditional variance of <img src="https://latex.codecogs.com/png.latex?%5Chat%5Calpha"> can be written as <span id="eq-alpha-expectation"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BE%7D%5Cleft(%5Cleft.%5Chat%5Calpha%5Cright%7C%20%5Cboldsymbol%5Csigma%20%5Cright)%20=%20%5Csum_%7Bi=1%7D%5EK%20%5Cleft%5B%5Cfrac%7Bw_i%7D%7BW%7D%20%20-%20%5Cfrac%7B%5Cbar%7Bx%7D%20w_i%20(x_i%20-%20%5Cbar%7Bx%7D)%7D%7BSS_x%7D%20%5Cright%5D%20%5Ctimes%20%5Cmathbb%7BE%7D%5Cleft(%5Cleft.%20T_i%20%5Cright%7C%20%5Csigma_i%20%5Cright)%0A%5Ctag%7B3%7D"></span> and <span id="eq-alpha-variance"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BV%7D%5Cleft(%5Cleft.%5Chat%5Calpha%5Cright%7C%20%5Cboldsymbol%5Csigma%20%5Cright)%20=%20%5Csum_%7Bi=1%7D%5EK%20%5Cleft%5B%5Cfrac%7Bw_i%7D%7BW%7D%20%20-%20%5Cfrac%7B%5Cbar%7Bx%7D%20w_i%20(x_i%20-%20%5Cbar%7Bx%7D)%7D%7BSS_x%7D%20%5Cright%5D%5E2%20%5Ctimes%20%5Cmathbb%7BV%7D%5Cleft(%5Cleft.%20T_i%20%5Cright%7C%20%5Csigma_i%20%5Cright).%0A%5Ctag%7B4%7D"></span> If the real regression is linear in <img src="https://latex.codecogs.com/png.latex?x_i">, then <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BE%7D%5Cleft(%5Cleft.%20T_i%20%5Cright%7C%20%5Csigma_i%20%5Cright)%20=%20%5Calpha%20+%20%5Cbeta%20%5C%20x_i">. Substitute this into Equation&nbsp;16 and you’ll find <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BE%7D%5Cleft(%5Cleft.%5Chat%5Calpha%5Cright%7C%20%5Cboldsymbol%5Csigma%20%5Cright)%20=%20%5Calpha">, so the regression estimator is indeed unbiased. But what if the real conditional expectation is not linear?</p>
</section>
<section id="data-generating-processes" class="level2">
<h2 class="anchored" data-anchor-id="data-generating-processes">Data-generating processes</h2>
<p>Regression adjustment methods are a bit hard to pin down because they’re not full generative models of the process by which the observed set of effect sizes arises. Instead, they’re just different forms of approximations, which don’t really commit to any particular model for how selective reporting occurs. To say anything about how well the regression adjustments work, I will need to look beyond these specific methods to other models for the selective reporting process.</p>
<p><span class="citation" data-cites="stanley2014metaregression">Stanley &amp; Doucouliagos (2014)</span> motivated the PEESE adjustment through a Taylor series approximation to the bias of effect size estimates under a simple form of a <a href="../..\posts/step-function-selection-models/">step-function selection model</a>, in which the real form of the bias is nonlinear in <img src="https://latex.codecogs.com/png.latex?%5Csigma_i">. There are a number of other models where the strength of selection depends on the statistical significance of the effect size estimate (e.g., the <a href="../..\posts/beta-density-selection-models/">beta density model</a>), as well as models that exhibit small-study effects produced by other selection processes (e.g., the <a href="../..\posts/Copas-selection-models">Copas selection model</a>). Here I’ll look at a step-function model and the Copas model, mostly because these are fairly tractable to analyze. Both models posit that effect size estimates follow a conventional random effects model prior to being put through the selection process. Denoting an effect size estimate prior to selection as <img src="https://latex.codecogs.com/png.latex?T_i%5E*">, we assume <span id="eq-random-effects"><img src="https://latex.codecogs.com/png.latex?%0AT_i%5E*%20=%20%5Cmu%20+%20v_i%5E*%20+%20e_i%5E*%0A%5Ctag%7B5%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%5Cmu"> is the overall average effect size, <img src="https://latex.codecogs.com/png.latex?v_i%5E*"> is a mean-zero random effect with variance <img src="https://latex.codecogs.com/png.latex?%5Ctau%5E2">, which captures heterogeneity in the effect size parameters, and <img src="https://latex.codecogs.com/png.latex?e_i%5E*"> is a mean zero sampling error with known standard error <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*">. In the ideal, a selective reporting correction would recover an estimate of the mean of the effect size distribution <img src="https://latex.codecogs.com/png.latex?%5Cmu">.</p>
<section id="step-function-models" class="level3">
<h3 class="anchored" data-anchor-id="step-function-models">Step function models</h3>
<p>In the step function model, we assume that the generated effect size estimate <img src="https://latex.codecogs.com/png.latex?T_i%5E*"> is observed with some probability that depends on its <img src="https://latex.codecogs.com/png.latex?p">-value for the one-sided hypothesis test of <img src="https://latex.codecogs.com/png.latex?H_0:%20%5Cdelta%20%5Cleq%200">. Letting <img src="https://latex.codecogs.com/png.latex?p_i%5E*%20=%201%20-%20%5CPhi%5Cleft(T_i%5E*%20/%20%5Csigma_i%5E*%5Cright)">, the selective reporting process of the step-function model is then <span id="eq-step-selection-process"><img src="https://latex.codecogs.com/png.latex?%0A%5CPr%5Cleft(T_i%5E*%20%5Ctext%7B%20is%20observed%7D%7C%20T_i%5E*,%20%5Csigma_i%5E*%5Cright)%20=%20%5Cbegin%7Bcases%7D%0A1%20&amp;%20%5Ctext%7Bif%7D%20%5Cquad%20p_i%5E*%20%3C%20%5Calpha_1%20%5C%5C%0A%5Clambda_1%20&amp;%20%5Ctext%7Bif%7D%20%5Cquad%20%5Calpha_h%20%5Cleq%20p_i%5E*%20%3C%20%5Calpha_%7Bh+1%7D,%20%5Cquad%20h%20=%201,...,H-1%20%5C%5C%0A%5Clambda_H%20&amp;%20%5Ctext%7Bif%7D%20%5Cquad%20%5Calpha_H%20%5Cleq%20p_i%5E*%20%5C%5C%0A%5Cend%7Bcases%7D%0A%5Ctag%7B6%7D"></span> for some set of steps <img src="https://latex.codecogs.com/png.latex?%5Calpha_1,...,%5Calpha_H"> and selection weights <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%5Clambda%20=%20%5Cleft(%5Clambda_1,...,%5Clambda_H%5Cright)">.</p>
<p>In my <a href="../..\posts/step-function-selection-models/">previous post on the step-function model</a>, I showed that the conditional expectation of the observed effect size estimates is <span id="eq-step-expectation"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BE%7D(T_i%20%7C%20%5Csigma_i)%20=%20%5Cmu%20+%20%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%20%5Ctimes%20%5Cpsi(%5Cmu,%20%5Ctau,%20%5Cboldsymbol%5Clambda,%20%5Csigma_i),%0A%5Ctag%7B7%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%5Cpsi()"> is a certain, rather complicated non-linear function of the model parameters given by <span id="eq-psi-bar"><img src="https://latex.codecogs.com/png.latex?%0A%5Cpsi(%5Cmu,%5Ctau,%20%5Cboldsymbol%5Clambda,%20%5Csigma_i)%20=%20%5Cfrac%7B%5Csum_%7Bh=0%7D%5EH%20%5Clambda_h%20%5Cleft(%5Cphi(c_%7Bh+1,i%7D)%20-%20%5Cphi(c_%7Bhi%7D)%5Cright)%7D%7B%5Csum_%7Bh=0%7D%5EH%20%5Clambda_h%20%5Cleft(%5CPhi(c_%7Bh+1,i%7D)%20-%20%5CPhi(c_%7Bhi%7D)%5Cright)%7D,%0A%5Ctag%7B8%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%0Ac_%7Bhi%7D%20=%20%5Cfrac%7B%5Csigma_i%20%5CPhi%5E%7B-1%7D(1%20-%20%5Calpha_h)%20-%20%5Cmu%7D%7B%5Csqrt%7B%5Ctau%5E2+%20%5Csigma_i%5E2%7D%7D,%0A"> with <img src="https://latex.codecogs.com/png.latex?c_%7B0i%7D%20=%20%5Cinfty"> and <img src="https://latex.codecogs.com/png.latex?c_%7BH+1,i%7D%20=%20-%5Cinfty">.<sup>4</sup> Letting <img src="https://latex.codecogs.com/png.latex?%0A%5Ckappa_i%20=%20%5Ckappa(%5Cmu,%5Ctau,%20%5Cboldsymbol%5Clambda,%20%5Csigma_i)%20=%20%5Cfrac%7B%5Csum_%7Bh=0%7D%5EH%20%5Clambda_h%20%5Cleft%5Bc_%7Bhi%7D%20%5Cphi%5Cleft(c_%7Bhi%7D%5Cright)%20-%20c_%7Bh+1,i%7D%20%5Cphi%5Cleft(c_%7Bh+1,i%7D%5Cright)%5Cright%5D%7D%7B%5Csum_%7Bh=0%7D%5EH%20%5Clambda_h%20%5Cleft(%5CPhi(c_%7Bh+1,i%7D)%20-%20%5CPhi(c_%7Bhi%7D)%5Cright)%7D%0A"> and <img src="https://latex.codecogs.com/png.latex?%5Cpsi_i%20=%20%5Cpsi(%5Cmu,%5Ctau,%20%5Cboldsymbol%5Clambda,%20%5Csigma_i)">, the conditional variance is <span id="eq-step-variance"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BV%7D(T_i%20%7C%20%5Csigma_i)%20=%20%5Cleft(%5Ctau%5E2%20+%20%5Csigma_i%5E2%5Cright)%20%5Cleft(1%20-%20%5Ckappa_i%20-%20%5Cpsi_i%5E2%5Cright).%0A%5Ctag%7B9%7D"></span></p>
<p>Substituting Equation&nbsp;7 into Equation&nbsp;16, the bias of a regression-adjustment estimator under the step-function selection model is <span id="eq-alpha-expectation-step"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BE%7D%5Cleft(%5Cleft.%5Chat%5Calpha%5Cright%7C%20%5Cboldsymbol%5Csigma%20%5Cright)%20-%20%5Cmu%20=%20%5Csum_%7Bi=1%7D%5EK%20%5Cleft%5B%5Cfrac%7Bw_i%7D%7BW%7D%20%20-%20%5Cfrac%7B%5Cbar%7Bx%7D%20w_i%20(x_i%20-%20%5Cbar%7Bx%7D)%7D%7BSS_x%7D%20%5Cright%5D%20%5Ctimes%20%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%20%5Ctimes%20%5Cpsi(%5Cmu,%20%5Ctau,%20%5Cboldsymbol%5Clambda,%20%5Csigma_i).%0A%5Ctag%7B10%7D"></span> Thus, the bias of a regression adjustment depends on how well the predictor <img src="https://latex.codecogs.com/png.latex?x_i"> approximates the non-linear function <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%20%5Ctimes%20%5Cpsi(%5Cmu,%20%5Ctau,%20%5Cboldsymbol%5Clambda,%20%5Csigma_i)">.</p>
<p>Substituting Equation&nbsp;9 into Equation&nbsp;4, an expression for the sampling variance of the regression adjustment estimator is <span id="eq-alpha-variance-step"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BV%7D%5Cleft(%5Cleft.%5Chat%5Calpha%5Cright%7C%20%5Cboldsymbol%5Csigma%20%5Cright)%20=%20%5Csum_%7Bi=1%7D%5EK%20%5Cleft%5B%5Cfrac%7Bw_i%7D%7BW%7D%20%20-%20%5Cfrac%7B%5Cbar%7Bx%7D%20w_i%20(x_i%20-%20%5Cbar%7Bx%7D)%7D%7BSS_x%7D%20%5Cright%5D%5E2%20%5Ctimes%20%5Cleft(%5Ctau%5E2%20+%20%5Csigma_i%5E2%5Cright)%20%5Cleft(1%20-%20%5Ckappa_i%20-%20%5Cpsi_i%5E2%5Cright).%0A%5Ctag%7B11%7D"></span> Combining the bias and the variance in the usual way leads to an expression for RMSE: <span id="eq-alpha-RMSE"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BRMSE%7D%5Cleft(%5Cleft.%5Chat%5Calpha%5Cright%7C%20%5Cboldsymbol%5Csigma%20%5Cright)%20=%20%5Csqrt%7B%5Cleft(%5Cmathbb%7BE%7D%5Cleft(%5Cleft.%5Chat%5Calpha%5Cright%7C%20%5Cboldsymbol%5Csigma%20%5Cright)%20-%20%5Cmu%5Cright)%5E2%20+%20%5Cmathbb%7BV%7D%5Cleft(%5Cleft.%5Chat%5Calpha%5Cright%7C%20%5Cboldsymbol%5Csigma%20%5Cright)%7D.%0A%5Ctag%7B12%7D"></span> In general, the magnitude of the bias and RMSE will depend on:</p>
<ul>
<li>the parameters of the true distribution of effects, <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau">,</li>
<li>the strength of selective reporting, measured by <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%5Clambda">,</li>
<li>the choice of predictors <img src="https://latex.codecogs.com/png.latex?x_i"> and weights <img src="https://latex.codecogs.com/png.latex?w_i">, and</li>
<li>the distribution of <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> values (i.e., the average and spread of the standard errors).</li>
</ul>
<p>That’s a lot of moving pieces. However, the bias and RMSE are at least <em>computable</em>, and analytic expressions are much quicker to calculate than running a couple of thousand replications of a simulation.</p>
</section>
<section id="copas-selection-models" class="level3">
<h3 class="anchored" data-anchor-id="copas-selection-models">Copas selection models</h3>
<p>The Copas selection model posits a different selection process than the step-function model, in which the probability that a generated effect size estimate is reported is expressed in terms of an unobserved, normally distributed variable that is correlated with the sampling error of the effect size estimate (i.e., correlated with <img src="https://latex.codecogs.com/png.latex?e_i%5E*"> in Equation&nbsp;5). See <a href="../..\posts/Copas-selection-models/">my previous post on the Copas model</a> for a more detailed description, interactive illustration, and some spicy takes on why this model is pretty odd. The selection process here has three parameters, which I will denote as <img src="https://latex.codecogs.com/png.latex?a">, <img src="https://latex.codecogs.com/png.latex?b">, and <img src="https://latex.codecogs.com/png.latex?%5Crho"> (my previous post used <img src="https://latex.codecogs.com/png.latex?%5Calpha"> and <img src="https://latex.codecogs.com/png.latex?%5Cbeta">, but in this post I need these to define the regression equations). The <img src="https://latex.codecogs.com/png.latex?a"> parameter controls the overall fraction of generated effect size estimates that are observed, the <img src="https://latex.codecogs.com/png.latex?b"> parameter controls how strongly the probability of observation depends on the precision of the effect size estimate, and the <img src="https://latex.codecogs.com/png.latex?%5Crho"> parameter controls the degree to which the probability depends on the magnitude of the observed effect size estimate relative to the overall average effect. The probability that a generated effect size estimate is observed is given by <span id="eq-Copas-selection-probability"><img src="https://latex.codecogs.com/png.latex?%0A%5CPr%5Cleft(O_i%5E*%20=%201%20%7C%20T_i%5E*,%20%5Csigma_i%5E*%5Cright)%20=%20%5CPhi%5Cleft(%5Csqrt%7B%5Cfrac%7B%5Ctau%5E2%20+%20%5Csigma_i%5E%7B*2%7D%7D%7B%5Ctau%5E2%20+%20(1%20-%20%5Crho%5E2)%20%5Csigma_i%5E%7B*2%7D%7D%7D%5Cleft%5B%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%5E*%7D%20+%20%20%5Cfrac%7B%5Crho%20%5Csigma_i%5E*%20%5Cleft(T_i%5E*%20-%20%5Cmu%5Cright)%7D%7B%5Ctau%5E2%20+%20%5Csigma_i%5E%7B*2%7D%7D%5Cright%5D%5Cright).%0A%5Ctag%7B13%7D"></span> In <a href="../..\posts/Copas-selection-models/">my previous post</a>, I gave expressions for the mean and variance of observed effect size estimate conditional on <img src="https://latex.codecogs.com/png.latex?%5Csigma_i">. The conditional expectation is <span id="eq-Copas-mean"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BE%7D%5Cleft(T_i%20%7C%20%5Csigma_i%20%5Cright)%20=%20%5Cmu%20+%20%5Crho%20%5Csigma_i%20%5Cxi%5Cleft(%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%7D%5Cright)%0A%5Ctag%7B14%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%5Cxi(u)%20=%20%5Cphi(u)%20/%20%5CPhi(u)">. The conditional variance is <span id="eq-Copas-variance"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BV%7D%5Cleft(T_i%20%7C%20%5Csigma_i%20%5Cright)%20=%20%5Ctau%5E2%20+%20%5Csigma_i%5E2%5Cleft(1%20-%20%5Crho%5E2%20%5Cxi%5Cleft(%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%7D%5Cright)%20%5Ctimes%20%5Cleft%5B%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%7D%20%20+%20%5Cxi%5Cleft(%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%7D%5Cright)%5Cright%5D%5Cright).%0A%5Ctag%7B15%7D"></span> Substituting into Equation&nbsp;16, the bias of a regression-adjustment estimator under the Copas selection model is <span id="eq-alpha-expectation"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BE%7D%5Cleft(%5Cleft.%5Chat%5Calpha%5Cright%7C%20%5Cboldsymbol%5Csigma%20%5Cright)%20-%20%5Cmu%20=%20%5Crho%20%5Csum_%7Bi=1%7D%5EK%20%5Cleft%5B%5Cfrac%7Bw_i%7D%7BW%7D%20%20-%20%5Cfrac%7B%5Cbar%7Bx%7D%20w_i%20(x_i%20-%20%5Cbar%7Bx%7D)%7D%7BSS_x%7D%20%5Cright%5D%20%5Ctimes%20%5Csigma_i%20%5Cxi%5Cleft(%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%7D%5Cright).%0A%5Ctag%7B16%7D"></span> This expression is a bit simpler than the bias under the step function model. For one, the bias depends neither on <img src="https://latex.codecogs.com/png.latex?%5Cmu"> nor on <img src="https://latex.codecogs.com/png.latex?%5Ctau">, and is multiplicative in the <img src="https://latex.codecogs.com/png.latex?%5Crho"> parameter. An implication is that, if you were running a simulation where the Copas model was the true data-generating process, the bias of the regression adjustment estimator should be invariant across <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau"> and should be strictly proportional to <img src="https://latex.codecogs.com/png.latex?%5Crho">. Just as with the step-function selection model, the bias will depend on how well the predictor <img src="https://latex.codecogs.com/png.latex?x_i"> approximates the functional form of the bias curve <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%20%5Cxi%5Cleft(%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%7D%5Cright)">, which will in turn depend on the distribution of the standard errors. In other words, the regression adjustments will perform better or worse, depending on the average <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> and shape of the <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> distribution across the included studies.</p>
</section>
</section>
<section id="why-care" class="level1">
<h1>Why care?</h1>
<p>I’ve just thrown down a lot of rather ugly looking formulas, and one might well ask why anyone should care about this mess of math. What are these formulas good for? To be honest, I worked through this stuff mostly for myself,<sup>5</sup> but I do think there might be some useful implications to be drawn from this. For one, the expressions for bias and RMSE show how the performance of the regression adjustments depend on the model parameters, which is useful to know if you’re trying to determine how to set up a simulation study involving PET or PEESE, choose which parameters to vary, or fit a meta-model to the results.</p>
<p>Another, perhaps more pragmatic application would be to use the expressions to compare the bias or accuracy of different forms of regression adjustment. For a given application, should we use PET or PEESE? And should we weight by inverse sampling variances (fixed effects weights) or inverse total variances (random effects weights) or something else (like equal weighting)? We might be able to get some purchase on these questions by computing bias or RMSE for some hypothetical scenarios. Under either the step function model or the Copas model, the performance of a regression adjustment will depend on the distribution of sampling standard errors, <img src="https://latex.codecogs.com/png.latex?%5Csigma_1,...,%5Csigma_K">. When conducting a meta-analysis, we will know this sample distribution but we won’t know the true values of <img src="https://latex.codecogs.com/png.latex?%5Cmu">, <img src="https://latex.codecogs.com/png.latex?%5Ctau">, or the parameters of the selection process. Still, we could evaluate the expressions above under some plausible hypothetical scenarios and see whether one regression adjustment is consistently better than the others. This will take some further fleshing out, which I will leave for another day.</p>


<!-- -->


</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" data-line-spacing="2">
<div id="ref-bom2019kinked" class="csl-entry">
Bom, P. R. D., &amp; Rachinger, H. (2019). A kinked meta-regression model for publication bias correction. <em>Research Synthesis Methods</em>, <em>10</em>(4), 497–514. <a href="https://doi.org/10.1002/jrsm.1352">https://doi.org/10.1002/jrsm.1352</a>
</div>
<div id="ref-bramley2021examining" class="csl-entry">
Bramley, P., López-López, J. A., &amp; Higgins, J. P. T. (2021). Examining how meta-analytic methods perform in the presence of bias: <span>A</span> simulation study. <em>Research Synthesis Methods</em>, <em>12</em>(6), 816–830. <a href="https://doi.org/10.1002/jrsm.1516">https://doi.org/10.1002/jrsm.1516</a>
</div>
<div id="ref-carter2019correcting" class="csl-entry">
Carter, E. C., Schönbrodt, F. D., Gervais, W. M., &amp; Hilgard, J. (2019). Correcting for bias in psychology: A comparison of meta-analytic methods. <em>Advances in Methods and Practices in Psychological Science</em>, <em>2</em>(2). <a href="https://doi.org/10.1177/2515245919847196">https://doi.org/10.1177/2515245919847196</a>
</div>
<div id="ref-hong2021using" class="csl-entry">
Hong, S., &amp; Reed, W. R. (2021). Using <span>Monte</span> <span>Carlo</span> experiments to select meta-analytic estimators. <em>Research Synthesis Methods</em>, <em>12</em>(2), 192–215. <a href="https://doi.org/10.1002/jrsm.1467">https://doi.org/10.1002/jrsm.1467</a>
</div>
<div id="ref-mcshane2016adjusting" class="csl-entry">
McShane, B. B., Böckenholt, U., &amp; Hansen, K. T. (2016). Adjusting for publication bias in meta-analysis an evaluation of selection methods and some cautionary notes. <em>Perspectives on Psychological Science</em>, <em>11</em>(5), 730–749. <a href="http://pps.sagepub.com/content/11/5/730.short">http://pps.sagepub.com/content/11/5/730.short</a>
</div>
<div id="ref-moreno2009assessment" class="csl-entry">
Moreno, S. G., Sutton, A. J., Ades, A., Stanley, T. D., Abrams, K. R., Peters, J. L., &amp; Cooper, N. J. (2009). Assessment of regression-based methods to adjust for publication bias through a comprehensive simulation study. <em><span>BMC</span> Medical Research Methodology</em>, <em>9</em>(1). <a href="https://doi.org/10.1186/1471-2288-9-2">https://doi.org/10.1186/1471-2288-9-2</a>
</div>
<div id="ref-stanley2008metaregression" class="csl-entry">
Stanley, T. D. (2008). Meta-regression methods for detecting and estimating empirical effects in the presence of publication selection*. <em>Oxford Bulletin of Economics and Statistics</em>, <em>70</em>(1), 103–127. <a href="https://doi.org/10.1111/j.1468-0084.2007.00487.x">https://doi.org/10.1111/j.1468-0084.2007.00487.x</a>
</div>
<div id="ref-stanley2017limitations" class="csl-entry">
Stanley, T. D. (2017). Limitations of <span>PET</span>-<span>PEESE</span> and other meta-analysis methods. <em>Social Psychological and Personality Science</em>, <em>8</em>(5), 581–591. <a href="https://doi.org/10.1177/1948550617693062">https://doi.org/10.1177/1948550617693062</a>
</div>
<div id="ref-stanley2014metaregression" class="csl-entry">
Stanley, T. D., &amp; Doucouliagos, H. (2014). Meta-regression approximations to reduce publication selection bias. <em>Research Synthesis Methods</em>, <em>5</em>(1), 60–78.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>I will treat the standard errors as known quantities that are independent of the effect size estimates, even though the standard errors are actually stochastic and, for some effect size metrics, correlated with the effect size estimates.↩︎</p></li>
<li id="fn2"><p>All of the adjustment methods will run into trouble if small study effects are the result of some mechanism other than selective reporting. For instance, if some primary study feature is systematically, positively associated with effect size and tends to be less common in larger studies, then it will act as a confounder, inducing correlation between effect size and standard error even in the absence of selective reporting.↩︎</p></li>
<li id="fn3"><p>With the EK estimator, the kink is an estimated quantity, defined by a preliminary estimator of <img src="https://latex.codecogs.com/png.latex?%5Calpha"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau%5E2">. This makes is quite tricky to analyze, but I’m going to gloss over that detail entirely (at least for the remainder of this post).↩︎</p></li>
<li id="fn4"><p>For a model with a single step at <img src="https://latex.codecogs.com/png.latex?%5Calpha_1"> and a single selection parameter <img src="https://latex.codecogs.com/png.latex?%5Clambda_1">, <img src="https://latex.codecogs.com/png.latex?%0A%20%20%5Cpsi(%5Cmu,%5Ctau,%5Clambda_1,%20%5Csigma_i)%20=%20%5Cfrac%7B(1%20-%20%5Clambda_1)%20%5Cphi(c_%7B1i%7D)%7D%7B1%20-%20(1%20-%20%5Clambda_1)%5CPhi(c_%7B1i%7D)%7D.%0A%20%20">↩︎</p></li>
<li id="fn5"><p>Sometimes, I get a theoretical itch that I just can’t help but scratch.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>effect-size</category>
  <category>distribution-theory</category>
  <category>selective-reporting</category>
  <guid>https://jepusto.netlify.app/posts/Regression-adjustment-for-selective-reporting/</guid>
  <pubDate>Sat, 17 Jan 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Variance stabilization of Cohen’s d</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/d-to-r-to-z/</link>
  <description><![CDATA[ 





<p>In a recent <em>Psychological Methods</em> paper, <span class="citation" data-cites="Haaf2023does">Haaf &amp; Rouder (2023)</span> suggest conducting meta-analysis of standardized mean differences after transforming them to point biserial correlations and then applying Fisher’s <img src="https://latex.codecogs.com/png.latex?z">-transformation. They argue that this leads to a variance-stabilized effect size estimator, which has sampling variance that is constant across varying values of the true parameter <img src="https://latex.codecogs.com/png.latex?%5Cdelta">. <span class="citation" data-cites="Bartos2023robust">Bartoš et al. (2023)</span> cites <span class="citation" data-cites="Haaf2023does">Haaf &amp; Rouder (2023)</span> as justification for conducting meta-analysis of standardized mean differences after applying this <img src="https://latex.codecogs.com/png.latex?d">-to-<img src="https://latex.codecogs.com/png.latex?r">-to-<img src="https://latex.codecogs.com/png.latex?z"> transformation. All this surprised me a bit because the transformation was unfamiliar, although I’ve written about these sorts of effect size conversions before <span class="citation" data-cites="Pustejovsky2014converting">(cf. Pustejovsky, 2014)</span>. In other work <span class="citation" data-cites="Pustejovsky2018testing">(Pustejovsky &amp; Rodgers, 2018)</span>, I’ve used the variance-stabilizing transformation given in <span class="citation" data-cites="Hedges1985statistical">Hedges &amp; Olkin (1985)</span>, which is different than this approach. What gives? Is this <img src="https://latex.codecogs.com/png.latex?d">-to-<img src="https://latex.codecogs.com/png.latex?r">-to-<img src="https://latex.codecogs.com/png.latex?z"> business <em>really</em> variance stabilizing?</p>
<section id="zd" class="level2">
<h2 class="anchored" data-anchor-id="zd"><img src="https://latex.codecogs.com/png.latex?z(d)"></h2>
<p>The first step in the transformation proposed by <span class="citation" data-cites="Haaf2023does">Haaf &amp; Rouder (2023)</span> depends on the relative sample sizes of the two groups, which I will parameterize as <img src="https://latex.codecogs.com/png.latex?R%20=%20N_1%20:%20N_2">. Letting <img src="https://latex.codecogs.com/png.latex?a%20=%20(R%20+%201)%5E2%20/%20R">, the transformation function is given by <img src="https://latex.codecogs.com/png.latex?%0Az(d;%20a)%20=%20%5Cfrac%7B1%7D%7B2%7D%5Cleft%5B%5Clog%5Cleft(%5Csqrt%7Bd%5E2%20+%20a%7D%20+%20d%5Cright)%20-%20%5Clog%5Cleft(%5Csqrt%7Bd%5E2%20+%20a%7D%20-%20d%5Cright)%5Cright%5D%0A"></p>
<p>The shape of the transformation is depicted in Figure&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="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">d_to_z <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>(d, R) {</span>
<span id="cb1-4">  r <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> <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><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> (R <span 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> R)</span>
<span id="cb1-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">atanh</span>(r)</span>
<span id="cb1-6">}</span>
<span id="cb1-7"></span>
<span id="cb1-8">d_to_h <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>(d, R) {</span>
<span id="cb1-9">  a <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> (R <span 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> R</span>
<span id="cb1-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sign</span>(d) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(<span class="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> <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><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> 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;">log</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> 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="cb1-11">}</span>
<span id="cb1-12"></span>
<span id="cb1-13">transform_dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb1-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb1-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>),</span>
<span id="cb1-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">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="cb1-17">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb1-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">a =</span> (R <span 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> R,</span>
<span id="cb1-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">z =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">d_to_z</span>(d, R),</span>
<span id="cb1-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">h =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">d_to_h</span>(d, R),</span>
<span id="cb1-22">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R_fac =</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>(R,<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;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">":"</span>))</span>
<span id="cb1-23">  )</span>
<span id="cb1-24"></span>
<span id="cb1-25"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(transform_dat) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(d, z, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> R_fac) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-27">  <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="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;">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;">"dashed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-30">  <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;">"inside"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position.inside =</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.9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</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;">minor_breaks =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-Haaf-transform" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-Haaf-transform-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://jepusto.netlify.app/posts/d-to-r-to-z/index_files/figure-html/fig-Haaf-transform-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-Haaf-transform-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: d-to-r-to-z transformation for various allocation fractions <img src="https://latex.codecogs.com/png.latex?p">. The dashed line is y = x / 2.
</figcaption>
</figure>
</div>
</div>
</div>
<p>One way to check whether this transformation is variance-stabilizing is by finding the <a href="../..\posts/Multivariate-delta-method/">delta-method approximation</a> to its variance. I find the first derivative of <img src="https://latex.codecogs.com/png.latex?z(d)"> to be <img src="https://latex.codecogs.com/png.latex?%0Az'(d;%20a)%20=%20%5Cfrac%7B1%7D%7B%5Csqrt%7Bd%5E2%20+%20a%7D%7D,%0A"> and so <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Ctext%7BVar%7D(z(d))%20&amp;%5Capprox%20%5Cleft(%20z'(%5Cdelta;%20a)%20%5Cright)%5E2%20%5Ctimes%20%5Ctext%7BVar%7D(d)%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B%5Cdelta%5E2%20+%20a%7D%20%5Ctimes%20%5Cfrac%7B1%7D%7BN%7D%20%5Cleft(a%20+%20%5Cfrac%7B%5Cdelta%5E2%7D%7B2%7D%5Cright)%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7BN%7D%20%5Cleft(%5Cfrac%7Ba%20+%20%5Cfrac%7B1%7D%7B2%7D%5Cdelta%5E2%7D%7Ba%20+%20%5Cdelta%5E2%7D%5Cright).%0A%5Cend%7Baligned%7D%0A"> This looks like 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="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">transform_dat <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;">mutate</span>(</span>
<span id="cb2-3">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Vz =</span> (a <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="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> (a <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> d<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb2-4">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb2-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(d, Vz, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> R_fac) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <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;">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;">"inside"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position.inside =</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.9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(delta), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%*%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Var</span>(z)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</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;">minor_breaks =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-Var-z" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-Var-z-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://jepusto.netlify.app/posts/d-to-r-to-z/index_files/figure-html/fig-Var-z-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-Var-z-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Delta method approximation for the variance of <img src="https://latex.codecogs.com/png.latex?z(d)">.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Based on this approximation, <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BVar%7D(z(d))"> is not independent of <img src="https://latex.codecogs.com/png.latex?%5Cdelta"> and is instead <em>decreasing</em> in the magnitude of the true effect size.</p>
</section>
<section id="hz" class="level2">
<h2 class="anchored" data-anchor-id="hz"><img src="https://latex.codecogs.com/png.latex?h(z)"></h2>
<p>The variance-stabilizing transformation given in <span class="citation" data-cites="Hedges1985statistical Pustejovsky2018testing">Hedges &amp; Olkin (1985; see also Pustejovsky &amp; Rodgers, 2018)</span> is <img src="https://latex.codecogs.com/png.latex?%0Ah(d;%20a)%20=%20%5Csqrt%7B2%7D%20%5Ctimes%20%5Ctext%7Bsgn%7D(d)%20%5Ctimes%20%5Ctext%7Bsinh%7D%5E%7B-1%7D%5Cleft(%5Cfrac%7B%7Cd%7C%7D%7B%5Csqrt%7B2a%7D%7D%5Cright)%20=%20%5Csqrt%7B2%7D%20%5Cleft(%5Cfrac%7Bd%7D%7B%7Cd%7C%7D%5Cright)%20%5Cleft%5B%5Clog%5Cleft(%7Cd%7C%20+%20%5Csqrt%7Bd%5E2%20+%202a%7D%5Cright)%20-%20%5Cfrac%7B1%7D%7B2%7D%5Clog%5Cleft(2a%5Cright)%5Cright%5D.%0A"> This transformation has derivative <img src="https://latex.codecogs.com/png.latex?%0Ah'(d;%20a)%20=%20%5Cfrac%7B2%7D%7B%5Csqrt%7Bd%5E2%20+%202a%7D%7D,%0A"> and so <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BVar%7D(h(d))%20%5Capprox%20%5Cleft(%20h'(%5Cdelta;%20a)%20%5Cright)%5E2%20%5Ctimes%20%5Ctext%7BVar%7D(d)%20=%20%5Cfrac%7B2%7D%7B%5Cdelta%5E2%20+%202a%7D%20%5Ctimes%20%5Cfrac%7B1%7D%7BN%7D%20%5Cleft(a%20+%20%5Cfrac%7B%5Cdelta%5E2%7D%7B2%7D%5Cright)%20=%20%5Cfrac%7B1%7D%7BN%7D.%0A"></p>
<p>Figure&nbsp;3 compares the two transformation functions, with <img src="https://latex.codecogs.com/png.latex?h(z)"> in red and <img src="https://latex.codecogs.com/png.latex?z(d)"> in blue. The functions are very similar over the range [-2, 2] and only begin to diverge when <img src="https://latex.codecogs.com/png.latex?%7Cd%7C%20%3E%203">, the realm of what would typically be considered <em>very</em> large effect sizes.</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">transform_dat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R_fac =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(R_fac) <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;">fct_relabel</span>(\(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R =="</span>, x))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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;">c</span>(z, h), <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;">"stat"</span>, <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;">"val"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</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;">aes</span>(d, val, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> stat) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-7">  <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> R_fac, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_parsed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-9">  <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;">"inside"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position.inside =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-transformation-comparison" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-transformation-comparison-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://jepusto.netlify.app/posts/d-to-r-to-z/index_files/figure-html/fig-transformation-comparison-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-transformation-comparison-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: Comparison of transformation functions given by Haaf and Rouder (2023) and by Hedges and Olkin (1985)
</figcaption>
</figure>
</div>
</div>
</div>
<p>This suggests that any differences in the performance of the transformations will be driven by behavior in the extremes of the distribution and will thus be less pronounced when <img src="https://latex.codecogs.com/png.latex?N_1"> and <img src="https://latex.codecogs.com/png.latex?N_2"> are large.</p>
</section>
<section id="two-sample-simulations" class="level1 page-columns page-full">
<h1>Two-sample simulations</h1>
<p>I ran some quick simulations to look at how the sampling variance of <img src="https://latex.codecogs.com/png.latex?d">, <img src="https://latex.codecogs.com/png.latex?z(d)">, and <img src="https://latex.codecogs.com/png.latex?h(d)"> change as a function of the true average effect size <img src="https://latex.codecogs.com/png.latex?%5Cdelta">. These simulations are based on a data-generating process that is consistent with the stated assumptions of <span class="citation" data-cites="Haaf2023does">Haaf &amp; Rouder (2023)</span>, in which two independent samples are drawn from normally distributed populations with a standardized mean difference of <img src="https://latex.codecogs.com/png.latex?%5Cdelta">, with total sample size <img src="https://latex.codecogs.com/png.latex?N"> and allocation ratio of <img src="https://latex.codecogs.com/png.latex?R%20=%20N_1:N_2">. A variance-stabilizing transformation should produce an estimator with true standard error (i.e., square root of the sampling variance) that is constant, not depending on <img src="https://latex.codecogs.com/png.latex?%5Cdelta">.</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;">library</span>(simhelpers)</span>
<span id="cb4-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(future)</span>
<span id="cb4-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plan</span>(multisession)</span>
<span id="cb4-4"></span>
<span id="cb4-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate standardized mean differences d, z(d), h(d)</span></span>
<span id="cb4-6"></span>
<span id="cb4-7">r_smd <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>(reps, <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="at" style="color: #657422;
background-color: null;
font-style: inherit;">N =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) {</span>
<span id="cb4-8">  a <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> R <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (R <span 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>
<span id="cb4-9">  ncp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> delta <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> a</span>
<span id="cb4-10">  tstats <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rt</span>(reps, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncp =</span> ncp)</span>
<span id="cb4-11">  d <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tstats <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> a</span>
<span id="cb4-12">  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;">d_to_z</span>(d, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R =</span> R)</span>
<span id="cb4-13">  h <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">d_to_h</span>(d, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R =</span> R)</span>
<span id="cb4-14">  <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;">d =</span> d, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">z =</span> z, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">h =</span> h)</span>
<span id="cb4-15">}</span>
<span id="cb4-16"></span>
<span id="cb4-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Summarize mean and variance</span></span>
<span id="cb4-18">calc_M_SE <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>(dat) {</span>
<span id="cb4-19">  M <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colMeans</span>(dat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb4-20">  SE <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(dat, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, sd, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb4-21">  <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;">stat =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(dat), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">M =</span> M, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE =</span> SE)</span>
<span id="cb4-22">}</span>
<span id="cb4-23"></span>
<span id="cb4-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simulation driver</span></span>
<span id="cb4-25">sim_d_twosample <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">compose</span>(calc_M_SE, r_smd)</span>
<span id="cb4-26"></span>
<span id="cb4-27"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Parameter grid</span></span>
<span id="cb4-28">sim_grid <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb4-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb4-30">    <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;">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;">30</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>),</span>
<span id="cb4-31">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">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="cb4-32">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">delta =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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;">3</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb4-33">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb4-35">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2e4</span></span>
<span id="cb4-36">  )</span>
<span id="cb4-37"></span>
<span id="cb4-38"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Execute simulations</span></span>
<span id="cb4-39">d_twosample_res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb4-40">  sim_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">evaluate_by_row</span>(</span>
<span id="cb4-42">    sim_d_twosample, </span>
<span id="cb4-43">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">system_time =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb4-44">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">verbose =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb4-45">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-46">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb4-47">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R_fac =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(R) <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;">fct_relabel</span>(\(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R == "</span>, x, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">":1"</span>)),</span>
<span id="cb4-48">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">N_fac =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(N) <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;">fct_relabel</span>(\(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"N =="</span>, x)),</span>
<span id="cb4-49">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE_scaled =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(stat <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;">"d"</span>, SE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>((N <span 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> R <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (R <span 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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> SE)</span>
<span id="cb4-50">  )</span></code></pre></div></div>
</details>
</div>
<p>Figure&nbsp;4 shows the relationship between the parameter <img src="https://latex.codecogs.com/png.latex?%5Cdelta"> and the true standard error of the standardized mean difference estimator <img src="https://latex.codecogs.com/png.latex?d">, along with the true standard errors of the transformed effect size estimators <img src="https://latex.codecogs.com/png.latex?z(d)"> and <img src="https://latex.codecogs.com/png.latex?h(d)">. To facilitate comparison between the raw and transformed estimators, I have re-scaled the standard errors according to their values when <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20=%200"> (multiplying by <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B(N%20-%202)%20R%20/%20(R%20+%201)%5E2%7D"> for <img src="https://latex.codecogs.com/png.latex?d"> and by <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7BN%20-%202%7D"> for <img src="https://latex.codecogs.com/png.latex?z(d)"> and <img src="https://latex.codecogs.com/png.latex?h(d)">).</p>
<div class="cell page-columns page-full">
<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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(d_twosample_res) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(delta, SE_scaled, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> stat) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(N_fac <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> R_fac, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_y"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_parsed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb5-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(delta), </span>
<span id="cb5-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"True Standard Error (rescaled)"</span>, </span>
<span id="cb5-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span></span>
<span id="cb5-11">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display page-columns page-full">
<div id="fig-true-SE-twosample" class="quarto-float quarto-figure quarto-figure-center anchored page-columns page-full">
<figure class="quarto-float quarto-float-fig figure page-columns page-full">
<div aria-describedby="fig-true-SE-twosample-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca" class="page-columns page-full">
<a href="index_files/figure-html/fig-true-SE-twosample-1.png" class="lightbox page-columns page-full" data-gallery="quarto-lightbox-gallery-1" title="Figure&nbsp;4: True standard errors of untransformed d and transformed (z(d) and h(d)) effect size estimates under a two-sample homoskedastic normal model. Standard errors are rescaled so that SE = 1 when \delta = 0."><img src="https://jepusto.netlify.app/posts/d-to-r-to-z/index_files/figure-html/fig-true-SE-twosample-1.png" class="img-fluid figure-img column-body-outset" style="width:100.0%"></a>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-true-SE-twosample-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: True standard errors of untransformed <img src="https://latex.codecogs.com/png.latex?d"> and transformed (<img src="https://latex.codecogs.com/png.latex?z(d)"> and <img src="https://latex.codecogs.com/png.latex?h(d)">) effect size estimates under a two-sample homoskedastic normal model. Standard errors are rescaled so that SE = 1 when <img src="https://latex.codecogs.com/png.latex?%5Cdelta"> = 0.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Consistent with the delta method approximation, it is evident that the sampling variance of <img src="https://latex.codecogs.com/png.latex?z(d)"> is not constant, but rather is <em>decreasing</em> in <img src="https://latex.codecogs.com/png.latex?%5Cdelta">. For instance, when <img src="https://latex.codecogs.com/png.latex?R%20=%201:1"> and <img src="https://latex.codecogs.com/png.latex?N%20=%2050">, the true SE of <img src="https://latex.codecogs.com/png.latex?z(d)"> decreases to 87% of its null value as <img src="https://latex.codecogs.com/png.latex?%5Cdelta"> increases to 2. This pattern is the opposite of what we see for the raw effect size <img src="https://latex.codecogs.com/png.latex?d">, which has standard error that increases to 125% of its null value under the same conditions. Between these two, the transformed <img src="https://latex.codecogs.com/png.latex?h(d)"> effect sizes have stable SEs across the range of <img src="https://latex.codecogs.com/png.latex?%5Cdelta">. Thus, <img src="https://latex.codecogs.com/png.latex?h(d)"> is variance stabilizing but <img src="https://latex.codecogs.com/png.latex?z(d)"> is not.</p>
</section>
<section id="dichotomized-bivariate-normal-simulations" class="level1 page-columns page-full">
<h1>Dichotomized bivariate normal simulations</h1>
<p>In <span class="citation" data-cites="Pustejovsky2014converting">Pustejovsky (2014)</span>, I argued that the appropriateness of <img src="https://latex.codecogs.com/png.latex?d">-to-<img src="https://latex.codecogs.com/png.latex?r">-to-<img src="https://latex.codecogs.com/png.latex?z"> transformations and the specific form of transformation to use both depend on features of the study’s design. The two-sample normal model would be relevant for experimental studies, and it seems that the <img src="https://latex.codecogs.com/png.latex?z(d)"> transformation is not variance-stabilizing there. But perhaps it would work for other study designs and data-generating processes? In <span class="citation" data-cites="Pustejovsky2014converting">Pustejovsky (2014)</span>, I also looked at extreme groups designs and “dichotomization” designs, where a researcher is interested in the correlation between two continuous variables, one of which has been dichotomized based on some quantile of its distribution. Just out of curiosity, I will check whether the <img src="https://latex.codecogs.com/png.latex?r">-to-<img src="https://latex.codecogs.com/png.latex?z"> transformation works for a dichotomization design.</p>
<p>There are several ways to simulate a dichotomization design, which vary depending on a) whether you use a threshold defined by a population quantile or a sample quantile and b) whether, with the population quantile approach, you hold the per-group sample sizes fixed or only the total sample size (both are naturally fixed when defining the threshold based on a sample quantile). I will simulate using either population and sample quantiles, in each case while holding the total sample size fixed.<sup>1</sup> This creates a complication with small sample sizes because it’s possible to generate data where all of the observations fall above or below the threshold, so the standardized mean difference is undefined. I will handle this by just excluding such cases (i.e., conditioning on <img src="https://latex.codecogs.com/png.latex?N_1%20%3E%200"> and <img src="https://latex.codecogs.com/png.latex?N_2%20%3E%200">).</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate standardized mean differences d, z(d), h(d)</span></span>
<span id="cb6-2"></span>
<span id="cb6-3">r_bivariate <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="cb6-4">  reps, <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="at" style="color: #657422;
background-color: null;
font-style: inherit;">N =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R =</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;">threshold =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"population"</span></span>
<span id="cb6-5">) {</span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">require</span>(mvtnorm)</span>
<span id="cb6-7">  rho <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> delta <span 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>(delta<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (R <span 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> R)</span>
<span id="cb6-8">  Sigma <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rho <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diag</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rho, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>L)</span>
<span id="cb6-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;">replicate</span>(reps, {</span>
<span id="cb6-10">    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;">rmvnorm</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;">mean =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma =</span> Sigma)</span>
<span id="cb6-11">    </span>
<span id="cb6-12">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (threshold <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;">"population"</span>) {</span>
<span id="cb6-13">      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;">ifelse</span>(Z[,<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;">&lt;=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qnorm</span>(R <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (R <span 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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"B"</span>)</span>
<span id="cb6-14">      Xtb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(X)</span>
<span id="cb6-15">      <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;">any</span>(Xtb <span 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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA_real_</span>)</span>
<span id="cb6-16">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb6-17">      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;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rank</span>(Z[,<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;">&lt;=</span> N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> R <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (R <span 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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"B"</span>)</span>
<span id="cb6-18">      Xtb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(X)</span>
<span id="cb6-19">      R <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> Xtb[<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> Xtb[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]</span>
<span id="cb6-20">    }</span>
<span id="cb6-21">    </span>
<span id="cb6-22">    M <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tapply</span>(Z[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>], X, mean)</span>
<span id="cb6-23">    V <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tapply</span>(Z[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>], X, var)</span>
<span id="cb6-24">    Vpool <span class="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>((Xtb <span 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> V) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb6-25">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diff</span>(M)) <span 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>(Vpool)</span>
<span id="cb6-26">  }, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simplify =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-27">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>()</span>
<span id="cb6-28">  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;">d_to_z</span>(d, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R =</span> R)</span>
<span id="cb6-29">  h <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">d_to_h</span>(d, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R =</span> R)</span>
<span id="cb6-30">  <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;">d =</span> d, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">z =</span> z, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">h =</span> h)</span>
<span id="cb6-31">}</span>
<span id="cb6-32"></span>
<span id="cb6-33"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simulation driver</span></span>
<span id="cb6-34">sim_bivariate <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">compose</span>(calc_M_SE, r_bivariate)</span>
<span id="cb6-35"></span>
<span id="cb6-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Execute simulations</span></span>
<span id="cb6-37">d_bivariate <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb6-38">  sim_grid <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-39">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cross_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">threshold =</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;">"population"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sample"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb6-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">evaluate_by_row</span>(</span>
<span id="cb6-41">    sim_bivariate,</span>
<span id="cb6-42">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">system_time =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb6-43">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">verbose =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb6-44">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-45">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-46">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R_fac =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(R) <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;">fct_relabel</span>(\(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R == "</span>, x, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">":1"</span>)),</span>
<span id="cb6-47">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">N_fac =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(N) <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;">fct_relabel</span>(\(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"N =="</span>, x)),</span>
<span id="cb6-48">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE_scaled =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(stat <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;">"d"</span>, SE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>((N <span 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> R <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (R <span 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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> SE)</span>
<span id="cb6-49">  )</span></code></pre></div></div>
</details>
</div>
<p>The figures below show the true standard errors of <img src="https://latex.codecogs.com/png.latex?d">, <img src="https://latex.codecogs.com/png.latex?z(d)">, and <img src="https://latex.codecogs.com/png.latex?h(d)"> as a function of the standardized mean difference parameter <img src="https://latex.codecogs.com/png.latex?%5Cdelta">. They are constructed using the same layout as Figure&nbsp;4 (click on the tab for “population” or “sample” to see the results for your preferred form of dichotomization). Is <img src="https://latex.codecogs.com/png.latex?d">-to-<img src="https://latex.codecogs.com/png.latex?r">-to-<img src="https://latex.codecogs.com/png.latex?z"> variance stabilizing for the dichotomization design? In short, nope. Applying it here leads to an even stronger mean-variance relation than in the two-sample data-generating process, where larger means produce effect sizes with smaller sampling variation. But the <img src="https://latex.codecogs.com/png.latex?h(d)"> transformation does not really work either. It too exhibits a negative relation between true SE and <img src="https://latex.codecogs.com/png.latex?%5Cdelta">, though less pronounced than that of <img src="https://latex.codecogs.com/png.latex?z(d)">. The untransformed effect size <img src="https://latex.codecogs.com/png.latex?d"> still shows a positive relation between true SE and <img src="https://latex.codecogs.com/png.latex?%5Cdelta"> under some conditions, but it is weaker than under the two-sample data-generating process. For all three effect sizes, the strength of the relation changes depending on sample size—something that was not evident in the two-sample data-generating process.</p>
<div class="tabset-margin-container"></div><div class="panel-tabset page-columns page-full">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-1-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-1" aria-controls="tabset-1-1" aria-selected="true" href="">Population</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-2" aria-controls="tabset-1-2" aria-selected="false" href="">Sample</a></li></ul>
<div class="tab-content page-columns page-full">
<div id="tabset-1-1" class="tab-pane active page-columns page-full" aria-labelledby="tabset-1-1-tab">
<div class="cell page-columns page-full">
<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">d_bivariate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(threshold <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;">"population"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(delta, SE_scaled, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> stat) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(N_fac <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> R_fac, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_y"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_parsed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb7-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(delta), </span>
<span id="cb7-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"True Standard Error (rescaled)"</span>, </span>
<span id="cb7-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span></span>
<span id="cb7-14">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display page-columns page-full">
<div id="fig-true-SE-bivariate-population" class="quarto-float quarto-figure quarto-figure-center anchored page-columns page-full">
<figure class="quarto-float quarto-float-fig figure page-columns page-full">
<div aria-describedby="fig-true-SE-bivariate-population-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca" class="page-columns page-full">
<a href="index_files/figure-html/fig-true-SE-bivariate-population-1.png" class="lightbox page-columns page-full" data-gallery="quarto-lightbox-gallery-2" title="Figure&nbsp;5: True standard errors of untransformed d and transformed (z(d) and h(d)) effect size estimates under a dichotomized bivariate normal model with a population quantile threshold. Standard errors are rescaled so that SE = 1 when \delta = 0."><img src="https://jepusto.netlify.app/posts/d-to-r-to-z/index_files/figure-html/fig-true-SE-bivariate-population-1.png" class="img-fluid figure-img column-body-outset" style="width:100.0%"></a>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-true-SE-bivariate-population-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: True standard errors of untransformed <img src="https://latex.codecogs.com/png.latex?d"> and transformed (<img src="https://latex.codecogs.com/png.latex?z(d)"> and <img src="https://latex.codecogs.com/png.latex?h(d)">) effect size estimates under a dichotomized bivariate normal model with a population quantile threshold. Standard errors are rescaled so that SE = 1 when <img src="https://latex.codecogs.com/png.latex?%5Cdelta"> = 0.
</figcaption>
</figure>
</div>
</div>
</div>
</div>
<div id="tabset-1-2" class="tab-pane page-columns page-full" aria-labelledby="tabset-1-2-tab">
<div class="cell page-columns page-full">
<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_bivariate <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;">filter</span>(threshold <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;">"sample"</span>) <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;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(delta, SE_scaled, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> stat) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb8-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb8-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb8-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb8-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(N_fac <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> R_fac, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_y"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_parsed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb8-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb8-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb8-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(delta), </span>
<span id="cb8-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"True Standard Error (rescaled)"</span>, </span>
<span id="cb8-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span></span>
<span id="cb8-14">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display page-columns page-full">
<div id="fig-true-SE-bivariate-sampled" class="quarto-float quarto-figure quarto-figure-center anchored page-columns page-full">
<figure class="quarto-float quarto-float-fig figure page-columns page-full">
<div aria-describedby="fig-true-SE-bivariate-sampled-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca" class="page-columns page-full">
<a href="index_files/figure-html/fig-true-SE-bivariate-sampled-1.png" class="lightbox page-columns page-full" data-gallery="quarto-lightbox-gallery-3" title="Figure&nbsp;6: True standard errors of untransformed d and transformed (z(d) and h(d)) effect size estimates under a dichotomized bivariate normal model with a sample quantile threshold. Standard errors are rescaled so that SE = 1 when \delta = 0."><img src="https://jepusto.netlify.app/posts/d-to-r-to-z/index_files/figure-html/fig-true-SE-bivariate-sampled-1.png" class="img-fluid figure-img column-body-outset" style="width:100.0%"></a>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-true-SE-bivariate-sampled-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6: True standard errors of untransformed <img src="https://latex.codecogs.com/png.latex?d"> and transformed (<img src="https://latex.codecogs.com/png.latex?z(d)"> and <img src="https://latex.codecogs.com/png.latex?h(d)">) effect size estimates under a dichotomized bivariate normal model with a sample quantile threshold. Standard errors are rescaled so that SE = 1 when <img src="https://latex.codecogs.com/png.latex?%5Cdelta"> = 0.
</figcaption>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section id="observations" class="level1">
<h1>Observations</h1>
<p>In neither data-generating processes does the <img src="https://latex.codecogs.com/png.latex?d">-to-<img src="https://latex.codecogs.com/png.latex?r">-to-<img src="https://latex.codecogs.com/png.latex?z"> transformation lead to variance stabilization. For effect sizes that are any less than very large, the transformations appear to be quite close to linear. Here is a zoomed-in view of both transformations:</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<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">transform_dat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-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;">R_fac =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(R_fac) <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;">fct_relabel</span>(\(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"R =="</span>, x))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-3">  <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;">c</span>(z, h), <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;">"stat"</span>, <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;">"val"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</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;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb9-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(d, val, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> stat) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-8">  <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> R_fac, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_parsed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-10">  <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;">"inside"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position.inside =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="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;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</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;">seq</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-13">  <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;">y =</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;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div id="fig-transformation-comparison-zoom" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-transformation-comparison-zoom-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://jepusto.netlify.app/posts/d-to-r-to-z/index_files/figure-html/fig-transformation-comparison-zoom-1.png" class="img-fluid figure-img" width="768">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-transformation-comparison-zoom-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;7: Comparison of transformation functions given by Haaf and Rouder (2023) and by Hedges and Olkin (1985), over the range [-1.5, 1.5].
</figcaption>
</figure>
</div>
</div>
</div>
<p>It would seem that applying <em>either</em> transformation will often be inconsequential for one’s conclusions except in meta-analyses with quite large effect size estimates. In meta-analyses where the transformation is consequential, its performance seems to be contingent on the assumed data-generating process, yet meta-analysts rarely have sufficient information to assess distributional assumptions about the individual-level outcomes in primary studies.</p>
<p>A further difficulty with both of the transformations is that they depend on the allocation ratio <img src="https://latex.codecogs.com/png.latex?R">. In some meta-analyses of experimental studies, it may be that most or all primary studies have equally sized groups. But this will not always be the case. In meta-analyses where primary studies have varied sample sizes, one is then faced with the question of how to apply the transformation: should you use the correct variance-stabilizing transformation for each effect size, which then puts each primary study <em>on a different metric</em>, or should you use a common transformation (i.e., the same value of <img src="https://latex.codecogs.com/png.latex?a">) and then accept that the transformation will not stabilize all of the effects? Personally, I would opt for neither.</p>
<p>In my view, using a variance-stabilizing transformation of <img src="https://latex.codecogs.com/png.latex?d"> from an experimental study seems like extra work and more hassle than it’s worth. It adds an additional layer of technical complication to a meta-analysis, and the potential gains (in terms of variance-stabilization) are contingent on assumptions that one is rarely in position to adequately assess. Better to work with untransformed effect sizes, acknowledging the extent of the approximations involved and, when necessary, finding other ways to deal with the mean-variance relation of standardized mean differences.</p>


<!-- -->


</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" data-line-spacing="2">
<div id="ref-Azzalini2005skewnormal" class="csl-entry">
Azzalini, A. (2005). The <span class="nocase">Skew-normal Distribution</span> and <span>Related Multivariate Families</span>. <em>Scandinavian Journal of Statistics</em>, <em>32</em>(2), 159–188. <a href="https://doi.org/10.1111/j.1467-9469.2005.00426.x">https://doi.org/10.1111/j.1467-9469.2005.00426.x</a>
</div>
<div id="ref-Bartos2023robust" class="csl-entry">
Bartoš, F., Maier, M., Wagenmakers, E.-J., Doucouliagos, H., &amp; Stanley, T. D. (2023). Robust <span>Bayesian</span> meta-analysis: <span>Model</span>-averaging across complementary publication bias adjustment methods. <em>Research Synthesis Methods</em>, <em>14</em>(1), 99–116. <a href="https://doi.org/10.1002/jrsm.1594">https://doi.org/10.1002/jrsm.1594</a>
</div>
<div id="ref-Haaf2023does" class="csl-entry">
Haaf, J. M., &amp; Rouder, J. N. (2023). Does every study? <span>Implementing</span> ordinal constraint in meta-analysis. <em>Psychological Methods</em>, <em>28</em>(2), 472–487. <a href="https://doi.org/10.1037/met0000428">https://doi.org/10.1037/met0000428</a>
</div>
<div id="ref-Hedges1985statistical" class="csl-entry">
Hedges, L. V., &amp; Olkin, I. (1985). <em>Statistical methods for meta-analysis</em>. Academic Press.
</div>
<div id="ref-Pustejovsky2014converting" class="csl-entry">
Pustejovsky, J. E. (2014). Converting from d to r to z when the design uses extreme groups, dichotomization, or experimental control. <em>Psychological Methods</em>, <em>19</em>(1), 92–112. <a href="https://doi.org/10.1037/a0033788">https://doi.org/10.1037/a0033788</a>
</div>
<div id="ref-Pustejovsky2018testing" class="csl-entry">
Pustejovsky, J. E., &amp; Rodgers, M. (2018). Testing for funnel plot asymmetry of standardized mean differences. <em>Research Synthesis Methods</em>. <a href="https://doi.org/10.1002/jrsm.1332">https://doi.org/10.1002/jrsm.1332</a>
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Interested readers could modify the code to handle the further case, with population quantile thresholds and sample sizes fixed per-group, by generating observations from skew-normal distributions for each group. See <span class="citation" data-cites="Azzalini2005skewnormal">Azzalini (2005)</span> and the <code>rsn()</code> function from the <code>{sn}</code> package.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>effect-size</category>
  <category>standardized-mean-difference</category>
  <category>delta-method</category>
  <guid>https://jepusto.netlify.app/posts/d-to-r-to-z/</guid>
  <pubDate>Wed, 23 Jul 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Interactive display of simulation results with Observable.js</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/Displaying-simulation-results/</link>
  <description><![CDATA[ 





<p>Monte Carlo simulations are an essential and ubiquitous feature of my work as a statistical methodologist. With my students and collaborators, I have conducted simulations for nearly all of my methodological publications (<a href="../..\posts/Bootstrap-CI-variant-simulations/">and</a> <a href="../..\posts/Simulating-correlated-SMDs/">many</a> <a href="../..\posts/dizzy-for-d-z/">of</a> <a href="../..\posts/PET-PEESE-performance/">my</a> <a href="../..\posts/Easily-simulate-thousands-of-single-case-designs/">blog</a> <a href="../..\posts/PIR-overestimates-prevalence/">posts</a>, for that matter). For research simulations, I usually use factorial designs involving several factors, each with multiple levels, to explore a big space of model parameters and study design features.<sup>1</sup> If you’ve got the infrastructure to do the computing, then it doesn’t take much further effort to run big multifactor simulations. What does become more challenging is interpreting and making sense of all the results.</p>
<p>For analyzing simulation results, I rely heavily on graphical representations of performance measures (such as bias, root mean-squared error, coverage, etc.). Because the simulation designs are multifactor, the graphs are usually small multiples plots (i.e., facet-grids in <code>ggplot2</code> terminology). Small multiples plots can be used to represent variation in a performance measure (plotted on the vertical axis) across up to four different factors, if those factors are mapped to the horizontal axis and color (and/or stroke and/or shape), along with the horizontal and vertical facets. For designs with more than that many factors, one needs to find other ways to deal with remaining factors. That might mean creating a bunch of plots that vary across the remaining dimensions, or finding ways to marginalize across those dimensions. It can quickly become unwieldy.</p>
<p>For a long while now, I’ve been looking for easy ways to create more interactive visualizations of simulation results. Interactivity could be a big help with managing dimensionality, by letting a viewer iterate over different values of a parameter to see how a graph changes. Interactivity also seems useful and appealing as a way to focus in (even literally zoom in) on particular results. With the development of <a href="https://quarto.org/">Quarto</a> and support for tools like <a href="https://observablehq.com/documentation/cells/observable-javascript">Observable.js</a>, creating such interactive visualizations has evidently gotten much easier, even for someone (yours truly!) who knows next to nothing about web development.<br>
In this post, I’ll give an example of an interactive visualization of simulation results to illustrate what’s possible. I’ll also comment on some alternative approaches that I’ve seen and note how they differ from the approach demonstrated here.</p>
<section id="an-example" class="level1 page-columns page-full">
<h1>An example</h1>
<p>In <a href="../..\posts/Bootstrap-CI-variant-simulations/">my previous post</a> on bootstrap confidence intervals for correlation coefficients, I represented the results of a small simulation with graphs like this one:</p>
<div class="cell">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/Bootstrap-CI-variant-simulations/index_files/figure-html/coverage-graph-1.png" class="img-fluid figure-img" style="width:100.0%"></p>
</figure>
</div>
</div>
</div>
<p>This graph encodes four distinct factors:</p>
<ul>
<li>sample size on the horizontal axis</li>
<li>correlation parameter <img src="https://latex.codecogs.com/png.latex?(%5Crho)"> in the column facet</li>
<li>degrees of freedom <img src="https://latex.codecogs.com/png.latex?(%5Cnu)"> in the row facet</li>
<li>confidence interval type, represented with color.</li>
</ul>
<p>This was a fairly small simulation (by my standards) of a relatively simple problem. But even here, some interactivity would be appealing to allow a viewer to zoom in on a panel. It would also be nice to be able to focus in on just one or two of the interval types or to easily remove an interval type that you don’t care about.</p>
<p>Below is my attempt at an interactive version of this graphic. I specified the interactive tools with Observable’s <a href="https://observablehq.com/framework/inputs/">inputs library</a>. I developed the figure with Observable’s <a href="https://observablehq.com/plot/">plot library</a>. I will not get into the details of the programming because I’m still very new to both of these tools.<sup>2</sup> Suffice it to say, I more or less followed the first example in the <a href="https://quarto.org/docs/interactive/ojs/">Quarto guide to Observable</a>, then fiddled with the plotting code to make it look more like a <code>ggplot2</code> graph.</p>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb1" data-startfrom="92" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 91;"><span id="cb1-92">rho_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (rho <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;">"All"</span>)</span>
<span id="cb1-93">  <span 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.0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>]</span>
<span id="cb1-94">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [rho]</span>
<span id="cb1-95"></span>
<span id="cb1-96">rho_lab <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (rho <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;">"All"</span>)</span>
<span id="cb1-97">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span></span>
<span id="cb1-98">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> rho</span>
<span id="cb1-99">  </span>
<span id="cb1-100">df_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (df <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;">"All"</span>)</span>
<span id="cb1-101">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">32</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">48</span>]</span>
<span id="cb1-102">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [df]</span>
<span id="cb1-103"></span>
<span id="cb1-104">x_width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (rho <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;">"All"</span>)</span>
<span id="cb1-105">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">800</span></span>
<span id="cb1-106">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> (df <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;">"All"</span>) </span>
<span id="cb1-107">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span></span>
<span id="cb1-108">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">640</span></span>
<span id="cb1-109"></span>
<span id="cb1-110">y_height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (df <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;">"All"</span>)</span>
<span id="cb1-111">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">480</span></span>
<span id="cb1-112">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> (rho <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;">"All"</span>) </span>
<span id="cb1-113">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">180</span></span>
<span id="cb1-114">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">320</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-5" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb2" data-startfrom="118" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 117;"><span id="cb2-118">filtered <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">transpose</span>(dat)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(el) {</span>
<span id="cb2-119">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> types<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">includes</span>(el<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span></span>
<span id="cb2-120">    rho_val<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">includes</span>(el<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> </span>
<span id="cb2-121">    df_val<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">includes</span>(el<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> </span>
<span id="cb2-122">    (bootstraps_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> el<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bootstraps</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> el<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bootstraps</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-123">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb3" data-startfrom="127" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 126;"><span id="cb3-127">label_filtered <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> filtered<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(el) {</span>
<span id="cb3-128">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> rho_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> el<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho</span></span>
<span id="cb3-129">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="grid column-page">
<div class="g-col-3">
<div class="cell panel-input card bg-light p-2">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb4" data-startfrom="140" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 139;"><span id="cb4-140">viewof rho <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(</span>
<span id="cb4-141">      [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb4-142">      {</span>
<span id="cb4-143">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb4-144">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Correlation"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-145">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"100px"</span></span>
<span id="cb4-146">      }</span>
<span id="cb4-147">    )</span>
<span id="cb4-148"></span>
<span id="cb4-149">viewof df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(</span>
<span id="cb4-150">      [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">32</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">48</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb4-151">      {</span>
<span id="cb4-152">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"All"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb4-153">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Degrees of freedom"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-154">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"100px"</span></span>
<span id="cb4-155">      }</span>
<span id="cb4-156">    )</span>
<span id="cb4-157"></span>
<span id="cb4-158">viewof bootstraps_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(</span>
<span id="cb4-159">      [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">49</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">199</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">299</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">399</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb4-160">      {</span>
<span id="cb4-161">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb4-162">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of bootstraps"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-163">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"100px"</span></span>
<span id="cb4-164">      }</span>
<span id="cb4-165">    )</span>
<span id="cb4-166"></span>
<span id="cb4-167">viewof types <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">checkbox</span>(</span>
<span id="cb4-168">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Fisher-z"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb4-169">  {</span>
<span id="cb4-170">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Interval type"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-171">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Fisher-z"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-172">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"100px"</span></span>
<span id="cb4-173">  }</span>
<span id="cb4-174">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-4-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-4-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-4-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-4-4" data-nodetype="declaration">

</div>
</div>
</div>
</div>
</div>
<div class="g-col-9 center">
<div class="tabset-margin-container"></div><div class="panel-tabset">
<ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" id="tabset-1-1-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-1" aria-controls="tabset-1-1" aria-selected="true" href="">Coverage</a></li><li class="nav-item"><a class="nav-link" id="tabset-1-2-tab" data-bs-toggle="tab" data-bs-target="#tabset-1-2" aria-controls="tabset-1-2" aria-selected="false" href="">Interval width</a></li></ul>
<div class="tab-content">
<div id="tabset-1-1" class="tab-pane active" aria-labelledby="tabset-1-1-tab">
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb5" data-startfrom="186" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 185;"><span id="cb5-186">colorPalette <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> { <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb5-187">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Fisher-z"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#D95F02"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-188">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1B9E77"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-189">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#7570B3"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-190">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#E7298A"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-191">}}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb6" data-startfrom="195" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 194;"><span id="cb6-195">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb6-196">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">105</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-197">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.85</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-198">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fx</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">padding</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-199">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fy</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">padding</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-200">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> x_width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-201">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> y_height<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-202">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb6-203">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb6-204">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</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;">keys</span>(colorPalette)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb6-205">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">range</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</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;">values</span>(colorPalette)</span>
<span id="cb6-206">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-207">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb6-208">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5,3"</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-209">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(filtered<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;">fx</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rho"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fy</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"df"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"n"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coverage"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CI_type"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marker</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"circle"</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-210">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(label_filtered<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectLast</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fx</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rho"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fy</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"df"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"n"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coverage"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CI_type"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CI_type"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textAnchor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">dx</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>}))</span>
<span id="cb6-211">  ]</span>
<span id="cb6-212">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-6" data-nodetype="expression">

</div>
</div>
</div>
</div>
<div id="tabset-1-2" class="tab-pane" aria-labelledby="tabset-1-2-tab">
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb7" data-startfrom="219" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 218;"><span id="cb7-219">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb7-220">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">105</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-221">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-222">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fx</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">padding</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-223">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fy</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">padding</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-224">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> x_width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-225">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> y_height<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-226">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb7-227">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb7-228">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</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;">keys</span>(colorPalette)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb7-229">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">range</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</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;">values</span>(colorPalette)</span>
<span id="cb7-230">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-231">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb7-232">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-233">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(filtered<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;">fx</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rho"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fy</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"df"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"n"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CI_type"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marker</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"circle"</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-234">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(label_filtered<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectLast</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fx</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rho"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fy</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"df"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"n"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CI_type"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CI_type"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textAnchor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">dx</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>}))</span>
<span id="cb7-235">  ]</span>
<span id="cb7-236">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-7" data-nodetype="expression">

</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p>Three of the four factors in the simulation design can be interactively filtered using the inputs to the left of the plot. (For simplicity, I kept sample size mapped to the horizontal axis and always display the full range.) Setting the correlation and degrees of freedom drop-downs to specific values lets you zoom in on a specific panel of the figure, so that it’s easier to see the fine details. In addition, the interactive figure lets you change the number of bootstraps used in the bootstrap intervals, a feature of the simulation’s design not represented in the static figure from my previous post.</p>
<p>This simulation only looked at a few confidence interval methods. There are others, including other bootstrap techniques, that might be interesting to add but would make a static figure very crowded and difficult to interpret. With the addition of interactivity, adding further methods might be more appealing because you could interactively filter out methods that don’t work well or that you’re not interested in.</p>
</section>
<section id="alternatives" class="level1">
<h1>Alternatives</h1>
<p>I’m certainly not the first to hit on the idea of interactive display of simulation results, and there are a certainly other tools for doing this sort of thing. For one, I’ve seen several methodological papers that provide Shiny apps with such interactive visualizations. For example, <span class="citation" data-cites="carter2019correcting">Carter et al. (2019)</span> reported a big simulation study on publication bias-correction methods in meta-analysis. They developed a <a href="https://www.shinyapps.org/apps/metaExplorer/">Shiny app with interactive figures</a> of the simulation results and are still serving it, five years after the paper appeared. These visualizations can be very compelling, but the implementation feels a bit heavy to me—it seems like overkill to have to run a server and regenerate figures just to see graphs. In contrast, the interactive graphic above is not hosted—it’s just a static web page.</p>
<p>Of course, just creating a bunch of graphs and sticking them in a pdf doesn’t seem ideal either. In <a href="../..\publications/Adapting-methods-for-correcting-selective-reporting-bias/">this working paper with Man Chen</a> <span class="citation" data-cites="chen2024adapting">(Chen and Pustejovsky 2024)</span>, Man hit on the idea of organizing all our graphs using tabsets to make it a bit easier to navigate all the different conditions in a big simulation. You can see the results in the <a href="https://osf.io/uja37">supplementary materials</a><sup>3</sup>. I think it took a fair amount of copy-pasta to create these graphs, but it seems like the sort of thing that could be automated.</p>
<p>Yihui Xie has a <a href="https://yihui.org/en/2023/02/js-shiny/">blog post</a> demonstrating a fairly simple javascript technique that could be used to accomplish much the same thing as Man’s tabsets or my interactive graphs. The core idea is to generate a <em>bunch</em> of images, covering every possible scenario the viewer might care to see, and then use simple interactive elements to determine which image gets viewed. This seems like a pretty useful approach, and one that could be automated for use in Rmarkdown- or Quarto-generated html. It seems more useful when the total number of possible graphs is fairly small.<sup>4</sup> For visualizations with more options (and thus a greater number of unique possible states), truly interactive graphics like the one above seem like the way to go.</p>
</section>
<section id="where-and-wherefore" class="level1">
<h1>Where and wherefore?</h1>
<p>Creating this interactive graph took some fiddling, but the process was quick enough that I could certainly see using this approach for future projects (not just blog posts). It will probably take a bit of experimentation to figure out exactly where this fits into my research process. Is it just an internal tool to help our team to explore simulation results? Or is it something public-facing and connected to a manuscript? If the latter, where do we put it? If the academic journal model weren’t so tied to pdf, I would love to just plop one (or more) of these into a manuscript and let readers explore our results for as long as they care to. Short of that, I suppose these graphs could be part of supplementary materials. I could also see using interactive graphs like this as part of conference presentations or teaching.</p>


<!-- -->


</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-carter2019correcting" class="csl-entry">
Carter, Evan C, Felix D. Schönbrodt, Will M Gervais, and Joseph Hilgard. 2019. <span>“Correcting for Bias in Psychology: A Comparison of Meta-Analytic Methods.”</span> <em>Advances in Methods and Practices in Psychological Science</em> 2 (2). <a href="https://doi.org/10.1177/2515245919847196">https://doi.org/10.1177/2515245919847196</a>.
</div>
<div id="ref-chen2024adapting" class="csl-entry">
Chen, Man, and James E Pustejovsky. 2024. <span>“Adapting Methods for Correcting Selective Reporting Bias in Meta-Analysis of Dependent Effect Sizes.”</span> MetaArXiv. <a href="https://doi.org/10.31222/osf.io/jq52s">https://doi.org/10.31222/osf.io/jq52s</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>It’s not a Pusto lab simulation if it doesn’t have at least 1200 conditions in it, we say around here.↩︎</p></li>
<li id="fn2"><p>If you’d like to inspect my code just click on the <code>&lt;/&gt;CODE</code> drop-down in the header of the post and select <code>VIEW SOURCE</code>.↩︎</p></li>
<li id="fn3"><p>You’ll need to download the html to view the graphs↩︎</p></li>
<li id="fn4"><p>The interactive figure above includes 6 settings for the correlation, 5 settings for the degrees of freedom, 6 settings for the number of bootstraps, and <img src="https://latex.codecogs.com/png.latex?2%5E4%20=%2016"> settings for the combination of methods to display. In all, that comes to 2880 unique combinations of settings, times two different graphs, for a total of 5760 graphs that would need to be generated following Yihui’s approach. Each image is 69.4Kb, so the total size of the files for every possible iteration would come to 390.3Mb.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>simulation</category>
  <category>programming</category>
  <guid>https://jepusto.netlify.app/posts/Displaying-simulation-results/</guid>
  <pubDate>Sun, 19 Jan 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>A bigger simulation of bootstrap confidence interval variations</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/Bootstrap-CI-variant-simulations/</link>
  <description><![CDATA[ 





<p>In my <a href="../..\posts/Bootstrap-CI-variations/">previous post</a>, I demonstrated some new brand-new additions to the <a href="https://meghapsimatrix.github.io/simhelpers/"><code>simhelpers</code> package</a>: utilities for calculating bootstrap confidence intervals. That post walked through validating the functions against the results of other packages and showing how they can be used to extrapolate confidence interval coverage rates using fewer bootstraps than one would want to see for a real data analysis. In the course of illustrating the functions, I set up a small simulation study (with just one set of parameters) to show how the extrapolation technique works. In this post, I’m going to expand these simulations across a bigger set of conditions in a multi-factor simulation. This exercise is mostly an excuse to showcase some of the other useful features of <code>simhelpers</code>—especially the <code>bundle_sim()</code> function for creating simulation drivers and the <code>evaluate_by_row()</code> function for executing simulations across a grid of parameter values.</p>
<p>The goal of the simulation is to evaluate how the bootstrap CIs work for estimating the Pearson correlation from a bivariate <img src="https://latex.codecogs.com/png.latex?t"> data-generating process. I will compare the performance of four different confidence intervals for the correlation coefficient: 1) the Fisher-z interval, which is derived assuming bivariate normality of the measurements; 2) a percentile bootstrap CI; 3) a studentized bootstrap CI; and 4) Efron’s bias-corrected-and-accelerated bootstrap CI. For the bootstrap intervals, I will use my implementation of the <span class="citation" data-cites="boos2000MonteCarloEvaluation">Boos &amp; Zhang (2000)</span> extrapolation technique (which <a href="../..\posts/Simulating-bootstrap-CIs/">I described in much greater detail here</a>).</p>
<div class="cell">
<details open="" 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;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(simhelpers)</span></code></pre></div></div>
</details>
</div>
<section id="data-generating-process" class="level1">
<h1>Data-generating process</h1>
<p>As a more-or-less arbitrary data-generating process, I’ll look at a bivariate central <img src="https://latex.codecogs.com/png.latex?t"> distribution with scale matrix <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%5CSigma%20=%20%5Cleft%5B%5Cbegin%7Barray%7D%7Bcc%7D%201%20%5C%20%5Crho%20%5C%5C%20%5Crho%20%5C%201%20%5Cend%7Barray%7D%5Cright%5D"> and degrees of freedom <img src="https://latex.codecogs.com/png.latex?%5Cnu">: <img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(%5Cbegin%7Barray%7D%7Bc%7D%20X_1%20%5C%5C%20X_2%20%5Cend%7Barray%7D%5Cright)%20%5Csim%20t_%7BMV%7D%20%5Cleft(%20%5Cleft%5B%5Cbegin%7Barray%7D%7Bc%7D%200%20%5C%5C%200%20%5Cend%7Barray%7D%5Cright%5D,%20%5Cleft%5B%5Cbegin%7Barray%7D%7Bcc%7D%201%20%5C%20%5Crho%20%5C%5C%20%5Crho%20%5C%201%20%5Cend%7Barray%7D%5Cright%5D,%20%5Cnu%20%20%5Cright).%0A"> The scale matrix of the multivariate <img src="https://latex.codecogs.com/png.latex?t"> is not exactly the same as its covariance, but <img src="https://latex.codecogs.com/png.latex?%5Crho"> nonetheless corresponds to the correlation between <img src="https://latex.codecogs.com/png.latex?X_1"> and <img src="https://latex.codecogs.com/png.latex?X_2">. For purposes of simulating data, I’ve fixed the means to zero and the diagonals of the scale matrix to 1 because they should not affect the distribution of the sample correlation.</p>
<p>Here’s a data-generating function that returns randomly generated samples based on the bivariate <img src="https://latex.codecogs.com/png.latex?t"> model:</p>
<div class="cell">
<details open="" 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">r_t_bi <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, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho =</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;">df =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>) {</span>
<span id="cb2-2">  Sigma <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rho <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diag</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rho, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb2-3">  mvtnorm<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rmvt</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;">sigma =</span> Sigma, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> df)</span>
<span id="cb2-4">}</span>
<span id="cb2-5"></span>
<span id="cb2-6">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r_t_bi</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;">rho =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb2-7">dat</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>           [,1]       [,2]
[1,] -1.3127111 -1.9011068
[2,] -0.5437800 -0.3590287
[3,] -0.9715497 -0.4678720
[4,] -0.8036683 -1.4880140
[5,] -0.4911120 -0.2064628
[6,] -0.5032190 -0.7707798</code></pre>
</div>
</div>
</section>
<section id="estimation-methods" class="level1">
<h1>Estimation methods</h1>
<p>Following along the same lines as my previous post, I will look at several different confidence intervals. First, I’ll use an interval based on Fisher’s z-transformation, which is both normalizing and variance-stabilizing (so that the standard error of the point estimator does not depend on the parameter) when the data come from a bivariate normal distribution. Let <img src="https://latex.codecogs.com/png.latex?r"> denote the usual sample correlation based on a sample of <img src="https://latex.codecogs.com/png.latex?n"> observations and let <img src="https://latex.codecogs.com/png.latex?z(r)%20=%20%5Cfrac%7B1%7D%7B2%7D%5Cln%5Cleft(%5Cfrac%7B1%20+%20r%7D%7B1%20-%20r%7D%5Cright)%20=%20%5Ctext%7Batan%7D%5E%7B-1%7D(r)"> be the Fisher transformation function, with inverse <img src="https://latex.codecogs.com/png.latex?r(z)%20=%20%5Ctext%7Batan%7D(z)%20=%20%5Cfrac%7Be%5E%7B2z%7D%20-%201%7D%7Be%5E%7B2z%7D%20+%201%7D">. The <img src="https://latex.codecogs.com/png.latex?1%20-%202%5Calpha">-level Fisher-z interval is given by <img src="https://latex.codecogs.com/png.latex?%0A%5Cleft%5B%5Ctext%7Batan%7D%5Cleft(z(r)%20-%20%5Cfrac%7B%5CPhi%5E%7B-1%7D(1%20-%20%5Calpha)%7D%7B%5Csqrt%7Bn%20-%203%7D%7D%5Cright),%20%5C%20%5Ctext%7Batan%7D%5Cleft(z(r)%20+%20%5Cfrac%7B%5CPhi%5E%7B-1%7D(1%20-%20%5Calpha)%7D%7B%5Csqrt%7Bn%20-%203%7D%7D%5Cright)%20%5Cright%5D.%0A"> This interval is based on a bivariate normality assumption that isn’t actually consistent with the data-generating process, so I would not expect it to have the correct coverage unless the degrees of freedom are large enough that the bivariate <img src="https://latex.codecogs.com/png.latex?t"> approaches the bivariate normal.</p>
<p>In addition to this interval, I’ll look at several different bootstrap intervals, including the usual percentile interval, a studentized interval, and a bias-corrected-and-accelerated interval. The percentile interval is approximate so will not necessarily have exactly nominal coverage, but its coverage rate should approach the nominal level as the sample size gets bigger. The BCa interval should have second-order accurate coverage <span class="citation" data-cites="efron1987better">(Efron, 1987)</span> and so one would expect its coverage rate to approach the nominal level more quickly than the percentile interval. With all these intervals, I’ll use the the <span class="citation" data-cites="boos2000MonteCarloEvaluation">Boos &amp; Zhang (2000)</span> extrapolation technique to estimate the coverage level, for which I’ll need to calculate and keep track of intervals based on <img src="https://latex.codecogs.com/png.latex?B%20=%2049,%2099,%20199,%20299">, and <img src="https://latex.codecogs.com/png.latex?399"> bootstrap replicates.</p>
<p>The BCa interval involves making small tweaks to the percentile interval based on an estimate of bias and an estimate of an acceleration constant that is a function of the empirical influence values. I’m going to keep track of the bias correction estimate and the acceleration correction estimates, so that I can understand how noisy they are.</p>
<p>Here’s a function that calculates the point estimator <img src="https://latex.codecogs.com/png.latex?r">, the Fisher-z interval, the empirical influence values, and then the bootstrap CIs.</p>
<div class="cell">
<details open="" 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">cor_CI <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="cb4-2">  dat, </span>
<span id="cb4-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</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;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>),</span>
<span id="cb4-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_vals =</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;">49</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">199</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">299</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">399</span>)</span>
<span id="cb4-5">) {</span>
<span id="cb4-6">  </span>
<span id="cb4-7">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># point estimate</span></span>
<span id="cb4-8">  r_est <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cor</span>(dat[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], dat[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb4-9">  N <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(dat)</span>
<span id="cb4-10">  SE_r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</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> r_est<span 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> (N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb4-11">  </span>
<span id="cb4-12">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Fisher z CI</span></span>
<span id="cb4-13">  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;">atanh</span>(r_est)</span>
<span id="cb4-14">  SE_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;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(N <span 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="cb4-15">  CI_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;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="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;">qnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> SE_z</span>
<span id="cb4-16"></span>
<span id="cb4-17">  </span>
<span id="cb4-18">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># empirical influence if needed</span></span>
<span id="cb4-19">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> CI_type) {</span>
<span id="cb4-20">    jacks <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sapply</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>N, \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cor</span>(dat[<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>x,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], dat[<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>x,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]))</span>
<span id="cb4-21">    inf_vals <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> r_est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> jacks</span>
<span id="cb4-22">  } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb4-23">    inf_vals <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb4-24">  }</span>
<span id="cb4-25">  </span>
<span id="cb4-26">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># bootstrap samples</span></span>
<span id="cb4-27">  r_boot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">replicate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(B_vals), {</span>
<span id="cb4-28">    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;">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>N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> N)</span>
<span id="cb4-29">    r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cor</span>(dat[i,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], dat[i,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb4-30">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(r, <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;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> r<span 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> (N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)))</span>
<span id="cb4-31">  })</span>
<span id="cb4-32">  </span>
<span id="cb4-33">  bs_CIs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> simhelpers<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootstrap_CIs</span>(</span>
<span id="cb4-34">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_est =</span> r_boot[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,],</span>
<span id="cb4-35">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_se =</span> r_boot[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,],</span>
<span id="cb4-36">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> r_est,</span>
<span id="cb4-37">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> SE_r,</span>
<span id="cb4-38">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">influence =</span> inf_vals,</span>
<span id="cb4-39">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</span> CI_type,</span>
<span id="cb4-40">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_vals =</span> B_vals,</span>
<span id="cb4-41">    <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;">"wide-list"</span></span>
<span id="cb4-42">  )</span>
<span id="cb4-43"></span>
<span id="cb4-44">  tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb4-45">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> r_est,</span>
<span id="cb4-46">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE =</span> SE_r,</span>
<span id="cb4-47">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lo =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tanh</span>(CI_z[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]),</span>
<span id="cb4-48">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hi =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tanh</span>(CI_z[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]),</span>
<span id="cb4-49">    <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;">qnorm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(r_boot <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> r_est)),</span>
<span id="cb4-50">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">a =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(inf_vals<span 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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(inf_vals<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>),</span>
<span id="cb4-51">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bs_CIs =</span> bs_CIs</span>
<span id="cb4-52">  )</span>
<span id="cb4-53">}</span>
<span id="cb4-54"></span>
<span id="cb4-55">res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cor_CI</span>(dat)</span>
<span id="cb4-56">res</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 1 × 7
      r    SE     lo    hi     w     a bs_CIs      
  &lt;dbl&gt; &lt;dbl&gt;  &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;btstr_CI&gt;  
1 0.741 0.202 -0.177 0.970 0.581 0.111 &lt;df [5 × 7]&gt;</code></pre>
</div>
</div>
<p>The <code>bundle_sim</code> function is a convenient way to combine the data-generating function and the estimation function into one. It wraps the composition of both functions in a call to <code>replicate()</code>, so that I can repeat the steps of generating data and analyzing the data to my heart’s content:</p>
<div class="cell">
<details open="" 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">sim_cor <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bundle_sim</span>(</span>
<span id="cb6-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">f_generate =</span> r_t_bi, </span>
<span id="cb6-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">f_analyze =</span> cor_CI</span>
<span id="cb6-4">)</span></code></pre></div></div>
</details>
</div>
<p>The result is one function, <code>sim_cor()</code>, with the all of the arguments from the data-generating function and analysis function combined and with an additional argument (called <code>reps</code>) to specify the number of times to repeat the whole thing:</p>
<div class="cell">
<details open="" 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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">args</span>(sim_cor)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>function (reps, n, rho = 0, df = 8, CI_type = c("percentile", 
    "student", "BCa"), B_vals = c(49, 99, 199, 299, 399), seed = NA_integer_) 
NULL</code></pre>
</div>
</div>
<p>To illustrate how it works, I can call <code>sim_cor()</code> to generate five replications of the generate-and-analyze steps:</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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">five_reps <span class="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_cor</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span>
<span id="cb9-2">five_reps</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 5 × 7
      r    SE    lo    hi     w        a bs_CIs      
  &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;    &lt;dbl&gt; &lt;btstr_CI&gt;  
1 0.543 0.162 0.133 0.795 0.680 -0.00590 &lt;df [5 × 7]&gt;
2 0.735 0.106 0.433 0.888 0.529  0.0188  &lt;df [5 × 7]&gt;
3 0.623 0.140 0.250 0.835 0.676  0.0284  &lt;df [5 × 7]&gt;
4 0.672 0.126 0.326 0.859 0.688  0.0675  &lt;df [5 × 7]&gt;
5 0.723 0.110 0.412 0.883 0.615  0.0284  &lt;df [5 × 7]&gt;</code></pre>
</div>
</div>
</section>
<section id="performance-measures" class="level1">
<h1>Performance measures</h1>
<p>After generating many sets of results, I’ll need to summarize across replications to evaluate the coverage rates of each set of confidence intervals. In my previous post, I did this with a bit of <code>dplyr</code> code. Because I’m going to run the simulation across multiple conditions with different parameter values, it will be helpful to have a function so that I can re-use it later. Here’s such a function, which has basically the same content as the code chunk from my previous post:</p>
<div class="cell">
<details open="" 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">eval_performance <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>(dat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho =</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;">B_target =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>) {</span>
<span id="cb11-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">require</span>(simhelpers, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quietly =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb11-3">  </span>
<span id="cb11-4">  dat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb11-5">    dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb11-6">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">calc_absolute</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimates =</span> r, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_param =</span> rho, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">criteria =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bias"</span>),</span>
<span id="cb11-7">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">calc_coverage</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower_bound =</span> lo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper_bound =</span> hi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_param =</span> rho),</span>
<span id="cb11-8">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extrapolate_coverage</span>(</span>
<span id="cb11-9">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_subsamples =</span> bs_CIs, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_param =</span> rho, </span>
<span id="cb11-10">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_target =</span> B_target,</span>
<span id="cb11-11">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nested =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"long"</span></span>
<span id="cb11-12">      ),</span>
<span id="cb11-13">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(w, a), <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;">M =</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), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SD =</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;">sd</span>(.x)))</span>
<span id="cb11-14">    )</span>
<span id="cb11-15">}</span>
<span id="cb11-16"></span>
<span id="cb11-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">eval_performance</span>(five_reps, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 1 × 18
  K_absolute   bias bias_mcse K_coverage coverage coverage_mcse width width_mcse
       &lt;int&gt;  &lt;dbl&gt;     &lt;dbl&gt;      &lt;int&gt;    &lt;dbl&gt;         &lt;dbl&gt; &lt;dbl&gt;      &lt;dbl&gt;
1          5 -0.141    0.0351          5      0.8         0.179 0.541     0.0380
# ℹ 10 more variables: K_boot_coverage &lt;int&gt;, bootstraps &lt;list&gt;,
#   boot_coverage &lt;list&gt;, boot_coverage_mcse &lt;list&gt;, boot_width &lt;list&gt;,
#   boot_width_mcse &lt;list&gt;, w_M &lt;dbl&gt;, w_SD &lt;dbl&gt;, a_M &lt;dbl&gt;, a_SD &lt;dbl&gt;</code></pre>
</div>
</div>
<p>The function that I created earlier with <code>bundle_sim()</code> can be further enhanced by wrapping in <code>eval_performance()</code>. I’ll just revise my earlier <code>sim_cor()</code> to add it:</p>
<div class="cell">
<details open="" 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">sim_cor <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bundle_sim</span>(</span>
<span id="cb13-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">f_generate =</span> r_t_bi, </span>
<span id="cb13-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">f_analyze =</span> cor_CI,</span>
<span id="cb13-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">f_summarize =</span> eval_performance</span>
<span id="cb13-5">)</span></code></pre></div></div>
</details>
</div>
<p>The result is a “simulation driver” function, which takes model parameters as inputs, runs a full simulation, and returns a dataset with performance measures:</p>
<div class="cell">
<details open="" 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;">sim_cor</span>(</span>
<span id="cb14-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span id="cb14-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, </span>
<span id="cb14-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, </span>
<span id="cb14-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>,</span>
<span id="cb14-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span></span>
<span id="cb14-7">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 1 × 18
  K_absolute     bias bias_mcse K_coverage coverage coverage_mcse width
       &lt;int&gt;    &lt;dbl&gt;     &lt;dbl&gt;      &lt;int&gt;    &lt;dbl&gt;         &lt;dbl&gt; &lt;dbl&gt;
1         10 -0.00667    0.0364         10      0.9        0.0949 0.374
# ℹ 11 more variables: width_mcse &lt;dbl&gt;, K_boot_coverage &lt;int&gt;,
#   bootstraps &lt;list&gt;, boot_coverage &lt;list&gt;, boot_coverage_mcse &lt;list&gt;,
#   boot_width &lt;list&gt;, boot_width_mcse &lt;list&gt;, w_M &lt;dbl&gt;, w_SD &lt;dbl&gt;,
#   a_M &lt;dbl&gt;, a_SD &lt;dbl&gt;</code></pre>
</div>
</div>
<p>To examine the raw results without running the performance summaries, just set the <code>summarize</code> argument to <code>FALSE</code>:</p>
<div class="cell">
<details open="" 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;">sim_cor</span>(</span>
<span id="cb16-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span id="cb16-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, </span>
<span id="cb16-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>, </span>
<span id="cb16-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>,</span>
<span id="cb16-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>,</span>
<span id="cb16-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">summarize =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span></span>
<span id="cb16-8">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 10 × 7
       r     SE    lo    hi     w        a bs_CIs      
   &lt;dbl&gt;  &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;    &lt;dbl&gt; &lt;btstr_CI&gt;  
 1 0.780 0.0800 0.556 0.898 0.645  0.0129  &lt;df [5 × 3]&gt;
 2 0.526 0.148  0.165 0.763 0.645 -0.0389  &lt;df [5 × 3]&gt;
 3 0.762 0.0855 0.525 0.889 0.661  0.0626  &lt;df [5 × 3]&gt;
 4 0.825 0.0652 0.638 0.920 0.665  0.0120  &lt;df [5 × 3]&gt;
 5 0.925 0.0294 0.836 0.967 0.716  0.105   &lt;df [5 × 3]&gt;
 6 0.775 0.0816 0.547 0.896 0.573 -0.0524  &lt;df [5 × 3]&gt;
 7 0.769 0.0835 0.537 0.893 0.676 -0.0401  &lt;df [5 × 3]&gt;
 8 0.878 0.0467 0.740 0.945 0.669  0.0384  &lt;df [5 × 3]&gt;
 9 0.831 0.0631 0.650 0.923 0.634  0.00181 &lt;df [5 × 3]&gt;
10 0.738 0.0930 0.483 0.877 0.661 -0.0162  &lt;df [5 × 3]&gt;</code></pre>
</div>
</div>
</section>
<section id="parameters-to-examine" class="level1">
<h1>Parameters to examine</h1>
<p>Now that I’ve got a simulation driver, I’m in position to run simulations across a wider set of conditions. For multifactor simulations, I like to instantiate the full set of conditions in a dataset, which I then process to actually do the computation. For these simulations, the model parameters are the true correlation, <img src="https://latex.codecogs.com/png.latex?%5Crho">, and the degrees of freedom, <img src="https://latex.codecogs.com/png.latex?%5Cnu">; the only design parameter is <img src="https://latex.codecogs.com/png.latex?n">, the sample size. For <img src="https://latex.codecogs.com/png.latex?%5Crho">, I’ll look at values between 0.0 and 0.8 just to cover most of the range of possibilities. (I don’t need to look at negative correlations because the statistics involved here are all symmetric with respect to the sign of <img src="https://latex.codecogs.com/png.latex?%5Crho">.) For degrees of freedom, I’ll look at a fairly small value of <img src="https://latex.codecogs.com/png.latex?%5Cnu%20=%208">, an intermediate value of <img src="https://latex.codecogs.com/png.latex?%5Cnu%20=%2016">, and a larger value of <img src="https://latex.codecogs.com/png.latex?%5Cnu%20=%2032">, the last of which should be fairly close to a bivariate normal distribution. For sake of complete overkill, I guess I’ll also throw in <img src="https://latex.codecogs.com/png.latex?%5Cnu%20=48">, which should be almost identical to a bivariate normal distribution. It’s useful to evaluate such a condition because the the Fisher z interval is known to be exact under bivariate normality, so we can validate the simulation set-up by verifying that the coverage levels are consistent with theory here. For the choice of sample sizes to examine, I’m interested in understanding how the coverage of the bootstrap intervals changes as sample size increases, so I will look at a fairly fine grid of values between a very small sample size of <img src="https://latex.codecogs.com/png.latex?n%20=%2010"> and a more moderate sample size of <img src="https://latex.codecogs.com/png.latex?n%20=%20100">. Here’s how I create a dataset of simulation conditions:</p>
<div class="cell">
<details open="" 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">params <span class="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="cb18-2">  <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;">seq</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;">100</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>),</span>
<span id="cb18-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>),</span>
<span id="cb18-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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;">16</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">32</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">48</span>)</span>
<span id="cb18-5">)</span>
<span id="cb18-6"></span>
<span id="cb18-7">params</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 200 × 3
       n   rho    df
   &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
 1    10   0       8
 2    10   0      16
 3    10   0      32
 4    10   0      48
 5    10   0.2     8
 6    10   0.2    16
 7    10   0.2    32
 8    10   0.2    48
 9    10   0.4     8
10    10   0.4    16
# ℹ 190 more rows</code></pre>
</div>
</div>
</section>
<section id="execute" class="level1">
<h1>Execute</h1>
<p>With all these components in place, it’s time to start computing. The task here is to run the <code>sim_cor()</code> simulation driver function on the set of parameters in each row of <code>params</code>. In the tidyverse idiom, one would normally do this with <code>purrr::pmap()</code> or one of its variants. The <code>simhelpers</code> package includes a function <code>evaluate_by_row()</code> that accomplishes the same thing. It’s more or less a wrapper to <code>pmap()</code>, with a few little extra touches. Instead of <code>purrr::pmap()</code>, it uses <code>furrr::future_pmap()</code> to enable parallel computing via <code>future</code> the package. It also keeps track of total compute time and does a little bit of tidying up the simulation results after running everything. Here is how I execute the simulation with <code>evaluate_by_row()</code>:</p>
<div class="cell">
<details open="" 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"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># enable parallel computing</span></span>
<span id="cb20-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(future)</span>
<span id="cb20-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(furrr)</span>
<span id="cb20-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plan</span>(multisession, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">workers =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>L)</span>
<span id="cb20-5"></span>
<span id="cb20-6"><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;">20250117</span>)</span>
<span id="cb20-7"></span>
<span id="cb20-8">res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">evaluate_by_row</span>(</span>
<span id="cb20-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">params =</span> params,</span>
<span id="cb20-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sim_function =</span> sim_cor,</span>
<span id="cb20-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4000</span>,</span>
<span id="cb20-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</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;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>),</span>
<span id="cb20-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_vals =</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;">49</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">199</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">299</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">399</span>),</span>
<span id="cb20-14">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_target =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>,</span>
<span id="cb20-15">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.options =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">furrr_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb20-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.progress =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb20-17">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>   user  system elapsed 
   4.13    0.57 4869.19 </code></pre>
</div>
</div>
</section>
<section id="results" class="level1 page-columns page-full">
<h1>Results</h1>
<p>After a little further data-cleaning on the back end, we can see how the coverage rates of different intervals compare to each other across the full range of parameter values and sample sizes. Here’s a graph of the simulated coverage rates as a function of <img src="https://latex.codecogs.com/png.latex?n">:</p>
<div class="cell page-columns page-full">
<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">Fisher_res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb22-2">  res <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb22-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(n, rho, df, coverage, width) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb22-4">  <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;">CI_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Fisher-z"</span>)</span>
<span id="cb22-5"></span>
<span id="cb22-6">boot_res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb22-7">  res <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb22-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(n, rho, df, bootstraps, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">coverage =</span> boot_coverage, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> boot_width) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb22-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(bootstraps, coverage, width)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb22-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(bootstraps <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb22-11">  <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>bootstraps)</span>
<span id="cb22-12"></span>
<span id="cb22-13">CI_res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb22-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(Fisher_res, boot_res) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb22-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb22-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho_lab =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rho =="</span>, rho),</span>
<span id="cb22-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df_lab =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(df, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">32</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">48</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;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"nu =="</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;">16</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">32</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">48</span>))),</span>
<span id="cb22-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(CI_type, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Fisher-z"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>))</span>
<span id="cb22-19">  )</span>
<span id="cb22-20"></span>
<span id="cb22-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(CI_res) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb22-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(n, coverage, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> CI_type) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb22-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(df_lab <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> rho_lab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_parsed"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb22-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</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;">20</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb22-25">  <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;">limits =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.87</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0</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;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb22-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</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="cb22-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb22-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb22-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb22-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"n"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coverage rate"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display page-columns page-full">
<div class="page-columns page-full">
<figure class="figure page-columns page-full">
<p class="page-columns page-full"><a href="index_files/figure-html/coverage-graph-1.png" class="lightbox page-columns page-full" data-gallery="quarto-lightbox-gallery-1"><img src="https://jepusto.netlify.app/posts/Bootstrap-CI-variant-simulations/index_files/figure-html/coverage-graph-1.png" class="img-fluid figure-img column-body-outset" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
<p>A few observations here:</p>
<ul>
<li>For small degrees of freedom, the Fisher-z interval has below-nominal coverage and appears to degrade further as sample size gets better. This makes sense because the interval is derived under a bivariate normal model that is not consistent with the actual data-generating process unless the degrees of freedom are large. With larger degrees of freedom <img src="https://latex.codecogs.com/png.latex?(%5Cnu%20=%2032)">, the Fisher-z has almost exactly nominal coverage.</li>
<li>Across degrees of freedom and true correlations, the percentile interval has below-nominal coverage for the smaller sample sizes but appears to get steadily better as sample size increases.</li>
<li>The studentized interval performs remarkably well, with coverage very close to nominal even at very small sample sizes.</li>
<li>Rather curiously, the BCa interval pretty consistently has worse coverage than the (simpler) percentile interval, even for larger sample sizes. This is counter-intuitive to me because the BCa interval is supposed to have second-order accurate coverage <span class="citation" data-cites="efron1987better">(Efron, 1987)</span> whereas the percentile interval is only first-order accurate. The upshot of this is that one would expect the coverage rate of the BCa interval to improve more quickly than the percentile interval, but that doesn’t seem to be the case here.</li>
</ul>
<p>For sake of completeness, here is a graph of the average width of each type of CI:</p>
<div class="cell page-columns page-full">
<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;">ggplot</span>(CI_res) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb23-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(n, width, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> CI_type) <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;">facet_grid</span>(df_lab <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> rho_lab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_parsed"</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;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</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;">20</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb23-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</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;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb23-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_limits</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb23-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb23-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb23-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb23-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb23-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"n"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Average interval width"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display page-columns page-full">
<div class="page-columns page-full">
<figure class="figure page-columns page-full">
<p class="page-columns page-full"><a href="index_files/figure-html/width-graph-1.png" class="lightbox page-columns page-full" data-gallery="quarto-lightbox-gallery-2"><img src="https://jepusto.netlify.app/posts/Bootstrap-CI-variant-simulations/index_files/figure-html/width-graph-1.png" class="img-fluid figure-img column-body-outset" style="width:100.0%"></a></p>
</figure>
</div>
</div>
</div>
<p>At the smallest sample sizes, all of the intervals are quite wide and the studentized interval is extremely so (I’ve truncated the graph at a width of 1.0, so the studentized interval goes off the scale when <img src="https://latex.codecogs.com/png.latex?n%20=%2010">). The other intervals are all pretty similar in width, and nearly identically so when the degrees of freedom get large enough.</p>
</section>
<section id="thoughts" class="level1">
<h1>Thoughts</h1>
<p>I think the most intriguing thing about these simulation results is the BCa interval seems to generally be <em>worse</em> than a regular percentile interval—not the refinement that one might expect. I’m not sure why that is. It could have something to do with how the acceleration constant is calculated. I’ve computed it with a jackknife approximation, but there are alternatives (such as using an infinitesimal jackknife, or just direct calculation if one is willing to impose a distributional assumption) which might work better. There are also some other interval construction methods that I haven’t bothered to look at here. For instance, <span class="citation" data-cites="hu2020Interval">Hu et al. (2020)</span> proposed two intervals based on non-parametric empirical likelihood methods. They reported their own set of simulations to evaluate their proposed intervals against the Fisher-z interval, but they didn’t look at bootstrap-based intervals. Their work could be the basis for a range of extensions to the simulation reported here, such as</p>
<ul>
<li>Adding their empirical likelihood intervals to the set of estimators examined here—how do they do compared to nonparametric bootstraps?</li>
<li>Evaluating the Fisher-z and bootstrap intervals under the non-normal data-generating processes that <span class="citation" data-cites="hu2020Interval">Hu et al. (2020)</span> examined. Does the performance of the bootstrap intervals change in meaningful ways under a bivariate exponential distribution?</li>
</ul>
<p>The main point of this post isn’t so much to get into the weeds of interval estimators for the correlation coefficient. Rather, it was to demonstrate an approach to programming simulations of bootstrap methods and showcase some of the tools available in <code>simhelpers</code> that can help with this process. The schematic I’ve followed for programming the simulations is discussed in much greater detail in <a href="https://jepusto.github.io/Designing-Simulations-in-R/">my book with Luke Miratrix</a> on writing simulations.</p>
<div class="callout callout-style-simple callout-note no-icon callout-titled" title="Session Information">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon no-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Session Information
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<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">sessioninfo<span 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.3.1 (2023-06-16 ucrt)
 os       Windows 10 x64 (build 19045)
 system   x86_64, mingw32
 ui       RTerm
 language (EN)
 collate  English_United States.utf8
 ctype    English_United States.utf8
 tz       America/Chicago
 date     2025-01-18
 pandoc   3.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────
 ! package     * version date (UTC) lib source
 P cli           3.6.3   2024-06-21 [?] RSPM (R 4.3.0)
 P colorspace    2.1-1   2024-07-26 [?] RSPM (R 4.3.0)
 P digest        0.6.37  2024-08-19 [?] RSPM (R 4.3.0)
 P dplyr       * 1.1.4   2023-11-17 [?] RSPM
 P evaluate      0.23    2023-11-01 [?] RSPM (R 4.3.0)
 P farver        2.1.2   2024-05-13 [?] RSPM
 P fastmap       1.1.1   2023-02-24 [?] RSPM
 P forcats     * 1.0.0   2023-01-29 [?] RSPM
 P generics      0.1.3   2022-07-05 [?] RSPM
 P ggplot2     * 3.5.1   2024-04-23 [?] RSPM (R 4.3.0)
 P glue          1.8.0   2024-09-30 [?] RSPM (R 4.3.0)
 P gtable        0.3.6   2024-10-25 [?] RSPM (R 4.3.0)
 P hms           1.1.3   2023-03-21 [?] RSPM
 P htmltools     0.5.7   2023-11-03 [?] RSPM (R 4.3.0)
 P htmlwidgets   1.6.4   2023-12-06 [?] RSPM
 P jsonlite      1.8.8   2023-12-04 [?] RSPM
 P knitr         1.47    2024-05-29 [?] RSPM
 P lifecycle     1.0.4   2023-11-07 [?] RSPM
 P lubridate   * 1.9.3   2023-09-27 [?] RSPM
 P magrittr      2.0.3   2022-03-30 [?] RSPM
 P munsell       0.5.1   2024-04-01 [?] RSPM
 P mvtnorm       1.3-2   2024-11-04 [?] RSPM (R 4.3.0)
   pillar        1.10.1  2025-01-07 [1] RSPM (R 4.3.0)
 P pkgconfig     2.0.3   2019-09-22 [?] RSPM
 P purrr       * 1.0.2   2023-08-10 [?] RSPM
 P R6            2.5.1   2021-08-19 [?] RSPM
 P rbibutils     2.3     2024-10-04 [?] RSPM (R 4.3.0)
   Rdpack        2.6.2   2024-11-15 [1] RSPM (R 4.3.0)
 P readr       * 2.1.5   2024-01-10 [?] RSPM
   renv          1.0.5   2024-02-29 [1] RSPM (R 4.3.1)
 P rlang         1.1.4   2024-06-04 [?] RSPM
 P rmarkdown     2.27    2024-05-17 [?] RSPM
 P rstudioapi    0.17.1  2024-10-22 [?] RSPM (R 4.3.0)
 P scales        1.3.0   2023-11-28 [?] RSPM
 P sessioninfo   1.2.2   2021-12-06 [?] RSPM
   simhelpers  * 0.3.1   2025-01-14 [1] Github (meghapsimatrix/simhelpers@3a7dda2)
 P stringi       1.8.4   2024-05-06 [?] RSPM (R 4.3.0)
 P stringr     * 1.5.1   2023-11-14 [?] RSPM
 P tibble      * 3.2.1   2023-03-20 [?] RSPM
 P tidyr       * 1.3.1   2024-01-24 [?] RSPM
 P tidyselect    1.2.1   2024-03-11 [?] RSPM
 P tidyverse   * 2.0.0   2023-02-22 [?] RSPM
 P timechange    0.3.0   2024-01-18 [?] RSPM
 P tzdb          0.4.0   2023-05-12 [?] RSPM
 P vctrs         0.6.5   2023-12-01 [?] RSPM
 P withr         3.0.2   2024-10-28 [?] RSPM (R 4.3.0)
 P xfun          0.45    2024-06-16 [?] RSPM
 P yaml          2.3.8   2023-12-11 [?] RSPM

 [1] C:/Users/James/Documents/jepusto-quarto/renv/library/R-4.3/x86_64-w64-mingw32
 [2] C:/Users/James/AppData/Local/R/cache/R/renv/sandbox/R-4.3/x86_64-w64-mingw32/bd3f13aa

 P ── Loaded and on-disk path mismatch.

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


<!-- -->


</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" data-line-spacing="2">
<div id="ref-boos2000MonteCarloEvaluation" class="csl-entry">
Boos, D. D., &amp; Zhang, J. (2000). <span>Monte Carlo</span> evaluation of resampling-based hypothesis tests. <em>Journal of the American Statistical Association</em>, <em>95</em>(450), 486–492. <a href="https://doi.org/10.1080/01621459.2000.10474226">https://doi.org/10.1080/01621459.2000.10474226</a>
</div>
<div id="ref-efron1987better" class="csl-entry">
Efron, B. (1987). Better bootstrap confidence intervals. <em>Journal of the American Statistical Association</em>, <em>82</em>(397), 171–185. <a href="https://doi.org/10.1080/01621459.1987.10478410">https://doi.org/10.1080/01621459.1987.10478410</a>
</div>
<div id="ref-hu2020Interval" class="csl-entry">
Hu, X., Jung, A., &amp; Qin, G. (2020). Interval estimation for the correlation coefficient. <em>The American Statistician</em>, <em>74</em>(1), 29–36. <a href="https://doi.org/10.1080/00031305.2018.1437077">https://doi.org/10.1080/00031305.2018.1437077</a>
</div>
</div></section></div> ]]></description>
  <category>programming</category>
  <category>Rstats</category>
  <category>bootstrap</category>
  <guid>https://jepusto.netlify.app/posts/Bootstrap-CI-variant-simulations/</guid>
  <pubDate>Sat, 18 Jan 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Bootstrap confidence interval variations</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/Bootstrap-CI-variations/</link>
  <description><![CDATA[ 





<p>I recently added some new utilities for calculating bootstrap confidence intervals to the <a href="https://meghapsimatrix.github.io/simhelpers/"><code>simhelpers</code> package</a>. The functions are designed to make it a bit more convenient to implement Monte Carlo simulations of bootstrap CIs, including when using an extrapolation technique suggested by <span class="citation" data-cites="boos2000MonteCarloEvaluation">Boos &amp; Zhang (2000)</span>, which <a href="../..\posts/Simulating-bootstrap-CIs/">I wrote about a while ago</a>. With the latest update, the package now provides options for a bunch of different variants of bootstrap CIs, including:</p>
<ul>
<li>the normal CI, which uses bootstrapping to estimate a standard error and bias-correction, then takes plus or minus a normal critical value times the SE;</li>
<li>the studentized CI, which uses the bootstrap distribution of a t-statistic rather than the point estimator;</li>
<li>the percentile CI, which takes percentiles of the bootstrap distribution as the end-points of the CI;</li>
<li>the so-called “basic” CI, which is similar to the percentile CI but pivots the bootstrap distribution around the point estimator;</li>
<li>a bias-corrected version of the percentile CI;</li>
<li>Efron’s <span class="citation" data-cites="efron1987better">(1987)</span> bias-corrected-and-accelerated CI, which is supposed to provide more accurate coverage levels than alternative CIs for some classes of estimators.</li>
</ul>
<p>These CI variants are also implemented in other packages. Most notably, all of them are implemented in <a href="https://cran.r-project.org/package=boot"><code>boot</code></a> <span class="citation" data-cites="bootpkg">(Canty &amp; Ripley, 2024)</span>, the venerable R package companion to the <span class="citation" data-cites="Davison1997bootstrap">Davison &amp; Hinkley (1997)</span> book on bootstrapping. Although very full-featured and widely used (it has 377 reverse dependencies!), the <code>boot</code> package does not offer a super-friendly user experience. Its output is a unwieldy, there are several quirks to its naming conventions, and its function for confidence interval calculations require the user to implement the bootstrap resampling calculations through <code>boot::boot()</code>, which is sometimes a bit awkward. Newer packages that provide some of the same methods include <a href="https://infer.netlify.app/"><code>infer</code></a> <span class="citation" data-cites="Couch2021infer">(Couch et al., 2021)</span> and <a href="https://rsample.tidymodels.org/"><code>rsample</code></a> <span class="citation" data-cites="rsamplepkg">(Frick et al., 2024)</span>. Both of these offer pipe-friendly workflows, but neither provides the full slate of CI variants. As with <code>boot</code>, these packages also lock in (or at least strongly nudge) the user to the package’s resampling tools. And none of the packages support a workflow for the <span class="citation" data-cites="boos2000MonteCarloEvaluation">Boos &amp; Zhang (2000)</span> extrapolation technique.</p>
<p>In this post, I’ll demonstrate the <code>simhelpers</code> implementation of these different CI variants with an example, compare the results to implementations in other packages, and then show how the <code>simhelpers</code> implementation can be used for the <span class="citation" data-cites="boos2000MonteCarloEvaluation">Boos &amp; Zhang (2000)</span> extrapolation technique.</p>
<section id="bootstrap-confidence-intervals-for-a-mean" class="level1">
<h1>Bootstrap confidence intervals for a mean</h1>
<p>Let me demonstrate the confidence intervals using a simple example of estimating a correlation. For illustrative purposes, I’ll use the <code>swiss</code> dataset of various socio-demographic measures of provinces in Switzerland from the late 19th century. I’ll look at the correlation between level of education and a measure of fertility:</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;">library</span>(ggplot2)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"swiss"</span>)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(swiss) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-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> Education, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> Fertility) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-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;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/Bootstrap-CI-variations/index_files/figure-html/unnamed-chunk-1-1.png" class="img-fluid figure-img" style="width:75.0%"></p>
</figure>
</div>
</div>
</div>
<p>Here is a function to calculate the sample correlation and its standard error (which is necessary for the studentized CIs):</p>
<div class="cell">
<details open="" 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">my_calc_cor <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="cb2-2">  r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cor</span>(x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Education, x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Fertility) </span>
<span id="cb2-3">  n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(x)</span>
<span id="cb2-4">  <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;">r =</span> r, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</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> r<span 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> (n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)))</span>
<span id="cb2-5">}</span>
<span id="cb2-6"></span>
<span id="cb2-7">est <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">my_calc_cor</span>(swiss)</span>
<span id="cb2-8">est</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>          r          SE 
-0.66378886  0.08247672 </code></pre>
</div>
</div>
<p>Using this function, we can generate a sample from the bootstrap distribution of the mean:</p>
<div class="cell">
<details open="" 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">N <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(swiss)</span>
<span id="cb4-2">cors_boot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">replicate</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">999</span>, {</span>
<span id="cb4-3">  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;">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>N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> N)</span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">my_calc_cor</span>(swiss[i,])</span>
<span id="cb4-5">}) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</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;">as.data.frame</span>()</span></code></pre></div></div>
</details>
</div>
<p>The bootstrap distribution of the sample correlations is clearly skewed and non-normal:</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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(cors_boot) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(r) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_density</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;">"green"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-4">  <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> est[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/Bootstrap-CI-variations/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" style="width:75.0%"></p>
</figure>
</div>
</div>
</div>
<p>As a consequence of the asymmetry and non-normality of the bootstrap distribution, the different CI variants will produce discrepant intervals. The simhelpers function for calculating these intervals is as follows:</p>
<div class="cell">
<details open="" 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;">library</span>(simhelpers)</span>
<span id="cb6-2"></span>
<span id="cb6-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootstrap_CIs</span>(</span>
<span id="cb6-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_est =</span> cors_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r,</span>
<span id="cb6-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_se =</span> cors_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SE,</span>
<span id="cb6-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> est[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span>],</span>
<span id="cb6-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> est[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SE"</span>],</span>
<span id="cb6-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</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;">"normal"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"basic"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bias-corrected"</span>),</span>
<span id="cb6-9">  <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;">"long"</span></span>
<span id="cb6-10">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>  bootstraps           type      lower      upper
1        999         normal -0.9061176 -0.4641111
2        999          basic -0.9571476 -0.5281576
3        999        student -0.8539880 -0.4535804
4        999     percentile -0.7994201 -0.3704302
5        999 bias-corrected -0.7994201 -0.3729852</code></pre>
</div>
</div>
<p>For the bias-corrected-and-accelerated interval, the function requires the user to provide a vector of the empirical influence values of each observation. I’ll calculate these using a jack-knife:</p>
<div class="cell">
<details open="" 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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># leave-one-out jack-knife</span></span>
<span id="cb8-2">jacks <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sapply</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>N, \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">my_calc_cor</span>(swiss[<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>x,])[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span>])</span>
<span id="cb8-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># empirical influence</span></span>
<span id="cb8-4">inf_vals <span class="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>(jacks) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> jacks</span>
<span id="cb8-5"></span>
<span id="cb8-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Now recalculate the bootstrap CIs</span></span>
<span id="cb8-7">my_boot_CIs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootstrap_CIs</span>(</span>
<span id="cb8-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_est =</span> cors_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r,</span>
<span id="cb8-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_se =</span> cors_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SE,</span>
<span id="cb8-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> est[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span>],</span>
<span id="cb8-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> est[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SE"</span>],</span>
<span id="cb8-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">influence =</span> inf_vals,</span>
<span id="cb8-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</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;">"normal"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"basic"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bias-corrected"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>),</span>
<span id="cb8-14">  <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;">"long"</span>,</span>
<span id="cb8-15">  <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;">20250111</span></span>
<span id="cb8-16">)</span></code></pre></div></div>
</details>
</div>
<p>For sample correlation coefficients, another way to compute a confidence interval is via Fisher’s z-transformation, which is both normalizing and variance-stabilizing (so that the standard error of the point estimator does not depend on the parameter) under bivariate normality. The end-points of the CI on the Fisher z scale can then be back-transformed to the original scale. Here’s my “by-hand” calculation of this interval:</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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">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;">atanh</span>(est[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span>])</span>
<span id="cb9-2">SE_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;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(N <span 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="cb9-3">CI_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;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="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;">qnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> SE_z</span>
<span id="cb9-4">CI_r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb9-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Fisher z"</span>,</span>
<span id="cb9-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tanh</span>(CI_z[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]),</span>
<span id="cb9-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tanh</span>(CI_z[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb9-8">)</span>
<span id="cb9-9"></span>
<span id="cb9-10">CI_r</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>      type      lower      upper
1 Fisher z -0.7987075 -0.4653206</code></pre>
</div>
</div>
<p>How do these various CIs compare? Here’s a graph illustrating all of the intervals:</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">CI_r<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bootstraps <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="cb11-2">all_CIs <span class="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>(my_boot_CIs, CI_r)</span>
<span id="cb11-3">all_CIs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>type <span class="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>(all_CIs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>type, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Fisher z"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bias-corrected"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"basic"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"normal"</span>))</span>
<span id="cb11-4"></span>
<span id="cb11-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(all_CIs) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-6">  <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;">xmin =</span> lower, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xmax =</span> upper, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> type, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> type) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb11-7">  <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> est[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span>], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb11-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_errorbar</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb11-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb11-10">  <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="cb11-11">  <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;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/Bootstrap-CI-variations/index_files/figure-html/unnamed-chunk-8-1.png" class="img-fluid figure-img" style="width:75.0%"></p>
</figure>
</div>
</div>
</div>
<p>The various bootstrap intervals differ by quite a bit. The percentile and bias-corrected percentile intervals are wide and extend to smaller correlations than the other intervals. The basic interval is markedly different, extending to much higher correlations than any of the other intervals. The studentized and BCa intervals are closer to each other and come closer to matching the end-points of the Fisher z interval. It’s not necessarily the case that Fisher’s z interval is correct or optimal, unless the observations actually are drawn from a bivariate normal distribution. But it does seem suggestive that the studentized and BCa intervals are closer to agreeing with Fisher.</p>
</section>
<section id="comparison-to-other-packages" class="level1">
<h1>Comparison to other packages</h1>
<section id="boot" class="level2">
<h2 class="anchored" data-anchor-id="boot"><code>boot</code></h2>
<p>Comparing the above calculations to what can be done with other packages is useful both as a validation exercise and as an illustration of the differences in workflow. Perhaps the most widely known R package for bootstrapping is Canty and Ripley’s <a href="https://cran.r-project.org/package=boot"><code>boot</code></a> package. Using it to obtain confidence intervals for a correlation requires running the bootstrap resampling process through its <code>boot()</code> function, which takes a bit of fiddling. First, I have to revise my <code>calc_cor()</code> function to take a subsetting index and to return the sampling variance instead of the standard error:</p>
<div class="cell">
<details open="" 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;">library</span>(boot) </span>
<span id="cb12-2"></span>
<span id="cb12-3">boot_calc_cor <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="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</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>(x)) {</span>
<span id="cb12-4">  r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cor</span>(x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Education[i], x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Fertility[i]) </span>
<span id="cb12-5">  n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(x[i,])</span>
<span id="cb12-6">  <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;">r =</span> r, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">V =</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> r<span 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> (n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb12-7">}</span></code></pre></div></div>
</details>
</div>
<p>Now I can run it through <code>boot()</code> and compute some confidence intervals:</p>
<div class="cell">
<details open="" 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"><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;">20250111</span>)</span>
<span id="cb13-2">swiss_boots <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boot</span>(swiss, boot_calc_cor, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">999</span>)</span>
<span id="cb13-3">boot_boot_CIs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boot.ci</span>(swiss_boots, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"all"</span>)</span>
<span id="cb13-4">boot_boot_CIs</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 999 bootstrap replicates

CALL : 
boot.ci(boot.out = swiss_boots, type = "all")

Intervals : 
Level      Normal              Basic             Studentized     
95%   (-0.8854, -0.4754 )   (-0.9211, -0.5268 )   (-0.8362, -0.4502 )  

Level     Percentile            BCa          
95%   (-0.8008, -0.4065 )   (-0.8111, -0.4518 )  
Calculations and Intervals on Original Scale</code></pre>
</div>
</div>
<p>The package does not have an option for bias-corrected intervals (without acceleration) but it can be hacked by feeding a symmetrically distributed vector of influence points:</p>
<div class="cell">
<details open="" 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">boot_BC_CI <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boot.ci</span>(swiss_boots, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bca"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">L =</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;">1</span>)</span>
<span id="cb15-2">boot_BC_CI</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 999 bootstrap replicates

CALL : 
boot.ci(boot.out = swiss_boots, type = "bca", L = -1:1)

Intervals : 
Level       BCa          
95%   (-0.8027, -0.4128 )  
Calculations and Intervals on Original Scale</code></pre>
</div>
</div>
<p>These results will not align exactly with those reported above because they’re based on a different sample from the bootstrap distribution. To allow for direct comparison, I’ll recompute the intervals using the bootstrap sample stored in <code>swiss_boots</code> (and computing the influence values using the same method as used implicitly by <code>boot.ci()</code>:</p>
<div class="cell">
<details open="" 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">emp_inf_vals <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">empinf</span>(swiss_boots)</span>
<span id="cb17-2"></span>
<span id="cb17-3">my_boot_CIs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootstrap_CIs</span>(</span>
<span id="cb17-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_est =</span> swiss_boots<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>],</span>
<span id="cb17-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_se =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(swiss_boots<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]),</span>
<span id="cb17-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> swiss_boots<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t0[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>],</span>
<span id="cb17-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(swiss_boots<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t0[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]),</span>
<span id="cb17-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">influence =</span> emp_inf_vals,</span>
<span id="cb17-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</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;">"normal"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"basic"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bias-corrected"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>),</span>
<span id="cb17-10">  <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;">"long"</span></span>
<span id="cb17-11">)</span></code></pre></div></div>
</details>
</div>
<p>It’d be nice to put the results from <code>boot.ci()</code> into a table to ease comparison with the output of <code>bootstrap_CIs()</code>, but its output is fairly untidy. Wrangling it takes a bit of work:</p>
<div class="cell">
<details open="" 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">boot_boot_CI_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;">data.frame</span>(</span>
<span id="cb18-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</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;">"normal"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"basic"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bias-corrected"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>),</span>
<span id="cb18-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_lower =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb18-4">    boot_boot_CIs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>normal[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>],</span>
<span id="cb18-5">    boot_boot_CIs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>basic[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>],</span>
<span id="cb18-6">    boot_boot_CIs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>student[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>],</span>
<span id="cb18-7">    boot_boot_CIs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>percent[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>],</span>
<span id="cb18-8">    boot_BC_CI<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bca[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>],</span>
<span id="cb18-9">    boot_boot_CIs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bca[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>]</span>
<span id="cb18-10">  ),</span>
<span id="cb18-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_upper =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb18-12">    boot_boot_CIs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>normal[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>],</span>
<span id="cb18-13">    boot_boot_CIs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>basic[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>],</span>
<span id="cb18-14">    boot_boot_CIs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>student[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>],</span>
<span id="cb18-15">    boot_boot_CIs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>percent[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>],</span>
<span id="cb18-16">    boot_BC_CI<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bca[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>],</span>
<span id="cb18-17">    boot_boot_CIs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bca[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]</span>
<span id="cb18-18">  )</span>
<span id="cb18-19">)</span>
<span id="cb18-20"></span>
<span id="cb18-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cbind</span>(my_boot_CIs, boot_boot_CI_tab[,<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;">3</span>])</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>  bootstraps           type      lower      upper boot_lower boot_upper
1        999         normal -0.8854201 -0.4754233 -0.8854201 -0.4754233
2        999          basic -0.9210706 -0.5268220 -0.9210706 -0.5268220
3        999        student -0.8361986 -0.4502460 -0.8361986 -0.4502460
4        999     percentile -0.8007557 -0.4065071 -0.8007557 -0.4065071
5        999 bias-corrected -0.8017628 -0.4135041 -0.8027344 -0.4127751
6        999            BCa -0.8110222 -0.4519353 -0.8111334 -0.4517669</code></pre>
</div>
</div>
<p>The first four intervals exactly match across packages. The bias-corrected and BCa intervals differ slightly because the packages use different interpolation methods for calculating percentiles that don’t correspond to integer positions in the sorted bootstrap sample.</p>
</section>
<section id="infer" class="level2">
<h2 class="anchored" data-anchor-id="infer"><code>infer</code></h2>
<p>The <a href="https://infer.netlify.app/"><code>infer</code></a> package aims to provide a coherent grammar for statistical inference (including hypothesis testing and confidence intervals) based on resampling methods, following principles of tidy data and offering a pipe-friendly workflow. Again, I’ll need to repeat the bootstrap re-sampling in the package’s idiom:</p>
<div class="cell">
<details open="" 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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(dplyr)</span>
<span id="cb20-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(infer)</span>
<span id="cb20-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20250111</span>)</span>
<span id="cb20-4"></span>
<span id="cb20-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Compute point estimate</span></span>
<span id="cb20-6">correlation_hat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> swiss <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-7">   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">specify</span>(Fertility <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Education) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-8">   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">calculate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"correlation"</span>)</span>
<span id="cb20-9"></span>
<span id="cb20-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Compute bootstrap distribution</span></span>
<span id="cb20-11">infer_boot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb20-12">  swiss <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-13">   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">specify</span>(Fertility <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Education) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-14">   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">generate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">999</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bootstrap"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb20-15">   <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">calculate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"correlation"</span>)</span></code></pre></div></div>
</details>
</div>
<p>I can then calculate studentized, percentile, and bias-corrected bootstrap CIs:</p>
<div class="cell">
<details open="" 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">CI_normal <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_confidence_interval</span>(</span>
<span id="cb21-2">  infer_boot, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"se"</span>, </span>
<span id="cb21-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">point_estimate =</span> correlation_hat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span></span>
<span id="cb21-4">)</span>
<span id="cb21-5"></span>
<span id="cb21-6">CI_percentile <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_confidence_interval</span>(</span>
<span id="cb21-7">  infer_boot, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span>, </span>
<span id="cb21-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span></span>
<span id="cb21-9">)</span>
<span id="cb21-10"></span>
<span id="cb21-11">CI_biascorrected <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_confidence_interval</span>(</span>
<span id="cb21-12">  infer_boot, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bias-corrected"</span>, </span>
<span id="cb21-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">point_estimate =</span> correlation_hat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">level =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span></span>
<span id="cb21-14">)</span>
<span id="cb21-15"></span>
<span id="cb21-16">infer_CIs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb21-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb21-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">normal =</span> CI_normal,</span>
<span id="cb21-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">percentile =</span> CI_percentile,</span>
<span id="cb21-20">    <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;">bias-corrected</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> CI_biascorrected,</span>
<span id="cb21-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"type"</span></span>
<span id="cb21-22">  )</span></code></pre></div></div>
</details>
</div>
<p>For comparison purposes, I’ll once again need to re-compute the intervals with <code>bootstrap_CIs()</code>, this time with the <code>infer</code> bootstrap sample:</p>
<div class="cell">
<details open="" 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">my_infer_CIs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootstrap_CIs</span>(</span>
<span id="cb22-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_est =</span> infer_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>stat,</span>
<span id="cb22-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> correlation_hat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>stat,</span>
<span id="cb22-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</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;">"normal"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bias-corrected"</span>),</span>
<span id="cb22-5">  <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;">"long"</span></span>
<span id="cb22-6">)</span>
<span id="cb22-7"></span>
<span id="cb22-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(my_infer_CIs, infer_CIs)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>  bootstraps           type      lower      upper   lower_ci   upper_ci
1        999         normal -0.9052953 -0.4614019 -0.8857356 -0.4418421
2        999     percentile -0.8030248 -0.3487307 -0.8027752 -0.3507277
3        999 bias-corrected -0.8027620 -0.3487307 -0.8027066 -0.3504208</code></pre>
</div>
</div>
<p>The results do not exactly match across packages. For the normal interval, the difference occurs because the <code>simhelpers</code> implementation (like the <code>boot</code> implementation) includes a bias-correction term that shifts the interval by the difference between the point estimate and the average bootstrap estimate, which <code>infer</code> does not do. The very small differences in the percentile and bias-corrected intervals are due to the use of different interpolation methods for calculating percentiles.</p>
</section>
<section id="rsample" class="level2">
<h2 class="anchored" data-anchor-id="rsample"><code>rsample</code></h2>
<p>Okay, one last time, this time using the <a href="https://rsample.tidymodels.org/"><code>rsample</code></a> package by <span class="citation" data-cites="rsamplepkg">Frick et al. (2024)</span>. I’ll first need to re-work my correlation calculation to provide a <code>data.frame</code> with columns called <code>term</code>, <code>estimate</code>, and <code>std.error</code>, and also ensure that the function allows for extra arguments with <code>...</code>.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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">rsample_calc_cor <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>(split, ...) {</span>
<span id="cb24-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;">analysis</span>(split)</span>
<span id="cb24-3">  n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(x)</span>
<span id="cb24-4">  r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cor</span>(x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Education, x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Fertility)</span>
<span id="cb24-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb24-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">term =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"corr"</span>,</span>
<span id="cb24-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimate =</span> r,</span>
<span id="cb24-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">std.error =</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;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> r<span 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> (n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb24-9">  )</span>
<span id="cb24-10">}</span></code></pre></div></div>
</details>
</div>
<p>Now I can generate a bootstrap distribution using <code>bootstraps</code>, setting <code>apparent = TRUE</code> to include calculation of the point estimate and analytical standard error. I’ll use about 2000 bootstraps here to avoid an automated warning message.</p>
<div class="cell">
<details open="" 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;">library</span>(purrr)</span>
<span id="cb25-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyr)</span>
<span id="cb25-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rsample)</span>
<span id="cb25-4"></span>
<span id="cb25-5"><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;">20250111</span>)</span>
<span id="cb25-6">rsample_boots <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb25-7">  swiss <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb25-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootstraps</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">apparent =</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;">%&gt;%</span></span>
<span id="cb25-9">  <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;">r =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(splits, rsample_calc_cor))</span></code></pre></div></div>
</details>
</div>
<p>The <code>resample</code> package provides functions for calculating percentile, studentized, and BCa intervals. I’ll do all three:</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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">rsample_CIs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(</span>
<span id="cb26-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">int_pctl</span>(rsample_boots, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> r),</span>
<span id="cb26-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">int_t</span>(rsample_boots, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> r),</span>
<span id="cb26-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">int_bca</span>(rsample_boots, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistics =</span> r, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.fn =</span> rsample_calc_cor)</span>
<span id="cb26-5">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb26-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> .method, .lower, .upper) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb26-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb26-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(type, <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;">student-t</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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span>)</span>
<span id="cb26-9">  )</span></code></pre></div></div>
</details>
</div>
<p>Now I’ll redo the interval calculations with <code>bootstrap_CIs()</code>:</p>
<div class="cell">
<details open="" 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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># just the point estimate</span></span>
<span id="cb27-2">rsample_apparent <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb27-3">  rsample_boots <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb27-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(id <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;">"Apparent"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb27-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(r)</span>
<span id="cb27-6"></span>
<span id="cb27-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># just the bootstraps</span></span>
<span id="cb27-8">rsample_boots <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb27-9">  rsample_boots <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb27-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(id <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;">"Apparent"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb27-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(r)</span>
<span id="cb27-12"></span>
<span id="cb27-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># jack-knife to get empirical influence values</span></span>
<span id="cb27-14">inf_vals <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb27-15">  swiss <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb27-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">loo_cv</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb27-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(splits, rsample_calc_cor)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb27-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(r) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb27-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb27-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">inf_val =</span> rsample_apparent<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> estimate</span>
<span id="cb27-21">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb27-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(inf_val)</span>
<span id="cb27-23"></span>
<span id="cb27-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># calculate bootstrap CIs  </span></span>
<span id="cb27-25">my_rsample_CIs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb27-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootstrap_CIs</span>(</span>
<span id="cb27-27">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_est =</span> rsample_boots<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate,</span>
<span id="cb27-28">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_se =</span> rsample_boots<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>std.error,</span>
<span id="cb27-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> rsample_apparent<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>estimate,</span>
<span id="cb27-30">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> rsample_apparent<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>std.error,</span>
<span id="cb27-31">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">influence =</span> inf_vals,</span>
<span id="cb27-32">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</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;">"student"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>),</span>
<span id="cb27-33">    <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;">"long"</span></span>
<span id="cb27-34">  )</span>
<span id="cb27-35"></span>
<span id="cb27-36"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Compare</span></span>
<span id="cb27-37"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inner_join</span>(my_rsample_CIs, rsample_CIs)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>  bootstraps       type      lower      upper     .lower     .upper
1       1999    student -0.8529496 -0.4470351 -0.8526882 -0.4484207
2       1999 percentile -0.8020261 -0.3725691 -0.8014797 -0.3731069
3       1999        BCa -0.8194484 -0.4326284 -0.8191845 -0.4324908</code></pre>
</div>
</div>
<p>All checks out, with small differences due to the method used to interpolate percentiles and how the acceleration constant is calculated.</p>
<p>Although <code>rsample</code> does not provide the full set of bootstrap CI variants, the three it does include are probably the most useful ones. The option to include the original sample estimate as an additional result in the <code>bootstraps</code> object is also quite nice, and the functions smoothly handle computing bootstraps for each of several terms (such as multiple regression coefficient estimates from a given model). However, the workflow enforced by <code>rsample</code> does seem to have a big downside with respect to memory management. Taking a bootstrap sample with <img src="https://latex.codecogs.com/png.latex?B"> replications creates <img src="https://latex.codecogs.com/png.latex?B"> new datasets (stored in a nested list). Similarly, running <code>loo_cv()</code> creates a near-copy of the dataset for every row of the original dataset. These could get to be quite large objects:</p>
<div class="cell">
<details open="" 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;">object.size</span>(swiss)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>6464 bytes</code></pre>
</div>
<details open="" 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;">object.size</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">loo_cv</span>(swiss))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>403696 bytes</code></pre>
</div>
<details open="" 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;">object.size</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootstraps</span>(swiss, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">times =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">999</span>))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>8561488 bytes</code></pre>
</div>
</div>
<p>Especially for large datasets, it would be much more memory-efficient to roll together the re-sampling step and the estimation step or to store only the resampled row indices rather than copies of the full dataset.</p>
</section>
</section>
<section id="extrapolating-coverage-rates-a-la-boos-and-zhang" class="level1">
<h1>Extrapolating coverage rates a la Boos and Zhang</h1>
<p>One big reason that I implemented all these boostrap CI variants in <code>simhelpers</code> is to assist with running Monte Carlo simulations of bootstrap procedures. The main novel feature of my implementation is that <code>bootstrap_CIs()</code> can compute not just one interval, but a collection of several intervals using different-sized subsamples of bootstrap replicates. The number of bootstrap replicates to use in each interval can be specified by providing a vector to the <code>B_vals</code> argument, as follows:</p>
<div class="cell">
<details open="" 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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootstrap_CIs</span>(</span>
<span id="cb35-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_est =</span> cors_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>r,</span>
<span id="cb35-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_se =</span> cors_boot<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>SE,</span>
<span id="cb35-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> est[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span>],</span>
<span id="cb35-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> est[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"SE"</span>],</span>
<span id="cb35-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">influence =</span> inf_vals,</span>
<span id="cb35-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>,</span>
<span id="cb35-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_vals =</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;">100</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>L,</span>
<span id="cb35-9">  <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;">"long"</span></span>
<span id="cb35-10">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>   bootstraps type      lower      upper
1          99  BCa -0.8187481 -0.4565992
2         199  BCa -0.8536818 -0.4314318
3         299  BCa -0.8163946 -0.4133028
4         399  BCa -0.8185373 -0.4314318
5         499  BCa -0.8264171 -0.4314478
6         599  BCa -0.8209467 -0.4317901
7         699  BCa -0.8231215 -0.4429049
8         799  BCa -0.8231215 -0.4314318
9         899  BCa -0.8213542 -0.4314318
10        999  BCa -0.8213542 -0.4314478</code></pre>
</div>
</div>
<p>In the context of a simulation study, this feature makes it feasible to compute coverage levels of a bootstrap CI for several different values of <img src="https://latex.codecogs.com/png.latex?B">, then extrapolate to higher numbers of replicates.</p>
<section id="simulating-bootstrap-cis-for-a-pearson-correlation" class="level2">
<h2 class="anchored" data-anchor-id="simulating-bootstrap-cis-for-a-pearson-correlation">Simulating bootstrap CIs for a Pearson correlation</h2>
<p>Here is a small simulation to demonstrate how all this can work. I’ll generate samples of size <img src="https://latex.codecogs.com/png.latex?n%20=%2025"> from a bivariate-<img src="https://latex.codecogs.com/png.latex?t"> distribution with correlation parameter <img src="https://latex.codecogs.com/png.latex?%5Crho%20=%200.75"> and with just <img src="https://latex.codecogs.com/png.latex?%5Cnu%20=%208"> degrees of freedom. With each sample, I’ll calculate the sample correlation and a set of bootstrapped confidence intervals with <img src="https://latex.codecogs.com/png.latex?B%20=%2049,%2099,%20199,%20299,%20399">. Here’s the data-generating function:</p>
<div class="cell">
<details open="" 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">r_t_bi <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, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho =</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;">df =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>) {</span>
<span id="cb37-2">  Sigma <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rho <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diag</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rho, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb37-3">  mvtnorm<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rmvt</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;">sigma =</span> Sigma, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> df)</span>
<span id="cb37-4">}</span>
<span id="cb37-5"></span>
<span id="cb37-6">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.75</span></span>
<span id="cb37-7">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">r_t_bi</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho =</span> rho, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>)</span></code></pre></div></div>
</details>
</div>
<p>And the estimation function:</p>
<div class="cell">
<details open="" 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">cor_CI <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="cb38-2">  dat, </span>
<span id="cb38-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span>, </span>
<span id="cb38-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_vals =</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;">49</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">199</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">299</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">399</span>)</span>
<span id="cb38-5">) {</span>
<span id="cb38-6">  </span>
<span id="cb38-7">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># point estimate</span></span>
<span id="cb38-8">  r_est <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cor</span>(dat[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], dat[,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb38-9">  N <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(dat)</span>
<span id="cb38-10">  SE_r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</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> r_est<span 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> (N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb38-11">  </span>
<span id="cb38-12">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Fisher z CI</span></span>
<span id="cb38-13">  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;">atanh</span>(r_est)</span>
<span id="cb38-14">  SE_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;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(N <span 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="cb38-15">  CI_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;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="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;">qnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> SE_z</span>
<span id="cb38-16"></span>
<span id="cb38-17">  </span>
<span id="cb38-18">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># empirical influence if needed</span></span>
<span id="cb38-19">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> CI_type) {</span>
<span id="cb38-20">    jacks <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sapply</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>N, \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cor</span>(dat[<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>x,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], dat[<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>x,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]))</span>
<span id="cb38-21">    inf_vals <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> r_est <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> jacks</span>
<span id="cb38-22">  } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb38-23">    inf_vals <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="cb38-24">  }</span>
<span id="cb38-25">  </span>
<span id="cb38-26">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># bootstrap samples</span></span>
<span id="cb38-27">  r_boot <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">replicate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(B_vals), {</span>
<span id="cb38-28">    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;">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>N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> N)</span>
<span id="cb38-29">    r <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cor</span>(dat[i,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], dat[i,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb38-30">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(r, <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;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> r<span 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> (N <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)))</span>
<span id="cb38-31">  })</span>
<span id="cb38-32">  </span>
<span id="cb38-33">  bs_CIs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> simhelpers<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bootstrap_CIs</span>(</span>
<span id="cb38-34">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_est =</span> r_boot[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,],</span>
<span id="cb38-35">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">boot_se =</span> r_boot[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,],</span>
<span id="cb38-36">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> r_est,</span>
<span id="cb38-37">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> SE_r,</span>
<span id="cb38-38">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">influence =</span> inf_vals,</span>
<span id="cb38-39">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</span> CI_type,</span>
<span id="cb38-40">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_vals =</span> B_vals,</span>
<span id="cb38-41">    <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;">"wide-list"</span></span>
<span id="cb38-42">  )</span>
<span id="cb38-43">  </span>
<span id="cb38-44">  tibble<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb38-45">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> r_est,</span>
<span id="cb38-46">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE =</span> SE_r,</span>
<span id="cb38-47">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lo =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tanh</span>(CI_z[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]),</span>
<span id="cb38-48">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hi =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tanh</span>(CI_z[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]),</span>
<span id="cb38-49">    <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;">mean</span>(r_boot <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> r_est),</span>
<span id="cb38-50">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">a =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(inf_vals<span 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="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(inf_vals<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>),</span>
<span id="cb38-51">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bs_CIs =</span> bs_CIs</span>
<span id="cb38-52">  )</span>
<span id="cb38-53">}</span>
<span id="cb38-54"></span>
<span id="cb38-55">res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cor_CI</span>(dat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</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;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span>))</span>
<span id="cb38-56">res</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 1 × 7
      r     SE    lo    hi     w     a bs_CIs      
  &lt;dbl&gt;  &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;btstr_CI&gt;  
1 0.788 0.0774 0.570 0.902 0.723   NaN &lt;df [5 × 5]&gt;</code></pre>
</div>
</div>
<p>Setting the argument <code>format = "wide-list"</code> in the call to <code>generate_CIs()</code> makes it convenient to store all the CIs in a nested list-column. Here’s the contents of <code>bs_CIs</code>:</p>
<div class="cell">
<details open="" 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">res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>bs_CIs[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>  bootstraps student_lower student_upper percentile_lower percentile_upper
1         49     0.6017501     0.9143423        0.5580763        0.8898411
2         99     0.5510270     0.8967928        0.6059297        0.9029773
3        199     0.5312326     0.9102482        0.5697594        0.9073084
4        299     0.5327977     0.8988743        0.6005613        0.9069798
5        399     0.5510270     0.9054740        0.5829886        0.9029773</code></pre>
</div>
</div>
<p>Now let me pass these functions to <code>simhelpers::bundle_sim()</code> so that I can replicate the data-generation and estimation calls as many times as I like. Calling the resulting function gives me 2000 replications of the whole process, where each replication involves generating <img src="https://latex.codecogs.com/png.latex?B%20=%20399"> bootstraps and also <img src="https://latex.codecogs.com/png.latex?n"> leave-one-out jack-knife values:</p>
<div class="cell">
<details open="" 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"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># bundle the data-generating and estimation functions </span></span>
<span id="cb42-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># into a simulation driver</span></span>
<span id="cb42-3">sim_cor <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bundle_sim</span>(r_t_bi, cor_CI)</span>
<span id="cb42-4"></span>
<span id="cb42-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Run many replications</span></span>
<span id="cb42-6">sim_reps <span class="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_cor</span>(</span>
<span id="cb42-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2000</span>, </span>
<span id="cb42-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho =</span> rho,</span>
<span id="cb42-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_vals =</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;">49</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">199</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">299</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">399</span>),</span>
<span id="cb42-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</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;">"normal"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"basic"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bias-corrected"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>)</span>
<span id="cb42-11">)</span>
<span id="cb42-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(sim_reps)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6 × 7
      r     SE    lo    hi     w        a bs_CIs       
  &lt;dbl&gt;  &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;    &lt;dbl&gt; &lt;btstr_CI&gt;   
1 0.507 0.152  0.140 0.752 0.721 -0.0768  &lt;df [5 × 13]&gt;
2 0.866 0.0509 0.717 0.940 0.747  0.0203  &lt;df [5 × 13]&gt;
3 0.679 0.110  0.388 0.847 0.767  0.112   &lt;df [5 × 13]&gt;
4 0.677 0.111  0.385 0.846 0.766  0.0941  &lt;df [5 × 13]&gt;
5 0.807 0.0711 0.605 0.912 0.754  0.0252  &lt;df [5 × 13]&gt;
6 0.813 0.0691 0.616 0.914 0.746 -0.00761 &lt;df [5 × 13]&gt;</code></pre>
</div>
</div>
<p>Now I’ll summarize across replications to evaluate the coverage rates of each set of confidence intervals. For the Fisher intervals, <code>simhelpers::calc_coverage()</code> does the trick, but for the bootstrap intervals I need to use <code>simhelpers::extrapolate_coverage()</code> because each replication is a specially structured <em>set</em> of multiple confidence intervals with different values of <img src="https://latex.codecogs.com/png.latex?B">.</p>
<div class="cell">
<details open="" 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">perf <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb44-2">  sim_reps <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb44-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb44-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">calc_absolute</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">estimates =</span> r, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_param =</span> rho, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">criteria =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bias"</span>),</span>
<span id="cb44-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">calc_coverage</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower_bound =</span> lo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper_bound =</span> hi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_param =</span> rho),</span>
<span id="cb44-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extrapolate_coverage</span>(</span>
<span id="cb44-7">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_subsamples =</span> bs_CIs, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_param =</span> rho, </span>
<span id="cb44-8">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_target =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>,</span>
<span id="cb44-9">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nested =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"long"</span></span>
<span id="cb44-10">    )</span>
<span id="cb44-11">  )</span>
<span id="cb44-12"></span>
<span id="cb44-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Bias and Fisher interval</span></span>
<span id="cb44-14">perf <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb44-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(bias, coverage, width)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 1 × 3
      bias coverage width
     &lt;dbl&gt;    &lt;dbl&gt; &lt;dbl&gt;
1 -0.00879    0.919 0.377</code></pre>
</div>
</div>
<p>The correlation has a slight negative bias. The Fisher <img src="https://latex.codecogs.com/png.latex?z"> interval has coverage a bit below nominal and an average width of 0.377. Here is the performance summary of all the percentile intervals:</p>
<div class="cell">
<details open="" 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">boot_performance <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb46-2">  perf <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb46-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">starts_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"boot"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb46-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">everything</span>())</span>
<span id="cb46-5"></span>
<span id="cb46-6">boot_performance <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb46-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(CI_type <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;">"percentile"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb46-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(CI_type, bootstraps, boot_coverage, boot_width)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6 × 4
  CI_type    bootstraps boot_coverage boot_width
  &lt;chr&gt;           &lt;dbl&gt;         &lt;dbl&gt;      &lt;dbl&gt;
1 percentile         49         0.896      0.371
2 percentile         99         0.914      0.390
3 percentile        199         0.921      0.400
4 percentile        299         0.917      0.391
5 percentile        399         0.924      0.396
6 percentile       1999         0.926      0.400</code></pre>
</div>
</div>
<p>In addition to the coverage rates and average widths of intervals based on between 49 and 399 bootstraps, the results also include performance summaries for intervals with <img src="https://latex.codecogs.com/png.latex?B%20=%201999"> bootstraps, based on the Boos and Zhang extrapolation method. Here’s a graph showing the extrapolated coverage rates for each of the CI variants:</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">boot_performance_top <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(boot_performance, bootstraps <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>)</span>
<span id="cb48-2"></span>
<span id="cb48-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(boot_performance) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb48-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> bootstraps, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> boot_coverage, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> CI_type) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb48-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">49</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">199</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">399</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">transform =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reciprocal"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb48-6">  <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;">limits =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</span>(<span class="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="at" style="color: #657422;
background-color: null;
font-style: inherit;">sec.axis =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dup_axis</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;">""</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb48-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</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="cb48-8">  <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;">data =</span> perf, <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;">yintercept =</span> coverage), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkgrey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb48-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb48-10">  ggrepel<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_label_repel</span>(</span>
<span id="cb48-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> boot_performance_top, </span>
<span id="cb48-12">    <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> CI_type), </span>
<span id="cb48-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nudge_x =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.004</span></span>
<span id="cb48-14">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb48-15">  <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="cb48-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb48-17">  <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="cb48-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb48-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bootstraps (B)"</span>, </span>
<span id="cb48-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CI coverage rate"</span></span>
<span id="cb48-21">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/Bootstrap-CI-variations/index_files/figure-html/unnamed-chunk-29-1.png" class="img-fluid figure-img" style="width:100.0%"></p>
</figure>
</div>
</div>
</div>
<p>The studentized interval gets very close to the nominal coverage level with <img src="https://latex.codecogs.com/png.latex?B%20=%201999"> bootstraps. Surprisingly, BCa does not do nearly as well and is worse than the regular percentile interval.<br>
Perhaps this is because, for this simple problem, the extra machinery of the bias and acceleration corrections might not be needed or the corrections cannot be estimated accurately enough with a sample of this size.</p>
<p>Here’s the average widths of each variant:</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<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">boot_performance_bottom <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(boot_performance, bootstraps <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">49</span>)</span>
<span id="cb49-2"></span>
<span id="cb49-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(boot_performance) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb49-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> bootstraps, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> boot_width, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> CI_type) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb49-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">49</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">199</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">399</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">transform =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reciprocal"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb49-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> perf, <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;">yintercept =</span> width), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"darkgrey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb49-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb49-8">  ggrepel<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_label_repel</span>(</span>
<span id="cb49-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> boot_performance_bottom, </span>
<span id="cb49-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> CI_type), </span>
<span id="cb49-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nudge_x =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.004</span></span>
<span id="cb49-12">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb49-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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="cb49-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb49-15">  <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="cb49-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb49-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bootstraps (B)"</span>, </span>
<span id="cb49-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Average CI width"</span></span>
<span id="cb49-19">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/Bootstrap-CI-variations/index_files/figure-html/unnamed-chunk-30-1.png" class="img-fluid figure-img" style="width:100.0%"></p>
</figure>
</div>
</div>
</div>
<p>The near-nominal coverage rate for the studentized interval comes with an increased width. The percentile and basic CIs have identical widths because they’re based on the same percentiles, just used in different ways. Notably, the percentile interval has shorter average width than the bias-corrected or BCa intervals, even though it also has better coverage.</p>
</section>
<section id="timing" class="level2">
<h2 class="anchored" data-anchor-id="timing">Timing</h2>
<p>This particular problem is perhaps not the most compelling way illustrate Boos and Zhang’s extrapolation method because it would fairly simple to just compute a larger number of bootstraps and not worry about the complications of computing a bunch of extra CIs and extrapolating. Here’s some timing comparisons. First, the brute-force approach of just computing <img src="https://latex.codecogs.com/png.latex?B=1999"> bootstraps for each of 500 replications:</p>
<div class="cell">
<details open="" 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;">library</span>(tictoc)</span>
<span id="cb50-2"></span>
<span id="cb50-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tic</span>()</span>
<span id="cb50-4">perf_1999 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb50-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sim_cor</span>(</span>
<span id="cb50-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>, </span>
<span id="cb50-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>,</span>
<span id="cb50-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_vals =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>,</span>
<span id="cb50-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</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;">"normal"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"basic"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bias-corrected"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>)</span>
<span id="cb50-10">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb50-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(bs_CIs) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb50-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(</span>
<span id="cb50-13">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ends_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_lower"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ends_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_upper"</span>)),</span>
<span id="cb50-14">    <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="cb50-15">    <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;">"CI_type"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".value"</span>)</span>
<span id="cb50-16">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb50-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(CI_type) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb50-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb50-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">calc_coverage</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower_bound =</span> lower, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">upper_bound =</span> upper, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_param =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>)</span>
<span id="cb50-20">  )</span>
<span id="cb50-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toc</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>30.95 sec elapsed</code></pre>
</div>
</div>
<p>Compare that to doing 500 replications, each with 399 bootstraps but computing 5 confidence intervals each time and then extrapolating out to <img src="https://latex.codecogs.com/png.latex?B%20=%201999">:</p>
<div class="cell">
<details open="" 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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tic</span>()</span>
<span id="cb52-2">perf_extra <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb52-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sim_cor</span>(</span>
<span id="cb52-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>, </span>
<span id="cb52-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rho =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span>,</span>
<span id="cb52-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_vals =</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;">49</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">199</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">299</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">399</span>),</span>
<span id="cb52-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_type =</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;">"normal"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"student"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"basic"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"percentile"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bias-corrected"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BCa"</span>)</span>
<span id="cb52-8">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb52-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb52-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extrapolate_coverage</span>(</span>
<span id="cb52-11">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CI_subsamples =</span> bs_CIs, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">true_param =</span> rho, </span>
<span id="cb52-12">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_target =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>,</span>
<span id="cb52-13">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nested =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"long"</span></span>
<span id="cb52-14">    )</span>
<span id="cb52-15">  )</span>
<span id="cb52-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toc</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>11.28 sec elapsed</code></pre>
</div>
</div>
<p>There is some time savings, but perhaps not worth the extra hassle in this instance. The extrapolation method is much more useful when the statistic calculated on each bootstrap re-sample takes a relatively long time to compute, so that using only a fraction of the bootstraps (399 versus 1999, in this example) substantially reduces the total compute time.</p>


<!-- -->


</section>
</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" data-line-spacing="2">
<div id="ref-boos2000MonteCarloEvaluation" class="csl-entry">
Boos, D. D., &amp; Zhang, J. (2000). <span>Monte Carlo</span> evaluation of resampling-based hypothesis tests. <em>Journal of the American Statistical Association</em>, <em>95</em>(450), 486–492. <a href="https://doi.org/10.1080/01621459.2000.10474226">https://doi.org/10.1080/01621459.2000.10474226</a>
</div>
<div id="ref-bootpkg" class="csl-entry">
Canty, A., &amp; Ripley, B. D. (2024). <em>Boot: Bootstrap r (s-plus) functions</em>.
</div>
<div id="ref-Couch2021infer" class="csl-entry">
Couch, S. P., Bray, A. P., Ismay, C., Chasnovski, E., Baumer, B. S., &amp; Çetinkaya-Rundel, M. (2021). <span class="nocase">infer</span>: An <span>R</span> package for tidyverse-friendly statistical inference. <em>Journal of Open Source Software</em>, <em>6</em>(65), 3661. <a href="https://doi.org/10.21105/joss.03661">https://doi.org/10.21105/joss.03661</a>
</div>
<div id="ref-Davison1997bootstrap" class="csl-entry">
Davison, A. C., &amp; Hinkley, D. V. (1997). <em>Bootstrap methods and their applications</em>. Cambridge University Press. <a href="https://doi:10.1017/CBO9780511802843">doi:10.1017/CBO9780511802843</a>
</div>
<div id="ref-efron1987better" class="csl-entry">
Efron, B. (1987). Better bootstrap confidence intervals. <em>Journal of the American Statistical Association</em>, <em>82</em>(397), 171–185. <a href="https://doi.org/10.1080/01621459.1987.10478410">https://doi.org/10.1080/01621459.1987.10478410</a>
</div>
<div id="ref-rsamplepkg" class="csl-entry">
Frick, H., Chow, F., Kuhn, M., Mahoney, M., Silge, J., &amp; Wickham, H. (2024). <em>Rsample: General resampling infrastructure</em>.
</div>
</div></section></div> ]]></description>
  <category>programming</category>
  <category>Rstats</category>
  <category>bootstrap</category>
  <guid>https://jepusto.netlify.app/posts/Bootstrap-CI-variations/</guid>
  <pubDate>Wed, 15 Jan 2025 00:00:00 GMT</pubDate>
</item>
<item>
  <title>A quirk of nlme::varIdent</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/varIdent-function-in-nlme/</link>
  <description><![CDATA[ 





<p>The <code>nlme</code> package is a venerable, now quite old package for fitting hierarchical models in R. Compared to the better-known <code>lme4</code> package, <code>nlme</code> provides greater flexibility for specifying dependence structures at the finest-grain level of the model, such as allowing for heteroskedastic errors or correlated errors that follow an auto-regressive structure within each higher-level unit.<sup>1</sup> Due to its quite advanced age (the first entry in the changelog is from December 23, 1999!), it is perhaps not surprising that the package has a number of what one might call quirks—odd, counter-intuitive behaviors that are unlike the behavior of other core model-fitting functions in R. A few of my past posts have documented <a href="../..\posts/bug-in-nlme-getVarCov/">some</a> of <a href="../..\posts/Bug-in-nlme-with-fixed-sigma/">these quirks</a>. Here’s another one.</p>
<div class="no-row-height column-margin column-container"><div id="fn1"><p><sup>1</sup>&nbsp;<code>nlme</code> is a minor obsession for me because Several packages that I’ve worked on provide formal enhancements to or are at least very closely connected to it. The <a href="../..\software/clubSandwich/"><code>clubSandwich</code> package</a> provides cluster-robust standard errors for fitted models, and it supports models fitted with <code>nlme::lme()</code> and <code>nlme::gls()</code>. The <a href="../..\software/lmeInfo/"><code>lmeInfo</code> package</a> provides analytic derivatives for models fitted with <code>nlme::lme()</code> and <code>nlme::gls()</code>. The <a href="../..\software/scdhlm/"><code>scdhlm</code> package</a> for calculating effect sizes from single-case designs relies heavily on <code>nlme::lme()</code> and on <code>lmeInfo::g_mlm()</code>.</p></div></div><section id="varident" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="varident">varIdent()</h3>
<p>In <code>nlme</code>’s syntax, <code>varIdent()</code> is used to specify a model in which the variance of the lowest-level error term differs depending on a categorical covariate. I’ll call this a “heteroskedastic error” model. Say that we have repeated measures (indexed by <img src="https://latex.codecogs.com/png.latex?h">) nested within units (indexed by <img src="https://latex.codecogs.com/png.latex?i">), so that <img src="https://latex.codecogs.com/png.latex?y_%7Bhi%7D"> is measurement <img src="https://latex.codecogs.com/png.latex?h"> on unit <img src="https://latex.codecogs.com/png.latex?i"> for <img src="https://latex.codecogs.com/png.latex?h%20=%201,...,H_i"> and <img src="https://latex.codecogs.com/png.latex?i=1,...,N">. Let <img src="https://latex.codecogs.com/png.latex?c_%7Bhi%7D%20%5Cin%20%5C%7B1,...,C%5C%7D"> denote the category of observation <img src="https://latex.codecogs.com/png.latex?hi">, and suppose that the last category serves as a reference level. Say we have some model with predictors <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bx%7D_%7Bhi%7D"> and potentially also with random effects terms described by <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bz%7D_%7Bhi%7D">: <img src="https://latex.codecogs.com/png.latex?%0Ay_%7Bhi%7D%20=%20%5Cmathbf%7Bx%7D_%7Bhi%7D%20%5Cboldsymbol%5Cbeta%20+%20%5Cmathbf%7Bz%7D_%7Bhi%7D%20%5Cmathbf%7Bu%7D_i%20+%20e_%7Bhi%7D%0A"> where <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BVar%7D(e_%7Bhi%7D)%20=%20%5Csigma%5E2%20%5Ctimes%20%5Cexp%5Cleft(%20%5Csum_%7Bj=1%7D%5E%7BC-1%7D%20%5Clambda_j%20I(c_%7Bhi%7D%20=%20j)%5Cright).%0A"> The coefficients <img src="https://latex.codecogs.com/png.latex?%5Clambda_1,...,%5Clambda_%7BC-1%7D"> capture how the variance of errors in category <img src="https://latex.codecogs.com/png.latex?j"> differ from the variance of errors in category <img src="https://latex.codecogs.com/png.latex?C">. The question is, how can one control the reference level (i.e., choose which category is <img src="https://latex.codecogs.com/png.latex?C">) when fitting this model?</p>
<p>Let me give a few examples of models with this feature using <code>Orthodont</code>, one of the standard datasets included in the <code>nlme</code> package. Below I do a bit of tidying up on the factors in this dataset.</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 class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(nlme)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Orthodont"</span>)</span>
<span id="cb1-4"></span>
<span id="cb1-5">Orthodont <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb1-6">  Orthodont <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.frame</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb1-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">age =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>(age),</span>
<span id="cb1-10">    <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;">factor</span>(Subject, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(Subject)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordered =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>),</span>
<span id="cb1-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Sex_rev =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_rev</span>(Sex),</span>
<span id="cb1-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Sex3 =</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;">if_else</span>(</span>
<span id="cb1-13">      Subject <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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M11"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M12"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M13"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M14"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M15"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M16"</span>),</span>
<span id="cb1-14">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-binary"</span>, </span>
<span id="cb1-15">      Sex), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Female"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Male"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Non-binary"</span>)</span>
<span id="cb1-16">    )</span>
<span id="cb1-17">  )</span></code></pre></div></div>
</div>
<p>Here is a simple example of a heteroskedastic error model, without any random effects or any other bells or whistles.</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">gls1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gls</span>(</span>
<span id="cb2-2">  distance <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> Sex, </span>
<span id="cb2-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex),</span>
<span id="cb2-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont</span>
<span id="cb2-5">)</span>
<span id="cb2-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(gls1)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Generalized least squares fit by REML
  Model: distance ~ age + Sex 
  Data: Orthodont 
       AIC      BIC    logLik
  494.3251 507.5949 -242.1626

Variance function:
 Structure: Different standard deviations per stratum
 Formula: ~1 | Sex 
 Parameter estimates:
     Male    Female 
1.0000000 0.9378976 

Coefficients:
                Value Std.Error   t-value p-value
(Intercept) 17.811621 1.1119255 16.018718       0
age          0.650648 0.0975569  6.669421       0
SexFemale   -2.321023 0.4396048 -5.279794       0

 Correlation: 
          (Intr) age   
age       -0.965       
SexFemale -0.173  0.000

Standardized residuals:
        Min          Q1         Med          Q3         Max 
-2.58304984 -0.65117352 -0.02923653  0.51805238  2.30992386 

Residual standard error: 2.329342 
Degrees of freedom: 108 total; 105 residual</code></pre>
</div>
</div>
<p>The reference level of the variance structure is <code>Male</code>.<sup>2</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn2"><p><sup>2</sup>&nbsp;For ease of exposition, let me make a little helper function that pulls out the reference level of the variance structure.</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">ref_level <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>(mod) {</span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(mod<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>modelStruct<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>varStruct, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"groupNames"</span>)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb4-3">}</span>
<span id="cb4-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>(gls1)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Male"</code></pre>
</div>
</div>
</div></div><p>Here’s another <code>gls</code> model, this time allowing the errors to be correlated within subject:</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">gls2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb6-2">  gls1, </span>
<span id="cb6-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">correlation =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">corCompSymm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Subject)</span>
<span id="cb6-4">)</span>
<span id="cb6-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>(gls2)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
</div>
<p>The reference category has now changed to Female. The same thing happens if I fit a heteroskedastic error model using <code>lme()</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">lme1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lme</span>(</span>
<span id="cb8-2">  distance <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> Sex, </span>
<span id="cb8-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">random =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> Subject, </span>
<span id="cb8-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex),</span>
<span id="cb8-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont</span>
<span id="cb8-6">)</span>
<span id="cb8-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>(lme1)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
</div>
<p>It would be nice to be able to control the reference level.<sup>3</sup></p>
<div class="no-row-height column-margin column-container"><div id="fn3"><p><sup>3</sup>&nbsp;I’m not the only one seeking to do this. Someone on the R-SIG-mixed-models listserv <a href="https://stat.ethz.ch/pipermail/r-sig-mixed-models/2013q3/020572.html">had the same query</a> in July of 2013, but none of the responses provide a solution.</p></div></div></section>
<section id="what-doesnt-work" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="what-doesnt-work">What doesn’t work</h3>
<p>The usual way that one would specify reference levels is to set a contrast for the factor:</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;">contrasts</span>(Orthodont<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Sex) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contr.treatment</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;">base =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div></div>
</div>
<p>But this does not seem to have any effect on the selected reference level of the variance structures:</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;">update</span>(gls1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont) <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;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Male"</code></pre>
</div>
<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;">update</span>(gls2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont) <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;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(lme1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont) <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;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
</div>
<p>Nor does using a factor with the levels in reverse order:</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;">update</span>(gls1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex_rev)) <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;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Male"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(gls2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex_rev)) <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;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
<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;">update</span>(lme1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex_rev)) <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;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
</div>
<p>Emma Knight <a href="https://stat.ethz.ch/pipermail/r-sig-mixed-models/2013q3/020587.html">suggested on R-SIG-mixed-models</a> that the reference level is selected based on the category with the largest number of observations (which is <code>Male</code>). That could be what determines the reference level in <code>gls1</code> (though it clearly can’t be so for <code>gls2</code> or <code>lme</code>). I’ve created another factor called <code>Sex3</code> where the largest category is Female. If this theory is true, then the reference level of <code>gls1</code> should change to Female:</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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(gls1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3)) <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;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Male"</code></pre>
</div>
</div>
<p>Nothing changes with the other models either:</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(gls2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3)) <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;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(lme1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3)) <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;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
</div>
<p>What about the order of the data? There is <a href="https://bugs.r-project.org/show_bug.cgi?id=18505">a bug report</a> documenting that <code>varIdent()</code> depends on the sort order of the categorical grouping variable when used in a <code>gls()</code> call.<sup>4</sup> Sorting the data in descending order of <code>Sex3</code> does affect the reference level for <code>gls1</code>:</p>
<div class="no-row-height column-margin column-container"><div id="fn4"><p><sup>4</sup>&nbsp;This <a href="https://stackoverflow.com/questions/75929847/reference-category-in-varident-function-nlme-package-depends-on-data-order">StackOverflow question</a> notes the same issue and links to a patch from <a href="https://math.mcmaster.ca/~bolker/">Ben Bolker</a>.</p></div></div><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">Orthodont_sort <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(Orthodont, Sex3)</span>
<span id="cb29-2">Orthodont_rev <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(Orthodont, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(Sex3))</span>
<span id="cb29-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(Orthodont_sort<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Sex, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] Female Female Female Female
attr(,"contrasts")
       2
Male   0
Female 1
Levels: Male Female</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(Orthodont_rev<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Sex3, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] Non-binary Non-binary Non-binary Non-binary
Levels: Female Male Non-binary</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb33-2">  gls1, </span>
<span id="cb33-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont_sort</span>
<span id="cb33-4">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb33-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb35" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb35-2">  gls1, </span>
<span id="cb35-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3),</span>
<span id="cb35-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont_rev</span>
<span id="cb35-5">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb35-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Non-binary"</code></pre>
</div>
</div>
<p>However, this doesn’t seem to affect <code>gls2</code> or <code>lme1</code> at all:</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;">update</span>(</span>
<span id="cb37-2">  gls2, </span>
<span id="cb37-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont_sort</span>
<span id="cb37-4">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb37-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
<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;">update</span>(</span>
<span id="cb39-2">  gls2, </span>
<span id="cb39-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3), </span>
<span id="cb39-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont_rev</span>
<span id="cb39-5">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb39-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb41" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb41-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb41-2">  lme1, </span>
<span id="cb41-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont_sort</span>
<span id="cb41-4">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb41-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
<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;">update</span>(</span>
<span id="cb43-2">  lme1, </span>
<span id="cb43-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3), </span>
<span id="cb43-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont_rev</span>
<span id="cb43-5">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb43-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
</div>
<p>Very curious.</p>
</section>
<section id="how-to-control-the-reference-level" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="how-to-control-the-reference-level">How to control the reference level</h3>
<p>I <a href="https://stat.ethz.ch/pipermail/r-sig-mixed-models/2024q4/030737.html">posted about this issue</a> to R-SIG-mixed-models with some of the above notes. <a href="https://www.imbe.med.fau.de/lehrstuhl/sebastian-meyer/#collapse_0">Sebastian Meyer</a> provided a very helpful response, noting that</p>
<blockquote class="blockquote">
<p><code>lme()</code> internally reorders the data by the grouping factor(s) before initialization, so the order of that factor (‘Subject’ in your example…) will indirectly determine the reference level of varIdent(), regardless of how your data or strata levels are ordered originally.</p>
</blockquote>
<p>Similar re-ordering behavior occurs in <code>gls()</code> when the model includes a grouping structure, as it does in <code>gls2</code> because of the <code>corCompSymm()</code> correlation structure. This insight provides a key for controlling the reference level: for a given categorical variable, the reference level will be taken as the level of the first observation in the first level of the grouping factor. Thus, for models with grouping structure, one can set the reference level to Male by re-ordering the levels of <code>Subject</code> so that a unit with <code>Sex = 'Male'</code> occurs first.</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">Orthodont<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Subject2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_relevel</span>(Orthodont<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Subject, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M01"</span>)</span>
<span id="cb45-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(Orthodont<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Subject2) <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;">head</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>
M01 F01 F02 F03 F04 F05 
  4   4   4   4   4   4 </code></pre>
</div>
<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;">update</span>(</span>
<span id="cb47-2">  gls2, </span>
<span id="cb47-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">correlation =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">corCompSymm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Subject2)</span>
<span id="cb47-4">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb47-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Male"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb49" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb49-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb49-2">  lme1, </span>
<span id="cb49-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">random =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> Subject2</span>
<span id="cb49-4">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb49-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Male"</code></pre>
</div>
</div>
<p>For models without grouping structure, the reference level is indeed controlled by sort order, as if there were only a single group. To control the reference level, one would need to sort the data accordingly. For example, to make Female the reference level in <code>gls1</code>, the first observation in the data needs to have <code>Sex = 'Female'</code>. This is so in <code>Orthodont_sort</code>:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb51" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb51-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(gls1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont_sort) <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;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
</div>
<p>What if the categorical variable varies within the grouping factor? For instance, say that we want to fit a model with heteroskedastic errors varying by age of the subject, which varies from 8 to 14 across the repeated measures of each participant. Here’s a basic heteroskedastic error <code>gls()</code>:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb53" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb53-1">gls3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gls</span>(</span>
<span id="cb53-2">  distance <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> Sex, </span>
<span id="cb53-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> age),</span>
<span id="cb53-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont</span>
<span id="cb53-5">)</span></code></pre></div></div>
</div>
<p>And here is one with a correlation structure:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb54" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb54-1">gls4 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb54-2">  gls3, </span>
<span id="cb54-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">correlation =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">corCompSymm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Subject)</span>
<span id="cb54-4">)</span></code></pre></div></div>
</div>
<p>In both cases, the reference level is the youngest age:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb55" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb55-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>(gls3), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>(gls4))</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "8" "8"</code></pre>
</div>
</div>
<p>To set this to something else in the first model, just re-arrange the first few rows:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb57" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb57-1">Orthodont2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> Orthodont[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">108</span>),]</span>
<span id="cb57-2"></span>
<span id="cb57-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb57-4">  gls3, </span>
<span id="cb57-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont2</span>
<span id="cb57-6">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb57-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "14"</code></pre>
</div>
</div>
<p>However, this doesn’t work for <code>gls4</code><sup>5</sup> because the first level of the grouping factor is not the first one to appear in the data.<sup>6</sup> But we could sort the data by the grouping factor and then by <code>age</code> so that the desired reference level appears first:</p>
<div class="no-row-height column-margin column-container"><div id="fn5"><p><sup>5</sup>&nbsp;See</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb59" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb59-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(gls4, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont2) <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;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "8"</code></pre>
</div>
</div>
</div><div id="fn6"><p><sup>6</sup>&nbsp;The first level of <code>Subject</code> corresponds to rows 65 through 68:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb61" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb61-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(Orthodont2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Subject)[<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> Orthodont2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Subject)  </span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 65 66 67 68</code></pre>
</div>
</div>
</div></div><div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb63" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb63-1">Orthodont2_sort <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb63-2">  Orthodont <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb63-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(Subject, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">desc</span>(age))</span>
<span id="cb63-4"></span>
<span id="cb63-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(Orthodont2_sort)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>   distance age Subject    Sex Sex_rev   Sex3 Subject2
68     23.0  14     F01 Female  Female Female      F01
67     21.5  12     F01 Female  Female Female      F01
66     20.0  10     F01 Female  Female Female      F01
65     21.0   8     F01 Female  Female Female      F01
72     25.5  14     F02 Female  Female Female      F02
71     24.0  12     F02 Female  Female Female      F02</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb65" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb65-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(gls4, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Orthodont2_sort) <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;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "14"</code></pre>
</div>
</div>
<p>It’s not elegant, nor particularly intuitive, but it seems to work.</p>
</section>
<section id="setting-a-value" class="level3">
<h3 class="anchored" data-anchor-id="setting-a-value">Setting a <code>value</code></h3>
<p>Sebastian also suggested another technique for directly controlling the reference level of the variance structure:</p>
<blockquote class="blockquote">
<p>It seems that only if there are more than two strata, the reference level for varIdent() can be chosen via a named initial parameter ‘value’, leaving out the desired reference level, but I haven’t tested if this works as intended with both gls() and lme(). It would then make sense to support such a choice also in the case of only two strata, so for a single parameter.</p>
</blockquote>
<p>Setting the argument <code>value</code> of <code>varIdent()</code> specifies initialization values for the variance structure. Sebastian’s suggestion is to specify values for every level of the categorical variable except for the desired reference level. Let me give this a try with the <code>Sex3</code> variable, which has three distinct levels.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb67" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb67-1">gls_M <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb67-2">  gls1, </span>
<span id="cb67-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3)</span>
<span id="cb67-4">)</span>
<span id="cb67-5"></span>
<span id="cb67-6">gls_F <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb67-7">  gls1, </span>
<span id="cb67-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(</span>
<span id="cb67-9">    <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;">c</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;">Non-binary</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Male =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>), </span>
<span id="cb67-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3</span>
<span id="cb67-11">  )</span>
<span id="cb67-12">)</span>
<span id="cb67-13"></span>
<span id="cb67-14">gls_NB <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb67-15">  gls1, </span>
<span id="cb67-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(</span>
<span id="cb67-17">    <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;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Female =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Male =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>), </span>
<span id="cb67-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3</span>
<span id="cb67-19">  )</span>
<span id="cb67-20">)</span>
<span id="cb67-21"></span>
<span id="cb67-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(gls_M<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>modelStruct<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>varStruct, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">unconstrained =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Non-binary     Female 
 0.7438755  0.8608531 </code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb69" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb69-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(gls_F<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>modelStruct<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>varStruct, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">unconstrained =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Non-binary       Male 
  0.864114   1.161639 </code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb71" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb71-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coef</span>(gls_NB<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>modelStruct<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>varStruct, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">unconstrained =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>  Female     Male 
1.157254 1.344311 </code></pre>
</div>
</div>
<p>Indeed, this works for models with variance structures but no correlation structures or random effects. Likewise for <code>gls</code> models that include grouping structure:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb73" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb73-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb73-2">  gls2, </span>
<span id="cb73-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3)</span>
<span id="cb73-4">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb73-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb75" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb75-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb75-2">  gls2, </span>
<span id="cb75-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(</span>
<span id="cb75-4">    <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;">c</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;">Non-binary</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Female =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>), </span>
<span id="cb75-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3</span>
<span id="cb75-6">  )</span>
<span id="cb75-7">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb75-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Male"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb77" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb77-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb77-2">  gls2, </span>
<span id="cb77-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(</span>
<span id="cb77-4">    <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;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Female =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Male =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>), </span>
<span id="cb77-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3</span>
<span id="cb77-6">  )</span>
<span id="cb77-7">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb77-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Non-binary"</code></pre>
</div>
</div>
<p>And for <code>lme</code> models with random effects:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb79" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb79-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(lme1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb79-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb81" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb81-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb81-2">  lme1, </span>
<span id="cb81-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(</span>
<span id="cb81-4">    <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;">c</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;">Non-binary</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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Female =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>), </span>
<span id="cb81-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3</span>
<span id="cb81-6">  )</span>
<span id="cb81-7">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb81-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Male"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb83" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb83-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb83-2">  lme1, </span>
<span id="cb83-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(</span>
<span id="cb83-4">    <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;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Female =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Male =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>), </span>
<span id="cb83-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex3</span>
<span id="cb83-6">  )</span>
<span id="cb83-7">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb83-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Non-binary"</code></pre>
</div>
</div>
<p>However, as Sebastian noted, it does not work for categories with only two levels (so only one non-reference level):</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb85" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb85-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb85-2">  gls1, </span>
<span id="cb85-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(</span>
<span id="cb85-4">    <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;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Male =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>), </span>
<span id="cb85-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex</span>
<span id="cb85-6">  )</span>
<span id="cb85-7">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb85-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Male"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb87" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb87-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb87-2">  gls2, </span>
<span id="cb87-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(</span>
<span id="cb87-4">    <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;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Female =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>), </span>
<span id="cb87-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex</span>
<span id="cb87-6">  )</span>
<span id="cb87-7">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb87-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb89" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb89-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>(</span>
<span id="cb89-2">  lme1, </span>
<span id="cb89-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weights =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">varIdent</span>(</span>
<span id="cb89-4">    <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;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Female =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span>), </span>
<span id="cb89-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">form =</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> Sex</span>
<span id="cb89-6">  )</span>
<span id="cb89-7">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb89-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ref_level</span>()</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Female"</code></pre>
</div>
</div>
<p>Thus, this is only a partial solution. I agree with Sebastian that it would be useful to support user-specified levels within the <code>value</code> argument, even for factors with just one non-reference level.</p>
</section>
<section id="colophon" class="level3">
<h3 class="anchored" data-anchor-id="colophon">Colophon</h3>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb91" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb91-1">sessioninfo<span 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.4.1 (2024-06-14 ucrt)
 os       Windows 11 x64 (build 22631)
 system   x86_64, mingw32
 ui       RTerm
 language (EN)
 collate  English_United States.utf8
 ctype    English_United States.utf8
 tz       America/Chicago
 date     2024-12-28
 pandoc   3.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────
 ! package     * version date (UTC) lib source
 P cli           3.6.3   2024-06-21 [?] RSPM
 P colorspace    2.1-1   2024-07-26 [?] RSPM
 P digest        0.6.37  2024-08-19 [?] RSPM (R 4.4.0)
 P dplyr       * 1.1.4   2023-11-17 [?] RSPM
 P evaluate      0.23    2023-11-01 [?] RSPM (R 4.4.0)
 P fansi         1.0.6   2023-12-08 [?] RSPM
 P fastmap       1.1.1   2023-02-24 [?] RSPM (R 4.4.0)
 P forcats     * 1.0.0   2023-01-29 [?] RSPM
 P generics      0.1.3   2022-07-05 [?] RSPM
 P ggplot2     * 3.5.1   2024-04-23 [?] RSPM
 P glue          1.8.0   2024-09-30 [?] RSPM (R 4.4.0)
 P gtable        0.3.6   2024-10-25 [?] RSPM (R 4.4.0)
 P hms           1.1.3   2023-03-21 [?] RSPM
 P htmltools     0.5.7   2023-11-03 [?] RSPM (R 4.4.1)
 P htmlwidgets   1.6.4   2023-12-06 [?] RSPM
 P jsonlite      1.8.8   2023-12-04 [?] RSPM
 P knitr         1.47    2024-05-29 [?] RSPM (R 4.4.0)
 P lattice       0.22-5  2023-10-24 [?] RSPM (R 4.4.1)
 P lifecycle     1.0.4   2023-11-07 [?] RSPM
 P lubridate   * 1.9.3   2023-09-27 [?] RSPM
 P magrittr      2.0.3   2022-03-30 [?] RSPM
 P munsell       0.5.1   2024-04-01 [?] RSPM
 P nlme        * 3.1-166 2024-08-14 [?] RSPM
 P pillar        1.9.0   2023-03-22 [?] RSPM
 P pkgconfig     2.0.3   2019-09-22 [?] RSPM
 P purrr       * 1.0.2   2023-08-10 [?] RSPM
 P R6            2.5.1   2021-08-19 [?] RSPM
 P readr       * 2.1.5   2024-01-10 [?] RSPM
   renv          1.0.5   2024-02-29 [1] RSPM (R 4.4.0)
 P rlang         1.1.4   2024-06-04 [?] RSPM
 P rmarkdown     2.27    2024-05-17 [?] RSPM
 P rstudioapi    0.17.1  2024-10-22 [?] RSPM (R 4.4.0)
 P scales        1.3.0   2023-11-28 [?] RSPM
 P sessioninfo   1.2.2   2021-12-06 [?] RSPM (R 4.4.0)
 P stringi       1.8.4   2024-05-06 [?] RSPM
 P stringr     * 1.5.1   2023-11-14 [?] RSPM
 P tibble      * 3.2.1   2023-03-20 [?] RSPM
 P tidyr       * 1.3.1   2024-01-24 [?] RSPM
 P tidyselect    1.2.1   2024-03-11 [?] RSPM
 P tidyverse   * 2.0.0   2023-02-22 [?] RSPM
 P timechange    0.3.0   2024-01-18 [?] RSPM
 P tzdb          0.4.0   2023-05-12 [?] RSPM
 P utf8          1.2.4   2023-10-22 [?] RSPM
 P vctrs         0.6.5   2023-12-01 [?] RSPM
   withr         3.0.2   2024-10-28 [1] RSPM (R 4.4.0)
 P xfun          0.45    2024-06-16 [?] RSPM (R 4.4.0)
 P yaml          2.3.8   2023-12-11 [?] RSPM (R 4.4.0)

 [1] C:/Users/jamespustejovsky/Documents/jepusto-quarto/renv/library/R-4.4/x86_64-w64-mingw32
 [2] C:/Users/jamespustejovsky/AppData/Local/R/cache/R/renv/sandbox/R-4.4/x86_64-w64-mingw32/e0da0d43

 P ── Loaded and on-disk path mismatch.

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


<!-- -->

</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Rstats</category>
  <category>programming</category>
  <category>hierarchical models</category>
  <category>nlme</category>
  <guid>https://jepusto.netlify.app/posts/varIdent-function-in-nlme/</guid>
  <pubDate>Sat, 28 Dec 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Beta-density selection models for meta-analysis</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/beta-density-selection-models/</link>
  <description><![CDATA[ 





<p>I still have meta-analytic selection models on the brain. As part of <a href="https://ies.ed.gov/funding/grantsearch/details.asp?ID=5730">an IES-funded project</a> with <a href="https://www.air.org/mosaic/experts">colleagues from the American Institutes for Research</a>, I’ve been working on developing methods for estimating selection models that can accommodate dependent effect sizes. We’re looking at two variations of p-value selection models: step-function selection models similar to those proposed by <span class="citation" data-cites="hedges1992modeling">Hedges (1992)</span> and <span class="citation" data-cites="vevea1995general">Vevea &amp; Hedges (1995)</span> and beta-density models as developed in <span class="citation" data-cites="Citkowicz2017parsimonious">Citkowicz &amp; Vevea (2017)</span>. Both models fall within the broader class of <img src="https://latex.codecogs.com/png.latex?p">-value selection models, which make explicit assumptions about the probability of observing an effect size, given its statistical significance level and sign. I’ve already described how step-function models work (see <a href="../..\posts/step-function-selection-models/">this previous post</a>) and, as a bit of a detour, I also took a stab at demystifying the <a href="../..\posts/Copas-selection-models">Copas selection model</a>. In this post, I’ll look at the beta-density model, highlight how it differs from step-function models, and do a deep dive into some of the tweaks to the model that we’ve implemented as part of the project.</p>
<section id="the-beta-density-selection-model" class="level1 page-columns page-full">
<h1>The beta-density selection model</h1>
<p>The beta-density selection model is another entry in the class of <img src="https://latex.codecogs.com/png.latex?p">-value selection models. Like the step-function model, it consists of a set of assumptions about how effect size estimates are generated prior to selection (the <em>evidence-generation process</em>), and a set of assumptions about how selective reporting happens as a function of the effect size estimates (the <em>selective reporting process</em>). In both the beta-density and step-function models, the evidence-generating process is a random effects model: <span id="eq-evidence-generation"><img src="https://latex.codecogs.com/png.latex?%0AT_i%5E*%20%7C%20%5Csigma_i%5E*%20%5Csim%20N%5Cleft(%5Cmu,%20%5Ctau%5E2%20+%20%5Cleft(%5Csigma_i%5E*%5Cright)%5E2%5Cright),%0A%5Ctag%7B1%7D"></span> where <img src="https://latex.codecogs.com/png.latex?T_i%5E*"> denotes an effect size estimate prior to selective reporting and <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*"> denotes its (known) standard error.<sup>1</sup></p>
<p>The only difference between the beta-density and step-function selection models is the functional form of the selective reporting process. Letting <img src="https://latex.codecogs.com/png.latex?O_i%5E*"> be an indicator equal to 1 if <img src="https://latex.codecogs.com/png.latex?T_i%5E*"> is reported and <img src="https://latex.codecogs.com/png.latex?p_i%5E*%20=%201%20-%20%5CPhi%5Cleft(T_i%5E*%20/%20%5Csigma_i%5E*%5Cright)"> be the one-sided p-value corresponding to the effect size estimate, the selective reporting process describes the shape of <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D(O_i%5E*%20=%201%20%7C%20p_i%5E*)">. The step-function model uses a piece-wise constant function with level shifts at analyst-specified significance thresholds (see Figure&nbsp;1). The beta-density model instead uses…wait for it…a beta density kernel function, which can take on a variety of smooth shapes over the unit interval (see Figure&nbsp;2).</p>
<div class="column-body-outset quarto-layout-panel" data-layout-ncol="2">
<div class="quarto-layout-row">
<div class="cell quarto-layout-cell" style="flex-basis: 50.0%;justify-content: flex-start;">
<div class="cell-output-display">
<div id="fig-step-fun" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-step-fun-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://jepusto.netlify.app/posts/beta-density-selection-models/index_files/figure-html/fig-step-fun-1.png" class="img-fluid figure-img" width="480">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-step-fun-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Two-step selection model with <img src="https://latex.codecogs.com/png.latex?%5Clambda_1%20=%200.6,%20%5Clambda_2%20=%200.4">
</figcaption>
</figure>
</div>
</div>
</div>
<div class="cell quarto-layout-cell" style="flex-basis: 50.0%;justify-content: flex-start;">
<div class="cell-output-display">
<div id="fig-beta-dens" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-beta-dens-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://jepusto.netlify.app/posts/beta-density-selection-models/index_files/figure-html/fig-beta-dens-1.png" class="img-fluid figure-img" width="480">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-beta-dens-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Beta-density selection model with <img src="https://latex.codecogs.com/png.latex?%5Clambda_1%20=%200.5,%20%5Clambda_2%20=%200.8">
</figcaption>
</figure>
</div>
</div>
</div>
</div>
</div>
<p>In the original formulation of the beta density model, the selection function is given by <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D(O_i%5E*%20=%201%20%7C%20p_i%5E*)%20%5Cpropto%20%5Cleft(p_i%5E*%5Cright)%5E%7B(%5Clambda_1%20-%201)%7D%20%5Cleft(1%20-%20p_i%5E*%5Cright)%5E%7B(%5Clambda_2%20-%201)%7D,%0A"> where the parameters <img src="https://latex.codecogs.com/png.latex?%5Clambda_1"> and <img src="https://latex.codecogs.com/png.latex?%5Clambda_2"> must be strictly greater than zero, and <img src="https://latex.codecogs.com/png.latex?%5Clambda_1%20=%20%5Clambda_2%20=%201"> corresponds to a constant probability of selection (i.e., no selective reporting bias). Because <img src="https://latex.codecogs.com/png.latex?p_i%5E*"> is a function of the effect size estimate and its standard error, the selection function can also be written as <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D(O_i%5E*%20=%201%20%7C%20T_i%5E*,%20%5Csigma_i%5E*)%20%5Cpropto%20%5Cleft%5B%5CPhi(-T_i%5E*%20/%20%5Csigma_i%5E*)%5Cright%5D%5E%7B(%5Clambda_1%20-%201)%7D%20%5Cleft%5B%5CPhi(T_i%5E*%20/%20%5Csigma_i%5E*)%5Cright%5D%5E%7B(%5Clambda_2%20-%201)%7D,%0A"> where <img src="https://latex.codecogs.com/png.latex?%5CPhi()"> is the cumulative standard normal distribution. In proposing the model, <span class="citation" data-cites="Citkowicz2017parsimonious">Citkowicz &amp; Vevea (2017)</span> argued that the beta-density function provides a parsimonious expression of more complex forms of selective reporting than can easily be captured by a step function. For instance, the beta density in Figure&nbsp;2 is smoothly declining from <img src="https://latex.codecogs.com/png.latex?p%20%3C%20.005"> through the psychologically salient thresholds <img src="https://latex.codecogs.com/png.latex?p%20=%20.025"> and <img src="https://latex.codecogs.com/png.latex?p%20=%20.05"> and beyond. In order to approximate such a smooth curve with a step function, one would have to use many thresholds and therefore many more than the two parameters of the beta density.</p>
</section>
<section id="a-truncated-beta-density" class="level1">
<h1>A truncated beta-density</h1>
<p>Although using smoothly varying selection probabilities may seem appealing, the beta density also comes with an important limitation, highlighted in a commentary by <span class="citation" data-cites="hedges2017plausibility">Hedges (2017)</span>. For some parameter values, the beta density implies selection probabilities that differ by many orders of magnitude. These extreme differences in selection probability can imply implausible selection processes, in which hundreds of non-significant effect size estimates would need to go unreported to observe a sample of a few dozen findings. Extreme differences in selection probabilities make the model highly sensitive to the inclusion or exclusion of some effect size estimates because the influence of each estimate is driven by the inverse of its selection probability <span class="citation" data-cites="hedges2017plausibility">(Hedges, 2017)</span>.</p>
<p>As a means to mitigate these issues with the beta density, we consider a modification of the model where the function is truncated at <img src="https://latex.codecogs.com/png.latex?p">-values larger or smaller than certain thresholds. For user-specified thresholds <img src="https://latex.codecogs.com/png.latex?%5Calpha_1"> and <img src="https://latex.codecogs.com/png.latex?%5Calpha_2">, let <img src="https://latex.codecogs.com/png.latex?%5Ctilde%7Bp%7D_i%5E*%20=%20%5Cmin%5C%7B%5Cmax%5C%7B%5Calpha_1,%20p_i%5E*%5C%7D,%20%5Calpha_2%5C%7D">. The truncated beta density is then <span id="eq-selection-process"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D(O_i%5E*%20=%201%20%7C%20p_i%5E*)%20%5Cpropto%20(%5Ctilde%7Bp%7D_i%5E*)%5E%7B(%5Clambda_1%20-%201)%7D%20%5Cleft(1%20-%20%5Ctilde%7Bp%7D_i%5E*%5Cright)%5E%7B(%5Clambda_2%20-%201)%7D,%0A%5Ctag%7B2%7D"></span> Setting the truncation thresholds at psychologically salient levels such as <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.025"> and <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%20.975"> (which correspond to positive and negative effects that are statistically significant based on two-sided tests with <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20.05">) gives something kind of like the step-function selection model, but with smoothly varying selection probabilities in the interior. Alternately, one could set the second threshold at <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%20.500"> (corresponding to an effect of zero) so that all negative effect size estimates have a constant probability of selection, but positive effect size estimates that are non-significant have smoothly varying selection probabilities up to the point where <img src="https://latex.codecogs.com/png.latex?p_i%5E*%20=%20.025">.</p>
</section>
<section id="distribution-of-observed-effect-sizes" class="level1 page-columns page-full">
<h1>Distribution of observed effect sizes</h1>
<p>Just as with the step-function selection model, the assumptions of the evidence-generating process (1) and the selection process (2) can be combined to obtain the distribution of observed effect sizes, with <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5CPr(T_i%20=%20t%20%7C%20%5Csigma_i)%20&amp;%5Cpropto%20%5CPr%5Cleft(O_i%5E*%20=%201%7C%20T_i%5E*%20=%20t,%20%5Csigma_i%5E*%20=%20%5Csigma_i%5Cright)%20%5Ctimes%20%5CPr(T_i%5E*%20%20=%20t%7C%20%5Csigma_i%5E*%20=%20%5Csigma_i)%20%5C%5C%0A&amp;%5Cpropto%20%5Cleft%5B%5CPhi(-t%20/%20%5Csigma_i%5E*)%5Cright%5D%5E%7B(%5Clambda_1%20-%201)%7D%20%5Cleft%5B%5CPhi(t%20/%20%5Csigma_i%5E*)%5Cright%5D%5E%7B(%5Clambda_2%20-%201)%7D%20%5Ctimes%20%5Cfrac%7B1%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%7D%20%5Cphi%5Cleft(%5Cfrac%7Bt%20-%20%5Cmu%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%7D%5Cright)%0A%5Cend%7Baligned%7D%0A"></p>
<p>Here is an interactive graph showing the distribution of the effects prior to selection (in grey) and the distribution of observed effect sizes (in blue) based on the truncated beta-density selection model. Initially, the truncation points are set at <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.025"> and <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%20.975"> and the selection parameters are set to <img src="https://latex.codecogs.com/png.latex?%5Clambda_1%20=%200.5"> and <img src="https://latex.codecogs.com/png.latex?%5Clambda_2%20=%200.8">, but you can change these however you like. Below the effect size distribution are the moments of the distribution (computed numerically) and a graph of the truncated beta density that determines the selection probabilities.</p>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb1" data-startfrom="135" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 134;"><span id="cb1-135">math <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">require</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mathjs"</span>)</span>
<span id="cb1-136">norm <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://unpkg.com/norm-dist@3.1.0/index.js?module'</span>)</span>
<span id="cb1-137"></span>
<span id="cb1-138"><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;">findprob</span>(p<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alp1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alp2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lam1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lam2) {</span>
<span id="cb1-139">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> p_ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> 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;">min</span>(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;">max</span>(p<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alp1)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alp2)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-140">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> prob <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (p_)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span>(lam1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> p_)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span>(lam2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-141">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> prob<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-142">}</span>
<span id="cb1-143"></span>
<span id="cb1-144">eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> 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;">sqrt</span>(tau<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-145"></span>
<span id="cb1-146">max_p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb1-147">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (lambda1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> lambda2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) {</span>
<span id="cb1-148">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> (lambda1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (lambda1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> lambda2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-149">  } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (lambda1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> lambda2) {</span>
<span id="cb1-150">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> alpha2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-151">  } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb1-152">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> alpha1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-153">  }</span>
<span id="cb1-154">}</span>
<span id="cb1-155"></span>
<span id="cb1-156">max_prob <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findprob</span>(max_p<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda2)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-6" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb2" data-startfrom="161" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 160;"><span id="cb2-161">pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">201</span></span>
<span id="cb2-162"></span>
<span id="cb2-163">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(pts)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</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;">map</span>((element<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> index) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-164">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> index <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-165">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> norm<span 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>(t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> sigma)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-166">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> dt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> norm<span 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>((t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-167">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> prob <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findprob</span>(p<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda2)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-168">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> ({</span>
<span id="cb2-169">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">t</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-170">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">d_unselected</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> dt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-171">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">d_selected</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> prob <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> dt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> max_prob</span>
<span id="cb2-172">  })</span>
<span id="cb2-173">})</span>
<span id="cb2-174"></span>
<span id="cb2-175">selfundat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(pts)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</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;">map</span>((element<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> index) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-176">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> index <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-177">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> prob <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findprob</span>(p<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda2)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-178">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> ({</span>
<span id="cb2-179">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> p<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-180">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">prob</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> prob</span>
<span id="cb2-181">  })</span>
<span id="cb2-182">})</span>
<span id="cb2-183"></span>
<span id="cb2-184">moments <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb2-185">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> prob <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-186">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> ET <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-187">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> ET2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-188">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> pts<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) {</span>
<span id="cb2-189">    prob <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> dat[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d_selected</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-190">    ET <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> dat[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> dat[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d_selected</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-191">    ET2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> dat[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> dat[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">d_selected</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-192">  }</span>
<span id="cb2-193">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> ET_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ET <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> prob<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-194">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> VT_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ET2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> prob <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> ET_val<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-195">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> ({</span>
<span id="cb2-196">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Ai</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> prob <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-197">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">ET</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> ET_val<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-198">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">SDT</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> 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;">sqrt</span>(VT_val)</span>
<span id="cb2-199">  })</span>
<span id="cb2-200">}</span>
<span id="cb2-201"></span>
<span id="cb2-202">eta_toprint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> eta<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb2-203">Ai_toprint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> moments<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Ai</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb2-204">ET_toprint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> moments<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ET</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb2-205">SDT_toprint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> moments<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SDT</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-8" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="grid column-page">
<div class="g-col-8 center">
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb3" data-startfrom="213" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 212;"><span id="cb3-213">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb3-214">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-215">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">700</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-216">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb3-217">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-218">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span></span>
<span id="cb3-219">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-220">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb3-221">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Effect size estimate (Ti)"</span></span>
<span id="cb3-222">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>   </span>
<span id="cb3-223">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb3-224">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-225">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-226">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">areaY</span>(dat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d_unselected"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-227">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">areaY</span>(dat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d_selected"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-228">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(dat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d_selected"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>})</span>
<span id="cb3-229">  ]</span>
<span id="cb3-230">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="expression">

</div>
</div>
</div>
<div class="grid">
<div class="g-col-4 moments">
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb4" data-startfrom="238" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 237;"><span id="cb4-238"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb4-239"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\b</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">egin{aligned}</span></span>
<span id="cb4-240"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\P</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">r(O_i^* = 1) &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>Ai_toprint<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span></span>
<span id="cb4-241"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">u &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>mu<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span></span>
<span id="cb4-242"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">athbb{E}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">eft(T_i</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ight) &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>ET_toprint<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb4-243"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\e</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ta_i &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>eta_toprint<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span></span>
<span id="cb4-244"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\s</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">qrt{</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">athbb{V}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">eft(T_i</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ight)} &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>SDT_toprint<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-245"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\e</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">nd{aligned}`</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="expression">

</div>
</div>
</div>
</div>
<div class="g-col-8 center">
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb5" data-startfrom="253" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 252;"><span id="cb5-253">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb5-254">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-255">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">400</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-256">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb5-257">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-258">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Selection probability"</span></span>
<span id="cb5-259">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-260">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb5-261">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p-value (one-sided)"</span></span>
<span id="cb5-262">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>   </span>
<span id="cb5-263">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb5-264">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-265">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-266">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">areaY</span>(selfundat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"prob"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-267">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(selfundat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"p"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"prob"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>})</span>
<span id="cb5-268">  ]</span>
<span id="cb5-269">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="expression">

</div>
</div>
</div>
</div>
</div>
</div>
<div class="g-col-4">
<div class="cell panel-input card bg-light p-2">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb6" data-startfrom="284" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 283;"><span id="cb6-284">viewof mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb6-285">  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb6-286">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">u`</span>}</span>
<span id="cb6-287">)</span>
<span id="cb6-288"></span>
<span id="cb6-289">viewof tau <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb6-290">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb6-291">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\t</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">au`</span>}</span>
<span id="cb6-292">)</span>
<span id="cb6-293"></span>
<span id="cb6-294">viewof sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb6-295">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb6-296">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.20</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\s</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">igma_i`</span>}</span>
<span id="cb6-297">)</span>
<span id="cb6-298"></span>
<span id="cb6-299">viewof alpha1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb6-300">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-301">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.005</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\a</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">lpha_1`</span>}</span>
<span id="cb6-302">)</span>
<span id="cb6-303"></span>
<span id="cb6-304">viewof alpha2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb6-305">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-306">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.005</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\a</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">lpha_2`</span>}</span>
<span id="cb6-307">)</span>
<span id="cb6-308"></span>
<span id="cb6-309">viewof lambda1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb6-310">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-311">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.50</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ambda_1`</span>}</span>
<span id="cb6-312">)</span>
<span id="cb6-313"></span>
<span id="cb6-314">viewof lambda2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb6-315">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-316">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.80</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ambda_2`</span>}</span>
<span id="cb6-317">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-7" data-nodetype="declaration">

</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section id="empirical-example" class="level1 page-columns page-full">
<h1>Empirical example</h1>
<p><span class="citation" data-cites="Citkowicz2017parsimonious">Citkowicz &amp; Vevea (2017)</span> presented an example of a meta-analysis where applying the original form of the beta-density selection model led to dramatically different findings from the summary meta-analysis. The data come from a synthesis by <span class="citation" data-cites="baskerville2012systematic">Baskerville et al. (2012)</span> that examined the effects of practice facilitation on the uptake of evidence-based practices (EBPs) in primary care settings. The original meta-analysis found a large average effect indicating that facilitation improves adoption of EBPs, although there were also indications of publication bias based on an Egger’s regression test. Fitting the beta-density model leads to much smaller effects. However, <span class="citation" data-cites="hedges2017plausibility">Hedges (2017)</span> criticized the beta-density results as involving an implausibly large degree of selection and noted that the estimated average effect is very sensitive to high-influence observations. Does using a more strongly truncated beta density change this picture? I’ll first work through the previously presented analyses, then examine the extent to which introducing truncation points for the beta density affects the model estimates.</p>
<section id="summary-random-effects-model" class="level2">
<h2 class="anchored" data-anchor-id="summary-random-effects-model">Summary random effects model</h2>
<p>Here are the random effects meta-analysis results, estimated using maximum likelihood for consistency with subsequent modeling:</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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tibble)</span>
<span id="cb7-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(dplyr)</span>
<span id="cb7-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyr)</span>
<span id="cb7-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(metafor)</span>
<span id="cb7-5"></span>
<span id="cb7-6">Baskerville <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tribble</span>(</span>
<span id="cb7-7">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> SMD, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> V, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> Blinded,</span>
<span id="cb7-8">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.01</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2704</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span>,</span>
<span id="cb7-9">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.82</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2116</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'O'</span>,</span>
<span id="cb7-10">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.59</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0529</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'O'</span>,</span>
<span id="cb7-11">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.44</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0324</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'O'</span>,</span>
<span id="cb7-12">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.84</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0841</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span>,</span>
<span id="cb7-13">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.73</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0841</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'O'</span>,</span>
<span id="cb7-14">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.12</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1296</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span>,</span>
<span id="cb7-15">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.04</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1369</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span>,</span>
<span id="cb7-16">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.24</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0225</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'O'</span>,</span>
<span id="cb7-17">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.32</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1600</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'O'</span>,</span>
<span id="cb7-18">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.04</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1024</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'O'</span>,</span>
<span id="cb7-19">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.31</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3249</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span>,</span>
<span id="cb7-20">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.59</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0841</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span>,</span>
<span id="cb7-21">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.66</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0361</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'O'</span>,</span>
<span id="cb7-22">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.62</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0961</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span>,</span>
<span id="cb7-23">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.47</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0729</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span>,</span>
<span id="cb7-24">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.08</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1024</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'O'</span>,</span>
<span id="cb7-25">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.98</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1024</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span>,</span>
<span id="cb7-26">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.26</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0324</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span>,</span>
<span id="cb7-27">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.39</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0324</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span>,</span>
<span id="cb7-28">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.60</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0961</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span>,</span>
<span id="cb7-29">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.94</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2809</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span>,</span>
<span id="cb7-30">  <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.11</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.0729</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'B'</span></span>
<span id="cb7-31">)</span>
<span id="cb7-32"></span>
<span id="cb7-33">RE_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rma</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yi =</span> SMD, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vi =</span> V, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Baskerville, <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;">"ML"</span>)</span>
<span id="cb7-34">RE_fit</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
Random-Effects Model (k = 23; tau^2 estimator: ML)

tau^2 (estimated amount of total heterogeneity): 0.0162 (SE = 0.0236)
tau (square root of estimated tau^2 value):      0.1274
I^2 (total heterogeneity / total variability):   18.64%
H^2 (total variability / sampling variability):  1.23

Test for Heterogeneity:
Q(df = 22) = 27.5518, p-val = 0.1910

Model Results:

estimate      se    zval    pval   ci.lb   ci.ub      
  0.5552  0.0633  8.7751  &lt;.0001  0.4312  0.6792  *** 

---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</code></pre>
</div>
</div>
<p>The average effect estimate is <img src="https://latex.codecogs.com/png.latex?%5Chat%5Cmu%20=%200.555">, with a 95% CI of <img src="https://latex.codecogs.com/png.latex?%5B0.431,%200.679%5D">. Here is a funnel plot of the effect size estimates against standard errors, with contours indicating regions of statistical significance for positive and negative estimates:</p>
<div class="cell">
<details class="code-fold">
<summary>Code</summary>
<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;">par</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mar=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb9-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">funnel</span>(RE_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refline =</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-display">
<div id="fig-funnel" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-funnel-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://jepusto.netlify.app/posts/beta-density-selection-models/index_files/figure-html/fig-funnel-1.png" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-funnel-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: Funnel plot of effect size estimates from the Baskerville meta-analysis
</figcaption>
</figure>
</div>
</div>
</div>
<p>There’s clearly asymmetry in the funnel plot, which can be an indication of selective reporting.</p>
</section>
<section id="original-beta-density-model" class="level2">
<h2 class="anchored" data-anchor-id="original-beta-density-model">Original beta-density model</h2>
<p><span class="citation" data-cites="Citkowicz2017parsimonious">Citkowicz &amp; Vevea (2017)</span> fit the original form of the beta-density model to the data. This is now quite easy to do with the <code>metafor</code> package:</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">beta_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selmodel</span>(RE_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"beta"</span>)</span>
<span id="cb10-2">beta_fit</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
Random-Effects Model (k = 23; tau^2 estimator: ML)

tau^2 (estimated amount of total heterogeneity): 0.0000
tau (square root of estimated tau^2 value):      0.0016

Test for Heterogeneity:
LRT(df = 1) = 0.0088, p-val = 0.9252

Model Results:

estimate      se    zval    pval    ci.lb   ci.ub    
  0.1147  0.1664  0.6895  0.4905  -0.2114  0.4409    

Test for Selection Model Parameters:
LRT(df = 2) = 7.8469, p-val = 0.0198

Selection Model Results:

         estimate      se     zval    pval   ci.lb   ci.ub    
delta.1    0.4731  0.2352  -2.2397  0.0251  0.0120  0.9342  * 
delta.2    4.4613  2.1842   1.5847  0.1130  0.1803  8.7423    

---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</code></pre>
</div>
</div>
<p>The overall average effect size in the un-selected population is now estimated to be <img src="https://latex.codecogs.com/png.latex?%5Chat%5Cmu%20=%200.115">, 95% CI <img src="https://latex.codecogs.com/png.latex?%5B-0.211,%200.441%5D">, with selection parameters (called <img src="https://latex.codecogs.com/png.latex?%5Cdelta_1"> and <img src="https://latex.codecogs.com/png.latex?%5Cdelta_2"> in metafor) estimated as <img src="https://latex.codecogs.com/png.latex?%5Chat%5Clambda_1%20=%200.473"> and <img src="https://latex.codecogs.com/png.latex?%5Chat%5Clambda_2%20=%204.461">.</p>
<p>The same model can also be fit using our <code>metaselection</code> package:</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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(metaselection)</span>
<span id="cb12-2">Baskerville<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>se <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(Baskerville<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>V)</span>
<span id="cb12-3">Baskerville<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>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;">with</span>(Baskerville, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pnorm</span>(SMD <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> se, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lower.tail =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>))</span>
<span id="cb12-4"></span>
<span id="cb12-5">beta_sel <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selection_model</span>(</span>
<span id="cb12-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> Baskerville,</span>
<span id="cb12-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yi =</span> SMD,</span>
<span id="cb12-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sei =</span> se,</span>
<span id="cb12-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">selection_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"beta"</span>,</span>
<span id="cb12-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</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;">1e-5</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;">1e-5</span>),</span>
<span id="cb12-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vcov_type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"model-based"</span></span>
<span id="cb12-12">)</span>
<span id="cb12-13"></span>
<span id="cb12-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(beta_sel)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Beta Density Model 
 
Call: 
selection_model(data = Baskerville, yi = SMD, sei = se, selection_type = "beta", 
    steps = c(1e-05, 1 - 1e-05), vcov_type = "model-based")

Number of effects = 23

Steps: 1e-05, 0.99999 
Estimator: maximum likelihood 
Variance estimator: model-based 

Log composite likelihood of selection model: -2.79229

Mean effect estimates:                                        
                            Large Sample
 Coef. Estimate Std. Error  Lower  Upper
  beta    0.115      0.166 -0.211   0.44

Heterogeneity estimates:                                            
                              Large   Sample
 Coef. Estimate Std. Error    Lower    Upper
  tau2 3.79e-11   1.38e-20 3.79e-11 3.79e-11

Selection process estimates:                                          
                              Large Sample
    Coef. Estimate Std. Error Lower  Upper
 lambda_1    0.473      0.235 0.179   1.25
 lambda_2    4.461      2.184 1.709  11.65</code></pre>
</div>
</div>
<p>I will stick with the <code>metaselection</code> package for subsequent analysis because it allows the user to specify their own truncation points for the beta-density model. It also has some helper functions such as <code>selection_plot()</code> for graphing the estimated selection function:</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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selection_plot</span>(beta_sel, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ref_pval =</span> Baskerville<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">14</span>]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb14-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)) <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;">theme_minimal</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/beta-density-selection-models/index_files/figure-html/unnamed-chunk-13-1.png" class="img-fluid figure-img" style="width:70.0%"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="hedges-critiques" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="hedges-critiques">Hedges’ critiques</h2>

<div class="no-row-height column-margin column-container"><div class="">
<div class="cell">
<div id="tbl-selection-probs" 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-selection-probs-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1: Probabilities of selection relative to <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D(O_i%20=%201%20%5Cvert%20p_i%20=%20.0005)">
</figcaption>
<div aria-describedby="tbl-selection-probs-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<table class="do-not-create-environment cell caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?p_i"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D(O_i%20=%201%20%5Cvert%20p_i)"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">0.001</td>
<td style="text-align: right;">0.693</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.005</td>
<td style="text-align: right;">0.293</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.010</td>
<td style="text-align: right;">0.200</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.025</td>
<td style="text-align: right;">0.117</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.050</td>
<td style="text-align: right;">0.074</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.100</td>
<td style="text-align: right;">0.043</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.500</td>
<td style="text-align: right;">0.002</td>
</tr>
</tbody>
</table>
</div>
</div>
</figure>
</div>
</div>
</div></div><p><span class="citation" data-cites="hedges2017plausibility">Hedges (2017)</span> noted that the beta-density model for these data generates very extreme selection probabilities. Following along with his numerical example, Table&nbsp;1 reports the probability of observing effects for several different <img src="https://latex.codecogs.com/png.latex?p">-values, relative to the probability of observing a highly significant effect with <img src="https://latex.codecogs.com/png.latex?p%20=%20.0005">. Notably, based on the estimated selection function, an effect with one-sided <img src="https://latex.codecogs.com/png.latex?p_i%20=%20.0005"> is over eight times more likely to be reported than an effect with <img src="https://latex.codecogs.com/png.latex?p%20=%20.025"> and nearly 500 times more likely to be reported than an effect of zero with <img src="https://latex.codecogs.com/png.latex?p_i%20=%20.500">. Quoth <span class="citation" data-cites="hedges2017plausibility">Hedges (2017)</span>: “This seems like an extraordinarily high degree of selection” (p.&nbsp;43).</p>
<p>Hedges goes on to explain how the estimated selection parameters can be used to infer the total number of effect sizes that would need to be <em>generated</em> in order to obtain a sample of <img src="https://latex.codecogs.com/png.latex?k%20=%2023"> observed effect sizes. The calculation involves the quantity <img src="https://latex.codecogs.com/png.latex?%0AA_i%20=%20%5Ctext%7BPr%7D(O_i%5E*%20=%201%20%7C%20%5Csigma_i%5E*)%20=%20%5Ctext%7BE%7D%5Cleft%5B%5Cleft.%5CPr%5Cleft(O_i%5E*%20=%201%7C%20p_i%5E*%5Cright)%20%5Cright%7C%20%5Csigma_i%5E*%5Cright%5D,%0A"> which is the overall probability of observing an effect size estimate in a study with standard error <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*">.<sup>2</sup> The inverse of <img src="https://latex.codecogs.com/png.latex?A_i"> is the expected number of effect size estimates that would need to be generated (including both those that are subsequently reported and those that remain unreported) in order to obtain one observed estimate. A challenge here is that the selective reporting process is only identified up to a proportionality constant, so the <em>absolute</em> probability of reporting cannot be estimated without making some further assumption. Hedges approaches this by assuming that any effect size estimate with <img src="https://latex.codecogs.com/png.latex?p">-value equal to the smallest observed <img src="https://latex.codecogs.com/png.latex?p">-value will be reported with certainty, so that the proportionality constant becomes <img src="https://latex.codecogs.com/png.latex?w_%7Bmin%7D%20=%20(p_%7Bmin%7D)%5E%7B%5Clambda_1%20-%201%7D%20(1%20-%20p_%7Bmin%7D)%5E%7B%5Clambda_2%20-%201%7D">. Under this assumption, estimates of <img src="https://latex.codecogs.com/png.latex?A_i"> can be computed given the parameter estimates <img src="https://latex.codecogs.com/png.latex?%5Chat%5Cmu">, <img src="https://latex.codecogs.com/png.latex?%5Chat%5Ctau">, <img src="https://latex.codecogs.com/png.latex?%5Chat%5Clambda_1">, <img src="https://latex.codecogs.com/png.latex?%5Chat%5Clambda_2"> and the reference <img src="https://latex.codecogs.com/png.latex?p">-value <img src="https://latex.codecogs.com/png.latex?p_%7Bmin%7D">. Taking the sum across the sample of observed standard errors, we can find an estimate of the number of effect sizes that would need to be generated: <img src="https://latex.codecogs.com/png.latex?%0Ak_%7Bgen%7D%20=%20%5Csum_%7Bi=1%7D%5E%7Bk%7D%20%5Cfrac%7B1%7D%7B%5Chat%7BA%7D_i%7D.%0A"></p>
<p>My attempt to reproduce the calculations in Table 1 of <span class="citation" data-cites="hedges2017plausibility">Hedges (2017)</span> are displayed in Table&nbsp;2 below Columns <img src="https://latex.codecogs.com/png.latex?T_i"> and <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> are the effect size estimates and standard errors reported by <span class="citation" data-cites="baskerville2012systematic">Baskerville et al. (2012)</span>; <img src="https://latex.codecogs.com/png.latex?p_i"> is the one-sided <img src="https://latex.codecogs.com/png.latex?p">-value calculated from the data. The column labeled <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bw%7D(p_i)"> is the relative selection probability calculated from the estimated selection parameters <img src="https://latex.codecogs.com/png.latex?%5Chat%5Clambda_1%20=%200.473,%20%5Chat%5Clambda_2%20=%204.461">; the next column reports the same quantities, standardized by the relative probability of observation 14, which has the smallest reported <img src="https://latex.codecogs.com/png.latex?p">-value of <img src="https://latex.codecogs.com/png.latex?p_%7Bmin%7D%20=%202.6%5Ctimes%2010%5E%7B-4%7D">. Using the beta-density parameter estimates and standardizing to the minimum observed <img src="https://latex.codecogs.com/png.latex?p">-value, I calculate the probability of observing effect size estimates with each observed standard error. The inverse of this quantity is the number of generated effect sizes one would need to produce a single observed effect size estimate; it is reported in the column labeled <img src="https://latex.codecogs.com/png.latex?%5Chat%7BA%7D_i%5E%7B-1%7D">. Totalling these, I find <img src="https://latex.codecogs.com/png.latex?k_%7Bgen%7D%20=%20972">.<sup>3</sup> This implies quite a large number of missing studies that were conducted but not reported; Hedges argues that it is so large as to be implausible.</p>
<div class="cell">
<div id="tbl-Hedges-Table1" 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-Hedges-Table1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;2: Effect size estimates and computed values for beta density selection model estimated on Baskerville meta-analysis data
</figcaption>
<div aria-describedby="tbl-Hedges-Table1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output-display">
<table class="do-not-create-environment cell caption-top table table-sm table-striped small">
<colgroup>
<col style="width: 5%">
<col style="width: 5%">
<col style="width: 10%">
<col style="width: 5%">
<col style="width: 14%">
<col style="width: 32%">
<col style="width: 16%">
<col style="width: 10%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: right;">Study</th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?T_i"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?%5Csigma_i"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?p_i"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?%5Chat%7Bw%7D(p_i)"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?%5Chat%7Bw%7D(p_i)%20/%20%5Chat%7Bw%7D(p_%7Bmin%7D)"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?%5Chat%7BA%7D_i%5E%7B-1%7D"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?%5Comega_i"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">1</td>
<td style="text-align: right;">1.01</td>
<td style="text-align: right;">0.52</td>
<td style="text-align: right;">0.026</td>
<td style="text-align: right;">6.237</td>
<td style="text-align: right;">0.080</td>
<td style="text-align: right;">56.484</td>
<td style="text-align: right;">0.014</td>
</tr>
<tr class="even">
<td style="text-align: right;">2</td>
<td style="text-align: right;">0.82</td>
<td style="text-align: right;">0.46</td>
<td style="text-align: right;">0.037</td>
<td style="text-align: right;">4.957</td>
<td style="text-align: right;">0.064</td>
<td style="text-align: right;">53.788</td>
<td style="text-align: right;">0.018</td>
</tr>
<tr class="odd">
<td style="text-align: right;">3</td>
<td style="text-align: right;">0.59</td>
<td style="text-align: right;">0.23</td>
<td style="text-align: right;">0.005</td>
<td style="text-align: right;">15.760</td>
<td style="text-align: right;">0.202</td>
<td style="text-align: right;">35.335</td>
<td style="text-align: right;">0.006</td>
</tr>
<tr class="even">
<td style="text-align: right;">4</td>
<td style="text-align: right;">0.44</td>
<td style="text-align: right;">0.18</td>
<td style="text-align: right;">0.007</td>
<td style="text-align: right;">13.069</td>
<td style="text-align: right;">0.168</td>
<td style="text-align: right;">28.034</td>
<td style="text-align: right;">0.007</td>
</tr>
<tr class="odd">
<td style="text-align: right;">5</td>
<td style="text-align: right;">0.84</td>
<td style="text-align: right;">0.29</td>
<td style="text-align: right;">0.002</td>
<td style="text-align: right;">27.073</td>
<td style="text-align: right;">0.348</td>
<td style="text-align: right;">42.016</td>
<td style="text-align: right;">0.003</td>
</tr>
<tr class="even">
<td style="text-align: right;">6</td>
<td style="text-align: right;">0.73</td>
<td style="text-align: right;">0.29</td>
<td style="text-align: right;">0.006</td>
<td style="text-align: right;">14.622</td>
<td style="text-align: right;">0.188</td>
<td style="text-align: right;">42.016</td>
<td style="text-align: right;">0.006</td>
</tr>
<tr class="odd">
<td style="text-align: right;">7</td>
<td style="text-align: right;">1.12</td>
<td style="text-align: right;">0.36</td>
<td style="text-align: right;">0.001</td>
<td style="text-align: right;">39.385</td>
<td style="text-align: right;">0.506</td>
<td style="text-align: right;">47.834</td>
<td style="text-align: right;">0.002</td>
</tr>
<tr class="even">
<td style="text-align: right;">8</td>
<td style="text-align: right;">0.04</td>
<td style="text-align: right;">0.37</td>
<td style="text-align: right;">0.457</td>
<td style="text-align: right;">0.183</td>
<td style="text-align: right;">0.002</td>
<td style="text-align: right;">48.536</td>
<td style="text-align: right;">0.485</td>
</tr>
<tr class="odd">
<td style="text-align: right;">9</td>
<td style="text-align: right;">0.24</td>
<td style="text-align: right;">0.15</td>
<td style="text-align: right;">0.055</td>
<td style="text-align: right;">3.800</td>
<td style="text-align: right;">0.049</td>
<td style="text-align: right;">22.676</td>
<td style="text-align: right;">0.023</td>
</tr>
<tr class="even">
<td style="text-align: right;">10</td>
<td style="text-align: right;">0.32</td>
<td style="text-align: right;">0.40</td>
<td style="text-align: right;">0.212</td>
<td style="text-align: right;">0.994</td>
<td style="text-align: right;">0.013</td>
<td style="text-align: right;">50.483</td>
<td style="text-align: right;">0.089</td>
</tr>
<tr class="odd">
<td style="text-align: right;">11</td>
<td style="text-align: right;">1.04</td>
<td style="text-align: right;">0.32</td>
<td style="text-align: right;">0.001</td>
<td style="text-align: right;">50.764</td>
<td style="text-align: right;">0.652</td>
<td style="text-align: right;">44.724</td>
<td style="text-align: right;">0.002</td>
</tr>
<tr class="even">
<td style="text-align: right;">12</td>
<td style="text-align: right;">1.31</td>
<td style="text-align: right;">0.57</td>
<td style="text-align: right;">0.011</td>
<td style="text-align: right;">10.481</td>
<td style="text-align: right;">0.135</td>
<td style="text-align: right;">58.376</td>
<td style="text-align: right;">0.008</td>
</tr>
<tr class="odd">
<td style="text-align: right;">13</td>
<td style="text-align: right;">0.59</td>
<td style="text-align: right;">0.29</td>
<td style="text-align: right;">0.021</td>
<td style="text-align: right;">7.123</td>
<td style="text-align: right;">0.091</td>
<td style="text-align: right;">42.016</td>
<td style="text-align: right;">0.012</td>
</tr>
<tr class="even">
<td style="text-align: right;">14</td>
<td style="text-align: right;">0.66</td>
<td style="text-align: right;">0.19</td>
<td style="text-align: right;">0.000</td>
<td style="text-align: right;">77.873</td>
<td style="text-align: right;">1.000</td>
<td style="text-align: right;">29.647</td>
<td style="text-align: right;">0.001</td>
</tr>
<tr class="odd">
<td style="text-align: right;">15</td>
<td style="text-align: right;">0.62</td>
<td style="text-align: right;">0.31</td>
<td style="text-align: right;">0.023</td>
<td style="text-align: right;">6.777</td>
<td style="text-align: right;">0.087</td>
<td style="text-align: right;">43.861</td>
<td style="text-align: right;">0.013</td>
</tr>
<tr class="even">
<td style="text-align: right;">16</td>
<td style="text-align: right;">0.47</td>
<td style="text-align: right;">0.27</td>
<td style="text-align: right;">0.041</td>
<td style="text-align: right;">4.666</td>
<td style="text-align: right;">0.060</td>
<td style="text-align: right;">39.997</td>
<td style="text-align: right;">0.019</td>
</tr>
<tr class="odd">
<td style="text-align: right;">17</td>
<td style="text-align: right;">1.08</td>
<td style="text-align: right;">0.32</td>
<td style="text-align: right;">0.000</td>
<td style="text-align: right;">64.286</td>
<td style="text-align: right;">0.826</td>
<td style="text-align: right;">44.724</td>
<td style="text-align: right;">0.001</td>
</tr>
<tr class="even">
<td style="text-align: right;">18</td>
<td style="text-align: right;">0.98</td>
<td style="text-align: right;">0.32</td>
<td style="text-align: right;">0.001</td>
<td style="text-align: right;">36.113</td>
<td style="text-align: right;">0.464</td>
<td style="text-align: right;">44.724</td>
<td style="text-align: right;">0.002</td>
</tr>
<tr class="odd">
<td style="text-align: right;">19</td>
<td style="text-align: right;">0.26</td>
<td style="text-align: right;">0.18</td>
<td style="text-align: right;">0.074</td>
<td style="text-align: right;">3.011</td>
<td style="text-align: right;">0.039</td>
<td style="text-align: right;">28.034</td>
<td style="text-align: right;">0.029</td>
</tr>
<tr class="even">
<td style="text-align: right;">20</td>
<td style="text-align: right;">0.39</td>
<td style="text-align: right;">0.18</td>
<td style="text-align: right;">0.015</td>
<td style="text-align: right;">8.631</td>
<td style="text-align: right;">0.111</td>
<td style="text-align: right;">28.034</td>
<td style="text-align: right;">0.010</td>
</tr>
<tr class="odd">
<td style="text-align: right;">21</td>
<td style="text-align: right;">0.60</td>
<td style="text-align: right;">0.31</td>
<td style="text-align: right;">0.026</td>
<td style="text-align: right;">6.176</td>
<td style="text-align: right;">0.079</td>
<td style="text-align: right;">43.861</td>
<td style="text-align: right;">0.014</td>
</tr>
<tr class="even">
<td style="text-align: right;">22</td>
<td style="text-align: right;">0.94</td>
<td style="text-align: right;">0.53</td>
<td style="text-align: right;">0.038</td>
<td style="text-align: right;">4.893</td>
<td style="text-align: right;">0.063</td>
<td style="text-align: right;">56.885</td>
<td style="text-align: right;">0.018</td>
</tr>
<tr class="odd">
<td style="text-align: right;">23</td>
<td style="text-align: right;">0.11</td>
<td style="text-align: right;">0.27</td>
<td style="text-align: right;">0.342</td>
<td style="text-align: right;">0.414</td>
<td style="text-align: right;">0.005</td>
<td style="text-align: right;">39.997</td>
<td style="text-align: right;">0.214</td>
</tr>
</tbody>
</table>
</div>
</div>
</figure>
</div>
</div>
<p>Another, related limitation of the beta density model is that it puts extreme emphasis on a few individual observations that have low probability of selection. <span class="citation" data-cites="hedges2017plausibility">Hedges (2017)</span> noted that the influence of individual observations can be approximated by the inverse selection probabilities, such that the fraction of the total weight allocated to observation <img src="https://latex.codecogs.com/png.latex?i"> is <img src="https://latex.codecogs.com/png.latex?%0A%5Comega_i%20=%20%5Cfrac%7B1%20/%20%5Chat%7Bw%7D(p_i)%7D%7B%5Csum_%7Bj=1%7D%5Ek%201%20/%20%5Chat%7Bw%7D(p_j)%7D.%0A"> The last column of Table&nbsp;2 reports these relative weights. As Hedges noted, the overall average effect is strongly influenced by just two observations: study 8, which has approximately 49% of the weight, and study 23, which has approximately 21% of the weight.</p>
</section>
<section id="sensitivity-to-truncation-points" class="level2">
<h2 class="anchored" data-anchor-id="sensitivity-to-truncation-points">Sensitivity to truncation points</h2>
<p>Does introducing truncation points into the beta density selection function change this picture in any meaningful way? My intuition is that using truncation points connected to psychologically salient thresholds (such as <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.025"> and <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%20.50"> or <img src="https://latex.codecogs.com/png.latex?.975">) should tend to moderate things in terms of both the implied overall degree of selection and the degree to which individual observations influence the model results. Here’s what happens if I use truncation points corresponding to the usual 2-sided significance threshold of <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20.05">:</p>
<div class="cell">
<div class="cell-output cell-output-stdout">
<pre><code>Beta Density Model 
 
Call: 
selection_model(data = Baskerville, yi = SMD, sei = se, selection_type = "beta", 
    steps = c(0.025, 0.975), vcov_type = "model-based")

Number of effects = 23

Steps: 0.025, 0.975 
Estimator: maximum likelihood 
Variance estimator: model-based 

Log composite likelihood of selection model: -1.94561

Mean effect estimates:                                        
                            Large Sample
 Coef. Estimate Std. Error  Lower  Upper
  beta    0.188      0.437 -0.669   1.05

Heterogeneity estimates:                                          
                              Large Sample
 Coef. Estimate Std. Error    Lower  Upper
  tau2   0.0574      0.122 0.000874   3.77

Selection process estimates:                                               
                                 Large   Sample
    Coef. Estimate Std. Error    Lower    Upper
 lambda_1 3.41e-09   2.81e-17 3.41e-09 3.41e-09
 lambda_2 1.74e+00   2.10e+00 1.63e-01 1.86e+01</code></pre>
</div>
</div>
<p>Under the truncated beta density, the estimated average effect size increases to <img src="https://latex.codecogs.com/png.latex?%5Chat%5Cmu%20=%200.188">, but with much greater uncertainty, 95% CI <img src="https://latex.codecogs.com/png.latex?%5B-0.669,%201.046%5D">. Contributing to this additional uncertainty is the larger estimate of between-study heterogeneity, <img src="https://latex.codecogs.com/png.latex?%5Ctau%5E2%20=%20%200.057">. The selection parameters are now estimated as <img src="https://latex.codecogs.com/png.latex?%5Chat%5Clambda_1%20%5Capprox%200"> and <img src="https://latex.codecogs.com/png.latex?%5Chat%5Clambda_2%20=%201.741">.</p>
<div class="cell">
<div class="cell-output-display">
<div id="fig-selection-functions" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-selection-functions-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://jepusto.netlify.app/posts/beta-density-selection-models/index_files/figure-html/fig-selection-functions-1.png" class="img-fluid figure-img" style="width:80.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-selection-functions-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: Estimated selection function under the truncated beta density model (green) and original beta density model (blue).
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;4 is a graph of the estimated selection function. The green area is the selection function based on the truncated beta density model; for reference, the blue area is the selection function from the previous, untruncated model. The model with truncation points does indicate a more moderate degree of selective reporting, although it still represents a fairly strong degree of selection. The estimated selection parameters imply that <img src="https://latex.codecogs.com/png.latex?k_%7Bgen%7D%20=%2089"> effect sizes would need to have been generated to produce a sample of 23 observed effects—this is large but not nearly so far outside the realm of plausible as with the untruncated beta density.</p>
<p>To get a more systematic sense of how sensitive the results are to the use of truncation points, I re-estimated the model many times with a range of different truncation points. For the left-hand truncation, I looked at <img src="https://latex.codecogs.com/png.latex?%5Calpha_1"> ranging from <img src="https://latex.codecogs.com/png.latex?10%5E%7B-5%7D"> to <img src="https://latex.codecogs.com/png.latex?10%5E%7B-2%7D"> and then also <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.025"> and <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.05">; for every one of these values, I looked at two different right-hand truncation points, first setting <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%201%20-%20%5Calpha_1"> and then fixing <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%20.5">. With each model, I tracked the maximum log-likelihood, estimated mean and variance of the effects prior to selective reporting, and the total number of generated effects (<img src="https://latex.codecogs.com/png.latex?k_%7Bgen%7D">) implied by the fitted model. The results are depicted in Figure&nbsp;5.</p>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div id="fig-parameter-sensitivity" class="quarto-float quarto-figure quarto-figure-center anchored" data-fig-align="center">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-parameter-sensitivity-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://jepusto.netlify.app/posts/beta-density-selection-models/index_files/figure-html/fig-parameter-sensitivity-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" style="width:100.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-parameter-sensitivity-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: Sensitivity analysis for the beta density model across varying truncation points
</figcaption>
</figure>
</div>
</div>
</div>
<p>In the top left-hand panel of Figure&nbsp;5, it can be seen that the estimate of <img src="https://latex.codecogs.com/png.latex?k_%7Bgen%7D"> is <em>strongly</em> influenced by the truncation point. Models with <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%202%20%5Ctimes%2010%5E%7B-4%7D"> and neighboring truncation points produce extremely high estimates, with <img src="https://latex.codecogs.com/png.latex?k_%7Bgen%7D%20%3E%202500">. Models with more psychologically relevant truncation points of <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.01"> or <img src="https://latex.codecogs.com/png.latex?.025"> lead to much more moderated estimates with <img src="https://latex.codecogs.com/png.latex?k_%7Bgen%7D%20%3C%20150">. The top right-hand panel shows the log-likelihood of models with different truncation points. Models where <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%201%20-%20%5Calpha_1"> consistently have higher likelihood than those with the right-hand truncation point fixed to <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%20.5">. Of those examined, the truncation point with the highest overall likelihood is <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%205%20%5Ctimes%2010%5E%7B-4%7D">, which is rather curious. The bottom panels of Figure&nbsp;5 depict the parameter estimates <img src="https://latex.codecogs.com/png.latex?%5Chat%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Chat%5Ctau%5E2">; <img src="https://latex.codecogs.com/png.latex?%5Chat%5Cmu"> is fairly sensitive to the choice of truncation point, though <img src="https://latex.codecogs.com/png.latex?%5Chat%5Ctau%5E2"> is sensitive only for larger truncation points of <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20%5Cgeq%20.01">.</p>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div id="fig-weight-sensitivity" class="quarto-float quarto-figure quarto-figure-center anchored" data-fig-align="center">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-weight-sensitivity-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://jepusto.netlify.app/posts/beta-density-selection-models/index_files/figure-html/fig-weight-sensitivity-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" style="width:100.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-weight-sensitivity-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6: Sensitivity of approximate weights <img src="https://latex.codecogs.com/png.latex?%5Comega_i"> under the beta density model across varying truncation points
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;6 plots the fraction of the total weight (i.e., the <img src="https://latex.codecogs.com/png.latex?%5Comega_i"> values for each effect size) assigned to each effect size as a function of the left-hand truncation point; the left panel shows the weights when <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%201%20-%20%5Calpha_1"> and the right panel shows the same quantities from the slightly lower-likelihood models with <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%200.5">. Across both panels, the highest-influence observation (Study <img src="https://latex.codecogs.com/png.latex?i%20=%208">) becomes less so when <img src="https://latex.codecogs.com/png.latex?%5Calpha_1"> is set to higher truncation points. When <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.025">, it receives 35% of the total weight, compared to almost 50% in the untruncated model. Still, it remains strongly influential. The next-most influential observation (Study <img src="https://latex.codecogs.com/png.latex?i%20=%2023">) has a fairly stable weight across all truncation points, and the third-most influential observation (Study <img src="https://latex.codecogs.com/png.latex?i%20=%2010">) grows moreso for higher truncation points. Even in the model with truncation points <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.025,%20%5Calpha_2%20=%20.975">, these three points still account for 69% of the total weight.</p>
<p>Looking across all of the model outputs, it seems that adding truncation points to the beta density is consequential, in that the model results are generally sensitive to the specific truncation points chosen. In this example, using psychologically salient truncation points led to less extreme estimates of selection, with less implausible implications, but also yieleded estimates that are still strongly influenced by a few data points.</p>
</section>
</section>
<section id="comments" class="level1">
<h1>Comments</h1>
<p>The re-analysis that I have presented is, of course, just one example of how the truncated beta density selection model might be applied—other datasets will have different features and might show a different degree of sensitivity to the truncation points. Still, this exercise has got me thinking about what more is needed to actually use meta-analytic selection models in practice. For one, I like the <img src="https://latex.codecogs.com/png.latex?k_%7Bgen%7D"> statistic and think it’s pretty evocative. For a proper analysis, it should come with measures of uncertainty, so working out a standard error and confidence interval to go along with the point estimate seems useful and necessary.</p>
<p>For another, it seems to me that there’s a need for more thinking, tools, and guidance about how to choose a model specification (…how to <em>select</em> a selection model, if you will…) and assess its fit and appropriateness. The <img src="https://latex.codecogs.com/png.latex?k_%7Bgen%7D"> statistic is one tool for building some intuition about a selection model. <span class="citation" data-cites="hedges1992modeling">Hedges (1992)</span> suggests another, which is to examine the distribution of <img src="https://latex.codecogs.com/png.latex?p">-values in the observed sample and consider whether and how it differs from the distribution of reported p-values implied by a fitted model.<sup>4</sup> I think there might be still other diagnostics that could be worth exploring. For instance, one could use the reporting probabilities from the estimated selection model to estimate not only the <em>total</em> number of generated studies, but also the distribution of standard errors in the evidence base prior to selective reporting. Here’s a hacky attempt at representing this:</p>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div id="fig-SE-distribution" class="quarto-float quarto-figure quarto-figure-center anchored" data-fig-align="center">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-SE-distribution-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://jepusto.netlify.app/posts/beta-density-selection-models/index_files/figure-html/fig-SE-distribution-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" style="width:60.0%">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-SE-distribution-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;7: Distribution of standard errors across observed effect sizes and across all generated effect sizes (observed and unreported)
</figcaption>
</figure>
</div>
</div>
</div>
<p>The green density shows the distribution of standard errors for the 23 reported effect sizes. The larger grey density shows the distribution of standard errors for all <em>generated</em> effect sizes, as implied by the truncated beta density model. The plot suggests that many of the unobserved effect sizes would be from relatively larger studies (with standard errors of 0.3 or less), even though the probability of going unreported is larger for smaller studies. Other interesting diagnostics might be to consider how <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BE%7D(T_i%20%7C%20O_i%5E*%20=%201,%20%5Csigma_i)"> varies with <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> or how <img src="https://latex.codecogs.com/png.latex?A_i%20=%20%5Ctext%7BPr%7D(O_i%5E*%20=%201%20%7C%20%5Csigma_i)"> varies with <img src="https://latex.codecogs.com/png.latex?%5Csigma_i">.</p>
<p>Finally, pulling out a bit, working through this stuff has only reinforced my sense that there’s still a real need for guidance about how to examine selective reporting bias in actual, empirical meta-analysis projects. Right now, it feels to me like the methodological literature is kind of a mess. <em>Lots</em> of tools have been proposed, but uptake seems slow and pretty haphazard (based on my own informal experience) and the main advice I hear is to throw spaghetti at the wall and run <em>lots</em> of different analyses. This leaves it on the meta-analyst to figure out what to conclude when all those analyses don’t all tell a consistent story, which hardly seems fair or even feasible. To get out of this fix, I think it will be fruitful to put more stock in and invest further in developing formal, generative models—whether that involves the beta density model, the <a href="../..\posts/step-function-selection-models/">step function selection model</a>, <a href="../..\posts/Copas-selection-models">the Copas model</a>, or some other form of selection model—and doing careful model assessment and critique.</p>


<!-- -->


</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" data-line-spacing="2">
<div id="ref-baskerville2012systematic" class="csl-entry">
Baskerville, N. B., Liddy, C., &amp; Hogg, W. (2012). Systematic review and meta-analysis of practice facilitation within primary care settings. <em>Annals of Family Medicine</em>, <em>10</em>(1), 63–74. <a href="https://doi.org/10.1370/afm.1312">https://doi.org/10.1370/afm.1312</a>
</div>
<div id="ref-Citkowicz2017parsimonious" class="csl-entry">
Citkowicz, M., &amp; Vevea, J. L. (2017). <span class="nocase">A parsimonious weight function for modeling publication bias</span>. <em>Psychological Methods</em>, <em>22</em>(1), 28–41. <a href="https://doi.org/10.1037/met0000119">https://doi.org/10.1037/met0000119</a>
</div>
<div id="ref-hedges1992modeling" class="csl-entry">
Hedges, L. V. (1992). Modeling publication selection effects in meta-analysis. <em>Statistical Science</em>, <em>7</em>(2), 246–255. <a href="https://doi.org/10.1214/ss/1177011364">https://doi.org/10.1214/ss/1177011364</a>
</div>
<div id="ref-hedges2017plausibility" class="csl-entry">
Hedges, L. V. (2017). Plausibility and influence in selection models: <span>A</span> comment on <span>Citkowicz</span> and <span>Vevea</span> (2017). <em>Psychological Methods</em>, <em>22</em>(1), 42–46. <a href="https://doi.org/10.1037/met0000108">https://doi.org/10.1037/met0000108</a>
</div>
<div id="ref-vevea1995general" class="csl-entry">
Vevea, J. L., &amp; Hedges, L. V. (1995). A general linear model for estimating effect size in the presence of publication bias. <em>Psychometrika</em>, <em>60</em>(3), 419–435. <a href="https://doi.org/10.1007/BF02294384">https://doi.org/10.1007/BF02294384</a>
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>With either model, the evidence-generating process can be extended to include a meta-regression with predictors of the average effect size. This amounts to replacing <img src="https://latex.codecogs.com/png.latex?%5Cmu"> with <img src="https://latex.codecogs.com/png.latex?%5Cbeta_0%20+%20%5Cbeta_1%20x_%7B1i%7D%20+%20%5Ccdots%20+%20%5Cbeta_p%20x_%7Bpi%7D"> for some set of predictors <img src="https://latex.codecogs.com/png.latex?x_%7B1i%7D,...,x_%7Bpi%7D">. For present purposes, I’m not going to worry about this additional complexity.↩︎</p></li>
<li id="fn2"><p><span class="citation" data-cites="hedges2017plausibility">Hedges (2017)</span> denotes this quantity as <img src="https://latex.codecogs.com/png.latex?g_i(T_i)">.↩︎</p></li>
<li id="fn3"><p>My estimate of <img src="https://latex.codecogs.com/png.latex?k_%7Bgen%7D"> and the component quantities differ from those reported in Table 1 of <span class="citation" data-cites="hedges2017plausibility">Hedges (2017)</span>; I am currently unsure why there is a discrepancy.↩︎</p></li>
<li id="fn4"><p>In a Bayesian framework, one might refine this further by simulating from the posterior predictive distribution of reported <img src="https://latex.codecogs.com/png.latex?p">-values.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>effect size</category>
  <category>distribution theory</category>
  <category>selective reporting</category>
  <guid>https://jepusto.netlify.app/posts/beta-density-selection-models/</guid>
  <pubDate>Fri, 08 Nov 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Copas selection models for meta-analysis</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/Copas-selection-models/</link>
  <description><![CDATA[ 





<p>Recently, I’ve been studying and tinkering with meta-analytic models for selective reporting of findings from primary studies. I’ve mostly focused on <a href="../..\posts/step-function-selection-models/">step-function selection models</a> <span class="citation" data-cites="hedges1992modeling vevea1995general Hedges1996estimating vevea2005publication">(Hedges, 1992; Hedges &amp; Vevea, 1996; Vevea &amp; Hedges, 1995; Vevea &amp; Woods, 2005)</span>, which assume that selective reporting of primary study results is driven by the <img src="https://latex.codecogs.com/png.latex?p">-values of the effect size estimates (and specifically, where those <img src="https://latex.codecogs.com/png.latex?p">-values fall relative to certain thresholds). This is not the only form of selection model, though. One prominent alternative model, described in a series of papers by John Copas and colleagues <span class="citation" data-cites="copas1997inference copas1999what copas2000metaanalysis Copas2001sensitivity">(Copas, 1999; Copas &amp; Li, 1997; Copas &amp; Shi, 2000, 2001)</span>, is based on distinctly different assumptions than the step-function model. The Copas selection model has received a fair amount of attention in the literature on meta-analysis of medical and epidemiological research, but relatively little attention from the social science side of things. In this post, I’ll give an overview of the Copas model and try to highlight some of the ways that it differs from step function selection models.</p>
<section id="the-copas-selection-model" class="level1">
<h1>The Copas selection model</h1>
<p>Similar to the step function selection model, the Copas model is composed of two components: an <em>evidence-generating process</em> that describes the distribution of effect size estimates prior to selection and a <em>selective reporting process</em> that describes how selective reporting happens as a function of the effect size estimates and associated quantities like standard errors and <img src="https://latex.codecogs.com/png.latex?p">-values. The evidence-generating process is just a conventional random effects model. Letting <img src="https://latex.codecogs.com/png.latex?T_i%5E*"> denote an effect size estimate prior to selective reporting, <img src="https://latex.codecogs.com/png.latex?%5Ctheta_i%5E*"> denote the corresponding effect size parameter, and <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*"> denote its (known) standard error, we assume that effect size estimate <img src="https://latex.codecogs.com/png.latex?i"> is drawn from a normal distribution with mean <img src="https://latex.codecogs.com/png.latex?%5Ctheta_i%5E*"> and standard deviation <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*">: <span id="eq-evidence-generation-level1"><img src="https://latex.codecogs.com/png.latex?%0AT_i%5E*%20%7C%20%5Ctheta_i%5E*,%20%5Csigma_i%5E*%20%5Csim%20N%5Cleft(%5Ctheta_i%5E*,%20%20%5Cleft(%5Csigma_i%5E*%5Cright)%5E2%5Cright).%0A%5Ctag%7B1%7D"></span> We further assume that the effect size parameters are drawn from a normal distribution with overall average effect size <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and standard deviation <img src="https://latex.codecogs.com/png.latex?%5Ctau">: <span id="eq-evidence-generation-level2"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctheta_i%5E*%20%7C%20%5Csigma_i%5E*%20%5Csim%20N%5Cleft(%5Cmu,%20%20%5Ctau%5E2%5Cright).%0A%5Ctag%7B2%7D"></span> The full evidence-generating process can also be written as a random effects model with two sources of error: <span id="eq-evidence-generation-full"><img src="https://latex.codecogs.com/png.latex?%0AT_i%5E*%20=%20%5Cmu%20+%20%5Cnu_i%5E*%20+%20%5Cepsilon_i%5E*,%0A%5Ctag%7B3%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%5Cnu_i%5E*%20%5Csim%20N(0,%20%5Ctau%5E2)"> and <img src="https://latex.codecogs.com/png.latex?%5Cepsilon_i%5E*%20%5Csim%20N%5Cleft(0,%20%5Cleft(%5Csigma_i%5E*%5Cright)%5E2%5Cright)">.</p>
<p>The second component is where the Copas model diverges from the step-function model. The Copas model posits that selection is driven by a latent index <img src="https://latex.codecogs.com/png.latex?%5Czeta_i"> that is normally distributed and correlated with <img src="https://latex.codecogs.com/png.latex?%5Cepsilon_i%5E*">, with mean that is a function of <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*">: <span id="eq-selection"><img src="https://latex.codecogs.com/png.latex?%0A%5Czeta_i%20=%20%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%5E*%7D%20+%20%5Cdelta_i,%0A%5Ctag%7B4%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%5Cdelta_i%20%5Csim%20N(0,%201)"> and <img src="https://latex.codecogs.com/png.latex?%5Ctext%7Bcor%7D(%5Cdelta_i,%20%5Cepsilon_i%5E*)%20=%20%5Crho">. With this specification, <img src="https://latex.codecogs.com/png.latex?T_i%5E*"> is reported (and thus available for inclusion in a meta-analysis) if <img src="https://latex.codecogs.com/png.latex?%5Czeta_i%20%3E%200"> and is otherwise unreported. Following the notation of my previous post, I’ll use <img src="https://latex.codecogs.com/png.latex?O_i%5E*"> to denote a binary indicator equal to 1 if <img src="https://latex.codecogs.com/png.latex?T_i%5E*"> is reported and otherwise equal to zero. With this notation, <img src="https://latex.codecogs.com/png.latex?%5CPr%5Cleft(O_i%5E*%20=%201%20%7C%20%5Csigma_i%5E*%5Cright)%20=%20%5CPr%5Cleft(%5Czeta_i%20%3E%200%20%7C%20%5Csigma_i%5E*%5Cright)">.</p>
<p><span class="citation" data-cites="Copas2001sensitivity">Copas &amp; Shi (2001)</span> calls <img src="https://latex.codecogs.com/png.latex?%5Czeta_i"> the <em>propensity for selection</em>. Under the posited model, the selection propensity depends both on the precision of the study through <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*"> (because the mean of <img src="https://latex.codecogs.com/png.latex?%5Czeta_i"> depends on the inverse of <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*">) and on the magnitude of the reported effect size estimate (because <img src="https://latex.codecogs.com/png.latex?%5Czeta_i"> is correlated with <img src="https://latex.codecogs.com/png.latex?%5Cepsilon_i%5E*">). The parameter <img src="https://latex.codecogs.com/png.latex?%5Calpha"> controls the overall probability of selection, irrespective of the findings; <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> controls how strongly selection depends on study precision; and <img src="https://latex.codecogs.com/png.latex?%5Crho"> controls how strongly selection depends on the magnitude of the effect size estimate itself.</p>
<p>The Copas model posits a stable correlation <img src="https://latex.codecogs.com/png.latex?%5Crho"> between the selection propensity index and the <em>samplng error</em> of the random effects model, <img src="https://latex.codecogs.com/png.latex?%5Cepsilon_i%5E*">. If there is heterogeneity in the effect size parameters and heterogeneity in the sampling variances, then the correlation between <img src="https://latex.codecogs.com/png.latex?%5Czeta_i"> and <img src="https://latex.codecogs.com/png.latex?T_i%5E*"> will be lower than <img src="https://latex.codecogs.com/png.latex?%5Crho"> and will differ from study to study. With a little variance algebra, it can be seen that <span id="eq-zeta-correlation"><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7Bcor%7D%5Cleft(%5Czeta_i,%20T_i%5E*%20%7C%20%5Csigma_i%5E*%5Cright)%20=%20%5Ctilde%5Crho_i%20=%20%5Cfrac%7B%5Crho%20%5Csigma_i%5E*%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Cleft(%5Csigma_i%5E*%5Cright)%5E2%7D%7D.%0A%5Ctag%7B5%7D"></span> Using the correlation, we can write the selection propensity index in terms of a regression on <img src="https://latex.codecogs.com/png.latex?T_i%5E*">: <img src="https://latex.codecogs.com/png.latex?%0A%5Czeta_i%20%7C%20T_i%5E*,%20%5Csigma_i%5E*%20%5Csim%20N%20%5Cleft(%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%5E*%7D%20+%20%5Ctilde%5Crho_i%20%5Cleft(%5Cfrac%7BT_i%5E*%20-%20%5Cmu%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Cleft(%5Csigma_i%5E*%5Cright)%5E2%7D%7D%5Cright),%20%5C%201%20-%20%5Crho_i%5E2%5Cright).%0A"> Thus, given the effect size estimate <img src="https://latex.codecogs.com/png.latex?T_i%5E*"> and its standard error <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*">, the probability that finding <img src="https://latex.codecogs.com/png.latex?i"> is reported is <span id="eq-conditional-selection-probability"><img src="https://latex.codecogs.com/png.latex?%0A%5CPr%5Cleft(O_i%5E*%20=%201%20%7C%20T_i%5E*,%20%5Csigma_i%5E*%5Cright)%20=%20%5CPhi%5Cleft(%5Cfrac%7B1%7D%7B%5Csqrt%7B1%20-%20%5Ctilde%5Crho_i%5E2%7D%7D%5Cleft%5B%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%5E*%7D%20+%20%5Ctilde%5Crho_i%20%5Cleft(%5Cfrac%7BT_i%5E*%20-%20%5Cmu%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Cleft(%5Csigma_i%5E*%5Cright)%5E2%7D%7D%5Cright)%5Cright%5D%5Cright)%0A%5Ctag%7B6%7D"></span> <span class="citation" data-cites="Copas2001sensitivity hedges2005selection">(Copas &amp; Shi, 2001, Equation 4; Hedges &amp; Vevea, 2005, Equation 9.6)</span>.</p>
</section>
<section id="distribution-of-observed-effect-sizes" class="level1 page-columns page-full">
<h1>Distribution of observed effect sizes</h1>
<p>The observed effect size estimates <img src="https://latex.codecogs.com/png.latex?T_i"> follow a distribution equivalent to that of <img src="https://latex.codecogs.com/png.latex?%5Cleft(T_i%5E*%20%7C%20%5Csigma_i%5E*,%20O_i%5E*%20=%201%5Cright)">. It’s possible to find an analytic expression for the density of the observed effect sizes. Using Bayes Theorem, the density of the observed <img src="https://latex.codecogs.com/png.latex?T_i">’s is <span id="eq-Bayes-theorem"><img src="https://latex.codecogs.com/png.latex?%0A%5CPr%5Cleft(T_i%20=%20t%7C%20%5Csigma_i%5E*%5Cright)%20=%20%5CPr%5Cleft(T_i%5E*%20=%20t%20%7C%20%5Csigma_i%5E*,%20O_i%5E*%20=%201%5Cright)%20=%20%5Cfrac%7B%5CPr%5Cleft(O_i%5E*%20=%201%20%7C%20T_i%5E*%20=%20t,%20%5Csigma_i%5E*%5Cright)%20%5Ctimes%20%5CPr%5Cleft(T_i%5E*%20=%20t%20%7C%20%5Csigma_i%5E*%5Cright)%7D%7B%5CPr%5Cleft(O_i%5E*%20=%201%20%7C%20%5Csigma_i%5E*%5Cright)%7D,%0A%5Ctag%7B7%7D"></span> where the first term in the numerator is given in (6), the second term in the numerator can be derived from (3), and the denominator can be derived from (4). Letting <img src="https://latex.codecogs.com/png.latex?%5Ceta_i%20=%20%5Csqrt%7B%5Ctau%5E2%20+%20%5Cleft(%5Csigma_i%5E*%5Cright)%5E2%7D"> and substituting everything into the above gives <span id="eq-observed-density"><img src="https://latex.codecogs.com/png.latex?%0A%5CPr%5Cleft(T_i%20=%20t%7C%20%5Csigma_i%5E*%5Cright)%20=%20%5Cfrac%7B1%7D%7B%5Ceta_i%7D%20%5Cphi%5Cleft(%5Cfrac%7Bt%20-%20%5Cmu%7D%7B%5Ceta_i%7D%5Cright)%20%5Ctimes%20%5Cfrac%7B%5CPhi%5Cleft(%5Cfrac%7B1%7D%7B%5Csqrt%7B1%20-%20%5Ctilde%5Crho_i%5E2%7D%7D%5Cleft%5B%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%5E*%7D%20+%20%5Ctilde%5Crho_i%20%5Cleft(%5Cfrac%7Bt%20-%20%5Cmu%7D%7B%5Ceta_i%7D%5Cright)%5Cright%5D%5Cright)%7D%20%7B%5CPhi%5Cleft(%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%5E*%7D%5Cright)%7D.%0A%5Ctag%7B8%7D"></span> This density is identical to that of the <em>generalized skew-normal distribution</em> <span class="citation" data-cites="arellano20006unification">(Arellano-Valle &amp; Azzalini, 2006)</span>.</p>
<p>Here is an interactive graph showing the distribution of the effects prior to selection (in grey) and the distribution of observed effect sizes (in blue) based on the Copas selection model.<sup>1</sup> Initially, the selection parameters are set to <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20-3">, <img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%200.5"> and <img src="https://latex.codecogs.com/png.latex?%5Crho%20=%200.5">, but you can change these however you like. Try wiggling <img src="https://latex.codecogs.com/png.latex?%5Crho"> up and down to see how the bias and shape of the density changes.</p>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb1" data-startfrom="92" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 91;"><span id="cb1-92">math <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">require</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mathjs"</span>)</span>
<span id="cb1-93">norm <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://unpkg.com/norm-dist@3.1.0/index.js?module'</span>)</span>
<span id="cb1-94"></span>
<span id="cb1-95">eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> 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;">sqrt</span>(tau<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-96">rho_i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rho <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta</span>
<span id="cb1-97">u <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> beta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> sigma</span>
<span id="cb1-98">lambda <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> norm<span 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>(u) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> norm<span 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>(u)</span>
<span id="cb1-99"></span>
<span id="cb1-100">Ai <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> norm<span 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>(u)</span>
<span id="cb1-101">ET <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> rho <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> lambda</span>
<span id="cb1-102">SDT <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> 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;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rho_i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> lambda <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (u <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> lambda))</span>
<span id="cb1-103">Ai_toprint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Ai<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb1-104">ET_toprint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ET<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb1-105">eta_toprint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> eta<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb1-106">SDT_toprint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> SDT<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb1-107"></span>
<span id="cb1-108"><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;">CopasSelection</span>(t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> beta<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> rho) {</span>
<span id="cb1-109">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> u <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> beta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-110">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> eta_ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> 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;">sqrt</span>(tau<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-111">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> rho_i_ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rho <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> s <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> </span>
<span id="cb1-112">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> z <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-113">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (u <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> rho_i_ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> z) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> 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;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rho_i_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-114">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> norm<span 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>(x)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-115">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-8" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-9" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-10" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-11" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-12" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-13" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-14" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb2" data-startfrom="120" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 119;"><span id="cb2-120">pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">201</span></span>
<span id="cb2-121"></span>
<span id="cb2-122">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(pts)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</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;">map</span>((element<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> index) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-123">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> index <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-124">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> dt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> norm<span 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>((t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-125">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> pr_sel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">CopasSelection</span>(t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> beta<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> rho)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-126">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> ({</span>
<span id="cb2-127">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">t</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-128">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">d_unselected</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> dt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-129">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">d_selected</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> pr_sel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> dt</span>
<span id="cb2-130">  })</span>
<span id="cb2-131">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-2" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="grid column-page">
<div class="g-col-8 center">
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb3" data-startfrom="139" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 138;"><span id="cb3-139">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb3-140">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-141">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">700</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-142">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb3-143">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-144">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span></span>
<span id="cb3-145">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-146">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb3-147">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Effect size estimate (Ti)"</span></span>
<span id="cb3-148">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>   </span>
<span id="cb3-149">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb3-150">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-151">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-152">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">areaY</span>(dat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d_unselected"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-153">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">areaY</span>(dat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d_selected"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-154">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(dat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d_selected"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>})</span>
<span id="cb3-155">  ]</span>
<span id="cb3-156">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="expression">

</div>
</div>
</div>
<div class="moments">
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb4" data-startfrom="162" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 161;"><span id="cb4-162"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb4-163"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\b</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">egin{aligned}</span></span>
<span id="cb4-164"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">u &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>mu<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> &amp; </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\q</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">quad </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\e</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ta_i &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>eta_toprint<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span></span>
<span id="cb4-165"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">athbb{E}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">eft(T_i | </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\s</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">igma_i</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ight) &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>ET_toprint<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-166"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&amp; </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\q</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">quad </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\s</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">qrt{</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">athbb{V}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">eft(T_i | </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\s</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">igma_i</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ight)} &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>SDT_toprint<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb4-167"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\P</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">r(O_i^* = 1 | </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\s</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">igma_i^*) &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>Ai_toprint<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-168"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\e</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">nd{aligned}</span></span>
<span id="cb4-169"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="expression">

</div>
</div>
</div>
</div>
</div>
<div class="g-col-4">
<div class="cell panel-input card bg-light p-2">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb5" data-startfrom="181" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 180;"><span id="cb5-181">viewof mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-182">  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-183">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">u`</span>}</span>
<span id="cb5-184">)</span>
<span id="cb5-185"></span>
<span id="cb5-186">viewof tau <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-187">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-188">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\t</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">au`</span>}</span>
<span id="cb5-189">)</span>
<span id="cb5-190"></span>
<span id="cb5-191">viewof sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-192">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-193">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.20</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\s</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">igma_i`</span>}</span>
<span id="cb5-194">)</span>
<span id="cb5-195"></span>
<span id="cb5-196">viewof alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-197">  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-198">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</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;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\a</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">lpha`</span>}</span>
<span id="cb5-199">)</span>
<span id="cb5-200"></span>
<span id="cb5-201">viewof beta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-202">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-203">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\b</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">eta`</span>}</span>
<span id="cb5-204">)</span>
<span id="cb5-205"></span>
<span id="cb5-206">viewof rho <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-207">  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-208">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ho`</span>}</span>
<span id="cb5-209">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-6" data-nodetype="declaration">

</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section id="moments-of-t_i-sigma_i" class="level1">
<h1>Moments of <img src="https://latex.codecogs.com/png.latex?T_i%20%7C%20%5Csigma_i"></h1>
<p><span class="citation" data-cites="arnold1999nontruncated">Arnold et al. (1993)</span> derived the moment-generating function and first several moments of a further generalization of the skew-normal distribution, of which the distribution of <img src="https://latex.codecogs.com/png.latex?T_i"> is a special case. Letting <img src="https://latex.codecogs.com/png.latex?Z_i%20=%20%5Cfrac%7BT_i%20-%20%5Cmu%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%7D">, <img src="https://latex.codecogs.com/png.latex?u_i%20=%20%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%7D">, and <img src="https://latex.codecogs.com/png.latex?%5Clambda(u_i)%20=%20%5Cphi(u_i)%20/%20%5CPhi(u_i)">, they give the first two moments of <img src="https://latex.codecogs.com/png.latex?Z_i"> as <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathbb%7BE%7D%5Cleft(Z_i%20%7C%20%5Csigma_i%20%5Cright)%20&amp;=%20%5Crho_i%20%5Clambda%5Cleft(u_i%5Cright)%20%5C%5C%0A%5Cmathbb%7BE%7D%5Cleft(Z_i%5E2%20%7C%20%5Csigma_i%20%5Cright)%20&amp;=%201%20-%20%5Crho_i%5E2%20u_i%20%5Clambda(u_i)%0A%5Cend%7Baligned%7D%0A"> by which it follows that <span id="eq-Ti-mean"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathbb%7BE%7D%5Cleft(T_i%20%7C%20%5Csigma_i%20%5Cright)%20&amp;=%20%5Cmu%20+%20%5Csqrt%7B%5Ctau%5E2%20+%20%5Csigma_i%5E2%7D%20%5Ctimes%20%5Crho_i%20%5Clambda%5Cleft(u_i%5Cright)%20%5C%5C%0A&amp;=%20%5Cmu%20+%20%5Crho%20%5Csigma_i%20%5Clambda%5Cleft(u_i%5Cright)%0A%5Cend%7Baligned%7D%0A%5Ctag%7B9%7D"></span> and <span id="eq-Ti-variance"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathbb%7BV%7D%5Cleft(T_i%20%7C%20%5Csigma_i%20%5Cright)%20&amp;=%20%5Cleft(%5Ctau%5E2%20+%20%5Csigma_i%5E2%5Cright)%20%5Cleft(1%20-%20%5Crho_i%5E2%5Clambda(u_i)%20%5Ctimes%20%5Bu_i%20%20+%20%5Clambda(u_i)%5D%5Cright)%20%5C%5C%0A&amp;=%20%5Ctau%5E2%20+%20%5Csigma_i%5E2%5Cleft(1%20-%20%5Crho%5E2%20%5Clambda(u_i)%20%5Ctimes%20%5Bu_i%20%20+%20%5Clambda(u_i)%5D%5Cright).%0A%5Cend%7Baligned%7D%0A%5Ctag%7B10%7D"></span> The expression for <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BE%7D%5Cleft(T_i%20%7C%20%5Csigma_i%20%5Cright)"> is also given in <span class="citation" data-cites="copas2000metaanalysis">Copas &amp; Shi (2000)</span> and <span class="citation" data-cites="Copas2001sensitivity">Copas &amp; Shi (2001)</span>.<sup>2</sup></p>
<p>Several things are noteworthy about these expressions. For one, the expectation of <img src="https://latex.codecogs.com/png.latex?T_i"> is additive in <img src="https://latex.codecogs.com/png.latex?%5Cmu">, so the bias <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BE%7D(T_i%20%7C%20%5Csigma_i)%20-%20%5Cmu"> does not depend on the location of the distribution prior to selection. Nor does it depend on the degree of heterogeneity <img src="https://latex.codecogs.com/png.latex?%5Ctau">. Likewise, the variance of <img src="https://latex.codecogs.com/png.latex?T_i"> is additive in <img src="https://latex.codecogs.com/png.latex?%5Ctau%5E2">. Only the sampling variance is affected by selection. All of these properties are in contrast to the step-function selection model, where both the bias and the variance are complex functions that <em>do</em> depend on <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau">.</p>
<p>Under the Copas model, the bias of <img src="https://latex.codecogs.com/png.latex?T_i"> is directly proportional to <img src="https://latex.codecogs.com/png.latex?%5Crho"> and is a more complicated function of <img src="https://latex.codecogs.com/png.latex?%5Calpha"> and <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> (through <img src="https://latex.codecogs.com/png.latex?u_i">). The bias is an increasing function of <img src="https://latex.codecogs.com/png.latex?%5Csigma">, the shape of which depends on <img src="https://latex.codecogs.com/png.latex?%5Calpha"> and <img src="https://latex.codecogs.com/png.latex?%5Cbeta">. Here’s an illustration of <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%20%5Ctimes%20%5Clambda(u_i)"> as a function of <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> for a few different values of the selection parameters:</p>
<div class="cell">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/Copas-selection-models/index_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" style="width:100.0%"></p>
</figure>
</div>
</div>
</div>
<p>When <img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%200">, the bias is directly proportional to <img src="https://latex.codecogs.com/png.latex?%5Csigma_i">, just like in an Egger regression or the PET meta-regression adjustment method <span class="citation" data-cites="stanley2008metaregression">(Stanley, 2008)</span>. As <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> increases, the bias is initially very close to zero and then grows almost linearly after a certain point—much as in the kinked meta-regression adjustment proposed by <span class="citation" data-cites="bom2019kinked">Bom &amp; Rachinger (2019)</span>. Very curious.</p>
</section>
<section id="funnel-density" class="level1 page-columns page-full">
<h1>Funnel density</h1>
<p>Here is an interactive funnel plot showing the distribution of effect size estimates under the Copas selection model. I initially set <img src="https://latex.codecogs.com/png.latex?%5Cmu%20=%200.15"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau%20=%200.10"> and selection parameters of <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20-3">, <img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%200.5"> and <img src="https://latex.codecogs.com/png.latex?%5Crho%20=%200.5">, but you can change these however you like.</p>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb6" data-startfrom="296" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 295;"><span id="cb6-296">SE_pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span></span>
<span id="cb6-297">t_pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">181</span></span>
<span id="cb6-298">sigma_max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span></span>
<span id="cb6-299">eta_max_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> 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;">sqrt</span>(tau_f<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sigma_max<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb6-300"></span>
<span id="cb6-301">funnel_dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(t_pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> SE_pts)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</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;">map</span>((x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>row) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb6-302">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> SE_pts<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-303">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> j <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> i) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> SE_pts<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-304">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sigma_max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> SE_pts<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-305">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> mu_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> eta_max_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> eta_max_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (t_pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-306">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> 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;">sqrt</span>(tau_f<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-307">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> dt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> norm<span 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>((t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu_f) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-308">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> pr_sel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">CopasSelection</span>(t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha_f<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> beta_f<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> rho_f)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-309">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">t</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">sigma</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> sigma<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;">dt</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> dt<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;">pr_sel</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> pr_sel<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;">d_selected</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> pr_sel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> dt})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-310">})</span>
<span id="cb6-311"></span>
<span id="cb6-312">sigline_dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb6-313">  ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">t</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">sigma</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-314">  ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">t</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> sigma_max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> norm<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">icdf</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">sigma</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> sigma_max})</span>
<span id="cb6-315">]</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-6" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="grid column-page">
<div class="g-col-8 center">
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb7" data-startfrom="324" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 323;"><span id="cb7-324">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb7-325">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">400</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-326">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">700</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-327">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">padding</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-328">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-329">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">axis</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Effect size estimate (Ti)"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-330">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Standard error (sigma_i)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">reverse</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-331">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb7-332">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">scheme</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pubugn"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-333">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sqrt"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-334">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span></span>
<span id="cb7-335">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-336">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb7-337">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>(funnel_dat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d_selected"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">symbol</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"square"</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-338">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-339">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey"</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-340">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">line</span>(sigline_dat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>})</span>
<span id="cb7-341">  ]</span>
<span id="cb7-342">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-7" data-nodetype="expression">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb8" data-startfrom="346" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 345;"><span id="cb8-346">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">legend</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">scheme</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pubugn"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sqrt"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>}})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-8" data-nodetype="expression">

</div>
</div>
</div>
</div>
<div class="g-col-4">
<div class="cell panel-input card bg-light p-2">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb9" data-startfrom="357" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 356;"><span id="cb9-357">viewof mu_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb9-358">  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb9-359">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">u`</span>}</span>
<span id="cb9-360">)</span>
<span id="cb9-361"></span>
<span id="cb9-362">viewof tau_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb9-363">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb9-364">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\t</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">au`</span>}</span>
<span id="cb9-365">)</span>
<span id="cb9-366"></span>
<span id="cb9-367">viewof alpha_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb9-368">  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb9-369">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</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;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\a</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">lpha`</span>}</span>
<span id="cb9-370">)</span>
<span id="cb9-371"></span>
<span id="cb9-372">viewof beta_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb9-373">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb9-374">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\b</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">eta`</span>}</span>
<span id="cb9-375">)</span>
<span id="cb9-376"></span>
<span id="cb9-377">viewof rho_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb9-378">  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb9-379">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ho`</span>}</span>
<span id="cb9-380">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-9-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-9-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-9-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-9-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-9-5" data-nodetype="declaration">

</div>
</div>
</div>
</div>
</div>
</div>
<p>The funnel plot shows the <em>un-normalized</em> distribution of the observed effect sizes conditional on <img src="https://latex.codecogs.com/png.latex?%5Csigma_i">. One of the very striking things about the funnel is just how steeply the marginal selection probabilities (i.e., <img src="https://latex.codecogs.com/png.latex?%5CPr(O_i%5E*%20=%201%7C%20%5Csigma_i%5E*)">) drop off as <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> increases (going from the top to the bottom of the plot). With the initial parameter settings, findings from small studies with large <img src="https://latex.codecogs.com/png.latex?%5Csigma_i">s are generally <em>quite</em> unlikely to be published, regardless of their significance or effect size. Increasing <img src="https://latex.codecogs.com/png.latex?%5Calpha"> will increase the marginal selection probability for all studies, though in a non-linear way depending on their <img src="https://latex.codecogs.com/png.latex?%5Csigma_i">’s. Reducing <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> will mitigate the drop-off in selection probabilities from large studies to small ones.</p>
</section>
<section id="comments" class="level1">
<h1>Comments</h1>
<p>There are several aspects of the Copas model that I find somewhat perplexing. One is the assumption that the selection propensity index is correlated with the <em>sampling errors</em> rather than with the marginal distribution of <img src="https://latex.codecogs.com/png.latex?T_i%5E*">. Taken literally, this means that the selection propensity depends not just on the effect size estimate (which is an observable quantity) but on where that estimate lies relative to the true study-specific effect size parameter <img src="https://latex.codecogs.com/png.latex?%5Ctheta_i">. It seems more plausible to me that authors, reviewers, editors, etc. would make decisions that could influence selective reporting based on observable quantities such as effect size estimates, standard errors, or <img src="https://latex.codecogs.com/png.latex?p">-values (as in the <a href="../..\posts/step-function-selection-models/">step-function selection model</a>).</p>
<p>Another perplexing aspect of the model is that, for a given set of selection parameters <img src="https://latex.codecogs.com/png.latex?%5Calpha">, <img src="https://latex.codecogs.com/png.latex?%5Cbeta">, and <img src="https://latex.codecogs.com/png.latex?%5Crho">, the bias due to selection is constant and unaffected by the location <img src="https://latex.codecogs.com/png.latex?%5Cmu"> or scale <img src="https://latex.codecogs.com/png.latex?%5Ctau"> of the true effect size distribution. As a result, under the model’s posited form of selection bias, the extent of bias is disconnected from considerations of statistical significance or power. In practice, I would expect the risk of selection bias to be greater for small studies examining small effects than for small studies examining very strong effect sizes, but the parameterization of the Copas model makes it kind of hard to capture such a pattern. Put another way, I think this implies that the plausibility of a given selection parameters <img src="https://latex.codecogs.com/png.latex?%5Calpha">, <img src="https://latex.codecogs.com/png.latex?%5Cbeta">, and <img src="https://latex.codecogs.com/png.latex?%5Crho"> might actually depend on <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau">.</p>
<p>Third, a well known aspect of the model is that its three selection-related parameters are only very weakly identifiable from observed effect size distributions. Because of this, the Copas model is typically used as a sort of sensitivity analysis, where the analyst estimates <img src="https://latex.codecogs.com/png.latex?%5Cmu">, <img src="https://latex.codecogs.com/png.latex?%5Ctau">, and <img src="https://latex.codecogs.com/png.latex?%5Crho"> by maximum likelihood <span class="citation" data-cites="Copas2001sensitivity">(Copas &amp; Shi, 2001)</span> for specified values for <img src="https://latex.codecogs.com/png.latex?%5Calpha"> and <img src="https://latex.codecogs.com/png.latex?%5Cbeta">, and then examines how these parameter estimates vary across a range of possible <img src="https://latex.codecogs.com/png.latex?%5Calpha"> and <img src="https://latex.codecogs.com/png.latex?%5Cbeta">.<sup>3</sup> But sensitivity analysis is only really helpful to the extent that the analyst can specify a plausible range of values for the selection parameters, which is hard to do if the plausible range depends on <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau">. Other scholars have proposed using the Copas in a Bayesian framework <span class="citation" data-cites="bai2021robust mavridis2013fully">(e.g., Bai et al., 2021; Mavridis et al., 2013)</span>, but it seems like similar concerns would apply—if key parameters are only weakly identified, then their priors may be strongly influential, but if it’s hard to formulas credible priors….</p>
<p>To be clear, my comments here are all just half-baked impressions as I work through a model that’s pretty new to me. Copas has some more recent work that considers alternative assumptions about the selective reporting process <span class="citation" data-cites="copas2013likelihood">(Copas, 2013)</span>, which seem simpler and more closely connected to <img src="https://latex.codecogs.com/png.latex?p">-value-based selection processes. However, other scholars have continued to study and extend the Copas selection model <span class="citation" data-cites="duan2020testing ning2017maximum piao2019copas">(e.g., Duan et al., 2020; Ning et al., 2017; Piao et al., 2019)</span>, so I probably just need to read more about how it’s applied to get a better sense of its strengths and utility.</p>


<!-- -->


</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" data-line-spacing="2">
<div id="ref-arellano20006unification" class="csl-entry">
Arellano-Valle, R. B., &amp; Azzalini, A. (2006). On the unification of families of skew-normal distributions. <em>Scandinavian Journal of Statistics</em>, <em>33</em>(3), 561–574. <a href="https://doi.org/10.1111/j.1467-9469.2006.00503.x">https://doi.org/10.1111/j.1467-9469.2006.00503.x</a>
</div>
<div id="ref-arnold1999nontruncated" class="csl-entry">
Arnold, B. C., Beaver, R. J., Groeneveld, R. A., &amp; Meeker, W. Q. (1993). The nontruncated marginal of a truncated bivariate normal distribution. <em>Psychometrika</em>, <em>58</em>(3), 471–488. <a href="https://doi.org/10.1007/BF02294652">https://doi.org/10.1007/BF02294652</a>
</div>
<div id="ref-bai2021robust" class="csl-entry">
Bai, R., Lin, L., Boland, M. R., &amp; Chen, Y. (2021). <em>A robust <span>Bayesian</span> <span>Copas</span> selection model for quantifying and correcting publication bias</em>. arXiv. <a href="https://doi.org/10.48550/arXiv.2005.02930">https://doi.org/10.48550/arXiv.2005.02930</a>
</div>
<div id="ref-bom2019kinked" class="csl-entry">
Bom, P. R. D., &amp; Rachinger, H. (2019). A kinked meta-regression model for publication bias correction. <em>Research Synthesis Methods</em>, <em>10</em>(4), 497–514. <a href="https://doi.org/10.1002/jrsm.1352">https://doi.org/10.1002/jrsm.1352</a>
</div>
<div id="ref-copas1999what" class="csl-entry">
Copas, J. B. (1999). What works?: <span>Selectivity</span> models and meta-analysis. <em>Journal of the Royal Statistical Society Series A: Statistics in Society</em>, <em>162</em>(1), 95–109. <a href="https://doi.org/10.1111/1467-985X.00123">https://doi.org/10.1111/1467-985X.00123</a>
</div>
<div id="ref-copas2013likelihood" class="csl-entry">
Copas, J. B. (2013). A likelihood-based sensitivity analysis for publication bias in meta-analysis. <em>Journal of the Royal Statistical Society Series C: Applied Statistics</em>, <em>62</em>(1), 47–66. <a href="https://doi.org/10.1111/j.1467-9876.2012.01049.x">https://doi.org/10.1111/j.1467-9876.2012.01049.x</a>
</div>
<div id="ref-copas1997inference" class="csl-entry">
Copas, J. B., &amp; Li, H. G. (1997). Inference for non-random samples. <em>Journal of the Royal Statistical Society Series B: Statistical Methodology</em>, <em>59</em>(1), 55–95. <a href="https://doi.org/10.1111/1467-9868.00055">https://doi.org/10.1111/1467-9868.00055</a>
</div>
<div id="ref-copas2000metaanalysis" class="csl-entry">
Copas, J. B., &amp; Shi, J. Q. (2000). Meta-analysis, funnel plots and sensitivity analysis. <em>Biostatistics</em>, <em>1</em>(3), 247–262. <a href="https://doi.org/10.1093/biostatistics/1.3.247">https://doi.org/10.1093/biostatistics/1.3.247</a>
</div>
<div id="ref-Copas2001sensitivity" class="csl-entry">
Copas, J. B., &amp; Shi, J. Q. (2001). <span class="nocase">A sensitivity analysis for publication bias in systematic reviews.</span> <em>Statistical Methods in Medical Research</em>, <em>10</em>, 251–265.
</div>
<div id="ref-duan2020testing" class="csl-entry">
Duan, R., Piao, J., Marks-Anglin, A., Tong, J., Lin, L., Chu, H., Ning, J., &amp; Chen, Y. (2020). <em>Testing for publication bias in meta-analysis under <span>Copas</span> selection model</em>. <a href="https://doi.org/10.48550/arXiv.2007.00836">https://doi.org/10.48550/arXiv.2007.00836</a>
</div>
<div id="ref-hedges1992modeling" class="csl-entry">
Hedges, L. V. (1992). Modeling publication selection effects in meta-analysis. <em>Statistical Science</em>, <em>7</em>(2), 246–255. <a href="https://doi.org/10.1214/ss/1177011364">https://doi.org/10.1214/ss/1177011364</a>
</div>
<div id="ref-Hedges1996estimating" class="csl-entry">
Hedges, L. V., &amp; Vevea, J. L. (1996). <span class="nocase">Estimating effect size under publication bias: Small sample properties and robustness of a random effects selection model</span>. <em>Journal of Educational and Behavioral Statistics</em>, <em>21</em>(4), 299. <a href="https://doi.org/10.3102/10769986021004299">https://doi.org/10.3102/10769986021004299</a>
</div>
<div id="ref-hedges2005selection" class="csl-entry">
Hedges, L. V., &amp; Vevea, J. L. (2005). Selection method approaches. In <em>Publication bias in meta-analysis: Prevention, assessment, and adjustments</em> (pp. 145–174). John Wiley &amp; Sons.
</div>
<div id="ref-huang2021using" class="csl-entry">
Huang, A., Komukai, S., Friede, T., &amp; Hattori, S. (2021). Using clinical trial registries to inform <span>Copas</span> selection model for publication bias in meta-analysis. <em>Research Synthesis Methods</em>, <em>12</em>(5), 658–673. <a href="https://doi.org/10.1002/jrsm.1506">https://doi.org/10.1002/jrsm.1506</a>
</div>
<div id="ref-mavridis2013fully" class="csl-entry">
Mavridis, D., Sutton, A., Cipriani, A., &amp; Salanti, G. (2013). A fully <span>Bayesian</span> application of the <span>Copas</span> selection model for publication bias extended to network meta-analysis. <em>Statistics in Medicine</em>, <em>32</em>(1), 51–66. <a href="https://doi.org/10.1002/sim.5494">https://doi.org/10.1002/sim.5494</a>
</div>
<div id="ref-ning2017maximum" class="csl-entry">
Ning, J., Chen, Y., &amp; Piao, J. (2017). Maximum likelihood estimation and <span>EM</span> algorithm of <span>Copas</span>-like selection model for publication bias correction. <em>Biostatistics</em>, <em>18</em>(3), 495–504. <a href="https://doi.org/10.1093/biostatistics/kxx004">https://doi.org/10.1093/biostatistics/kxx004</a>
</div>
<div id="ref-piao2019copas" class="csl-entry">
Piao, J., Liu, Y., Chen, Y., &amp; Ning, J. (2019). Copas-like selection model to correct publication bias in systematic review of diagnostic test studies. <em>Statistical Methods in Medical Research</em>, <em>28</em>(10-11), 2912–2923. <a href="https://doi.org/10.1177/0962280218791602">https://doi.org/10.1177/0962280218791602</a>
</div>
<div id="ref-stanley2008metaregression" class="csl-entry">
Stanley, T. D. (2008). Meta-regression methods for detecting and estimating empirical effects in the presence of publication selection*. <em>Oxford Bulletin of Economics and Statistics</em>, <em>70</em>(1), 103–127. <a href="https://doi.org/10.1111/j.1468-0084.2007.00487.x">https://doi.org/10.1111/j.1468-0084.2007.00487.x</a>
</div>
<div id="ref-vevea1995general" class="csl-entry">
Vevea, J. L., &amp; Hedges, L. V. (1995). A general linear model for estimating effect size in the presence of publication bias. <em>Psychometrika</em>, <em>60</em>(3), 419–435. <a href="https://doi.org/10.1007/BF02294384">https://doi.org/10.1007/BF02294384</a>
</div>
<div id="ref-vevea2005publication" class="csl-entry">
Vevea, J. L., &amp; Woods, C. M. (2005). Publication bias in research synthesis: Sensitivity analysis using a priori weight functions. <em>Psychological Methods</em>, <em>10</em>(4), 428–443. <a href="https://doi.org/10.1037/1082-989X.10.4.428">https://doi.org/10.1037/1082-989X.10.4.428</a>
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Note that I’ve plotted the <em>unnormalized density</em> (the density before dividing by <img src="https://latex.codecogs.com/png.latex?%5CPhi%5Cleft(%5Calpha%20+%20%5Cfrac%7B%5Cbeta%7D%7B%5Csigma_i%5E*%7D%5Cright)">) so that it’s clear that the distribution of observed effects is a subset of the distribution of effects prior to selection.↩︎</p></li>
<li id="fn2"><p>These sources give the variance of the observed effect size estimates as <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BV%7D%5Cleft(T_i%20%7C%20%5Csigma_i%20%5Cright)%20=%20%20%5Csigma_i%5E2%5Cleft(1%20-%20%5Crho%5E2%20%5Clambda(u_i)%20%5Ctimes%20%5Bu_i%20%20+%20%5Clambda(u_i)%5D%5Cright)"> <span class="citation" data-cites="copas2000metaanalysis Copas2001sensitivity">(see p.&nbsp;250 of Copas &amp; Shi, 2000; see Equation 6 of Copas &amp; Shi, 2001)</span>. However, these expressions are incorrect as stated because they omit the between-study heterogeneity <img src="https://latex.codecogs.com/png.latex?%5Ctau%5E2">.↩︎</p></li>
<li id="fn3"><p>Some recent work by <span class="citation" data-cites="huang2021using">Huang et al. (2021)</span> proposes using clinical trial registry information to estimate all the parameters of the Copas model, which seems like an interesting and potentially useful strategy.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>effect size</category>
  <category>distribution theory</category>
  <category>selective reporting</category>
  <guid>https://jepusto.netlify.app/posts/Copas-selection-models/</guid>
  <pubDate>Sat, 27 Jul 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Step-function selection models for meta-analysis</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/step-function-selection-models/</link>
  <description><![CDATA[ 





<p>In <a href="../..\posts/distribution-of-significant-effects/">a recent post</a> I looked at the distribution of statistically significant effect sizes in studies that report multiple outcomes, when those studies are subject to a certain form of selective reporting. I considered a model where each effect size within the study is more likely to be reported when it is <em>affirmative</em>—or statistically significant and in the hypothesized direction—than when it is <em>non-affirmative</em>. Because studies with multiple effect sizes are a very common occurrence in social science meta-analysis, it’s interesting to think about how this form of selection leads to distortions of the results that are actually reported and available for meta-analysis.</p>
<p>In this post, I want to look a different scenario that is simpler in one respect but more complicated in another. Simpler, in that I’m going to ignore dependence issues and just think about the distribution of one effect size at a time. More complicated, in that I’m going to look at a more general model for how selective reporting occurs, which I’ll call the <strong><em>step-function selection model</em></strong>.</p>
<section id="the-step-function-selection-model" class="level1">
<h1>The step-function selection model</h1>
<p>The step-function selection model was introduced by <span class="citation" data-cites="hedges1992modeling">Hedges (1992)</span> and has been further expanded, tweaked, and studied in a bunch of subsequent work. The model has two components: a set of assumptions about how effect size estimates are generated prior to selection (the <em>evidence-generation process</em>), and a set of assumptions about how selective reporting happens as a function of the effect size estimates (the <em>selective reporting process</em>).</p>
<p>In the original formulation, the evidence-generation process is a random effects model. Letting <img src="https://latex.codecogs.com/png.latex?T_i%5E*"> denote an effect size estimate prior to selective reporting and <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*"> denote its (known) standard error, we assume that <span id="eq-evidence-generation"><img src="https://latex.codecogs.com/png.latex?%0AT_i%5E*%20%7C%20%5Csigma_i%5E*%20%5Csim%20N%5Cleft(%5Cmu,%20%5Ctau%5E2%20+%20%5Cleft(%5Csigma_i%5E*%5Cright)%5E2%5Cright),%0A%5Ctag%7B1%7D"></span> just as in the conventional random effects model. Here <img src="https://latex.codecogs.com/png.latex?%5Cmu"> is the overall average effect size and <img src="https://latex.codecogs.com/png.latex?%5Ctau"> is the standard deviation of the effect size parameter distribution.</p>
<p>For the second component, we assume that the selective-reporting process is fully determined by the statistical significance and sign of the effect size estimates. We can therefore formalize the selective reporting process in terms of the one-sided p-values of the effect size estimates. Assuming that the degrees of freedom are large enough to not worry about, the one-sided p-value for effect size <img src="https://latex.codecogs.com/png.latex?i"> is a transformation of the effect size and its standard error: <span id="eq-p-onesided"><img src="https://latex.codecogs.com/png.latex?%0Ap_i%5E*%20=%201%20-%20%5CPhi%5Cleft(T_i%5E*%20/%20%5Csigma_i%5E*%5Cright)%0A%5Ctag%7B2%7D"></span> In the step-function model, we assume that the probability that an effect size estimate is reported (and thus available for meta-analysis) depends on where this one-sided p-value lies relative to a pre-specified set of significance thresholds, <img src="https://latex.codecogs.com/png.latex?%5Calpha_1,...,%5Calpha_H">. These thresholds define a set of intervals, each of which can have a different probability of selection. Let <img src="https://latex.codecogs.com/png.latex?O_i%5E*"> be a binary indicator equal to 1 if <img src="https://latex.codecogs.com/png.latex?T_i%5E*"> is reported and otherwise equal to zero. The selective reporting process is then <span id="eq-selection-process"><img src="https://latex.codecogs.com/png.latex?%0A%5CPr%5Cleft(O_i%5E*%20=%201%7C%20T_i%5E*,%20%5Csigma_i%5E*%5Cright)%20=%20%5Cbegin%7Bcases%7D%0A1%20&amp;%20%5Ctext%7Bif%7D%20%5Cquad%20p_i%5E*%20%3C%20%5Calpha_1%20%5C%5C%0A%5Clambda_1%20&amp;%20%5Ctext%7Bif%7D%20%5Cquad%20%5Calpha_h%20%5Cleq%20p_i%5E*%20%3C%20%5Calpha_%7Bh+1%7D,%20%5Cquad%20h%20=%201,...,H-1%20%5C%5C%0A%5Clambda_H%20&amp;%20%5Ctext%7Bif%7D%20%5Cquad%20%5Calpha_H%20%5Cleq%20p_i%5E*%20%5C%5C%0A%5Cend%7Bcases%7D.%0A%5Ctag%7B3%7D"></span> Note that the selection probability for the lowest interval <img src="https://latex.codecogs.com/png.latex?%5B0,%20%5Calpha_1)"> is fixed to 1 because we can’t estimate the absolute probability that an effect size estimate is reported. The remaining parameters of the selection process therefore each represent a ratio of the probability of reporting an effect size estimate falling in a given interval to the probability of reporting an effect size estimate falling in the lowest interval.</p>
<p>In practice, the analyst will need to specify the thresholds of the significance intervals in order to estimate the model. One common choice is to use only a single threshold at <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.025">, which corresponds to a two-sided level of .05—Fisher’s vaunted criteria for when a result should be considered significant. This is the so-called “three-parameter” selection model, where the parameters of interest are the average effect size <img src="https://latex.codecogs.com/png.latex?%5Cmu">, the heterogeneity SD <img src="https://latex.codecogs.com/png.latex?%5Ctau">, and the relative selection probability <img src="https://latex.codecogs.com/png.latex?%5Clambda_1">. Other possible choices for thresholds might be:</p>
<ul>
<li>A single threshold at <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.50">, so that negatively-signed effect size estimates have a different selection probability than positively-signed estimates;</li>
<li>A two-threshold model with <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.025"> and <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%20.50"> (I like to call this a four-parameter selection model); or</li>
<li>A model with thresholds for significant, positive results at <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.025">, for the sign of the estimate at <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%20.50">, and for statistically significant results in the opposite of the expected direction at <img src="https://latex.codecogs.com/png.latex?%5Calpha_3%20=%20.975">.</li>
</ul>
<p>Many other choices are possible, of course.</p>
</section>
<section id="distribution-of-observed-effect-sizes" class="level1 page-columns page-full">
<h1>Distribution of observed effect sizes</h1>
<p>Equations (1) and (3) are sufficient to describe the distribution of effect sizes actually observed after selection. If we let <img src="https://latex.codecogs.com/png.latex?T_i"> and <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> denote effect size estimates that are actually observed, then the distribution of <img src="https://latex.codecogs.com/png.latex?%5Cleft(T_i%20%7C%20%5Csigma_i%5Cright)"> is the same as that of <img src="https://latex.codecogs.com/png.latex?%5Cleft(T_i%5E*%20%7C%20%5Csigma_i%5E*,%20O_i%5E*%20=%201%5Cright)">. By Bayes Theorem, <span id="eq-observed-effect-distribution"><img src="https://latex.codecogs.com/png.latex?%0A%5CPr(T_i%20=%20t%20%7C%20%5Csigma_i)%20=%20%5Cfrac%7B%5CPr%5Cleft(O_i%5E*%20=%201%7C%20T_i%5E*%20=%20t,%20%5Csigma_i%5E*%20=%20%5Csigma_i%5Cright)%20%5Ctimes%20%5CPr(T_i%5E*%20%20=%20t%7C%20%5Csigma_i%5E*%20=%20%5Csigma_i)%7D%7B%5CPr%5Cleft(O_i%5E*%20=%201%7C%20%5Csigma_i%5E*%20=%20%5Csigma_i%5Cright)%7D%0A%5Ctag%7B4%7D"></span> For the specific distributional assumptions of the step-function selection model, we can find an expression for the exact form of (4). In doing so, it will be useful to define a further random variable—call it <img src="https://latex.codecogs.com/png.latex?S_i">—that is equal to the p-value interval into which effect size <img src="https://latex.codecogs.com/png.latex?T_i"> falls. For a given effect size with standard error <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*">, these intervals are equivalent to intervals on the scale of the outcome, with thresholds <img src="https://latex.codecogs.com/png.latex?%5Cgamma_%7Bhi%7D%20=%20%5Csigma_i%5E*%20%5CPhi%5E%7B-1%7D(1%20-%20%5Calpha_h)">. Now, let’s define <img src="https://latex.codecogs.com/png.latex?S_i%5E*"> as <img src="https://latex.codecogs.com/png.latex?%0AS_i%5E*%20=%20%5Cbegin%7Bcases%7D%0A0%20&amp;%20%5Ctext%7Bif%7D%20%5Cquad%20%5Cgamma_%7B1i%7D%20%3C%20T_i%5E*%20%5C%5C%0Ah%20&amp;%20%5Ctext%7Bif%7D%20%5Cquad%20%5Cgamma_%7Bh+1,i%7D%20%3C%20T_i%5E*%20%5Cleq%20%5Cgamma_%7Bhi%7D,%20%5Cquad%20h%20=%201,...,H-1%20%5C%5C%0AH%20&amp;%20%5Ctext%7Bif%7D%20%5Cquad%20T_i%5E*%20%5Cleq%20%5Cgamma_%7BHi%7D%20%5C%5C%0A%5Cend%7Bcases%7D%0A"> and <img src="https://latex.codecogs.com/png.latex?S_i"> as the corresponding interval for the observed effect size <img src="https://latex.codecogs.com/png.latex?T_i">. Note that (3) is equivalent to writing the relative selection probabilities as a function of <img src="https://latex.codecogs.com/png.latex?S_i">: <span id="eq-selection-weights"><img src="https://latex.codecogs.com/png.latex?%0Aw%5Cleft(T_i%5E*,%20%5Csigma_i%5E*%5Cright)%20=%20%5Clambda_%7BS_i%5E*%7D%0A%5Ctag%7B5%7D"></span> Also note that, prior to selection, the effect size estimate <img src="https://latex.codecogs.com/png.latex?T_i%5E*"> has marginal variance <img src="https://latex.codecogs.com/png.latex?%5Ceta_i%5E2%20=%20%5Ctau%5E2%20+%20%5Cleft(%5Csigma_i%5E*%5Cright)%5E2">, so we can write <img src="https://latex.codecogs.com/png.latex?%5CPr(T_i%5E*%20%20=%20t%7C%20%5Csigma_i%5E*)%20=%20%20%5Cfrac%7B1%7D%7B%5Ceta_i%7D%5Cphi%5Cleft(%5Cfrac%7Bt%20-%20%5Cmu%7D%7B%5Ceta_i%7D%5Cright)">, where <img src="https://latex.codecogs.com/png.latex?%5Cphi()"> is the standard normal density. We can then write the distribution of the observed effect size estimates as <span id="eq-observed-effect-density"><img src="https://latex.codecogs.com/png.latex?%0A%5CPr(T_i%20=%20t%20%7C%20%5Csigma_i)%20=%20%5Cfrac%7Bw%5Cleft(t,%20%5Csigma_i%5Cright)%20%5Ctimes%20%5Cfrac%7B1%7D%7B%5Ceta_i%7D%5Cphi%5Cleft(%5Cfrac%7Bt%20-%20%5Cmu%7D%7B%5Ceta_i%7D%5Cright)%7D%7BA_i%7D,%0A%5Ctag%7B6%7D"></span> where <span id="eq-Ai"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0AA_i%20&amp;=%20%5Cint%20w%5Cleft(t,%20%5Csigma_i%5E*%5Cright)%20%5Ctimes%20%5Cfrac%7B1%7D%7B%5Ceta_i%7D%5Cphi%5Cleft(%5Cfrac%7Bt%20-%20%5Cmu%7D%7B%5Ceta_i%7D%5Cright)%20dt%20%5C%5C%0A&amp;=%20%5Csum_%7Bh=0%7D%5EH%20%5Clambda_h%20B_%7Bhi%7D,%0A%5Cend%7Baligned%7D%0A%5Ctag%7B7%7D"></span> with <img src="https://latex.codecogs.com/png.latex?%0AB_%7Bhi%7D%20=%20%5CPhi%5Cleft(%5Cfrac%7B%5Cgamma_%7Bhi%7D%20-%20%5Cmu%7D%7B%5Ceta_i%7D%5Cright)%20-%20%5CPhi%5Cleft(%5Cfrac%7B%5Cgamma_%7Bh+1,i%7D%20-%20%5Cmu%7D%7B%5Ceta_i%7D%5Cright)%0A"> and where we take <img src="https://latex.codecogs.com/png.latex?%5Clambda_0%20=%201">, <img src="https://latex.codecogs.com/png.latex?%5Calpha_0%20=%200">, and <img src="https://latex.codecogs.com/png.latex?%5Calpha_%7BH+1%7D%20=%201"> <span class="citation" data-cites="hedges2005selection">(Hedges &amp; Vevea, 2005)</span>. Note that <img src="https://latex.codecogs.com/png.latex?A_i%20%20=%20%5CPr(O%5E*%20=%201%20%7C%20%5Csigma_i%5E*)">, the probability that an effect size estimate with precision <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*"> will be observed.</p>
<p>The observed effect size estimates follow what we might call a “piece-wise normal” distribution. For a given <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> and given the interval <img src="https://latex.codecogs.com/png.latex?S_i"> into which the effect size falls, the effect size follows a truncated normal distribution. Formally, <img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(T_i%20%7C%20S_i%20=%20h,%20%5Csigma_i%20%5Cright)%20%5Csim%20TN(%5Cmu,%5Ceta_i%5E2,%20%5Cgamma_%7Bh+1,i%7D,%5Cgamma_%7Bh%20i%7D).%0A"> Furthermore, the distribution of <img src="https://latex.codecogs.com/png.latex?S_i"> is given by <img src="https://latex.codecogs.com/png.latex?%0A%5CPr(S_i%20=%20h%20%7C%20%5Csigma_i)%20=%20%5Cfrac%7B%5Clambda_h%20B_%7Bhi%7D%7D%7B%5Csum_%7Bg=0%7D%5EH%20%5Clambda_g%20B_%7Bgi%7D%7D,%0A"> which will be useful for deriving moments of the distribution of <img src="https://latex.codecogs.com/png.latex?T_i">.</p>
<p>Here is an interactive graph showing the distribution of the effects prior to selection (in grey) and the distribution of observed effect sizes (in blue) based on a four-parameter selection model with selection thresholds of <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.025"> and <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%20.50">. Initially, the selection parameters are set to <img src="https://latex.codecogs.com/png.latex?%5Clambda_1%20=%200.6"> and <img src="https://latex.codecogs.com/png.latex?%5Clambda_2%20=%200.3">, but you can change these however you like.</p>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb1" data-startfrom="115" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 114;"><span id="cb1-115">math <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">require</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mathjs"</span>)</span>
<span id="cb1-116">norm <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://unpkg.com/norm-dist@3.1.0/index.js?module'</span>)</span>
<span id="cb1-117"></span>
<span id="cb1-118">eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> 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;">sqrt</span>(tau<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-119">H <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb1-120">alpha <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="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">025</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>]</span>
<span id="cb1-121">lambda <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda2]</span>
<span id="cb1-122">lambda_max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> 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;">max</span>(lambda)</span>
<span id="cb1-123"></span>
<span id="cb1-124"><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;">findlambda</span>(p<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alp<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lam) {</span>
<span id="cb1-125">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">var</span> m <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-126">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> alp[m]) {</span>
<span id="cb1-127">    m <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-128">  }</span>
<span id="cb1-129">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> lam[m]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-130">}</span>
<span id="cb1-131"></span>
<span id="cb1-132"><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;">findMoments</span>(mu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> tau<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alp<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lam) {</span>
<span id="cb1-133">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> H <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> alp<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-134">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> 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;">sqrt</span>(tau<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-135">  </span>
<span id="cb1-136">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> gamma_h <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(H<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</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;">map</span>((x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-137">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) {</span>
<span id="cb1-138">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">Infinity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-139">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span>H<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) {</span>
<span id="cb1-140">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">Infinity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-141">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb1-142">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> norm<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">icdf</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> alp[i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-143">    }</span>
<span id="cb1-144">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-145">  </span>
<span id="cb1-146">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> c_h <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(H<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</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;">map</span>((x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-147">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> (gamma_h[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-148">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-149"></span>
<span id="cb1-150">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> B_h <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(H<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</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;">map</span>((x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-151">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> norm<span 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>(c_h[i]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> norm<span 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>(c_h[i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb1-152">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-153"></span>
<span id="cb1-154">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> Ai <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-155">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> H<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) {</span>
<span id="cb1-156">    Ai <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> lam[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> B_h[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-157">  }</span>
<span id="cb1-158">  </span>
<span id="cb1-159">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> psi_h <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(H<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</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;">map</span>((x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-160">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> (norm<span 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>(c_h[i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> norm<span 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>(c_h[i])) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> B_h[i]</span>
<span id="cb1-161">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> </span>
<span id="cb1-162"></span>
<span id="cb1-163">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> psi_top <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-164">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> H<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) {</span>
<span id="cb1-165">    psi_top <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> lam[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> B_h[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> psi_h[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-166">  }</span>
<span id="cb1-167">  </span>
<span id="cb1-168">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> psi_bar <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> psi_top <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> Ai<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-169"></span>
<span id="cb1-170">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> ET <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> psi_bar<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-171"></span>
<span id="cb1-172">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> dc_h <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> c_h<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((c_val) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-173">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (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;">abs</span>(c_val) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">Infinity</span>) {</span>
<span id="cb1-174">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-175">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb1-176">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> c_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> norm<span 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>(c_val)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-177">    }</span>
<span id="cb1-178">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-179"></span>
<span id="cb1-180">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> kappa_h <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(H<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</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;">map</span>((x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-181">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> (dc_h[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> dc_h[i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> B_h[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-182">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-183"></span>
<span id="cb1-184">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> kappa_top <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-185">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> H<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) {</span>
<span id="cb1-186">    kappa_top <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> lam[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> B_h[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> kappa_h[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-187">  }</span>
<span id="cb1-188">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> kappa_bar <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> kappa_top <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> Ai<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-189">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> SDT <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> 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;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> kappa_bar <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> psi_bar<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-190">  </span>
<span id="cb1-191">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">Ai</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Ai<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;">ET</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> ET<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;">SDT</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> SDT})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-192">}</span>
<span id="cb1-193"></span>
<span id="cb1-194">moments <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findMoments</span>(mu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> tau<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda)</span>
<span id="cb1-195">Ai_toprint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> moments<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Ai</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb1-196">ET_toprint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> moments<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ET</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb1-197">eta_toprint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> eta<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb1-198">SDT_toprint <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> moments<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SDT</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-8" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-9" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-10" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-11" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-12" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-13" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-14" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb2" data-startfrom="203" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 202;"><span id="cb2-203">pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">201</span></span>
<span id="cb2-204"></span>
<span id="cb2-205">dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(pts)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</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;">map</span>((element<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> index) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-206">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> index <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-207">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> norm<span 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>(t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> sigma)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-208">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> dt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> norm<span 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>((t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-209">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> lambda_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findlambda</span>(p<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-210">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> ({</span>
<span id="cb2-211">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">t</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-212">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">d_unselected</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> dt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-213">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">d_selected</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> lambda_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> dt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> lambda_max</span>
<span id="cb2-214">  })</span>
<span id="cb2-215">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-2" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="grid column-page">
<div class="g-col-8 center">
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb3" data-startfrom="223" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 222;"><span id="cb3-223">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb3-224">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-225">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">700</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-226">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb3-227">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-228">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span></span>
<span id="cb3-229">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-230">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb3-231">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Effect size estimate (Ti)"</span></span>
<span id="cb3-232">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>   </span>
<span id="cb3-233">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb3-234">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-235">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-236">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">areaY</span>(dat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d_unselected"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-237">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">areaY</span>(dat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d_selected"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fillOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-238">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lineY</span>(dat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d_selected"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>})</span>
<span id="cb3-239">  ]</span>
<span id="cb3-240">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="expression">

</div>
</div>
</div>
<div class="moments">
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb4" data-startfrom="246" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 245;"><span id="cb4-246"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb4-247"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\b</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">egin{aligned}</span></span>
<span id="cb4-248"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">u &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>mu<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> &amp; </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\q</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">quad </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\e</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ta_i &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>eta_toprint<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span></span>
<span id="cb4-249"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">athbb{E}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">eft(T_i</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ight) &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>ET_toprint<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-250"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&amp; </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\q</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">quad </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\s</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">qrt{</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">athbb{V}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">eft(T_i</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ight)} &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>SDT_toprint<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span></span>
<span id="cb4-251"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\P</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">r(O_i^* = 1) &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>Ai_toprint<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-252"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\e</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">nd{aligned}</span></span>
<span id="cb4-253"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="expression">

</div>
</div>
</div>
</div>
</div>
<div class="g-col-4">
<div class="cell panel-input card bg-light p-2">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb5" data-startfrom="265" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 264;"><span id="cb5-265">viewof mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-266">  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-267">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">u`</span>}</span>
<span id="cb5-268">)</span>
<span id="cb5-269"></span>
<span id="cb5-270">viewof tau <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-271">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-272">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\t</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">au`</span>}</span>
<span id="cb5-273">)</span>
<span id="cb5-274"></span>
<span id="cb5-275">viewof sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-276">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-277">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.20</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\s</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">igma_i`</span>}</span>
<span id="cb5-278">)</span>
<span id="cb5-279"></span>
<span id="cb5-280">viewof lambda1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-281">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-282">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.60</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ambda_1`</span>}</span>
<span id="cb5-283">)</span>
<span id="cb5-284"></span>
<span id="cb5-285">viewof lambda2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-286">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-287">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.30</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ambda_2`</span>}</span>
<span id="cb5-288">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-5" data-nodetype="declaration">

</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section id="moments-of-t_i-sigma_i" class="level1">
<h1>Moments of <img src="https://latex.codecogs.com/png.latex?T_i%20%7C%20%5Csigma_i"></h1>
<p>Using the auxiliary random variable <img src="https://latex.codecogs.com/png.latex?S_i"> makes it pretty straight-forward to find the moments of <img src="https://latex.codecogs.com/png.latex?T_i%20%7C%20%5Csigma_i">. Let me denote <img src="https://latex.codecogs.com/png.latex?%0A%5Cpsi_%7Bhi%7D%20=%20%5Cfrac%7B%5Cphi%5Cleft(c_%7Bh+1,i%7D%5Cright)%20-%20%5Cphi%5Cleft(c_%7Bhi%7D%5Cright)%7D%7BB_%7Bhi%7D%7D,%0A"> where <img src="https://latex.codecogs.com/png.latex?c_%7Bhi%7D%20=%20%5Cleft(%5Cgamma_%7Bhi%7D%20-%20%5Cmu%5Cright)%20/%20%5Ceta_i"> for <img src="https://latex.codecogs.com/png.latex?h=0,...,H">. Then from the properties of truncated normal distributions, <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BE%7D(T_i%20%7C%20S_i%20=%20h,%20%5Csigma_i)%20=%20%5Cmu%20+%20%5Ceta_i%20%5Ctimes%20%5Cpsi_%7Bhi%7D,%0A"> It follows immediately that <span id="eq-Ti-expectation"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathbb%7BE%7D(T_i%20%7C%20%5Csigma_i)%20&amp;=%20%5Csum_%7Bh=0%7D%5EH%20%5CPr(S_i%20=%20h%20%7C%20%5Csigma_i)%20%5Ctimes%20%5Cmathbb%7BE%7D(T_i%20%7C%20S_i%20=%20h,%20%5Csigma_i)%20%5C%5C%0A&amp;=%20%5Cmu%20+%20%5Ceta_i%20%5Cfrac%7B%5Csum_%7Bh=0%7D%5EH%20%5Clambda_h%20B_%7Bhi%7D%20%5Cpsi_%7Bhi%7D%7D%7B%5Csum_%7Bh=0%7D%5EH%20%5Clambda_h%20B_%7Bhi%7D%7D.%0A%5Cend%7Baligned%7D%0A%5Ctag%7B8%7D"></span> The second term of (8) is the bias of <img src="https://latex.codecogs.com/png.latex?T_i"> relative to the overall mean effect <img src="https://latex.codecogs.com/png.latex?%5Cmu">. Generally, it will depend on all the parameters of the evidence-generating process, including <img src="https://latex.codecogs.com/png.latex?%5Csigma_i">, <img src="https://latex.codecogs.com/png.latex?%5Cmu">, and <img src="https://latex.codecogs.com/png.latex?%5Ctau"> (through the <img src="https://latex.codecogs.com/png.latex?c_%7Bhi%7D"> and <img src="https://latex.codecogs.com/png.latex?B_%7Bhi%7D"> terms) and on the selection weights <img src="https://latex.codecogs.com/png.latex?%5Clambda_1,...,%5Clambda_H">.</p>
<p>Just for giggles, let me chug through and get the variance of <img src="https://latex.codecogs.com/png.latex?T_i"> as well. Letting <img src="https://latex.codecogs.com/png.latex?%0A%5Cbar%5Cpsi_i%20=%20%5Cfrac%7B%5Csum_%7Bh=0%7D%5EH%20%5Clambda_h%20B_%7Bhi%7D%20%5Cpsi_%7Bhi%7D%7D%7B%5Csum_%7Bh=0%7D%5EH%20%5Clambda_h%20B_%7Bhi%7D%7D%0A"> and <img src="https://latex.codecogs.com/png.latex?%0A%5Ckappa_%7Bhi%7D%20=%20%5Cfrac%7Bc_%7Bhi%7D%20%5Cphi%5Cleft(c_%7Bhi%7D%5Cright)%20-%20c_%7Bh+1,i%7D%20%5Cphi%5Cleft(c_%7Bh+1,i%7D%5Cright)%7D%7BB_%7Bhi%7D%7D,%0A"> we can write the variance of the truncated normal conditional distribution <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BV%7D(T_i%20%7C%20S_i%20=%20h,%20%5Csigma_i)%20=%20%5Ceta_i%5E2%20%5Cleft(1%20-%20%5Ckappa_%7Bhi%7D%20-%20%5Cpsi_%7Bhi%7D%5E2%5Cright).%0A"> Using variance decomposition, we then have <span id="eq-Ti-variance"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathbb%7BV%7D(T_i%20%7C%20%5Csigma_i)%20&amp;=%20%5Cmathbb%7BE%7D%5Cleft%5B%5Cmathbb%7BV%7D(T_i%20%7C%20S_i,%20%5Csigma_i)%5Cright%5D%20+%20%5Cmathbb%7BV%7D%5Cleft%5B%5Cmathbb%7BE%7D(T_i%20%7C%20S_i,%20%5Csigma_i)%5Cright%5D%20%5C%5C%0A&amp;=%20%5Cmathbb%7BE%7D%5Cleft%5B%5Cmathbb%7BV%7D(T_i%20%7C%20S_i,%20%5Csigma_i)%20+%20%5Cleft%5B%5Cmathbb%7BE%7D(T_i%20%7C%20S_i,%20%5Csigma_i)%20-%20%5Cmathbb%7BE%7D(T_i%20%7C%20%5Csigma_i)%5Cright%5D%5E2%5Cright%5D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B%5Csum_%7Bh=0%7D%5EH%20%5Clambda_h%20B_%7Bhi%7D%7D%20%5Csum_%7Bh=0%7D%5EH%20%5Clambda_h%20B_%7Bhi%7D%20%5Cleft(%20%5Ceta_i%5E2%20%5Cleft(1%20-%20%5Ckappa_%7Bhi%7D%20-%20%5Cpsi_%7Bhi%7D%5E2%5Cright)%20+%20%5Ceta_i%5E2%20%20%5Cleft%5B%5Cpsi_%7Bhi%7D%20-%20%5Cbar%5Cpsi_i%20%5Cright%5D%5E2%5Cright)%20%5C%5C%0A&amp;=%20%5Ceta_i%5E2%20%5Cleft(1%20-%20%5Cbar%5Ckappa_i%20-%20%5Cbar%5Cpsi_i%5E2%5Cright),%0A%5Cend%7Baligned%7D%0A%5Ctag%7B9%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%0A%5Cbar%5Ckappa_i%20=%20%5Cfrac%7B%5Csum_%7Bh=0%7D%5EH%20%5Clambda_h%20B_%7Bhi%7D%20%5Ckappa_%7Bhi%7D%7D%7B%5Csum_%7Bh=0%7D%5EH%20%5Clambda_h%20B_%7Bhi%7D%7D%0A"> Just as with the expectation, the variance is a complicated function of all the model parameters.</p>
</section>
<section id="funnel-density" class="level1 page-columns page-full">
<h1>Funnel density</h1>
<p>The graph above shows the distribution of observed effect size estimates with a given sampling standard error <img src="https://latex.codecogs.com/png.latex?%5Csigma_i">. In practice, meta-analysis datasets include many effect sizes with a range of different standard errors. Funnel plots are a commonly used graphical representation the distribution of effects in a meta-analysis. They are simply scatterplots, showing effect size estimates on the horizontal axis and standard errors (or some measure of precision) on the vertical axis. Usually, they are arranged so that effects from larger studies appear closer to the top of the plot. Funnel plots are often used a diagnostic for selective reporting because they will tend to be asymmetric when non-affirmative effects are less likely to be reported than affirmative effects.</p>
<p>I think it’s pretty useful to use the layout of a funnel plot to understand how meta-analytic models work. A basic random effects model implies a certain distribution of population effects, which can be represented by the density of points in a funnel plot.<sup>1</sup> That density will have a shape kind of like an upside down funnel: narrow near the top (where studies are large and <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> is small), getting wider and wider as <img src="https://latex.codecogs.com/png.latex?%5Csigma_i"> increases (i.e., as studies get smaller and smaller).</p>
<p>Here’s an illustration of this density, using darker color to indicate areas of the plot where effect sizes are more likely. I’ve used <img src="https://latex.codecogs.com/png.latex?%5Cmu%20=%200.15"> (represented by the vertical red line) and <img src="https://latex.codecogs.com/png.latex?%5Ctau%20=%200.10"> to calculate the density. The vertical gray line corresponds to <img src="https://latex.codecogs.com/png.latex?%5Cmu%20=%200">, which is also the threshold where effect size estimates will have <img src="https://latex.codecogs.com/png.latex?p">-values of <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20.50">. The sloped gray line corresponds to the treshold where effect size estimates have <img src="https://latex.codecogs.com/png.latex?p">-values of <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20.025">; to the right of this line, effects will be statistically significant and affirmative; to the left, effects are non-affirmative.</p>
<div class="cell">
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/step-function-selection-models/index_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" style="width:90.0%"></p>
</figure>
</div>
</div>
</div>
<p>The above graph shows the (conditional) distribution of effect size estimates under the random effects model, without any selective reporting. Selective reporting of study results will distort this distribution, shrinking the density for effects that are not affirmative.</p>
<p>Here is an interactive funnel plot showing the distribution of effect size estimates under a four-parameter selection model. Just as in the interactive graph above, I use fixed selection thresholds of <img src="https://latex.codecogs.com/png.latex?%5Calpha_1%20=%20.025"> and <img src="https://latex.codecogs.com/png.latex?%5Calpha_2%20=%20.50">. Initially, I set <img src="https://latex.codecogs.com/png.latex?%5Cmu%20=%200.15"> and <img src="https://latex.codecogs.com/png.latex?%5Ctau%20=%200.10"> and selection parameters of <img src="https://latex.codecogs.com/png.latex?%5Clambda_1%20=%200.6"> and <img src="https://latex.codecogs.com/png.latex?%5Clambda_2%20=%200.3">, but you can change these however you like.</p>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb6" data-startfrom="412" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 411;"><span id="cb6-412">SE_pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span></span>
<span id="cb6-413">t_pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">181</span></span>
<span id="cb6-414">lambda_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda1_f<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda2_f]</span>
<span id="cb6-415">alpha_f <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="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">025</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>]</span>
<span id="cb6-416">sigma_max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span></span>
<span id="cb6-417">eta_max_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> 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;">sqrt</span>(tau_f<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sigma_max<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb6-418"></span>
<span id="cb6-419">funnel_dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(t_pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> SE_pts)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</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;">map</span>((x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>row) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb6-420">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> SE_pts<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-421">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> j <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> i) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> SE_pts<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-422">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sigma_max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> SE_pts<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-423">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> mu_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> eta_max_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> eta_max_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (t_pts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-424">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> eta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> 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;">sqrt</span>(tau_f<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-425">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> norm<span 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>(t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> sigma)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-426">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> dt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> norm<span 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>((t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu_f) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> eta<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-427">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> lambda_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findlambda</span>(p<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> alpha_f<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> lambda_f)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-428">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">i</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">j</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> j<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;">t</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">sigma</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> sigma<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;">eta</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> eta<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;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> p<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">dt</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> dt<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;">lambda</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> lambda_val<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;">d_selected</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> lambda_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> dt})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb6-429">})</span>
<span id="cb6-430"></span>
<span id="cb6-431">sigline_dat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb6-432">  ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">t</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">sigma</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-433">  ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">t</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> sigma_max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> norm<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">icdf</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">sigma</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> sigma_max})</span>
<span id="cb6-434">]</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-6-8" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="grid column-page">
<div class="g-col-8 center">
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb7" data-startfrom="443" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 442;"><span id="cb7-443">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb7-444">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">400</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-445">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">700</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-446">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">padding</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-447">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-448">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">axis</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Effect size estimate (Ti)"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-449">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Standard error (sigma_i)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">reverse</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-450">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb7-451">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">scheme</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pubugn"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-452">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sqrt"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-453">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span></span>
<span id="cb7-454">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-455">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb7-456">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>(funnel_dat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"d_selected"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">symbol</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"square"</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-457">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-458">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleX</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey"</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-459">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">line</span>(sigline_dat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>})</span>
<span id="cb7-460">  ]</span>
<span id="cb7-461">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-7" data-nodetype="expression">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb8" data-startfrom="465" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 464;"><span id="cb8-465">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">legend</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">scheme</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pubugn"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sqrt"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>}})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-8" data-nodetype="expression">

</div>
</div>
</div>
</div>
<div class="g-col-4">
<div class="cell panel-input card bg-light p-2">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb9" data-startfrom="476" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 475;"><span id="cb9-476">viewof mu_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb9-477">  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb9-478">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.15</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">u`</span>}</span>
<span id="cb9-479">)</span>
<span id="cb9-480"></span>
<span id="cb9-481">viewof tau_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb9-482">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb9-483">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\t</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">au`</span>}</span>
<span id="cb9-484">)</span>
<span id="cb9-485"></span>
<span id="cb9-486">viewof lambda1_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb9-487">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb9-488">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.60</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ambda_1`</span>}</span>
<span id="cb9-489">)</span>
<span id="cb9-490"></span>
<span id="cb9-491">viewof lambda2_f <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb9-492">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb9-493">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.30</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ambda_2`</span>}</span>
<span id="cb9-494">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-9-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-9-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-9-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-9-4" data-nodetype="declaration">

</div>
</div>
</div>
</div>
</div>
</div>
<p>If you fiddle with the selection parameters, you will see that the density of certain areas of the plot changes. For instance, lowering <img src="https://latex.codecogs.com/png.latex?%5Clambda_2"> will reduce the density of negative effect size estimates; lowering <img src="https://latex.codecogs.com/png.latex?%5Clambda_1"> will reduce the density of positive but non-affirmative effect size estimates, which fall between the vertical axis and the diagonal line corresponding to <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20.025">.</p>
</section>
<section id="comment" class="level1">
<h1>Comment</h1>
<p>In this post, I’ve given expressions for the density of effect size estimates under the step-function selection model, as well as expressions for the mean and variance of effect size estimates of a given precision (i.e., for <img src="https://latex.codecogs.com/png.latex?T_i%20%7C%20%5Csigma_i">). Although these expressions are pretty complex, it seems like they could be useful for studying the properties of different estimators that have been proposed for dealing with selective reporting, such as the “unrestricted weighted least squares” method, which is just the idea of using fixed effects weights even though the effects are heterogeneous <span class="citation" data-cites="henmi2010confidence stanley2014metaregression">(Henmi &amp; Copas, 2010; Stanley &amp; Doucouliagos, 2014)</span>; the PET and PEESE estimators <span class="citation" data-cites="stanley2008metaregression">(Stanley, 2008)</span>; the endogenous kink meta-regression <span class="citation" data-cites="bom2019kinked">(Bom &amp; Rachinger, 2019)</span>; and perhaps other estimators in the literature. Graphical depictions of the step function density (as in the funnel plot above) also seem potentially useful for understanding the properties of these estimators.</p>


<!-- -->


</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" data-line-spacing="2">
<div id="ref-bom2019kinked" class="csl-entry">
Bom, P. R. D., &amp; Rachinger, H. (2019). A kinked meta-regression model for publication bias correction. <em>Research Synthesis Methods</em>, <em>10</em>(4), 497–514. <a href="https://doi.org/10.1002/jrsm.1352">https://doi.org/10.1002/jrsm.1352</a>
</div>
<div id="ref-hedges1992modeling" class="csl-entry">
Hedges, L. V. (1992). Modeling publication selection effects in meta-analysis. <em>Statistical Science</em>, <em>7</em>(2), 246–255. <a href="https://doi.org/10.1214/ss/1177011364">https://doi.org/10.1214/ss/1177011364</a>
</div>
<div id="ref-hedges2005selection" class="csl-entry">
Hedges, L. V., &amp; Vevea, J. L. (2005). Selection method approaches. In <em>Publication bias in meta-analysis: Prevention, assessment, and adjustments</em> (pp. 145–174). John Wiley &amp; Sons.
</div>
<div id="ref-henmi2010confidence" class="csl-entry">
Henmi, M., &amp; Copas, J. B. (2010). Confidence intervals for random effects meta-analysis and robustness to publication bias. <em>Statistics in Medicine</em>, <em>29</em>(29), 2969–2983.
</div>
<div id="ref-stanley2008metaregression" class="csl-entry">
Stanley, T. D. (2008). Meta-regression methods for detecting and estimating empirical effects in the presence of publication selection*. <em>Oxford Bulletin of Economics and Statistics</em>, <em>70</em>(1), 103–127. <a href="https://doi.org/10.1111/j.1468-0084.2007.00487.x">https://doi.org/10.1111/j.1468-0084.2007.00487.x</a>
</div>
<div id="ref-stanley2014metaregression" class="csl-entry">
Stanley, T. D., &amp; Doucouliagos, H. (2014). Meta-regression approximations to reduce publication selection bias. <em>Research Synthesis Methods</em>, <em>5</em>(1), 60–78.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>To be precise, the density will depend on the marginal distribution of <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*">’s in the population of effects. I’m going to side-step this problem by using the funnel plot layout to show the <em>conditional</em> distribution of the effect size estimates, given <img src="https://latex.codecogs.com/png.latex?%5Csigma_i%5E*%20=%20%5Csigma_i">.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>effect size</category>
  <category>distribution theory</category>
  <category>selective reporting</category>
  <guid>https://jepusto.netlify.app/posts/step-function-selection-models/</guid>
  <pubDate>Tue, 09 Jul 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Simulating bootstrap confidence intervals</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/Simulating-bootstrap-CIs/</link>
  <description><![CDATA[ 





<p>Bootstrapping is a brilliant statistical idea. I realize that it’s become pretty routine, these days, and maybe has lost some of the magical veneer it once had, but I will fess up that I am still a fanboy. I teach my students to think of bootstrapping as your back-pocket tool for inference: if you’re not sure how to get a standard error or a confidence interval for some quantity that you’ve estimated, bootstrapping is probably a good place to start—and possibly good enough.</p>
<p>The core idea behind bootstrap inference is to use simulation to emulate the process of collecting a sample, and to take the variation across simulation results as a proxy for the sampling uncertainty in your real data. A sample of <img src="https://latex.codecogs.com/png.latex?B"> simulated results (which we might call <em>booties</em>) form the basis of bootstrap standard errors, confidence intervals, hypothesis tests, and the like. The simulation process can be as simple as re-sampling observations from your original data, in which case the original sample is a stand-in for the population and each re-sample is a replication of the process of collecting a dataset for analysis. Other simulation processes are possible too, which can account for more complex study designs or make stronger use of parametric modeling assumptions.</p>
<p>Across all its variations, bootstrapping involves using brute-force computation to do something that would otherwise take a bunch of math (like <a href="../..\posts/Multivariate-delta-method/">delta-method</a> calculations). This same feature makes it a royal pain to study bootstrap techniques using Monte Carlo simulation. In a Monte Carlo simulation, one has to generate hypothetical data, apply an estimator to each simulated dataset, and then repeat the whole process <img src="https://latex.codecogs.com/png.latex?R"> times (for some large <img src="https://latex.codecogs.com/png.latex?R">) to see the sampling distribution of the estimator. But if the estimator itself requires doing a bunch of re-sampling (or some other form of simulation) just to get one confidence interval, then the computation involved in the whole process can be pretty demanding. In this post, I’ll look at a trick that can make the whole process a bit more efficient.</p>
<p><span class="citation" data-cites="boos2000MonteCarloEvaluation">Boos &amp; Zhang (2000)</span> proposed a technique for approximating the power of a <img src="https://latex.codecogs.com/png.latex?B%20=%20%5Cinfty"> bootstrap test, while using only a finite, feasibly small number of replicates. Their work focused on hypothesis tests, but the approach applies directly to confidence interval simulations as well. The trick is to calculate the bootstrap test several times for each replication, each time with a different number of booties, and then extrapolate to <img src="https://latex.codecogs.com/png.latex?B%20=%20%5Cinfty">.</p>
<section id="simulating-a-bootstrap" class="level1">
<h1>Simulating a bootstrap</h1>
<p>Suppose we’re doing a simulation to evaluate the properties of a some sort of bootstrap confidence interval, where the main performance characteristics of interest are the coverage rate and the average width of the intervals. The simulation process will need to be repeated <img src="https://latex.codecogs.com/png.latex?R"> times, and <img src="https://latex.codecogs.com/png.latex?R"> will need to be fairly large to control the Monte Carlo error in the simulation results (e.g., to ensure that Monte Carlo standard errors for coverage rates will be less than 1%, we’ll need to run at least 2500 replications). For each of those replications, we’ll need to do <img src="https://latex.codecogs.com/png.latex?B"> bootstrap replications (ahem, <em>booties</em>!) to obtain a confidence interval. On top of all that, we will also often want to repeat the whole process across a number of different conditions. For example, the first simulation in <span class="citation" data-cites="joshiClusterWildBootstrapping2022">Joshi et al. (2022)</span> involved a <img src="https://latex.codecogs.com/png.latex?4%20%5Ctimes%202%20%5Ctimes%202%20%5Ctimes%2011"> factorial design (176 total conditions), with <img src="https://latex.codecogs.com/png.latex?R%20=%202400"> replications per condition and <img src="https://latex.codecogs.com/png.latex?B%20=%20399"> booties per replication. It quickly adds up—or rather, it quickly multiplies out!</p>
<p>A challenge here is that the power of a bootstrap hypothesis test depends on <img src="https://latex.codecogs.com/png.latex?B"> <span class="citation" data-cites="davidson2000BootstrapTestsHow">(as discussed in Davidson &amp; MacKinnon, 2000)</span>; by extension, so too does the coverage rate and width of a bootstrap confidence interval. If we use only a small number of booties, then the simulation results will under-state coverage relative to what we might obtain when applying the method in practice (where we might use something more like <img src="https://latex.codecogs.com/png.latex?B%20=%201999"> or <img src="https://latex.codecogs.com/png.latex?3999">) But if we use a realistically large number of booties, then our simulations will take forever to finish…or we’ll have to cut down on the number of conditions include…or both…or maybe we’ll decide that the delta-method math isn’t so bad after all.</p>
</section>
<section id="extrapolating" class="level1">
<h1>Extrapolating</h1>
<p>Now imagine that we generate <img src="https://latex.codecogs.com/png.latex?B"> booties, but then take several simple random sub-samples from the booties, of size <img src="https://latex.codecogs.com/png.latex?B_1%20%3C%20B_2%20%3C...%20%3C%20B_P%20=%20B">. Each of these is a valid bootstrap sample, but using a smaller number of booties. We can calculate a confidence interval for each one, so we end up with a total of <img src="https://latex.codecogs.com/png.latex?P%20%5Ctimes%20R"> confidence intervals. Let <img src="https://latex.codecogs.com/png.latex?C_%7Bbr%7D"> be an indicator for whether replication <img src="https://latex.codecogs.com/png.latex?r"> of the confidence interval with <img src="https://latex.codecogs.com/png.latex?b"> booties covers the true parameter, for <img src="https://latex.codecogs.com/png.latex?b%20=%20B_1,B_2,...,B_P"> and <img src="https://latex.codecogs.com/png.latex?r%20=%201,...,R">. We can extrapolate the coverage rate using a linear regression<sup>1</sup> of <img src="https://latex.codecogs.com/png.latex?C_%7Bbr%7D"> on <img src="https://latex.codecogs.com/png.latex?1%20/%20b">: <img src="https://latex.codecogs.com/png.latex?%0AC_%7Bbr%7D%20=%20%5Calpha_0%20+%20%5Calpha_1%20%5Cfrac%7B1%7D%7Bb%7D%20+%20%5Cepsilon_%7Bbr%7D.%0A"> Then <img src="https://latex.codecogs.com/png.latex?%5Calpha_0"> is the coverage rate when <img src="https://latex.codecogs.com/png.latex?b%20=%20%5Cinfty">. The outcomes <img src="https://latex.codecogs.com/png.latex?C_%7BB_1r%7D,...,C_%7BB_P%20r%7D"> will be dependent because they’re based on the same set of booties. However, the replicates are independent, so we can just use cluster-robust variance estimators to get Monte Carlo standard errors for an estimate of <img src="https://latex.codecogs.com/png.latex?%5Calpha_0">. Essentially the same thing works for extrapolating the width of a <img src="https://latex.codecogs.com/png.latex?B%20=%20%5Cinfty"> confidence interval: just replace <img src="https://latex.codecogs.com/png.latex?C_%7Bbr%7D"> with <img src="https://latex.codecogs.com/png.latex?W_%7Bbr%7D">, the width of the confidence interval based on the <img src="https://latex.codecogs.com/png.latex?b%5E%7Bth%7D"> bootstrap subsample from replication <img src="https://latex.codecogs.com/png.latex?r">.</p>
<p>In the context of hypothesis testing problems, <span class="citation" data-cites="boos2000MonteCarloEvaluation">Boos &amp; Zhang (2000)</span> actually proposed something a little bit more complicated than what I’ve described above. Instead of just taking a single sub-sample of each size <img src="https://latex.codecogs.com/png.latex?B_1,...,B_P">, they note that that expected rejection rate for each size sub-sample can be computed using hypergeometric probabilities. The same thing works for computing confidence interval coverage, but I don’t see any way to make it work for confidence interval width. However, instead of computing just one sub-sample of size <img src="https://latex.codecogs.com/png.latex?b">, we could compute several and then average across them to approximate the expected value of <img src="https://latex.codecogs.com/png.latex?C_%7Bbr%7D"> or <img src="https://latex.codecogs.com/png.latex?W_%7Bbr%7D"> given the full set of <img src="https://latex.codecogs.com/png.latex?B"> booties.</p>
</section>
<section id="an-example" class="level1 page-columns page-full">
<h1>An example</h1>
<p>Here’s an example of how this all works. For sake of simplicity (and compute time), I’m going to use an overly simple, not particularly well-motivated example of bootstrapping: using a percentile bootstrap for the population mean, where the estimator is a trimmed sample mean. As a data-generating process, I’ll use a shifted <img src="https://latex.codecogs.com/png.latex?t"> distribution with population mean <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and degrees of freedom <img src="https://latex.codecogs.com/png.latex?%5Cnu">: <img src="https://latex.codecogs.com/png.latex?%0AY_1,...,Y_N%20%5Cstackrel%7Biid%7D%7B%5Csim%7D%20%5Cmu%20+%20t(%5Cnu)%0A"> Or in R code:</p>
<div class="cell">
<details open="" 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;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20240629</span>)</span>
<span id="cb1-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;">50</span></span>
<span id="cb1-3">mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb1-4">nu <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;">5</span></span>
<span id="cb1-5">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rt</span>(N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> nu)</span></code></pre></div></div>
</details>
</div>
<p>As an estimator, I’ll use the 10% trimmed mean:</p>
<div class="cell">
<details open="" 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">y_bar_trim <span class="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>(dat, <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.1</span>)</span></code></pre></div></div>
</details>
</div>
<p>A bootstrap confidence interval for <img src="https://latex.codecogs.com/png.latex?%5Cmu"> can be computed as follows:</p>
<div class="cell">
<details open="" 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">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;">399</span></span>
<span id="cb3-2">booties <span class="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>(B, {</span>
<span id="cb3-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(dat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</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.1</span>)</span>
<span id="cb3-5">})</span>
<span id="cb3-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(booties, <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;">025</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">975</span>))</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>    2.5%    97.5% 
1.491885 2.255334 </code></pre>
</div>
</div>
<p>Now, instead of computing just the one CI based on all <img src="https://latex.codecogs.com/png.latex?B"> booties, I’ll also compute confidence intervals for several smaller subsamples from the booties:</p>
<div class="cell">
<details open="" 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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb5-2"></span>
<span id="cb5-3">B_vals <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">39</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">59</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">79</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">199</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">399</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># sub-sample sizes</span></span>
<span id="cb5-4">m <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;">10</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># number of CIs per B_val</span></span>
<span id="cb5-5"></span>
<span id="cb5-6">sub_boots <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(B_vals, \(x) {</span>
<span id="cb5-7">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</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;">length</span>(booties)) m <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>L</span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">replicate</span>(m , {</span>
<span id="cb5-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(booties, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</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;">025</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">975</span>))</span>
<span id="cb5-11">  }, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simplify =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb5-12">})</span></code></pre></div></div>
</details>
</div>
<p>The result in <code>sub_boots</code> is a list with one entry per sub-sample size, where each entry includes <img src="https://latex.codecogs.com/png.latex?m%20=%2010"> bootstrap confidence intervals.</p>
<p>Now I’ll compute the expected coverage rate and interval width for each of the <code>B_vals</code>:</p>
<div class="cell">
<details open="" 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">boot_coverage <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(sub_boots, \(x) {</span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(x, \(y) y[<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;">&lt;</span> mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> y[<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="cb6-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>()</span>
<span id="cb6-4">})</span>
<span id="cb6-5">boot_width <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(sub_boots, \(x) {</span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(x, diff) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>()</span>
<span id="cb6-8">})</span>
<span id="cb6-9">boot_performance <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb6-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B =</span> B_vals,</span>
<span id="cb6-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">coverage =</span> boot_coverage,</span>
<span id="cb6-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> boot_width</span>
<span id="cb6-13">)</span>
<span id="cb6-14">boot_performance</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>    B coverage     width
1  39        1 0.7400180
2  59        1 0.7680832
3  79        1 0.7214260
4  99        1 0.7424530
5 199        1 0.7519438
6 399        1 0.7809795</code></pre>
</div>
</div>
<section id="across-replications" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="across-replications">Across replications</h2>
<p>The above is just for a single realization of the data-generating process, so it’s not particularly revealing. More interesting is if we replicate the whole process a bunch of times:</p>
<div class="cell">
<details open="" 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">dgp <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, mu, nu) {</span>
<span id="cb8-2">  mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rt</span>(N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">df =</span> nu)</span>
<span id="cb8-3">}</span>
<span id="cb8-4"></span>
<span id="cb8-5">estimator <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="cb8-6">    dat, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># data</span></span>
<span id="cb8-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_vals =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">399</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># number of booties to evaluate</span></span>
<span id="cb8-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;">1</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># CIs to replicate per sub-sample size</span></span>
<span id="cb8-9">    <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.1</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># trimming percentage</span></span>
<span id="cb8-10">  ) {</span>
<span id="cb8-11">  </span>
<span id="cb8-12">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute booties</span></span>
<span id="cb8-13">  N <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(dat)</span>
<span id="cb8-14">  booties <span class="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>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(B_vals), {</span>
<span id="cb8-15">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(dat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb8-16">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</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.1</span>)</span>
<span id="cb8-17">  })</span>
<span id="cb8-18"></span>
<span id="cb8-19">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># confidence intervals for each B_vals</span></span>
<span id="cb8-20">  sub_boots <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(B_vals, \(x) {</span>
<span id="cb8-21">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</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;">length</span>(booties)) m <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>L</span>
<span id="cb8-22">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">replicate</span>(m , {</span>
<span id="cb8-23">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>(booties, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">replace =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-24">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</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;">025</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">975</span>))</span>
<span id="cb8-25">    }, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simplify =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb8-26">  })</span>
<span id="cb8-27"></span>
<span id="cb8-28">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># coverage rates</span></span>
<span id="cb8-29">  boot_coverage <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(sub_boots, \(x) {</span>
<span id="cb8-30">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(x, \(y) y[<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;">&lt;</span> mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> y[<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="cb8-31">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>()</span>
<span id="cb8-32">  })</span>
<span id="cb8-33">  </span>
<span id="cb8-34">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># CI widths</span></span>
<span id="cb8-35">  boot_width <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(sub_boots, \(x) {</span>
<span id="cb8-36">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(x, diff) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb8-37">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>()</span>
<span id="cb8-38">  })</span>
<span id="cb8-39">  </span>
<span id="cb8-40">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># put it all together</span></span>
<span id="cb8-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb8-42">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B =</span> B_vals,</span>
<span id="cb8-43">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">coverage =</span> boot_coverage,</span>
<span id="cb8-44">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> boot_width</span>
<span id="cb8-45">  )</span>
<span id="cb8-46">}</span>
<span id="cb8-47"></span>
<span id="cb8-48"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># build a simulation driver function</span></span>
<span id="cb8-49"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(simhelpers)</span>
<span id="cb8-50">simulate_bootCIs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bundle_sim</span>(</span>
<span id="cb8-51">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">f_generate =</span> dgp,</span>
<span id="cb8-52">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">f_analyze =</span> estimator</span>
<span id="cb8-53">)</span>
<span id="cb8-54"></span>
<span id="cb8-55"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># run the simulation</span></span>
<span id="cb8-56">res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simulate_bootCIs</span>(</span>
<span id="cb8-57">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>,</span>
<span id="cb8-58">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">N =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,</span>
<span id="cb8-59">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb8-60">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nu =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb8-61">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_vals =</span> B_vals,</span>
<span id="cb8-62">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">m =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span></span>
<span id="cb8-63">)</span></code></pre></div></div>
</details>
</div>
<p>The object <code>res</code> has 2500 replications of the bootstrapping process, where each replication has averaged coverage rates for <img src="https://latex.codecogs.com/png.latex?B_1%20=%2039,...,B_6%20=%20399">.</p>
<p>Summarizing across replications results in the following:</p>
<div class="cell page-columns page-full">
<details class="code-fold">
<summary>Code</summary>
<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">sim_summary <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb9-2">  res <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(B) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb9-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">coverage_M =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(coverage),</span>
<span id="cb9-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">coverage_SE =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(coverage) <span 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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()),</span>
<span id="cb9-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width_M =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(width),</span>
<span id="cb9-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width_SE =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(width) <span 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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()),</span>
<span id="cb9-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="cb9-10">  )</span>
<span id="cb9-11"></span>
<span id="cb9-12">qn <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qnorm</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.975</span>)</span>
<span id="cb9-13"></span>
<span id="cb9-14">sim_summary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(</span>
<span id="cb9-16">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ends_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_M"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ends_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_SE"</span>)), </span>
<span id="cb9-17">    <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;">"metric"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".value"</span>), </span>
<span id="cb9-18">    <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="cb9-19">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-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> B, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> M) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">transform =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reciprocal"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(B_vals, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9999</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_limits</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9999</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-24">  <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;">fullrange =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">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="cb9-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_pointrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> M <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> qn <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> SE, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> M <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> qn <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> SE)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-26">  <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> metric, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bootstraps (B)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display page-columns page-full">
<div class="page-columns page-full">
<figure class="figure page-columns page-full">
<p class="page-columns page-full"><img src="https://jepusto.netlify.app/posts/Simulating-bootstrap-CIs/index_files/figure-html/unnamed-chunk-8-1.png" class="img-fluid figure-img column-body-outset" style="width:100.0%"></p>
</figure>
</div>
</div>
</div>
<p>The graphs above suggest that linear extrapolation is quite reasonable, both for coverage and interval width. The graphs also show that both metrics are meaningfully affected by the number of bootstraps.</p>
</section>
<section id="computing-the-extrapolation" class="level2">
<h2 class="anchored" data-anchor-id="computing-the-extrapolation">Computing the extrapolation</h2>
<p>A literal approach to computing the extrapolated coverage rate and interval width is to fit a regression across all the replications and values of <img src="https://latex.codecogs.com/png.latex?b">:</p>
<div class="cell">
<details open="" 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;">library</span>(clubSandwich)</span>
<span id="cb10-2">res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>rep <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(B_vals))</span>
<span id="cb10-3"></span>
<span id="cb10-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># coverage extrapolation</span></span>
<span id="cb10-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(coverage <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">I</span>(<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> B), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> res) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb10-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">conf_int</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vcov =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CR1"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cluster =</span> res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>rep, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">test =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"z"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">coefs =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(Intercept)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>       Coef. Estimate      SE d.f. Lower 95% CI Upper 95% CI
 (Intercept)    0.946 0.00433  Inf        0.938        0.955</code></pre>
</div>
<details open="" 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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># width extrapolation</span></span>
<span id="cb12-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lm</span>(width <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">I</span>(<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> B), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> res) <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;">conf_int</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vcov =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"CR1"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cluster =</span> res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>rep, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">test =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"z"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">coefs =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(Intercept)"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>       Coef. Estimate      SE d.f. Lower 95% CI Upper 95% CI
 (Intercept)    0.654 0.00182  Inf        0.651        0.658</code></pre>
</div>
</div>
<p>The calculation can be simplified a bit (or at least made a little more transparent?) by recognizing that <img src="https://latex.codecogs.com/png.latex?%5Chat%5Calpha_0"> is a simple average of the intercepts from each block-specific regression (call these <img src="https://latex.codecogs.com/png.latex?%5Chat%5Calpha_%7B0r%7D"> for <img src="https://latex.codecogs.com/png.latex?r%20=%201,..,R">) and that <img src="https://latex.codecogs.com/png.latex?%5Chat%5Calpha_%7B0r%7D"> is just a weighted average of the outcomes, with weights determined by <img src="https://latex.codecogs.com/png.latex?B_1,...,B_P">. The weights are given by <img src="https://latex.codecogs.com/png.latex?%0Aw_%7Bbr%7D%20=%20%5Cfrac%7B1%7D%7Bp%7D%20-%20%5Cfrac%7B%5Ctilde%7BB%7D%7D%7BS_B%7D%20%5Ctimes%20%5Cleft(%5Cfrac%7B1%7D%7Bb%7D%20-%20%5Ctilde%7BB%7D%5Cright),%0A"> where <img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%7B%5Ctilde%7BB%7D%20=%20%5Cfrac%7B1%7D%7Bp%7D%20%5Csum_%7Bb%20%5Cin%20%5C%7BB_1,...,B_P%5C%7D%7D%20%5Cfrac%7B1%7D%7Bb%7D%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%7BS_B%20=%20%5Csum_%7Bb%20%5Cin%20%5C%7BB_1,...,B_P%5C%7D%7D%20%5Cleft(%5Cfrac%7B1%7D%7Bb%7D%20-%20%5Ctilde%7BB%7D%5Cright)%5E2%7D">. With these weights, <img src="https://latex.codecogs.com/png.latex?%0A%5Chat%5Calpha_%7B0r%7D%20=%20%5Csum_%7Bb%20%5Cin%20%5C%7BB_1,...,B_P%5C%7D%7D%20w_%7Bbr%7D%20C_%7Bbr%7D%0A"> and <img src="https://latex.codecogs.com/png.latex?%0A%5Chat%5Calpha_0%20=%20%5Cfrac%7B1%7D%7BR%7D%20%5Csum_%7Br=1%7D%5ER%20%5Chat%5Calpha_%7B0r%7D%0A"> with (cluster-robust) standard error <img src="https://latex.codecogs.com/png.latex?%0ASE%20=%20%5Csqrt%7B%5Cfrac%7B1%7D%7BR%7D%20%5Ctimes%20%5Cfrac%7B%5Csum_%7Br=1%7D%5ER%20%5Cleft(%5Chat%5Calpha_%7B0r%7D%20-%20%5Chat%5Calpha_0%5Cright)%5E2%7D%7BR%20-%201%7D%7D.%0A"> Here’s a function that does the above calculations:</p>
<div class="cell">
<details open="" 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">calc_CI_coverage_width <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(res, B_vals) {</span>
<span id="cb14-2">  </span>
<span id="cb14-3">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># calculate wts for each replication</span></span>
<span id="cb14-4">  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;">length</span>(B_vals)</span>
<span id="cb14-5">  Btilde <span class="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>(<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> B_vals)</span>
<span id="cb14-6">  x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> B_vals <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> Btilde</span>
<span id="cb14-7">  S_B <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">crossprod</span>(x))</span>
<span id="cb14-8">  B_wts <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> p <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> Btilde <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> S_B</span>
<span id="cb14-9">  </span>
<span id="cb14-10">  res <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb14-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(rep) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb14-12">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># calculate alpha_0r per replication</span></span>
<span id="cb14-13">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb14-14">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(coverage, width), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(.x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> B_wts)),</span>
<span id="cb14-15">      <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="cb14-16">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb14-17">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># average over replications</span></span>
<span id="cb14-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb14-19">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(coverage, width), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb14-20">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">M =</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),</span>
<span id="cb14-21">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE =</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;">sd</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;">sqrt</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>())</span>
<span id="cb14-22">      ))</span>
<span id="cb14-23">    )</span>
<span id="cb14-24">  </span>
<span id="cb14-25">}</span>
<span id="cb14-26"></span>
<span id="cb14-27"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">calc_CI_coverage_width</span>(res, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_vals =</span> B_vals)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 1 × 4
  coverage_M coverage_SE width_M width_SE
       &lt;dbl&gt;       &lt;dbl&gt;   &lt;dbl&gt;    &lt;dbl&gt;
1      0.946     0.00433   0.654  0.00182</code></pre>
</div>
</div>
</section>
<section id="validation" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="validation">Validation</h2>
<p>Let’s see how the extrapolated coverage rate and interval width compare to the brute-force approach. I’ll do this by re-running the simulations using <img src="https://latex.codecogs.com/png.latex?B%20=%202399"> booties, but not bothering with the extrapolation.</p>
<div class="cell">
<details open="" 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">big_booties <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">simulate_bootCIs</span>(</span>
<span id="cb16-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>,</span>
<span id="cb16-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">N =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,</span>
<span id="cb16-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb16-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nu =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,</span>
<span id="cb16-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_vals =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2399</span></span>
<span id="cb16-7">)</span>
<span id="cb16-8"></span>
<span id="cb16-9">big_sim_summary <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb16-10">  big_booties <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb16-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarize</span>(</span>
<span id="cb16-12">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(coverage, width), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb16-13">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">M =</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),</span>
<span id="cb16-14">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE =</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;">sd</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;">sqrt</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>())</span>
<span id="cb16-15">      ))</span>
<span id="cb16-16">    )</span>
<span id="cb16-17"></span>
<span id="cb16-18">big_sim_summary</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>  coverage_M coverage_SE  width_M    width_SE
1     0.9516 0.004293058 0.655017 0.001779658</code></pre>
</div>
</div>
<div class="cell page-columns page-full">
<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">big_sim_summary <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-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;">B =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>L) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(sim_summary) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb18-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">est =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">if_else</span>(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;">1999</span>L, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Brute-force"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Extrapolation"</span>)</span>
<span id="cb18-6">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(</span>
<span id="cb18-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ends_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_M"</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ends_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_SE"</span>)), </span>
<span id="cb18-9">    <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;">"metric"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".value"</span>), </span>
<span id="cb18-10">    <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="cb18-11">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb18-13">  <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> B, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> M) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb18-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">transform =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"reciprocal"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(B_vals, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9999</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb18-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Brute-force</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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"red"</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;">Extrapolation</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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb18-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_limits</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9999</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb18-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_smooth</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> est), <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;">fullrange =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">se =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb18-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_pointrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> M <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> qn <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> SE, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> M <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> qn <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> SE, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> est)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb18-19">  <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> metric, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb18-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb18-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="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.9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb18-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Bootstraps (B)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display page-columns page-full">
<div class="page-columns page-full">
<figure class="figure page-columns page-full">
<p class="page-columns page-full"><img src="https://jepusto.netlify.app/posts/Simulating-bootstrap-CIs/index_files/figure-html/unnamed-chunk-12-1.png" class="img-fluid figure-img column-body-outset" style="width:100.0%"></p>
</figure>
</div>
</div>
</div>
<p>The extrapolated coverage rate and interval width are consistent with the brute-force calculations. The brute-force approach requires calculating <img src="https://latex.codecogs.com/png.latex?2399%20%5Ctimes%20R"> booties, whereas the extrapolation requires only <img src="https://latex.codecogs.com/png.latex?399%20%5Ctimes%20R"> booties. However, the number of confidence interval calculations is one per bootstrap, or <img src="https://latex.codecogs.com/png.latex?2399%20%5Ctimes%20R"> in all for the brute-force calculation (in this example, that comes out to be 5,997,500), but <img src="https://latex.codecogs.com/png.latex?399%20%5Ctimes%20R%20%5Ctimes%20%5Cleft(m%20%5Ctimes%20(P%20-%201)%20+%201%5Cright)"> for the extrapolation approach (in this example, that comes out to 50,872,500). Thus, this technique is only going to be worth the trouble if computing the booties takes much longer than doing the confidence interval calculations.</p>
</section>
</section>
<section id="notes-and-loose-ends" class="level1">
<h1>Notes and loose ends</h1>
<p>The <span class="citation" data-cites="boos2000MonteCarloEvaluation">Boos &amp; Zhang (2000)</span> technique seems quite useful and worth knowing about if you’re doing any sort of Monte Carlo simulations involving bootstrapping. I’ve provided a proof-of-concept code-through, but there’s a certainly a few loose ends here. For one, what’s the right set of sub-sample bootie sizes? I’ve followed Boos and Zhang’s suggestion, but it’s not based on much of any theory. I’ve deviated a little bit from the original paper by using <img src="https://latex.codecogs.com/png.latex?m"> repeated sub-samples instead of implementing the probability calculations proposed in the original paper. Is there a cost to this? Not sure. Is <img src="https://latex.codecogs.com/png.latex?m%20=%2010"> the right number to use? Again, not sure. Some further fiddling seems warranted.</p>
<p>This code-through also has me wondering about how the approach could be abstracted to make it easier to apply to new problems. It seems like the sort of thing that would fit well in <a href="../..\software/simhelpers/"><code>simhelpers</code></a>, but this will take a bit more thought.</p>


<!-- -->


</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" data-line-spacing="2">
<div id="ref-boos2000MonteCarloEvaluation" class="csl-entry">
Boos, D. D., &amp; Zhang, J. (2000). <span>Monte Carlo</span> evaluation of resampling-based hypothesis tests. <em>Journal of the American Statistical Association</em>, <em>95</em>(450), 486–492. <a href="https://doi.org/10.1080/01621459.2000.10474226">https://doi.org/10.1080/01621459.2000.10474226</a>
</div>
<div id="ref-davidson2000BootstrapTestsHow" class="csl-entry">
Davidson, R., &amp; MacKinnon, J. G. (2000). Bootstrap tests: How many bootstraps? <em>Econometric Reviews</em>, <em>19</em>(1), 55–68. <a href="https://doi.org/10.1080/07474930008800459">https://doi.org/10.1080/07474930008800459</a>
</div>
<div id="ref-joshiClusterWildBootstrapping2022" class="csl-entry">
Joshi, M., Pustejovsky, J. E., &amp; Beretvas, S. N. (2022). Cluster wild bootstrapping to handle dependent effect sizes in meta-analysis with a small number of studies. <em>Research Synthesis Methods</em>, <em>13</em>(4), 457–477. <a href="https://doi.org/10.1002/jrsm.1554">https://doi.org/10.1002/jrsm.1554</a>
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p><span class="citation" data-cites="boos2000MonteCarloEvaluation">Boos &amp; Zhang (2000)</span> provided some technical justification for using linear extrapolation rather than some other type of curve. They also reported that linear extrapolation worked better than a quadratic model in their numerical experiments.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>programming</category>
  <category>Rstats</category>
  <category>bootstrap</category>
  <guid>https://jepusto.netlify.app/posts/Simulating-bootstrap-CIs/</guid>
  <pubDate>Mon, 01 Jul 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Correlations between z-transformed correlation coefficients</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/correlated-z-transformed-correlations/</link>
  <description><![CDATA[ 





<p>For a little meta-analysis project that I’m working on with <a href="../..\people/jingru-zhang/">Jingru</a>, we are dealing with a database of correlation coefficients, where some of the included studies report correlations for more than one instrument or sub-scale for one of the relevant variables. This leads to every meta-analytic methodologist’s favorite tongue-twister of distribution theory: inter-correlated correlation coefficients. Fortunately, Grandpa Ingram worked out the distribution theory for this stuff long ago (Olkin and Siotani, 1976; reviewed in <a href="https://doi.org/10.1037/0033-2909.108.2.330">Olkin and Finn, 1990</a>).</p>
<p>Suppose that we have three variables, <img src="https://latex.codecogs.com/png.latex?a">, <img src="https://latex.codecogs.com/png.latex?b">, and <img src="https://latex.codecogs.com/png.latex?c">, where <img src="https://latex.codecogs.com/png.latex?b"> and <img src="https://latex.codecogs.com/png.latex?c"> are different measures of the same construct. From a sample of size <img src="https://latex.codecogs.com/png.latex?N">, we have correlation estimates <img src="https://latex.codecogs.com/png.latex?r_%7Bab%7D"> and <img src="https://latex.codecogs.com/png.latex?r_%7Bac%7D">, both of which are relevant for understanding the underlying construct relation. These correlations are estimates of underlying population correlations <img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bab%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bac%7D"> respectively, and the population correlation between <img src="https://latex.codecogs.com/png.latex?b"> and <img src="https://latex.codecogs.com/png.latex?c"> is <img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bbc%7D">. Typically, we would analyze the correlations after applying Fisher’s variance stabilizing and normalizing transformation. Denote the Fisher transformation as <img src="https://latex.codecogs.com/png.latex?Z(r)=%20%5Cfrac%7B1%7D%7B2%7D%5Cln%5Cleft(%5Cfrac%7B1%20+%20r%7D%7B1%20-%20r%7D%5Cright)">), with derivative given by <img src="https://latex.codecogs.com/png.latex?Z'(r)%20=%20%5Cfrac%7B1%7D%7B1%20-%20r%5E2%7D">. Let <img src="https://latex.codecogs.com/png.latex?z_%7Bab%7D%20=%20Z(r_%7Bab%7D)">, with the other transformed correlations defined similarly. The question is then: how strongly correlated are the sampling errors of the resulting effect size estimates—that is, what is <img src="https://latex.codecogs.com/png.latex?%5Ctext%7Bcor%7D(z_%7Bab%7D,%20z_%7Bac%7D)">?</p>
<p><a href="https://doi.org/10.1037/0033-2909.108.2.330">Olkin and Finn (1990)</a> give the following expression for the covariance between two sample correlation coefficients that share a common variable: <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BCov%7D(r_%7Bab%7D,%20r_%7Bac%7D)%20=%20%5Cfrac%7B1%7D%7BN%20-%201%7D%5Cleft%5B%5Cleft(%5Crho_%7Bbc%7D%20-%20%5Cfrac%7B1%7D%7B2%7D%5Crho_%7Bab%7D%5Crho_%7Bac%7D%5Cright)%5Cleft(1%20-%20%5Crho_%7Bab%7D%5E2%20-%20%5Crho_%7Bac%7D%5E2%5Cright)%20+%20%5Cfrac%7B1%7D%7B2%7D%20%5Crho_%7Bab%7D%20%5Crho_%7Bac%7D%20%5Crho_%7Bbc%7D%5E2%5Cright%5D.%0A"> If correlations are converted to the Fisher-z scale, then we can use a delta method approximation to obtain an expression for the covariance between two sample z estimates that share a common variable. Using <img src="https://latex.codecogs.com/png.latex?N-3"> in place of <img src="https://latex.codecogs.com/png.latex?N-1">, the covariance between the z-transformed correlations is approximately <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Ctext%7BCov%7D(z_%7Bab%7D,%20z_%7Bac%7D)%20&amp;=%20Z'(%5Crho_%7Bab%7D)%20%5Ctimes%20Z'(%5Crho_%7Bac%7D)%5Ctimes%20%5Ctext%7BCov%7D(r_%7Bab%7D,%20r_%7Bac%7D)%20%5C%5C%0A&amp;=%5Cfrac%7B1%7D%7BN%20-%203%7D%20%5Cfrac%7B%5Cleft(%5Crho_%7Bbc%7D%20-%20%5Cfrac%7B1%7D%7B2%7D%5Crho_%7Bab%7D%5Crho_%7Bac%7D%5Cright)%5Cleft(1%20-%20%5Crho_%7Bab%7D%5E2%20-%20%5Crho_%7Bac%7D%5E2%5Cright)%20+%20%5Cfrac%7B1%7D%7B2%7D%20%5Crho_%7Bab%7D%20%5Crho_%7Bac%7D%20%5Crho_%7Bbc%7D%5E2%7D%7B%5Cleft(1%20-%20%5Crho_%7Bab%7D%5E2%5Cright)%20%5Cleft(1%20-%20%5Crho_%7Bac%7D%5E2%5Cright)%7D.%0A%5Cend%7Baligned%7D%0A"> The corresponding correlation is thus <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7Bcor%7D(z_%7Bab%7D,%20z_%7Bac%7D)%20=%20%5Cfrac%7B%5Cleft(%5Crho_%7Bbc%7D%20-%20%5Cfrac%7B1%7D%7B2%7D%5Crho_%7Bab%7D%5Crho_%7Bac%7D%5Cright)%5Cleft(1%20-%20%5Crho_%7Bab%7D%5E2%20-%20%5Crho_%7Bac%7D%5E2%5Cright)%20+%20%5Cfrac%7B1%7D%7B2%7D%20%5Crho_%7Bab%7D%20%5Crho_%7Bac%7D%20%5Crho_%7Bbc%7D%5E2%7D%7B%5Cleft(1%20-%20%5Crho_%7Bab%7D%5E2%5Cright)%20%5Cleft(1%20-%20%5Crho_%7Bac%7D%5E2%5Cright)%7D.%0A"></p>
<p>In the context of a meta-analysis, we might expect that the focal correlations will usually be very similar, if not exactly equal. For simplicity, let’s assume that they’re actually identical, <img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bab%7D%20=%20%5Crho_%7Bac%7D">. The sampling correlation then simplifies further to<br>
<img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Ctext%7Bcor%7D(z_%7Bab%7D,%20z_%7Bac%7D)%20&amp;=%20%5Cfrac%7B%5Cleft(%5Crho_%7Bbc%7D%20-%20%5Cfrac%7B1%7D%7B2%7D%5Crho_%7Bab%7D%5E2%5Cright)%5Cleft(1%20-%202%5Crho_%7Bab%7D%5E2%5Cright)%20+%20%5Cfrac%7B1%7D%7B2%7D%20%5Crho_%7Bab%7D%5E2%20%5Crho_%7Bbc%7D%5E2%7D%7B%5Cleft(1%20-%20%5Crho_%7Bab%7D%5E2%5Cright)%5E2%7D%20%5C%5C%0A&amp;=1%20-%20%20%5Cfrac%7B(1%20-%20%5Crho_%7Bbc%7D)%5Cleft%5B2%20-%20%5Crho_%7Bab%7D%5E2(3%20-%20%5Crho_%7Bbc%7D)%5Cright%5D%7D%7B2%5Cleft(1%20-%20%5Crho_%7Bab%7D%5E2%5Cright)%5E2%7D.%0A%5Cend%7Baligned%7D%0A"> To apply this formula, we need to specify values of <img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bab%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bbc%7D">. The following table gives the resulting correlation between z-transformed sample correlations for a few values of <img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bab%7D%20=%20%5Crho_%7Bac%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bbc%7D">.</p>
<div class="grid">
<div class="g-col-2">

</div>
<div class="g-col-8">
<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">ccc <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>(r_ab, r_bc) {</span>
<span id="cb1-2">  <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> r_bc) <span 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> r_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 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> r_bc)) <span 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> r_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 class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-3">}</span>
<span id="cb1-4"></span>
<span id="cb1-5">r_bc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(</span>
<span id="cb1-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r_bc =</span> r_bc, </span>
<span id="cb1-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r_ab_20 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ccc</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.20</span>, r_bc),</span>
<span id="cb1-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r_ab_25 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ccc</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, r_bc),</span>
<span id="cb1-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r_ab_33 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ccc</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.33</span>, r_bc),</span>
<span id="cb1-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r_ab_40 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ccc</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.40</span>, r_bc),</span>
<span id="cb1-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r_ab_50 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ccc</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.50</span>, r_bc)</span>
<span id="cb1-13">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb1-14">  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>
<span id="cb1-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, </span>
<span id="cb1-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb1-17">      <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;">rho_{bc}$"</span>, </span>
<span id="cb1-18">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$</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;">rho_{ab} = "</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">formatC</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.20</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.33</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.40</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.50</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;">"f"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$"</span>)</span>
<span id="cb1-19">    ),</span>
<span id="cb1-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">escape =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>,</span>
<span id="cb1-21">    <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;">"{.sm}"</span></span>
<span id="cb1-22">  )</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<table class="table-sm small caption-top table table-striped">
<colgroup>
<col style="width: 11%">
<col style="width: 17%">
<col style="width: 17%">
<col style="width: 17%">
<col style="width: 17%">
<col style="width: 17%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bbc%7D"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bab%7D%20=%200.20"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bab%7D%20=%200.25"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bab%7D%20=%200.33"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bab%7D%20=%200.40"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bab%7D%20=%200.50"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">0.4</td>
<td style="text-align: right;">0.383</td>
<td style="text-align: right;">0.373</td>
<td style="text-align: right;">0.351</td>
<td style="text-align: right;">0.327</td>
<td style="text-align: right;">0.280</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.5</td>
<td style="text-align: right;">0.485</td>
<td style="text-align: right;">0.476</td>
<td style="text-align: right;">0.456</td>
<td style="text-align: right;">0.433</td>
<td style="text-align: right;">0.389</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.6</td>
<td style="text-align: right;">0.587</td>
<td style="text-align: right;">0.579</td>
<td style="text-align: right;">0.562</td>
<td style="text-align: right;">0.542</td>
<td style="text-align: right;">0.502</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.7</td>
<td style="text-align: right;">0.689</td>
<td style="text-align: right;">0.683</td>
<td style="text-align: right;">0.670</td>
<td style="text-align: right;">0.653</td>
<td style="text-align: right;">0.620</td>
</tr>
<tr class="odd">
<td style="text-align: right;">0.8</td>
<td style="text-align: right;">0.793</td>
<td style="text-align: right;">0.788</td>
<td style="text-align: right;">0.778</td>
<td style="text-align: right;">0.766</td>
<td style="text-align: right;">0.742</td>
</tr>
<tr class="even">
<td style="text-align: right;">0.9</td>
<td style="text-align: right;">0.896</td>
<td style="text-align: right;">0.894</td>
<td style="text-align: right;">0.888</td>
<td style="text-align: right;">0.882</td>
<td style="text-align: right;">0.869</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p>When the focal correlations are fairly small, then the sampling correlation is the same order of magnitude as <img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bbc%7D">. It’s only when the focal correlations are stronger that the sampling correlation is noticeably attenuated from <img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bbc%7D">, and the degree of attenuation is weaker when <img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bbc%7D"> is larger. Thus, for strongly related instruments or sub-scales, <img src="https://latex.codecogs.com/png.latex?%5Ctext%7Bcor%7D(z_%7Bab%7D,%20z_%7Bac%7D)"> won’t be much different from <img src="https://latex.codecogs.com/png.latex?%5Crho_%7Bbc%7D">.</p>



<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>effect size</category>
  <category>correlation</category>
  <category>distribution theory</category>
  <category>meta-analysis</category>
  <guid>https://jepusto.netlify.app/posts/correlated-z-transformed-correlations/</guid>
  <pubDate>Thu, 06 Jun 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Distribution of the number of significant effect sizes</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/distribution-of-significant-effects/</link>
  <description><![CDATA[ 





<p><a href="../..\posts/number-of-significant-effects/">A while back</a>, I posted the outline of a problem about the number of significant effect size estimates in a study that reports multiple outcomes. This problem interests me because it connects to the issue of selective reporting of study results, which creates problems for meta-analysis. Here, I’ll re-state the problem in slightly more general terms and then make some notes about what’s going on.</p>
<p>Consider a study that assesses some effect size across <img src="https://latex.codecogs.com/png.latex?m"> different outcomes. (We’ll be thinking about one study at a time here, so no need to index the study as we would in a meta-analysis problem.) Let <img src="https://latex.codecogs.com/png.latex?T_i"> denote the effect size estimate for outcome <img src="https://latex.codecogs.com/png.latex?i">, let <img src="https://latex.codecogs.com/png.latex?V_i"> denote the sampling variance of the effect size estimate for outcome <img src="https://latex.codecogs.com/png.latex?i">, and let <img src="https://latex.codecogs.com/png.latex?%5Ctheta_i"> denote the true effect size parameter for corresponding to outcome <img src="https://latex.codecogs.com/png.latex?i">. Assume that the study outcomes <img src="https://latex.codecogs.com/png.latex?%5Cleft%5BT_i%5Cright%5D_%7Bi=1%7D%5Em"> follow a correlated-and-hierarchical effects model, in which <img src="https://latex.codecogs.com/png.latex?T_i%20=%20%5Cmu%20+%20u%20+%20v_i%20+%20e_i,"> where the study-level error <img src="https://latex.codecogs.com/png.latex?u%20%5Csim%20N%5Cleft(0,%5Ctau%5E2%5Cright)">, the effect-specific error <img src="https://latex.codecogs.com/png.latex?v_i%20%5Cstackrel%7Biid%7D%7B%5Csim%7D%20N%5Cleft(0,%20%5Comega%5E2%5Cright)">, and the vector of sampling errors <img src="https://latex.codecogs.com/png.latex?%5Cleft%5Be_i%5Cright%5D_%7Bi=1%7D%5Em"> is multivariate normal with mean <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7B0%7D">, known variances <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BVar%7D(e_i)%20=%20%5Csigma%5E2">, and compound symmetric correlation structure <img src="https://latex.codecogs.com/png.latex?%5Ctext%7Bcor%7D(e_h,%20e_i)%20=%20%5Crho">.</p>
<p>Define <img src="https://latex.codecogs.com/png.latex?A_i"> as an indicator that is equal to one if <img src="https://latex.codecogs.com/png.latex?T_i"> is statistically significant at level <img src="https://latex.codecogs.com/png.latex?%5Calpha"> based on a one-sided test, and otherwise equal to zero. (Equivalently, let <img src="https://latex.codecogs.com/png.latex?A_i"> be equal to one if the effect is statistically significant at level <img src="https://latex.codecogs.com/png.latex?2%20%5Calpha"> and in the theoretically expected direction.) Formally, <img src="https://latex.codecogs.com/png.latex?A_i%20=%20I%5Cleft(%5Cfrac%7BT_i%7D%7B%5Csigma%7D%20%3E%20q_%5Calpha%20%5Cright)"> where <img src="https://latex.codecogs.com/png.latex?q_%5Calpha%20=%20%5CPhi%5E%7B-1%7D(1%20-%20%5Calpha)"> is the critical value from a standard normal distribution (e.g., <img src="https://latex.codecogs.com/png.latex?q_%7B.05%7D%20=%201.645">, <img src="https://latex.codecogs.com/png.latex?q_%7B.025%7D%20=%201.96">). Let <img src="https://latex.codecogs.com/png.latex?N_A%20=%20%5Csum_%7Bi=1%7D%5Em%20A_i"> denote the total number of statistically significant effect sizes in the study. The question is: what is the distribution of <img src="https://latex.codecogs.com/png.latex?N_A">.</p>
<section id="compound-symmetry-to-the-rescue" class="level2">
<h2 class="anchored" data-anchor-id="compound-symmetry-to-the-rescue">Compound symmetry to the rescue</h2>
<p>As I noted in the previous post, this set-up means that the effect size estimates have a compound symmetric distribution. We can make this a bit more explicit by writing the sampling errors in terms of the sum of a component that’s common acrosss outcomes and a component that’s specific to each outcome. Thus, let <img src="https://latex.codecogs.com/png.latex?e_i%20=%20f%20+%20g_i">, where <img src="https://latex.codecogs.com/png.latex?f%20%5Csim%20N%5Cleft(0,%20%5Crho%20%5Csigma%5E2%20%5Cright)"> and <img src="https://latex.codecogs.com/png.latex?g_i%20%5Cstackrel%7Biid%7D%7B%5Csim%7D%20N%20%5Cleft(0,%20(1%20-%20%5Crho)%20%5Csigma%5E2%5Cright)">. Let me also define <img src="https://latex.codecogs.com/png.latex?%5Czeta%20=%20%5Cmu%20+%20u%20+%20f"> as the conditional mean of the effects. It then follows that the effect size estimates are <em>conditionally independent</em>, given the common components: <img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(T_i%20%7C%20%5Czeta%20%5Cright)%20%5Cstackrel%7Biid%7D%7B%5Csim%7D%20N%5Cleft(%5Czeta,%20%5Comega%5E2%20+%20(1%20-%20%5Crho)%20%5Csigma%5E2%5Cright)%0A"> Furthermore, the conditional probability of a significant effect is <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D(A_i%20=%201%20%7C%20%5Czeta)%20=%20%5CPhi%5Cleft(%5Cfrac%7B%5Czeta%20-%20q_%7B%5Calpha%7D%20%5Csigma%7D%7B%5Csqrt%7B%5Comega%5E2%20+%20(1%20-%20%5Crho)%5Csigma%5E2%7D%7D%5Cright)%0A"> and <img src="https://latex.codecogs.com/png.latex?A_1,...,A_m"> are mutually independent, conditional on <img src="https://latex.codecogs.com/png.latex?%5Czeta">. Therefore, the conditional distribution of <img src="https://latex.codecogs.com/png.latex?N_A"> is binomial, <img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(N_A%20%7C%20%5Czeta%5Cright)%20%5Csim%20Bin(m,%20%5Cpi)%0A"> where <img src="https://latex.codecogs.com/png.latex?%0A%5Cpi%20=%20%5CPhi%5Cleft(%5Cfrac%7B%5Czeta%20-%20q_%7B%5Calpha%7D%20%5Csigma%7D%7B%5Csqrt%7B%5Comega%5E2%20+%20(1%20-%20%5Crho)%5Csigma%5E2%7D%7D%5Cright).%0A"> What about the unconditional distribution?</p>
<p>To get rid of the <img src="https://latex.codecogs.com/png.latex?%5Czeta">, we need to integrate over its distribution, which leads to <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BPr%7D(N_A%20=%20a)%20=%20%5Ctext%7BE%7D%5Cleft%5B%5Ctext%7BPr%7D%5Cleft(N_A%20%7C%20%5Czeta%5Cright)%5Cright%5D%20=%20%5Cint%20f_%7BN_A%7D%5Cleft(a%20%7C%20%5Czeta,%20%5Comega,%20%5Csigma,%20%5Crho,%20m%5Cright)%20%5Ctimes%20f_%5Czeta(%5Czeta%20%7C%20%5Cmu,%20%5Ctau,%20%5Csigma,%20%5Crho)%20%5C%20d%20%5Czeta,%0A"> where <img src="https://latex.codecogs.com/png.latex?f_%7BN_A%7D%5Cleft(a%20%7C%20%5Czeta,%20%5Comega,%20%5Csigma,%20%5Crho%20%5Cright)"> is a binomial density with size <img src="https://latex.codecogs.com/png.latex?m"> and probability <img src="https://latex.codecogs.com/png.latex?%5Cpi%20=%20%5Cpi(%5Czeta,%20%5Comega,%20%5Csigma,%20%5Crho)"> and <img src="https://latex.codecogs.com/png.latex?f_%5Czeta(%5Czeta%20%7C%20%5Cmu,%20%5Ctau,%20%5Csigma,%20%5Crho)"> is a normal density with mean <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and variance <img src="https://latex.codecogs.com/png.latex?%5Ctau%5E2%20+%20%5Crho%20%5Csigma%5E2">.</p>
<p>This distribution is what you might call a binomial-normal convolution or a random-intercept probit model (where the random intercept is <img src="https://latex.codecogs.com/png.latex?%5Czeta">). As far as I know, the distribution cannot be evaluated analytically but instead must be calculated using some sort of numerical integration routine.</p>
</section>
<section id="just-the-moments-please" class="level2">
<h2 class="anchored" data-anchor-id="just-the-moments-please">Just the moments, please</h2>
<p>If all we care about is the expectation of <img src="https://latex.codecogs.com/png.latex?N_A">, we don’t need to bother with all the conditioning business and can just look at the marginal distribution of the effect size estimates taken individually. Marginally, <img src="https://latex.codecogs.com/png.latex?T_i"> is normally distributed with mean <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and variance <img src="https://latex.codecogs.com/png.latex?%5Ctau%5E2%20+%20%5Comega%5E2%20+%20%5Csigma%5E2">, so <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BPr%7D(A_i%20=%201)%20=%20%5Cpsi">, where <img src="https://latex.codecogs.com/png.latex?%0A%5Cpsi%20=%20%5CPhi%5Cleft(%5Cfrac%7B%5Cmu%20-%20q_%7B%5Calpha%7D%20%5Csigma%7D%7B%5Csqrt%7B%5Ctau%5E2%20+%20%5Comega%5E2%20+%20%5Csigma%5E2%7D%7D%5Cright).%0A"> By the linearity of expectations, <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BE%7D(N_A)%20=%20%5Csum_%7Bi=1%7D%5Em%20%5Ctext%7BE%7D(A_i)%20=%20m%20%5Cpsi.%0A"></p>
<p>We can also get an approximation for the variance of <img src="https://latex.codecogs.com/png.latex?N_A"> by working with its conditional distribution above. By the rule of variance decomposition, <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Ctext%7BVar%7D(N_A)%20&amp;=%20%5Ctext%7BE%7D%5Cleft%5B%5Ctext%7BVar%7D%5Cleft(N_A%20%7C%20%5Czeta%5Cright)%5Cright%5D%20+%20%5Ctext%7BVar%7D%5Cleft%5B%5Ctext%7BE%7D%5Cleft(N_A%20%7C%20%5Czeta%5Cright)%5Cright%5D%20%5C%5C%0A&amp;=%20m%20%5Ctimes%20%5Ctext%7BE%7D%5Cleft%5B%5Cpi%20(1%20-%20%5Cpi)%5Cright%5D%20+%20m%5E2%20%5Ctimes%20%5Ctext%7BVar%7D%5Cleft%5B%5Cpi%5Cright%5D%5C%5C%0A&amp;=%20m%20%5Ctimes%20%5Ctext%7BE%7D%5Cleft%5B%5Cpi%5Cright%5D%20%5Cleft(1%20-%20%5Ctext%7BE%7D%5Cleft%5B%5Cpi%5Cright%5D%5Cright)%20+%20m%20(m%20-%201)%20%5Ctimes%20%5Ctext%7BVar%7D%5Cleft%5B%5Cpi%5Cright%5D,%0A%5Cend%7Baligned%7D%0A"> where <img src="https://latex.codecogs.com/png.latex?%5Cpi"> is, as defined above, a function of <img src="https://latex.codecogs.com/png.latex?%5Czeta"> and thus a random variable. Now, <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BE%7D(%5Cpi)%20=%20%5Cpsi"> and we can get something close to <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BVar%7D(%5Cpi)"> using a first-order approximation: <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BVar%7D%5Cleft(%5Cpi%5Cright)%20%5Capprox%20%5Cleft(%5Cleft.%5Cfrac%7B%5Cdelta%20%5Cpi%7D%7B%5Cdelta%20%5Czeta%7D%5Cright%7C_%7B%5Czeta%20=%20%5Cmu%7D%5Cright)%5E2%20%5Ctimes%20%5Ctext%7BVar%7D%5Cleft(%5Czeta%5Cright)%20=%20%5Cleft%5B%5Cphi%5Cleft(%5Cfrac%7B%5Cmu%20-%20q_%7B%5Calpha%7D%20%5Csigma%7D%7B%5Csqrt%7B%5Comega%5E2%20+%20(1%20-%20%5Crho)%5Csigma%5E2%7D%7D%5Cright)%5Cright%5D%5E2%20%5Ctimes%20%5Cfrac%7B%5Ctau%5E2%20+%20%5Crho%20%5Csigma%5E2%7D%7B%5Comega%5E2%20+%20(1%20-%20%5Crho)%5Csigma%5E2%7D.%0A"> Thus, <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Ctext%7BVar%7D(N_A)%20%5Capprox%20m%20%5Ctimes%20%5Cpsi%20%5Cleft(1%20-%20%5Cpsi%5Cright)%20+%20m%20(m%20-%201)%20%5Ctimes%20%5Cleft%5B%5Cphi%5Cleft(%5Cfrac%7B%5Cmu%20-%20q_%7B%5Calpha%7D%20%5Csigma%7D%7B%5Csqrt%7B%5Comega%5E2%20+%20(1%20-%20%5Crho)%5Csigma%5E2%7D%7D%5Cright)%5Cright%5D%5E2%20%5Ctimes%20%5Cfrac%7B%5Ctau%5E2%20+%20%5Crho%20%5Csigma%5E2%7D%7B%5Comega%5E2%20+%20(1%20-%20%5Crho)%5Csigma%5E2%7D.%0A%5Cend%7Baligned%7D%0A"> If the amount of common variation is small, so <img src="https://latex.codecogs.com/png.latex?%5Ctau%5E2"> is near zero and <img src="https://latex.codecogs.com/png.latex?%5Crho"> is near zero, then the contribution of the second term will be small, and <img src="https://latex.codecogs.com/png.latex?N_A"> will act more or less like a binomial random variable with size <img src="https://latex.codecogs.com/png.latex?m"> and probability <img src="https://latex.codecogs.com/png.latex?%5Cpsi">. On the other hand, if the amount of independent variation in the effect sizes is small, so <img src="https://latex.codecogs.com/png.latex?%5Comega%5E2"> is near zero and <img src="https://latex.codecogs.com/png.latex?%5Crho"> is near 1, then the term on the right will approach <img src="https://latex.codecogs.com/png.latex?m(m%20-%201)%5Cpsi(1%20-%20%5Cpsi)"> and <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BVar%7D%5Cleft(N_A%5Cright)"> will approach <img src="https://latex.codecogs.com/png.latex?m%5E2%20%5Cpsi(1%20-%20%5Cpsi)">, or the variance of <img src="https://latex.codecogs.com/png.latex?m"> times a single Bernoulli variate. So you could say that <img src="https://latex.codecogs.com/png.latex?N_A"> has anywhere between <img src="https://latex.codecogs.com/png.latex?1"> and <img src="https://latex.codecogs.com/png.latex?m"> variate’s worth of information in it, depending on the degree of correlation between the effect size estimates.</p>
</section>
<section id="interactive-distribution" class="level1 page-columns page-full">
<h1>Interactive distribution</h1>
<p>Here is an interactive graph of the probability mass function of <img src="https://latex.codecogs.com/png.latex?N_A">, with probability points calculated using Gaussian quadrature. Below the graph, I also report <img src="https://latex.codecogs.com/png.latex?%5Cpsi">, the exact mean and variance of <img src="https://latex.codecogs.com/png.latex?N_A">, and the first-order approximation to the variance (denoted $V_{approx}). When <img src="https://latex.codecogs.com/png.latex?%5Ctau%20%3E%200"> and <img src="https://latex.codecogs.com/png.latex?%5Crho%20%3E%200">, the approximate variance is not all that accurate because the first-order approximation to <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BVar%7D(%5Cpi)"> isn’t that good.</p>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb1" data-startfrom="104" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 103;"><span id="cb1-104">math <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">require</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mathjs"</span>)</span>
<span id="cb1-105">norm <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'https://unpkg.com/norm-dist@3.1.0/index.js?module'</span>)</span>
<span id="cb1-106"></span>
<span id="cb1-107">quad_points <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">JSON</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;">parse</span>(all_quad_points)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">at</span>(qp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-108"></span>
<span id="cb1-109">sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> 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;">sqrt</span>(ESS)</span>
<span id="cb1-110"></span>
<span id="cb1-111">zeta_sd <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> 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;">sqrt</span>(tau<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> rho <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-112">ID_sd <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> 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;">sqrt</span>(omega<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rho) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb1-113"></span>
<span id="cb1-114">crit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> norm<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">icdf</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> alpha)</span>
<span id="cb1-115"></span>
<span id="cb1-116">binomial_coefs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(m<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</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;">map</span>((x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>index) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-117">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> 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;">combinations</span>(m<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> index)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-118">})</span>
<span id="cb1-119"></span>
<span id="cb1-120">probs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> quad_points<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(zeta <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-121">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> Z <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (zeta[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> zeta_sd <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> crit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sigma) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> ID_sd<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-122">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> [norm<span 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>(Z)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> zeta[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-123">})</span>
<span id="cb1-124"></span>
<span id="cb1-125">p_binom_norm <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> binomial_coefs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((coef<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> a) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-126">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> probs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((x) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-127">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> (x[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span>a) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> ((<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> x[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span>(m <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> a)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-128">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-129">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> coef <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> 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;">sum</span>(p)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-130">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-8" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-9" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-10" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb2" data-startfrom="135" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 134;"><span id="cb2-135">psi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> norm<span 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>((mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> crit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sigma) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> 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;">sqrt</span>(tau<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> omega<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb2-136">psi_print <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> psi<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb2-137"></span>
<span id="cb2-138">E_NA <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> m <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> psi </span>
<span id="cb2-139">E_NA_print <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> E_NA<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb2-140"></span>
<span id="cb2-141">dpi_dzeta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> norm<span 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>((mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> crit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> sigma) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> ID_sd)</span>
<span id="cb2-142">V_pi_approx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (dpi_dzeta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> zeta_sd <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> ID_sd)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb2-143">V_approx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> m <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> psi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> psi) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> m <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (m <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> V_pi_approx</span>
<span id="cb2-144">V_approx_print <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> V_approx<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb2-145"></span>
<span id="cb2-146">V_NA <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb2-147">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> V_NA <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> E_NA<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-148">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> m<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) {</span>
<span id="cb2-149">    V_NA <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> p_binom_norm[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-150">  }</span>
<span id="cb2-151">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> V_NA<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-152">}</span>
<span id="cb2-153">V_NA_print <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> V_NA<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-8" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-9" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-10" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="grid column-page">
<div class="g-col-7">
<section id="distribution-of-n_a" class="level4">
<h4 class="anchored" data-anchor-id="distribution-of-n_a">Distribution of <img src="https://latex.codecogs.com/png.latex?N_A"></h4>
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb3" data-startfrom="162" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 161;"><span id="cb3-162">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb3-163">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb3-164">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of significant effect sizes"</span></span>
<span id="cb3-165">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-166">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb3-167">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-168">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Probability"</span></span>
<span id="cb3-169">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-170">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb3-171">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-172">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">barY</span>(p_binom_norm<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb3-173">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"steelblue"</span></span>
<span id="cb3-174">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-175">  ]</span>
<span id="cb3-176">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="expression">

</div>
</div>
</div>
</section>
<section id="moments-of-n_a" class="level4">
<h4 class="anchored" data-anchor-id="moments-of-n_a">Moments of <img src="https://latex.codecogs.com/png.latex?N_A"></h4>
<div class="moments">
<div class="cell">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb4" data-startfrom="184" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 183;"><span id="cb4-184"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tex</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb4-185"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\b</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">egin{aligned}</span></span>
<span id="cb4-186"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\p</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">si &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>psi_print<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span></span>
<span id="cb4-187"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">athbb{E}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">eft(N_A</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ight) &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>E_NA_print<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span></span>
<span id="cb4-188"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\m</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">athbb{V}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\l</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">eft(N_A</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ight) &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>V_NA_print<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> &amp;V_{approx} &amp;= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>V_approx_print<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-189"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\e</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">nd{aligned}</span></span>
<span id="cb4-190"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="expression">

</div>
</div>
</div>
</div>
</section>
</div>
<div class="g-col-5">
<div class="cell panel-input card bg-light p-2">
<details class="code-fold hidden">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb5" data-startfrom="201" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 200;"><span id="cb5-201">viewof m <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-202">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-203">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of effect sizes (m):"</span>}</span>
<span id="cb5-204">)</span>
<span id="cb5-205"></span>
<span id="cb5-206">viewof ESS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-207">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">300</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-208">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Effective sample size:"</span>}</span>
<span id="cb5-209">)</span>
<span id="cb5-210"></span>
<span id="cb5-211">viewof mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-212">  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-213">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Average effect size (mu):"</span>}</span>
<span id="cb5-214">)</span>
<span id="cb5-215"></span>
<span id="cb5-216">viewof tau <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-217">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-218">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Between-study SD (tau):"</span>}</span>
<span id="cb5-219">)</span>
<span id="cb5-220"></span>
<span id="cb5-221">viewof omega <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-222">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-223">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Within-study SD (omega):"</span>}</span>
<span id="cb5-224">)</span>
<span id="cb5-225"></span>
<span id="cb5-226">viewof rho <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-227">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-228">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sampling error correlation (rho):"</span>}</span>
<span id="cb5-229">)</span>
<span id="cb5-230"></span>
<span id="cb5-231">viewof alpha <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-232">  [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.005</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.995</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-233">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">005</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One-sided significance threshold (alpha):"</span>}</span>
<span id="cb5-234">)</span>
<span id="cb5-235"></span>
<span id="cb5-236">viewof qp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(</span>
<span id="cb5-237">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-238">  {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of quadrature points:"</span>}</span>
<span id="cb5-239">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-5-8" data-nodetype="declaration">

</div>
</div>
</div>
</div>
</div>
</div>


</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>effect size</category>
  <category>distribution theory</category>
  <guid>https://jepusto.netlify.app/posts/distribution-of-significant-effects/</guid>
  <pubDate>Thu, 28 Mar 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Approximating the distribution of cluster-robust Wald statistics</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/cluster-robust-Wald-statistics/</link>
  <description><![CDATA[ 





<p>In <a href="http://doi.org/10.3102/1076998615606099">Tipton and Pustejovsky (2015)</a>, we examined several different small-sample approximations for cluster-robust Wald test statistics, which are like <img src="https://latex.codecogs.com/png.latex?F"> statistics but based on cluster-robust variance estimators. These statistics are, frankly, kind of weird and awkward to work with, and the approximations that we examined were far from perfect. In this post, I will look in detail at the robust Wald statistic for a simple but common scenario: a one-way ANOVA problem with clusters of dependent observations. <img src="https://latex.codecogs.com/png.latex?%5Cdef%5CPr%7B%7B%5Ctext%7BPr%7D%7D%7D%0A%5Cdef%5CE%7B%7B%5Ctext%7BE%7D%7D%7D%0A%5Cdef%5CVar%7B%7B%5Ctext%7BVar%7D%7D%7D%0A%5Cdef%5CCov%7B%7B%5Ctext%7BCov%7D%7D%7D%0A%5Cdef%5Ccor%7B%7B%5Ctext%7Bcor%7D%7D%7D%0A%5Cdef%5Cbm%7B%5Cmathbf%7D%0A%5Cdef%5Cbs%7B%5Cboldsymbol%7D"></p>
<section id="meta-anova" class="level1">
<h1>Meta-ANOVA</h1>
<p>Consider a setup where clusters can be classified into one of <img src="https://latex.codecogs.com/png.latex?C"> categories, with each cluster of observations falling into a single category. Let <img src="https://latex.codecogs.com/png.latex?%5Cbs%5Cmu%20=%20%5Cleft%5B%5Cmu_c%20%5Cright%5D_%7Bc=1%7D%5EC"> denote the means of these categories. Suppose we have an estimator of those means <img src="https://latex.codecogs.com/png.latex?%5Cbs%7B%5Chat%5Cmu%7D%20=%20%5Cleft%5B%5Chat%5Cmu_c%5Cright%5D_%7Bc=1%7D%5EC"> and a corresponding cluster-robust variance estimator <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BV%7D%5ER%20=%20%5Cbigoplus_%7Bc=1%7D%5EC%20V%5ER_c">. Note that <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BV%7D%5ER"> is diagonal because the estimators for each category are independent. Assume that the robust variance estimator is unbiased so <img src="https://latex.codecogs.com/png.latex?%5CE%5Cleft(V%5ER_c%5Cright)%20=%20%5CVar%5Cleft(%20%5Chat%5Cmu_c%20%5Cright)%20=%20%5Cpsi_c"> for <img src="https://latex.codecogs.com/png.latex?c%20=%201,...,C">. Let <img src="https://latex.codecogs.com/png.latex?%5Cbs%5CPsi%20=%20%5Cbigoplus_%7Bc=1%7D%5EC%20%5Cpsi_c">.</p>
<p>Suppose that we want to test the null hypothesis that that means of the categories are all equal, <img src="https://latex.codecogs.com/png.latex?H_0:%20%5Cmu_1%20=%20%5Cmu_2%20=%20%5Ccdots%20=%20%5Cmu_C">. We can express this null using a <img src="https://latex.codecogs.com/png.latex?q%20%5Ctimes%20C"> contrast matrix <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BC%7D%20=%20%5Cleft%5B-%5Cbm%7B1%7D_q%20%5C%20%5Cbm%7BI%7D_q%20%5Cright%5D">, where <img src="https://latex.codecogs.com/png.latex?q%20=%20C%20-%201">. The null hypothesis is then <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BC%7D%20%5Cbs%5Cmu%20=%20%5Cbm%7B0%7D_q">. The corresponding cluster-robust Wald statistic is <img src="https://latex.codecogs.com/png.latex?%0AQ%20=%20%5Cbs%7B%5Chat%5Cmu%7D'%20%5Cbm%7BC%7D'%20%5Cleft(%5Cbm%7BC%7D%20%5Cbm%7BV%7D%5ER%20%5Cbm%7BC%7D'%5Cright)%5E%7B-1%7D%20%5Cbm%7BC%7D%20%5Cbs%7B%5Chat%5Cmu%7D.%0A"> Under the null hypothesis, the distribution of <img src="https://latex.codecogs.com/png.latex?Q"> will converge to a <img src="https://latex.codecogs.com/png.latex?%5Cchi%5E2_q"> as the number of clusters in each category grows large. However, with a limited number of clusters in some of the categories, this approximate reference distribution is not very accurate and tests based on it can have wildly inflated type I error rates.</p>
</section>
<section id="small-sample-approximation" class="level1">
<h1>Small-sample approximation</h1>
<p>In the paper, we considered several different ways of approximating the distribution of <img src="https://latex.codecogs.com/png.latex?Q"> that work at smaller sample sizes. One class of approaches to approximating the sampling distribution of <img src="https://latex.codecogs.com/png.latex?Q"> is to use a Hotelling’s <img src="https://latex.codecogs.com/png.latex?T%5E2"> distribution with degrees of freedom <img src="https://latex.codecogs.com/png.latex?%5Ceta">. Given the degrees of freedom, Hotelling’s <img src="https://latex.codecogs.com/png.latex?T%5E2"> is a multiple of an <img src="https://latex.codecogs.com/png.latex?F"> distribution: <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Ceta%20-%20q%20+%201%7D%7B%5Ceta%20q%7D%20Q%20%5Csim%20F(q,%20%5Ceta%20-%20q%20+%201).%0A"> The question is then how to determine <img src="https://latex.codecogs.com/png.latex?%5Ceta">.</p>
<p>Several of the approaches that we considered are based on representing the <img src="https://latex.codecogs.com/png.latex?Q"> statistic as <img src="https://latex.codecogs.com/png.latex?%0AQ%20=%20%5Cbm%7Bz%7D'%20%5Cbm%7BD%7D%5E%7B-1%7D%20%5Cbm%7Bz%7D,%0A"> where <img src="https://latex.codecogs.com/png.latex?%5Cbs%5COmega%20=%20%5Cbm%7BC%7D%20%5Cbs%5CPsi%20%5Cbm%7BC%7D'">, <img src="https://latex.codecogs.com/png.latex?%5Cbm%7Bz%7D%20=%20%5Cbs%5COmega%5E%7B-1/2%7D%5Cbm%7BC%7D%5Chat%5Cmu_c">, <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BG%7D%20=%20%5Cbs%5COmega%5E%7B-1/2%7D%20%5Cbm%7BC%7D">, and <img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7BD%7D%20=%20%5Cbm%7BG%7D%20%5Cbm%7BV%7D%5ER%20%5Cbm%7BG%7D'.%0A"> The various approaches we considered involve different ways of approximating the sampling distribution of <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BD%7D">.</p>
<section id="zhangs-approximation" class="level2">
<h2 class="anchored" data-anchor-id="zhangs-approximation">Zhang’s approximation</h2>
<p>One of the approximations involves finding degrees of freedom <img src="https://latex.codecogs.com/png.latex?%5Ceta"> by following a strategy suggested by Zhang (<a href="https://doi.org/10.1016/j.jspi.2011.07.023">2012</a>, <a href="https://doi.org/10.14419/ijasp.v1i2.908">2013</a>). These degrees of freedom are given by <img src="https://latex.codecogs.com/png.latex?%0A%5Ceta_Z%20=%20%5Cfrac%7Bq(q%20+%201)%7D%7B%5Csum_%7Bs=1%7D%5Eq%20%5Csum_%7Bt%20=%201%7D%5Eq%20%5CVar(d_%7Bst%7D)%7D,%0A"> where <img src="https://latex.codecogs.com/png.latex?d_%7Bst%7D"> is the entry in row <img src="https://latex.codecogs.com/png.latex?s">, column <img src="https://latex.codecogs.com/png.latex?t"> of <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BD%7D">. To find <img src="https://latex.codecogs.com/png.latex?%5Ceta_Z">, we can compute the denominator using general formulas given in the paper. However, with a bit of analysis we can find a much simpler expression for the special case of one-way ANOVA.</p>
</section>
<section id="a-bit-of-math" class="level2">
<h2 class="anchored" data-anchor-id="a-bit-of-math">A bit of math</h2>
<p>Before going further, it’s useful to observe that <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BD%7D"> is invariant to linear transformations of <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BC%7D">. In particular, an equivalent way to write the null hypothesis is as <img src="https://latex.codecogs.com/png.latex?H_0:%20%5Cbs%5CPsi_%7B%5Ccirc%7D%5E%7B-1/2%7D%20%5Cbm%7BC%7D%20=%20%5Cbm%7B0%7D_q">, where <img src="https://latex.codecogs.com/png.latex?%5Cbs%5CPsi_%7B%5Ccirc%7D%20=%20%5Cbigoplus_%7Bc=2%7D%5EC%20%5Cpsi_c"> is the diagonal of the true sampling variances of categories 2 through <img src="https://latex.codecogs.com/png.latex?C">, omitting the first category. Thus, let me redefine <img src="https://latex.codecogs.com/png.latex?%0A%5Cbs%5COmega%20=%20%5Cbs%5CPsi_%7B%5Ccirc%7D%5E%7B-1/2%7D%20%5Cbm%7BC%7D%20%5Cbs%5CPsi%20%5Cbm%7BC%7D'%5Cbs%5CPsi_%7B%5Ccirc%7D%5E%7B-1/2%7D,%0A"> <img src="https://latex.codecogs.com/png.latex?%5Cbm%7Bz%7D%20=%20%5Cbs%5COmega%5E%7B-1/2%7D%5Cbs%5CPsi_%7B%5Ccirc%7D%5E%7B-1/2%7D%5Cbm%7BC%7D%5Chat%5Cmu_c">, and <img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7BG%7D%20=%20%5Cbs%5COmega%5E%7B-1/2%7D%20%5Cbs%5CPsi_%7B%5Ccirc%7D%5E%7B-1/2%7D%20%5Cbm%7BC%7D.%0A"> This transformation of the constraint matrix will make it possible to find a closed-form expression for <img src="https://latex.codecogs.com/png.latex?%5Cbs%5COmega%5E%7B-1/2%7D">.</p>
</section>
<section id="deriving-zhangs-degrees-of-freedom" class="level2">
<h2 class="anchored" data-anchor-id="deriving-zhangs-degrees-of-freedom">Deriving Zhang’s degrees of freedom</h2>
<p>Now, observe that <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cbs%5COmega%20&amp;=%20%5Cbs%5CPsi_%7B%5Ccirc%7D%5E%7B-1/2%7D%20%5Cbm%7BC%7D%20%5Cbs%5CPsi%20%5Cbm%7BC%7D'%5Cbs%5CPsi_%7B%5Ccirc%7D%5E%7B-1/2%7D%20%5C%5C%0A&amp;=%20%5Cbs%5CPsi_%7B%5Ccirc%7D%5E%7B-1/2%7D%20%5Cleft(%5Cbs%5CPsi_%7B%5Ccirc%7D%20+%20%5Cpsi_1%20%5Cbm%7B1%7D_q%20%5Cbm%7B1%7D_q'%5Cright)%5Cbs%5CPsi_%7B%5Ccirc%7D%5E%7B-1/2%7D%20%5C%5C%0A&amp;=%20%5Cbm%7BI%7D_q%20+%20%5Cpsi_1%20%5Cbm%7Bf%7D%20%5Cbm%7Bf%7D',%0A%5Cend%7Baligned%7D%0A"> where <img src="https://latex.codecogs.com/png.latex?%5Cbm%7Bf%7D%20=%20%5Cbs%5CPsi_%7B%5Ccirc%7D%5E%7B-1/2%7D%20%5Cbm%7B1%7D_q%20=%20%5Cleft%5B%20%5Cpsi_c%5E%7B-1/2%7D%5Cright%5D_%7Bc%20=%202%7D%5EC">. From the <a href="\bs\Psi_{\circ}^{-1/2}">Woodbury identity</a>, <img src="https://latex.codecogs.com/png.latex?%0A%5Cbs%5COmega%5E%7B-1%7D%20=%20%5Cbm%7BI%7D%20-%20%5Cfrac%7B1%7D%7BW%7D%20%5Cbm%7Bf%7D%20%5Cbm%7Bf%7D',%0A"> where <img src="https://latex.codecogs.com/png.latex?W%20=%20%5Csum_%7Bc=1%7D%5EC%20%5Cfrac%7B1%7D%7B%5Cpsi_c%7D">.</p>
<p><a href="https://doi.org/10.1137/22M1471559">Fasi, Higham, and Liu (2023)</a> provide formulas for <img src="https://latex.codecogs.com/png.latex?p%5E%7Bth%7D"> roots of low-rank updates to scaled identity matrices. Their results provide a neat closed-form expression for <img src="https://latex.codecogs.com/png.latex?%5Cbs%5COmega%5E%7B-1/2%7D">. From their Equation (1.9), <img src="https://latex.codecogs.com/png.latex?%0A%5Cbs%5COmega%5E%7B-1/2%7D%20=%20%5Cmathbf%7BI%7D_q%20-%20%5Ckappa%20%5C%20%5Cbm%7Bf%7D%20%5Cbm%7Bf%7D',%0A"> where <img src="https://latex.codecogs.com/png.latex?%5Ckappa%20=%20%5Cfrac%7B%5Csqrt%7B%5Cpsi_1%7D%7D%7BW%20%5Csqrt%7B%5Cpsi_1%7D%20+%20%5Csqrt%7BW%7D%7D">. Further, we can write the <img src="https://latex.codecogs.com/png.latex?q%20%5Ctimes%20C"> matrix <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BG%7D"> as <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cbm%7BG%7D%20&amp;=%20%5Cbs%5COmega%5E%7B-1/2%7D%20%5Cbs%5CPsi_%7B%5Ccirc%7D%5E%7B-1/2%7D%20%5Cbm%7BC%7D%20%5C%5C%0A&amp;=%20%5Cleft(%20%5Cmathbf%7BI%7D_q%20-%20%5Ckappa%20%5C%20%5Cbm%7Bf%7D%20%5Cbm%7Bf%7D'%20%5Cright)%20%5Cbs%5CPsi_%7B%5Ccirc%7D%5E%7B-1/2%7D%20%5Cleft%5B-%5Cbm%7B1%7D_q,%20%5C%20%5Cbm%7BI%7D_q%20%5Cright%5D%20%5C%5C%0A&amp;=%20%5Cleft%5B%5Cfrac%7B%5Ckappa(W%20%5Cpsi_1%20-%201)%20-%20%5Cpsi_1%7D%7B%5Cpsi_1%7D%20%5Cbm%7Bf%7D,%20%20%5Cleft(%20%5Cmathbf%7BI%7D_q%20-%20%5Ckappa%20%5C%20%5Cbm%7Bf%7D%20%5Cbm%7Bf%7D'%20%5Cright)%20%5Cbs%5CPsi_%7B%5Ccirc%7D%5E%7B-1/2%7D%5Cright%5D,%0A%5Cend%7Baligned%7D%0A"> with entries given by <img src="https://latex.codecogs.com/png.latex?%0Ag_%7Bsc%7D%20=%20%5Cbegin%7Bcases%7D%0A%5Cfrac%7B%5Ckappa(W%20%5Cpsi_1%20-%201)%20-%20%5Cpsi_1%7D%7B%5Cpsi_1%20%5Csqrt%7B%5Cpsi_%7Bs+1%7D%7D%7D%20&amp;%20%5Ctext%7Bif%7D%20%5Cquad%20c%20=%201%20%5C%5C%0A%5Cfrac%7BI(s+1%20=%20c)%7D%7B%5Csqrt%7B%5Cpsi_%7Bc%7D%7D%7D%20-%20%5Cfrac%7B%5Ckappa%7D%7B%5Cpsi_c%20%5Csqrt%7B%5Cpsi_%7Bs+1%7D%7D%7D%20&amp;%20%5Ctext%7Bif%7D%20%5Cquad%20c%20%3E%201.%0A%5Cend%7Bcases%7D%0A"> Because <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BD%7D%20=%20%5Cbm%7BG%7D%20%5Cbm%7BV%7D%5ER%20%5Cbm%7BG%7D'"> and <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BV%7D%5ER"> is diagonal, we can write the entries of <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BD%7D"> as <img src="https://latex.codecogs.com/png.latex?%0Ad_%7Bst%7D%20=%20%5Csum_%7Bc=1%7D%5EC%20g_%7Bsc%7D%20g_%7Btc%7D%20V%5ER_c.%0A"> And because the variance estimators for each category are independent, <img src="https://latex.codecogs.com/png.latex?%0A%5CVar(d_%7Bst%7D)%20=%20%5Csum_%7Bc=1%7D%5EC%20g_%7Bsc%7D%5E2%20g_%7Btc%7D%5E2%20%5CVar(V%5ER_c).%0A"> In <a href="../..\publication/power-approximations-for-dependent-effects/">prior work</a>, we derived expressions for the Satterthwaite degrees of freedom for variances of average effect sizes, and the same formulas can be applied here with the category-specific <img src="https://latex.codecogs.com/png.latex?V%5ER_c">. Let me write <img src="https://latex.codecogs.com/png.latex?%5Cnu_c%20=%202%5Cleft%5B%5CE(V%5ER_c)%5Cright%5D%5E2%20/%20%5CVar(V%5ER_c)"> for the degrees of freedom corresponding to category <img src="https://latex.codecogs.com/png.latex?c">. Then <img src="https://latex.codecogs.com/png.latex?%0A%5CVar(d_%7Bst%7D)%20=%202%20%5Csum_%7Bc=1%7D%5EC%20g_%7Bsc%7D%5E2%20g_%7Btc%7D%5E2%20%5Cfrac%7B%5Cpsi_c%5E2%7D%7B%5Cnu_c%7D.%0A"> We can use this to obtain an expression for Zhang’s approximate degrees of freedom: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0Aq(q%20+%201)%5Ceta_Z%5E%7B-1%7D%20&amp;=%20%5Csum_%7Bs=1%7D%5Eq%20%5Csum_%7Bt%20=%201%7D%5Eq%20%5CVar(d_%7Bst%7D)%20%5C%5C%0A&amp;=%202%5Csum_%7Bs=1%7D%5Eq%20%5Csum_%7Bt%20=%201%7D%5Eq%20%5Csum_%7Bc=1%7D%5EC%20g_%7Bsc%7D%5E2%20g_%7Btc%7D%5E2%20%5Cfrac%7B%5Cpsi_c%5E2%7D%7B%5Cnu_c%7D%20%5C%5C%0A&amp;=%202%5Csum_%7Bc=1%7D%5EC%20%5Cfrac%7B%5Cpsi_c%5E2%7D%7B%5Cnu_c%7D%20%5Cleft(%5Csum_%7Bs=1%7D%5Eq%20g_%7Bsc%7D%5E2%5Cright)%5E2.%0A%5Cend%7Baligned%7D%0A"> Now, all we need to do is simplify… <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Csum_%7Bs=1%7D%5Eq%20g_%7Bs1%7D%5E2%20&amp;=%20%5Csum_%7Bs=1%7D%5Eq%20%5Cfrac%7B%5Cleft(%5Ckappa(W%20%5Cpsi_1%20-%201)%20-%20%5Cpsi_1%5Cright)%5E2%7D%7B%5Cpsi_1%5E2%20%5Cpsi_%7Bs+1%7D%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B%5Cleft(%5Ckappa(W%20%5Cpsi_1%20-%201)%20-%20%5Cpsi_1%5Cright)%5E2%7D%7B%5Cpsi_1%5E2%7D%20%5Csum_%7Bc=2%7D%5EC%20%5Cfrac%7B1%7D%7B%5Cpsi_%7Bs+1%7D%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B%5Cleft(%5Ckappa(W%20%5Cpsi_1%20-%201)%20-%20%5Cpsi_1%5Cright)%5E2%7D%7B%5Cpsi_1%5E2%7D%20%5Cfrac%7B(W%20%5Cpsi_1%20-%201)%7D%7B%5Cpsi_1%7D%20%5C%5C%0A&amp;=%20%5Ctext%7B...a%20bunch%20of%20tedious%20algebra...%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B%5Cpsi_1%5E2%7D%20%5Cleft(%5Cpsi_1%20-%20%5Cfrac%7B1%7D%7BW%7D%5Cright)%0A%5Cend%7Baligned%7D%0A"> and, for <img src="https://latex.codecogs.com/png.latex?c%20=%202,...,C">, <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Csum_%7Bs=1%7D%5Eq%20g_%7Bsc%7D%5E2%20&amp;=%20%5Csum_%7Bs=1%7D%5Eq%20%5Cleft(%5Cfrac%7BI(s+1%20=%20c)%7D%7B%5Csqrt%7B%5Cpsi_%7Bc%7D%7D%7D%20-%20%5Cfrac%7B%5Ckappa%7D%7B%5Cpsi_c%20%5Csqrt%7B%5Cpsi_%7Bs+1%7D%7D%7D%5Cright)%5E2%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B%5Cpsi_c%7D%20-%20%5Cfrac%7B2%20%5Ckappa%7D%7B%5Cpsi_c%5E2%7D%20+%20%5Cfrac%7B%5Ckappa%5E2%7D%7B%5Cpsi_c%5E2%7D%5Csum_%7Bs=1%7D%5Eq%20%5Cfrac%7B1%7D%7B%5Cpsi_%7Bs+1%7D%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B%5Cpsi_c%7D%20-%20%5Cfrac%7B2%20%5Ckappa%7D%7B%5Cpsi_c%5E2%7D%20+%20%5Cfrac%7B%5Ckappa%5E2%7D%7B%5Cpsi_c%5E2%7D%5Cfrac%7B(W%20%5Cpsi_1%20-%201)%7D%7B%5Cpsi_1%7D%20%5C%5C%0A&amp;=%20%5Ctext%7B...a%20bunch%20of%20tedious%20algebra...%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B%5Cpsi_c%5E2%7D%20%5Cleft(%5Cpsi_c%20-%20%5Cfrac%7B1%7D%7BW%7D%5Cright)%0A%5Cend%7Baligned%7D%0A"> Thus, <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0Aq(q%20+%201)%5Ceta_Z%5E%7B-1%7D%20&amp;=%202%5Csum_%7Bc=1%7D%5EC%20%5Cfrac%7B%5Cpsi_c%5E2%7D%7B%5Cnu_c%7D%20%5Cleft(%5Csum_%7Bs=1%7D%5Eq%20g_%7Bsc%7D%5E2%5Cright)%5E2%20%5C%5C%0A&amp;=%202%5Csum_%7Bc=1%7D%5EC%20%5Cfrac%7B1%7D%7B%5Cnu_c%20%5Cpsi_c%5E2%7D%5Cleft(%5Cpsi_c%20-%20%5Cfrac%7B1%7D%7BW%7D%5Cright)%5E2%20%5C%5C%0A&amp;=%202%5Csum_%7Bc=1%7D%5EC%20%5Cfrac%7B1%7D%7B%5Cnu_c%7D%5Cleft(1%20-%20%5Cfrac%7B1%7D%7B%5Cpsi_c%20W%7D%5Cright)%5E2%0A%5Cend%7Baligned%7D%0A"> or, rearranging, <img src="https://latex.codecogs.com/png.latex?%0A%5Ceta_Z%20=%20%5Cfrac%7BC(C%20-%201)%7D%7B2%20%5Csum_%7Bc=1%7D%5EC%20%5Cfrac%7B1%7D%7B%5Cnu_c%7D%5Cleft(1%20-%20%5Cfrac%7B1%7D%7B%5Cpsi_c%20W%7D%5Cright)%5E2%7D.%0A"> It’s a surprisingly clean formula! Once these degrees of freedom are calculated, the degrees of freedom for the reference <img src="https://latex.codecogs.com/png.latex?F"> distribution would be <img src="https://latex.codecogs.com/png.latex?q"> and <img src="https://latex.codecogs.com/png.latex?%5Ceta_Z%20-%20q%20+%201">.</p>
</section>
<section id="other-approximations" class="level2">
<h2 class="anchored" data-anchor-id="other-approximations">Other approximations</h2>
<p>In the paper, we also considered two other degrees of freedom approximations, which involve not only the variances of <img src="https://latex.codecogs.com/png.latex?d_%7Bst%7D"> but also the covariances between entries. In principle, one could follow similar algebra to get expressions for these other degrees of freedom as well. However, our simulations indicated that the other degrees of freedom approximations tend to be overly conservative and produce type-I error rates way below the nominal level (essentially, hardly ever rejecting the null) and less accurate than HTZ. So, there’s not much reason to work through them unless you find algebra enjoyable for its own sake.</p>
</section>
</section>
<section id="whats-the-right-non-central-distribution" class="level1">
<h1>What’s the right non-central distribution?</h1>
<p>A further question about this cluster-robust Wald statistic is how to approximate its sampling distribution under specific alternative hypotheses. In other words, given a vector of means <img src="https://latex.codecogs.com/png.latex?%5Cmu_1,...,%5Cmu_C"> where the null does not hold, plus some information to determine <img src="https://latex.codecogs.com/png.latex?%5Cpsi_c"> and <img src="https://latex.codecogs.com/png.latex?%5Cnu_c"> for <img src="https://latex.codecogs.com/png.latex?c%20=%201,...,C">, how could we approximate the distribution of <img src="https://latex.codecogs.com/png.latex?Q">? We need something like a non-central Hotelling’s <img src="https://latex.codecogs.com/png.latex?T%5E2"> distribution…</p>


<!-- -->

</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>robust variance estimation</category>
  <category>distribution theory</category>
  <guid>https://jepusto.netlify.app/posts/cluster-robust-Wald-statistics/</guid>
  <pubDate>Sun, 24 Mar 2024 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Implementing Consul’s generalized Poisson distribution in Stan</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/generalized-poisson-in-Stan/</link>
  <description><![CDATA[ 





<p>For a project I am working on, we are using <a href="https://mc-stan.org/">Stan</a> to fit generalized random effects location-scale models to a bunch of count data. In <a href="../..\posts/double-poisson-in-Stan/">a previous post</a>, I walked through our implementation of <a href="https://doi.org/10.2307/2289002">Efron’s (1986)</a> double-Poisson distribution, which we are interested in using because it allows for both over- and under-dispersion relative to the Poisson distribution. Another distribution with these properties is the generalized Poisson distribution described by <a href="https://doi.org/10.1080/00401706.1973.10489112">Consul and Jain (1973)</a>.</p>
<p>In this post, I’ll walk through my implementation of the GPO in Stan. The <a href="https://cran.r-project.org/package=gamlss.dist"><code>gamlss.dist</code> package</a> provides a full set of distributional functions for the generalized Poisson distribution, including a sampler, but the functions are configured to only allow for over-dispersion. Since I’m interested in allowing for under-dispersion as well, I’ll need to write my own functions. As in my previous post, I can validate my Stan functions against the functions from <code>gamlss.dist</code> (although only for over-dispersion scenarios).</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cdef%5CPr%7B%7B%5Ctext%7BPr%7D%7D%7D%0A%5Cdef%5CE%7B%7B%5Ctext%7BE%7D%7D%7D%0A%5Cdef%5CVar%7B%7B%5Ctext%7BVar%7D%7D%7D%0A%5Cdef%5CCov%7B%7B%5Ctext%7BCov%7D%7D%7D%0A%5Cdef%5Cbm%7B%5Cmathbf%7D%0A%5Cdef%5Cbs%7B%5Cboldsymbol%7D%0A"></p>
<div class="cell">
<details open="" 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;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(patchwork)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># composing figures</span></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(gamlss.dist) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># DPO distribution functions</span></span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rstan)       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Stan interface to R</span></span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(brms)        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fitting generalized linear models</span></span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(bayesplot)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Examine fitted models</span></span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(loo)         <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Model fit measures</span></span></code></pre></div></div>
</details>
</div>
<section id="the-generalized-poisson" class="level2">
<h2 class="anchored" data-anchor-id="the-generalized-poisson">The generalized Poisson</h2>
<p>Consul and Jain’s generalized Poisson distribution is a discrete distribution for non-negative counts, with support <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BS%7D_X%20=%20%5C%7B0,%201,%202,%203,%20...%5C%7D">. The mean-variance relationship of the generalized Poisson is constant; for <img src="https://latex.codecogs.com/png.latex?X%20%5Csim%20GPO(%5Cmu,%20%5Cphi)">, <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BE%7D(X)%20=%20%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BVar%7D(X)%20=%20%5Cmu%20/%20%5Cphi"> for <img src="https://latex.codecogs.com/png.latex?0%20%3C%20%5Cphi%20%3C%201">; the expectation and variance are not exact but are close approximations when there is underdispersion, so <img src="https://latex.codecogs.com/png.latex?%5Cphi%20%3E%201">. Thus, like the double-Poisson distribution, the generalized Poisson satisfies the assumptions of a quasi-Poisson generalized linear model (at least approximately).</p>
<p>The density of the generalized Poisson distribution with mean <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and inverse-disperson <img src="https://latex.codecogs.com/png.latex?%5Cphi"> is: <img src="https://latex.codecogs.com/png.latex?%0Af(x%20%7C%20%5Cmu,%20%5Cphi)%20=%20%5Cmu%20%5Csqrt%7B%5Cphi%7D%20%5Cleft(%20x%20+%20%5Csqrt%7B%5Cphi%7D(%5Cmu%20-%20x)%20%5Cright)%5E%7Bx-1%7D%20%5Cfrac%7B%5Cexp%20%5Cleft%5B-%5Cleft(%20x%20+%20%5Csqrt%7B%5Cphi%7D(%5Cmu%20-%20x)%5Cright)%5Cright%5D%7D%7Bx!%7D.%0A"> We then have <img src="https://latex.codecogs.com/png.latex?%0A%5Cln%20f(x%20%7C%20%5Cmu,%20%5Cphi)%20=%20%5Cfrac%7B1%7D%7B2%7D%20%5Cln%20%5Cphi%20+%20%5Cln%20%5Cmu%20+%20(x%20-%201)%20%5Cln%20%5Cleft(%20x%20+%20%5Csqrt%7B%5Cphi%7D(%5Cmu%20-%20x)%20%5Cright)%20-%20%5Cleft(%20x%20+%20%5Csqrt%7B%5Cphi%7D(%5Cmu%20-%20x)%20%5Cright)%20-%20%5Cln%20%5Cleft(x!%5Cright).%0A"> Using the GPO with under-dispersed data is a little bit more controversial (by statistical standards) than using the DPO. This is because, for parameter values corresponding to under-dispersion, its probability mass function becomes negative for large counts. In particular, note that for values <img src="https://latex.codecogs.com/png.latex?x%20%3E%20%5Cfrac%7B%5Cmu%5Csqrt%5Cphi%7D%7B%5Csqrt%5Cphi%20-%201%7D">, the quantity <img src="https://latex.codecogs.com/png.latex?x%20+%20%5Csqrt%7B%5Cphi%7D(%5Cmu%20-%20x)"> becomes negative, and so <img src="https://latex.codecogs.com/png.latex?f(x%7C%20%5Cmu,%20%5Cphi)"> is no longer a proper probability. Consul suggested handling this situation by truncating the distribution at <img src="https://latex.codecogs.com/png.latex?m%20=%20%5Cleft%5Clfloor%20%5Cfrac%7B%5Cmu%5Csqrt%5Cphi%7D%7B%5Csqrt%5Cphi%20-%201%7D%5Cright%5Crfloor">. However, doing so makes the distribution only an approximation, such that <img src="https://latex.codecogs.com/png.latex?%5Cmu"> is no longer exactly the mean and <img src="https://latex.codecogs.com/png.latex?%5Cphi"> is no longer exactly the inverse dispersion. For modest under-dispersion of no less than 60% of the mean, <img src="https://latex.codecogs.com/png.latex?1%20%3C%20%5Cphi%20%3C%205%20/%203"> and the truncation point is fairly extreme, with <img src="https://latex.codecogs.com/png.latex?m%20%5Capprox%204.4%20%5Cmu">, so I’m not too worried about this issue. We’ll see how it plays out in application, of course.</p>
</section>
<section id="log-of-the-probability-mass-function" class="level1">
<h1>Log of the probability mass function</h1>
<p>Here’s a Stan function implementing the lpmf, with the truncation bit:</p>
<div class="cell">
<details open="" 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">stancode_lpmf <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="cb2-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">real gpo_lpmf(int X, real mu, real phi) {</span></span>
<span id="cb2-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real ans;</span></span>
<span id="cb2-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real m = mu / (1 - inv(sqrt(phi)));</span></span>
<span id="cb2-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real z = X + sqrt(phi) * (mu - X);</span></span>
<span id="cb2-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  if (phi &gt; 1 &amp;&amp; X &gt; m)</span></span>
<span id="cb2-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ans = negative_infinity();</span></span>
<span id="cb2-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  else </span></span>
<span id="cb2-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ans = log(mu) + inv(2) * log(phi) + (X - 1) * log(z) - z - lgamma(X + 1);</span></span>
<span id="cb2-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return ans;</span></span>
<span id="cb2-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb2-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span></code></pre></div></div>
</details>
</div>
<p>To check that this is accurate, I’ll compare the Stan function to the corresponding function from <code>gamlss.dist</code> for a couple of different parameter values and for <img src="https://latex.codecogs.com/png.latex?x%20=%200,...,100">. If my function is accurate, my calculated log-probabilities should be equal to the results from <code>gamlss.dist::dGPO</code>. Note that the <code>gamlss.dist</code> function uses a different parameterization for the dispersion, with <img src="https://latex.codecogs.com/png.latex?%5Csigma%20=%20%5Cfrac%7B%5Cphi%5E%7B-1/2%7D%20-%201%7D%7B%5Cmu%7D">.</p>
<div class="cell">
<details open="" 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;">writeLines</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"functions {"</span>, stancode_lpmf, <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;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GPO-lpmf.stan"</span>)</span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expose_stan_functions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GPO-lpmf.stan"</span>)</span>
<span id="cb3-3"></span>
<span id="cb3-4">test_lpmf <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb3-6">    <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;">2</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;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>),</span>
<span id="cb3-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),</span>
<span id="cb3-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">X =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">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;">100</span></span>
<span id="cb3-9">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb3-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma =</span> (phi<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> mu,</span>
<span id="cb3-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gamlss_lpmf =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dGPO</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;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma =</span> sigma, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">log =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb3-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">my_lpmf =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmap_dbl</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.l =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">X =</span> X, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> phi), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.f =</span> gpo_lpmf),</span>
<span id="cb3-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff =</span> my_lpmf <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> gamlss_lpmf</span>
<span id="cb3-15">  )</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" 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;">ggplot</span>(test_lpmf, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(phi), diff, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(phi))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-2">  <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="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>( <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_both"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/generalized-poisson-in-Stan/index_files/figure-html/unnamed-chunk-1-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Checks out. Onward!</p>
</section>
<section id="quantile-function" class="level1">
<h1>Quantile function</h1>
<p>I’ll next implement the generalized Poisson quantile function, taking advantage of a recurrence relationship for sequential values. Note that <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0Af(0%20%7C%20%5Cmu,%20%5Cphi)%20&amp;=%20%5Cexp%20%5Cleft(-%5Cmu%20%5Csqrt%7B%5Cphi%7D%5Cright)%20%5C%5C%0Af(x%20%7C%20%5Cmu,%20%5Cphi)%20&amp;=%20f(x%20-%201%20%7C%20%5Cmu,%20%5Cphi)%20%5Ctimes%20%5Cfrac%7B%5Cleft(x%20+%20%5Csqrt%7B%5Cphi%7D(%5Cmu%20-%20x)%5Cright)%5E%7Bx%20-%201%7D%7D%7B%5Cleft(x%20-%201%20+%20%5Csqrt%7B%5Cphi%7D(%5Cmu%20-%20(x%20-%201))%5Cright)%5E%7Bx%20-%202%7D%7D%20%5Ctimes%20%5Cfrac%7B%5Cexp(%5Csqrt%7B%5Cphi%7D%20-%201)%7D%7Bx%7D%0A%5Cend%7Baligned%7D%0A"> where the second expression holds for <img src="https://latex.codecogs.com/png.latex?x%20%5Cgeq%201">.</p>
<p>The function below computes the quantile given a value <img src="https://latex.codecogs.com/png.latex?p"> by computing the cumulative distribution function until <img src="https://latex.codecogs.com/png.latex?p"> is exceeded:</p>
<div class="cell">
<details open="" 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">stancode_quantile <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="cb5-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">int gpo_quantile(real p, real mu, real phi) {</span></span>
<span id="cb5-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int q = 0;</span></span>
<span id="cb5-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real phi_sqrt = sqrt(phi);</span></span>
<span id="cb5-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real mu_phi_sqrt = mu * phi_sqrt;</span></span>
<span id="cb5-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real m;</span></span>
<span id="cb5-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  if (phi &gt; 1) </span></span>
<span id="cb5-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    m = mu / (1 - inv(phi_sqrt));</span></span>
<span id="cb5-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  else </span></span>
<span id="cb5-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    m = positive_infinity();</span></span>
<span id="cb5-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real lpmf = - mu_phi_sqrt;</span></span>
<span id="cb5-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real cdf = exp(lpmf);</span></span>
<span id="cb5-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real ln_inc;</span></span>
<span id="cb5-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  while (cdf &lt; p &amp;&amp; q &lt; m) {</span></span>
<span id="cb5-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    q += 1;</span></span>
<span id="cb5-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ln_inc = (q - 1) * log(mu_phi_sqrt + q * (1 - phi_sqrt)) - (q - 2) * log(mu_phi_sqrt + (q - 1) * (1 - phi_sqrt)) + (phi_sqrt - 1) - log(q);</span></span>
<span id="cb5-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    lpmf += ln_inc;    </span></span>
<span id="cb5-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    cdf += exp(lpmf);</span></span>
<span id="cb5-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb5-20"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return q;</span></span>
<span id="cb5-21"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb5-22"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span></code></pre></div></div>
</details>
</div>
<p>If my quantile function is accurate, it should match the value computed from <code>gamlss.dist::qDPO()</code> exactly.</p>
<div class="cell">
<details open="" 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;">writeLines</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"functions {"</span>, stancode_quantile, <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;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GPO-quantile.stan"</span>)</span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expose_stan_functions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GPO-quantile.stan"</span>)</span>
<span id="cb6-3"></span>
<span id="cb6-4">test_quantile <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb6-6">    <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;">2</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;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>),</span>
<span id="cb6-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),</span>
<span id="cb6-8">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma =</span> (phi<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> mu,</span>
<span id="cb6-11">    <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;">map</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;">n</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;">runif</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)),</span>
<span id="cb6-12">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(p) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">my_q =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmap_dbl</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;">p =</span> p, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> phi), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.f =</span> gpo_quantile),</span>
<span id="cb6-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gamlss_q =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qGPO</span>(p, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma =</span> sigma),</span>
<span id="cb6-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff =</span> my_q <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> gamlss_q</span>
<span id="cb6-18">  )</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" 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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(test_quantile, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(phi), diff, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(phi))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>( <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_both"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/generalized-poisson-in-Stan/index_files/figure-html/check-quantile-plot-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>I should enter this figure in the competition for the world’s most boring statistical graphic.</p>
</section>
<section id="sampler" class="level1">
<h1>Sampler</h1>
<p>The last thing I’ll need is a sampler, which I’ll implement by generating random points from a uniform distribution, then computing the generalized Poisson quantiles of these random points. My implementation just generates a single random variate:</p>
<div class="cell">
<details open="" 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">stancode_qr <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="cb8-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">int gpo_quantile(real p, real mu, real phi) {</span></span>
<span id="cb8-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int q = 0;</span></span>
<span id="cb8-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real phi_sqrt = sqrt(phi);</span></span>
<span id="cb8-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real mu_phi_sqrt = mu * phi_sqrt;</span></span>
<span id="cb8-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real m;</span></span>
<span id="cb8-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  if (phi &gt; 1) </span></span>
<span id="cb8-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    m = mu / (1 - inv(phi_sqrt));</span></span>
<span id="cb8-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  else </span></span>
<span id="cb8-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    m = positive_infinity();</span></span>
<span id="cb8-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real lpmf = - mu_phi_sqrt;</span></span>
<span id="cb8-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real cdf = exp(lpmf);</span></span>
<span id="cb8-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real ln_inc;</span></span>
<span id="cb8-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  while (cdf &lt; p &amp;&amp; q &lt; m) {</span></span>
<span id="cb8-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    q += 1;</span></span>
<span id="cb8-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ln_inc = (q - 1) * log(mu_phi_sqrt + q * (1 - phi_sqrt)) - (q - 2) * log(mu_phi_sqrt + (q - 1) * (1 - phi_sqrt)) + (phi_sqrt - 1) - log(q);</span></span>
<span id="cb8-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    lpmf += ln_inc;    </span></span>
<span id="cb8-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    cdf += exp(lpmf);</span></span>
<span id="cb8-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb8-20"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return q;</span></span>
<span id="cb8-21"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb8-22"></span>
<span id="cb8-23"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">int gpo_rng(real mu, real phi) {</span></span>
<span id="cb8-24"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real p = uniform_rng(0,1);</span></span>
<span id="cb8-25"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int x = gpo_quantile(p, mu, phi);</span></span>
<span id="cb8-26"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return x;</span></span>
<span id="cb8-27"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb8-28"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span></code></pre></div></div>
</details>
</div>
<p>To check this function, I’ll generate some large samples from the generalized Poisson with a few different parameter sets. If the sampler is working properly, the empirical cumulative distribution should line up closely with the cumulative distribution computed using <code>gamlss.dist::pGPO()</code>.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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;">writeLines</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"functions {"</span>, stancode_qr, <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;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GPO-rng.stan"</span>)</span>
<span id="cb9-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expose_stan_functions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"GPO-rng.stan"</span>)</span>
<span id="cb9-3"></span>
<span id="cb9-4">gpo_rng_sampler <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, mu, phi) {</span>
<span id="cb9-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">replicate</span>(N, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gpo_rng</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> phi))</span>
<span id="cb9-6">}</span>
<span id="cb9-7"></span>
<span id="cb9-8">test_rng <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb9-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb9-10">    <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;">2</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;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>),</span>
<span id="cb9-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),</span>
<span id="cb9-12">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb9-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma =</span> (phi<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> mu,</span>
<span id="cb9-15">    <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;">pmap</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.l =</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;">N =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> phi), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.f =</span> gpo_rng_sampler),</span>
<span id="cb9-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tb =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</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;">as.data.frame</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(.x)))</span>
<span id="cb9-17">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-18">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(mu, phi) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(tb) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb9-22">    <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.integer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(.x))[.x],</span>
<span id="cb9-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Freq_cum =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cumsum</span>(Freq) <span 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>
<span id="cb9-24">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gamlss_F =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pGPO</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q =</span> .x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma =</span> sigma)</span>
<span id="cb9-25">  )</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" 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;">ggplot</span>(test_rng, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(gamlss_F, Freq_cum, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(phi))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb10-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</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="cb10-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>  </span>
<span id="cb10-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_grid</span>(phi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_both"</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;">theme_minimal</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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Theoretical cdf (gamlss.dist)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Empirical cdf (my function)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb10-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/generalized-poisson-in-Stan/index_files/figure-html/check-rng-plot-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Another approach to checking the sampler is to simulate a bunch of observations and check whether the empirical mean and variance match the theoretical moments. I’ll do this as well, using some values of <img src="https://latex.codecogs.com/png.latex?%5Cphi%20%3E%201"> to test whether the sampler still works when there’s under-dispersion.</p>
<div class="cell">
<details open="" 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">test_moments <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb11-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb11-3">    <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;">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;">20</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>),</span>
<span id="cb11-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>),</span>
<span id="cb11-5">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb11-7">    <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;">pmap</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.l =</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;">N =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> phi), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.f =</span> gpo_rng_sampler),</span>
<span id="cb11-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">M =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(x, mean),</span>
<span id="cb11-9">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">S =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dbl</span>(x, sd),</span>
<span id="cb11-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">M_ratio =</span> M <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> mu,</span>
<span id="cb11-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">S_ratio =</span> S <span 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>(mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> phi)</span>
<span id="cb11-12">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-13">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-14">  <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;">ends_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_ratio"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"moment"</span>,<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;">"ratio"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb11-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb11-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">moment =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(moment, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M_ratio"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S_ratio"</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;">"Sample mean"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Standard deviation"</span>)),</span>
<span id="cb11-17">    <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;">factor</span>(mu)</span>
<span id="cb11-18">  )</span>
<span id="cb11-19"></span>
<span id="cb11-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(test_moments, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(phi, ratio, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> mu)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb11-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb11-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> moment) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb11-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/generalized-poisson-in-Stan/index_files/figure-html/test-sample-moments-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>Looks like the sample moments closely match the parameter values, with deviations that look pretty much like random error. Nice!</p>
</section>
<section id="using-the-custom-distribution-functions" class="level1">
<h1>Using the custom distribution functions</h1>
<p>To finish out my tests of these functions, I’ll try out a small simulation. Following my <a href="../..\posts/Double-Poisson-in-Stan/">previous post</a>, I’ll generate data based on a generalized linear model with a single predictor <img src="https://latex.codecogs.com/png.latex?X">, where the outcome <img src="https://latex.codecogs.com/png.latex?Y"> follows a generalized Poisson distribution conditional on <img src="https://latex.codecogs.com/png.latex?X">. The data-generating process is:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0AX%20&amp;%5Csim%20%5CGamma(6,2)%20%5C%5C%0AY%7CX%20&amp;%5Csim%20GPO(%5Cmu(X),%20%5Cphi)%20%5C%5C%0A%5Clog%20%5Cmu(X)%20&amp;=%202%20+%200.3%20%5Ctimes%20X%0A%5Cend%7Baligned%7D%0A"> with the dispersion parameter set to <img src="https://latex.codecogs.com/png.latex?%5Cphi%20=%206/10"> so that the outcome is <em>over</em>-dispersed. I’m looking at over-dispersion here so that the negative binomial has a chance to keep up, since it doesn’t allow for any degree of under-dispersion.</p>
<p>The following code generates a large sample from the data-generating process:</p>
<div class="cell">
<details open="" 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;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20231206</span>)</span>
<span id="cb12-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;">1500</span></span>
<span id="cb12-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;">rgamma</span>(N, <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;">6</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rate =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb12-4">mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</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.3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> X)</span>
<span id="cb12-5">phi <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span> <span class="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="cb12-6">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;">map_dbl</span>(mu, gpo_rng, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> phi)</span>
<span id="cb12-7">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span 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></code></pre></div></div>
</details>
</div>
<p>Here’s what the sample looks like, along with a smoothed regression estimated using a basic cubic spline:</p>
<div class="cell">
<details open="" 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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(dat, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(X, Y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb13-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>) <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_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;">"cs"</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;">theme_minimal</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/generalized-poisson-in-Stan/index_files/figure-html/glm-scatterplot-1.png" class="img-fluid figure-img" width="576"></p>
</figure>
</div>
</div>
</div>
<p>Here is a fit using quasi-likelihood estimation of a log-linear model:</p>
<div class="cell">
<details open="" 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">quasi_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(Y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> X, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasipoisson</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;">"log"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat)</span>
<span id="cb14-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(quasi_fit)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
Call:
glm(formula = Y ~ X, family = quasipoisson(link = "log"), data = dat)

Coefficients:
            Estimate Std. Error t value Pr(&gt;|t|)    
(Intercept) 1.981959   0.020609   96.17   &lt;2e-16 ***
X           0.306733   0.005525   55.52   &lt;2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for quasipoisson family taken to be 1.680427)

    Null deviance: 7248.1  on 1499  degrees of freedom
Residual deviance: 2520.5  on 1498  degrees of freedom
AIC: NA

Number of Fisher Scoring iterations: 4</code></pre>
</div>
</div>
<p>This approach recovers the data-generating parameters quite well, with a dispersion estimate of 1.68 compared to the true dispersion parameter of 1.67.</p>
<section id="candidate-models" class="level2">
<h2 class="anchored" data-anchor-id="candidate-models">Candidate models</h2>
<p>Now let me fit the same generalized linear model but assuming that the outcome follow a couple of different distributions, including a true Poisson (with unit dispersion), a negative binomial, the double-Poisson distribution from the previous post, and the generalized Poisson distribution. Here goes!</p>
<div class="cell">
<details open="" 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">Poisson_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb16-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">brm</span>(</span>
<span id="cb16-3">    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;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">poisson</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;">"log"</span>),</span>
<span id="cb16-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat, </span>
<span id="cb16-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warmup =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>, </span>
<span id="cb16-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>, </span>
<span id="cb16-7">    <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="cb16-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cores =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb16-9">    <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;">20231204</span></span>
<span id="cb16-10">  )</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" 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">negbin_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb17-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">brm</span>(</span>
<span id="cb17-3">    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;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">negbinomial</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;">"log"</span>),</span>
<span id="cb17-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat, </span>
<span id="cb17-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warmup =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>, </span>
<span id="cb17-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>, </span>
<span id="cb17-7">    <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="cb17-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cores =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb17-9">    <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;">20231204</span></span>
<span id="cb17-10">  )</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" 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">stancode_dpo <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="cb18-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">real dpo_lpmf(int X, real mu, real phi) {</span></span>
<span id="cb18-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real ans;</span></span>
<span id="cb18-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real A = inv(2) * log(phi) - phi * mu;</span></span>
<span id="cb18-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  if (X == 0)</span></span>
<span id="cb18-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ans = A;</span></span>
<span id="cb18-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  else</span></span>
<span id="cb18-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ans = A + X * (phi * (1 + log(mu)) - 1) - lgamma(X + 1) + (1 - phi) * X * log(X);</span></span>
<span id="cb18-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return ans;</span></span>
<span id="cb18-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb18-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">vector dpo_cdf_vec(real mu, real phi, int maxval) {</span></span>
<span id="cb18-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real d = exp(phi * (1 + log(mu)) - 1);</span></span>
<span id="cb18-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real prob;</span></span>
<span id="cb18-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int n = maxval + 1;</span></span>
<span id="cb18-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[n] cdf;</span></span>
<span id="cb18-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cdf[1] = sqrt(phi) * exp(-mu * phi);</span></span>
<span id="cb18-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  prob = cdf[1] * d;</span></span>
<span id="cb18-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cdf[2] = cdf[1] + prob;</span></span>
<span id="cb18-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  for (i in 2:maxval) {</span></span>
<span id="cb18-20"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    prob = prob * d * exp((1 - phi) * (i - 1) * (log(i) - log(i - 1))) / (i^phi);</span></span>
<span id="cb18-21"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    cdf[i + 1] = cdf[i] + prob;</span></span>
<span id="cb18-22"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    if (prob / cdf[i + 1] &lt; 1e-8) {</span></span>
<span id="cb18-23"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">      n = i + 1;</span></span>
<span id="cb18-24"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">      break;</span></span>
<span id="cb18-25"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    }</span></span>
<span id="cb18-26"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb18-27"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return cdf / cdf[n];</span></span>
<span id="cb18-28"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb18-29"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">int dpo_quantile(real p, real mu, real phi, int maxval) {</span></span>
<span id="cb18-30"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[maxval + 1] cdf_vec = dpo_cdf_vec(mu, phi, maxval);</span></span>
<span id="cb18-31"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int q = 0;</span></span>
<span id="cb18-32"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  while (cdf_vec[q + 1] &lt; p) {</span></span>
<span id="cb18-33"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">      q += 1;</span></span>
<span id="cb18-34"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    }</span></span>
<span id="cb18-35"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return q;</span></span>
<span id="cb18-36"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb18-37"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">int dpo_rng(real mu, real phi, int maxval) {</span></span>
<span id="cb18-38"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real p = uniform_rng(0,1);</span></span>
<span id="cb18-39"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int x = dpo_quantile(p, mu, phi, maxval);</span></span>
<span id="cb18-40"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return x;</span></span>
<span id="cb18-41"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb18-42"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb18-43">double_Poisson <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">custom_family</span>(</span>
<span id="cb18-44">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dpo"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dpars =</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;">"mu"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>),</span>
<span id="cb18-45">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">links =</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;">"log"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>),</span>
<span id="cb18-46">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lb =</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="at" style="color: #657422;
background-color: null;
font-style: inherit;">ub =</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="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>),</span>
<span id="cb18-47">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"int"</span></span>
<span id="cb18-48">)</span>
<span id="cb18-49"></span>
<span id="cb18-50">double_Poisson_stanvars <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stanvar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scode =</span> stancode_dpo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">block =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"functions"</span>)</span>
<span id="cb18-51"></span>
<span id="cb18-52">phi_prior <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">prior</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exponential</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;">class =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>)</span>
<span id="cb18-53"></span>
<span id="cb18-54">DPO_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb18-55">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">brm</span>(</span>
<span id="cb18-56">    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;">family =</span> double_Poisson,</span>
<span id="cb18-57">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prior =</span> phi_prior,</span>
<span id="cb18-58">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stanvars =</span> double_Poisson_stanvars,</span>
<span id="cb18-59">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat, </span>
<span id="cb18-60">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warmup =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>, </span>
<span id="cb18-61">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>, </span>
<span id="cb18-62">    <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="cb18-63">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cores =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb18-64">    <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;">20231204</span></span>
<span id="cb18-65">  )</span>
<span id="cb18-66"></span>
<span id="cb18-67"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expose_functions</span>(DPO_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vectorize =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb18-68"></span>
<span id="cb18-69">log_lik_dpo <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>(i, prep) {</span>
<span id="cb18-70">  mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> brms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_dpar</span>(prep, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</span> i)</span>
<span id="cb18-71">  phi <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> brms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_dpar</span>(prep, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</span> i)</span>
<span id="cb18-72">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> prep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y[i]</span>
<span id="cb18-73">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dpo_lpmf</span>(y, mu, phi)</span>
<span id="cb18-74">}</span>
<span id="cb18-75"></span>
<span id="cb18-76">posterior_predict_dpo <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>(i, prep, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxval =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>, ...) {</span>
<span id="cb18-77">  mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> brms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_dpar</span>(prep, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</span> i)</span>
<span id="cb18-78">  phi <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> brms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_dpar</span>(prep, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</span> i)</span>
<span id="cb18-79">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(maxval)) maxval <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;">20</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(phi, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb18-80">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dpo_rng</span>(mu, phi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxval =</span> maxval)</span>
<span id="cb18-81">}</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" 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">stancode_gpo <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="cb19-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">real gpo_lpmf(int X, real mu, real phi) {</span></span>
<span id="cb19-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real ans;</span></span>
<span id="cb19-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real m = mu / (1 - inv(sqrt(phi)));</span></span>
<span id="cb19-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real z = X + sqrt(phi) * (mu - X);</span></span>
<span id="cb19-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  if (phi &gt; 1 &amp;&amp; X &gt; m)</span></span>
<span id="cb19-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ans = negative_infinity();</span></span>
<span id="cb19-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  else </span></span>
<span id="cb19-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ans = log(mu) + inv(2) * log(phi) + (X - 1) * log(z) - z - lgamma(X + 1);</span></span>
<span id="cb19-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return ans;</span></span>
<span id="cb19-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb19-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">int gpo_quantile(real p, real mu, real phi) {</span></span>
<span id="cb19-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int q = 0;</span></span>
<span id="cb19-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real phi_sqrt = sqrt(phi);</span></span>
<span id="cb19-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real mu_phi_sqrt = mu * phi_sqrt;</span></span>
<span id="cb19-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real m;</span></span>
<span id="cb19-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  if (phi &gt; 1) </span></span>
<span id="cb19-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    m = mu / (1 - inv(phi_sqrt));</span></span>
<span id="cb19-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  else </span></span>
<span id="cb19-20"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    m = positive_infinity();</span></span>
<span id="cb19-21"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real lpmf = - mu_phi_sqrt;</span></span>
<span id="cb19-22"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real cdf = exp(lpmf);</span></span>
<span id="cb19-23"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real ln_inc;</span></span>
<span id="cb19-24"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  while (cdf &lt; p &amp;&amp; q &lt; m) {</span></span>
<span id="cb19-25"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    q += 1;</span></span>
<span id="cb19-26"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ln_inc = (q - 1) * log(mu_phi_sqrt + q * (1 - phi_sqrt)) - (q - 2) * log(mu_phi_sqrt + (q - 1) * (1 - phi_sqrt)) + (phi_sqrt - 1) - log(q);</span></span>
<span id="cb19-27"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    lpmf += ln_inc;    </span></span>
<span id="cb19-28"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    cdf += exp(lpmf);</span></span>
<span id="cb19-29"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb19-30"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return q;</span></span>
<span id="cb19-31"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb19-32"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">int gpo_rng(real mu, real phi) {</span></span>
<span id="cb19-33"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real p = uniform_rng(0,1);</span></span>
<span id="cb19-34"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int x = gpo_quantile(p, mu, phi);</span></span>
<span id="cb19-35"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return x;</span></span>
<span id="cb19-36"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb19-37"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb19-38">generalized_Poisson <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">custom_family</span>(</span>
<span id="cb19-39">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gpo"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dpars =</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;">"mu"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>),</span>
<span id="cb19-40">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">links =</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;">"log"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>),</span>
<span id="cb19-41">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lb =</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="at" style="color: #657422;
background-color: null;
font-style: inherit;">ub =</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="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>),</span>
<span id="cb19-42">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"int"</span></span>
<span id="cb19-43">)</span>
<span id="cb19-44"></span>
<span id="cb19-45">generalized_Poisson_stanvars <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stanvar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scode =</span> stancode_gpo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">block =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"functions"</span>)</span>
<span id="cb19-46"></span>
<span id="cb19-47">phi_prior <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">prior</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exponential</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;">class =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>)</span>
<span id="cb19-48"></span>
<span id="cb19-49">GPO_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb19-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">brm</span>(</span>
<span id="cb19-51">    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;">family =</span> generalized_Poisson,</span>
<span id="cb19-52">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prior =</span> phi_prior,</span>
<span id="cb19-53">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stanvars =</span> generalized_Poisson_stanvars,</span>
<span id="cb19-54">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat, </span>
<span id="cb19-55">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warmup =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>, </span>
<span id="cb19-56">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2500</span>, </span>
<span id="cb19-57">    <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="cb19-58">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cores =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb19-59">    <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;">20231204</span></span>
<span id="cb19-60">  )</span>
<span id="cb19-61"></span>
<span id="cb19-62"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expose_functions</span>(GPO_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vectorize =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb19-63"></span>
<span id="cb19-64">log_lik_gpo <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>(i, prep) {</span>
<span id="cb19-65">  mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> brms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_dpar</span>(prep, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</span> i)</span>
<span id="cb19-66">  phi <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> brms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_dpar</span>(prep, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</span> i)</span>
<span id="cb19-67">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> prep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y[i]</span>
<span id="cb19-68">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gpo_lpmf</span>(y, mu, phi)</span>
<span id="cb19-69">}</span>
<span id="cb19-70"></span>
<span id="cb19-71">posterior_predict_gpo <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>(i, prep, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxval =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>, ...) {</span>
<span id="cb19-72">  mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> brms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_dpar</span>(prep, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</span> i)</span>
<span id="cb19-73">  phi <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> brms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_dpar</span>(prep, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</span> i)</span>
<span id="cb19-74">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gpo_rng</span>(mu, phi)</span>
<span id="cb19-75">}</span></code></pre></div></div>
</details>
</div>
</section>
<section id="model-comparison" class="level2">
<h2 class="anchored" data-anchor-id="model-comparison">Model comparison</h2>
<p>Here is a comparison of LOOIC for all of the models:</p>
<div class="cell">
<details open="" 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">loo_comparison <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">loo</span>(Poisson_fit, negbin_fit, DPO_fit, GPO_fit)</span>
<span id="cb20-2">loo_comparison<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>diffs</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>            elpd_diff se_diff
DPO_fit        0.0       0.0 
GPO_fit       -2.9       2.8 
negbin_fit    -8.9       4.4 
Poisson_fit -120.8      20.1 </code></pre>
</div>
</div>
<p>The model based on the double-Poisson distribution fits equally well to the true data-generating process here, suggesting that there’s really just not enough information to distriguish between the two models. The negative binomial distribution fit is substantially worse, and the Poisson distribution fit is awful.</p>
<p>Here’s the posterior for the dispersion (i.e., <img src="https://latex.codecogs.com/png.latex?1%20/%20%5Cphi">) based on the GPO and DPO models:</p>
<div class="cell">
<details open="" 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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>)</span>
<span id="cb22-2">GPO_dispersion <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb22-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mcmc_areas</span>(GPO_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pars =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">transformations =</span> \(x) <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> x) <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;">theme_minimal</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;">ggtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Generalized Poisson"</span>)</span>
<span id="cb22-6"></span>
<span id="cb22-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"brightblue"</span>)</span>
<span id="cb22-8">DPO_dispersion <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb22-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mcmc_areas</span>(DPO_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pars =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">transformations =</span> \(x) <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> x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb22-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb22-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggtitle</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Double Poisson"</span>)</span>
<span id="cb22-12"></span>
<span id="cb22-13">DPO_dispersion <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> GPO_dispersion <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> </span>
<span id="cb22-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.0</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/generalized-poisson-in-Stan/index_files/figure-html/dispersion-comparison-1.png" class="img-fluid figure-img" width="480"></p>
</figure>
</div>
</div>
</div>
<p>Right on par. To get a better sense of model fit, I’ll run some posterior predictive checks, using the quasi-likelihood dispersion as a summary statistic:</p>
<div class="cell">
<details open="" 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">Yrep_Poisson <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">posterior_predict</span>(Poisson_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ndraws =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>) </span>
<span id="cb23-2">Yrep_negbin <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">posterior_predict</span>(negbin_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ndraws =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>)</span>
<span id="cb23-3">Yrep_dpo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">posterior_predict</span>(DPO_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ndraws =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>)</span>
<span id="cb23-4">Yrep_gpo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">posterior_predict</span>(GPO_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ndraws =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>)</span>
<span id="cb23-5"></span>
<span id="cb23-6">dispersion_coef <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(y) {</span>
<span id="cb23-7">  quasi_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> dat<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;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasipoisson</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;">"log"</span>))</span>
<span id="cb23-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">residuals</span>(quasi_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pearson"</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> quasi_fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>df.residual</span>
<span id="cb23-9">}</span>
<span id="cb23-10"></span>
<span id="cb23-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>)</span>
<span id="cb23-12">Poisson_disp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_stat</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_Poisson, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat =</span> dispersion_coef, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb23-13">  <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;">"Poisson"</span>)</span>
<span id="cb23-14"></span>
<span id="cb23-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>)</span>
<span id="cb23-16">negbin_disp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_stat</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_negbin, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat =</span> dispersion_coef, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb23-17">  <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;">"Negative-binomial"</span>)</span>
<span id="cb23-18"></span>
<span id="cb23-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"brightblue"</span>)</span>
<span id="cb23-20">dpo_disp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_stat</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_dpo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat =</span> dispersion_coef, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb23-21">  <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;">"Double Poisson"</span>)</span>
<span id="cb23-22"></span>
<span id="cb23-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>)</span>
<span id="cb23-24">gpo_disp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_stat</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_gpo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat =</span> dispersion_coef, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb23-25">  <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;">"Generalized Poisson"</span>)</span>
<span id="cb23-26"></span>
<span id="cb23-27">Poisson_disp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> negbin_disp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> dpo_disp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> gpo_disp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span></span>
<span id="cb23-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> </span>
<span id="cb23-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">2.1</span>))</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/generalized-poisson-in-Stan/index_files/figure-html/ppc-dispersion-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>Both the double Poisson and the generalized Poisson models generate data with levels of dispersion similar to the observed data. The negative binomial distribution is not noticeably worse.</p>
</section>
<section id="marginal-posterior-predictive-densities" class="level2">
<h2 class="anchored" data-anchor-id="marginal-posterior-predictive-densities">Marginal posterior predictive densities</h2>
<p>Here’s some rootograms for the posterior predictive density of the raw outcomes:</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>)</span>
<span id="cb24-2">Poisson_root <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_rootogram</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_Poisson, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hanging"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Poisson"</span>)</span>
<span id="cb24-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>)</span>
<span id="cb24-4">negbin_root <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_rootogram</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_negbin, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hanging"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Negative-binomial"</span>)</span>
<span id="cb24-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"brightblue"</span>)</span>
<span id="cb24-6">dpo_root <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_rootogram</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_dpo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hanging"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Double Poisson"</span>)</span>
<span id="cb24-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>)</span>
<span id="cb24-8">gpo_root <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_rootogram</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_gpo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hanging"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Generalized Poisson"</span>)</span>
<span id="cb24-9"></span>
<span id="cb24-10">Poisson_root <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> negbin_root <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> dpo_root <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> gpo_root <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span></span>
<span id="cb24-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/generalized-poisson-in-Stan/index_files/figure-html/ppd-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>You can see from these that the Poisson model maybe expects slightly fewer low counts and slightly fewer high counts than are present in the observed data. However, the figure doesn’t really capture the degree of mis-fit that is apparent with the dispersion summary statistics. I think this is because the distribution of <img src="https://latex.codecogs.com/png.latex?Y"> changes so much depending on the value of the predictor <img src="https://latex.codecogs.com/png.latex?X">.</p>
</section>
<section id="posterior-predictive-residual-densities" class="level2">
<h2 class="anchored" data-anchor-id="posterior-predictive-residual-densities">Posterior predictive residual densities</h2>
<p>One way to focus in on the distributional assumption is to examine the distribution of residuals rather than raw outcomes. I’ll do that here by looking the deviance residuals from the quasi-Poisson GLM model, treating the calculation of the residuals as merely a transformation of the raw data. Here are some posterior predictive density plots of these deviance residuals:</p>
<div class="cell">
<details open="" 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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># quasi-Poisson deviance residuals</span></span>
<span id="cb25-2">dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>resid <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">residuals</span>(quasi_fit)</span>
<span id="cb25-3"></span>
<span id="cb25-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># function to calculate quasi-Poisson deviance residuals</span></span>
<span id="cb25-5">quasi_residuals <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(y) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">residuals</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> dat<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;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasipoisson</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;">"log"</span>))))</span>
<span id="cb25-6"></span>
<span id="cb25-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># transform posterior predictive data into residuals</span></span>
<span id="cb25-8">R <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span></span>
<span id="cb25-9">resid_Poisson <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(Yrep_Poisson[<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>R,], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, quasi_residuals) <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;">t</span>()</span>
<span id="cb25-10">resid_negbin <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(Yrep_negbin[<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>R,], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, quasi_residuals) <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;">t</span>()</span>
<span id="cb25-11">resid_dpo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(Yrep_dpo[<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>R,], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, quasi_residuals) <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;">t</span>()</span>
<span id="cb25-12">resid_gpo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(Yrep_gpo[<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>R,], <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, quasi_residuals) <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;">t</span>()</span>
<span id="cb25-13"></span>
<span id="cb25-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># make density plots</span></span>
<span id="cb25-15"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>)</span>
<span id="cb25-16">Poisson_resid_density <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_dens_overlay</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>resid, resid_Poisson) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Poisson"</span>)</span>
<span id="cb25-17"></span>
<span id="cb25-18"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>)</span>
<span id="cb25-19">negbin_resid_density <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_dens_overlay</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>resid, resid_negbin) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Negative-binomial"</span>)</span>
<span id="cb25-20"></span>
<span id="cb25-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"brightblue"</span>)</span>
<span id="cb25-22">dpo_resid_density <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_dens_overlay</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>resid, resid_dpo) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Double Poisson"</span>)</span>
<span id="cb25-23"></span>
<span id="cb25-24"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>)</span>
<span id="cb25-25">gpo_resid_density <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_dens_overlay</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>resid, resid_gpo) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Generalized Poisson"</span>)</span>
<span id="cb25-26"></span>
<span id="cb25-27">Poisson_resid_density <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> negbin_resid_density <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> dpo_resid_density <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> gpo_resid_density <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span></span>
<span id="cb25-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> </span>
<span id="cb25-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</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;">3.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.5</span>))</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/generalized-poisson-in-Stan/index_files/figure-html/ppd-residuals-1.png" class="img-fluid figure-img" width="576"></p>
</figure>
</div>
</div>
</div>
<p>It’s quite a bit clearer from these plots that the DPO and GPO models are closer to replicating the distribution of the data than the Poisson model. The negative binomial model is not obviously mis-specified either.</p>
<p>A notable difference between the negative binomial versus the DPO and GPO distributions is in the form of the mean-variance relationship. For the negative binomial, the variance increases with the square of the mean, whereas for the DPO and GPO, the variance increases in constant proportion to the mean. The residual posterior density plots above don’t really capture these mean-variance relationships in an obvious way. I took one more crack at a posterior predictive check to get at this. Below is a figure showing the loess smooth of the squared residuals versus <img src="https://latex.codecogs.com/png.latex?X"> based on the posterior predictive distributions versus the real data. I couldn’t find an easy way to do this with the <code>bayesplot</code> functions I’ve used above, so I had to bang it out in regular <code>ggplot</code>.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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">X_grid <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>X), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(dat<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;">length.out =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)</span>
<span id="cb26-2"></span>
<span id="cb26-3">smooth_square_resid <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>(r, x_dat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">X_pred =</span> X_grid) {</span>
<span id="cb26-4">  loess_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">loess</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">I</span>(r<span 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> x_dat)</span>
<span id="cb26-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">predict</span>(loess_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">newdata =</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_dat =</span> X_pred))</span>
<span id="cb26-6">}</span>
<span id="cb26-7"></span>
<span id="cb26-8">dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>sm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">smooth_square_resid</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">r =</span> dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>resid, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x_dat =</span> dat<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;">X_pred =</span> dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>X)</span>
<span id="cb26-9"></span>
<span id="cb26-10">smooth_square_resid_ppcs <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>(R, x_dat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">X_pred =</span> X_grid) {</span>
<span id="cb26-11">  smooth_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;">apply</span>(R, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, smooth_square_resid, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x_dat =</span> dat<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;">X_pred =</span> X_pred, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">simplify =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb26-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb26-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(smooth_list),</span>
<span id="cb26-14">    <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;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(X_pred), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(smooth_list)),</span>
<span id="cb26-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sm =</span> smooth_list</span>
<span id="cb26-16">  )</span>
<span id="cb26-17">}</span>
<span id="cb26-18"></span>
<span id="cb26-19">smooth_MV <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb26-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(</span>
<span id="cb26-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Poisson =</span> resid_Poisson, </span>
<span id="cb26-22">    <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;">Negative binomial</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> resid_negbin,</span>
<span id="cb26-23">    <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;">Double Poisson</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> resid_dpo,</span>
<span id="cb26-24">    <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;">Generalized Poisson</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> resid_gpo</span>
<span id="cb26-25">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb26-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_dfr</span>(smooth_square_resid_ppcs, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x_dat =</span> dat<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;">.id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"distribution"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb26-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(X, sm) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb26-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb26-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">distribution =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(distribution, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">levels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Poisson"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Negative binomial"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Double Poisson"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Generalized Poisson"</span>))</span>
<span id="cb26-30">  )</span>
<span id="cb26-31"></span>
<span id="cb26-32"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(smooth_MV, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(X, sm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> group, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> distribution)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb26-33">  <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;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb26-34">  <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;">data =</span> dat, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(X, sm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">group =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linewidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.25</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb26-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_manual</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"grey"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lightblue"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lightgreen"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb26-36">  <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;">limits =</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;">9</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</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;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</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="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb26-37">  <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> distribution, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb26-38">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb26-39">  <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="cb26-40">  <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;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Loess smooth of squared residuals"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/generalized-poisson-in-Stan/index_files/figure-html/ppd-residual-smooth-1.png" class="img-fluid figure-img" style="width:100.0%"></p>
</figure>
</div>
</div>
</div>
<p>Aha! Here we can clearly see that the negative binomial model generates residuals that have more curvature to the mean-variance relationship, and so don’t really fit with the observed data. The double Poisson and generalized Poisson both generate residuals that match the observed mean-variance relationship decently well.</p>
</section>
</section>
<section id="colophon" class="level1">
<h1>Colophon</h1>
<div class="cell">
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/Chicago
tzcode source: internal

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

other attached packages:
 [1] loo_2.7.0          bayesplot_1.11.1   brms_2.21.0        Rcpp_1.0.12       
 [5] rstan_2.32.6       StanHeaders_2.32.6 gamlss.dist_6.1-1  patchwork_1.2.0   
 [9] lubridate_1.9.3    forcats_1.0.0      stringr_1.5.1      dplyr_1.1.4       
[13] purrr_1.0.2        readr_2.1.5        tidyr_1.3.1        tibble_3.2.1      
[17] ggplot2_3.5.0      tidyverse_2.0.0   

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.1     farver_2.1.1         fastmap_1.1.1       
 [4] tensorA_0.36.2.1     digest_0.6.35        timechange_0.3.0    
 [7] lifecycle_1.0.4      magrittr_2.0.3       posterior_1.5.0     
[10] compiler_4.3.3       rlang_1.1.3          tools_4.3.3         
[13] utf8_1.2.4           yaml_2.3.8           knitr_1.45          
[16] labeling_0.4.3       bridgesampling_1.1-2 htmlwidgets_1.6.4   
[19] pkgbuild_1.4.4       plyr_1.8.9           BH_1.84.0-0         
[22] abind_1.4-5          withr_3.0.0          grid_4.3.3          
[25] stats4_4.3.3         fansi_1.0.6          colorspace_2.1-0    
[28] inline_0.3.19        scales_1.3.0         MASS_7.3-60.0.1     
[31] ggridges_0.5.6       cli_3.6.2            mvtnorm_1.2-4       
[34] rmarkdown_2.26       generics_0.1.3       RcppParallel_5.1.7  
[37] rstudioapi_0.16.0    reshape2_1.4.4       tzdb_0.4.0          
[40] splines_4.3.3        parallel_4.3.3       matrixStats_1.2.0   
[43] vctrs_0.6.5          Matrix_1.6-5         jsonlite_1.8.8      
[46] hms_1.1.3            glue_1.7.0           codetools_0.2-19    
[49] distributional_0.4.0 stringi_1.8.3        gtable_0.3.4        
[52] QuickJSR_1.1.3       munsell_0.5.1        pillar_1.9.0        
[55] htmltools_0.5.7      Brobdingnag_1.2-9    R6_2.5.1            
[58] RcppEigen_0.3.4.0.0  evaluate_0.23        lattice_0.22-5      
[61] backports_1.4.1      renv_1.0.5           rstantools_2.4.0    
[64] coda_0.19-4.1        gridExtra_2.3        nlme_3.1-165        
[67] checkmate_2.3.1      mgcv_1.9-1           xfun_0.42           
[70] pkgconfig_2.0.3     </code></pre>
</div>
</div>


<!-- -->

</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>Bayes</category>
  <category>simulation</category>
  <category>distribution-theory</category>
  <category>generalized linear model</category>
  <category>programming</category>
  <category>Rstats</category>
  <guid>https://jepusto.netlify.app/posts/generalized-poisson-in-Stan/</guid>
  <pubDate>Wed, 06 Dec 2023 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Implementing Efron’s double Poisson distribution in Stan</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/double-poisson-in-Stan/</link>
  <description><![CDATA[ 





<p>For a project I am working on, we are using <a href="https://mc-stan.org/">Stan</a> to fit generalized random effects location-scale models to a bunch of count data. We’re interested in using the double-Poisson distribution, as described by <a href="https://doi.org/10.2307/2289002">Efron (1986)</a>. This is an interesting distribution because it admits for both over- and under-dispersion relative to the Poisson distribution, whereas most of the conventional alternatives such as the negative binomial distribution or Poisson-normal mixture distribution allow only for over-dispersion. The double-Poisson distribution is not implemented in Stan, so we’ve had to write our own distribution function. That’s fine and not particularly difficult. What’s a bit more of a challenge is writing Stan functions to generate random samples from the double-Poisson, so that we can generate posterior predictive checks.<sup>1</sup> In this post, I’ll walk through the implementation of the custom distribution functions needed to use the double-Poisson in Stan. The <a href="https://cran.r-project.org/package=gamlss.dist"><code>gamlss.dist</code> package</a> provides a full set of distributional functions for the double-Poisson distribution, including a sampler. Thus, I can validate my Stan functions against the functions from <code>gamlss.dist</code>.<sup>2</sup></p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cdef%5CPr%7B%7B%5Ctext%7BPr%7D%7D%7D%0A%5Cdef%5CE%7B%7B%5Ctext%7BE%7D%7D%7D%0A%5Cdef%5CVar%7B%7B%5Ctext%7BVar%7D%7D%7D%0A%5Cdef%5CCov%7B%7B%5Ctext%7BCov%7D%7D%7D%0A%5Cdef%5Cbm%7B%5Cmathbf%7D%0A%5Cdef%5Cbs%7B%5Cboldsymbol%7D%0A"></p>
<div class="cell">
<details open="" 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;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(patchwork)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># composing figures</span></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(gamlss.dist) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># DPO distribution functions</span></span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rstan)       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Stan interface to R</span></span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(brms)        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fitting generalized linear models</span></span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(bayesplot)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Examine fitted models</span></span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(loo)         <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Model fit measures</span></span></code></pre></div></div>
</details>
</div>
<section id="the-double-poisson" class="level2">
<h2 class="anchored" data-anchor-id="the-double-poisson">The double-Poisson</h2>
<p>The double-Poisson distribution is a discrete distribution for non-negative counts, with support <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BS%7D_X%20=%20%5C%7B0,%201,%202,%203,%20...%5C%7D">. The mean-variance relationship of the double-Poisson is approximately constant; for <img src="https://latex.codecogs.com/png.latex?X%20%5Csim%20DPO(%5Cmu,%20%5Cphi)">, <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BE%7D(X)%20%5Capprox%20%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BVar%7D(X)%20%5Capprox%20%5Cmu%20/%20%5Cphi">, so that the double-Poisson distribution approximately satisfies the assumptions of a quasi-Poisson generalized linear model (although not quite exactly so).</p>
<p><a href="https://doi.org/10.2307/2289002">Efron (1986)</a> gives the following expression for the density of the double-Poisson distribution with mean <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and inverse-disperson <img src="https://latex.codecogs.com/png.latex?%5Cphi">: <img src="https://latex.codecogs.com/png.latex?%0Af(x%20%7C%20%5Cmu,%20%5Cphi)%20=%20%5Cfrac%7B%5Cphi%5E%7B1/2%7D%20e%5E%7B-%5Cphi%20%5Cmu%7D%7D%7Bc(%5Cmu,%5Cphi)%7D%20%5Cleft(%5Cfrac%7Be%5E%7B-x%7D%20x%5Ex%7D%7Bx!%7D%5Cright)%20%5Cleft(%5Cfrac%7Be%20%5Cmu%7D%7Bx%7D%5Cright)%5E%7B%5Cphi%20x%7D,%0A"> where <img src="https://latex.codecogs.com/png.latex?c(%5Cmu,%5Cphi)"> is a scaling constant to ensure that the density sums to one, which is closely approximated by <img src="https://latex.codecogs.com/png.latex?%0Ac(%5Cmu,%20%5Cphi)%20%5Capprox%201%20+%20%5Cfrac%7B1%20-%20%5Cphi%7D%7B12%20%5Cmu%20%5Cphi%7D%5Cleft(1%20+%20%5Cfrac%7B1%7D%7B%5Cmu%20%5Cphi%7D%5Cright).%0A"> We then have <img src="https://latex.codecogs.com/png.latex?%0A%5Cln%20f(x%20%7C%20%5Cmu,%20%5Cphi)%20=%20%5Cfrac%7B1%7D%7B2%7D%20%5Cln%20%5Cphi%20-%20%5Cphi%20%5Cmu%20-%20%5Cln%20c(%5Cmu,%20%5Cphi)%20+%20x%20(%5Cphi%20+%20%5Cphi%20%5Cln%20%5Cmu%20-%201)%20+%20(1%20-%20%5Cphi)%20x%20%5Cln(x)%20-%20%5Cln%20%5Cleft(x!%5Cright),%0A"> where <img src="https://latex.codecogs.com/png.latex?0%20%5Ctimes%20%5Cln%20(0)"> is evaluated as 0.</p>
</section>
<section id="log-of-the-probability-mass-function" class="level1">
<h1>Log of the probability mass function</h1>
<p>For purposes of using this distribution in Stan, it’s sufficient to provide the log of the probability mass function up to a constant—there’s no need to normalize it to sum to one. Thus, we can ignore the <img src="https://latex.codecogs.com/png.latex?c(%5Cmu,%20%5Cphi)"> term above. Here’s a Stan function implementing the lpmf:</p>
<div class="cell">
<details open="" 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">stancode_lpmf <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="cb2-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">real dpo_lpmf(int X, real mu, real phi) {</span></span>
<span id="cb2-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real ans;</span></span>
<span id="cb2-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real A = inv(2) * log(phi) - phi * mu;</span></span>
<span id="cb2-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  if (X == 0)</span></span>
<span id="cb2-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ans = A;</span></span>
<span id="cb2-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  else</span></span>
<span id="cb2-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ans = A + X * (phi * (1 + log(mu)) - 1) - lgamma(X + 1) + (1 - phi) * X * log(X);</span></span>
<span id="cb2-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return ans;</span></span>
<span id="cb2-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb2-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span></code></pre></div></div>
</details>
</div>
<p>To check that this is accurate, I’ll compare the Stan function to the corresponding function from <code>gamlss.dist</code> for a couple of different parameter values and for <img src="https://latex.codecogs.com/png.latex?x%20=%200,...,100">. If my function is accurate, the calculated log-probabilities should differ by a constant value for each set of parameters.</p>
<div class="cell">
<details open="" 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;">writeLines</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"functions {"</span>, stancode_lpmf, <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;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DPO-lpmf.stan"</span>)</span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expose_stan_functions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DPO-lpmf.stan"</span>)</span>
<span id="cb3-3"></span>
<span id="cb3-4">test_lpmf <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb3-6">    <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;">2</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;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>),</span>
<span id="cb3-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</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.1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>),</span>
<span id="cb3-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">X =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">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;">100</span></span>
<span id="cb3-9">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb3-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gamlss_lpmf =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dDPO</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;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> phi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">log =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb3-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">my_lpmf =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmap_dbl</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.l =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">X =</span> X, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> phi), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.f =</span> dpo_lpmf),</span>
<span id="cb3-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff =</span> my_lpmf <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> gamlss_lpmf</span>
<span id="cb3-14">  )</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" 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;">ggplot</span>(test_lpmf, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(phi), diff, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(phi))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-2">  <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="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>( <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_both"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/double-poisson-in-Stan/index_files/figure-html/unnamed-chunk-1-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Checks out. Onward!</p>
</section>
<section id="cumulative-distribution-function" class="level1">
<h1>Cumulative distribution function</h1>
<p>I’ll next implement a function to evaluate the cumulative distriution function over a range of values. This is an expensive calculation, but it can be improved a little bit by noting the relationship between sequential values of the probability mass function. Letting <img src="https://latex.codecogs.com/png.latex?d%20=%20%5Cexp%20%5Cleft(%5Cphi%20+%20%5Cphi%20%5Cln%20%5Cmu%20-%201%20%5Cright)">, observe that <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0Af(0%20%7C%20%5Cmu,%20%5Cphi)%20&amp;=%20%5Cfrac%7B%5Cphi%5E%7B1/2%7D%20e%5E%7B-%5Cphi%20%5Cmu%7D%7D%7Bc(%5Cmu,%5Cphi)%7D%20%5C%5C%0Af(1%20%7C%20%5Cmu,%20%5Cphi)%20&amp;=%20f(0%20%7C%20%5Cmu,%20%5Cphi)%20%5Ctimes%20d%20%5C%5C%0Af(x%20%7C%20%5Cmu,%20%5Cphi)%20&amp;=%20f(x%20-%201%20%7C%20%5Cmu,%20%5Cphi)%20%5Ctimes%20d%20%5Ctimes%20%5Cfrac%7B%5Cexp%5Cleft%5B(1%20-%20%5Cphi)(x%20-%201)%5Cleft(%5Cln(x)%20-%20%5Cln(x%20-%201)%5Cright)%20%5Cright%5D%7D%7Bx%5E%5Cphi%7D%0A%5Cend%7Baligned%7D%0A"> where the last expression holds for <img src="https://latex.codecogs.com/png.latex?x%20%5Cgeq%202">.</p>
<p>The function below computes the cumulative distribution function over the range <img src="https://latex.codecogs.com/png.latex?x%20=%200,...,m"> as follows:</p>
<ul>
<li>Compute <img src="https://latex.codecogs.com/png.latex?f(x%20%7C%20%5Cmu,%20%5Cphi)"> for <img src="https://latex.codecogs.com/png.latex?x%20=%200,1,2,...">, without the scaling constant <img src="https://latex.codecogs.com/png.latex?c(%5Cmu,%20%5Cphi)"></li>
<li>Take <img src="https://latex.codecogs.com/png.latex?F(0%20%7C%20%5Cmu,%20%5Cphi)%20=%20f(0%20%7C%20%5Cmu,%20%5Cphi)"> and accumulate <img src="https://latex.codecogs.com/png.latex?F(x%20%7C%20%5Cmu,%20%5Cphi)%20=%20F(x%20-%201%20%7C%20%5Cmu,%20%5Cphi)%20+%20f(x%20%7C%20%5Cmu,%20%5Cphi)"> for <img src="https://latex.codecogs.com/png.latex?x%20=%200,...,m">.</li>
<li>Check if <img src="https://latex.codecogs.com/png.latex?f(x%20%7C%20%5Cmu,%20%5Cphi)%20/%20F(x%20%7C%20%5Cmu,%20%5Cphi)"> is small (less than <img src="https://latex.codecogs.com/png.latex?10%5E%7B-8%7D">), in which case accumulation stops at the value <img src="https://latex.codecogs.com/png.latex?n">.</li>
<li>The normalized cumulative distribution function will then be <img src="https://latex.codecogs.com/png.latex?F(x%20%7C%20%5Cmu,%20%5Cphi)%20/%20F(n%20%7C%20%5Cmu,%20%5Cphi)">.</li>
</ul>
<div class="cell">
<details open="" 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">stancode_cdf <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="cb5-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">vector dpo_cdf_vec(real mu, real phi, int maxval) {</span></span>
<span id="cb5-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real d = exp(phi * (1 + log(mu)) - 1);</span></span>
<span id="cb5-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real prob;</span></span>
<span id="cb5-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int n = maxval + 1;</span></span>
<span id="cb5-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[n] cdf;</span></span>
<span id="cb5-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cdf[1] = sqrt(phi) * exp(-mu * phi);</span></span>
<span id="cb5-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  prob = cdf[1] * d;</span></span>
<span id="cb5-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cdf[2] = cdf[1] + prob;</span></span>
<span id="cb5-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  for (i in 2:maxval) {</span></span>
<span id="cb5-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    prob = prob * d * exp((1 - phi) * (i - 1) * (log(i) - log(i - 1))) / (i^phi);</span></span>
<span id="cb5-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    cdf[i + 1] = cdf[i] + prob;</span></span>
<span id="cb5-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    if (prob / cdf[i + 1] &lt; 1e-8) {</span></span>
<span id="cb5-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">      n = i + 1;</span></span>
<span id="cb5-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">      break;</span></span>
<span id="cb5-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    }</span></span>
<span id="cb5-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb5-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return cdf / cdf[n];</span></span>
<span id="cb5-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb5-20"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span></code></pre></div></div>
</details>
</div>
<p>To check that this is accurate, I’ll again compare the Stan function to the corresponding function from <code>gamlss.dist</code>. If my function is accurate, the computed cdf values should be proportional to the cdf calculated from <code>gamlss.dist::pDPO()</code> and the ratio should be very close to 1.</p>
<div class="cell">
<details open="" 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;">writeLines</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"functions {"</span>, stancode_cdf, <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;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DPO-cdf.stan"</span>)</span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expose_stan_functions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DPO-cdf.stan"</span>)</span>
<span id="cb6-3"></span>
<span id="cb6-4">test_cdf <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb6-6">    <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;">2</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;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>),</span>
<span id="cb6-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</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.1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>),</span>
<span id="cb6-8">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxval =</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> mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmin</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, phi),</span>
<span id="cb6-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">my_cdf =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmap</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.l =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> phi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxval =</span> maxval), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.f =</span> dpo_cdf_vec)</span>
<span id="cb6-12">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(my_cdf) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-14">  <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.nan</span>(my_cdf)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(mu, phi) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">row_number</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>L,</span>
<span id="cb6-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gamlss_cdf =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pDPO</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q =</span> q, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma =</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> phi),</span>
<span id="cb6-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ratio =</span> my_cdf <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> gamlss_cdf</span>
<span id="cb6-20">  )</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" 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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(test_cdf, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(phi), ratio, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(phi))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>( <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_both"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylim</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;">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;">1e-6</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e-6</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/double-poisson-in-Stan/index_files/figure-html/unnamed-chunk-2-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Still on track here (although you might wonder—would I be sharing this post if I couldn’t get the function working?).</p>
</section>
<section id="quantile-function-and-sampler" class="level1">
<h1>Quantile function and sampler</h1>
<p>The main other thing we need is a function for generating random samples from the double-Poisson. The <code>gamlss.dist</code> package has the function <code>rDPO()</code> for this purpose. It’s implemented using the standard inversion method, by calculating quantiles of the double-Poisson corresponding to a random sample from a uniform distribution. Just for funzies, I’ll implement the same approach using Stan.</p>
<p>The function below calculates quantiles by finding the minimum value of <img src="https://latex.codecogs.com/png.latex?q%20%5Cgeq%200"> such that <img src="https://latex.codecogs.com/png.latex?F(q%20+%201%20%7C%20%5Cmu,%20%5Cphi)%20%5Cgeq%20p"> for a specified probability <img src="https://latex.codecogs.com/png.latex?p%20%5Cin%20%5B0,%201%5D">. It is vectorized over <img src="https://latex.codecogs.com/png.latex?p"> and solves for <img src="https://latex.codecogs.com/png.latex?q"> by starting with the smallest <img src="https://latex.codecogs.com/png.latex?p"> and continuing through the largest value.</p>
<div class="cell">
<details open="" 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">stancode_quantile <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="cb8-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">vector dpo_cdf_vec(real mu, real phi, int maxval) {</span></span>
<span id="cb8-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real d = exp(phi * (1 + log(mu)) - 1);</span></span>
<span id="cb8-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real prob;</span></span>
<span id="cb8-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int n = maxval + 1;</span></span>
<span id="cb8-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[n] cdf;</span></span>
<span id="cb8-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cdf[1] = sqrt(phi) * exp(-mu * phi);</span></span>
<span id="cb8-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  prob = cdf[1] * d;</span></span>
<span id="cb8-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cdf[2] = cdf[1] + prob;</span></span>
<span id="cb8-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  for (i in 2:maxval) {</span></span>
<span id="cb8-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    prob = prob * d * exp((1 - phi) * (i - 1) * (log(i) - log(i - 1))) / (i^phi);</span></span>
<span id="cb8-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    cdf[i + 1] = cdf[i] + prob;</span></span>
<span id="cb8-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    if (prob / cdf[i + 1] &lt; 1e-8) {</span></span>
<span id="cb8-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">      n = i + 1;</span></span>
<span id="cb8-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">      break;</span></span>
<span id="cb8-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    }</span></span>
<span id="cb8-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb8-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return cdf / cdf[n];</span></span>
<span id="cb8-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb8-20"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">array[] int dpo_quantiles(vector p, real mu, real phi, int maxval) {</span></span>
<span id="cb8-21"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int N = rows(p);</span></span>
<span id="cb8-22"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  array[N] int qs;</span></span>
<span id="cb8-23"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  array[N] int indices = sort_indices_asc(p);</span></span>
<span id="cb8-24"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[maxval + 1] cdf_vec = dpo_cdf_vec(mu, phi, maxval);</span></span>
<span id="cb8-25"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int j = 0;</span></span>
<span id="cb8-26"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  for (i in indices) {</span></span>
<span id="cb8-27"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    while (cdf_vec[j + 1] &lt; p[i]) {</span></span>
<span id="cb8-28"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">      j += 1;</span></span>
<span id="cb8-29"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    }</span></span>
<span id="cb8-30"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    qs[i] = j;</span></span>
<span id="cb8-31"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb8-32"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return qs;</span></span>
<span id="cb8-33"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb8-34"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span></code></pre></div></div>
</details>
</div>
<p>If my quantile function is accurate, it should match the value computed from <code>gamlss.dist::qDPO()</code> exactly.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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;">writeLines</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"functions {"</span>, stancode_quantile, <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;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DPO-quantile.stan"</span>)</span>
<span id="cb9-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expose_stan_functions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DPO-quantile.stan"</span>)</span>
<span id="cb9-3"></span>
<span id="cb9-4">test_quantile <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb9-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb9-6">    <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;">2</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;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>),</span>
<span id="cb9-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</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.1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>),</span>
<span id="cb9-8">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb9-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxval =</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> mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmin</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, phi),</span>
<span id="cb9-11">    <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;">map</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;">n</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;">runif</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)),</span>
<span id="cb9-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">my_q =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmap</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.l =</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;">p =</span> p, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> phi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxval =</span> maxval), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.f =</span> dpo_quantiles),</span>
<span id="cb9-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gamlss_q =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmap</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.l =</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;">p =</span> p, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma =</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> phi), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.f =</span> qDPO)</span>
<span id="cb9-14">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(p, my_q, gamlss_q)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb9-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb9-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">diff =</span> my_q <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> gamlss_q</span>
<span id="cb9-18">  )</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" 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;">ggplot</span>(test_quantile, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(phi), diff, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(phi))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb10-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>() <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;">facet_wrap</span>( <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_both"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb10-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</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;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/double-poisson-in-Stan/index_files/figure-html/unnamed-chunk-3-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Phew, still got it!</p>
<p>The last piece of the puzzle is to write a sampler by generating random points from a uniform distribution, then computing the double-Poisson quantiles of these random points. I will implement this two ways: first with an argument for the number of random variates to generate and then, more simply, to generate a single random variate.<sup>3</sup></p>
<div class="cell">
<details open="" 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">stancode_qr <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="cb11-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">real dpo_lpmf(int X, real mu, real phi) {</span></span>
<span id="cb11-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real ans;</span></span>
<span id="cb11-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real A = inv(2) * log(phi) - phi * mu;</span></span>
<span id="cb11-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  if (X == 0)</span></span>
<span id="cb11-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ans = A;</span></span>
<span id="cb11-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  else</span></span>
<span id="cb11-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    ans = A + X * (phi * (1 + log(mu)) - 1) - lgamma(X + 1) + (1 - phi) * X * log(X);</span></span>
<span id="cb11-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return ans;</span></span>
<span id="cb11-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb11-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">vector dpo_cdf_vec(real mu, real phi, int maxval) {</span></span>
<span id="cb11-12"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real d = exp(phi * (1 + log(mu)) - 1);</span></span>
<span id="cb11-13"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real prob;</span></span>
<span id="cb11-14"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int n = maxval + 1;</span></span>
<span id="cb11-15"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[n] cdf;</span></span>
<span id="cb11-16"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cdf[1] = sqrt(phi) * exp(-mu * phi);</span></span>
<span id="cb11-17"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  prob = cdf[1] * d;</span></span>
<span id="cb11-18"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  cdf[2] = cdf[1] + prob;</span></span>
<span id="cb11-19"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  for (i in 2:maxval) {</span></span>
<span id="cb11-20"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    prob = prob * d * exp((1 - phi) * (i - 1) * (log(i) - log(i - 1))) / (i^phi);</span></span>
<span id="cb11-21"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    cdf[i + 1] = cdf[i] + prob;</span></span>
<span id="cb11-22"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    if (prob / cdf[i + 1] &lt; 1e-8) {</span></span>
<span id="cb11-23"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">      n = i + 1;</span></span>
<span id="cb11-24"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">      break;</span></span>
<span id="cb11-25"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    }</span></span>
<span id="cb11-26"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb11-27"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return cdf / cdf[n];</span></span>
<span id="cb11-28"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb11-29"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">array[] int dpo_quantiles(vector p, real mu, real phi, int maxval) {</span></span>
<span id="cb11-30"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int N = rows(p);</span></span>
<span id="cb11-31"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  array[N] int qs;</span></span>
<span id="cb11-32"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  array[N] int indices = sort_indices_asc(p);</span></span>
<span id="cb11-33"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[maxval + 1] cdf_vec = dpo_cdf_vec(mu, phi, maxval);</span></span>
<span id="cb11-34"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int j = 0;</span></span>
<span id="cb11-35"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  for (i in indices) {</span></span>
<span id="cb11-36"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    while (cdf_vec[j + 1] &lt; p[i]) {</span></span>
<span id="cb11-37"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">      j += 1;</span></span>
<span id="cb11-38"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    }</span></span>
<span id="cb11-39"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    qs[i] = j;</span></span>
<span id="cb11-40"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb11-41"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return qs;</span></span>
<span id="cb11-42"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb11-43"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">array[] int dpo_sample_rng(int n, real mu, real phi, int maxval) {</span></span>
<span id="cb11-44"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[n] p;</span></span>
<span id="cb11-45"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  for (i in 1:n) {</span></span>
<span id="cb11-46"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    p[i] = uniform_rng(0,1);</span></span>
<span id="cb11-47"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb11-48"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  array[n] int x = dpo_quantiles(p, mu, phi, maxval);</span></span>
<span id="cb11-49"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return x;</span></span>
<span id="cb11-50"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb11-51"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">int dpo_quantile(real p, real mu, real phi, int maxval) {</span></span>
<span id="cb11-52"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  vector[maxval + 1] cdf_vec = dpo_cdf_vec(mu, phi, maxval);</span></span>
<span id="cb11-53"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int q = 0;</span></span>
<span id="cb11-54"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  while (cdf_vec[q + 1] &lt; p) {</span></span>
<span id="cb11-55"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">      q += 1;</span></span>
<span id="cb11-56"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">    }</span></span>
<span id="cb11-57"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return q;</span></span>
<span id="cb11-58"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb11-59"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">int dpo_rng(real mu, real phi, int maxval) {</span></span>
<span id="cb11-60"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  real p = uniform_rng(0,1);</span></span>
<span id="cb11-61"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  int x = dpo_quantile(p, mu, phi, maxval);</span></span>
<span id="cb11-62"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  return x;</span></span>
<span id="cb11-63"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb11-64"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span></code></pre></div></div>
</details>
</div>
<p>To check this function, I’ll generate some large samples from the double-Poisson with a few different parameter sets. If the sampler is working properly, the empirical cumulative distribution should line up closely with the cumulative distribution computed using <code>gamlss.dist::pDPO()</code>.</p>
<div class="cell">
<details open="" 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;">writeLines</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"functions {"</span>, stancode_qr, <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;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DPO-rng.stan"</span>)</span>
<span id="cb12-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expose_stan_functions</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DPO-rng.stan"</span>)</span>
<span id="cb12-3"></span>
<span id="cb12-4">test_rng <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb12-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expand_grid</span>(</span>
<span id="cb12-6">    <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;">2</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;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>),</span>
<span id="cb12-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</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.1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>),</span>
<span id="cb12-8">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb12-10">    <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;">pmap</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.l =</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;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">phi =</span> phi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxval =</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;">.f =</span> dpo_sample_rng),</span>
<span id="cb12-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tb =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</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;">as.data.frame</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(.x)))</span>
<span id="cb12-12">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-13">  dplyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>x) <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;">group_by</span>(mu, phi) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(tb) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb12-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb12-17">    <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.integer</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">levels</span>(.x))[.x],</span>
<span id="cb12-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Freq_cum =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cumsum</span>(Freq) <span 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>
<span id="cb12-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">gamlss_F =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pDPO</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q =</span> .x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma =</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> phi)</span>
<span id="cb12-20">  )</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<details open="" 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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(test_rng, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(gamlss_F, Freq_cum, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(phi))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb13-2">  <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;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</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="cb13-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</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;">facet_grid</span>(phi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labeller =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label_both"</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;">theme_minimal</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;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Theoretical cdf (gamlss.dist)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Empirical cdf (my function)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb13-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>) </span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/double-poisson-in-Stan/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Looks pretty good, no?</p>
</section>
<section id="using-the-custom-distribution-functions" class="level1">
<h1>Using the custom distribution functions</h1>
<p>To finish out my tests of these functions, let me demonstrate their use in an actual estimation problem. I’ll generate data based on a simple generalized linear model with a single predictor <img src="https://latex.codecogs.com/png.latex?X">, where the outcome <img src="https://latex.codecogs.com/png.latex?Y"> follows a double-Poisson distribution conditional on <img src="https://latex.codecogs.com/png.latex?X">. The data-generating process is:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0AX%20&amp;%5Csim%20N(0,%201)%20%5C%5C%0AY%7CX%20&amp;%5Csim%20DPO(%5Cmu(X),%20%5Cphi)%20%5C%5C%0A%5Clog%20%5Cmu(X)%20&amp;=%202%20+%200.3%20%5Ctimes%20X%0A%5Cend%7Baligned%7D%0A"> To make things interesting, I’ll set the dispersion parameter to <img src="https://latex.codecogs.com/png.latex?1%20/%20%5Cphi%20=%200.6"> so that the outcome is <em>under</em>-dispersed relative to the Poisson.</p>
<p>The following code generates a large sample from the data-generating process. To keep things R-centric, I use <code>gamlss.dist::rDPO</code> to generate the outcome.</p>
<div class="cell">
<details open="" 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;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20230913</span>)</span>
<span id="cb14-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;">600</span></span>
<span id="cb14-3">X <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(N)</span>
<span id="cb14-4">mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</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.3</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> X)</span>
<span id="cb14-5">phi_inv <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.6</span></span>
<span id="cb14-6">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;">rDPO</span>(N, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sigma =</span> phi_inv)</span>
<span id="cb14-7">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(<span 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></code></pre></div></div>
</details>
</div>
<p>Here’s what the sample looks like, along with a smoothed regression estimated using a basic cubic spline:</p>
<div class="cell">
<details open="" 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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(dat, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(X, Y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb15-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb15-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;">"cs"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb15-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/double-poisson-in-Stan/index_files/figure-html/unnamed-chunk-6-1.png" class="img-fluid figure-img" width="576"></p>
</figure>
</div>
</div>
</div>
<section id="comparison-models" class="level2">
<h2 class="anchored" data-anchor-id="comparison-models">Comparison models</h2>
<p>Before using the custom distribution, I’ll fit a couple of out-of-the-box models that are useful points of comparison. Surely the simplest, quickest, and dirtiest way to estimate such a regression is with a generalized linear model, using the “quasi-Poisson” family to allow for non-unit dispersion. In R:</p>
<div class="cell">
<details open="" 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">quasi_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(Y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> X, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasipoisson</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;">"log"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat)</span>
<span id="cb16-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(quasi_fit)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
Call:
glm(formula = Y ~ X, family = quasipoisson(link = "log"), data = dat)

Coefficients:
            Estimate Std. Error t value Pr(&gt;|t|)    
(Intercept)  1.98784    0.01219  163.03   &lt;2e-16 ***
X            0.29276    0.01178   24.85   &lt;2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for quasipoisson family taken to be 0.6324771)

    Null deviance: 777.74  on 599  degrees of freedom
Residual deviance: 384.90  on 598  degrees of freedom
AIC: NA

Number of Fisher Scoring iterations: 4</code></pre>
</div>
</div>
<p>This approach recovers the data-generating parameters quite well, with a dispersion estimate of 0.632 compared to the true dispersion parameter of 0.6.</p>
<p>Now let me fit the same generalized linear model but assuming that the outcome follows a true Poisson distribution (with unit dispersion). I’ll fit the model in a Bayesian framework with the <code>brms</code> package.</p>
<div class="cell">
<details open="" 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">Poisson_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb18-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">brm</span>(</span>
<span id="cb18-3">    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;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">poisson</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;">"log"</span>),</span>
<span id="cb18-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat, </span>
<span id="cb18-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warmup =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>, </span>
<span id="cb18-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1500</span>, </span>
<span id="cb18-7">    <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="cb18-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cores =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb18-9">    <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;">20230913</span></span>
<span id="cb18-10">  )</span>
<span id="cb18-11"></span>
<span id="cb18-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(Poisson_fit)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code> Family: poisson 
  Links: mu = log 
Formula: Y ~ X 
   Data: dat (Number of observations: 600) 
  Draws: 4 chains, each with iter = 1500; warmup = 500; thin = 1;
         total post-warmup draws = 4000

Regression Coefficients:
          Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept     1.99      0.02     1.96     2.02 1.00     2865     2658
X             0.29      0.01     0.26     0.32 1.00     2552     2381

Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).</code></pre>
</div>
</div>
<p>This specification recovers the intercept and slope parameters well too, but doesn’t provide any estimate of dispersion.</p>
<p>As an alternative, I’ll also fit the model using the negative binomial distribution, which is a generalization of the Poisson that allows for over-dispersion (but not under-dispersion):</p>
<div class="cell">
<details open="" 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">negbin_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb20-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">brm</span>(</span>
<span id="cb20-3">    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;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">negbinomial</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;">"log"</span>),</span>
<span id="cb20-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat, </span>
<span id="cb20-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warmup =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>, </span>
<span id="cb20-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1500</span>, </span>
<span id="cb20-7">    <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="cb20-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cores =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb20-9">    <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;">20230913</span></span>
<span id="cb20-10">  )</span>
<span id="cb20-11"></span>
<span id="cb20-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(negbin_fit)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code> Family: negbinomial 
  Links: mu = log; shape = identity 
Formula: Y ~ X 
   Data: dat (Number of observations: 600) 
  Draws: 4 chains, each with iter = 1500; warmup = 500; thin = 1;
         total post-warmup draws = 4000

Regression Coefficients:
          Estimate Est.Error l-95% CI u-95% CI  Rhat Bulk_ESS Tail_ESS
Intercept     1.98      0.01     1.96     1.99  8.46        4        4
X             0.31      0.03     0.29     0.36 11.39        4       NA

Further Distributional Parameters:
                                                                                                                      Estimate
shape 288635341964439312984004668864260822628440088608000200668088264284802644482664682404200862480406040224646204882688664.00
                                                                                                                     Est.Error
shape 499993580246645223926226042864464406466686242028244246282864888460026284662046208044222402820440664060080422624068464.00
               l-95% CI
shape 12948941308882.21
                                                                                                                       u-95% CI
shape 1154541367857757248926006442246840288482660022402000800442022846826208466628446428606800248620604060886464806228422446.00
      Rhat Bulk_ESS Tail_ESS
shape  Inf        4       NA

Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).</code></pre>
</div>
</div>
<p>The <code>brms</code> package implements the negative binomial using the rate parameterization, so the <code>shape</code> parameter corresponds to the inverse dispersion. Thus, a large shape parameter (as in the above fit) implies dispersion that is very close to one (i.e., close to the Poisson).</p>
</section>
<section id="double-poisson-model" class="level2">
<h2 class="anchored" data-anchor-id="double-poisson-model">Double-Poisson model</h2>
<p>Now I’ll fit the same model as previously but using my custom-built double-Poisson distribution. Following <a href="https://cran.r-project.org/web/packages/brms/vignettes/brms_customfamilies.html">Paul Buerkner’s vignette</a> on using custom distributions in <code>brms</code>, I’ll first specify the custom family object for the double-Poisson:</p>
<div class="cell">
<details open="" 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">double_Poisson <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">custom_family</span>(</span>
<span id="cb22-2">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dpo"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dpars =</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;">"mu"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>),</span>
<span id="cb22-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">links =</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;">"log"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span>),</span>
<span id="cb22-4">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lb =</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="at" style="color: #657422;
background-color: null;
font-style: inherit;">ub =</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="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>),</span>
<span id="cb22-5">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"int"</span></span>
<span id="cb22-6">)</span></code></pre></div></div>
</details>
</div>
<p>I set the defaults to use a log-link for the mean (just as with the Poisson and negative binomial families) and a log-link for the inverse-dispersion. Next, I’ll create an object to add the custom stan code from above into the code created by <code>brm</code> for fitting the model:</p>
<div class="cell">
<details open="" 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">double_Poisson_stanvars <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stanvar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scode =</span> stancode_qr, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">block =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"functions"</span>)</span></code></pre></div></div>
</details>
</div>
<p>I’ll also need to specify a prior to use for the <img src="https://latex.codecogs.com/png.latex?%5Cphi"> parameter of the double-Poisson distribution:</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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">phi_prior <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">prior</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exponential</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;">class =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>)</span></code></pre></div></div>
</details>
</div>
<p>Now I’m ready to fit the model:</p>
<div class="cell">
<details open="" 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">DPO_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb25-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">brm</span>(</span>
<span id="cb25-3">    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;">family =</span> double_Poisson,</span>
<span id="cb25-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prior =</span> phi_prior,</span>
<span id="cb25-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stanvars =</span> double_Poisson_stanvars,</span>
<span id="cb25-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat, </span>
<span id="cb25-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">warmup =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">500</span>, </span>
<span id="cb25-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">iter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1500</span>, </span>
<span id="cb25-9">    <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="cb25-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cores =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,</span>
<span id="cb25-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;">20230913</span></span>
<span id="cb25-12">  )</span>
<span id="cb25-13"></span>
<span id="cb25-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summary</span>(DPO_fit)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code> Family: dpo 
  Links: mu = log; phi = identity 
Formula: Y ~ X 
   Data: dat (Number of observations: 600) 
  Draws: 4 chains, each with iter = 1500; warmup = 500; thin = 1;
         total post-warmup draws = 4000

Regression Coefficients:
          Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept     1.99      0.01     1.96     2.01 1.00     3592     2849
X             0.29      0.01     0.27     0.32 1.00     3330     3103

Further Distributional Parameters:
    Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
phi     1.55      0.09     1.38     1.72 1.00     3043     2560

Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).</code></pre>
</div>
</div>
<p>The regression coefficient estimates are basically identical to those from the Poisson and negative-binomial models, estimated with slightly better precision than with the Poisson or negative binomial families. However, we get a posterior for <img src="https://latex.codecogs.com/png.latex?%5Cphi"> that corresponds to <em>under</em>-dispersion. Here’s the posterior for the dispersion (i.e., <img src="https://latex.codecogs.com/png.latex?1%20/%20%5Cphi">):</p>
<div class="cell">
<details open="" 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;">mcmc_areas</span>(DPO_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pars =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">transformations =</span> \(x) <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> x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb27-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/double-poisson-in-Stan/index_files/figure-html/DPO-dispersion-1.png" class="img-fluid figure-img" width="480"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="model-comparison" class="level2">
<h2 class="anchored" data-anchor-id="model-comparison">Model comparison</h2>
<p>I’d like to get a sense of how much better the double-Poisson model does with capturing the real data-generating process compared to the simple Poisson model or the negative binomial model. There’s a wide range of diagnostics that can inform such comparisons. I’ll consider the leave-one-out information criteria (LOOIC) and also look at some posterior predictive checks.</p>
<p>To calculate LOOIC for the double-Poisson model, I first need to provide a <code>log_lik</code> function that <code>brms</code> can use<sup>4</sup>. Here’s code, using the Stan function from above:</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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;">expose_functions</span>(DPO_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vectorize =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb28-2">log_lik_dpo <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>(i, prep) {</span>
<span id="cb28-3">  mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> brms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_dpar</span>(prep, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</span> i)</span>
<span id="cb28-4">  phi <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> brms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_dpar</span>(prep, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</span> i)</span>
<span id="cb28-5">  y <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> prep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y[i]</span>
<span id="cb28-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dpo_lpmf</span>(y, mu, phi)</span>
<span id="cb28-7">}</span></code></pre></div></div>
</details>
</div>
<p>I can then compute LOOIC for all three models:</p>
<div class="cell">
<details open="" 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;">loo</span>(DPO_fit, Poisson_fit, negbin_fit)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Output of model 'DPO_fit':

Computed from 4000 by 600 log-likelihood matrix.

         Estimate   SE
elpd_loo  -1305.7 16.9
p_loo         2.9  0.2
looic      2611.4 33.7
------
MCSE of elpd_loo is 0.0.
MCSE and ESS estimates assume MCMC draws (r_eff in [0.7, 1.3]).

All Pareto k estimates are good (k &lt; 0.7).
See help('pareto-k-diagnostic') for details.

Output of model 'Poisson_fit':

Computed from 4000 by 600 log-likelihood matrix.

         Estimate   SE
elpd_loo  -1330.0 11.3
p_loo         1.3  0.1
looic      2660.1 22.6
------
MCSE of elpd_loo is 0.0.
MCSE and ESS estimates assume MCMC draws (r_eff in [0.5, 0.9]).

All Pareto k estimates are good (k &lt; 0.7).
See help('pareto-k-diagnostic') for details.

Output of model 'negbin_fit':

Computed from 4000 by 600 log-likelihood matrix.

         Estimate   SE
elpd_loo  -1332.9 11.6
p_loo         2.9  0.3
looic      2665.8 23.2
------
MCSE of elpd_loo is NA.
MCSE and ESS estimates assume MCMC draws (r_eff in [0.0, 0.0]).

Pareto k diagnostic values:
                         Count Pct.    Min. ESS
(-Inf, 0.7]   (good)     157   26.2%   2       
   (0.7, 1]   (bad)        0    0.0%   &lt;NA&gt;    
   (1, Inf)   (very bad) 443   73.8%   &lt;NA&gt;    
See help('pareto-k-diagnostic') for details.

Model comparisons:
            elpd_diff se_diff
DPO_fit       0.0       0.0  
Poisson_fit -24.3       6.0  
negbin_fit  -27.2       6.0  </code></pre>
</div>
</div>
<p>By these measures, the double-Poisson model has substantially better fit than either of the other models.</p>
<p>To do posterior predictive checks, I need to provide a <code>posterior_predict</code> function that <code>brms</code> can use. I’ll again do an implementation that uses my custom <code>dpo_rng()</code> from Stan.<sup>5</sup></p>
<div class="cell">
<details open="" 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">posterior_predict_dpo <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>(i, prep, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxval =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>, ...) {</span>
<span id="cb31-2">  mu <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> brms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_dpar</span>(prep, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</span> i)</span>
<span id="cb31-3">  phi <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> brms<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get_dpar</span>(prep, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"phi"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</span> i)</span>
<span id="cb31-4">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(maxval)) maxval <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;">20</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(phi, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb31-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dpo_rng</span>(mu, phi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxval =</span> maxval)</span>
<span id="cb31-6">}</span></code></pre></div></div>
</details>
</div>
<p>Functions in hand, I can now compute posterior predictions for the double-Poisson model and make pretty pictures of them, along with corresponding plots for the Poisson and negative-binomial models.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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">Yrep_Poisson <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">posterior_predict</span>(Poisson_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">draws =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">400</span>) </span>
<span id="cb32-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>)</span>
<span id="cb32-3">Poisson_root <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_rootogram</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_Poisson, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hanging"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Poisson"</span>)</span>
<span id="cb32-4"></span>
<span id="cb32-5">Yrep_negbin <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">posterior_predict</span>(negbin_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">draws =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">400</span>)</span>
<span id="cb32-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>)</span>
<span id="cb32-7">negbin_root <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_rootogram</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_negbin, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hanging"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Negative-binomial"</span>)</span>
<span id="cb32-8"></span>
<span id="cb32-9">Yrep_dpo <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">posterior_predict</span>(DPO_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">draws =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">400</span>)</span>
<span id="cb32-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>)</span>
<span id="cb32-11">dpo_root <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_rootogram</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_dpo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hanging"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Double-Poisson"</span>)</span>
<span id="cb32-12"></span>
<span id="cb32-13">dpo_root <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> Poisson_root <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> negbin_root <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span></span>
<span id="cb32-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/double-poisson-in-Stan/index_files/figure-html/ppd-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>The differences in predicted frequencies are not that obvious from these plots. The main notable difference is that the Poisson and negative-binomial distributions predict more small counts (in the range of 0 to 3) than are observed, whereas the double-Poisson does better at matching the observed frequency in this range.</p>
<p>I think the lack of glaring differences in the above plots happens because I’m just looking at the marginal distribution of the outcome, and the (explained) variation due to the predictor dampens the degree of under-dispersion. To see this, I’ll create some plots that are grouped by quintiles of <img src="https://latex.codecogs.com/png.latex?X">:</p>
<div class="cell">
<details open="" 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">dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>g <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cut</span>(dat<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;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>X, <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.2</span>)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">include.lowest =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb33-2"></span>
<span id="cb33-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>)</span>
<span id="cb33-4">Poisson_bars <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_bars_grouped</span>(</span>
<span id="cb33-5">  dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_Poisson, dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>g, </span>
<span id="cb33-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prob =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, </span>
<span id="cb33-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">facet_args =</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;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb33-8">) <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;">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;">"Poisson"</span>)</span>
<span id="cb33-10"></span>
<span id="cb33-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>)</span>
<span id="cb33-12">negbin_bars <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_bars_grouped</span>(</span>
<span id="cb33-13">  dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_negbin, dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>g, </span>
<span id="cb33-14">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prob =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, </span>
<span id="cb33-15">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">facet_args =</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;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb33-16">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb33-17">  <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;">"Negative-binomial"</span>)</span>
<span id="cb33-18"></span>
<span id="cb33-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>)</span>
<span id="cb33-20">dpo_bars <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_bars_grouped</span>(</span>
<span id="cb33-21">  dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_dpo, dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>g, </span>
<span id="cb33-22">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prob =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, </span>
<span id="cb33-23">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">facet_args =</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;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb33-24">) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb33-25">  <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;">"Double-Poisson"</span>)</span>
<span id="cb33-26"></span>
<span id="cb33-27">dpo_bars <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> Poisson_bars <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> negbin_bars <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span></span>
<span id="cb33-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>()</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/double-poisson-in-Stan/index_files/figure-html/ppd-grouped-1.png" class="img-fluid figure-img" width="1152"></p>
</figure>
</div>
</div>
</div>
<p>Still kind of subtle, I suppose, but you can see more clearly that the double-Poisson does a better job than the other distributions at matching the modes (peaks) of the empirical distribution in each of these subgroups.</p>
<p>One last approach is to look directly at the degree of dispersion in the posterior predictive distributions relative to the actual data. I’ll calculate this dispersion by re-fitting the quick-and-dirty quasi-poisson model in each sample:</p>
<div class="cell">
<details open="" 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">dispersion_coef <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(y) {</span>
<span id="cb34-2">  quasi_fit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glm</span>(y <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> dat<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;">family =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quasipoisson</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;">"log"</span>))</span>
<span id="cb34-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">residuals</span>(quasi_fit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pearson"</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> quasi_fit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>df.residual</span>
<span id="cb34-4">}</span>
<span id="cb34-5"></span>
<span id="cb34-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</span>)</span>
<span id="cb34-7">Poisson_disp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_stat</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_Poisson, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat =</span> dispersion_coef, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb34-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">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;">"Poisson"</span>)</span>
<span id="cb34-9"></span>
<span id="cb34-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>)</span>
<span id="cb34-11">negbin_disp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_stat</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_negbin, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat =</span> dispersion_coef, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb34-12">  <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;">"Negative-binomial"</span>)</span>
<span id="cb34-13"></span>
<span id="cb34-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color_scheme_set</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</span>)</span>
<span id="cb34-15">dpo_disp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ppc_stat</span>(dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>Y, Yrep_dpo, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat =</span> dispersion_coef, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">binwidth =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb34-16">  <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;">"Double-Poisson"</span>)</span>
<span id="cb34-17"></span>
<span id="cb34-18">dpo_disp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> Poisson_disp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> negbin_disp <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span></span>
<span id="cb34-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> </span>
<span id="cb34-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</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.45</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.3</span>))</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/double-poisson-in-Stan/index_files/figure-html/ppc-dispersion-1.png" class="img-fluid figure-img" width="768"></p>
</figure>
</div>
</div>
</div>
<p>From this, we can clearly see that the Poisson and negative binomial model generate data with approximately unit dispersion, which doesn’t match at all with the degree of dispersion in the observed data.</p>
</section>
</section>
<section id="kudos" class="level1">
<h1>Kudos</h1>
<p>So there you have it. It’s really quite feasible to build models with custom distributions. Efron (1986) also describes a double-binomial distribution (as an approximation to the “quasi-binomial” family of generalized linear models), which you could play with implementing for yourself, dear reader, if you are in the mood. Major kudos to <a href="https://paul-buerkner.github.io/">Paul Buerkner</a> for <a href="https://paul-buerkner.github.io/brms/"><code>brms</code></a>, <a href="https://jgabry.github.io/">Jonah Gabry</a> and collaborators for <a href="https://mc-stan.org/bayesplot/"><code>bayesplot</code></a>, and <a href="https://mc-stan.org/about/team/">the incredible team of folks</a> developing <a href="https://mc-stan.org/"><code>Stan</code></a>.</p>
</section>
<section id="colophon" class="level1">
<h1>Colophon</h1>
<div class="cell">
<div class="cell-output cell-output-stdout">
<pre><code>R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/Chicago
tzcode source: internal

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

other attached packages:
 [1] loo_2.7.0          bayesplot_1.11.1   brms_2.21.0        Rcpp_1.0.12       
 [5] rstan_2.32.6       StanHeaders_2.32.6 gamlss.dist_6.1-1  patchwork_1.2.0   
 [9] lubridate_1.9.3    forcats_1.0.0      stringr_1.5.1      dplyr_1.1.4       
[13] purrr_1.0.2        readr_2.1.5        tidyr_1.3.1        tibble_3.2.1      
[17] ggplot2_3.5.0      tidyverse_2.0.0   

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.1     farver_2.1.1         fastmap_1.1.1       
 [4] tensorA_0.36.2.1     digest_0.6.35        timechange_0.3.0    
 [7] lifecycle_1.0.4      magrittr_2.0.3       posterior_1.5.0     
[10] compiler_4.3.3       rlang_1.1.3          tools_4.3.3         
[13] utf8_1.2.4           yaml_2.3.8           knitr_1.45          
[16] labeling_0.4.3       bridgesampling_1.1-2 htmlwidgets_1.6.4   
[19] pkgbuild_1.4.4       plyr_1.8.9           BH_1.84.0-0         
[22] abind_1.4-5          withr_3.0.0          grid_4.3.3          
[25] stats4_4.3.3         fansi_1.0.6          colorspace_2.1-0    
[28] inline_0.3.19        scales_1.3.0         MASS_7.3-60.0.1     
[31] ggridges_0.5.6       cli_3.6.2            mvtnorm_1.2-4       
[34] rmarkdown_2.26       generics_0.1.3       RcppParallel_5.1.7  
[37] rstudioapi_0.16.0    reshape2_1.4.4       tzdb_0.4.0          
[40] splines_4.3.3        parallel_4.3.3       matrixStats_1.2.0   
[43] vctrs_0.6.5          Matrix_1.6-5         jsonlite_1.8.8      
[46] hms_1.1.3            glue_1.7.0           codetools_0.2-19    
[49] distributional_0.4.0 stringi_1.8.3        gtable_0.3.4        
[52] QuickJSR_1.1.3       munsell_0.5.1        pillar_1.9.0        
[55] htmltools_0.5.7      Brobdingnag_1.2-9    R6_2.5.1            
[58] RcppEigen_0.3.4.0.0  evaluate_0.23        lattice_0.22-5      
[61] backports_1.4.1      renv_1.0.5           rstantools_2.4.0    
[64] coda_0.19-4.1        gridExtra_2.3        nlme_3.1-165        
[67] checkmate_2.3.1      mgcv_1.9-1           xfun_0.42           
[70] pkgconfig_2.0.3     </code></pre>
</div>
</div>


<!-- -->

</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>To be clear up front, what I present is more complicated than really necessary because of these existing R functions to simulate values from the double-Poisson—we can just use the functions from <code>gamlss.dist</code> for purposes of posterior predictive checks (about which more below). I’m trying to work in Stan to the maximum extent possible solely as an excuse to learn more about the language, which I haven’t used much up until today.↩︎</p></li>
<li id="fn2"><p>I should also note that the <a href="http://www.bamlss.org/index.html"><code>bamlss</code> package</a> provides similar functionality and can be combined with <code>gamlss.dist</code> to accomplish basically the same thing as I’m going to do here.↩︎</p></li>
<li id="fn3"><p>The simpler version is what’s needed for generating posterior predictive checks, the fancy version is just to show off how clever I am.↩︎</p></li>
<li id="fn4"><p>Rather than exposing and calling the Stan function, one could just re-implement the log likelihood in R. (Probably the easier way in practice, but again I’m trying to learn me some Stan here…)↩︎</p></li>
<li id="fn5"><p>Of course, I could have saved a bunch of trouble by just using <code>gamlss.dist::rDPO()</code> instead.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Bayes</category>
  <category>simulation</category>
  <category>distribution-theory</category>
  <category>generalized linear model</category>
  <category>programming</category>
  <category>Rstats</category>
  <guid>https://jepusto.netlify.app/posts/double-poisson-in-Stan/</guid>
  <pubDate>Fri, 15 Sep 2023 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Cluster-Bootstrapping a meta-analytic selection model</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <dc:creator>Megha Joshi</dc:creator>
  <link>https://jepusto.netlify.app/posts/cluster-bootstrap-selection-model/</link>
  <description><![CDATA[ 





<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Important
</div>
</div>
<div class="callout-body-container callout-body">
<p>The research reported here was supported, in whole or in part, by the Institute of Education Sciences, U.S. Department of Education, through grant R305D220026 to the American Institutes for Research. The opinions expressed are those of the authors and do not represent the views of the Institute or the U.S. Department of Education.</p>
</div>
</div>
<section id="selective-reporting" class="level1">
<h1>Selective reporting</h1>
<p>Selective reporting of study results is a big concern for meta-analysts. By selective reporting, we mean the phenomenon where affirmative findings—that is, statistically significant findings in the theoretically expected direction—are more likely to be reported and more likely to be available for a systematic review compared to non-affirmative findings. Selective reporting arises due to biases in the publication process, on the part of journals, editors, and reviewers, as well as strategic decisions on part of the authors <span class="citation" data-cites="rothstein2006publication sutton2009publication">(Rothstein et al., 2006; Sutton, 2009)</span>. Research synthesists worry about selective reporting because it can distort the evidence base available for meta-analysis, almost like a fun-house mirror distorts your appearance, leading to inflation of average effect size estimates and biased estimates of heterogeneity.</p>
<p>If you read the meta-analysis methods literature, you will find scores of tools available to investigate and adjust for the biases created by selective reporting. Well known and widely used methods include:</p>
<ul>
<li>graphical representations like funnel plots and contour-enhanced funnel plots <span class="citation" data-cites="sterne2001funnel Sterne2011recommendations">(Sterne et al., 2011; Sterne &amp; Egger, 2001)</span>;</li>
<li>tests for selective reporting (or at least funnel plot asymmetry) like Egger’s regression <span class="citation" data-cites="egger1997bias">(Egger et al., 1997)</span> or Begg and Mazumdar’s rank correlation test <span class="citation" data-cites="begg1994operating">(Begg &amp; Mazumdar, 1994)</span>;</li>
<li>bias-adjustment methods like PET-PEESE <span class="citation" data-cites="stanley2008metaregression stanley2014metaregression">(Stanley, 2008; Stanley &amp; Doucouliagos, 2014)</span>, Trim-and-Fill <span class="citation" data-cites="duval2000nonparametric">(Duval &amp; Tweedie, 2000)</span>, and selection models <span class="citation" data-cites="hedges2005selection">(Hedges &amp; Vevea, 2005)</span>;</li>
<li>p-value diagnostics like p-curve <span class="citation" data-cites="simonsohn2014pcurve">(Simonsohn et al., 2014)</span>, p-uniform <span class="citation" data-cites="VanAssen2015meta vanaert2016conducting">(van Aert et al., 2016; van Assen et al., 2015)</span>, and the test of excess significance <span class="citation" data-cites="ioannidis2007exploratory">(Ioannidis &amp; Trikalinos, 2007)</span>; and</li>
<li>sensitivity analyses based on various forms of selection models <span class="citation" data-cites="vevea2005publication Copas2001sensitivity mathur2020sensitivity">(Copas &amp; Shi, 2001; Mathur &amp; VanderWeele, 2020; Vevea &amp; Woods, 2005)</span>.</li>
</ul>
<p>However, nearly all of the statistical methods here have the limitation that they are premised on observing independent effect sizes. That presents a problem for meta-analyses in education, psychology, and other social science fields, where it is very common to have meta-analyses involving <em>dependent</em> effect sizes.</p>
<p>Dependent effects occur in meta-analyses of group comparisons when primary studies report effects for multiple correlated measures of an outcome, at multiple points in time, or for multiple treatment groups compared to the same control group <span class="citation" data-cites="Becker2000multivariate">(Becker, 2000)</span>. Dependent effects are also common in meta-analyses of correlational effect sizes, where primary studies report more than one relevant correlation coefficient based on the same sample of participants. Methods such as multi-level meta-analysis <span class="citation" data-cites="VandenNoortgate2013threelevel">(Van den Noortgate et al., 2013)</span> and robust variance estimation <span class="citation" data-cites="Hedges2010robust">(Hedges et al., 2010)</span> are available to accommodate dependent effects when summarizing findings across studies or investigating moderators of effect size using meta-regression, but these techniques have yet to be extended to methods for testing or correcting bias due to selective reporting. Consequently, it’s pretty common to see research synthesis papers that use very sophisticated models for part of the analysis, but then use kludgey, awkward, or hacky approaches when it comes time to investigating selective reporting <span class="citation" data-cites="rodgers2020evaluating">(Rodgers &amp; Pustejovsky, 2020)</span>.</p>
<p>Along with <a href="https://www.air.org/mosaic">a group of our colleagues</a> from the American Institutes for Research, we are currently working on a project to develop better methods for investigating selective reporting issues in meta-analyses of dependent effect sizes. In this post, we will share an early peek under the hood at one little piece of what we’re studying, by sketching out what we think is a promising and pragmatic method for examining selective reporting while <em>also</em> accounting for effect size dependency. The method is to use a cluster-level bootstrap, which involves re-sampling clusters of observations (i.e., the set of multiple effect size estimates reported within a given primary study) to approximate the sampling distribution of an estimator <span class="citation" data-cites="boos2003introduction cameron2008bootstrap">(Boos, 2003; Cameron et al., 2008)</span>. To illustrate this technique, we will demonstrate how to bootstrap a Vevea-Hedges selection model.</p>
<p>Selection models comprise a large class of models that have two parts: a model describing the evidence-generation process and a model describing the process by which evidence is reported <span class="citation" data-cites="hedges2005selection">(Hedges &amp; Vevea, 2005)</span>. Vevea-Hedges selection models <span class="citation" data-cites="hedges1992modeling vevea1995general Hedges1996estimating">(Hedges, 1992; Hedges &amp; Vevea, 1996; Vevea &amp; Hedges, 1995)</span> involve a random effects meta-regression model for the evidence-generation process and a step function for the reporting process. With a step function, we assume that the probability that an effect size estimate is observed depends on the range in which its p-value falls. For instance, effects with <img src="https://latex.codecogs.com/png.latex?.01%20%3C%20p%20%5Cleq%20.05"> might have some probability <img src="https://latex.codecogs.com/png.latex?%5Clambda_1"> of being reported, effects with <img src="https://latex.codecogs.com/png.latex?.05%20%3C%20p%20%5Cleq%20.10"> might have some other probability <img src="https://latex.codecogs.com/png.latex?%5Clambda_2">, and effects with <img src="https://latex.codecogs.com/png.latex?.10%20%3C%20p"> might have some other probability <img src="https://latex.codecogs.com/png.latex?%5Clambda_3">.<sup>1</sup> Because the Vevea-Hedges model and other selection models separate the data-generation process into these two distinct stages, their parameters have clear interpretations and they can be used to generate bias-adjusted estimates of the distribution of effect sizes and to test for selective reporting issues. The only problem is that available implementations of selection models do not account for effect size dependency—but that’s where cluster bootstrapping could potentially help.</p>
</section>
<section id="disclaimer" class="level1">
<h1>Disclaimer</h1>
<p>To be clear, this post is based on work in progress. The cluster-bootstrap selection model that we’re going to demonstrate is an <em>experimental</em> and <em>exploratory</em> technique. We’re currently studying its properties and performance using Monte Carlo simulations, but we don’t have formal results to share yet. In the spirit of open and collaborative science, we wrote this post to demonstrate our approach to coding the method, in case others would like to experiment with the technique. Given that there are so few methods available for investigating selective reporting in meta-analyses with dependent effect sizes, we think this method is worth playing with and investigating further, and we would be happy to have others try it out as well. But, if you do so, please treat the results as tentative until we learn more about when the methods work well enough to trust the results.</p>
</section>
<section id="an-example" class="level1">
<h1>An Example</h1>
<p>For demonstrating this method, we will use data from a recent meta-analysis by Lehmann and colleagues <span class="citation" data-cites="lehmann2018metaanalysis">(2018)</span> that examined the effects of the color red on attractiveness judgments. The data is available via the <a href="https://wviechtb.github.io/metadat/reference/dat.lehmann2018.html"><code>metadat</code></a> package <span class="citation" data-cites="metadat">(White et al., 2022)</span>. The dataset includes 81 effect sizes from 41 unique studies. You can browse the data for yourself here:</p>
<div class="cell">
<details open="" 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;">library</span>(metadat)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for the example dataset</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for tidying</span></span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(janitor)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for tidying variable names</span></span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(metafor)   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for meta-analysis</span></span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(boot)      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for bootstrapping</span></span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tictoc)    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for keeping time</span></span>
<span id="cb1-7"></span>
<span id="cb1-8">lehmann_dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb1-9">  dat.lehmann2018 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clean_names</span>() <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;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">study =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_split_fixed</span>(short_title, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pattern =</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;">n =</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;">1</span>]) <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;">arrange</span>(study) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb1-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(study, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">presentation =</span> stimuli_presentation, yi, vi, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">everything</span>())</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<div class="cell-output-display">
<div style="border: 1px solid #ddd; padding: 0px; overflow-y: scroll; height:300px; overflow-x: scroll; width:100%; ">
<table class="table table-striped table-hover caption-top table-sm small">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">study</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">presentation</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">yi</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">vi</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">short_title</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">full_citation</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">year</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">pr_publication</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">source_type</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">preregistered</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">moderator_group</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">context</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">gender</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">color_contrast</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">color_form</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">photo_type</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">photo_similarity</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">dv_type</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">dv_items</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">dv_scale</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">dv_scale_bottom</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">dv_scale_top</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">location</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">continent</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">participants</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">participant_notes</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">design</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">eth_majority</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">eth_majority_detail</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">eth_stim</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">eth_match</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">red_age</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">control_age</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">color_red</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">color_control</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">red_original</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">color_match</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">presentation_control</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">red_n</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">red_m</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">red_sd</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">control_n</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">control_m</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">control_sd</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">sd_diff</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">rm_r</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">control_attractiveness</th>
<th data-quarto-table-cell-role="th" style="text-align: left; position: sticky; top: 0; background-color: #FFFFFF;">notes</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">total_sample_size</th>
<th data-quarto-table-cell-role="th" style="text-align: right; position: sticky; top: 0; background-color: #FFFFFF;">pooled</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Banas, 2014</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.06</td>
<td style="text-align: right;">0.10</td>
<td style="text-align: left;">Banas, 2014 - Exp 1</td>
<td style="text-align: left;">Banas, K. (2014, July 7). Replication of Elliot et al. (2010) for CREP at the University of Edinburgh. Retrieved from osf.io/cvdpw</td>
<td style="text-align: right;">2014.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">CREP</td>
<td style="text-align: left;">Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Scotland</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">20.43</td>
<td style="text-align: right;">20.95</td>
<td style="text-align: left;">LCh(50.0, 59.6, 31.3)</td>
<td style="text-align: left;">LCh(50.0, -, 69.1)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">20</td>
<td style="text-align: right;">6.05</td>
<td style="text-align: right;">1.59</td>
<td style="text-align: right;">19</td>
<td style="text-align: right;">5.96</td>
<td style="text-align: right;">1.49</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.62</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">39</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Berthold, 2013</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.55</td>
<td style="text-align: right;">0.06</td>
<td style="text-align: left;">Berthold, 2013 - Exp 1 - In Group</td>
<td style="text-align: left;">Berthold, A. (2013). Unpublished data</td>
<td style="text-align: right;">2013.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">4</td>
<td style="text-align: left;">1-7</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">7</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">25.00</td>
<td style="text-align: right;">25.00</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">36</td>
<td style="text-align: right;">2.31</td>
<td style="text-align: right;">1.29</td>
<td style="text-align: right;">33</td>
<td style="text-align: right;">1.73</td>
<td style="text-align: right;">0.65</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.12</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">69</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Bigelow et al., 2013</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.31</td>
<td style="text-align: right;">0.30</td>
<td style="text-align: left;">Bigelow et al., 2013 - Exp 1</td>
<td style="text-align: left;">Bigelow, M.G., Taylor, G. &amp; Underwood, M. (2013). Context-moderated effect of color on physiological and self-report measures of emotional response. UNC Asheville Journal, Undergraduate Research Program, Asheville, NC</td>
<td style="text-align: right;">2013.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Head Shot</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Single item</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">Lab(37.43/59.24/47.63)</td>
<td style="text-align: left;">Lab(36.68/34.86/87.99)</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">5.22</td>
<td style="text-align: right;">1.77</td>
<td style="text-align: right;">8</td>
<td style="text-align: right;">4.56</td>
<td style="text-align: right;">2.09</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.44</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">14</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Bigelow et al., 2013</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.73</td>
<td style="text-align: right;">0.53</td>
<td style="text-align: left;">Bigelow et al., 2013 - Exp 1</td>
<td style="text-align: left;">Bigelow, M.G., Taylor, G. &amp; Underwood, M. (2013). Context-moderated effect of color on physiological and self-report measures of emotional response. UNC Asheville Journal, Undergraduate Research Program, Asheville, NC</td>
<td style="text-align: right;">2013.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Head Shot</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Single item</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">Lab(37.43/59.24/47.63)</td>
<td style="text-align: left;">Lab(36.68/34.86/87.99)</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">4.65</td>
<td style="text-align: right;">2.05</td>
<td style="text-align: right;">4</td>
<td style="text-align: right;">6.28</td>
<td style="text-align: right;">1.81</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.66</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">8</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Blech, 2014</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.08</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: left;">Blech, 2014 - Exp 1</td>
<td style="text-align: left;">Blech, C. (2014, August 4). Replication of Elliot et al. (2010). Red, rank, and romance in women viewing men. Retrieved from osf.io/tx2u5</td>
<td style="text-align: right;">2014.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Head Shot</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness, German translation</td>
<td style="text-align: right;">4</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">71</td>
<td style="text-align: right;">5.36</td>
<td style="text-align: right;">1.43</td>
<td style="text-align: right;">78</td>
<td style="text-align: right;">5.25</td>
<td style="text-align: right;">1.48</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.53</td>
<td style="text-align: left;">Not part of CREP because Used white as control condition, dropped yellow as not an original control color, age not included because separated into categories (&lt;25, 26-40, &gt;=41)</td>
<td style="text-align: right;">149</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Blech, 2015</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.35</td>
<td style="text-align: right;">0.05</td>
<td style="text-align: left;">Blech, 2015 - Class Exp</td>
<td style="text-align: left;">Blech, C. (2015). Unpublished data from a class experiment</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">4</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Adults</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">31.40</td>
<td style="text-align: right;">31.40</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">37</td>
<td style="text-align: right;">3.95</td>
<td style="text-align: right;">1.29</td>
<td style="text-align: right;">37</td>
<td style="text-align: right;">4.45</td>
<td style="text-align: right;">1.50</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.43</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">74</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Boelk &amp; Madden, 2014</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">-0.27</td>
<td style="text-align: right;">0.06</td>
<td style="text-align: left;">Boelk &amp; Madden, 2014 - Exp 1</td>
<td style="text-align: left;">Boelk, K., &amp; Madden, W. (2014, August 5). Fork of Elliot, A. J., Niesta Kayser, D., Greitemeyer, T., Lichtenfeld, S., Gramzow, R. H., Maier, M. A., &amp; Liu, H. (2010). Retrieved from osf.io/zf7c9</td>
<td style="text-align: right;">2014.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">CREP</td>
<td style="text-align: left;">Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">19.06</td>
<td style="text-align: right;">19.35</td>
<td style="text-align: left;">LCh(50.0, 59.6, 31.3)</td>
<td style="text-align: left;">LCh(50.0, -, 69.1)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">34</td>
<td style="text-align: right;">6.03</td>
<td style="text-align: right;">1.24</td>
<td style="text-align: right;">34</td>
<td style="text-align: right;">6.40</td>
<td style="text-align: right;">1.49</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.68</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">68</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Buechner et al., 2015</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.68</td>
<td style="text-align: right;">0.09</td>
<td style="text-align: left;">Buechner et al., 2015 - Exp 1 - Prideful Pose</td>
<td style="text-align: left;">Buechner, V. L., Maier, M. A., Lichtenfeld, S., &amp; Elliot, A. J. (2015). Emotion Expression and Color: Their Joint Influence on Perceived Attractiveness and Social Position. Current Psychology, 34(2), 422-433. http://doi.org/10.1007/s12144-014-9266-x</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Dot</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">High School</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">16.88</td>
<td style="text-align: right;">16.88</td>
<td style="text-align: left;">LCh(50.9, 59.7, 25.7)</td>
<td style="text-align: left;">LCh(49.2, 60.2, 278.2)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">21</td>
<td style="text-align: right;">4.30</td>
<td style="text-align: right;">1.65</td>
<td style="text-align: right;">29</td>
<td style="text-align: right;">3.21</td>
<td style="text-align: right;">1.53</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.28</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">50</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Costello et al., 2017</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">-0.12</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: left;">Costello et al., 2017 - Exp 1</td>
<td style="text-align: left;">Costello J., Groeneboom L. &amp; Pollet T. (2017). Romantic red: Do red products enhance the attractiveness of the consumer? Unpublished masters degree manuscript, University of Leiden</td>
<td style="text-align: right;">2017.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Item</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Single item perceived attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-5</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">5</td>
<td style="text-align: left;">Netherlands</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrad</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Asian</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">22.60</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">65</td>
<td style="text-align: right;">2.25</td>
<td style="text-align: right;">1.04</td>
<td style="text-align: right;">64</td>
<td style="text-align: right;">2.38</td>
<td style="text-align: right;">0.95</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.34</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">129</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Costello et al., 2017</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.08</td>
<td style="text-align: right;">0.02</td>
<td style="text-align: left;">Costello et al., 2017 - Exp 2</td>
<td style="text-align: left;">Costello J., Groeneboom L. &amp; Pollet T. (2017). Romantic red: Do red products enhance the attractiveness of the consumer? Unpublished masters degree manuscript, University of Leiden</td>
<td style="text-align: right;">2017.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Blue/Green</td>
<td style="text-align: left;">Item</td>
<td style="text-align: left;">Head Shot</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Single item perceived attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-5</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">5</td>
<td style="text-align: left;">Netherlands</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrad</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">21.32</td>
<td style="text-align: right;">21.06</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">67</td>
<td style="text-align: right;">2.60</td>
<td style="text-align: right;">1.37</td>
<td style="text-align: right;">140</td>
<td style="text-align: right;">2.49</td>
<td style="text-align: right;">1.38</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.37</td>
<td style="text-align: left;">Same filters applied as in Exp 1 (excluded homosexual and preferred not to answer). Control combines blue and green</td>
<td style="text-align: right;">207</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Elliot &amp; Maier, 2013</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.25</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: left;">Elliot &amp; Maier, 2013 - Exp 1</td>
<td style="text-align: left;">Elliot, A. J., &amp; Maier, M. a. (2013). The red-attractiveness effect, applying the Ioannidis and Trikalinos (2007b) test, and the broader scientific context: a reply to Francis (2013). Journal of Experimental Psychology. General, 142(1), 297-300. http://doi.org/10.1037/a0029592</td>
<td style="text-align: right;">2013.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">19.47</td>
<td style="text-align: right;">19.47</td>
<td style="text-align: left;">LCh(42.6, 45.2, 15.8)</td>
<td style="text-align: left;">LCh(43.0, -, 296.7)</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">75</td>
<td style="text-align: right;">6.29</td>
<td style="text-align: right;">1.35</td>
<td style="text-align: right;">69</td>
<td style="text-align: right;">5.93</td>
<td style="text-align: right;">1.49</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.62</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">144</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Elliot &amp; Niesta, 2008</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.62</td>
<td style="text-align: right;">0.14</td>
<td style="text-align: left;">Elliot &amp; Niesta, 2008 - Exp 4</td>
<td style="text-align: left;">Elliot, A. J., &amp; Niesta, D. (2008). Romantic red: red enhances men's attraction to women. Journal of Personality and Social Psychology, 95(5), 1150-1164. http://doi.org/10.1037/0022-3514.95.5.1150</td>
<td style="text-align: right;">2008.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Green</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">19.97</td>
<td style="text-align: right;">19.97</td>
<td style="text-align: left;">LCh(46.1, 51.2, 29.3)</td>
<td style="text-align: left;">LCh(46.1, 51.0, 147.6)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">16</td>
<td style="text-align: right;">6.29</td>
<td style="text-align: right;">0.89</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">5.66</td>
<td style="text-align: right;">1.09</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.58</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">31</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Elliot &amp; Niesta, 2008</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.67</td>
<td style="text-align: right;">0.11</td>
<td style="text-align: left;">Elliot &amp; Niesta, 2008 - Exp 3</td>
<td style="text-align: left;">Elliot, A. J., &amp; Niesta, D. (2008). Romantic red: red enhances men's attraction to women. Journal of Personality and Social Psychology, 95(5), 1150-1164. http://doi.org/10.1037/0022-3514.95.5.1150</td>
<td style="text-align: right;">2008.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">20.00</td>
<td style="text-align: right;">20.00</td>
<td style="text-align: left;">LCh(50.0, 58.7, 30.3)</td>
<td style="text-align: left;">LCh(50.0, -, 52.6)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">20</td>
<td style="text-align: right;">6.65</td>
<td style="text-align: right;">1.10</td>
<td style="text-align: right;">17</td>
<td style="text-align: right;">5.91</td>
<td style="text-align: right;">1.07</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.61</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">37</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Elliot &amp; Niesta, 2008</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.84</td>
<td style="text-align: right;">0.19</td>
<td style="text-align: left;">Elliot &amp; Niesta, 2008 - Exp 5</td>
<td style="text-align: left;">Elliot, A. J., &amp; Niesta, D. (2008). Romantic red: red enhances men's attraction to women. Journal of Personality and Social Psychology, 95(5), 1150-1164. http://doi.org/10.1037/0022-3514.95.5.1150</td>
<td style="text-align: right;">2008.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">19.77</td>
<td style="text-align: right;">19.77</td>
<td style="text-align: left;">LCh(45.9, 54.8, 32.5)</td>
<td style="text-align: left;">LCh(46.0, 54.9, 283.0)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">12</td>
<td style="text-align: right;">7.21</td>
<td style="text-align: right;">1.05</td>
<td style="text-align: right;">11</td>
<td style="text-align: right;">6.09</td>
<td style="text-align: right;">1.49</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.64</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">23</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Elliot &amp; Niesta, 2008</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.75</td>
<td style="text-align: right;">0.13</td>
<td style="text-align: left;">Elliot &amp; Niesta, 2008 - Exp 2</td>
<td style="text-align: left;">Elliot, A. J., &amp; Niesta, D. (2008). Romantic red: red enhances men's attraction to women. Journal of Personality and Social Psychology, 95(5), 1150-1164. http://doi.org/10.1037/0022-3514.95.5.1150</td>
<td style="text-align: right;">2008.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">19.27</td>
<td style="text-align: right;">19.27</td>
<td style="text-align: left;">LCh(55.5, 78.0, 28.0)</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">16</td>
<td style="text-align: right;">7.07</td>
<td style="text-align: right;">0.78</td>
<td style="text-align: right;">16</td>
<td style="text-align: right;">6.13</td>
<td style="text-align: right;">1.53</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.64</td>
<td style="text-align: left;">Age includes both male and female participants.</td>
<td style="text-align: right;">32</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Elliot &amp; Niesta, 2008</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">1.08</td>
<td style="text-align: right;">0.17</td>
<td style="text-align: left;">Elliot &amp; Niesta, 2008 - Exp 1</td>
<td style="text-align: left;">Elliot, A. J., &amp; Niesta, D. (2008). Romantic red: red enhances men's attraction to women. Journal of Personality and Social Psychology, 95(5), 1150-1164. http://doi.org/10.1037/0022-3514.95.5.1150</td>
<td style="text-align: right;">2008.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">20.52</td>
<td style="text-align: right;">20.52</td>
<td style="text-align: left;">LCh(50.3, 58.8, 29.9)</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">7.33</td>
<td style="text-align: right;">0.90</td>
<td style="text-align: right;">12</td>
<td style="text-align: right;">6.25</td>
<td style="text-align: right;">1.05</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.66</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">27</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Elliot et al., 2010</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.82</td>
<td style="text-align: right;">0.13</td>
<td style="text-align: left;">Elliot et al., 2010 - Exp 3</td>
<td style="text-align: left;">Elliot, A. J., Niesta Kayser, D., Greitemeyer, T., Lichtenfeld, S., Gramzow, R. H., Maier, M. A., &amp; Liu, H. (2010). Red, rank, and romance in women viewing men. Journal of Experimental Psychology: General, 139(3), 399-417. http://doi.org/10.1037/a0019689</td>
<td style="text-align: right;">2010.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">19.64</td>
<td style="text-align: right;">19.64</td>
<td style="text-align: left;">LCh(50.0, 59.6, 31.3)</td>
<td style="text-align: left;">LCh(50.0, -, 69.1)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">16</td>
<td style="text-align: right;">6.69</td>
<td style="text-align: right;">1.22</td>
<td style="text-align: right;">17</td>
<td style="text-align: right;">5.27</td>
<td style="text-align: right;">2.04</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.53</td>
<td style="text-align: left;">df doesn't match sample size</td>
<td style="text-align: right;">33</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Elliot et al., 2010</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.61</td>
<td style="text-align: right;">0.08</td>
<td style="text-align: left;">Elliot et al., 2010 - Exp 4</td>
<td style="text-align: left;">Elliot, A. J., Niesta Kayser, D., Greitemeyer, T., Lichtenfeld, S., Gramzow, R. H., Maier, M. A., &amp; Liu, H. (2010). Red, rank, and romance in women viewing men. Journal of Experimental Psychology: General, 139(3), 399-417. http://doi.org/10.1037/a0019689</td>
<td style="text-align: right;">2010.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Green</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Mehrabian &amp; Blum's Perceived attractiveness</td>
<td style="text-align: right;">4</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">China</td>
<td style="text-align: left;">Asia</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">Chinese</td>
<td style="text-align: left;">Chinese</td>
<td style="text-align: left;">Chinese</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">20.60</td>
<td style="text-align: right;">20.60</td>
<td style="text-align: left;">LCh(51.3, 51.7, 30.1)</td>
<td style="text-align: left;">LCh(51.5, 51.6, 136.6)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">27</td>
<td style="text-align: right;">6.32</td>
<td style="text-align: right;">1.09</td>
<td style="text-align: right;">28</td>
<td style="text-align: right;">5.50</td>
<td style="text-align: right;">1.50</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.56</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">55</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Elliot et al., 2010</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.90</td>
<td style="text-align: right;">0.21</td>
<td style="text-align: left;">Elliot et al., 2010 - Exp 1</td>
<td style="text-align: left;">Elliot, A. J., Niesta Kayser, D., Greitemeyer, T., Lichtenfeld, S., Gramzow, R. H., Maier, M. A., &amp; Liu, H. (2010). Red, rank, and romance in women viewing men. Journal of Experimental Psychology: General, 139(3), 399-417. http://doi.org/10.1037/a0019689</td>
<td style="text-align: right;">2010.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">20.19</td>
<td style="text-align: right;">20.19</td>
<td style="text-align: left;">LCh(49.6, 58.8, 30.4)</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">10</td>
<td style="text-align: right;">6.79</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">11</td>
<td style="text-align: right;">5.67</td>
<td style="text-align: right;">1.34</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.58</td>
<td style="text-align: left;">df doesn't match sample size</td>
<td style="text-align: right;">21</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Elliot et al., 2010</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.82</td>
<td style="text-align: right;">0.16</td>
<td style="text-align: left;">Elliot et al., 2010 - Exp 7</td>
<td style="text-align: left;">Elliot, A. J., Niesta Kayser, D., Greitemeyer, T., Lichtenfeld, S., Gramzow, R. H., Maier, M. A., &amp; Liu, H. (2010). Red, rank, and romance in women viewing men. Journal of Experimental Psychology: General, 139(3), 399-417. http://doi.org/10.1037/a0019689</td>
<td style="text-align: right;">2010.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Maner et al perceived attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">England</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">19.44</td>
<td style="text-align: right;">19.44</td>
<td style="text-align: left;">LCh(54.8, 43.2, 30.3)</td>
<td style="text-align: left;">LCh(55.1, 43.7, 283.0)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">12</td>
<td style="text-align: right;">7.50</td>
<td style="text-align: right;">1.17</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">6.13</td>
<td style="text-align: right;">1.89</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.64</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">27</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Elliot et al., 2010</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">1.05</td>
<td style="text-align: right;">0.15</td>
<td style="text-align: left;">Elliot et al., 2010 - Exp 2</td>
<td style="text-align: left;">Elliot, A. J., Niesta Kayser, D., Greitemeyer, T., Lichtenfeld, S., Gramzow, R. H., Maier, M. A., &amp; Liu, H. (2010). Red, rank, and romance in women viewing men. Journal of Experimental Psychology: General, 139(3), 399-417. http://doi.org/10.1037/a0019689</td>
<td style="text-align: right;">2010.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">20.46</td>
<td style="text-align: right;">20.46</td>
<td style="text-align: left;">LCh(49.6, 58.8, 30.4)</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">20</td>
<td style="text-align: right;">7.15</td>
<td style="text-align: right;">0.74</td>
<td style="text-align: right;">12</td>
<td style="text-align: right;">6.20</td>
<td style="text-align: right;">1.08</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.65</td>
<td style="text-align: left;">Sample size taken from Francis, t(df) seems to be using ANOVA df for post-hoc, age data for both male and female participants (separate was not provided)</td>
<td style="text-align: right;">32</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Elliot et al., 2013</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.64</td>
<td style="text-align: right;">0.10</td>
<td style="text-align: left;">Elliot et al., 2013 - Exp 1</td>
<td style="text-align: left;">Elliot, A. J., Tracy, J. L., Pazda, A. D., &amp; Beall, A. T. (2013). Red enhances women's attractiveness to men: First evidence suggesting universality. Journal of Experimental Social Psychology, 49(1), 165-168. http://doi.org/10.1016/j.jesp.2012.07.017</td>
<td style="text-align: right;">2013.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Head Shot</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-5</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">5</td>
<td style="text-align: left;">Burkina Faso</td>
<td style="text-align: left;">Africa</td>
<td style="text-align: left;">Adults</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">Black</td>
<td style="text-align: left;">Black</td>
<td style="text-align: left;">Black</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">26.80</td>
<td style="text-align: right;">26.80</td>
<td style="text-align: left;">LCh(42.7, 51.5, 20.4)</td>
<td style="text-align: left;">LCh(43.4, 51.5, 269.8)</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">21</td>
<td style="text-align: right;">4.62</td>
<td style="text-align: right;">0.59</td>
<td style="text-align: right;">21</td>
<td style="text-align: right;">4.14</td>
<td style="text-align: right;">0.85</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.78</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">42</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Frazier, 2014</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.09</td>
<td style="text-align: right;">0.06</td>
<td style="text-align: left;">Frazier, 2014 - Exp 1</td>
<td style="text-align: left;">Frazier, A. (2014, November 13). Fork of Elliot, A. J., Niesta Kayser, D., Greitemeyer, T., Lichtenfeld, S., Gramzow, R. H., Maier, M. A., &amp; Liu, H. (2010). Retrieved from osf.io/u0mig</td>
<td style="text-align: right;">2014.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">CREP</td>
<td style="text-align: left;">Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">18.90</td>
<td style="text-align: right;">18.90</td>
<td style="text-align: left;">LCh(50.0, 59.6, 31.3)</td>
<td style="text-align: left;">LCh(50.0, -, 69.1)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">29</td>
<td style="text-align: right;">6.09</td>
<td style="text-align: right;">1.39</td>
<td style="text-align: right;">39</td>
<td style="text-align: right;">5.97</td>
<td style="text-align: right;">1.26</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.62</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">68</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Gilston &amp; Privitera, 2016</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">1.92</td>
<td style="text-align: right;">0.04</td>
<td style="text-align: left;">Gilston &amp; Privitera, 2016 - Exp 1 - Healthy</td>
<td style="text-align: left;">Gilston, A., &amp; Privitera, G. J. (2015). A 'Healthy' Color: Information About Healthy Eating Attenuates the 'Red Effect.' Global Journal of Health Science, 8(1), 56-61. https://doi.org/10.5539/gjhs.v8n1p56</td>
<td style="text-align: right;">2016.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Head Shot</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-7</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">7</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrad</td>
<td style="text-align: left;">Within Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">19.85</td>
<td style="text-align: right;">19.85</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">54</td>
<td style="text-align: right;">5.65</td>
<td style="text-align: right;">1.51</td>
<td style="text-align: right;">54</td>
<td style="text-align: right;">3.09</td>
<td style="text-align: right;">1.09</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.89</td>
<td style="text-align: right;">0.35</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">54</td>
<td style="text-align: right;">1.32</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Gueguen, 2012</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.74</td>
<td style="text-align: right;">0.05</td>
<td style="text-align: left;">Gueguen, 2012 - Exp 1</td>
<td style="text-align: left;">Gueguen, N. (2012). Color and Women Attractiveness: When Red Clothed Women Are Perceived to Have More Intense Sexual Intent. The Journal of Social Psychology, 152(3), 261-265. http://doi.org/10.1080/00224545.2011.605398</td>
<td style="text-align: right;">2012.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue/Green/White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">France</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">19.20</td>
<td style="text-align: right;">19.20</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">5.95</td>
<td style="text-align: right;">1.24</td>
<td style="text-align: right;">90</td>
<td style="text-align: right;">5.04</td>
<td style="text-align: right;">1.22</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.50</td>
<td style="text-align: left;">Control is average of blue, white, and green</td>
<td style="text-align: right;">120</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Hesslinger et al. 2015</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.46</td>
<td style="text-align: right;">0.13</td>
<td style="text-align: left;">Hesslinger et al. 2015 - Exp 2</td>
<td style="text-align: left;">Hesslinger, V. M., Goldbach, L., Carbon, C.-C., Allgemeine, A., Psychologie, E., &amp; Note, A. (2015). Men in red: A reexamination of the red-attractiveness effect. Psychonomic Bulletin &amp; Review, 55(4), 1-6. http://doi.org/10.3758/s13423-015-0866-8</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Full Body</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness, German translation</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">20.20</td>
<td style="text-align: right;">20.20</td>
<td style="text-align: left;">CIE-Lab(50, 51, 30)</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">16</td>
<td style="text-align: right;">4.98</td>
<td style="text-align: right;">0.70</td>
<td style="text-align: right;">16</td>
<td style="text-align: right;">4.63</td>
<td style="text-align: right;">0.79</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.45</td>
<td style="text-align: left;">Age includes both male and female participants.</td>
<td style="text-align: right;">32</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Hesslinger et al. 2015</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.06</td>
<td style="text-align: right;">0.06</td>
<td style="text-align: left;">Hesslinger et al. 2015 - Exp 1</td>
<td style="text-align: left;">Hesslinger, V. M., Goldbach, L., Carbon, C.-C., Allgemeine, A., Psychologie, E., &amp; Note, A. (2015). Men in red: A reexamination of the red-attractiveness effect. Psychonomic Bulletin &amp; Review, 55(4), 1-6. http://doi.org/10.3758/s13423-015-0866-8</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness, German translation</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">21.20</td>
<td style="text-align: right;">22.60</td>
<td style="text-align: left;">CIE-Lab(50, 51, 30)</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">35</td>
<td style="text-align: right;">5.71</td>
<td style="text-align: right;">1.65</td>
<td style="text-align: right;">37</td>
<td style="text-align: right;">5.62</td>
<td style="text-align: right;">1.44</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.58</td>
<td style="text-align: left;">Age includes both male and female participants.</td>
<td style="text-align: right;">72</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Johnson et al., 2015</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">-0.01</td>
<td style="text-align: right;">0.05</td>
<td style="text-align: left;">Johnson et al., 2015 - Exp 1</td>
<td style="text-align: left;">Johnson, K., Meltzer, A., &amp; Grahe, J. E. (2015, October 12). Fork of Elliot, A. J., Niesta Kayser, D., Greitemeyer, T., Lichtenfeld, S., Gramzow, R. H., Maier, M. A., &amp; Liu, H. (2010). Retrieved from osf.io/ictud</td>
<td style="text-align: right;">2014.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">CREP</td>
<td style="text-align: left;">Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">18.94</td>
<td style="text-align: right;">18.92</td>
<td style="text-align: left;">LCh(50.0, 59.6, 31.3)</td>
<td style="text-align: left;">LCh(50.0, -, 69.1)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">35</td>
<td style="text-align: right;">5.97</td>
<td style="text-align: right;">1.60</td>
<td style="text-align: right;">38</td>
<td style="text-align: right;">5.99</td>
<td style="text-align: right;">1.34</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.62</td>
<td style="text-align: left;">Yellow group also run, but not included</td>
<td style="text-align: right;">73</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Khislavsky, 2016</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.06</td>
<td style="text-align: right;">0.02</td>
<td style="text-align: left;">Khislavsky, 2016 - Exp 1</td>
<td style="text-align: left;">Khislavsky, A. (2016, March 14). Replication of Elliot et al. (2010). Red, rank, and romance in women viewing men. Retrieved from osf.io/f2udj</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">19.91</td>
<td style="text-align: right;">20.04</td>
<td style="text-align: left;">~LCh(50.0, 59.6, 31.3)</td>
<td style="text-align: left;">~LCh(50.0, -, 69.1)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">95</td>
<td style="text-align: right;">5.73</td>
<td style="text-align: right;">1.76</td>
<td style="text-align: right;">92</td>
<td style="text-align: right;">5.61</td>
<td style="text-align: right;">1.84</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.58</td>
<td style="text-align: left;">Not reviewed by CREP</td>
<td style="text-align: right;">187</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Kirsch, 2015</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.47</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: left;">Kirsch, 2015 - Exp 1 - Heterosexual</td>
<td style="text-align: left;">Kirsch, F. (2015). Wahrgenommene Attraktivitaet und sexuelle Orientierung: Die Wirkung von Rot und Farbpraeferenzen (Perceived attractiveness and sexual orientation: The effects of red and color preferences). Wiesbaden: Springer. doi: 10.1007/978-3-658-08405-9</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Online</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">22.45</td>
<td style="text-align: right;">22.45</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">76</td>
<td style="text-align: right;">5.33</td>
<td style="text-align: right;">1.83</td>
<td style="text-align: right;">85</td>
<td style="text-align: right;">6.13</td>
<td style="text-align: right;">1.54</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.64</td>
<td style="text-align: left;">Cross-gender rating (females rating males). Age includes participants in all conditions.</td>
<td style="text-align: right;">161</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Kirsch, 2015</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.32</td>
<td style="text-align: right;">0.04</td>
<td style="text-align: left;">Kirsch, 2015 - Exp 1 - Heterosexual</td>
<td style="text-align: left;">Kirsch, F. (2015). Wahrgenommene Attraktivitaet und sexuelle Orientierung: Die Wirkung von Rot und Farbpraeferenzen (Perceived attractiveness and sexual orientation: The effects of red and color preferences). Wiesbaden: Springer. doi: 10.1007/978-3-658-08405-9</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Monograph</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Online</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">22.45</td>
<td style="text-align: right;">22.45</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">57</td>
<td style="text-align: right;">6.85</td>
<td style="text-align: right;">1.44</td>
<td style="text-align: right;">48</td>
<td style="text-align: right;">6.42</td>
<td style="text-align: right;">1.22</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.68</td>
<td style="text-align: left;">Cross-gender rating (males rating females). Age includes participants in all conditions.</td>
<td style="text-align: right;">105</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Kirsch, 2015</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: right;">0.07</td>
<td style="text-align: left;">Kirsch, 2015 - Exp 2</td>
<td style="text-align: left;">Kirsch, F. (2015). Wahrgenommene Attraktivitaet und sexuelle Orientierung: Die Wirkung von Rot und Farbpraeferenzen (Perceived attractiveness and sexual orientation: The effects of red and color preferences). Wiesbaden: Springer. doi: 10.1007/978-3-658-08405-9</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Monograph</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">28</td>
<td style="text-align: right;">6.55</td>
<td style="text-align: right;">1.17</td>
<td style="text-align: right;">28</td>
<td style="text-align: right;">6.52</td>
<td style="text-align: right;">1.36</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.69</td>
<td style="text-align: left;">Means are only for cross-gender rating (males rating females)</td>
<td style="text-align: right;">56</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Legate et al., 2015</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">-0.35</td>
<td style="text-align: right;">0.08</td>
<td style="text-align: left;">Legate et al., 2015 - Exp 1</td>
<td style="text-align: left;">Legate, N., Baciu, C., Horne, L. M., Fiol, S., Paniagua, D., Muqeet, M., &amp; Zachocki, E. (2015, June 27). Replication of Elliot et al. (2010) at IIT. Retrieved from osf.io/zih7c</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">CREP</td>
<td style="text-align: left;">Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White (21 white, 16 asian)</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">20.73</td>
<td style="text-align: right;">20.25</td>
<td style="text-align: left;">~LCh(50.0, 59.6, 31.3)</td>
<td style="text-align: left;">~LCh(50.0, -, 69.1)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">25</td>
<td style="text-align: right;">5.76</td>
<td style="text-align: right;">1.61</td>
<td style="text-align: right;">23</td>
<td style="text-align: right;">6.33</td>
<td style="text-align: right;">1.58</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.67</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">48</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Lehmann &amp; Calin</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.39</td>
<td style="text-align: right;">0.07</td>
<td style="text-align: left;">Lehmann &amp; Calin-Jageman, 2015 - Class Exp</td>
<td style="text-align: left;">Lehmann &amp; Calin-Jageman (2017) Is red really romantic? Direct replications suggest little to no effect of the color red on perceived attractiveness for men and women. Social Psychology.</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Online</td>
<td style="text-align: left;">Mturk</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">31.70</td>
<td style="text-align: right;">36.15</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">29</td>
<td style="text-align: right;">4.34</td>
<td style="text-align: right;">1.63</td>
<td style="text-align: right;">28</td>
<td style="text-align: right;">3.69</td>
<td style="text-align: right;">1.65</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.34</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">57</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Lehmann &amp; Calin</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">-0.11</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: left;">Lehmann &amp; Calin-Jageman, 2017 - Exp 1</td>
<td style="text-align: left;">Lehmann &amp; Calin-Jageman (2017) Is red really romantic? Direct replications suggest little to no effect of the color red on perceived attractiveness for men and women. Social Psychology.</td>
<td style="text-align: right;">2017.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Mixed</td>
<td style="text-align: left;">White/Latino</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">20.41</td>
<td style="text-align: right;">21.22</td>
<td style="text-align: left;">LCh(51.3, 58.2, 29.5)</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">56</td>
<td style="text-align: right;">4.67</td>
<td style="text-align: right;">2.05</td>
<td style="text-align: right;">60</td>
<td style="text-align: right;">4.89</td>
<td style="text-align: right;">1.80</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.49</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">116</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Lehmann &amp; Calin</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.08</td>
<td style="text-align: right;">0.02</td>
<td style="text-align: left;">Lehmann &amp; Calin-Jageman, 2017 - Exp 2</td>
<td style="text-align: left;">Lehmann &amp; Calin-Jageman (2017) Is red really romantic? Direct replications suggest little to no effect of the color red on perceived attractiveness for men and women. Social Psychology.</td>
<td style="text-align: right;">2017.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Online</td>
<td style="text-align: left;">Mturk</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White/Latino</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">36.05</td>
<td style="text-align: right;">38.32</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">114</td>
<td style="text-align: right;">5.24</td>
<td style="text-align: right;">1.58</td>
<td style="text-align: right;">130</td>
<td style="text-align: right;">5.38</td>
<td style="text-align: right;">1.85</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.55</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">244</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Lehmann &amp; Calin</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.23</td>
<td style="text-align: right;">0.04</td>
<td style="text-align: left;">Lehmann &amp; Calin-Jageman, 2015 - Class Exp</td>
<td style="text-align: left;">Lehmann &amp; Calin-Jageman (2017) Is red really romantic? Direct replications suggest little to no effect of the color red on perceived attractiveness for men and women. Social Psychology.</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Online</td>
<td style="text-align: left;">Mturk</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">33.15</td>
<td style="text-align: right;">33.88</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">56</td>
<td style="text-align: right;">5.24</td>
<td style="text-align: right;">1.59</td>
<td style="text-align: right;">46</td>
<td style="text-align: right;">5.59</td>
<td style="text-align: right;">1.34</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.57</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">102</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Lehmann &amp; Calin</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.10</td>
<td style="text-align: right;">0.02</td>
<td style="text-align: left;">Lehmann &amp; Calin-Jageman, 2017 - Exp 2</td>
<td style="text-align: left;">Lehmann &amp; Calin-Jageman (2017) Is red really romantic? Direct replications suggest little to no effect of the color red on perceived attractiveness for men and women. Social Psychology.</td>
<td style="text-align: right;">2017.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Online</td>
<td style="text-align: left;">Mturk</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">35.78</td>
<td style="text-align: right;">35.85</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">104</td>
<td style="text-align: right;">6.51</td>
<td style="text-align: right;">1.32</td>
<td style="text-align: right;">106</td>
<td style="text-align: right;">6.38</td>
<td style="text-align: right;">1.32</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.67</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">210</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Lehmann &amp; Calin</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: right;">0.14</td>
<td style="text-align: left;">Lehmann &amp; Calin-Jageman, 2017 - Exp 1</td>
<td style="text-align: left;">Lehmann &amp; Calin-Jageman (2017) Is red really romantic? Direct replications suggest little to no effect of the color red on perceived attractiveness for men and women. Social Psychology.</td>
<td style="text-align: right;">2017.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">Mixed</td>
<td style="text-align: left;">Mixed</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">20.81</td>
<td style="text-align: right;">20.45</td>
<td style="text-align: left;">LCh(51.3, 58.2, 29.5)</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">21</td>
<td style="text-align: right;">6.52</td>
<td style="text-align: right;">1.16</td>
<td style="text-align: right;">11</td>
<td style="text-align: right;">6.52</td>
<td style="text-align: right;">1.56</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.69</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">32</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Lin, 2014</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">1.53</td>
<td style="text-align: right;">0.13</td>
<td style="text-align: left;">Lin, 2014 - Exp 1</td>
<td style="text-align: left;">Lin, H. (2014). Red-colored products enhance the attractiveness of women. Displays, 35(4), 202-205. http://doi.org/10.1016/j.displa.2014.05.009</td>
<td style="text-align: right;">2014.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Item</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Single item perceived attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-5</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">5</td>
<td style="text-align: left;">Taiwan</td>
<td style="text-align: left;">Asia</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">Asian</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Asian</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">20</td>
<td style="text-align: right;">3.50</td>
<td style="text-align: right;">0.69</td>
<td style="text-align: right;">20</td>
<td style="text-align: right;">2.55</td>
<td style="text-align: right;">0.51</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.39</td>
<td style="text-align: left;">Control condition is blue; silver condition is dropped as it is not an original control color</td>
<td style="text-align: right;">40</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Maves &amp; Nadler, 2016</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">-0.12</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: left;">Maves &amp; Nadler, 2016 - Exp 1</td>
<td style="text-align: left;">Maves, M., &amp; Nadler, J. T. (2016, June 2). Data and Analysis. Retrieved from osf.io/9bm8v</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">CREP</td>
<td style="text-align: left;">Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">21.86</td>
<td style="text-align: right;">22.48</td>
<td style="text-align: left;">~LCh(50.0, 59.6, 31.3)</td>
<td style="text-align: left;">~LCh(50.0, -, 69.1)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">66</td>
<td style="text-align: right;">6.07</td>
<td style="text-align: right;">1.40</td>
<td style="text-align: right;">64</td>
<td style="text-align: right;">6.23</td>
<td style="text-align: right;">1.38</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.65</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">130</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">O'Mara &amp; Trujillo, 2015</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.97</td>
<td style="text-align: right;">0.10</td>
<td style="text-align: left;">O'Mara &amp; Trujillo, 2015 - Exp 1 - Masculine Face</td>
<td style="text-align: left;">O'Mara, E. M., &amp; Trujillo, A. (2015), unpublished data.</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Head Shot</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">19.10</td>
<td style="text-align: right;">19.10</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">21</td>
<td style="text-align: right;">6.11</td>
<td style="text-align: right;">1.30</td>
<td style="text-align: right;">25</td>
<td style="text-align: right;">4.78</td>
<td style="text-align: right;">1.38</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.47</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">46</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">O'Mara &amp; Trujillo, 2015</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.20</td>
<td style="text-align: right;">0.09</td>
<td style="text-align: left;">O'Mara &amp; Trujillo, 2015 - Exp 2 - Masculine Face</td>
<td style="text-align: left;">O'Mara, E. M., &amp; Trujillo, A. (2015), unpublished data.</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Head Shot</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Online</td>
<td style="text-align: left;">Mturk</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">28.23</td>
<td style="text-align: right;">28.23</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">24</td>
<td style="text-align: right;">4.88</td>
<td style="text-align: right;">1.84</td>
<td style="text-align: right;">21</td>
<td style="text-align: right;">5.23</td>
<td style="text-align: right;">1.61</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.53</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">45</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">O'Mara et al., 2016</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.45</td>
<td style="text-align: right;">0.14</td>
<td style="text-align: left;">O'Mara et al., 2016 - Exp 2 - Long Shirt</td>
<td style="text-align: left;">O'Mara, E. M., Kershaw, C., Receveur, A., Hunt, C., Askar, S., Ballas, T., Farmer, C., O'Koon, B., Stitzel, C., Vavro, C., &amp; Wilhoit, S. (2016), unpublished data.</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Different between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">19.26</td>
<td style="text-align: right;">19.26</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">20</td>
<td style="text-align: right;">4.42</td>
<td style="text-align: right;">1.37</td>
<td style="text-align: right;">12</td>
<td style="text-align: right;">3.79</td>
<td style="text-align: right;">1.41</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.35</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">32</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">O'Mara et al., 2016</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.32</td>
<td style="text-align: right;">0.14</td>
<td style="text-align: left;">O'Mara et al., 2016 - Exp 2 - Tank Top</td>
<td style="text-align: left;">O'Mara, E. M., Kershaw, C., Receveur, A., Hunt, C., Askar, S., Ballas, T., Farmer, C., O'Koon, B., Stitzel, C., Vavro, C., &amp; Wilhoit, S. (2016), unpublished data.</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Different between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">19.26</td>
<td style="text-align: right;">19.26</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">17</td>
<td style="text-align: right;">3.91</td>
<td style="text-align: right;">1.09</td>
<td style="text-align: right;">12</td>
<td style="text-align: right;">4.33</td>
<td style="text-align: right;">1.51</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.42</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">29</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">O'Mara et al., 2016</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.47</td>
<td style="text-align: right;">0.07</td>
<td style="text-align: left;">O'Mara et al., 2016 - Exp 1 - Long Shirt</td>
<td style="text-align: left;">O'Mara, E. M., Kershaw, C., Receveur, A., Hunt, C., Askar, S., Ballas, T., Farmer, C., O'Koon, B., Stitzel, C., Vavro, C., &amp; Wilhoit, S. (2016), unpublished data.</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Different between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Online</td>
<td style="text-align: left;">Mturk</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">34.56</td>
<td style="text-align: right;">34.56</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">28</td>
<td style="text-align: right;">6.07</td>
<td style="text-align: right;">2.14</td>
<td style="text-align: right;">35</td>
<td style="text-align: right;">5.12</td>
<td style="text-align: right;">1.89</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.52</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">63</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">O'Mara et al., 2016</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.10</td>
<td style="text-align: right;">0.06</td>
<td style="text-align: left;">O'Mara et al., 2016 - Exp 1 - Tank Top</td>
<td style="text-align: left;">O'Mara, E. M., Kershaw, C., Receveur, A., Hunt, C., Askar, S., Ballas, T., Farmer, C., O'Koon, B., Stitzel, C., Vavro, C., &amp; Wilhoit, S. (2016), unpublished data.</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Different between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Online</td>
<td style="text-align: left;">Mturk</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">34.56</td>
<td style="text-align: right;">34.56</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">34</td>
<td style="text-align: right;">5.53</td>
<td style="text-align: right;">1.96</td>
<td style="text-align: right;">35</td>
<td style="text-align: right;">5.33</td>
<td style="text-align: right;">2.11</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.54</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">69</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">O'Mara et al., 2016</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.12</td>
<td style="text-align: right;">0.04</td>
<td style="text-align: left;">O'Mara et al., 2016 - Exp 3 - Tank Top</td>
<td style="text-align: left;">O'Mara, E. M., Kershaw, C., Receveur, A., Hunt, C., Askar, S., Ballas, T., Farmer, C., O'Koon, B., Stitzel, C., Vavro, C., &amp; Wilhoit, S. (2016), unpublished data.</td>
<td style="text-align: right;">2016.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Different between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">19.54</td>
<td style="text-align: right;">19.54</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">51</td>
<td style="text-align: right;">6.70</td>
<td style="text-align: right;">1.14</td>
<td style="text-align: right;">55</td>
<td style="text-align: right;">6.83</td>
<td style="text-align: right;">1.00</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.73</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">106</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">O'Mara et al., 2016</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.14</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: left;">O'Mara et al., 2016 - Exp 3 - Long Shirt</td>
<td style="text-align: left;">O'Mara, E. M., Kershaw, C., Receveur, A., Hunt, C., Askar, S., Ballas, T., Farmer, C., O'Koon, B., Stitzel, C., Vavro, C., &amp; Wilhoit, S. (2016), unpublished data.</td>
<td style="text-align: right;">2016.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Different between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">19.54</td>
<td style="text-align: right;">19.54</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">63</td>
<td style="text-align: right;">6.97</td>
<td style="text-align: right;">1.27</td>
<td style="text-align: right;">57</td>
<td style="text-align: right;">7.12</td>
<td style="text-align: right;">0.93</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.77</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">120</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Pazda et al., 2012</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.63</td>
<td style="text-align: right;">0.09</td>
<td style="text-align: left;">Pazda et al., 2012 - Exp 2</td>
<td style="text-align: left;">Pazda, A. D., Elliot, A. J., &amp; Greitemeyer, T. (2012). Sexy red: Perceived sexual receptivity mediates the red-attraction relation in men viewing woman. Journal of Experimental Social Psychology, 48(3), 787-790. http://doi.org/10.1016/j.jesp.2011.12.009</td>
<td style="text-align: right;">2012.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Green</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Austria</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">23.50</td>
<td style="text-align: right;">23.50</td>
<td style="text-align: left;">LCh(40.6, 40.4, 20.1)</td>
<td style="text-align: left;">LCh(40.3, 41.2, 146.8)</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">27</td>
<td style="text-align: right;">6.07</td>
<td style="text-align: right;">1.17</td>
<td style="text-align: right;">22</td>
<td style="text-align: right;">5.00</td>
<td style="text-align: right;">2.13</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.50</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">49</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Pazda et al., 2014</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.32</td>
<td style="text-align: right;">0.02</td>
<td style="text-align: left;">Pazda et al., 2014 - Exp 1</td>
<td style="text-align: left;">Pazda, A. D., Elliot, A. J., &amp; Greitemeyer, T. (2014). Perceived sexual receptivity and fashionableness: Separate paths linking red and black to perceived attractiveness. Color Research &amp; Application, 39(2), 208-212. http://doi.org/10.1002/col.21804</td>
<td style="text-align: right;">2014.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Full Body</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Not specified</td>
<td style="text-align: left;">Unknown</td>
<td style="text-align: left;">Online</td>
<td style="text-align: left;">Mturk</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White (170 white, 142 Asian)</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">24.50</td>
<td style="text-align: right;">24.50</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">109</td>
<td style="text-align: right;">6.03</td>
<td style="text-align: right;">1.78</td>
<td style="text-align: right;">125</td>
<td style="text-align: right;">5.46</td>
<td style="text-align: right;">1.77</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.56</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">234</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Pazda et al., 2017</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.17</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: left;">Pazda et al., 2017 - Exp 1</td>
<td style="text-align: left;">Pazda, A., Thorstenson &amp; Elliot, A. (2017). Unpublished data.</td>
<td style="text-align: right;">2017.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Green</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Full Body</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Single Item</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Lab study</td>
<td style="text-align: left;">Within Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">19.76</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">red LCh(42.00, 57.92, 348.89), green LCh(41.50, 56.71, 92.17)</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">115</td>
<td style="text-align: right;">7.81</td>
<td style="text-align: right;">1.21</td>
<td style="text-align: right;">115</td>
<td style="text-align: right;">7.58</td>
<td style="text-align: right;">1.41</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.84</td>
<td style="text-align: right;">0.82</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">115</td>
<td style="text-align: right;">1.31</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Pazda et al., 2017</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.10</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: left;">Pazda et al., 2017 - Exp 2</td>
<td style="text-align: left;">Pazda, A., Thorstenson &amp; Elliot, A. (2017). Unpublished data.</td>
<td style="text-align: right;">2017.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Green</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Full Body</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Single Item</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Online</td>
<td style="text-align: left;">Mturk</td>
<td style="text-align: left;">Within Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">37.43</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">red LCh(42.00, 57.92, 348.89), green LCh(41.50, 56.71, 92.17)</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">228</td>
<td style="text-align: right;">8.08</td>
<td style="text-align: right;">1.28</td>
<td style="text-align: right;">228</td>
<td style="text-align: right;">7.95</td>
<td style="text-align: right;">1.39</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.80</td>
<td style="text-align: right;">0.87</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">228</td>
<td style="text-align: right;">1.34</td>
</tr>
<tr class="even">
<td style="text-align: left;">Peperkoorn et al., 2016</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">-0.43</td>
<td style="text-align: right;">0.06</td>
<td style="text-align: left;">Peperkoorn et al., 2016 - Exp 1 - Short Term</td>
<td style="text-align: left;">Peperkoorn, L. S., Roberts, S. C., &amp; Pollet, T. V. (2016). Revisiting the Red Effect on Attractiveness and Sexual Receptivity: No Effect of the Color Red on Human Mate Preferences. Evolutionary Psychology, 14(4). http://doi.org/10.1177/1474704916673841</td>
<td style="text-align: right;">2016.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-11</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">22</td>
<td style="text-align: left;">Netherlands</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">23.67</td>
<td style="text-align: right;">23.67</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">34</td>
<td style="text-align: right;">14.26</td>
<td style="text-align: right;">3.31</td>
<td style="text-align: right;">34</td>
<td style="text-align: right;">15.47</td>
<td style="text-align: right;">2.18</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.67</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">68</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Peperkoorn et al., 2016</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.10</td>
<td style="text-align: right;">0.06</td>
<td style="text-align: left;">Peperkoorn et al., 2016 - Exp 2 - Short Term</td>
<td style="text-align: left;">Peperkoorn, L. S., Roberts, S. C., &amp; Pollet, T. V. (2016). Revisiting the Red Effect on Attractiveness and Sexual Receptivity: No Effect of the Color Red on Human Mate Preferences. Evolutionary Psychology, 14(4). http://doi.org/10.1177/1474704916673841</td>
<td style="text-align: right;">2016.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-11</td>
<td style="text-align: right;">2</td>
<td style="text-align: right;">22</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Online</td>
<td style="text-align: left;">Mturk</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">30.13</td>
<td style="text-align: right;">30.13</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">33</td>
<td style="text-align: right;">15.06</td>
<td style="text-align: right;">4.14</td>
<td style="text-align: right;">36</td>
<td style="text-align: right;">15.47</td>
<td style="text-align: right;">3.61</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.67</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">69</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Pollet, 2013</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.16</td>
<td style="text-align: right;">0.08</td>
<td style="text-align: left;">Pollet, 2013 - Exp 1</td>
<td style="text-align: left;">Pollet T. (2013). Unpublished data</td>
<td style="text-align: right;">2013.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Full Body</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Single item</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-7</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">7</td>
<td style="text-align: left;">Netherlands</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Primarily dutch nationality</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">26.60</td>
<td style="text-align: right;">28.40</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">26</td>
<td style="text-align: right;">3.15</td>
<td style="text-align: right;">1.22</td>
<td style="text-align: right;">23</td>
<td style="text-align: right;">2.96</td>
<td style="text-align: right;">1.19</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.33</td>
<td style="text-align: left;">Only blue control color used as other control colors were not in original</td>
<td style="text-align: right;">49</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Purdy, 2009</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.30</td>
<td style="text-align: right;">0.16</td>
<td style="text-align: left;">Purdy, 2009 - Exp 1 - High Arousal</td>
<td style="text-align: left;">Purdy, M. A. (2009). The influence of the amygdala and color on judgments of attractiveness. UNC Asheville Journal, Undergraduate Research Program, Asheville, NC</td>
<td style="text-align: right;">2009.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">21.00</td>
<td style="text-align: right;">21.00</td>
<td style="text-align: left;">RGB(185, 26, 23)</td>
<td style="text-align: left;">RGB(216,216,216)</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">13</td>
<td style="text-align: right;">7.26</td>
<td style="text-align: right;">3.27</td>
<td style="text-align: right;">13</td>
<td style="text-align: right;">6.24</td>
<td style="text-align: right;">3.27</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.66</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">26</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Purdy, 2009</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: right;">0.15</td>
<td style="text-align: left;">Purdy, 2009 - Exp 1 - Low Arousal</td>
<td style="text-align: left;">Purdy, M. A. (2009). The influence of the amygdala and color on judgments of attractiveness. UNC Asheville Journal, Undergraduate Research Program, Asheville, NC</td>
<td style="text-align: right;">2009.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">21.00</td>
<td style="text-align: right;">21.00</td>
<td style="text-align: left;">RGB(185, 26, 23)</td>
<td style="text-align: left;">RGB(216,216,216)</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">13</td>
<td style="text-align: right;">6.37</td>
<td style="text-align: right;">3.31</td>
<td style="text-align: right;">13</td>
<td style="text-align: right;">6.33</td>
<td style="text-align: right;">3.27</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.67</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">26</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Roberts et al., 2010</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.33</td>
<td style="text-align: right;">0.05</td>
<td style="text-align: left;">Roberts et al., 2010 - Exp 2</td>
<td style="text-align: left;">Roberts, S. C., Owen, R. C., &amp; Havlicek, J. (2010). Distinguishing between Perceiver and Wearer Effects in Clothing Color-Associated Attributions. Evolutionary Psychology, 8(3), 350-364. http://doi.org/10.1177/147470491000800304</td>
<td style="text-align: right;">2010.1</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Blue/Green/White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Different between conditions</td>
<td style="text-align: left;">Single item rating of attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-10</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">10</td>
<td style="text-align: left;">England</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Within Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Noted in manuscript all caucasian</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">3.66</td>
<td style="text-align: right;">0.60</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">3.45</td>
<td style="text-align: right;">0.61</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.66</td>
<td style="text-align: right;">0.27</td>
<td style="text-align: left;">Age range includes both male and female participants.</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">0.60</td>
</tr>
<tr class="even">
<td style="text-align: left;">Roberts et al., 2010</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.40</td>
<td style="text-align: right;">0.02</td>
<td style="text-align: left;">Roberts et al., 2010 - Exp 2</td>
<td style="text-align: left;">Roberts, S. C., Owen, R. C., &amp; Havlicek, J. (2010). Distinguishing between Perceiver and Wearer Effects in Clothing Color-Associated Attributions. Evolutionary Psychology, 8(3), 350-364. http://doi.org/10.1177/147470491000800304</td>
<td style="text-align: right;">2010.1</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue/Green/White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Different between conditions</td>
<td style="text-align: left;">Single item rating of attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-10</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">10</td>
<td style="text-align: left;">England</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Within Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Noted in manuscript all caucasian</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">3.65</td>
<td style="text-align: right;">0.45</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">3.46</td>
<td style="text-align: right;">0.48</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.92</td>
<td style="text-align: right;">0.27</td>
<td style="text-align: left;">Age range includes both male and female participants.</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">0.47</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Roberts et al., 2010</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.19</td>
<td style="text-align: right;">0.02</td>
<td style="text-align: left;">Roberts et al., 2010 - Exp 1</td>
<td style="text-align: left;">Roberts, S. C., Owen, R. C., &amp; Havlicek, J. (2010). Distinguishing between Perceiver and Wearer Effects in Clothing Color-Associated Attributions. Evolutionary Psychology, 8(3), 350-364. http://doi.org/10.1177/147470491000800304</td>
<td style="text-align: right;">2010.1</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Blue/Green/White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Different between conditions</td>
<td style="text-align: left;">Single item rating of attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-10</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">10</td>
<td style="text-align: left;">England</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Within Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Noted in manuscript all caucasian</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">4.50</td>
<td style="text-align: right;">1.23</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">4.26</td>
<td style="text-align: right;">1.18</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.66</td>
<td style="text-align: right;">0.36</td>
<td style="text-align: left;">Age range includes both male and female participants.</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">1.21</td>
</tr>
<tr class="even">
<td style="text-align: left;">Roberts et al., 2010</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.19</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: left;">Roberts et al., 2010 - Exp 1</td>
<td style="text-align: left;">Roberts, S. C., Owen, R. C., &amp; Havlicek, J. (2010). Distinguishing between Perceiver and Wearer Effects in Clothing Color-Associated Attributions. Evolutionary Psychology, 8(3), 350-364. http://doi.org/10.1177/147470491000800304</td>
<td style="text-align: right;">2010.1</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue/Green/White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Different between conditions</td>
<td style="text-align: left;">Single item rating of attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-10</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">10</td>
<td style="text-align: left;">England</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Within Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Noted in manuscript all caucasian</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">4.60</td>
<td style="text-align: right;">1.10</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">4.40</td>
<td style="text-align: right;">0.92</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.92</td>
<td style="text-align: right;">0.38</td>
<td style="text-align: left;">Age range includes both male and female participants.</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">1.01</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Roberts et al., 2010</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.08</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: left;">Roberts et al., 2010 - Exp 3</td>
<td style="text-align: left;">Roberts, S. C., Owen, R. C., &amp; Havlicek, J. (2010). Distinguishing between Perceiver and Wearer Effects in Clothing Color-Associated Attributions. Evolutionary Psychology, 8(3), 350-364. http://doi.org/10.1177/147470491000800304</td>
<td style="text-align: right;">2010.1</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Single item rating of attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-10</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">10</td>
<td style="text-align: left;">England</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Within Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Noted in manuscript all caucasian</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">25</td>
<td style="text-align: right;">4.82</td>
<td style="text-align: right;">0.90</td>
<td style="text-align: right;">25</td>
<td style="text-align: right;">4.88</td>
<td style="text-align: right;">0.85</td>
<td style="text-align: right;">0.36</td>
<td style="text-align: right;">0.92</td>
<td style="text-align: right;">0.43</td>
<td style="text-align: left;">Age range includes both male and female participants.</td>
<td style="text-align: right;">25</td>
<td style="text-align: right;">0.88</td>
</tr>
<tr class="even">
<td style="text-align: left;">Roberts et al., 2010</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.05</td>
<td style="text-align: right;">0.03</td>
<td style="text-align: left;">Roberts et al., 2010 - Exp 3</td>
<td style="text-align: left;">Roberts, S. C., Owen, R. C., &amp; Havlicek, J. (2010). Distinguishing between Perceiver and Wearer Effects in Clothing Color-Associated Attributions. Evolutionary Psychology, 8(3), 350-364. http://doi.org/10.1177/147470491000800304</td>
<td style="text-align: right;">2010.1</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Single item rating of attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-10</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">10</td>
<td style="text-align: left;">England</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Within Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Noted in manuscript all caucasian</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">23</td>
<td style="text-align: right;">4.87</td>
<td style="text-align: right;">0.75</td>
<td style="text-align: right;">23</td>
<td style="text-align: right;">4.90</td>
<td style="text-align: right;">0.73</td>
<td style="text-align: right;">0.61</td>
<td style="text-align: right;">0.66</td>
<td style="text-align: right;">0.43</td>
<td style="text-align: left;">Age range includes both male and female participants.</td>
<td style="text-align: right;">23</td>
<td style="text-align: right;">0.74</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Schwarz &amp; Singer, 2013</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.19</td>
<td style="text-align: right;">0.07</td>
<td style="text-align: left;">Schwarz &amp; Singer, 2013 - Exp 1 - Adults Rate Young</td>
<td style="text-align: left;">Schwarz, S., &amp; Singer, M. (2013). Romantic red revisited: Red enhances men's attraction to young, but not menopausal women. Journal of Experimental Social Psychology, 49(1), 161-164. http://doi.org/10.1016/j.jesp.2012.08.004</td>
<td style="text-align: right;">2013.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Adults</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">53.47</td>
<td style="text-align: right;">53.47</td>
<td style="text-align: left;">Lum: 35.2, Chroma: 39.3, Hue no specified</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">6.53</td>
<td style="text-align: right;">1.96</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">6.13</td>
<td style="text-align: right;">2.17</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.64</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">60</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Schwarz &amp; Singer, 2013</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">-0.15</td>
<td style="text-align: right;">0.07</td>
<td style="text-align: left;">Schwarz &amp; Singer, 2013 - Exp 1 - UGrads Rate Young</td>
<td style="text-align: left;">Schwarz, S., &amp; Singer, M. (2013). Romantic red revisited: Red enhances men's attraction to young, but not menopausal women. Journal of Experimental Social Psychology, 49(1), 161-164. http://doi.org/10.1016/j.jesp.2012.08.004</td>
<td style="text-align: right;">2013.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">24.67</td>
<td style="text-align: right;">24.67</td>
<td style="text-align: left;">Lum: 35.2, Chroma: 39.3, Hue no specified</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">6.20</td>
<td style="text-align: right;">1.42</td>
<td style="text-align: right;">30</td>
<td style="text-align: right;">6.40</td>
<td style="text-align: right;">1.18</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.68</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">60</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Seibt &amp; Klement, 2015</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.22</td>
<td style="text-align: right;">0.05</td>
<td style="text-align: left;">Seibt &amp; Klement, 2015 - Exp 1</td>
<td style="text-align: left;">Seibt, T., &amp; Klement, V. (2015). The Impact of the Colour Red on Attractiveness Perception. In 4th Advanced Research in Scientific Areas (pp. 20-24). http://doi.org/10.18638/arsa.2015.4.1.799</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Conference Proceedings</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Green</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived Attractiveness, subscale of Haselton und Gangestad (2006)</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads and Grads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">26.70</td>
<td style="text-align: right;">26.70</td>
<td style="text-align: left;">RGB(255.0.0)</td>
<td style="text-align: left;">RGB(0.139.0)</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">54</td>
<td style="text-align: right;">3.19</td>
<td style="text-align: right;">0.53</td>
<td style="text-align: right;">31</td>
<td style="text-align: right;">3.07</td>
<td style="text-align: right;">0.55</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.26</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">85</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Seibt &amp; Klement, 2015</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.20</td>
<td style="text-align: right;">0.16</td>
<td style="text-align: left;">Seibt &amp; Klement, 2015 - Exp 1</td>
<td style="text-align: left;">Seibt, T., &amp; Klement, V. (2015). The Impact of the Colour Red on Attractiveness Perception. In 4th Advanced Research in Scientific Areas (pp. 20-24). http://doi.org/10.18638/arsa.2015.4.1.799</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Conference Proceedings</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Green</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived Attractiveness, subscale of Haselton und Gangestad (2006)</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads and Grads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">26.70</td>
<td style="text-align: right;">26.70</td>
<td style="text-align: left;">RGB(255.0.0)</td>
<td style="text-align: left;">RGB(0.139.0)</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">12</td>
<td style="text-align: right;">3.40</td>
<td style="text-align: right;">0.43</td>
<td style="text-align: right;">14</td>
<td style="text-align: right;">3.30</td>
<td style="text-align: right;">0.54</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.29</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">26</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Seibt, 2015</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.20</td>
<td style="text-align: right;">0.05</td>
<td style="text-align: left;">Seibt, 2015 - Exp 1</td>
<td style="text-align: left;">Seibt, T. (2015). Romantic Red Effect in the Attractiveness Perception. In Hassacc (pp. 31-34). http://doi.org/10.18638/hassacc.2015.3.1.186</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Conference Proceedings</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Green</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived Attractiveness</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">1-5</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">5</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads and Grads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">25.50</td>
<td style="text-align: right;">25.50</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: right;">46</td>
<td style="text-align: right;">2.80</td>
<td style="text-align: right;">0.49</td>
<td style="text-align: right;">41</td>
<td style="text-align: right;">2.70</td>
<td style="text-align: right;">0.52</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.42</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">87</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Stefan &amp; Gueguen, 2013</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.62</td>
<td style="text-align: right;">0.12</td>
<td style="text-align: left;">Stefan &amp; Gueguen, 2013 - Exp 1</td>
<td style="text-align: left;">Stefan J. &amp; Gueguen, N. (2013). Unpublished data.</td>
<td style="text-align: right;">2013.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Full Body</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Single item</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-100</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">100</td>
<td style="text-align: left;">France</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads and Grads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">22.11</td>
<td style="text-align: right;">22.11</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">18</td>
<td style="text-align: right;">81.33</td>
<td style="text-align: right;">16.30</td>
<td style="text-align: right;">16</td>
<td style="text-align: right;">67.50</td>
<td style="text-align: right;">26.87</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.67</td>
<td style="text-align: left;">Data provided by Elliot</td>
<td style="text-align: right;">34</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Sullivan et al., 2016</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.24</td>
<td style="text-align: right;">0.04</td>
<td style="text-align: left;">Sullivan et al., 2016 - Exp 1</td>
<td style="text-align: left;">Sullivan, J., Amaral Lavoie, E., Bays, R. B., Fontana, S., Goodkind, R., Johnson, R., ... Lavoie, M. (2016, April 4). Replication of Elliot et al., 2010: Red, Rank, and Romance. Retrieved from osf.io/pm7fx</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">19.96</td>
<td style="text-align: right;">19.45</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">49</td>
<td style="text-align: right;">5.60</td>
<td style="text-align: right;">1.37</td>
<td style="text-align: right;">53</td>
<td style="text-align: right;">5.26</td>
<td style="text-align: right;">1.42</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.53</td>
<td style="text-align: left;">Two-year class project posted on OSF</td>
<td style="text-align: right;">102</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Sullivan et al., 2016</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.34</td>
<td style="text-align: right;">0.06</td>
<td style="text-align: left;">Sullivan et al., 2016 - Exp 2</td>
<td style="text-align: left;">Sullivan, J., Amaral Lavoie, E., Bays, R. B., Fontana, S., Goodkind, R., Johnson, R., ... Lavoie, M. (2016, April 4). Replication of Elliot et al., 2010: Red, Rank, and Romance. Retrieved from osf.io/pm7fx</td>
<td style="text-align: right;">2016.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Latino</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">38</td>
<td style="text-align: right;">4.85</td>
<td style="text-align: right;">1.65</td>
<td style="text-align: right;">27</td>
<td style="text-align: right;">5.37</td>
<td style="text-align: right;">1.38</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.55</td>
<td style="text-align: left;">Age recorded as dichotomy (younger then 20, older than 20) so not included</td>
<td style="text-align: right;">65</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Sullivan et al., 2016</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.42</td>
<td style="text-align: right;">0.04</td>
<td style="text-align: left;">Sullivan et al., 2016 - Exp 1</td>
<td style="text-align: left;">Sullivan, J., Amaral Lavoie, E., Bays, R. B., Fontana, S., Goodkind, R., Johnson, R., ... Lavoie, M. (2016, April 4). Replication of Elliot et al., 2010: Red, Rank, and Romance. Retrieved from osf.io/pm7fx</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">19.62</td>
<td style="text-align: right;">19.75</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">45</td>
<td style="text-align: right;">6.21</td>
<td style="text-align: right;">1.38</td>
<td style="text-align: right;">48</td>
<td style="text-align: right;">5.58</td>
<td style="text-align: right;">1.56</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.57</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">93</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Sullivan et al., 2016</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.02</td>
<td style="text-align: right;">0.12</td>
<td style="text-align: left;">Sullivan et al., 2016 - Exp 2</td>
<td style="text-align: left;">Sullivan, J., Amaral Lavoie, E., Bays, R. B., Fontana, S., Goodkind, R., Johnson, R., ... Lavoie, M. (2016, April 4). Replication of Elliot et al., 2010: Red, Rank, and Romance. Retrieved from osf.io/pm7fx</td>
<td style="text-align: right;">2016.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Unpublished/Online</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">21</td>
<td style="text-align: right;">6.24</td>
<td style="text-align: right;">1.29</td>
<td style="text-align: right;">14</td>
<td style="text-align: right;">6.21</td>
<td style="text-align: right;">1.45</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.65</td>
<td style="text-align: left;">Age recorded as dichotomy (younger then 20, older than 20) so not included</td>
<td style="text-align: right;">35</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Wartenberg et al., 2011</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.20</td>
<td style="text-align: right;">0.01</td>
<td style="text-align: left;">Wartenberg et al., 2011 - Exp 1 - In Group</td>
<td style="text-align: left;">Wartenberg, W., Hoepfner, T., Potthast, P., &amp; Mirau, A. (2011). If you wear red on a date, you will please your mate. Proceedings of Empiriepraktikumskongress, 6th, Aug. 7, pp 26-27. University of Jena, Germany.</td>
<td style="text-align: right;">2011.0</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Conference Proceedings</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">4</td>
<td style="text-align: left;">1-7</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">7</td>
<td style="text-align: left;">Germany</td>
<td style="text-align: left;">Europe</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Within Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">21.47</td>
<td style="text-align: right;">21.47</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No Data</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">39</td>
<td style="text-align: right;">3.00</td>
<td style="text-align: right;">1.18</td>
<td style="text-align: right;">39</td>
<td style="text-align: right;">2.76</td>
<td style="text-align: right;">1.13</td>
<td style="text-align: right;">0.63</td>
<td style="text-align: right;">0.86</td>
<td style="text-align: right;">0.29</td>
<td style="text-align: left;">Translation of summary provided by Elliot; within subjects info still needed</td>
<td style="text-align: right;">39</td>
<td style="text-align: right;">1.16</td>
</tr>
<tr class="even">
<td style="text-align: left;">Wen et al., 2014</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">0.16</td>
<td style="text-align: right;">0.07</td>
<td style="text-align: left;">Wen et al., 2014 - Exp 1 - Feminine Females</td>
<td style="text-align: left;">Wen, F., Zuo, B., Wu, Y., Sun, S., &amp; Liu, K. (2014). Red is Romantic, but Only for Feminine Females: Sexual Dimorphism Moderates Red Effect on Sexual Attraction. Evolutionary Psychology, 12(4), 719-735. http://doi.org/10.1177/147470491401200404</td>
<td style="text-align: right;">2014.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue/White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness, extracted factor</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-7</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">7</td>
<td style="text-align: left;">China</td>
<td style="text-align: left;">Asia</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">Asian</td>
<td style="text-align: left;">Asian</td>
<td style="text-align: left;">Asian</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">20.95</td>
<td style="text-align: right;">20.95</td>
<td style="text-align: left;">LCh(51.1, 57.7, 27.8)</td>
<td style="text-align: left;">LCh(51.6, 57.6, 278.3)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">22</td>
<td style="text-align: right;">0.24</td>
<td style="text-align: right;">0.93</td>
<td style="text-align: right;">44</td>
<td style="text-align: right;">0.10</td>
<td style="text-align: right;">0.81</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">Control is average of blue and white conditions; only normalized scores provided. Age range includes participants in all conditions.</td>
<td style="text-align: right;">66</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Wen et al., 2014</td>
<td style="text-align: left;">Paper</td>
<td style="text-align: right;">-0.08</td>
<td style="text-align: right;">0.07</td>
<td style="text-align: left;">Wen et al., 2014 - Exp 1 - Masculine Males</td>
<td style="text-align: left;">Wen, F., Zuo, B., Wu, Y., Sun, S., &amp; Liu, K. (2014). Red is Romantic, but Only for Feminine Females: Sexual Dimorphism Moderates Red Effect on Sexual Attraction. Evolutionary Psychology, 12(4), 719-735. http://doi.org/10.1177/147470491401200404</td>
<td style="text-align: right;">2014.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Females</td>
<td style="text-align: left;">Blue/White</td>
<td style="text-align: left;">Clothing</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness, extracted factor</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">1-7</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">7</td>
<td style="text-align: left;">China</td>
<td style="text-align: left;">Asia</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">Asian</td>
<td style="text-align: left;">Asian</td>
<td style="text-align: left;">Asian</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">20.95</td>
<td style="text-align: right;">20.95</td>
<td style="text-align: left;">LCh(51.1, 57.7, 27.8)</td>
<td style="text-align: left;">LCh(51.6, 57.6, 278.3)</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">21</td>
<td style="text-align: right;">-0.10</td>
<td style="text-align: right;">0.93</td>
<td style="text-align: right;">49</td>
<td style="text-align: right;">-0.03</td>
<td style="text-align: right;">0.85</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: left;">Control is average of blue and white conditions; only normalized scores provided. Age range includes participants in all conditions.</td>
<td style="text-align: right;">70</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Williams &amp; Neelon, 2013</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.58</td>
<td style="text-align: right;">0.13</td>
<td style="text-align: left;">Williams &amp; Neelon, 2013 - Exp 1 - All</td>
<td style="text-align: left;">Williams, C. L. &amp; Neelon, M. (2013). Conditional beauty: The impact of emotionally linked images on the red effect in sexual attraction. Psi Chi Journal of Psychological Research, 18(1), 10-19.</td>
<td style="text-align: right;">2013.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White (noted by authors)</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">22.50</td>
<td style="text-align: right;">22.50</td>
<td style="text-align: left;">RGB(183,70,60)</td>
<td style="text-align: left;">RGB(76,105,200)</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">16</td>
<td style="text-align: right;">6.81</td>
<td style="text-align: right;">1.03</td>
<td style="text-align: right;">15</td>
<td style="text-align: right;">6.15</td>
<td style="text-align: right;">1.20</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.64</td>
<td style="text-align: left;">Data provided by Elliot</td>
<td style="text-align: right;">31</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Williams &amp; Neelon, 2013</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">-0.13</td>
<td style="text-align: right;">0.08</td>
<td style="text-align: left;">Williams &amp; Neelon, 2013 - Exp 2 - Positive and Neutral</td>
<td style="text-align: left;">Williams, C. L. &amp; Neelon, M. (2013). Conditional beauty: The impact of emotionally linked images on the red effect in sexual attraction. Psi Chi Journal of Psychological Research, 18(1), 10-19.</td>
<td style="text-align: right;">2013.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Bust</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Perceived attractiveness</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">1-9</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">9</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Between Subjects</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">White (noted by authors)</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Matched</td>
<td style="text-align: right;">21.50</td>
<td style="text-align: right;">21.50</td>
<td style="text-align: left;">RGB(183,70,60)</td>
<td style="text-align: left;">RGB(76,105,200)</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">26</td>
<td style="text-align: right;">6.40</td>
<td style="text-align: right;">1.28</td>
<td style="text-align: right;">26</td>
<td style="text-align: right;">6.56</td>
<td style="text-align: right;">1.04</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">NA</td>
<td style="text-align: right;">0.69</td>
<td style="text-align: left;">Data provided by Elliot</td>
<td style="text-align: right;">52</td>
<td style="text-align: right;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">Young, 2015</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.14</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: left;">Young, 2015 - Exp 1 - More Attractive</td>
<td style="text-align: left;">Young, S. G. (2015). The effect of red on male perceptions of female attractiveness: Moderation by baseline attractiveness of female faces. European Journal of Social Psychology, 45(2), 146-151. http://doi.org/10.1002/ejsp.2098</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Head Shot</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Single item</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-7</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">7</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Within Subjects</td>
<td style="text-align: left;">Mixed</td>
<td style="text-align: left;">Mixed</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">19.90</td>
<td style="text-align: right;">19.90</td>
<td style="text-align: left;">LCh(62.7, 84.6, 34.1)</td>
<td style="text-align: left;">LCh(62.6, -, 265.5)</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">19</td>
<td style="text-align: right;">4.29</td>
<td style="text-align: right;">0.86</td>
<td style="text-align: right;">19</td>
<td style="text-align: right;">4.17</td>
<td style="text-align: right;">0.81</td>
<td style="text-align: right;">0.23</td>
<td style="text-align: right;">0.96</td>
<td style="text-align: right;">0.53</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">19</td>
<td style="text-align: right;">0.84</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Young, 2015</td>
<td style="text-align: left;">Screen</td>
<td style="text-align: right;">0.10</td>
<td style="text-align: right;">0.00</td>
<td style="text-align: left;">Young, 2015 - Exp 2 - More Attractive</td>
<td style="text-align: left;">Young, S. G. (2015). The effect of red on male perceptions of female attractiveness: Moderation by baseline attractiveness of female faces. European Journal of Social Psychology, 45(2), 146-151. http://doi.org/10.1002/ejsp.2098</td>
<td style="text-align: right;">2015.0</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Journal</td>
<td style="text-align: left;">Not Pre-Registered</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Romantic</td>
<td style="text-align: left;">Males</td>
<td style="text-align: left;">Blue/Gray</td>
<td style="text-align: left;">Background</td>
<td style="text-align: left;">Head Shot</td>
<td style="text-align: left;">Same between conditions</td>
<td style="text-align: left;">Single item</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">1-7</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">7</td>
<td style="text-align: left;">USA</td>
<td style="text-align: left;">North America</td>
<td style="text-align: left;">Students</td>
<td style="text-align: left;">Undergrads</td>
<td style="text-align: left;">Within Subjects</td>
<td style="text-align: left;">Mixed</td>
<td style="text-align: left;">Mixed</td>
<td style="text-align: left;">White</td>
<td style="text-align: left;">Mis-match</td>
<td style="text-align: right;">21.10</td>
<td style="text-align: right;">21.10</td>
<td style="text-align: left;">LCh(62.7, 84.6, 34.1)</td>
<td style="text-align: left;">LCh(62.7, 84.6, 34.1)</td>
<td style="text-align: left;">No</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: left;">Yes</td>
<td style="text-align: right;">46</td>
<td style="text-align: right;">4.30</td>
<td style="text-align: right;">1.11</td>
<td style="text-align: right;">46</td>
<td style="text-align: right;">4.19</td>
<td style="text-align: right;">1.07</td>
<td style="text-align: right;">0.25</td>
<td style="text-align: right;">0.98</td>
<td style="text-align: right;">0.53</td>
<td style="text-align: left;">Blue and Gray ratings averaged, then compared to red; original data provided</td>
<td style="text-align: right;">46</td>
<td style="text-align: right;">1.09</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<section id="preliminary-analysis" class="level1">
<h1>Preliminary Analysis</h1>
<p>As a little warm-up exercise, here is a basic random effects meta-analysis of these data, fit via the <a href="https://wviechtb.github.io/metafor/">metafor</a> package <span class="citation" data-cites="Viechtbauer2010conducting">(Viechtbauer, 2010)</span>. We use cluster-robust standard errors to account for effect size dependency.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Estimate random effects model</span></span>
<span id="cb2-2">RE_mod <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rma.uni</span>(yi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vi =</span> vi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> lehmann_dat, <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;">"ML"</span>)</span>
<span id="cb2-3"></span>
<span id="cb2-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Calculate cluster-robust standard errors</span></span>
<span id="cb2-5">RE_robust <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">robust</span>(RE_mod, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cluster =</span> study, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clubSandwich =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb2-6">RE_robust</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
Random-Effects Model (k = 81; tau^2 estimator: ML)

tau^2 (estimated amount of total heterogeneity): 0.1009 (SE = 0.0245)
tau (square root of estimated tau^2 value):      0.3176
I^2 (total heterogeneity / total variability):   81.54%
H^2 (total variability / sampling variability):  5.42

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

Number of estimates:   81
Number of clusters:    41
Estimates per cluster: 1-6 (mean: 1.98, median: 1)

Model Results:

estimate      se¹    tval¹     df¹    pval¹   ci.lb¹   ci.ub¹     
  0.2069  0.0569   3.6331   23.41   0.0014   0.0892   0.3245   ** 

---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

1) results based on cluster-robust inference (var-cov estimator: CR2,
   approx t-test and confidence interval, df: Satterthwaite approx)</code></pre>
</div>
</div>
<p>The random effects model indicates an average effect size of about 0.21 standard deviations and substantial heterogeneity, with <img src="https://latex.codecogs.com/png.latex?%5Chat%5Ctau%20=%200.32">. The cluster-robust standard error is about 27% bigger than the model-based standard error (not shown) because the latter does not account for dependent effect sizes.</p>
<p>Here is a contour-enhanced funnel plot of the data:</p>
<div class="cell">
<details open="" 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;">funnel</span>(RE_mod, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">refline =</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;">level=</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;">90</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">95</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">99</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shade=</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;">"white"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray55"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray75"</span>))</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/cluster-bootstrap-selection-model/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" style="width:90.0%"></p>
</figure>
</div>
</div>
</div>
<p>The funnel plot shows some asymmetry, suggesting that there is reason to be concerned about selective reporting bias in these data.</p>
</section>
<section id="a-selection-model" class="level1">
<h1>A Selection Model</h1>
<p>For starters, we will fit a very simple selection model, with a single step in the probability of reporting at <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20.025">. This is what’s come to be called the <em>three-parameter selection model</em> <span class="citation" data-cites="mcshane2016adjusting">(McShane et al., 2016)</span>. The step is defined in terms of a one-sided p-value, so <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20.025"> corresponds to the point where an effect size estimate in the theoretically expected direction would have a regular, two-sided p-value of .05, right at the mystical threshold of statistical significance. We fit the model using <code>metafor</code>’s <a href="https://wviechtb.github.io/metafor/reference/selmodel.html"><code>selmodel()</code></a> function:</p>
<div class="cell">
<details open="" 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">RE_sel <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selmodel</span>(RE_mod, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stepfun"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">025</span>)</span>
<span id="cb5-2">RE_sel</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
Random-Effects Model (k = 81; tau^2 estimator: ML)

tau^2 (estimated amount of total heterogeneity): 0.0811 (SE = 0.0261)
tau (square root of estimated tau^2 value):      0.2848

Test for Heterogeneity:
LRT(df = 1) = 37.3674, p-val &lt; .0001

Model Results:

estimate      se    zval    pval   ci.lb   ci.ub    
  0.1328  0.0655  2.0267  0.0427  0.0044  0.2612  * 

Test for Selection Model Parameters:
LRT(df = 1) = 1.7646, p-val = 0.1840

Selection Model Results:

                     k  estimate      se     zval    pval   ci.lb   ci.ub    
0     &lt; p &lt;= 0.025  25    1.0000     ---      ---     ---     ---     ---    
0.025 &lt; p &lt;= 1      56    0.5485  0.2495  -1.8097  0.0703  0.0594  1.0375  . 

---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</code></pre>
</div>
</div>
<p>The selection parameter represents the probability that an effect size estimate that is not in the theoretically expected direction or not statistically significant at the conventional level would be included in the synthesis, relative to the probability that an affirmative, statistically significant effect size estimate would be included. In this example, the probability of selection is estimated as 0.55, meaning only about 55% of the non-significant results that we would expect were generated are actually reported. Adjusting for this selection bias, the model estimates an overall average effect size of 0.13 SD—smaller than the unadjusted random effects estimate—with heterogeneity of <img src="https://latex.codecogs.com/png.latex?%5Chat%5Ctau%20=%200.28">.</p>
<p>The problem with this analysis is that the selection model is set up under the assumption that the effect size estimates are all independent. As a result, the reported standard errors are probably smaller than they should be and the confidence intervals are narrower than they should be. We’ll use cluster bootstrapping to get standard errors and confidence intervals that should better account for effect size dependency.</p>
</section>
<section id="cluster-bootstrapping-a-selection-model" class="level1">
<h1>Cluster Bootstrapping a Selection Model</h1>
<p>In R, the <a href="https://cran.r-project.org/web/packages/boot/boot.pdf"><code>boot</code></a> package provides tools for running a variety of different bootstrap techniques and obtaining confidence intervals based on bootstrap distributions <span class="citation" data-cites="boot">(Canty &amp; Ripley, 2021)</span>. It’s been around for ages and has some very nice features, but it requires a bit of trickery to use it for cluster bootstrapping. The main challenge is that the package functionality is set up under the assumption that every row of the dataset should be treated as an independent observation. To make it work for cluster bootstrapping, we will need a function to fit the selection model, which takes in a dataset with one row per cluster and returns a vector of parameter estimates. The function also has to have an index argument which is a vector of row indexes used to create the bootstrap sample. Here is a skeleton for such a function:</p>
<div class="cell">
<details open="" 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">fit_selmodel <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="cb7-2">    dat,   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># dataset with one row per cluster</span></span>
<span id="cb7-3">    index, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># vector of indexes used to create the bootstrap sample</span></span>
<span id="cb7-4">    ...    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># any further arguments</span></span>
<span id="cb7-5">) { </span>
<span id="cb7-6">  </span>
<span id="cb7-7">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># take subset of data</span></span>
<span id="cb7-8">  boot_dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dat[index,]</span>
<span id="cb7-9">  </span>
<span id="cb7-10">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fit selection model</span></span>
<span id="cb7-11">  </span>
<span id="cb7-12">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compile parameter estimates into a vector</span></span>
<span id="cb7-13">  </span>
<span id="cb7-14">}</span></code></pre></div></div>
</details>
</div>
<section id="clustering-and-unclustering" class="level2">
<h2 class="anchored" data-anchor-id="clustering-and-unclustering">Clustering and unclustering</h2>
<p>The Lehmann dataset has one row per effect size, sometimes with multiple rows per study, so we need to modify the data to have one row per study. There are at least two ways to accomplish this. One option is to create a dataset consisting only of study-level IDs, then merge it back on to the full data to get the effect-size level data:</p>
<div class="cell">
<details open="" 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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Make a dataset of study IDs</span></span>
<span id="cb8-2">cluster_IDs <span class="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;">study =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(lehmann_dat<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>study))</span>
<span id="cb8-3"></span>
<span id="cb8-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glimpse</span>(cluster_IDs)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 41
Columns: 1
$ study &lt;chr&gt; "Banas, 2014 ", "Berthold, 2013 ", "Bigelow et al., 2013 ", "Ble…</code></pre>
</div>
<details open="" 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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Merge with full data</span></span>
<span id="cb10-2">full_dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">merge</span>(cluster_IDs, lehmann_dat, <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;">"study"</span>)</span>
<span id="cb10-3"></span>
<span id="cb10-4">full_dat <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>(study, yi, vi) <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;">glimpse</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 81
Columns: 3
$ study &lt;chr&gt; "Banas, 2014 ", "Berthold, 2013 ", "Bigelow et al., 2013 ", "Big…
$ yi    &lt;dbl&gt; 0.05716727, 0.55411916, 0.31467980, -0.73259462, 0.07921700, -0.…
$ vi    &lt;dbl&gt; 0.10267348, 0.06030579, 0.29520322, 0.53354343, 0.02692608, 0.05…</code></pre>
</div>
</div>
<p>Another option is to use the <a href="https://dplyr.tidyverse.org/reference/nest_by.html"><code>dplyr::nest_by()</code></a> function to nest the data by cluster <span class="citation" data-cites="tidyverse">(Wickham et al., 2019)</span>. Then, we can use <a href="https://tidyr.tidyverse.org/reference/unnest.html"><code>tidyr::unnest()</code></a> to recover the effect size level data <span class="citation" data-cites="tidyverse">(Wickham et al., 2019)</span>. Like so:</p>
<div class="cell">
<details open="" 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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Nest the data for each study</span></span>
<span id="cb12-2">lehmann_nested <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nest_by</span>(lehmann_dat, study, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.key =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>)</span>
<span id="cb12-3"></span>
<span id="cb12-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glimpse</span>(lehmann_nested)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 41
Columns: 2
Rowwise: study
$ study &lt;chr&gt; "Banas, 2014 ", "Berthold, 2013 ", "Bigelow et al., 2013 ", "Ble…
$ data  &lt;list&lt;tibble[,49]&gt;&gt; [&lt;tbl_df[1 x 49]&gt;], [&lt;tbl_df[1 x 49]&gt;], [&lt;tbl_df[2…</code></pre>
</div>
<details open="" 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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Recover the full dataset</span></span>
<span id="cb14-2">full_dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb14-3">  lehmann_nested <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb14-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(data)</span>
<span id="cb14-5"></span>
<span id="cb14-6">full_dat <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>(study, yi, vi) <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;">glimpse</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 81
Columns: 3
Groups: study [41]
$ study &lt;chr&gt; "Banas, 2014 ", "Berthold, 2013 ", "Bigelow et al., 2013 ", "Big…
$ yi    &lt;dbl&gt; 0.05716727, 0.55411916, 0.31467980, -0.73259462, 0.07921700, -0.…
$ vi    &lt;dbl&gt; 0.10267348, 0.06030579, 0.29520322, 0.53354343, 0.02692608, 0.05…</code></pre>
</div>
</div>
<p>We will follow the latter strategy for the remainder of our example.</p>
<p>With this nest-and-unnest approach, we can fill in a little bit more of our function skeleton:</p>
<div class="cell">
<details open="" 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">fit_selmodel <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="cb16-2">    dat,   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># dataset with one row per cluster</span></span>
<span id="cb16-3">    index, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># vector of indexes used to create the bootstrap sample</span></span>
<span id="cb16-4">    ...    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># any further arguments</span></span>
<span id="cb16-5">) { </span>
<span id="cb16-6">  </span>
<span id="cb16-7">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># take subset of data</span></span>
<span id="cb16-8">  boot_dat_cluster <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dat[index, ]</span>
<span id="cb16-9">  </span>
<span id="cb16-10">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># expand to one row per effect size</span></span>
<span id="cb16-11">  boot_dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tidyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(boot_dat_cluster, data)</span>
<span id="cb16-12">  </span>
<span id="cb16-13">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fit selection model</span></span>
<span id="cb16-14">  </span>
<span id="cb16-15">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compile parameter estimates into a vector</span></span>
<span id="cb16-16">  </span>
<span id="cb16-17">}</span></code></pre></div></div>
</details>
</div>
</section>
<section id="selection-model-function" class="level2">
<h2 class="anchored" data-anchor-id="selection-model-function">Selection model function</h2>
<p>Next, we need to complete the function by writing code to fit the selection model. This is a little bit involved because of the way the <code>metafor</code> package implements the Vevea-Hedges selection model. We first need to fit a regular random effects model using <a href="https://wviechtb.github.io/metafor/reference/rma.uni.html"><code>metafor::rma.uni()</code></a>, then pass the result to the <a href="https://wviechtb.github.io/metafor/reference/selmodel.html"><code>metafor::selmodel()</code></a> function to fit a selection model, and then pull out the parameter estimates as a vector. To make the code clearer, we will move this step out into its own function:</p>
<div class="cell">
<details open="" 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">run_sel_model <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>(dat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">025</span>) {</span>
<span id="cb17-2">  </span>
<span id="cb17-3">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># initial random effects model</span></span>
<span id="cb17-4">  RE_mod <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> metafor<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rma.uni</span>(</span>
<span id="cb17-5">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yi =</span> yi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vi =</span> vi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat, <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;">"ML"</span></span>
<span id="cb17-6">  )</span>
<span id="cb17-7">  </span>
<span id="cb17-8">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fit selection model</span></span>
<span id="cb17-9">  res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> metafor<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selmodel</span>(</span>
<span id="cb17-10">    RE_mod, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stepfun"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> steps,</span>
<span id="cb17-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skiphes =</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;"># turn off SE calculation</span></span>
<span id="cb17-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skiphet =</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;"># turn off heterogeneity test</span></span>
<span id="cb17-13">  )</span>
<span id="cb17-14">  </span>
<span id="cb17-15">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compile parameter estimates into a vector</span></span>
<span id="cb17-16">  <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;">beta =</span> res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>beta[,<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;">tau =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>tau2), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">delta =</span> res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>delta[<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb17-17">  </span>
<span id="cb17-18">}</span></code></pre></div></div>
</details>
</div>
<p>Note the use of <code>skiphes</code> and <code>skiphet</code> arguments in the <code>selmodel()</code> call, which skip the calculation of standard errors and skip the calculation of the test for heterogeneity. We don’t need the standard errors here because we’re going to use bootstrapping instead, and we’re not interested in the heterogeneity test. Turning off these calculations saves computational time.</p>
<p>A further complication with fitting a selection model is that the parameter estimates are obtained by maximum likelihood, using an iterative optimization algorithm that sometimes fails to converge. To handle non-convergence, we will pass our function through <a href="https://purrr.tidyverse.org/reference/possibly.html"><code>purrr::possibly()</code></a> so that errors are suppressed, rather than causing everything to grind to a halt <span class="citation" data-cites="tidyverse">(Wickham et al., 2019)</span>. We set the <code>otherwise</code> argument so that non-convergent results are returned as <code>NA</code> values:</p>
<div class="cell">
<details open="" 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">run_sel_model <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">possibly</span>(run_sel_model, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">otherwise =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA_real_</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span></code></pre></div></div>
</details>
</div>
</section>
<section id="a-first-bootstrap" class="level2">
<h2 class="anchored" data-anchor-id="a-first-bootstrap">A first bootstrap</h2>
<p>Here is the completed fitting function called <code>fit_selmodel()</code>:</p>
<div class="cell">
<details open="" 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">fit_selmodel <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>(dat, </span>
<span id="cb19-2">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">index =</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>(dat), </span>
<span id="cb19-3">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>) {</span>
<span id="cb19-4">  </span>
<span id="cb19-5">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># take subset of data</span></span>
<span id="cb19-6">  boot_dat_cluster <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dat[index, ]</span>
<span id="cb19-7">  </span>
<span id="cb19-8">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># expand to one row per effect size</span></span>
<span id="cb19-9">  boot_dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tidyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(boot_dat_cluster, data)</span>
<span id="cb19-10">  </span>
<span id="cb19-11">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fit selection model, return vector</span></span>
<span id="cb19-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">run_sel_model</span>(boot_dat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> steps)</span>
<span id="cb19-13">  </span>
<span id="cb19-14">}</span></code></pre></div></div>
</details>
</div>
<p>First, we take a subset of the data based on the index argument. This generates a bootstrap sample from the original data based on re-sampled clusters. We then use <a href="https://tidyr.tidyverse.org/reference/unnest.html"><code>tidyr::unnest()</code></a> to get the effect size level data for those re-sampled clusters. We then re-fit the model using our <code>run_sel_model()</code> function.</p>
<p>Now let’s apply our function to the Lehmann dataset. We will first need to create a nested version of the dataset, with one row per study:</p>
<div class="cell">
<details open="" 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">lehmann_nested <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nest_by</span>(lehmann_dat, study, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.key =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>)</span></code></pre></div></div>
</details>
</div>
<p>Now we can fit the selection model using <code>fit_sel_model()</code>:</p>
<div class="cell">
<details open="" 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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fit_selmodel</span>(lehmann_nested)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>beta.intrcpt          tau        delta 
   0.1327996    0.2848304    0.5484541 </code></pre>
</div>
</div>
<p>The results reproduce what we saw earlier when we estimated the three parameter selection model.</p>
<p>Now we can bootstrap using the <a href="https://cran.r-project.org/web/packages/boot/boot.pdf"><code>boot::boot()</code></a> function. The inputs to <code>boot()</code> are the nested dataset, the function to fit the selection model, and then any additional arguments passed to <code>fit_selmodel()</code>—here we include an argument for <code>steps</code>—and finally, the number of bootstrap replications:</p>
<div class="cell">
<details open="" 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="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate bootstrap</span></span>
<span id="cb23-2"><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;">20230321</span>)</span>
<span id="cb23-3"></span>
<span id="cb23-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tic</span>()</span>
<span id="cb23-5"></span>
<span id="cb23-6">boots <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boot</span>(</span>
<span id="cb23-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> lehmann_nested,            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># nested dataset</span></span>
<span id="cb23-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistic =</span> fit_selmodel,         <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># function for fitting selection model</span></span>
<span id="cb23-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">025</span>,                     <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># further arguments to the fitting function</span></span>
<span id="cb23-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>                          <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># number of bootstraps</span></span>
<span id="cb23-11">)</span>
<span id="cb23-12"></span>
<span id="cb23-13">time_seq <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toc</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>114.99 sec elapsed</code></pre>
</div>
</div>
<p>This code takes a while to run, but we can speed it up with parallel processing.</p>
</section>
<section id="parallel-processing" class="level2">
<h2 class="anchored" data-anchor-id="parallel-processing">Parallel processing</h2>
<p>The <code>boot</code> package has some handy parallel processing features, but they can be a bit finicky to use here because of how R manages environments across multiple processes. With the above code, we can’t simply turn on parallel processing because the worker processes won’t know where to find the <code>run_sel_model()</code> function that gets called inside <code>fit_selmodel()</code>. To fix this, we include the <code>run_sel_model()</code> function <em>inside</em> our fitting function, as follows:</p>
<div class="cell">
<details open="" 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">fit_selmodel <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>(dat, </span>
<span id="cb25-2">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">index =</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>(dat), </span>
<span id="cb25-3">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.025</span>) {</span>
<span id="cb25-4">  </span>
<span id="cb25-5">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># take subset of data</span></span>
<span id="cb25-6">  boot_dat_cluster <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dat[index, ]</span>
<span id="cb25-7">  </span>
<span id="cb25-8">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># expand to one row per effect size</span></span>
<span id="cb25-9">  boot_dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tidyr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(boot_dat_cluster, data)</span>
<span id="cb25-10">  </span>
<span id="cb25-11">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># build run_selmodel</span></span>
<span id="cb25-12">  run_sel_model <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>(dat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">025</span>) {</span>
<span id="cb25-13">  </span>
<span id="cb25-14">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># initial random effects model</span></span>
<span id="cb25-15">    RE_mod <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> metafor<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rma.uni</span>(</span>
<span id="cb25-16">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yi =</span> yi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">vi =</span> vi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dat, <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;">"ML"</span></span>
<span id="cb25-17">    )</span>
<span id="cb25-18">    </span>
<span id="cb25-19">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fit selection model</span></span>
<span id="cb25-20">    res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> metafor<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selmodel</span>(</span>
<span id="cb25-21">      RE_mod, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stepfun"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> steps,</span>
<span id="cb25-22">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skiphes =</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;"># turn off SE calculation</span></span>
<span id="cb25-23">      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skiphet =</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;"># turn off heterogeneity test</span></span>
<span id="cb25-24">    )</span>
<span id="cb25-25">    </span>
<span id="cb25-26">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compile parameter estimates into a vector</span></span>
<span id="cb25-27">    <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;">beta =</span> res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>beta[,<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;">tau =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>tau2), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">delta =</span> res<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>delta[<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb25-28">    </span>
<span id="cb25-29">  }</span>
<span id="cb25-30">  </span>
<span id="cb25-31">  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;">2</span>L <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(steps)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># calculate total number of model parameters</span></span>
<span id="cb25-32">  </span>
<span id="cb25-33">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># error handling for run_sel_model</span></span>
<span id="cb25-34">  run_sel_model <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> purrr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">possibly</span>(run_sel_model, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">otherwise =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA_real_</span>, p))</span>
<span id="cb25-35">  </span>
<span id="cb25-36">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fit selection model, return vector of parameter estimates</span></span>
<span id="cb25-37">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">run_sel_model</span>(boot_dat, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> steps)</span>
<span id="cb25-38">  </span>
<span id="cb25-39">}</span></code></pre></div></div>
</details>
</div>
<p>Now we can call <code>boot()</code> with options for parallel processing. The machine we used to compile this post has 12 cores. We will use half of the available cores for parallel processing. The configuration of parallel processing will depend on your operating system (different options are available for Mac), so you may need to adapt this code a bit.</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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">ncpus <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> parallel<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">detectCores</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="cb26-2"></span>
<span id="cb26-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate bootstrap</span></span>
<span id="cb26-4"><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;">20230321</span>)</span>
<span id="cb26-5"></span>
<span id="cb26-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tic</span>()</span>
<span id="cb26-7"></span>
<span id="cb26-8">boots <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">boot</span>(</span>
<span id="cb26-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> lehmann_nested,</span>
<span id="cb26-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">statistic =</span> fit_selmodel, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">025</span>,</span>
<span id="cb26-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">R =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1999</span>,</span>
<span id="cb26-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parallel =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"snow"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncpus =</span> ncpus <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># parallel processing options</span></span>
<span id="cb26-13">)</span>
<span id="cb26-14"></span>
<span id="cb26-15">time_par <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toc</span>()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>35.97 sec elapsed</code></pre>
</div>
</div>
<p>Parallel processing is really helpful here. We get 2000 bootstraps in 36 seconds, 3.2 times faster than sequential processing.</p>
</section>
<section id="standard-errors" class="level2">
<h2 class="anchored" data-anchor-id="standard-errors">Standard Errors</h2>
<p>The standard deviations of the bootstrapped parameter estimates can be interpreted as standard errors for the parameter estimates that take into account the dependence structure of the effect size estimates. Here is a table comparing the cluster-bootstrapped standard errors to the model-based standard errors generated by <code>selmodel()</code>:</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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">est <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> boots<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t0 <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># original parameter estimates</span></span>
<span id="cb28-2"></span>
<span id="cb28-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># calculate bootstrap SEs</span></span>
<span id="cb28-4">boot_SE <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apply</span>(boots<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, sd, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)  </span>
<span id="cb28-5"></span>
<span id="cb28-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># calculate model-based SEs</span></span>
<span id="cb28-7">model_SE <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">with</span>(RE_sel, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(se, se.tau2 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(tau2)), se.delta[<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]))</span>
<span id="cb28-8"></span>
<span id="cb28-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># make a table</span></span>
<span id="cb28-10">res <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb28-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Parameter =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">names</span>(est),</span>
<span id="cb28-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Est =</span> est,</span>
<span id="cb28-13">  <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;">SE(bootstrap)</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> boot_SE,</span>
<span id="cb28-14">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE(model)</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> model_SE,</span>
<span id="cb28-15">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SE(bootstrap) / SE(model)</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> boot_SE <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> model_SE</span>
<span id="cb28-16">)</span></code></pre></div></div>
</details>
</div>
<div class="cell">
<div class="cell-output-display">
<table class="table table-striped table-condensed caption-top table-sm small">
<thead>
<tr class="header">
<th style="text-align: left;" data-quarto-table-cell-role="th">Parameter</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">Est</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">SE(bootstrap)</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">SE(model)</th>
<th style="text-align: right;" data-quarto-table-cell-role="th">SE(bootstrap) / SE(model)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">beta.intrcpt</td>
<td style="text-align: right;">0.133</td>
<td style="text-align: right;">0.113</td>
<td style="text-align: right;">0.066</td>
<td style="text-align: right;">1.732</td>
</tr>
<tr class="even">
<td style="text-align: left;">tau</td>
<td style="text-align: right;">0.285</td>
<td style="text-align: right;">0.148</td>
<td style="text-align: right;">0.046</td>
<td style="text-align: right;">3.234</td>
</tr>
<tr class="odd">
<td style="text-align: left;">delta</td>
<td style="text-align: right;">0.548</td>
<td style="text-align: right;">0.780</td>
<td style="text-align: right;">0.250</td>
<td style="text-align: right;">3.127</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The standard errors based on cluster bootstrapping are all substantially larger than the model-based standard errors, which don’t account for dependence.</p>
</section>
<section id="confidence-intervals" class="level2">
<h2 class="anchored" data-anchor-id="confidence-intervals">Confidence Intervals</h2>
<p>For reporting results from this sort of analysis, it is useful to provide confidence intervals along with the model parameter estimates and standard errors. These can be calculated using the <a href="https://cran.r-project.org/web/packages/boot/boot.pdf"><code>boot::boot_ci()</code></a> function. This function provides several different types of confidence intervals; for illustration, we will stick with simple percentile confidence intervals, which are calculated by taking percentiles of the bootstrap distribution of each parameter estimate. To use the function, we’ll specify the type of confidence interval and the index of the parameter we want. An index of 1 is for the overall average effect size:</p>
<div class="cell">
<details open="" 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;">boot.ci</span>(boots, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"perc"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">index =</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 overall average ES</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 1995 bootstrap replicates

CALL : 
boot.ci(boot.out = boots, type = "perc", index = 1)

Intervals : 
Level     Percentile     
95%   (-0.0038,  0.4171 )  
Calculations and Intervals on Original Scale</code></pre>
</div>
</div>
<p>Here is the confidence interval for between-study heterogeneity:</p>
<div class="cell">
<details open="" 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;">boot.ci</span>(boots, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"perc"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">index =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># For heterogeneity</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 1995 bootstrap replicates

CALL : 
boot.ci(boot.out = boots, type = "perc", index = 2)

Intervals : 
Level     Percentile     
95%   ( 0.001,  0.489 )  
Calculations and Intervals on Original Scale</code></pre>
</div>
</div>
<p>And for the selection weight:</p>
<div class="cell">
<details open="" 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;">boot.ci</span>(boots, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"perc"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">index =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># For selection weight</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 1995 bootstrap replicates

CALL : 
boot.ci(boot.out = boots, type = "perc", index = 3)

Intervals : 
Level     Percentile     
95%   ( 0.0574,  2.7536 )  
Calculations and Intervals on Original Scale</code></pre>
</div>
</div>
<p>Percentile confidence intervals can be asymmetric, and here the confidence interval for the selection weight parameter is notably asymmetric. The end-points of the confidence interval range from 0.057 (which represents very strong selective reporting, with only 6% of non-significant results reported) to 2.754 (which represents very strong selection <em>against</em> affirmative results).<sup>2</sup> So, overall we can’t really draw any strong conclusions about the strength of selective reporting.</p>
</section>
</section>
<section id="conclusion" class="level1">
<h1>Conclusion</h1>
<p>In this post, we’ve demonstrated how to code a cluster-level bootstrap for a three parameter version of the Vevea-Hedges selection model. We think this cluster-bootstrapping technique is interesting and promising because it can be applied with a very broad swath of models and methods to investigate selective reporting. For instance, the code we’ve demonstrated could be modified by:</p>
<ul>
<li>using a meta-regression model instead of just a summary meta-analysis;</li>
<li>using a different form of selection function such as the beta-weight model proposed by Citkowicz and Vevea <span class="citation" data-cites="Citkowicz2017parsimonious">(2017)</span> or a more elaborate step function with multiple steps; or</li>
<li>using a step function model applied across subsets of effect sizes, as in <span class="citation" data-cites="Coburn2015publication">Coburn &amp; Vevea (2015)</span>.</li>
</ul>
<p>The <a href="https://wviechtb.github.io/metafor/">metafor</a> package implements an expansive set of selection models with the <a href="https://wviechtb.github.io/metafor/reference/selmodel.html"><code>selmodel</code></a> function, so one could really just swap specifications in and out. In principle, the cluster-level bootstrap could also be used in combination with other forms of selective reporting analysis such as PET-PEESE <span class="citation" data-cites="rodgers2020evaluating">(although with such regression adjustments, cluster-robust variance estimation is also an option, see Rodgers &amp; Pustejovsky, 2020)</span> or Copas-style sensitivity analyses <span class="citation" data-cites="Copas2001sensitivity">(Copas &amp; Shi, 2001)</span>.</p>
<p>We are currently studying the performance of bootstrapping a three parameter selection model in some big Monte Carlo simulations. Based on some very preliminary results, it looks like the cluster bootstrapped selection model provides confidence intervals with reasonable coverage levels. We have more to do before we share these results, so again we want to emphasize that what we have demonstrated in this post is <em>experimental</em> and <em>exploratory</em>.</p>
<p>Further questions we need to investigate are how things work if we include covariates in the selection model, whether there are better variations of the bootstrap than what we have demonstrated here <span class="citation" data-cites="xu2020applications">(e.g., the fractionally weighted bootstrapping, Xu et al., 2020)</span>, and the limits of this method in terms of the number of studies needed for adequate performance. If things pan out, we also plan to turn the workflow we’ve demonstrated here into some more user-friendly functions, perhaps as part of the <a href="https://meghapsimatrix.github.io/wildmeta/index.html">wildmeta</a> package.</p>
</section>
<section id="references" class="level1">



<!-- -->


</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" data-line-spacing="2">
<div id="ref-Becker2000multivariate" class="csl-entry">
Becker, B. J. (2000). <span class="nocase">Multivariate Meta-analysis</span>. In S. D. Brown &amp; H. E. A. Tinsley (Eds.), <em>Handbook of applied multivariate statistics and mathematical modeling</em> (pp. 499–525). Academic Press. <a href="https://doi.org/10.1016/B978-012691360-6/50018-5">https://doi.org/10.1016/B978-012691360-6/50018-5</a>
</div>
<div id="ref-begg1994operating" class="csl-entry">
Begg, C. B., &amp; Mazumdar, M. (1994). Operating characteristics of a rank correlation test for publication bias. <em>Biometrics</em>, <em>50</em>(4), 1088. <a href="https://doi.org/10.2307/2533446">https://doi.org/10.2307/2533446</a>
</div>
<div id="ref-boos2003introduction" class="csl-entry">
Boos, D. D. (2003). Introduction to the bootstrap world. <em>Statistical Science</em>, <em>18</em>(2), 168–174.
</div>
<div id="ref-cameron2008bootstrap" class="csl-entry">
Cameron, A. C., Gelbach, J. B., &amp; Miller, D. L. (2008). Bootstrap-based improvements for inference with clustered errors. <em>The Review of Economics and Statistics</em>, <em>90</em>(3), 414–427.
</div>
<div id="ref-boot" class="csl-entry">
Canty, A., &amp; Ripley, B. D. (2021). <em>Boot: Bootstrap r (s-plus) functions</em>.
</div>
<div id="ref-Citkowicz2017parsimonious" class="csl-entry">
Citkowicz, M., &amp; Vevea, J. L. (2017). <span class="nocase">A parsimonious weight function for modeling publication bias</span>. <em>Psychological Methods</em>, <em>22</em>(1), 28–41. <a href="https://doi.org/10.1037/met0000119">https://doi.org/10.1037/met0000119</a>
</div>
<div id="ref-Coburn2015publication" class="csl-entry">
Coburn, K. M., &amp; Vevea, J. L. (2015). <span class="nocase">Publication bias as a function of study characteristics</span>. <em>Psychological Methods</em>, <em>20</em>(3), 310–330. <a href="https://doi.org/10.1037/met0000046">https://doi.org/10.1037/met0000046</a>
</div>
<div id="ref-Copas2001sensitivity" class="csl-entry">
Copas, J. B., &amp; Shi, J. Q. (2001). <span class="nocase">A sensitivity analysis for publication bias in systematic reviews.</span> <em>Statistical Methods in Medical Research</em>, <em>10</em>, 251–265.
</div>
<div id="ref-duval2000nonparametric" class="csl-entry">
Duval, S., &amp; Tweedie, R. (2000). A nonparametric "trim and fill" method of accounting for publication bias in meta-analysis. <em>Journal of the American Statistical Association</em>, <em>95</em>(449), 89–98. <a href="https://doi.org/10.2307/2669529">https://doi.org/10.2307/2669529</a>
</div>
<div id="ref-egger1997bias" class="csl-entry">
Egger, M., Smith, G. D., Schneider, M., &amp; Minder, C. (1997). Bias in meta-analysis detected by a simple, graphical test. <em>BMJ</em>, <em>315</em>(7109), 629–634.
</div>
<div id="ref-hedges1992modeling" class="csl-entry">
Hedges, L. V. (1992). Modeling publication selection effects in meta-analysis. <em>Statistical Science</em>, <em>7</em>(2), 246–255. <a href="https://doi.org/10.1214/ss/1177011364">https://doi.org/10.1214/ss/1177011364</a>
</div>
<div id="ref-Hedges2010robust" class="csl-entry">
Hedges, L. V., Tipton, E., &amp; Johnson, M. C. (2010). <span class="nocase">Robust variance estimation in meta-regression with dependent effect size estimates</span>. <em>Research Synthesis Methods</em>, <em>1</em>(1), 39–65. <a href="https://doi.org/10.1002/jrsm.5">https://doi.org/10.1002/jrsm.5</a>
</div>
<div id="ref-Hedges1996estimating" class="csl-entry">
Hedges, L. V., &amp; Vevea, J. L. (1996). <span class="nocase">Estimating effect size under publication bias: Small sample properties and robustness of a random effects selection model</span>. <em>Journal of Educational and Behavioral Statistics</em>, <em>21</em>(4), 299. <a href="https://doi.org/10.3102/10769986021004299">https://doi.org/10.3102/10769986021004299</a>
</div>
<div id="ref-hedges2005selection" class="csl-entry">
Hedges, L. V., &amp; Vevea, J. L. (2005). Selection method approaches. In <em>Publication bias in meta-analysis: Prevention, assessment, and adjustments</em> (pp. 145–174). John Wiley &amp; Sons.
</div>
<div id="ref-ioannidis2007exploratory" class="csl-entry">
Ioannidis, J. P. A., &amp; Trikalinos, T. A. (2007). An exploratory test for an excess of significant findings. <em>Clinical Trials</em>, <em>4</em>(3), 245–253. <a href="https://doi.org/10.1177/1740774507079441">https://doi.org/10.1177/1740774507079441</a>
</div>
<div id="ref-lehmann2018metaanalysis" class="csl-entry">
Lehmann, G. K., Elliot, A. J., &amp; Calin-Jageman, R. J. (2018). Meta-analysis of the effect of red on perceived attractiveness. <em>Evolutionary Psychology</em>, <em>16</em>(4), 147470491880241. <a href="https://doi.org/10.1177/1474704918802412">https://doi.org/10.1177/1474704918802412</a>
</div>
<div id="ref-mathur2020sensitivity" class="csl-entry">
Mathur, M. B., &amp; VanderWeele, T. J. (2020). Sensitivity analysis for publication bias in meta‐analyses. <em>Journal of the Royal Statistical Society: Series C (Applied Statistics)</em>, <em>69</em>(5), 1091–1119. <a href="https://doi.org/10.1111/rssc.12440">https://doi.org/10.1111/rssc.12440</a>
</div>
<div id="ref-mcshane2016adjusting" class="csl-entry">
McShane, B. B., Böckenholt, U., &amp; Hansen, K. T. (2016). Adjusting for publication bias in meta-analysis an evaluation of selection methods and some cautionary notes. <em>Perspectives on Psychological Science</em>, <em>11</em>(5), 730–749. <a href="http://pps.sagepub.com/content/11/5/730.short">http://pps.sagepub.com/content/11/5/730.short</a>
</div>
<div id="ref-rodgers2020evaluating" class="csl-entry">
Rodgers, M. A., &amp; Pustejovsky, J. E. (2020). Evaluating meta-analytic methods to detect selective reporting in the presence of dependent effect sizes. <em>Psychological Methods</em>. <a href="https://doi.org/10.1037/met0000300">https://doi.org/10.1037/met0000300</a>
</div>
<div id="ref-rothstein2006publication" class="csl-entry">
Rothstein, H. R., Sutton, A. J., &amp; Borenstein, M. (2006). <em>Publication bias in meta-analysis: Prevention, assessment and adjustments</em>. John Wiley &amp; Sons.
</div>
<div id="ref-simonsohn2014pcurve" class="csl-entry">
Simonsohn, U., Nelson, L. D., &amp; Simmons, J. P. (2014). P-curve and effect size: Correcting for publication bias using only significant results. <em>Perspectives on Psychological Science</em>, <em>9</em>(6), 666–681. <a href="https://doi.org/10.1177/1745691614553988">https://doi.org/10.1177/1745691614553988</a>
</div>
<div id="ref-stanley2008metaregression" class="csl-entry">
Stanley, T. D. (2008). Meta-regression methods for detecting and estimating empirical effects in the presence of publication selection*. <em>Oxford Bulletin of Economics and Statistics</em>, <em>70</em>(1), 103–127. <a href="https://doi.org/10.1111/j.1468-0084.2007.00487.x">https://doi.org/10.1111/j.1468-0084.2007.00487.x</a>
</div>
<div id="ref-stanley2014metaregression" class="csl-entry">
Stanley, T. D., &amp; Doucouliagos, H. (2014). Meta-regression approximations to reduce publication selection bias. <em>Research Synthesis Methods</em>, <em>5</em>(1), 60–78.
</div>
<div id="ref-sterne2001funnel" class="csl-entry">
Sterne, J. A. C., &amp; Egger, M. (2001). Funnel plots for detecting bias in meta-analysis: Guidelines on choice of axis. <em>Journal of Clinical Epidemiology</em>, <em>54</em>(10), 1046–1055.
</div>
<div id="ref-Sterne2011recommendations" class="csl-entry">
Sterne, J. A. C., Sutton, A. J., Ioannidis, J. P. A., Terrin, N., Jones, D. R., Lau, J., Carpenter, J., Rücker, G., Harbord, R. M., Schmid, C. H., Tetzlaff, J., Deeks, J. J., Peters, J. L., Macaskill, P., Schwarzer, G., Duval, S., Altman, D. G., Moher, D., &amp; Higgins, J. P. T. (2011). <span class="nocase">Recommendations for examining and interpreting funnel plot asymmetry in meta-analyses of randomised controlled trials.</span> <em>BMJ</em>, <em>343</em>, d4002. <a href="https://doi.org/10.1136/bmj.d4002">https://doi.org/10.1136/bmj.d4002</a>
</div>
<div id="ref-sutton2009publication" class="csl-entry">
Sutton, A. (2009). Publication bias. In <em>The handbook of research synthesis and meta-analysis</em> (pp. 435–445). Russell Sage Foundation.
</div>
<div id="ref-vanaert2016conducting" class="csl-entry">
van Aert, R. C. M., Wicherts, J. M., &amp; van Assen, M. A. L. M. (2016). Conducting meta-analyses based on <em>p</em> values: Reservations and recommendations for applying <em>p</em> -uniform and <em>p</em> -curve. <em>Perspectives on Psychological Science</em>, <em>11</em>(5), 713–729. <a href="https://doi.org/10.1177/1745691616650874">https://doi.org/10.1177/1745691616650874</a>
</div>
<div id="ref-VanAssen2015meta" class="csl-entry">
van Assen, M. A. L. M., van Aert, R. C. M., &amp; Wicherts, J. M. (2015). <span class="nocase">Meta-analysis using effect size distributions of only statistically significant studies</span>. <em>Psychological Methods</em>, <em>20</em>(3), 293–309. https://doi.org/<a href="http://dx.doi.org/10.1037/met0000025">http://dx.doi.org/10.1037/met0000025</a>
</div>
<div id="ref-VandenNoortgate2013threelevel" class="csl-entry">
Van den Noortgate, W., López-López, J. A., Marín-Martínez, F., &amp; Sánchez-Meca, J. (2013). <span class="nocase">Three-level meta-analysis of dependent effect sizes</span>. <em>Behavior Research Methods</em>, <em>45</em>(2), 576–594. <a href="https://doi.org/10.3758/s13428-012-0261-6">https://doi.org/10.3758/s13428-012-0261-6</a>
</div>
<div id="ref-vevea1995general" class="csl-entry">
Vevea, J. L., &amp; Hedges, L. V. (1995). A general linear model for estimating effect size in the presence of publication bias. <em>Psychometrika</em>, <em>60</em>(3), 419–435. <a href="https://doi.org/10.1007/BF02294384">https://doi.org/10.1007/BF02294384</a>
</div>
<div id="ref-vevea2005publication" class="csl-entry">
Vevea, J. L., &amp; Woods, C. M. (2005). Publication bias in research synthesis: Sensitivity analysis using a priori weight functions. <em>Psychological Methods</em>, <em>10</em>(4), 428–443. <a href="https://doi.org/10.1037/1082-989X.10.4.428">https://doi.org/10.1037/1082-989X.10.4.428</a>
</div>
<div id="ref-Viechtbauer2010conducting" class="csl-entry">
Viechtbauer, W. (2010). <span class="nocase">Conducting meta-analyses in R with the metafor package</span>. <em>Journal of Statistical Software</em>, <em>36</em>(3), 1–48.
</div>
<div id="ref-metadat" class="csl-entry">
White, T., Noble, D., Senior, A., Hamilton, W. K., &amp; Viechtbauer, W. (2022). <em>Metadat: Meta-analysis datasets</em>. <a href="https://CRAN.R-project.org/package=metadat">https://CRAN.R-project.org/package=metadat</a>
</div>
<div id="ref-tidyverse" class="csl-entry">
Wickham, H., Averick, M., Bryan, J., Chang, W., McGowan, L. D., François, R., Grolemund, G., Hayes, A., Henry, L., Hester, J., Kuhn, M., Pedersen, T. L., Miller, E., Bache, S. M., Müller, K., Ooms, J., Robinson, D., Seidel, D. P., Spinu, V., … Yutani, H. (2019). Welcome to the <span class="nocase">tidyverse</span>. <em>Journal of Open Source Software</em>, <em>4</em>(43), 1686. <a href="https://doi.org/10.21105/joss.01686">https://doi.org/10.21105/joss.01686</a>
</div>
<div id="ref-xu2020applications" class="csl-entry">
Xu, L., Gotwalt, C., Hong, Y., King, C. B., &amp; Meeker, W. Q. (2020). Applications of the fractional-random-weight bootstrap. <em>The American Statistician</em>, <em>74</em>(4), 345–358. <a href="https://doi.org/10.1080/00031305.2020.1731599">https://doi.org/10.1080/00031305.2020.1731599</a>
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Technically, these parameters <img src="https://latex.codecogs.com/png.latex?%5Clambda_1,%5Clambda_2,%5Clambda_3"> are not absolute probabilities but instead <em>relative</em> risks of being reported, compared to a reference range of <img src="https://latex.codecogs.com/png.latex?p">-values. In the above example, they would be defined relative to the probability of being reported for an effect size estimate with <img src="https://latex.codecogs.com/png.latex?p%20%5Cleq%20.01">.↩︎</p></li>
<li id="fn2"><p>Compare this to the model-based confidence interval of <img src="https://latex.codecogs.com/png.latex?%5B0.059,%201.037%5D">.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>bootstrap</category>
  <category>dependent effect sizes</category>
  <category>meta-analysis</category>
  <category>publication bias</category>
  <category>programming</category>
  <category>Rstats</category>
  <guid>https://jepusto.netlify.app/posts/cluster-bootstrap-selection-model/</guid>
  <pubDate>Thu, 30 Mar 2023 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Cohen’s \(d_z\) makes me dizzy when considering measurement error</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/dizzy-for-d-z/</link>
  <description><![CDATA[ 





<p>Meta-analyses in education, psychology, and related fields rely heavily of Cohen’s <img src="https://latex.codecogs.com/png.latex?d">, or the standardized mean difference effect size, for quantitatively describing the magnitude and direction of intervention effects. In these fields, Cohen’s <img src="https://latex.codecogs.com/png.latex?d"> is so pervasive that its use is nearly automatic, and analysts rarely question its utility or consider alternatives (response ratios, anyone? POMP?). Despite this state of affairs, working with Cohen’s <img src="https://latex.codecogs.com/png.latex?d"> is theoretically challenging because the standardized mean difference metric does not have a singular definition. Rather, its definition depends on the choice of the standardizing variance used in the denominator.<sup>1</sup></p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cdef%5CPr%7B%7B%5Ctext%7BPr%7D%7D%7D%0A%5Cdef%5CE%7B%7B%5Ctext%7BE%7D%7D%7D%0A%5Cdef%5CVar%7B%7B%5Ctext%7BVar%7D%7D%7D%0A%5Cdef%5CCov%7B%7B%5Ctext%7BCov%7D%7D%7D%0A%5Cdef%5Ccor%7B%7B%5Ctext%7Bcor%7D%7D%7D%0A%5Cdef%5Cbm%7B%5Cmathbf%7D%0A%5Cdef%5Cbs%7B%5Cboldsymbol%7D%0A"></p>
<p>In this post, I’m going to mull over how measurement error and design decisions influence the metric definition of Cohen’s <img src="https://latex.codecogs.com/png.latex?d"> in basic within-group experimental designs. The distorting effects of measurement error has long been a source of concern within psychometric meta-analysis, a perspective associated with the work of <a href="https://methods.sagepub.com/book/methods-of-meta-analysis-3e">Frank Schmidt and Jack Hunter</a>, and measurement-error corrections are well developed and often applied in meta-analyses of correlations. Straight-forward measurement-error corrections have also been described for Cohen’s <img src="https://latex.codecogs.com/png.latex?d"> from between-group designs (see recent work by <a href="https://psyarxiv.com/9mpbn/">Brenton Wiernik and Jeff Dahlke</a>). However, I have literally never seen a meta-analytic application that applied these corrections and I have thus far been unable to locate work on such corrections specifically for effect sizes in within-group designs.<sup>2</sup> So, time to muck about…</p>
<section id="effect-size-definitions-in-within-group-designs" class="level2">
<h2 class="anchored" data-anchor-id="effect-size-definitions-in-within-group-designs">Effect size definitions in within-group designs</h2>
<p>In basic between-group designs, the only variances in the model are the within-group variances, so the choice of standardizing variance is limited to a) the singular population variance, assuming it is homogeneous across groups, b) the variance of one group, or c) the average of the variances in each group. In most applications, homogeneity is assumed (often without much reflection), version (a) of Cohen’s <img src="https://latex.codecogs.com/png.latex?d"> is estimated, and the meta-analyst can go along their merry way. For sake of succinctness, I’ll call this effect size <img src="https://latex.codecogs.com/png.latex?d_%7Bb%7D">, where the <img src="https://latex.codecogs.com/png.latex?b"> indicates the usual version for basic between-group designs.</p>
<p>For within-group or repeated measures designs, the set of choices is more involved and includes a) standardizing by the across-participant variance in one condition (or both conditions, assuming homogeneity) or b) standardizing by the variance of the difference scores. The former approach is sometimes called <img src="https://latex.codecogs.com/png.latex?d_%7Bav%7D"><sup>3</sup>, the latter is called <img src="https://latex.codecogs.com/png.latex?d_z"><sup>4</sup>. The <img src="https://latex.codecogs.com/png.latex?d_%7Bav%7D"> metric uses the same standardizing variance as the <img src="https://latex.codecogs.com/png.latex?d"> from a basic between-group design, and so results from both types of designs are, in principle, on the same scale.</p>
<p>In the context of meta-analysis, the comparability of <img src="https://latex.codecogs.com/png.latex?d_b"> and <img src="https://latex.codecogs.com/png.latex?d_%7Bav%7D"> is useful when working with a set of studies that include both types of designs. On the other hand, in meta-analyses that consist solely of within-group or repeated measures designs, comparability with <img src="https://latex.codecogs.com/png.latex?d_b"> may be less of a priority and one could consider using <img src="https://latex.codecogs.com/png.latex?d_z"> for synthesis. Purely on a pragmatic level, using <img src="https://latex.codecogs.com/png.latex?d_z"> might be attractive because the only pieces of information needed to calculate it are the total sample size and the <img src="https://latex.codecogs.com/png.latex?t"> statistic (or <img src="https://latex.codecogs.com/png.latex?p">-value) from the comparison between conditions. In contrast, calculating <img src="https://latex.codecogs.com/png.latex?d_%7Bav%7D"> also requires the between-participant standard deviations from one or both groups, which primary studies might not always report.</p>
<p>Going in to this exercise, I had the notion that measurement error would affect <img src="https://latex.codecogs.com/png.latex?d_z"> to a greater degree than <img src="https://latex.codecogs.com/png.latex?d_%7Bav%7D"> because <img src="https://latex.codecogs.com/png.latex?d_z"> involves difference scores and difference scores get hit by measurement error twice. Does this intuition hold up? Let me try to formalize things a bit.</p>
</section>
<section id="a-within-group-design-with-measurement-error" class="level2">
<h2 class="anchored" data-anchor-id="a-within-group-design-with-measurement-error">A within-group design with measurement error</h2>
<p>Suppose we have a within-group design involving two conditions, where participants are assessed on <img src="https://latex.codecogs.com/png.latex?K"> trials under each condition. Let <img src="https://latex.codecogs.com/png.latex?Y_%7Bijk%7D"> denote the outcome from trial <img src="https://latex.codecogs.com/png.latex?k"> for participant <img src="https://latex.codecogs.com/png.latex?j"> under condition <img src="https://latex.codecogs.com/png.latex?i">, for <img src="https://latex.codecogs.com/png.latex?i%20=%201,2">, <img src="https://latex.codecogs.com/png.latex?j%20=%201,...,N">, and <img src="https://latex.codecogs.com/png.latex?k%20=%201,...,K">. A basic model for this set-up is <img src="https://latex.codecogs.com/png.latex?%0AY_%7Bijk%7D%20=%20%5Cmu_i%20+%20u_%7Bij%7D%20+%20e_%7Bijk%7D%0A"> where <img src="https://latex.codecogs.com/png.latex?u_%7B1j%7D"> and <img src="https://latex.codecogs.com/png.latex?u_%7B2j%7D"> are participant-specific errors in the true scores under each condition and the <img src="https://latex.codecogs.com/png.latex?e_%7Bijk%7D">’s are measurement errors. For simplicity, I will assume that:</p>
<ul>
<li>the true-score variance is equal across conditions, with <img src="https://latex.codecogs.com/png.latex?%5CVar(u_%7Bij%7D)%20=%20%5Csigma%5E2"> for <img src="https://latex.codecogs.com/png.latex?i%20=%201,2">,</li>
<li>the true scores are correlated across conditions, <img src="https://latex.codecogs.com/png.latex?%5Ccor(u_%7B1j%7D,%20u_%7B2j%7D)%20=%20%5Crho">, and</li>
<li>measurement errors are uncorrelated and have homogeneous variance across conditions, with <img src="https://latex.codecogs.com/png.latex?%5CVar(e_%7Bijk%7D)%20=%20%5Cpsi%5E2">.</li>
</ul>
<p>Let <img src="https://latex.codecogs.com/png.latex?%5Cphi%20=%20%5Csigma%5E2%20/%20(%5Csigma%5E2%20+%20%5Cpsi%5E2)"> denote the reliability (intra-class correlation) of a single observed score. Note that we can write <img src="https://latex.codecogs.com/png.latex?%5Cpsi%5E2"> in terms of the reliability and true-score variance as <img src="https://latex.codecogs.com/png.latex?%5Cpsi%5E2%20=%20%5Csigma%5E2%20%5Ctimes%20%5Cfrac%7B1%20-%20%5Cphi%7D%7B%5Cphi%7D">.</p>
<p>Under this model, there are several different standardized mean difference metrics that we could consider. Since measurement reliability might vary from study to study, it would make sense to define the metric in terms of true score variances alone, as <img src="https://latex.codecogs.com/png.latex?%0A%5Cdelta_%7Bav%7D%20=%20%5Cfrac%7B%5Cmu_2%20-%20%5Cmu_1%7D%7B%5Csigma%7D%0A"> or in terms of the variance of the difference in true scores, as <img src="https://latex.codecogs.com/png.latex?%0A%5Cdelta_z%20=%20%5Cfrac%7B%5Cmu_2%20-%20%5Cmu_1%7D%7B%5Csigma%20%5Csqrt%7B2(1%20-%20%5Crho)%7D%7D.%0A"> However, we don’t directly observe the true scores, and we can’t estimate their variance unless we have information about score reliabilities. Thus, meta-analysts will usually need to calculate effect sizes in terms of <em>observed</em> scores that include measurement error.</p>
<p>Suppose that the analysis is conducted by taking the average of the <img src="https://latex.codecogs.com/png.latex?K"> trials for each participant under each condition, <img src="https://latex.codecogs.com/png.latex?%5Cbar%7BY%7D_%7Bij%7D%20=%20%5Cfrac%7B1%7D%7BK%7D%20%5Csum_%7Bk=1%7D%5EK%20Y_%7Bijk%7D">, and conducting the analysis using these mean scores. The variance of the mean scores is <img src="https://latex.codecogs.com/png.latex?%0A%5CVar(%5Cbar%7BY%7D_%7Bij%7D)%20=%20%5Csigma%5E2%20%5Cleft(1%20+%20%5Cfrac%7B1%20-%20%5Cphi%7D%7B%5Cphi%20K%7D%5Cright),%0A"> so we can define the observed-score standardized mean difference using raw score standardization as <img src="https://latex.codecogs.com/png.latex?%0A%5Ctilde%5Cdelta_%7Bav%7D%20=%20%5Cfrac%7B%5Cmu_2%20-%20%5Cmu_1%7D%7B%5Csigma%20%5Csqrt%7B1%20+%20%5Cfrac%7B1%20-%20%5Cphi%7D%7B%5Cphi%20K%7D%7D%7D%20=%20%5Cfrac%7B1%7D%7B%5Csqrt%7B1%20+%20%5Cfrac%7B1%20-%20%5Cphi%7D%7B%5Cphi%20K%7D%7D%7D%20%5Ctimes%20%5Cdelta_%7Bav%7D.%0A"> From this expression, we can see that measurement error attenuates the true-score effect size because the multiplier term is always going to be less than one.</p>
<p>Similarly, the variance of the observed difference scores is <img src="https://latex.codecogs.com/png.latex?%0A%5CVar(%5Cbar%7BY%7D_%7B2j%7D%20-%20%5Cbar%7BY%7D_%7B1j%7D)%20=2%20%5Csigma%5E2%20%5Cleft(1%20-%20%5Crho%20+%20%5Cfrac%7B1%20-%20%5Cphi%7D%7B%5Cphi%20K%7D%5Cright),%0A"> so we can define the observed-score standardized mean difference using change score standardization as <img src="https://latex.codecogs.com/png.latex?%0A%5Ctilde%5Cdelta_z%20=%20%5Cfrac%7B%5Cmu_2%20-%20%5Cmu_1%7D%7B%5Csigma%20%5Csqrt%7B2%20%5Cleft(1%20-%20%5Crho%20+%20%5Cfrac%7B1%20-%20%5Cphi%7D%7B%5Cphi%20K%7D%5Cright)%7D%7D%20=%20%5Csqrt%7B%5Cfrac%7B1%20-%20%5Crho%7D%7B1%20-%20%5Crho%20+%20%5Cfrac%7B1%20-%20%5Cphi%7D%7B%5Cphi%20K%7D%7D%7D%20%5Ctimes%20%5Cdelta_z.%0A"> Again, we can see that measurement error attenuates the true-score effect size because the multiplier term is always going to be less than one. However, unlike with <img src="https://latex.codecogs.com/png.latex?d_%7Bav%7D">, the attenuation factor here depends on <img src="https://latex.codecogs.com/png.latex?%5Crho"> in addition to <img src="https://latex.codecogs.com/png.latex?%5Cphi"> and <img src="https://latex.codecogs.com/png.latex?K">. This additional term in the correction factor is one indication that <img src="https://latex.codecogs.com/png.latex?d_z"> might be less desirable for meta-analysis. Correcting <img src="https://latex.codecogs.com/png.latex?d_z"> for the distortion from measurement error would require estimates of both the true-score correlation and the reliability of the scores, whereas correcting <img src="https://latex.codecogs.com/png.latex?d_%7Bav%7D"> would require only the latter.</p>
</section>
<section id="meta-analysis" class="level2">
<h2 class="anchored" data-anchor-id="meta-analysis">Meta-analysis</h2>
<p>The relationships between the true-score effect sizes and the analogous observed score effect sizes starts to be a problem when we consider a meta-analysis of multiple primary studies. Primary studies will often use different instruments and procedures for measuring outcomes (necessitating the use of some standardized effect size), and those differences in instruments and procedures might come along with differences in score reliability as well as variation in the number of trials collected per condition (and plenty of other things, such as sample size, participant characteristics, etc.). Procedural heterogeneity like this creates two potential challenges for meta-analysis: bias in average effect sizes and extra heterogeneity in the distribution of effect sizes. Both could make findings from a meta-analysis more difficult to interpret, although I will argue that extra heterogeneity is more concerning than bias.</p>
<p>To illustrate, let’s now imagine that the parameters of the within-group study design, <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D"> or <img src="https://latex.codecogs.com/png.latex?%5Cdelta_z">, <img src="https://latex.codecogs.com/png.latex?%5Crho">, <img src="https://latex.codecogs.com/png.latex?%5Cphi">, and <img src="https://latex.codecogs.com/png.latex?K"> are random variables, drawn from the distribution of parameters across a population of hypothetical studies.</p>
<section id="a-model-for-delta_av" class="level3">
<h3 class="anchored" data-anchor-id="a-model-for-delta_av">A model for <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D"></h3>
<p>Let’s first consider <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D"> and assume that it follows a random effects model, with <img src="https://latex.codecogs.com/png.latex?%0A%5Cdelta_%7Bav%7D%20%5Csim%20N%5Cleft(%5Cmu,%20%5Ctau%5E2%5Cright).%0A"> Let’s also assume that the remaining parameters <img src="https://latex.codecogs.com/png.latex?%5Crho">, <img src="https://latex.codecogs.com/png.latex?%5Cphi">, and <img src="https://latex.codecogs.com/png.latex?K"> are independent of <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D">. These parameters determine the attenuation factor <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D%20=%20%5Cleft(1%20+%20%5Cfrac%7B1%20-%20%5Cphi%7D%7B%5Cphi%20K%7D%5Cright)%5E%7B-1/2%7D">, which relates the observed-score effect size parameter to the true score effect size parameter.</p>
<p>The bias of <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D"> is therefore <img src="https://latex.codecogs.com/png.latex?%0A%5CE%5Cleft(%5Ctilde%5Cdelta_%7Bav%7D%5Cright)%20=%20%5CE%5Cleft(A_%7Bav%7D%5Cdelta_%7Bav%7D%5Cright)%20=%20%5CE(A_%7Bav%7D)%20%5Ctimes%20%5Cmu.%0A"> Thus, under my very simplistic assumptions, a meta-analysis of observed score Cohen’s <img src="https://latex.codecogs.com/png.latex?d_%7Bav%7D"> estimates will be biased (downward) for the overall average effect in the true-score distribution.</p>
<p>You might find that the downward bias in <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D"> is undesirable. On the other hand, bias might not be as a big a problem as it first seems. If all of the observed-score effect sizes are biased to a degree that is unrelated to the true effects, then bias just stretches or compresses the scale of measurement, but doesn’t necessarily lead to interpretive problems. Imagine you have a ruler that is half an inch too short, and you’re trying to compare the heights of different objects. As long as you use the same ruler, then you will still be able to determine which objects are bigger and which are smaller, and by how much, even if the measurements are off in an absolute sense.</p>
<p>Apart from bias, however, variability in <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D"> will also induce <em>additional heterogeneity</em> in the distribution of observed score effect sizes. This is a clear problem because it creates additional uncertainty, making it harder to draw inferences about the distribution of effects, predict new effect sizes, or identify substantively interesting moderators. To measure this additional heterogeneity and keep its consequences separate from the consequences for bias, I will look at the coefficient of variation in <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D">. Under the assumption that <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D"> is independent of <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D">, <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Csqrt%7B%5CVar(%5Ctilde%5Cdelta_%7Bav%7D)%7D%7D%7B%5CE(%5Ctilde%5Cdelta_%7Bav%7D)%7D%20=%20%5Cfrac%7B%5Csqrt%7B(%5Cmu%5E2%20+%202%20%5Ctau%5E2)%20%5CVar(A_%7Bav%7D)%20+%20%5Ctau%5E2%20%5Cleft%5B%5CE(A_%7Bav%7D)%5Cright%5D%5E2%7D%7D%7B%5CE%5Cleft(A_%7Bav%7D%20%5Cright)%20%5Ctimes%20%5Cmu%20%7D%20=%20%5Csqrt%7B%5Cleft%5B%5Cleft(1%20+%20%5Cfrac%7B2%20%5Ctau%5E2%7D%7B%5Cmu%5E2%7D%5Cright)%20%5Cfrac%7B%5CVar(A_%7Bav%7D)%7D%7B%5Cleft%5B%5CE%5Cleft(A_%7Bav%7D%20%5Cright)%5Cright%5D%5E2%7D%20+%20%5Cfrac%7B%5Ctau%5E2%7D%7B%5Cmu%5E2%7D%5Cright%5D%7D.%0A"> Thus, the coefficient of variation for <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D"> is amplified by a factor that depends on the squared coefficient of variation of <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D">. Under the same model, <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_z%20=%20A_z%20%5Ctimes%20%5Cdelta_%7Bav%7D">, where <img src="https://latex.codecogs.com/png.latex?A_z%20=%20%5Cleft(1%20-%20%5Crho%20+%20%5Cfrac%7B1%20-%20%5Cphi%7D%7B%5Cphi%20K%7D%5Cright)%5E%7B-1/2%7D">, and so <img src="https://latex.codecogs.com/png.latex?%5CE(%5Ctilde%5Cdelta_z)%20=%20%5CE(A_z)%20%5Ctimes%20%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Csqrt%7B%5CVar(%5Ctilde%5Cdelta_z)%7D%7D%7B%5CE(%5Ctilde%5Cdelta_z)%7D%20=%20%5Csqrt%7B%5Cleft%5B%5Cleft(1%20+%20%5Cfrac%7B2%20%5Ctau%5E2%7D%7B%5Cmu%5E2%7D%5Cright)%20%5Cfrac%7B%5CVar(A_z)%7D%7B%5Cleft%5B%5CE%5Cleft(A_z%20%5Cright)%5Cright%5D%5E2%7D%20+%20%5Cfrac%7B%5Ctau%5E2%7D%7B%5Cmu%5E2%7D%5Cright%5D%7D.%0A"></p>
<p>To see what’s going on here, let’s consider some specific distributions for these measurement factors. First, let’s assume:</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?%5Crho%20%5Csim%20B(14,%206)">, so that <img src="https://latex.codecogs.com/png.latex?%5CE(%5Crho)%20=%20.7"> and <img src="https://latex.codecogs.com/png.latex?%5CVar(%5Crho)%20=%200.1%5E2">;</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Cphi%20%5Csim%20B(3,%205)">, so that <img src="https://latex.codecogs.com/png.latex?%5CE(%5Crho)%20=%20.0.375"> and <img src="https://latex.codecogs.com/png.latex?%5CVar(%5Crho)%20=%200.161%5E2">;</li>
<li><img src="https://latex.codecogs.com/png.latex?K%20%5Csim%201%20+%20Pois(9)">, so <img src="https://latex.codecogs.com/png.latex?%5CE(K)%20=%2010"> and <img src="https://latex.codecogs.com/png.latex?%5CVar(K)%20=%203%5E2">; and</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Crho">, <img src="https://latex.codecogs.com/png.latex?%5Cphi">, and <img src="https://latex.codecogs.com/png.latex?K"> are mutually independent and independent of <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D">.</li>
</ul>
<p>Below I simulate 50000 samples from these distributions and calculate <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D"> and <img src="https://latex.codecogs.com/png.latex?A_z">.</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">R <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;">50000</span></span>
<span id="cb1-2">rho <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbeta</span>(R, <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;">6</span>)</span>
<span id="cb1-3">phi <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbeta</span>(R, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb1-4">K <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rpois</span>(R, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>)</span>
<span id="cb1-5">A_av <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> phi) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (phi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> K))</span>
<span id="cb1-6">A_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;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<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> rho <span 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> phi) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (phi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> K)))</span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggplot2)</span>
<span id="cb1-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(patchwork)</span>
<span id="cb1-10"></span>
<span id="cb1-11">density_plot <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, lab, col, limits) {</span>
<span id="cb1-12">  <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;">data.frame</span>(x), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(x)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-13">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlim</span>(limits) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-14">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_density</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> col) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-15">    <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;">labels =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-16">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb1-17">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> lab, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)</span>
<span id="cb1-18">}</span>
<span id="cb1-19"></span>
<span id="cb1-20">p_A_av <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">density_plot</span>(A_av, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(A[av]),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</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.2</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb1-21">p_A_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;">density_plot</span>(A_z, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(A[z]), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</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;">3</span>))</span>
<span id="cb1-22">p_A_av <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> p_A_z</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/dizzy-for-d-z/index_files/figure-html/unnamed-chunk-2-1.png" class="img-fluid figure-img" width="960"></p>
</figure>
</div>
</div>
</div>
<p>The distribution of <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D"> is mostly concentrated around the mean of <img src="https://latex.codecogs.com/png.latex?E(A_%7Bav%7D)%20=%200.899">, with a coefficient of variation of <img src="https://latex.codecogs.com/png.latex?CV(A_%7Bav%7D)%20=%200.085">. In contrast, the distribution of <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D"> has a mean very close to one, <img src="https://latex.codecogs.com/png.latex?E(A_z)%20=%201.007"> but a coefficient of variation of <img src="https://latex.codecogs.com/png.latex?CV(A_z)%20=%200.209">, about 2.5 times larger. Thus, variation in measurement procedure induces more extra heterogeneity into the distribution of <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_z"> than into <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D">.</p>
<p>Now, one potential objection to this hypothetical scenario is that researchers do not choose the number of trials at random, without consideration for the other parameters of the study design. A more realistic assumption might be that researchers choose <img src="https://latex.codecogs.com/png.latex?K"> to ensure they achieve at least some threshold level of reliability for the observed scores. The reliability of the observed scores is <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D%5E2">, so ensuring some threshold of reliability is equivalent to ensuring the square root of the threshold for <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D">. Let’s suppose that researchers always ensure <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D%20%5Cgeq%200.8"> so that reliability is always at least <img src="https://latex.codecogs.com/png.latex?0.64">. This leads to the following distributions for <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D"> and <img src="https://latex.codecogs.com/png.latex?A_z">:</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">A_av_trunc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> A_av[A_av <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>]</span>
<span id="cb2-2">A_z_trunc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> A_z[A_av <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>]</span>
<span id="cb2-3">p_A_av_trunc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">density_plot</span>(A_av_trunc, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(A[av]),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"blue"</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.2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb2-4">p_A_z_trunc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">density_plot</span>(A_z_trunc, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(A[z]), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purple"</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;">3</span>))</span>
<span id="cb2-5">p_A_av_trunc <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> p_A_z_trunc</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/dizzy-for-d-z/index_files/figure-html/unnamed-chunk-3-1.png" class="img-fluid figure-img" width="960"></p>
</figure>
</div>
</div>
</div>
<p>The distribution of <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D"> loses its left tail, so that its mean is <img src="https://latex.codecogs.com/png.latex?E(A_%7Bav%7D%7CA_%7Bav%7D%20%5Cgeq%200.8)%20=%200.918"> and its coefficient of variation is reduced to <img src="https://latex.codecogs.com/png.latex?CV(A_%7Bav%7D%20%7C%20A_%7Bav%7D%20%5Cgeq%200.8)%20=%200.049">. The distribution of <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D"> now has a mean of <img src="https://latex.codecogs.com/png.latex?E(A_z%20%7C%20A_%7Bav%7D%20%5Cgeq%200.8)%20=%201.046"> and a coefficient of variation of <img src="https://latex.codecogs.com/png.latex?CV(A_z%20%7C%20A_%7Bav%7D%20%5Cgeq%200.8)%20=%200.172">, about 3.5 times larger than the squared coefficient of variation of <img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D">.</p>
<p>Under both of these scenarios, the observed-score <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_z"> is substantially more sensitive to procedural heterogeneity than is <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D">. Based on this model and hypothetical example, it seems clear <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D"> should be preferred over <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_z"> as a metric for meta-analysis. However, these relationships are predicated on a certain model for the study-specific parameters. One might object to this model because there’s a sense that we have assumed that <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D"> is the right answer. After all, the underlying effect size model is specified in terms of <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D">, and the design parameters—including <img src="https://latex.codecogs.com/png.latex?%5Crho"> in particular—are treated as noise, uncorrelated with <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D">. What happens to the observed-score metrics <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_z"> and <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D"> if we instead start with a model specified in terms of <img src="https://latex.codecogs.com/png.latex?%5Cdelta_z">?</p>
</section>
<section id="a-model-for-delta_z" class="level3">
<h3 class="anchored" data-anchor-id="a-model-for-delta_z">A model for <img src="https://latex.codecogs.com/png.latex?%5Cdelta_z"></h3>
<p>Let’s now see how this works if we treat <img src="https://latex.codecogs.com/png.latex?%5Cdelta_z"> as the correct metric and assume that the design parameters are independent of <img src="https://latex.codecogs.com/png.latex?%5Cdelta_z">. Assume that <img src="https://latex.codecogs.com/png.latex?%0A%5Cdelta_z%20%5Csim%20N(%5Calpha,%20%5Comega%5E2)%0A"> and that the remaining parameters <img src="https://latex.codecogs.com/png.latex?%5Crho">, <img src="https://latex.codecogs.com/png.latex?%5Cphi">, and <img src="https://latex.codecogs.com/png.latex?K"> are independent of <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D">. Then the observed-score standardized mean difference using change score standardization can be written as <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_z%20=%20B_z%20%5Ctimes%20%5Cdelta_z">, where <img src="https://latex.codecogs.com/png.latex?%0AB_z%20=%20%5Csqrt%7B%5Cfrac%7B1%20-%20%5Crho%7D%7B1%20-%20%5Crho%20+%20%5Cfrac%7B1%20-%20%5Cphi%7D%7B%5Cphi%20K%7D%7D%7D%0A"> and the observed-score standardized mean difference using raw score standardization can be written as <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D%20=%20B_%7Bav%7D%20%5Ctimes%20%5Cdelta_z">, where <img src="https://latex.codecogs.com/png.latex?%0AB_%7Bav%7D%20=%20%5Cfrac%7B%5Csqrt%7B2%7D(1%20-%20%5Crho)%7D%7B%5Csqrt%7B1%20-%20%5Crho%20+%20%5Cfrac%7B1%20-%20%5Cphi%7D%7B%5Cphi%20K%7D%7D%7D.%0A"> The plots below show the distribution of <img src="https://latex.codecogs.com/png.latex?B_z"> and <img src="https://latex.codecogs.com/png.latex?B_%7Bav%7D"> under the same scenarios considered above. First, the scenario where observed-score reliability is not controlled:</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">B_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>((<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> rho) <span 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> rho <span 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> phi) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (phi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> K)))</span>
<span id="cb3-2">B_av <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(<span class="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> rho) <span 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;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> rho <span 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> phi) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (phi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> K))</span>
<span id="cb3-3"></span>
<span id="cb3-4">p_B_av <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">density_plot</span>(B_av, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(B[av]),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>))</span>
<span id="cb3-5">p_B_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;">density_plot</span>(B_z, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(B[z]), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"yellow"</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="cb3-6">p_B_av <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> p_B_z</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/dizzy-for-d-z/index_files/figure-html/unnamed-chunk-4-1.png" class="img-fluid figure-img" width="960"></p>
</figure>
</div>
</div>
</div>
<p>Second, the scenario where observed-score reliability is at least 0.64:</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">B_z_trunc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> B_z[A_av <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>]</span>
<span id="cb4-2">B_av_trunc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> B_av[A_av <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>]</span>
<span id="cb4-3"></span>
<span id="cb4-4">p_B_av_trunc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">density_plot</span>(B_av, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(B[av]),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"green"</span>, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.5</span>))</span>
<span id="cb4-5">p_B_z_trunc <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">density_plot</span>(B_z, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(B[z]), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"yellow"</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="cb4-6">p_B_av_trunc <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> p_B_z_trunc</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/dizzy-for-d-z/index_files/figure-html/unnamed-chunk-5-1.png" class="img-fluid figure-img" width="960"></p>
</figure>
</div>
</div>
</div>
<p>The table below reports the coefficients of variation for each of the multiplicative factors I have considered.</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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(dplyr)</span>
<span id="cb5-2">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(A_av, A_z, B_av, B_z)</span>
<span id="cb5-3"></span>
<span id="cb5-4">random_rel <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb5-5">  dat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb5-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">everything</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;">sd</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>(.)),</span>
<span id="cb5-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reliability =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"random"</span></span>
<span id="cb5-9">  )</span>
<span id="cb5-10"></span>
<span id="cb5-11">controlled_rel <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb5-12">  dat <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(A_av <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(</span>
<span id="cb5-15">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">everything</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;">sd</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>(.)),</span>
<span id="cb5-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reliability =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"at least 0.64"</span></span>
<span id="cb5-17">  )</span>
<span id="cb5-18"></span>
<span id="cb5-19">CVs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb5-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(random_rel, controlled_rel) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb5-22">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">A_ratio =</span> A_z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> A_av,</span>
<span id="cb5-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">B_ratio =</span> B_z <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> B_av</span>
<span id="cb5-24">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb5-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(reliability, A_av, A_z, A_ratio, B_av, B_z, B_ratio)</span>
<span id="cb5-26"></span>
<span id="cb5-27">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>
<span id="cb5-28">  CVs, </span>
<span id="cb5-29">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</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;">3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb5-30">  <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;">"Coefficients of variation"</span>,</span>
<span id="cb5-31">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col.names =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reliability"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$A_{av}$"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$A_z$"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$A_z /A_{av}$"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$B_{av}$"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$B_z$"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"$B_{z} / B_{av}$"</span>),</span>
<span id="cb5-32">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">escape =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb5-33">)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<caption>Coefficients of variation</caption>
<colgroup>
<col style="width: 18%">
<col style="width: 12%">
<col style="width: 8%">
<col style="width: 18%">
<col style="width: 12%">
<col style="width: 8%">
<col style="width: 22%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">Reliability</th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?A_%7Bav%7D"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?A_z"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?A_z%20/A_%7Bav%7D"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?B_%7Bav%7D"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?B_z"></th>
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?B_%7Bz%7D%20/%20B_%7Bav%7D"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">random</td>
<td style="text-align: right;">0.085</td>
<td style="text-align: right;">0.209</td>
<td style="text-align: right;">2.5</td>
<td style="text-align: right;">0.285</td>
<td style="text-align: right;">0.181</td>
<td style="text-align: right;">0.63</td>
</tr>
<tr class="even">
<td style="text-align: left;">at least 0.64</td>
<td style="text-align: right;">0.049</td>
<td style="text-align: right;">0.172</td>
<td style="text-align: right;">3.5</td>
<td style="text-align: right;">0.258</td>
<td style="text-align: right;">0.137</td>
<td style="text-align: right;">0.53</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>The tables are now more or less turned. Under both reliability scenarios, <img src="https://latex.codecogs.com/png.latex?B_z"> has a lower coefficient of variation than <img src="https://latex.codecogs.com/png.latex?B_%7Bav%7D">, indicating that <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_z"> is less affected by procedural heterogeneity than is <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D">. However, <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_z"> is still affected in absolute terms, considering that the coefficient of variation for <img src="https://latex.codecogs.com/png.latex?B_z"> is about 79% of the coefficient of variation for <img src="https://latex.codecogs.com/png.latex?A_z">. Of course, <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D"> is quite strongly affected under this model, with a coefficient of variation of 0.258.</p>
</section>
<section id="consequences-for-heterogeneity" class="level3">
<h3 class="anchored" data-anchor-id="consequences-for-heterogeneity">Consequences for heterogeneity</h3>
<p>To make these results a bit more concrete, it’s useful to consider think in terms of heterogeneity of the observed score effect sizes. The figure below plots the CVs of observed-score effect size parameters as a function of the CVs of the true effect size distribution.</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;">library</span>(tidyr)</span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(stringr)</span>
<span id="cb6-3"></span>
<span id="cb6-4">CV_obs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb6-5">  CVs <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-6">  <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>A_ratio, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>B_ratio) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>reliability, <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;">"metric"</span>, <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;">"het"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-8">  <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;">tau_mu =</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.02</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-10">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reliability =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">recode</span>(reliability, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'at least 0.64'</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reliability of at least 0.64"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'random'</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Random reliability"</span>),</span>
<span id="cb6-11">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">metric =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_replace</span>(metric, <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="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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"]"</span>),</span>
<span id="cb6-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CV =</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;">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> tau_mu<span 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> het<span 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> tau_mu<span 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="cb6-13">  )</span>
<span id="cb6-14"></span>
<span id="cb6-15">CV_ex <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> CV_obs <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(tau_mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, reliability <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;">"Reliability of at least 0.64"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(metric, CV) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(</span>
<span id="cb6-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">CV =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(CV, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>),</span>
<span id="cb6-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">metric =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_replace</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_sub</span>(metric, <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="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="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_"</span>)</span>
<span id="cb6-21">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb6-22">  <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;">names_from =</span> metric, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from =</span> CV)</span>
<span id="cb6-23"></span>
<span id="cb6-24">CV_obs_labs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb6-25">  CV_obs <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(tau_mu <span 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="cb6-27"></span>
<span id="cb6-28"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(CV_obs, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(tau_mu, CV, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> metric)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-29">  <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>(reliability)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</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.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="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="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</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.2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">expand =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expansion</span>(<span class="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="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.2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-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;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_hline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">yintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-34">  <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;">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="cb6-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(</span>
<span id="cb6-36">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> CV_obs_labs, </span>
<span id="cb6-37">    <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> tau_mu, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> CV, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> metric, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> metric),</span>
<span id="cb6-38">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nudge_x =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>,</span>
<span id="cb6-39">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parse =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span></span>
<span id="cb6-40">  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expression</span>(tau <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> mu), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Coefficient of variation for observed score ES"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span></code></pre></div></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://jepusto.netlify.app/posts/dizzy-for-d-z/index_files/figure-html/unnamed-chunk-7-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>Consider, for instance, a scenario where observed-score reliability is always at least 0.64 and <img src="https://latex.codecogs.com/png.latex?%5Ctau%20/%20%5Cmu%20=%200.5">, which would be the case if effect sizes are normally distributed and about 97% of effect sizes are positive. Under the effect size model based on <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D">, the observed-score <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D"> is hardly affected by measurement heterogeneity at all, with a CV of 0.504 but the CV of the observed-score <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_z"> is 0.543. Under the effect size model based on <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D">, the observed-score <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D"> is strongly affected by measurement heterogeneity, with a CV of 0.591; in comparison, the CV of the observed-score <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_z"> of 0.527. Under both models, these increases in CV are effectively constant for larger values of <img src="https://latex.codecogs.com/png.latex?%5Ctau%20/%20%5Cmu">.</p>
</section>
</section>
<section id="so-whats-your-point" class="level2">
<h2 class="anchored" data-anchor-id="so-whats-your-point">So what’s your point?</h2>
<p>Unfortunately, this particular trip down a rabbit hole doesn’t seem to yield many clear take-aways. For the scenario that I looked at here, the preferred choice of effect size metric is apparently driven by what assumptions we find more plausible. If we think the more plausible model is the one in which <img src="https://latex.codecogs.com/png.latex?%5Crho"> is independent of <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D">, then <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D"> is less strongly affected by measurement variation and therefore preferred. Further, the attenuation in <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_%7Bav%7D"> depends only on <img src="https://latex.codecogs.com/png.latex?%5Cphi">, which might mean that a correction for attenuation is more feasible. However, if we think the more plausible model is the one in which <img src="https://latex.codecogs.com/png.latex?%5Crho"> is independent of <img src="https://latex.codecogs.com/png.latex?%5Cdelta_z">, then <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_z"> is less strongly affected by measurement variation and therefore preferred.<sup>5</sup> In the latter model, one caveat is that the measurement error attenuation in <img src="https://latex.codecogs.com/png.latex?%5Ctilde%5Cdelta_z"> is still a complicated mess, depending on both the true score correlation <img src="https://latex.codecogs.com/png.latex?%5Crho"> and the reliability <img src="https://latex.codecogs.com/png.latex?%5Cphi">. This would make it pretty hard to implement some sort of correction for attenuation.</p>
<p>So, how could one decide which meta-analytic model is more plausible in a given application? On a conceptual level, I would argue that the model for <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D"> would tend to be more plausible in meta-analyses where there is more operational variation in the interventions examined. I would venture that syntheses that include many different versions of an intervention would tend to have a wider range of correlations between true scores (i.e., more heterogeneous correlations between potential outcomes), even holding the outcome measurement procedures constant. This doesn’t necessarily justify the assumption that <img src="https://latex.codecogs.com/png.latex?%5Crho"> is independent of <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D">, but it does make it seem rather implausible that <img src="https://latex.codecogs.com/png.latex?%5Cdelta_z"> would be independent of <img src="https://latex.codecogs.com/png.latex?%5Crho">.</p>
<p>On a more practical level, it seems like there are a few empirical things that a meta-analyst could do to inform a choice between a model for <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bav%7D"> and one for <img src="https://latex.codecogs.com/png.latex?%5Cdelta_z">. Pragmatically, one could calculate both effect size metrics and just see which one exhibits more heterogeneity. All else equal, it seems reasonable to prefer the metric that has less heterogeneity. One could also try to gather data on the correlation between observed scores, on the reliability of the observed scores, and on the number of trials used in each study. With this information, one could construct measurement-related predictors and use them in a meta-regression to explain variation in the observed effect size estimates. Alternately, one could use the formulas given above to implement attenuation corrections for the effect sizes and see if this leads to reduced heterogeneity. How well would any of these approaches actually work? Answering that question would take some further, more careful and systematic investigation.</p>


<!-- -->

</section>


<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Perhaps because use of Cohen’s <img src="https://latex.codecogs.com/png.latex?d"> is so under-scrutinized in practice, methodologists have spent many an afternoon blogging about this problem. For general discussions about issues with how to define Cohen’s <img src="https://latex.codecogs.com/png.latex?d">, see excellent posts from <a href="https://janhove.github.io/reporting/2015/02/05/standardised-vs-unstandardised-es">Jan Vanhove</a> (with <a href="https://janhove.github.io/design/2015/03/16/standardised-es-revisited">a sequel</a>), <a href="http://jakewestfall.org/blog/index.php/2016/03/25/five-different-cohens-d-statistics-for-within-subject-designs/">Jake Westfall</a>, <a href="http://datacolada.org/33">Uri Simonsohn</a>, and <a href="https://transparentstatistics.org/2018/07/05/meanings-effect-size/">Pierre Dragicevic</a>; a more formal discussion by <a href="https://www.floppybunny.org/robin/web/virtualclassroom/stats/basics/articles/effect_size/effect_size_baguley_2009.pdf">Thom Baguley</a>; and some very interesting work on alternative conceptualizations by <a href="https://doi.org/10.1002/jrsm.1130">Tony Ades and colleagues</a>. I can promise, dear reader, that the present blog post will not be nearly as cogent as these contributions—this is more about getting my own thoughts straight than making any recommendations—and so <em>caveat lector</em> applies.↩︎</p></li>
<li id="fn2"><p>I would <em>love</em> to be corrected on both of these points. Please drop a comment or email me with suggested reading.↩︎</p></li>
<li id="fn3"><p>When the standardizing variance is calculated using measurements from only one condition (i.e., the pre-test in a repeated measures design), this version of <img src="https://latex.codecogs.com/png.latex?d"> corresponds to <code>measure = "SMCR"</code>, the “standardized mean change using raw score standardization” in <code>metafor::escalc</code>.↩︎</p></li>
<li id="fn4"><p>This version of <img src="https://latex.codecogs.com/png.latex?d"> corresponds to <code>measure = "SMCC"</code>, the “standardized mean change using change score standardization” in <code>metafor::escalc</code>.↩︎</p></li>
<li id="fn5"><p>And of course, these two models are not the only alternatives—one could look at intermediate scenarios where <img src="https://latex.codecogs.com/png.latex?%5Crho"> and <img src="https://latex.codecogs.com/png.latex?%5Cphi"> are more or less strongly correlated with the true score effect sizes.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>effect size</category>
  <category>standardized mean difference</category>
  <category>design-comparable SMD</category>
  <category>measurement-error</category>
  <guid>https://jepusto.netlify.app/posts/dizzy-for-d-z/</guid>
  <pubDate>Fri, 17 Feb 2023 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Corrigendum to Pustejovsky and Tipton (2018), redux</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/Pusto-Tipton-2018-Theorem-2-redux/</link>
  <description><![CDATA[ 





<div class="callout callout-style-default callout-tip callout-titled" title="UPDATE, March 8, 2023">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Tip</span>UPDATE, March 8, 2023
</div>
</div>
<div class="callout-body-container callout-body">
<p>The correction to our paper has now been published at <em>Journal of Business and Economic Statistics</em>. It is available at https://doi.org/10.1080/07350015.2023.2174123.</p>
</div>
</div>
<p>In my <a href="../..\publication/rve-in-fixed-effects-models/">2018 paper with Beth Tipton</a>, published in the <em>Journal of Business and Economic Statistics</em>, we considered how to do cluster-robust variance estimation in fixed effects models estimated by weighted (or unweighted) least squares. As explained in <a href="../..\posts/pusto-tipton-2018-theorem-2/">my previous post</a>, we were recently alerted that Theorem 2 in the paper is incorrect as stated. It turns out, the conditions in the original version of the theorem are too general. A more limited version of the Theorem does actually hold, but only for models estimated using ordinary (unweighted) least squares, under a working model that assumes independent, homoskedastic errors. In this post, I’ll give the revised theorem, following the notation and setup of <a href="../..\posts/pusto-tipton-2018-theorem-2/">the previous post</a> (so better read that first, or what follows won’t make much sense!). <img src="https://latex.codecogs.com/png.latex?%0A%5Cdef%5CPr%7B%7B%5Ctext%7BPr%7D%7D%7D%0A%5Cdef%5CE%7B%7B%5Ctext%7BE%7D%7D%7D%0A%5Cdef%5CVar%7B%7B%5Ctext%7BVar%7D%7D%7D%0A%5Cdef%5CCov%7B%7B%5Ctext%7BCov%7D%7D%7D%0A%5Cdef%5Cbm%7B%5Cmathbf%7D%0A%5Cdef%5Cbs%7B%5Cboldsymbol%7D%0A"></p>
<section id="theorem-2-revised" class="level3">
<h3 class="anchored" data-anchor-id="theorem-2-revised">Theorem 2, revised</h3>
<p>Consider the model <span id="eq-regression"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7By%7D_i%20=%20%5Cbm%7BR%7D_i%20%5Cbs%5Cbeta%20+%20%5Cbm%7BS%7D_i%20%5Cbs%5Cgamma%20+%20%5Cbm%7BT%7D_i%20%5Cbs%5Cmu%20+%20%5Cbs%5Cepsilon_i,%0A%5Ctag%7B1%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%5Cbm%7By%7D_i"> is an <img src="https://latex.codecogs.com/png.latex?n_i%20%5Ctimes%201"> vector of responses for cluster <img src="https://latex.codecogs.com/png.latex?i">, <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BR%7D_i"> is an <img src="https://latex.codecogs.com/png.latex?n_i%20%5Ctimes%20r"> matrix of focal predictors, <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BS%7D_i"> is an <img src="https://latex.codecogs.com/png.latex?n_i%20%5Ctimes%20s"> matrix of additional covariates that vary across multiple clusters, and <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BT%7D_i"> is an <img src="https://latex.codecogs.com/png.latex?n_i%20%5Ctimes%20t"> matrix encoding cluster-specific fixed effects, all for <img src="https://latex.codecogs.com/png.latex?i%20=%201,...,m">. Let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BU%7D_i%20=%20%5Cleft%5B%20%5Cbm%7BR%7D_i%20%5C%20%5Cbm%7BS%7D_i%20%5Cright%5D"> be the set of predictors that vary across clusters and <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BX%7D_i%20=%20%5Cleft%5B%20%5Cbm%7BR%7D_i%20%5C%20%5Cbm%7BS%7D_i%20%5C%20%5Cbm%7BT%7D_i%20%5Cright%5D"> be the full set of predictors. Let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Cddot%7BU%7D%7D_i%20=%20%5Cleft(%5Cbm%7BI%7D%20-%20%5Cbm%7BT%7D_i%20%5Cbm%7BM%7D_%7B%5Cbm%7BT%7D%7D%5Cbm%7BT%7D_i'%5Cright)%20%5Cbm%7BU%7D_i"> be an absorbed version of the focal predictors and the covariates. The cluster-robust variance estimator for the coefficients of <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BU%7D_i"> is <span id="eq-CRVE"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7BV%7D%5E%7BCR2%7D%20=%20%5Cbm%7BM%7D_%7B%5Cbm%7B%5Cddot%7BU%7D%7D%7D%20%5Cleft(%5Csum_%7Bi=1%7D%5Em%20%5Cbm%7B%5Cddot%7BU%7D%7D_i'%20%5Cbm%7BW%7D_i%20%5Cbm%7BA%7D_i%20%5Cbm%7Be%7D_i%20%5Cbm%7Be%7D_i'%20%5Cbm%7BA%7D_i%20%5Cbm%7BW%7D_i%20%5Cbm%7B%5Cddot%7BU%7D%7D_i%20%5Cright)%20%5Cbm%7BM%7D_%7B%5Cbm%7B%5Cddot%7BU%7D%7D%7D,%0A%5Ctag%7B2%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BA%7D_1,...,%5Cbm%7BA%7D_m"> are the CR2 adjustment matrices.</p>
<p>If we assume a working model in which <img src="https://latex.codecogs.com/png.latex?%5Cbs%5CPsi_i%20=%20%5Csigma%5E2%20%5Cbm%7BI%7D_i"> for <img src="https://latex.codecogs.com/png.latex?i%20=%201,...,m"> and estimate the model by ordinary least squares, then the CR2 adjustment matrices have a fairly simple form: <span id="eq-A-matrix"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7BA%7D_i%20=%20%5Cleft(%5Cbm%7BI%7D_i%20-%20%5Cbm%7BX%7D_i%20%5Cbm%7BM_X%7D%20%5Cbm%7BX%7D_i'%5Cright)%5E%7B+1/2%7D,%0A%5Ctag%7B3%7D"></span> where <img src="https://latex.codecogs.com/png.latex?B%5E%7B+1/2%7D"> is the symmetric square root of the Moore-Penrose inverse of <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BB%7D">. However, this form is computationally expensive because it involves the full set of predictors, <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BX%7D_i">, including the cluster-specific fixed effects <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BT%7D_i">. If the model is estimated after absorbing the cluster-specific fixed effects, then it would be convenient to use the adjustment matrices based on the absorbed predictors only, <span id="eq-A-tilde"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7B%5Ctilde%7BA%7D%7D_i%20=%20%5Cleft(%5Cbm%7BI%7D_i%20-%20%5Cbm%7B%5Cddot%7BU%7D%7D_i%20%5Cbm%7BM_%5Cddot%7BU%7D%7D%20%5Cbm%7B%5Cddot%7BU%7D%7D_i'%5Cright)%5E%7B+1/2%7D.%0A%5Ctag%7B4%7D"></span> The original version of Theorem 2 asserted that <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BA%7D_i%20=%20%5Cbm%7B%5Ctilde%7BA%7D%7D_i">, which is not actually the case. However, for ordinary least squares with the independent, homoskedastic working model, we can show that <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BA%7D_i%20%5Cbm%7B%5Cddot%7BU%7D%7D_i%20=%20%5Cbm%7B%5Ctilde%7BA%7D%7D_i%20%5Cbm%7B%5Cddot%7BU%7D%7D_i">. Thus, it doesn’t matter whether we use <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BA%7D_i"> or <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Ctilde%7BA%7D%7D_i"> to calculate the cluster-robust variance estimator. We’ll get the same result either way, but <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Ctilde%7BA%7D%7D_i"> is bit easier to compute.</p>
<p>Here’s a formal statement of Theorem 2:</p>
<blockquote class="blockquote">
<p>Let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BL%7D_i%20=%20%5Cleft(%5Cbm%7B%5Cddot%7BU%7D%7D'%5Cbm%7B%5Cddot%7BU%7D%7D%20-%20%5Cbm%7B%5Cddot%7BU%7D%7D_i'%5Cbm%7B%5Cddot%7BU%7D%7D_i%5Cright)"> and assume that <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BL%7D_1,...,%5Cbm%7BL%7D_m"> have full rank <img src="https://latex.codecogs.com/png.latex?r%20+%20s">. If <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BW%7D_i%20=%20%5Cbm%7BI%7D_i"> and <img src="https://latex.codecogs.com/png.latex?%5Cbs%5CPhi_i%20=%20%5Cbm%7BI%7D_i"> for <img src="https://latex.codecogs.com/png.latex?i%20=%201,...,m">, then <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BA%7D_i%20%5Cbm%7B%5Cddot%7BU%7D%7D_i%20=%20%5Cbm%7B%5Ctilde%7BA%7D%7D_i%20%5Cbm%7B%5Cddot%7BU%7D%7D_i">, where <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BA%7D_i"> and <img src="https://latex.codecogs.com/png.latex?%5Ctilde%7B%5Cbm%7BA%7D%7D_i"> are as defined in Equation&nbsp;3 and Equation&nbsp;4, respectively.</p>
</blockquote>
</section>
<section id="proof" class="level3">
<h3 class="anchored" data-anchor-id="proof">Proof</h3>
<p>We can prove this revised Theorem 2 by showing how <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BA%7D_i"> can be constructed in terms of <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Ctilde%7BA%7D%7D_i"> and <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BT%7D_i">. First, because <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BT%7D_i'%5Cbm%7BT%7D_k%20=%20%5Cbm%7B0%7D"> for any <img src="https://latex.codecogs.com/png.latex?i%20%5Cneq%20k">, it follows that <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%20%5Cbm%7BT%7D_i'"> is idempotent, i.e., <img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%20%5Cbm%7BT%7D_i'%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%20%5Cbm%7BT%7D_i'%20=%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%20%5Cbm%7BT%7D_i'.%0A"></p>
<p>Next, denote the thin QR decomposition of <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Cddot%7BU%7D%7D_i"> as <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BQ%7D_i%20%5Cbm%7BR%7D_i">, where <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BQ%7D_i"> is semi-orthogonal <img src="https://latex.codecogs.com/png.latex?(%5Cbm%7BQ%7D_i'%5Cbm%7BQ%7D_i%20=%20%5Cbm%7BI%7D)"> and <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BR%7D_i"> has the same rank as <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Cddot%7BU%7D%7D_i">. Next, let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Ctilde%7BB%7D%7D_i%20=%20%5Cbm%7BI%7D_i%20-%20%5Cbm%7B%5Cddot%7BU%7D%7D_i%20%5Cbm%7BM_%5Cddot%7BU%7D%7D%20%5Cbm%7B%5Cddot%7BU%7D%7D_i'"> and observe that this can be written as <img src="https://latex.codecogs.com/png.latex?%0A%5Ctilde%7B%5Cbm%7BB%7D%7D_i%20=%20%5Cbm%7BI%7D_i%20-%20%5Cbm%7BQ%7D_i%20%5Cbm%7BQ%7D_i'%20+%20%5Cbm%7BQ%7D_i%20%5Cleft(%5Cbm%7BI%7D%20-%20%5Cbm%7BR%7D_i%20%5Cbm%7BM%7D_%7B%5Cbm%7B%5Cddot%7BU%7D%7D%7D%20%5Cbm%7BR%7D_i'%5Cright)%5Cbm%7BQ%7D_i'.%0A"> It can then be seen that <img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7B%5Ctilde%7BA%7D%7D_i%20=%20%5Ctilde%7B%5Cbm%7BB%7D%7D_i%5E%7B+1/2%7D%20=%20%5Cbm%7BI%7D_i%20-%20%5Cbm%7BQ%7D_i%20%5Cbm%7BQ%7D_i'%20+%20%5Cbm%7BQ%7D_i%20%5Cleft(%5Cbm%7BI%7D%20-%20%5Cbm%7BR%7D_i%20%5Cbm%7BM%7D_%7B%5Cbm%7B%5Cddot%7BU%7D%7D%7D%20%5Cbm%7BR%7D_i'%5Cright)%5E%7B+1/2%7D%20%5Cbm%7BQ%7D_i'.%0A"> It follows that <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Ctilde%7BA%7D%7D_i%20%5Cbm%7BT%7D_i%20=%20%5Cbm%7BT%7D_i"> because <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BQ%7D_i'%5Cbm%7BT%7D_i%20=%20%5Cbm%7B0%7D">. Further, <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Ctilde%7BB%7D%7D_i%20%5Cbm%7BT%7D_i%20=%20%5Cbm%7BT%7D_i"> as well.</p>
<p>Now, let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BB%7D_i%20=%20%5Cleft(%5Cbm%7BI%7D_i%20-%20%5Cbm%7BX%7D_i%20%5Cbm%7BM_X%7D%20%5Cbm%7BX%7D_i'%5Cright)"> and observe that this can be written as <img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7BB%7D_i%20=%20%5Cbm%7BI%7D_i%20-%20%5Cbm%7B%5Cddot%7BU%7D%7D_i%20%5Cbm%7BM_%7B%5Cddot%7BU%7D%7D%7D%5Cbm%7B%5Cddot%7BU%7D%7D_i'%20-%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%5Cbm%7BT%7D_i'%20=%20%5Cbm%7B%5Ctilde%7BB%7D%7D_i%20-%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%5Cbm%7BT%7D_i'%0A"> because <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Cddot%7BU%7D%7D_i'%5Cbm%7BT%7D_i%20=%20%5Cbm%7B0%7D">.</p>
<p>We then construct the full adjustment matrix <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BA%7D_i"> as <span id="eq-A-constructed"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7BA%7D_i%20=%20%5Ctilde%7B%5Cbm%7BA%7D%7D_i%20-%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%5Cbm%7BT%7D_i'.%0A%5Ctag%7B5%7D"></span> Showing that <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BB%7D_i%20%5Cbm%7BA%7D_i%20%5Cbm%7BB%7D_i%20%5Cbm%7BA%7D_i%20=%20%5Cbm%7BB%7D_i"> will suffice to verify that <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BA%7D_i"> is the symmetric square root of the Moore-Penrose inverse of <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BB%7D_i">. Because <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%20%5Cbm%7BT%7D_i'"> is idempotent, <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Ctilde%7BB%7D%7D_i%20%5Cbm%7BT%7D_i%20=%20%5Cbm%7BT%7D_i">, and <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Ctilde%7BA%7D%7D_i%20%5Cbm%7BT%7D_i%20=%20%5Cbm%7BT%7D_i">, we have <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cbm%7BB%7D_i%20%5Cbm%7BA%7D_i%20%5Cbm%7BB%7D_i%20%5Cbm%7BA%7D_i%20&amp;=%20%5Cleft(%5Ctilde%7B%5Cbm%7BB%7D%7D_i%20-%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%5Cbm%7BT%7D_i'%5Cright)%20%5Cleft(%5Ctilde%7B%5Cbm%7BA%7D%7D_i%20-%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%5Cbm%7BT%7D_i'%5Cright)%5Cleft(%5Ctilde%7B%5Cbm%7BB%7D%7D_i%20-%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%5Cbm%7BT%7D_i'%5Cright)%20%5Cleft(%5Ctilde%7B%5Cbm%7BA%7D%7D_i%20-%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%5Cbm%7BT%7D_i'%5Cright)%20%5C%5C%0A&amp;=%20%5Cleft(%5Ctilde%7B%5Cbm%7BB%7D%7D_i%5Ctilde%7B%5Cbm%7BA%7D%7D_i%20-%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%5Cbm%7BT%7D_i'%5Cright)%5Cleft(%5Ctilde%7B%5Cbm%7BB%7D%7D_i%5Ctilde%7B%5Cbm%7BA%7D%7D_i%20-%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%5Cbm%7BT%7D_i'%5Cright)%20%5C%5C%0A&amp;=%20%5Cleft(%5Ctilde%7B%5Cbm%7BB%7D%7D_i%5Ctilde%7B%5Cbm%7BA%7D%7D_i%5Ctilde%7B%5Cbm%7BB%7D%7D_i%5Ctilde%7B%5Cbm%7BA%7D%7D_i%20-%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%5Cbm%7BT%7D_i'%5Cright)%20%5C%5C%0A&amp;=%20%5Cleft(%5Ctilde%7B%5Cbm%7BB%7D%7D_i%20-%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%5Cbm%7BT%7D_i'%5Cright)%20%5C%5C%0A&amp;=%20%5Cbm%7BB%7D_i.%0A%5Cend%7Baligned%7D%0A"></p>
<p>From the representation of <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BA%7D_i"> in Equation&nbsp;5, it is clear that <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BA%7D_i%20%5Cbm%7B%5Cddot%7BU%7D%7D_i%20=%20%5Cbm%7B%5Ctilde%7BA%7D%7D_i%20%5Cbm%7B%5Cddot%7BU%7D%7D_i%20-%20%5Cbm%7BT%7D_i%20%5Cbm%7BM_T%7D%20%5Cbm%7BT%7D_i'%20%5Cbm%7B%5Cddot%7BU%7D%7D_i%20=%20%5Cbm%7B%5Ctilde%7BA%7D%7D_i%20%5Cbm%7B%5Cddot%7BU%7D%7D_i">.</p>


<!-- -->

</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a> ]]></description>
  <category>robust variance estimation</category>
  <category>econometrics</category>
  <category>matrix algebra</category>
  <guid>https://jepusto.netlify.app/posts/Pusto-Tipton-2018-Theorem-2-redux/</guid>
  <pubDate>Mon, 07 Nov 2022 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Corrigendum to Pustejovsky and Tipton (2018)</title>
  <dc:creator>James E. Pustejovsky</dc:creator>
  <link>https://jepusto.netlify.app/posts/Pusto-Tipton-2018-Theorem-2/</link>
  <description><![CDATA[ 





<p>In my <a href="../..\publication/rve-in-fixed-effects-models/">2018 paper with Beth Tipton</a>, published in the <em>Journal of Business and Economic Statistics</em>, we considered how to do cluster-robust variance estimation in fixed effects models estimated by weighted (or unweighted) least squares. A careful reader, <a href="https://eeecon.uibk.ac.at/~pfaffermayr/">Dr.&nbsp;Michael Pfaffermayr</a>, recently alerted us to a problem with Theorem 2 in the paper, which concerns a computational short cut for a certain cluster-robust variance estimator in models with cluster-specific fixed effects. The theorem is incorrect as stated, and we are currently working on issuing a correction for the published version of the paper. In the interim, this post details the problem with Theorem 2. I’ll first review the CR2 variance estimator, then describe the assertion of the theorem, and then provide a numerical counter-example demonstrating that the assertion is not correct as stated.</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cdef%5CPr%7B%7B%5Ctext%7BPr%7D%7D%7D%0A%5Cdef%5CE%7B%7B%5Ctext%7BE%7D%7D%7D%0A%5Cdef%5CVar%7B%7B%5Ctext%7BVar%7D%7D%7D%0A%5Cdef%5CCov%7B%7B%5Ctext%7BCov%7D%7D%7D%0A%5Cdef%5Cbm%7B%5Cmathbf%7D%0A%5Cdef%5Cbs%7B%5Cboldsymbol%7D%0A"></p>
<section id="a-fixed-effects-model" class="level3">
<h3 class="anchored" data-anchor-id="a-fixed-effects-model">A fixed effects model</h3>
<p>For data that can be grouped into <img src="https://latex.codecogs.com/png.latex?m"> clusters of observations, we considered the model <span id="eq-regression"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7By%7D_i%20=%20%5Cbm%7BR%7D_i%20%5Cbs%5Cbeta%20+%20%5Cbm%7BS%7D_i%20%5Cbs%5Cgamma%20+%20%5Cbm%7BT%7D_i%20%5Cbs%5Cmu%20+%20%5Cbs%5Cepsilon_i,%0A%5Ctag%7B1%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%5Cbm%7By%7D_i"> is an <img src="https://latex.codecogs.com/png.latex?n_i%20%5Ctimes%201"> vector of responses for cluster <img src="https://latex.codecogs.com/png.latex?i">, <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BR%7D_i"> is an <img src="https://latex.codecogs.com/png.latex?n_i%20%5Ctimes%20r"> matrix of focal predictors, <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BS%7D_i"> is an <img src="https://latex.codecogs.com/png.latex?n_i%20%5Ctimes%20s"> matrix of additional covariates that vary across multiple clusters, and <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BT%7D_i"> is an <img src="https://latex.codecogs.com/png.latex?n_i%20%5Ctimes%20t"> matrix encoding cluster-specific fixed effects, all for <img src="https://latex.codecogs.com/png.latex?i%20=%201,...,m">. The cluster-specific fixed effects satisfy <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BT%7D_h%20%5Cbm%7BT%7D_i'%20=%20%5Cbm%7B0%7D"> for <img src="https://latex.codecogs.com/png.latex?h%20%5Cneq%20i">. Interest centers on inference for the coefficients on the focal predictors <img src="https://latex.codecogs.com/png.latex?%5Cbs%5Cbeta">.</p>
<p>We considered estimation of Model Equation&nbsp;1 by weighted least squares (WLS), possibly under a working model for the distribution of <img src="https://latex.codecogs.com/png.latex?%5Cbs%5Cepsilon_i">. Let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BW%7D_1,...,%5Cbm%7BW%7D_m"> be a set of symmetric weight matrices used for WLS estimation. Sometimes, these weight matrices may be diagonal, consisting of sampling weights for each observation. Other times, the weight matrices may involve off-diagonal terms as well. Consider a working model <img src="https://latex.codecogs.com/png.latex?%5CVar%5Cleft(%5Cbs%5Cepsilon_i%20%7C%20%5Cbm%7BR%7D_i,%20%5Cbm%7BS%7D_i,%20%5Cbm%7BT%7D_i%5Cright)%20=%20%5Csigma%5E2%20%5Cbs%5CPhi_i"> where <img src="https://latex.codecogs.com/png.latex?%5Cbs%5CPhi_i"> is a symmetric <img src="https://latex.codecogs.com/png.latex?n_i%20%5Ctimes%20n_i"> matrix that may be a function of a low-dimensional, estimable parameter. Based on this working model, the weight matrices might be taken as <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BW%7D_i%20=%20%5Cbs%7B%5Chat%5CPhi%7D_i%5E%7B-1%7D">, where <img src="https://latex.codecogs.com/png.latex?%5Cbs%7B%5Chat%5CPhi%7D_i"> is an estimate of <img src="https://latex.codecogs.com/png.latex?%5Cbs%5CPhi_i">.</p>
</section>
<section id="the-cr2-variance-estimator" class="level3">
<h3 class="anchored" data-anchor-id="the-cr2-variance-estimator">The CR2 variance estimator</h3>
<p>In the paper, we provide a generalization of the bias-reduced linearization estimator introduced by <span class="citation" data-cites="McCaffrey2001generalizations">McCaffrey et al. (2001)</span> and <span class="citation" data-cites="Bell2002bias">Bell &amp; McCaffrey (2002)</span> that can be applied to Model Equation&nbsp;1. The variance estimator is effectively a generalization of the HC2 correction for heteroskedasticity-robust standard errors, but that works for models with within-cluster dependence and cluster-specific fixed effects, and so we refer to it the “CR2” estimator.</p>
<p>In order to define the CR2 variance estimator and explain the issue with Theorem 2, I’ll need to lay down a bit more notation. Let <img src="https://latex.codecogs.com/png.latex?N%20=%20%5Csum_%7Bi=1%7D%5Em%20n_i"> be the total sample size. Let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BU%7D_i%20=%20%5Cleft%5B%20%5Cbm%7BR%7D_i%20%5C%20%5Cbm%7BS%7D_i%20%5Cright%5D"> be the set of predictors that vary across clusters and <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BX%7D_i%20=%20%5Cleft%5B%20%5Cbm%7BR%7D_i%20%5C%20%5Cbm%7BS%7D_i%20%5C%20%5Cbm%7BT%7D_i%20%5Cright%5D"> be the full set of predictors. Let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BR%7D">, <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BS%7D">, <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BT%7D">, <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BU%7D">, and <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BX%7D"> denote the stacked versions of the cluster-specific matrices (i.e., <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BR%7D%20=%20%5Cleft%5B%5Cbm%7BR%7D_1'%20%5C%20%5Cbm%7BR%7D_2'%20%5C%20%5Ccdots%20%5C%20%5Cbm%7BR%7D_m'%5Cright%5D'">, etc.). Let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BW%7D%20=%20%5Cbigoplus_%7Bi=1%7D%5Em%20%5Cbm%7BW%7D_i"> and <img src="https://latex.codecogs.com/png.latex?%5Cbs%5CPhi%20=%20%5Cbigoplus_%7Bi=1%7D%5Em%20%5Cbs%5CPhi_i">. For a generic matrix <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BZ%7D">, let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BM%7D_%7BZ%7D%20=%20%5Cleft(%5Cbm%7BZ%7D'%5Cbm%7BW%7D%5Cbm%7BZ%7D%5Cright)%5E%7B-1%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BH%7D_%7B%5Cbm%7BZ%7D%7D%20=%20%5Cbm%7BZ%7D%20%5Cbm%7BM%7D_%7B%5Cbm%7BZ%7D%7D%5Cbm%7BZ%7D'%5Cbm%7BW%7D">. Let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BC%7D_i"> be the <img src="https://latex.codecogs.com/png.latex?n_i%20%5Ctimes%20N"> matrix that selects the rows of cluster <img src="https://latex.codecogs.com/png.latex?i"> from the full set of observations, such that <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BX%7D_i%20=%20%5Cbm%7BC%7D_i%20%5Cbm%7BX%7D">. These operators provide an easy way to define absorbed versions of the predictors. Specifically, let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Cddot%7BS%7D%7D%20=%20%5Cleft(%5Cbm%7BI%7D%20-%20%5Cbm%7BH%7D_%7B%5Cbm%7BT%7D%7D%5Cright)%20%5Cbm%7BS%7D"> be the covariates after absorbing (i.e., partialling out) the cluster-specific effects, let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Cddot%7BU%7D%7D%20=%20%5Cleft(%5Cbm%7BI%7D%20-%20%5Cbm%7BH%7D_%7B%5Cbm%7BT%7D%7D%5Cright)%20%5Cbm%7BU%7D"> be an absorbed version of the focal predictors and the covariates, and let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Cddot%7BR%7D%7D%20=%20%5Cleft(%5Cbm%7BI%7D%20-%20%5Cbm%7BH%7D_%7B%5Cbm%7B%5Cddot%7BS%7D%7D%7D%5Cright)%5Cleft(%5Cbm%7BI%7D%20-%20%5Cbm%7BH%7D_%7B%5Cbm%7BT%7D%7D%5Cright)%20%5Cbm%7BR%7D"> be the focal predictors after absorbing the covariates and the cluster-specific fixed effects.</p>
<p>With this notation established, the CR2 variance estimator has the form <img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7BV%7D%5E%7BCR2%7D%20=%20%5Cbm%7BM%7D_%7B%5Cbm%7B%5Cddot%7BR%7D%7D%7D%20%5Cleft(%5Csum_%7Bi=1%7D%5Em%20%5Cbm%7B%5Cddot%7BR%7D%7D_i'%20%5Cbm%7BW%7D_i%20%5Cbm%7BA%7D_i%20%5Cbm%7Be%7D_i%20%5Cbm%7Be%7D_i'%20%5Cbm%7BA%7D_i%20%5Cbm%7BW%7D_i%20%5Cbm%7B%5Cddot%7BR%7D%7D_i%20%5Cright)%20%5Cbm%7BM%7D_%7B%5Cbm%7B%5Cddot%7BR%7D%7D%7D,%0A"> where <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Cddot%7BR%7D%7D_i%20=%20%5Cbm%7BC%7D_i%20%5Cbm%7B%5Cddot%7BR%7D%7D"> is the cluster-specific matrix of absorbed focal predictors, <img src="https://latex.codecogs.com/png.latex?%5Cbm%7Be%7D_i"> is the vector of weighted least squares residuals from cluster <img src="https://latex.codecogs.com/png.latex?i">, and <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BA%7D_1,...,%5Cbm%7BA%7D_m"> are a set of adjustment matrices that correct the bias of the residual cross-products. The adjustment matrices are calculated as follows. Let <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BD%7D_i"> be the upper-right Cholesky factorization of <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5CPhi%7D_i"> and define the matrices <span id="eq-B-matrix"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7BB%7D_i%20=%20%5Cbm%7BD%7D_i%20%5Cbm%7BC%7D_i%20%5Cleft(%5Cbm%7BI%7D%20-%20%5Cbm%7BH%7D_%7B%5Cbm%7BX%7D%7D%5Cright)%20%5Cbs%5CPhi%20%5Cleft(%5Cbm%7BI%7D%20-%20%5Cbm%7BH%7D_%7B%5Cbm%7BX%7D%7D%5Cright)'%5Cbm%7BC%7D_i'%20%5Cbm%7BD%7D_i'%0A%5Ctag%7B2%7D"></span> for <img src="https://latex.codecogs.com/png.latex?i%20=%201,...,m">. The adjustment matrices are then calculated as <span id="eq-A-matrix"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7BA%7D_i%20=%20%5Cbm%7BD%7D_i'%20%5Cbm%7BB%7D_i%5E%7B+1/2%7D%20%5Cbm%7BD%7D_i,%0A%5Ctag%7B3%7D"></span> where <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BB%7D_i%5E%7B+1/2%7D"> is the symmetric square root of the Moore-Penrose inverse of <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BB%7D_i">. Theorem 1 in the paper shows that, if the working model <img src="https://latex.codecogs.com/png.latex?%5Cbs%5CPhi"> is correctly specified and some conditions on the rank of <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BU%7D"> are satisfied, then the CR2 estimator is exactly unbiased for the sampling variance of the weighted least squares estimator of <img src="https://latex.codecogs.com/png.latex?%5Cbs%5Cbeta">. Across multiple simulation studies, it’s been observed that the CR2 estimator also works well and outperforms alternative sandwich estimators even when the working model is not correctly specified.</p>
</section>
<section id="theorem-2" class="level3">
<h3 class="anchored" data-anchor-id="theorem-2">Theorem 2</h3>
<p>The adjustment matrices given in Equation&nbsp;3 can be expensive to compute directly because the <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BB%7D_i"> matrices involve computing a “residualized” version of the <img src="https://latex.codecogs.com/png.latex?N%20%5Ctimes%20N"> matrix <img src="https://latex.codecogs.com/png.latex?%5Cbs%5CPhi"> involving the full set of predictors <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BX%7D">—including the cluster-specific fixed effects <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BT%7D_1,...,%5Cbm%7BT%7D_m">. Theorem 2 considered whether one can take a computational short cut by omitting the cluster-specific fixed effects from the calculation of the <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BB%7D_i"> matrices. Specifically, define the modified matrices <span id="eq-B-modified"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7B%5Ctilde%7BB%7D%7D_i%20=%20%5Cbm%7BD%7D_i%20%5Cbm%7BC%7D_i%20%5Cleft(%5Cbm%7BI%7D%20-%20%5Cbm%7BH%7D_%7B%5Cbm%7B%5Cddot%7BU%7D%7D%7D%5Cright)%20%5Cbs%5CPhi%20%5Cleft(%5Cbm%7BI%7D%20-%20%5Cbm%7BH%7D_%7B%5Cbm%7B%5Cddot%7BU%7D%7D%7D%5Cright)'%5Cbm%7BC%7D_i'%20%5Cbm%7BD%7D_i'%0A%5Ctag%7B4%7D"></span> and <span id="eq-A-modified"><img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7B%5Ctilde%7BA%7D%7D_i%20=%20%5Cbm%7BD%7D_i'%20%5Cbm%7B%5Ctilde%7BB%7D%7D_i%5E%7B+1/2%7D%20%5Cbm%7BD%7D_i.%0A%5Ctag%7B5%7D"></span> Theorem 2 claims that if the weight matrices are inverse of the working model, such that <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BW%7D_i%20=%20%5Cbs%5CPhi_i%5E%7B-1%7D"> for <img src="https://latex.codecogs.com/png.latex?i%20=%201,...,m">, then <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Ctilde%7BB%7D%7D_i%5E%7B+1/2%7D%20=%20%5Cbm%7BB%7D_i%5E%7B+1/2%7D"> and hence <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Ctilde%7BA%7D%7D_i%20=%20%5Cbm%7BA%7D_i">. The implication is that the cluster-specific fixed effects can be ignored when calculating the adjustment matrices. However, the claimed equivalence does not actually hold.</p>
<p>Here is a simple numerical example that contradicts the assertion of Theorem 2. I first create a predictor matrix consisting of 4 clusters, a single focal predictor, and cluster-specific fixed effects.</p>
<div class="cell">
<details open="" 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;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20220926</span>)</span>
<span id="cb1-2">m <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 class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># number of clusters</span></span>
<span id="cb1-3">ni <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="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rpois</span>(m, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">3.5</span>)                            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cluster sizes</span></span>
<span id="cb1-4">N <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(ni)                                       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># total sample size</span></span>
<span id="cb1-5">id <span class="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;">rep</span>(LETTERS[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>m], ni))                <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cluster ID</span></span>
<span id="cb1-6">R <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(N)                                      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># focal predictor</span></span>
<span id="cb1-7">dat <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data.frame</span>(R, id)                           <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># create raw data frame</span></span>
<span id="cb1-8">X <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">model.matrix</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> R <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> <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;">data =</span> dat)        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># full predictor matrix</span></span>
<span id="cb1-9">Ui <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tapply</span>(R, id, \(x) 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;">mean</span>(x))              <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># absorbed version of R</span></span>
<span id="cb1-10">U <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unsplit</span>(Ui, id)</span></code></pre></div></div>
</details>
</div>
<p>Consider a model estimated by ordinary least squares, where the assumed working model is homoskedastic and independent errors, so <img src="https://latex.codecogs.com/png.latex?%5Cbs%5CPhi_i%20=%20%5Cbm%7BI%7D_i">, an <img src="https://latex.codecogs.com/png.latex?n_i%20%5Ctimes%20n_i"> identity matrix (with no parameters to estimate). In this case, the adjustment matrices simplify considerably, to <img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7BA%7D_i%20=%20%5Cleft(%5Cbm%7BI%7D_i%20-%20%5Cbm%7BX%7D_i%20%5Cbm%7BM%7D_%7BX%7D%20%5Cbm%7BX%7D_i'%20%5Cright)%5E%7B+1/2%7D%20%5Cqquad%20%5Ctext%7Band%7D%20%5Cqquad%20%5Cbm%7B%5Ctilde%7BA%7D%7D_i%20=%20%5Cleft(%5Cbm%7BI%7D_i%20-%20%5Cbm%7B%5Cddot%7BU%7D%7D_i%20%5Cbm%7BM%7D_%7B%5Cddot%7BU%7D%7D%20%5Cbm%7B%5Cddot%7BU%7D%7D_i'%20%5Cright)%5E%7B+1/2%7D.%0A"> I calculate these directly as follows:</p>
<div class="cell">
<details open="" 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">matrix_power <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, p) {</span>
<span id="cb2-2">  eig <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">eigen</span>(x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">symmetric =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb2-3">  val_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;">with</span>(eig, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(values <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>, values<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span>p, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>))</span>
<span id="cb2-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">with</span>(eig, vectors <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%*%</span> (val_p <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(vectors)))</span>
<span id="cb2-5">}</span>
<span id="cb2-6"></span>
<span id="cb2-7">MX <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">solve</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">crossprod</span>(X))</span>
<span id="cb2-8">B <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> </span>
<span id="cb2-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">by</span>(X, id, as.matrix) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(\(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diag</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(x)) <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> MX <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%*%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(x))</span>
<span id="cb2-11">A <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(B, matrix_power, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p =</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>
<span id="cb2-12">  </span>
<span id="cb2-13">MU <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">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;">crossprod</span>(U)</span>
<span id="cb2-14">Btilde <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(Ui, \(x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">diag</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(x)) <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> MU <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%*%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(x))</span>
<span id="cb2-15">Atilde <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lapply</span>(Btilde, matrix_power, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p =</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></code></pre></div></div>
</details>
</div>
<p>Here are the adjustment matrices based on the full predictor matrix <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BX%7D">:</p>
<div class="cell">
<details open="" 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;">print</span>(A, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>$A
       [,1]   [,2]   [,3]   [,4]   [,5]
[1,]  0.853 -0.198 -0.207 -0.191 -0.257
[2,] -0.198  0.800 -0.200 -0.200 -0.202
[3,] -0.207 -0.200  0.801 -0.201 -0.192
[4,] -0.191 -0.200 -0.201  0.802 -0.210
[5,] -0.257 -0.202 -0.192 -0.210  0.860

$B
       [,1]   [,2]   [,3]
[1,]  0.668 -0.338 -0.330
[2,] -0.338  0.683 -0.345
[3,] -0.330 -0.345  0.675

$C
       [,1]   [,2]   [,3]   [,4]   [,5]   [,6]
[1,]  0.873 -0.206 -0.163 -0.105 -0.233 -0.166
[2,] -0.206  0.873 -0.171 -0.229 -0.100 -0.167
[3,] -0.163 -0.171  0.834 -0.160 -0.173 -0.167
[4,] -0.105 -0.229 -0.160  0.931 -0.271 -0.166
[5,] -0.233 -0.100 -0.173 -0.271  0.946 -0.168
[6,] -0.166 -0.167 -0.167 -0.166 -0.168  0.833

$D
       [,1]   [,2]   [,3]
[1,]  0.797 -0.342 -0.455
[2,] -0.342  0.667 -0.325
[3,] -0.455 -0.325  0.780</code></pre>
</div>
</div>
<p>Compare the above with the adjustment matrices based on the absorbed predictors only:</p>
<div class="cell">
<details open="" 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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(Atilde, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>$A
         [,1]      [,2]     [,3]      [,4]     [,5]
[1,]  1.05313  0.001860 -0.00742  0.008995 -0.05657
[2,]  0.00186  1.000065 -0.00026  0.000315 -0.00198
[3,] -0.00742 -0.000260  1.00104 -0.001257  0.00790
[4,]  0.00900  0.000315 -0.00126  1.001523 -0.00958
[5,] -0.05657 -0.001980  0.00790 -0.009576  1.06022

$B
         [,1]     [,2]     [,3]
[1,]  1.00139 -0.00478  0.00339
[2,] -0.00478  1.01642 -0.01163
[3,]  0.00339 -0.01163  1.00824

$C
          [,1]      [,2]      [,3]      [,4]     [,5]      [,6]
[1,]  1.039180 -0.039378  4.00e-03  0.061921 -0.06632  5.94e-04
[2,] -0.039378  1.039577 -4.02e-03 -0.062234  0.06665 -5.97e-04
[3,]  0.003999 -0.004019  1.00e+00  0.006320 -0.00677  6.07e-05
[4,]  0.061921 -0.062234  6.32e-03  1.097861 -0.10481  9.39e-04
[5,] -0.066317  0.066651 -6.77e-03 -0.104808  1.11225 -1.01e-03
[6,]  0.000594 -0.000597  6.07e-05  0.000939 -0.00101  1.00e+00

$D
         [,1]     [,2]    [,3]
[1,]  1.13078 -0.00914 -0.1216
[2,] -0.00914  1.00064  0.0085
[3,] -0.12165  0.00850  1.1131</code></pre>
</div>
</div>
<p>The matrices differ:</p>
<div class="cell">
<details open="" 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"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all.equal</span>(A, Atilde)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "Component \"A\": Mean relative difference: 0.6073885"
[2] "Component \"B\": Mean relative difference: 0.7403564"
[3] "Component \"C\": Mean relative difference: 0.5671847"
[4] "Component \"D\": Mean relative difference: 0.6682793"</code></pre>
</div>
</div>
<p>Thus, Theorem 2 is incorrect as stated. (I have yet to identify the mis-step in the proof as given in the supplementary materials of the paper.)</p>
</section>
<section id="further-thoughts" class="level3">
<h3 class="anchored" data-anchor-id="further-thoughts">Further thoughts</h3>
<p>For this particular model specification, it is interesting to note that <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Ctilde%7BA%7D%7D_i%20=%20%5Cbm%7BA%7D_i%20+%20%5Cbm%7BT%7D_i%20%5Cbm%7BM%7D_%7B%5Cbm%7BT%7D%7D%20%5Cbm%7BT%7D_i'">. Because <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Cddot%7BU%7D%7D_i'%20%5Cbm%7BT%7D_i%20=%20%5Cbm%7B0%7D">, it follows that <img src="https://latex.codecogs.com/png.latex?%0A%5Cbm%7B%5Cddot%7BU%7D%7D_i'%20%5Cbm%7B%5Ctilde%7BA%7D%7D_i%20=%20%5Cbm%7B%5Cddot%7BU%7D%7D_i'%20%5Cleft(%5Cbm%7BA%7D_i%20+%20%5Cbm%7BT%7D_i%20%5Cbm%7BM%7D_%7B%5Cbm%7BT%7D%7D%20%5Cbm%7BT%7D_i'%20%5Cright)%20=%20%5Cbm%7B%5Cddot%7BU%7D%7D_i'%20%5Cbm%7BA%7D_i.%0A"> This holds in the numerical example:</p>
<div class="cell">
<details open="" class="code-fold">
<summary>Code</summary>
<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">UiAtilde <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mapply</span>(\(u, a) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(u) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%*%</span> a, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">u =</span> Ui, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">a =</span> Atilde, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SIMPLIFY =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb9-2">UiA <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mapply</span>(\(u, a) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(u) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%*%</span> a, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">u =</span> Ui, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">a =</span> A, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">SIMPLIFY =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb9-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all.equal</span>(UiAtilde, UiA)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>[1] TRUE</code></pre>
</div>
</div>
<p>Thus, although the exact statement of Theorem 2 is incorrect, the substantive implication actually still holds. For this particular example, computing the CR2 variance estimator using the short-cut adjustment matrices <img src="https://latex.codecogs.com/png.latex?%5Cbm%7B%5Ctilde%7BA%7D%7D_1,...,%5Cbm%7B%5Ctilde%7BA%7D%7D_m"> is equivalent to computing the CR2 variance estimator using the full model adjustment matrices <img src="https://latex.codecogs.com/png.latex?%5Cbm%7BA%7D_1,...,%5Cbm%7BA%7D_m">. However, I have not yet been able to work out the general conditions under which this equivalence holds. It may require stricter conditions than those assumed in Theorem 2.</p>
</section>
<section id="references" class="level3">



<!-- -->


</section>

<a onclick="window.scrollTo(0, 0); return false;" id="quarto-back-to-top"><i class="bi bi-arrow-up"></i> Back to top</a><div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0" data-line-spacing="2">
<div id="ref-Bell2002bias" class="csl-entry">
Bell, R. M., &amp; McCaffrey, D. F. (2002). <span class="nocase">Bias reduction in standard errors for linear regression with multi-stage samples</span>. <em>Survey Methodology</em>, <em>28</em>(2), 169–181.
</div>
<div id="ref-McCaffrey2001generalizations" class="csl-entry">
McCaffrey, D. F., Bell, R. M., &amp; Botts, C. H. (2001). <span class="nocase">Generalizations of biased reduced linearization</span>. <em>Proceedings of the Annual Meeting of the American Statistical Association</em>.
</div>
</div></section></div> ]]></description>
  <category>robust variance estimation</category>
  <category>econometrics</category>
  <category>matrix algebra</category>
  <guid>https://jepusto.netlify.app/posts/Pusto-Tipton-2018-Theorem-2/</guid>
  <pubDate>Wed, 28 Sep 2022 00:00:00 GMT</pubDate>
</item>
</channel>
</rss>
