<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/another-reason-to-be-careful-about-what-you-control-for/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.rdatagen.net/post/another-reason-to-be-careful-about-what-you-control-for/"> ouR data generation</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Modeling data without any underlying causal theory can sometimes lead you down the wrong path, particularly if you are interested in understanding the <em>way</em> things work rather than making <em>predictions.</em> A while back, I <a rel="nofollow" href="https://www.rdatagen.net/post/be-careful/" target="_blank">described</a> what can go wrong when you control for a mediator when you are interested in an exposure and an outcome. Here, I describe the potential biases that are introduced when you inadvertently control for a variable that turns out to be a <strong><em>collider</em></strong>.</p>
<p>A collider, like a mediator, is a post-exposure/post-intervention outcome. Unlike a mediator, a collider is not necessarily causally related to the outcome of interest. (This is not to say that it cannot be, which is why this concept came up in a talk I gave about marginal structural models, described <a rel="nofollow" href="https://www.rdatagen.net/post/potential-outcomes-confounding/" target="_blank">here</a>, <a rel="nofollow" href="https://www.rdatagen.net/post/inverse-probability-weighting-when-the-outcome-is-binary/" target="_blank">here</a>, and <a rel="nofollow" href="https://www.rdatagen.net/post/when-a-covariate-is-a-confounder-and-a-mediator/" target="_blank">here</a>.) The key distinction of a collider is that it is an outcome that has two causes. In a directed acyclic graph (or <a rel="nofollow" href="http://www.dagitty.net/learn/index.html" target="_blank">DAG</a>), a collider is a variable with two arrows pointing towards it. This is easier to see visually:</p>
<div>
<img src="https://i1.wp.com/www.rdatagen.net/img/post-collider/Collider_names.png?w=456&ssl=1" data-recalc-dims="1">
</div>
<p>In this (admittedly thoroughly made-up though not entirely implausible) network diagram, the <em>test score</em> outcome is a collider, influenced by a <em>test preparation</em> class and <em>socio-economic status</em> (SES). In particular, both the test prep course and high SES are related to the probability of having a high test score. One might expect an arrow of some sort to connect SES and the test prep class; in this case, participation in test prep is randomized so there is no causal link (and I am assuming that everyone randomized to the class actually takes it, a compliance issue I addressed in a series of posts starting with <a rel="nofollow" href="https://www.rdatagen.net/post/cace-explored/" target="_blank">this one</a>.)</p>
<p>The researcher who carried out the randomization had a hypothesis that test prep actually is detrimental to college success down the road, because it de-emphasizes deep thinking in favor of wrote memorization. In reality, it turns out that the course and subsequent college success are not related, indicated by an <em>absence</em> of a connection between the course and the long term outcome.</p>
<div>
<h3>Simulate data</h3>
<p>We can simulate data from this hypothetical world (using functions from package <code>simstudy</code>):</p>
<pre><code># define data

library(simstudy)

defCollide &lt;- defData(varname = &quot;SES&quot;,
                      formula = &quot;0;1&quot;, 
                      dist = &quot;uniform&quot;)

defCollide &lt;- defData(defCollide, varname = &quot;testPrep&quot;,
                      formula = 0.5, 
                      dist = &quot;binary&quot;)

defCollide &lt;- defData(defCollide, varname = &quot;highScore&quot;, 
                      formula = &quot;-1.2 + 3*SES + 3*testPrep&quot;, 
                      dist = &quot;binary&quot;, link=&quot;logit&quot;)

defCollide &lt;- defData(defCollide, varname = &quot;successMeasure&quot;, 
                      formula = &quot;20 + SES*40&quot;, variance = 9,
                      dist = &quot;normal&quot;)

defCollide</code></pre>
<pre><code>##           varname                   formula variance    dist     link
## 1:            SES                       0;1        0 uniform identity
## 2:       testPrep                       0.5        0  binary identity
## 3:      highScore -1.2 + 3*SES + 3*testPrep        0  binary    logit
## 4: successMeasure               20 + SES*40        9  normal identity</code></pre>
<pre><code># generate data

set.seed(139)
dt &lt;- genData(1500, defCollide)

