<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/in-regression-we-assume-noise-is-independent-of-all-measured-predictors-what-happens-if-it-isnt/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.rdatagen.net/post/linear-regression-models-assume-noise-is-independent/"> ouR data generation</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>A number of key assumptions underlie the linear regression model – among them linearity and normally distributed noise (error) terms with constant variance In this post, I consider an additional assumption: the unobserved noise is uncorrelated with any covariates or predictors in the model.</p>
<p>In this simple model:</p>
<p><span>\[Y_i = \beta_0 + \beta_1X_i + e_i,\]</span></p>
<p><span>\(Y_i\)</span> has both a structural and stochastic (random) component. The structural component is the linear relationship of <span>\(Y\)</span> with <span>\(X\)</span>. The random element is often called the <span>\(error\)</span> term, but I prefer to think of it as <span>\(noise\)</span>. <span>\(e_i\)</span> is not measuring something that has gone awry, but rather it is variation emanating from some unknown, unmeasurable source or sources for each individual <span>\(i\)</span>. It represents everything we haven’t been able to measure.</p>
<p>Our goal is to estimate <span>\(\beta_1\)</span>, which characterizes the structural linear relationship of <span>\(X\)</span> and <span>\(Y\)</span>. When we estimate the model, we get a quantity <span>\(\hat{\beta_1}\)</span>, and we hope that on average we do pretty well (i.e. if we were to estimate <span>\(\beta_1\)</span> repeatedly, <span>\(E[\hat{\beta_1}] = \beta_1\)</span>). In order for us to make sure that is the case, we need to assume that <span>\(e_i\)</span> and <span>\(X_i\)</span> are independent. In other words, the sources that comprise <span>\(e_i\)</span> must not be related in way to whatever it is that <span>\(X_i\)</span> is measuring.</p>
<div>
<h3>Correlation without causation</h3>
<p>First, I’ll generate <span>\(X's\)</span> and <span>\(e's\)</span> that are correlated with a using a data generation process that makes no assumptions about the underlying causal process. The provides a picture of how <span>\(\hat{\beta_1}\)</span> might diverge from the true <span>\(\beta_1\)</span>.</p>
<pre><code>library(simstudy)
set.seed(3222)

dT &lt;- genCorData(500, mu = c(0, 0), sigma = c(sqrt(1.25), 1), 
                 rho = 0.446, corstr = &quot;cs&quot;, cnames = c(&quot;X&quot;,&quot;eCor&quot;))</code></pre>
<p>Outcome <span>\(Y\)</span> is based on <span>\(X\)</span> and <span>\(e_{cor}\)</span>. For comparison’s sake, I generate a parallel outcome that is also based on <span>\(X\)</span> but the noise variable <span>\(e_{ind}\)</span> is independent of <span>\(X\)</span>:</p>
<pre><code>def &lt;- defDataAdd(varname = &quot;Ycor&quot;, formula = &quot;X + eCor&quot;,
                  dist = &quot;nonrandom&quot;)
def &lt;- defDataAdd(def, varname = &quot;eInd&quot;, formula = 0, variance = 1,
                  dist = &quot;normal&quot; )
def &lt;- defDataAdd(def, varname = &quot;Yind&quot;, formula = &quot;X + eInd&quot;,
                  dist = &quot;nonrandom&quot;)

