<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/what-is-a-linear-trend-by-the-way/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://freakonometrics.hypotheses.org/50003"> R-english – Freakonometrics</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I had a very stranger discussion on twitter (yes, another one), about regression curves. I think it started with a tweet based on some xkcd picture (just for fun, because it was New Year’s Day)</p>
<blockquote class="twitter-tweet">
<p dir="ltr" lang="en">“don’t trust linear regressions” <a target="_blank" rel="nofollow" href="https://t.co/exUCvyRd1G">https://t.co/exUCvyRd1G</a> <a target="_blank" rel="nofollow" href="https://t.co/O6rBJfkULa">pic.twitter.com/O6rBJfkULa</a></p>
<p>— Arthur Charpentier (@freakonometrics) <a target="_blank" rel="nofollow" href="https://twitter.com/freakonometrics/status/815590818052538368">1 janvier 2017</a></p>
</blockquote>
<p>There were comments on that picture, by econometricians, mainly about ‘significant’ trends when datasets are very noisy. And I mentioned a graph that I saw earlier, that day</p>
<blockquote class="twitter-tweet">
<p dir="ltr" lang="en"><a target="_blank" rel="nofollow" href="https://twitter.com/AndyHarless">@AndyHarless</a> <a target="_blank" rel="nofollow" href="https://twitter.com/mileskimball">@mileskimball</a> actually, all that reminds me of a post by <a target="_blank" rel="nofollow" href="https://twitter.com/RogerPielkeJr">@RogerPielkeJr</a> earlier (not a big fan of the regression line) <a target="_blank" rel="nofollow" href="https://t.co/NQgzgVsBcE">pic.twitter.com/NQgzgVsBcE</a></p>
<p>— Arthur Charpentier (@freakonometrics) <a target="_blank" rel="nofollow" href="https://twitter.com/freakonometrics/status/815664761757114369">1 janvier 2017</a></p>
</blockquote>
<p>Let us reproduce that graph (Roger kindly sent me the dataset)</p>
<p><code>db=data.frame(year=1990:2016,<br>
ratio=c(.23,.27,.32,.37,.22,.26,.29,.15,.40,.28,.14,.09,.24,.18,.29,.51,.13,.17,.25,.13,.21,.29,.25,.2,.15,.12,.12))<br>
library(ggplot2)</code></p>
<p>The graph is here (using the same conventions as Roger’s initial graph, using some sort of barplot)</p>
<p><code>ggplot(db, aes(year, ratio)) +<br>
geom_bar(stat=&quot;identity&quot;) +<br>
stat_smooth(method = &quot;lm&quot;, se = FALSE)</code></p>
<p><img alt="" src="https://i0.wp.com/freakonometrics.hypotheses.org/files/2017/01/pilke1.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>My point was that we miss the ‘confidence band’ of the regression</p>
<blockquote class="twitter-tweet">
<p dir="ltr" lang="en"><a target="_blank" rel="nofollow" href="https://twitter.com/freakonometrics">@freakonometrics</a> <a target="_blank" rel="nofollow" href="https://twitter.com/AndyHarless">@AndyHarless</a> <a target="_blank" rel="nofollow" href="https://twitter.com/mileskimball">@mileskimball</a> Because it is not a sample. Since 1990 weather losses/global GDP have gone down.</p>
<p>— Roger Pielke Jr. (@RogerPielkeJr) <a target="_blank" rel="nofollow" href="https://twitter.com/RogerPielkeJr/status/815668251246166016">1 janvier 2017</a></p>
</blockquote>
<p>In R, at least, it is quite natural to get (and actually, it is the default version of the graph function)</p>
<p><code>ggplot(db, aes(year, ratio)) +<br>
geom_bar(stat=&quot;identity&quot;) +<br>
stat_smooth(method = &quot;lm&quot;, se = TRUE)</code></p>
<p><img alt="" src="https://i1.wp.com/freakonometrics.hypotheses.org/files/2017/01/pilke2.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>It is hard to claim that the ‘regression line’ is significant (in the sense significantly non horizontal). To be more specific, if we look at the output of the regression model, we get</p>
<p><code>summary(lm(ratio~year,data=db))<br>
</code></p>
<p><code>Coefficients:<br>
Estimate    Std. Error t value Pr(>|t|)<br>
(Intercept) 9.158531 4.549672  2.013 0.055 .<br>
year       -0.004457 0.002271 -1.962 0.061 .<br>
---<br>
Signif. codes: 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1</code></p>
<p>(which is exactly what Roger used in his graph to plot his red straight line). The <em>p</em>-value of the estimator of the slope, in a linear regression model is here 6%. But I found Roger’s point puzzeling</p>
<blockquote class="twitter-tweet">
<p dir="ltr" lang="en"><a target="_blank" rel="nofollow" href="https://twitter.com/freakonometrics">@freakonometrics</a> <a target="_blank" rel="nofollow" href="https://twitter.com/AndyHarless">@AndyHarless</a> <a target="_blank" rel="nofollow" href="https://twitter.com/mileskimball">@mileskimball</a> Disagree. U can create one, of course, but doesnt mean much. These data are not balls from urns.</p>
<p>— Roger Pielke Jr. (@RogerPielkeJr) <a target="_blank" rel="nofollow" href="https://twitter.com/RogerPielkeJr/status/815671247623294976">1 janvier 2017</a></p>
</blockquote>
<p>See also</p>
<blockquote class="twitter-tweet">
<p dir="ltr" lang="en"><a target="_blank" rel="nofollow" href="https://twitter.com/freakonometrics">@freakonometrics</a> <a target="_blank" rel="nofollow" href="https://twitter.com/AndyHarless">@AndyHarless</a> <a target="_blank" rel="nofollow" href="https://twitter.com/mileskimball">@mileskimball</a> These data are not random.</p>
<p>— Roger Pielke Jr. (@RogerPielkeJr) <a target="_blank" rel="nofollow" href="https://twitter.com/RogerPielkeJr/status/815671628596178944">1 janvier 2017</a></p>
</blockquote>
<p>First of all, let us get back to a more standard graph, with a scatterplot, and not bars,</p>
<p><code>ggplot(db, aes(year, ratio)) +<br>
stat_smooth(method = &quot;lm&quot;) +<br>
geom_point() </code></p>
<p><img alt="" src="https://i0.wp.com/freakonometrics.hypotheses.org/files/2017/01/pilke3.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>Here, we observe points <img alt="https://latex.codecogs.com/gif.latex?{y_{1990},y_{1991},cdots,y_{2016}}" src="https://latex.codecogs.com/gif.latex?%5C%7By_%7B1990%7D,y_%7B1991%7D,%5Ccdots,y_%7B2016%7D%5C%7D">. In order to draw that blue line, we assume (econometrics 101) that those observations are realizations of random variables <img alt="https://latex.codecogs.com/gif.latex?{Y_{1990},Y_{1991},cdots,Y_{2016}}" src="https://latex.codecogs.com/gif.latex?%5C%7BY_%7B1990%7D,Y_%7B1991%7D,%5Ccdots,Y_%7B2016%7D%5C%7D">. Randomness here does not come from a survey, or from ‘balls in an urn’. Randomness is because hurricanes and floods are themselves seen are realizations of random events. Yes, there might be measurement errors, but that’s not where randomness comes from. Here, when we talk about ‘randomness’, it should be related to ‘model error’ i.e. the error we make if we consider a linear model (here), that is</p>
<p><img alt="https://latex.codecogs.com/gif.latex?Y_t=beta_0+beta_1t+varepsilon_t" src="https://latex.codecogs.com/gif.latex?Y_t=%5Cbeta_0+%5Cbeta_1t+%5Cvarepsilon_t"></p>
<p>Even if observations are not obtained from balls in an urn, there is some kind of randomness here. One might consider a nonlinear model to reduce the error,</p>
<p><code>ggplot(db, aes(year, ratio)) +<br>
geom_point() +<br>
geom_smooth()</code></p>
<p>but in the case, the danger is to overfit</p>
<p><img alt="" src="https://i0.wp.com/freakonometrics.hypotheses.org/files/2017/01/pilke4.png?w=456&ssl=1" 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="http://freakonometrics.hypotheses.org/50003"> R-english – Freakonometrics</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/RWz99tqgtik"></a></div>