dt[1:6]</code></pre>
<pre><code>##    id        SES testPrep highScore successMeasure
## 1:  1 0.52510665        1         1       40.89440
## 2:  2 0.31565690        0         1       34.72037
## 3:  3 0.47978492        1         1       41.79532
## 4:  4 0.19114934        0         0       30.05569
## 5:  5 0.06889896        0         0       21.28575
## 6:  6 0.10139604        0         0       21.30306</code></pre>
<p>We can see that the distribution of the long-term (continuous) success outcome is the same for those who are randomized to test prep compared to those who are not, indicating there is no causal relationship between the test and the college outcome:</p>
<p><img src="https://i1.wp.com/www.rdatagen.net/post/2018-03-07-another-reason-to-be-careful-about-what-you-control-for_files/figure-html/unnamed-chunk-4-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>An unadjusted linear model leads us to the same conclusion, since the parameter estimate representing the treatment effect is quite small (and the hypothesis test is not statistically significant):</p>
<pre><code>library(broom)

rndtidy( lm(successMeasure ~ testPrep, data = dt))</code></pre>
<pre><code>##          term estimate std.error statistic p.value
## 1 (Intercept)   40.112      0.44    91.209   0.000
## 2    testPrep   -0.495      0.61    -0.811   0.418</code></pre>
</div>
<div>
<h3>But, don’t we need to adjust for some measure of intellectual ability?</h3>
<p>Or so the researcher might ask after looking at the initial results, questioning the model. He believes that differences in ability could be related to future outcomes. While this may be the case, the question isn’t about ability but the impact of test prep. Based on his faulty logic, the researcher decides to fit a second model and control for the test score that followed the experiment. And this is where things go awry. Take a look at the following model where there appears to be a relationship between test prep and college success after controlling for the test score:</p>
<pre><code># adjusted model

