<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/the-real-meaning-of-spurious-correlations/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://nsaunders.wordpress.com/2017/02/03/the-real-meaning-of-spurious-correlations/"> R – What You're Doing Is Rather Desperate</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Like many data nerds, I’m a big fan of Tyler Vigen’s <a target="_blank" rel="nofollow" href="http://www.tylervigen.com/spurious-correlations">Spurious Correlations</a>, a humourous illustration of the old adage “correlation does not equal causation”. Technically, I suppose it should be called “spurious interpretations” since the correlations themselves are quite real, but then good marketing is everything.</p>
<p>There is, however, a more formal definition of the term <em>spurious correlation</em> or more specifically, as the excellent <a target="_blank" rel="nofollow" href="https://en.wikipedia.org/wiki/Spurious_correlation_of_ratios">Wikipedia page</a> is now titled, <em>spurious correlation of ratios</em>. It describes the following situation:</p>
<ol>
<li>You take a bunch of measurements X1, X2, X3…</li>
<li>And a second bunch of measurements Y1, Y2, Y3…</li>
<li>There’s no correlation between them</li>
<li>Now divide both of them by a third set of measurements Z1, Z2, Z3…</li>
<li>Guess what? Now there is correlation between the ratios X/Z and Y/Z</li>
</ol>
<p>It’s easy to demonstrate for yourself, using R to create something like the chart in the Wikipedia article.</p>
<p><span></span></p>
<p>First, create 500 observations for each of x, y and z.</p>
<pre>
library(ggplot2)

set.seed(123)
spurious_data &lt;- data.frame(x = rnorm(500, 10, 1),
                            y = rnorm(500, 10, 1),
                            z = rnorm(500, 30, 3))
</pre>
<p>Next, convince yourself that x and y are uncorrelated.</p>
<pre>
cor(spurious_data$x, spurious_data$y)
# [1] -0.05943856
spurious_data %>% ggplot(aes(x, y)) + geom_point(alpha = 0.3) + 
theme_bw() + labs(title = &quot;Plot of y versus x for 500 observations with N(10, 1)&quot;)
</pre>
<p><img sizes="(max-width: 729px) 100vw, 729px" data-image-description="" data-orig-file="https://i0.wp.com/nsaunders.files.wordpress.com/2017/02/spurious1.png?w=456&amp;ssl=1" data-orig-size="729,519" data-image-title="spurious1" class="wp-image-4604" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="4604" data-permalink="https://nsaunders.wordpress.com/2017/02/03/the-real-meaning-of-spurious-correlations/spurious1/" alt="spurious1" data-medium-file="https://i0.wp.com/nsaunders.files.wordpress.com/2017/02/spurious1.png?w=456&amp;ssl=1?w=300" data-large-file="https://i0.wp.com/nsaunders.files.wordpress.com/2017/02/spurious1.png?w=456&amp;ssl=1?w=729" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i0.wp.com/nsaunders.files.wordpress.com/2017/02/spurious1.png?w=456&ssl=1"></p>
<p>Finally, repeat step 2 after dividing x and y through by z.</p>
<pre>
cor(spurious_data$x / spurious_data$z, spurious_data$y / spurious_data$z)
# [1] 0.4517972
spurious_data %>% ggplot(aes(x/z, y/z)) + geom_point(aes(color = z), alpha = 0.5) +
 theme_bw() + geom_smooth(method = &quot;lm&quot;) + 
