<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/x-x-is-not-2x/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.enchufa2.es/archives/x-x-is-not-2x.html"> R – Enchufa2</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>A few days ago, Joel Courtheyn posted <a target="_blank" rel="nofollow" href="https://github.com/Enchufa2/errors/issues/1">the following issue</a> in the <code>errors</code> package repository on GitHub:</p>
<blockquote><p>Experimenting with the new package I detected a difference in calculation of the error depending on the way a formula was written. Originally I tried to calculate the error for <code>z1 &lt;- (x^3 - 2y)/x^0.5</code> but this gave me a value which was different from the manual calculated error. When I transformed this formula to <code>z &lt;- x^2.5 - 2y*x^(-1/2)</code>, then I came to the right results.</p>
</blockquote>
<p>As I wrote there, the TL;DR version is that both calculations are correct, but the first formula is an abuse of notation. What do I mean by that? Let us consider a shorter but more intuitive version of the issue: <code>x + x</code> vs. <code>2*x</code>. In the first place, we define a quantity with a relative uncertainty of 5 %:</p>
<pre><code><span>library</span><span>(</span><span>errors</span><span>)</span>
<span>options</span><span>(</span><span>errors.notation</span> <span>=</span> <span>&quot;plus-minus&quot;</span><span>)</span>

<span>x</span> <span>&lt;-</span> <span>30</span>
<span>errors</span><span>(</span><span>x</span><span>)</span> <span>&lt;-</span> <span>x</span> <span>*</span> <span>0.05</span>
<span>x</span></code></pre>
<pre><code>## 30 +/- 2</code></pre>
<p>Now, let us see what happens:</p>
<pre><code><span>x</span> <span>+</span> <span>x</span></code></pre>
<pre><code>## 60 +/- 2</code></pre>
<pre><code><span>2</span><span>*</span><span>x</span></code></pre>
<pre><code>## 60 +/- 3</code></pre>
<p>First of all, we need to keep in mind that measurements with errors are not mathematical variables anymore: they are physical (in a broad sense) quantities. Imagine that we want to measure the width of a table, but we have a ruler that is only about half its width. So we manage to put a mark, by the means of some method (using a string, for instance), approximately at about half of the table. Then, we have two options: 1) to measure the first half and multiply it by two, or 2) to measure both halves and sum them.</p>
<p>Intuitively, 1), which corresponds to the <code>2*x</code> case, has a larger uncertainty, because we are not measuring the second half of the table (and note that this is exactly what we obtained before!). But in 2), even if the result of the second measurement matches the first one, <code>x + x</code> is an abuse of notation: <strong>they are different measurements</strong>, so we should write <code>x + y</code> instead, and the derived uncertainty is smaller.</p>
<p>Therefore, we can scale a certain measurement, apply any function to it… but to sum, multiply, divide… a measurement by itself has no physical meaning. <img title="x+x = 2x" alt="x+x = 2x" class="latex" src="https://s0.wp.com/latex.php?latex=x%2Bx+%3D+2x&bg=ffffff&%23038;fg=000&%23038;s=0"> is mathematically true, but <code>x + x</code> has no physical sense. We should say <code>x + y</code> (even if<code>x</code> is the same value as <code>y</code>), and <code>x + y != 2*x</code> when it comes to propagation of the uncertainty. The <code>errors</code> package helps us in the arduous task of uncertainty propagation, but checking the physical correctness of the expressions of derived measurements cannot be automated, and it is still our responsibility.</p>
<p><em>Article originally published in Enchufa2.es: <a target="_blank" rel="nofollow" href="https://www.enchufa2.es/archives/x-x-is-not-2x.html"><code>x + x</code> is not <code>2x</code></a></em>.</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://www.enchufa2.es/archives/x-x-is-not-2x.html"> R – Enchufa2</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/JqFNx-gM58Y"></a></div>