dT &lt;- addColumns(def, dT)
dT</code></pre>
<pre><code>##       id          X       eCor       Ycor       eInd        Yind
##   1:   1 -1.1955846 -0.1102777 -1.3058624  1.1369435 -0.05864113
##   2:   2 -0.4056655 -0.6709221 -1.0765875 -0.8441431 -1.24980856
##   3:   3 -0.5893938  1.2146488  0.6252550 -0.2666314 -0.85602516
##   4:   4  0.9090881  0.3108645  1.2199526  0.3397857  1.24887377
##   5:   5 -2.6139989 -1.7382986 -4.3522975 -0.1793858 -2.79338470
##  ---                                                            
## 496: 496  3.1615624  0.6160661  3.7776285  0.4658992  3.62746167
## 497: 497  0.6416140  0.1031316  0.7447456 -0.1440062  0.49760784
## 498: 498  0.1340967 -0.4029388 -0.2688421  0.6165793  0.75067604
## 499: 499 -1.2381040  0.8197002 -0.4184038  0.6717294 -0.56637463
## 500: 500 -0.7159373 -0.0905287 -0.8064660  0.9148175  0.19888019</code></pre>
<p>The observed <span>\(X\)</span> and <span>\(e_{cor}\)</span> are correlated, but <span>\(X\)</span> and <span>\(e_{ind}\)</span> are not:</p>
<pre><code>dT[, cor(cbind(X, eCor))]</code></pre>
<pre><code>##              X      eCor
## X    1.0000000 0.4785528
## eCor 0.4785528 1.0000000</code></pre>
<pre><code>dT[, cor(cbind(X, eInd))]</code></pre>
<pre><code>##                X        eInd
## X     1.00000000 -0.02346812
## eInd -0.02346812  1.00000000</code></pre>
<p>On the left below is a plot of outcome <span>\(Y_{ind}\)</span> as a function of <span>\(X\)</span>. The red line is the true structural component defining the relationship between these two variables. The points are scattered around that line without any clear pattern, which is indicative of independent noise.</p>
<p>The plot on the right shows <span>\(Y_{cor}\)</span> as a function of <span>\(X\)</span>. Since the stochastic component of <span>\(Y_{cor}\)</span> is the correlated noise, the lower <span>\(X\)</span> values are more likely to fall below the true line, and the larger <span>\(X\)</span> values above. The red line does not appear to be a very good fit in this case; this is the bias induced by correlated noise.</p>
<p><img src="https://i1.wp.com/www.rdatagen.net/post/2018-10-10-linear-regression-models-assume-noise-is-independent_files/figure-html/unnamed-chunk-4-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>The model fits corroborate the visual inspection. <span>\(\hat{\beta_1}\)</span> based on uncorrelated noise is close to 1, the true value:</p>
<pre><code>fit2 &lt;- lm(Yind ~ X, data = dT)
rndTidy(fit2)</code></pre>
<pre><code>##           term estimate std.error statistic p.value
## 1: (Intercept)     0.06      0.05      1.37    0.17
## 2:           X     0.98      0.04     25.75    0.00</code></pre>
<p><span>\(\hat{\beta_1}\)</span> based on correlated noise is 1.42, larger than the true value:</p>
<pre><code>fit1 &lt;- lm(Ycor ~ X, data = dT)
rndTidy(fit1)</code></pre>
<pre><code>##           term estimate std.error statistic p.value
## 1: (Intercept)    -0.01      0.04     -0.25     0.8
## 2:           X     1.42      0.03     41.28     0.0</code></pre>
<p>A plot of the fitted (blue) line based on the biased estimate clearly shows the problem of regression estimation in this context:</p>
<p><img src="https://i0.wp.com/www.rdatagen.net/post/2018-10-10-linear-regression-models-assume-noise-is-independent_files/figure-html/unnamed-chunk-7-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
</div>
<div>
<h3>Thinking about underlying causality and noise</h3>
<p>Here is a pure thought exercise to consider this bias induced by the correlation. Fundamentally, the implications depend on the purpose of the model. If we are using the model for description or prediction, we may not care about the bias. For example, if we are <em>describing</em> how <span>\(Y\)</span> changes as <span>\(X\)</span> changes in some population, the underlying data generation process may not be of interest. Likewise, if our goal is predicting <span>\(Y\)</span> based on an observed <span>\(X\)</span>, the biased estimate of <span>\(\beta_1\)</span> may be adequate.</p>
<p>However, if we are interested in understanding how <em>intervening</em> or <em>changing</em> the level of <span>\(X\)</span> at the individual level effects the outcome <span>\(Y\)</span> for that individual, then an unbiased estimate of <span>\(\beta_1\)</span> becomes more important, and noise that is correlated with the predictor of interest could be problematic.</p>
<p>However, in a causal context, all noise may not be created equally. Consider these two different causal models:</p>
<p><img src="https://i1.wp.com/www.rdatagen.net/img/post-correrrors/confounding_mediation.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>We can generate identically distributed data based on these two mechanisms:</p>
<pre><code># Confounding

defc &lt;- defData(varname = &quot;U&quot;, formula=0, variance=1, dist=&quot;normal&quot;)
defc &lt;- defData(defc, &quot;X&quot;, &quot;0.5*U&quot;, 1, &quot;normal&quot;)
defc &lt;- defData(defc, &quot;Y&quot;, &quot;X + U&quot;, dist = &quot;nonrandom&quot;)

dcon &lt;- genData(1000, defc)</code></pre>
<pre><code># Mediation

defm &lt;- defData(varname=&quot;X&quot;, formula=0, variance =1.25, dist=&quot;normal&quot;)
defm &lt;- defData(defm, &quot;U&quot;, &quot;.4*X&quot;, .8, &quot;normal&quot;)
defm &lt;- defData(defm, &quot;Y&quot;, &quot;X + U&quot;, dist = &quot;nonrandom&quot;)

dmed &lt;- genData(1000, defm)</code></pre>
<p>The observed covariance between <span>\(X\)</span> and <span>\(U\)</span> (the noise) is similar for the two processes …</p>
<pre><code>dcon[, var(cbind(X,U))]</code></pre>
<pre><code>##           X         U
## X 1.2516199 0.5807696
## U 0.5807696 1.0805321</code></pre>
<pre><code>dmed[, var(cbind(X,U))]</code></pre>
<pre><code>##           X         U
## X 1.2365285 0.5401577
## U 0.5401577 1.0695366</code></pre>
<p>… as is the model fit for each:</p>
<p><img src="https://i0.wp.com/www.rdatagen.net/post/2018-10-10-linear-regression-models-assume-noise-is-independent_files/figure-html/unnamed-chunk-11-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>And here is a pair of histograms of estimated values of <span>\(\beta_1\)</span> for each data generating process, based on 1000 replications of samples of 100 individuals. Again, pretty similar:</p>
<p><img src="https://i1.wp.com/www.rdatagen.net/post/2018-10-10-linear-regression-models-assume-noise-is-independent_files/figure-html/unnamed-chunk-12-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>Despite the apparent identical nature of the two data generating processes, I would argue that biased estimation is only a problem in the context of confounding noise. If we intervene on <span>\(X\)</span> without changing <span>\(U\)</span>, which could occur in the context of unmeasured confounding, the causal effect of <span>\(X\)</span> on <span>\(Y\)</span> would be overestimated by the regression model. However, if we intervene on <span>\(X\)</span> in the context of a process that involves mediation, it would be appropriate to consider all the post-intervention effects of changing <span>\(X\)</span>, so the “biased” estimate may in fact be the appropriate one.</p>
<p>The key here, of course, is that we cannot verify this unobserved process. By definition, the noise is unobservable and stochastic. But, if we are developing models that involve causal relations of unmeasured quantities, we have to be explicit about the causal nature underlying these unmeasured quantities. That way, we know if we should be concerned about hidden correlation or not.</p>
</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/linear-regression-models-assume-noise-is-independent/"> 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/2pbeyIh40QE" height="1"></a></div>