rndtidy( lm(successMeasure ~ highScore + testPrep, data = dt))</code></pre>
<pre><code>##          term estimate std.error statistic p.value
## 1 (Intercept)   35.525     0.619    57.409       0
## 2   highScore    8.027     0.786    10.207       0
## 3    testPrep   -3.564     0.662    -5.380       0</code></pre>
<p>It does indeed appear that the test prep course is causing problems for real learning in college later on!</p>
</div>
<div>
<h3>What is going on?</h3>
<p>Because the test score (here I am treating it as binary – either a high score or not), is related to both SES and test prep, the fact that someone does well on the test is due either to the fact that the student took the course, has high SES, or both. But, let’s consider the students who are possibly high SES or maybe took the course, but not not both, <strong><em>and</em></strong> who had a high test score. If a student is low SES, she probably took the course, or if she did not take the course, she is probably high SES. So, within the group that scored well, SES and the probability of taking the course are slightly negatively correlated.</p>
<p>If we “control” for test scores in the model, we are essentially comparing students within two distinct groups – those who scored well and those who did not. The updated network diagram shows a relationship between SES and test prep that didn’t exist before. This is the induced relationship we get by controlling a collider. (Control is shown in the diagram by removing the connection of SES and test prep to the test score.)</p>
<div>
<img src="https://i1.wp.com/www.rdatagen.net/img/post-collider/Collider_names_adjust.png?w=456&ssl=1" data-recalc-dims="1">
</div>
<p>If we look at the entire sample and compare the SES distribution (which is a continuous measure uniformly distributed between 0 and 1) for each test prep group, we see that both groups have the same distribution (i.e. there is no relationship):</p>
<p><img src="https://i1.wp.com/www.rdatagen.net/post/2018-03-07-another-reason-to-be-careful-about-what-you-control-for_files/figure-html/unnamed-chunk-7-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>But if we look at the relationship between SES and test prep within each test score group, the distributions no longer completely overlap – within each test score group, there is a relationship between SES and test prep.</p>
<p><img src="https://i2.wp.com/www.rdatagen.net/post/2018-03-07-another-reason-to-be-careful-about-what-you-control-for_files/figure-html/unnamed-chunk-8-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
</div>
<div>
<h3>Why does this matter?</h3>
<p>If the researcher has no good measure for SES or no measure at all, he cannot control for SES in the model. And now, because of the induced relationship between test prep and (unmeasured) SES, there is unmeasured confounding. This confounding leads to the biased estimate that we saw in the second model. And we see this bias in the densities shown for each test score group:</p>
<p><img src="https://i0.wp.com/www.rdatagen.net/post/2018-03-07-another-reason-to-be-careful-about-what-you-control-for_files/figure-html/unnamed-chunk-9-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>If it turns out that we <em>can</em> control for SES as well, because we have an adequate measure for it, then the artificial link between SES and test prep is severed, and so is the relationship between test prep and the long term college outcome.</p>
<pre><code>rndtidy( lm(successMeasure ~ SES + highScore + testPrep, data = dt))</code></pre>
<pre><code>##          term estimate std.error statistic p.value
## 1 (Intercept)   19.922     0.194   102.519   0.000
## 2         SES   40.091     0.279   143.528   0.000
## 3   highScore   -0.098     0.212    -0.462   0.644
## 4    testPrep    0.137     0.174     0.788   0.431</code></pre>
<p>The researcher can create problems by controlling for all the variables he has and not controlling for the variables he doesn’t have. Of course, if there are no colliders and mediators, then there is no harm. And unfortunately, without theory, it may be hard to know the structure of the DAG, particularly if there are important unmeasured variables. But, the researcher needs to proceed with a bit of caution.</p>
</div>
<div>
<h2>Addendum: selection bias</h2>
<p>“Selection bias” is used in a myriad of ways to characterize the improper assessment of an exposure-outcome relationship. For example, unmeasured confounding (where there is an unmeasured factor that influences both an exposure and an outcome) is often called selection bias, in the sense that the exposure is “selected” based on that particular characteristic.</p>
<p>Epidemiologists talk about selection bias in a very specific way, related to how individuals are selected or self-select into a study. In particular, if selection into a study depends on the exposure of interest and some other factor that is associated with the outcome, we can have selection bias.</p>
<p>How is this relevant to this post? Selection bias results from controlling a collider. In this case, however, control is done on through the study design, rather than through statistical modeling. Let’s say we have the same scenario with a randomized trial of a test prep course and we are primarily interested in the impact on the near-term test score. But, later on, we decide to explore the relationship of the course with the long-term college outcome and we send out a survey to collect the college outcome data. It turns out that those who did well on the near-term test were much more likely to respond to the survey – so those who have been selected (or in this case self-selected) will have an induced relationship between the test prep course and SES, just as before. Here is the new DAG:</p>
<div>
<img src="https://i2.wp.com/www.rdatagen.net/img/post-collider/Collider_names_select.png?w=456&ssl=1" data-recalc-dims="1">
</div>
<div>
<h3>Simulate new study selection variable</h3>
<p>The study response or selection variable is dependent on the near-term test score. The selected group is explicitly defined by the value of <code>inStudy</code></p>
<pre><code># selection bias

defS &lt;- defDataAdd(varname = &quot;inStudy&quot;, 
                   formula = &quot;-2.0 + 2.2 * highScore&quot;, 
                   dist = &quot;binary&quot;, link = &quot;logit&quot;)

dt &lt;- addColumns(defS, dt)

dSelect &lt;- dt[inStudy == 1]</code></pre>
<p>We can see that a large proportion of the the selected group has a high probability of having scored high on the test score:</p>
<pre><code>dSelect[, mean(highScore)]</code></pre>
<pre><code>## [1] 0.9339207</code></pre>
</div>
<div>
<h3>Selection bias is a muted version of full-on collider bias</h3>
<p>Within this group of selected students, there is an (incorrectly) estimated relationship between the test prep course and subsequent college success. This bias is what epidemiologists are talking about when they talk about selection bias:</p>
<pre><code>rndtidy( lm(successMeasure ~ testPrep, data = dSelect))</code></pre>
<pre><code>##          term estimate std.error statistic p.value
## 1 (Intercept)   41.759     0.718    58.154   0.000
## 2    testPrep   -2.164     0.908    -2.383   0.017</code></pre>
</div>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.rdatagen.net/post/another-reason-to-be-careful-about-what-you-control-for/"> ouR data generation</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/wTDdLvLMcQw" height="1"></a></div>