scale_color_gradientn(colours = c(&quot;red&quot;, &quot;white&quot;, &quot;blue&quot;)) + 
labs(title = &quot;Plot of y/z versus x/z for 500 observations with x,y N(10, 1); z N(30, 3)&quot;)
</pre>
<p><img sizes="(max-width: 729px) 100vw, 729px" data-image-description="" data-orig-file="https://i2.wp.com/nsaunders.files.wordpress.com/2017/02/spurious2.png?w=456&amp;ssl=1" data-orig-size="729,519" data-image-title="spurious2" data-comments-opened="1" class="wp-image-4619" data-recalc-dims="1" data-attachment-id="4619" data-permalink="https://nsaunders.wordpress.com/2017/02/03/the-real-meaning-of-spurious-correlations/spurious2/" alt="spurious2" data-medium-file="https://i2.wp.com/nsaunders.files.wordpress.com/2017/02/spurious2.png?w=456&amp;ssl=1?w=300" data-large-file="https://i2.wp.com/nsaunders.files.wordpress.com/2017/02/spurious2.png?w=456&amp;ssl=1?w=729" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i2.wp.com/nsaunders.files.wordpress.com/2017/02/spurious2.png?w=456&ssl=1"></p>
<p>This effect is reasonably intuitive: dividing both x and y by the same z forces them into the range (0,1). Larger values for z push x/z and y/z towards lower values, smaller values of z push them towards higher values. Visually though, it’s quite a striking effect which is even more pronounced if we increase the standard deviation for z.</p>
<pre>
spurious_data$z &lt;- rnorm(500, 30, 6)
cor(spurious_data$x / spurious_data$z, spurious_data$y / spurious_data$z)
# [1] 0.8424597
spurious_data %>% ggplot(aes(x/z, y/z)) + geom_point(aes(color = z), alpha = 0.5) + 
theme_bw() + geom_smooth(method = &quot;lm&quot;) + 
scale_color_gradientn(colours = c(&quot;red&quot;, &quot;white&quot;, &quot;blue&quot;)) + 
labs(title = &quot;Plot of y/z versus x/z for 500 observations with x,y N(10, 1); z N(30, 6)&quot;)
</pre>
<p><img sizes="(max-width: 729px) 100vw, 729px" data-image-description="" data-orig-file="https://i0.wp.com/nsaunders.files.wordpress.com/2017/02/spurious3.png?w=456&amp;ssl=1" data-orig-size="729,519" data-image-title="spurious3" data-comments-opened="1" class="wp-image-4640" data-recalc-dims="1" data-attachment-id="4640" data-permalink="https://nsaunders.wordpress.com/spurious3/" alt="spurious3" data-medium-file="https://i0.wp.com/nsaunders.files.wordpress.com/2017/02/spurious3.png?w=456&amp;ssl=1?w=300" data-large-file="https://i0.wp.com/nsaunders.files.wordpress.com/2017/02/spurious3.png?w=456&amp;ssl=1?w=729" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i0.wp.com/nsaunders.files.wordpress.com/2017/02/spurious3.png?w=456&ssl=1"></p>
<p>Which looks an awful lot like a chart that I found recently in a published article that I was reading at work. Note that both axes are rates between 0-100 (percentages), suggesting that values were divided by a common divisor.</p>
<p><img sizes="(max-width: 468px) 100vw, 468px" data-image-description="" data-orig-file="https://i1.wp.com/nsaunders.files.wordpress.com/2017/02/wp2014n22-2-pdf.png?w=456&amp;ssl=1" data-orig-size="468,349" data-image-title="wp2014n22-2-pdf" data-comments-opened="1" class="wp-image-4643" data-recalc-dims="1" data-attachment-id="4643" data-permalink="https://nsaunders.wordpress.com/wp2014n22-2-pdf/" alt="spurious4" data-medium-file="https://i1.wp.com/nsaunders.files.wordpress.com/2017/02/wp2014n22-2-pdf.png?w=456&amp;ssl=1?w=300" data-large-file="https://i1.wp.com/nsaunders.files.wordpress.com/2017/02/wp2014n22-2-pdf.png?w=456&amp;ssl=1?w=468" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i1.wp.com/nsaunders.files.wordpress.com/2017/02/wp2014n22-2-pdf.png?w=456&ssl=1"></p>
<p>Should you wish to compare ratios or “relative” measurements, consult <a target="_blank" rel="nofollow" href="http://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1004075">this reference</a> and take a look at the R package <em><a target="_blank" rel="nofollow" href="https://rdrr.io/cran/propr/">propr</a></em>, which implements methods for <em>proportionality</em>.</p>
<p>Filed under: <a target="_blank" rel="nofollow" href="https://nsaunders.wordpress.com/category/statistics/r/">R</a>, <a target="_blank" rel="nofollow" href="https://nsaunders.wordpress.com/category/statistics/">statistics</a> Tagged: <a target="_blank" rel="nofollow" href="https://nsaunders.wordpress.com/tag/causation/">causation</a>, <a target="_blank" rel="nofollow" href="https://nsaunders.wordpress.com/tag/correlation/">correlation</a>, <a target="_blank" rel="nofollow" href="https://nsaunders.wordpress.com/tag/proportionality/">proportionality</a>, <a target="_blank" rel="nofollow" href="https://nsaunders.wordpress.com/tag/ratios/">ratios</a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nsaunders.wordpress.com/4559/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/nsaunders.wordpress.com/4559/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" data-recalc-dims="1"></p>
<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://nsaunders.wordpress.com/2017/02/03/the-real-meaning-of-spurious-correlations/"> R – What You're Doing Is Rather Desperate</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/pwpmW7UXGRY"></a></div>