# What does correlation mean in error propagation?

From the python uncertainties package:

Correlations between expressions are correctly taken into account. Thus, x-x is exactly zero, for instance (most implementations found on the web yield a non-zero uncertainty for x-x, which is incorrect).

x is a single value, with an uncertainty. What does correlation mean in this context?

Example code to illustrate what it's talking about:

In : from uncertainties import ufloat, umath

In : x = ufloat(2,1)

In : x
Out: 2.0+/-1.0

In : y = ufloat(2,1)

In : y
Out: 2.0+/-1.0

In : z = umath.log(umath.exp(x))

In : z
Out: 2.0+/-1.0

In : x-y
Out: 0.0+/-1.4142135623730951

In : x-z
Out: 0.0+/-0


In this example, x, y, and z are all single values with an uncertainty. I don't understand how two single values can be "correlated".

In a practical sense, I'd also be interested to know how uncertainties actually keeps track of this "correlation".

Further, why doesn't this include some of the uncorrelated error between x and z?

In : b=x+y

In : c=y+z

In : b-c
Out: 0.0+/-0


$x$ is perfectly correlated with itself, so $x-x$ is $0$, with no uncertainty. The example given in the documentation is not really a very good one, since this isn't a common situation and the result is trivial. More importantly, if $x$ and $y$ are correlated, than the documentation is claiming that the code will take this correlation into account when computing an uncertainty for $x-y$.

The OP edited his question, so I've edited this response to try to answer the new question:

In this code, $x$, $y$, and $z$ are random variables with given expected values, standard deviations, and correlations. In your example, $x$ is a random variable with expected value 2.0 and standard deviation 1.0. $z$ is also a random variable with expected value 2.0 and standard deviation 1.0. Furthermore, by keeping track of the operations that connected $x$ to $z$, the code knows that the correlation between $x$ and $z$ is 1. Thus $x-z$ is a random variable with expected value 0 and standard deviation 0.

Meanwhile $y$ is an independent random variable with expected value 2.0 and standard deviation $1$. $x-y$ is then a random variable with expected value 0.0 and standard deviation 1.414...

The software is propagating variances using the basic formulas that

$E[aX+bY]=aE[X]+bE[Y]$.

and

$\mbox{Var}(aX+bY)=a^2\mbox{Var}(X)+b^{2}\mbox{Var}(Y)+2ab\mbox{Cov}(X,Y)$

The package is presumably capable of using simple Taylor series expansions to compute means and variances for expressions involving more complicated functions (It may have handled the log(exp(x)) by Taylor series expansion or it may have simplified log(exp(x)) to x directly- I'm not familiar with the innards of the package.)

• I understand what the code is doing, I'm just not clear why. – naught101 Feb 26 '15 at 2:53
• Which of the answers in Out, Out, Out, and out do you think is incorrect, and what part of the answer (the expected value or the standard deviation or perhaps both) do you feel is wrong? – Brian Borchers Feb 26 '15 at 3:21
• Or, if you're willing to accept that these outputs are correct, which output would you like to have explained in more detail? – Brian Borchers Feb 26 '15 at 3:52
• Thanks for the added details. Given your answer, I understand the $x-y$ having a standard deviation of 0 (mistake in your answer there), and $x-z$ having a std dev of $\sqrt{2}$, but I would expect $b-c$ to have a non-zero variance, because it is effectively two partially correlated variables - $(x+y) - (y+z)$ where $x$ and $y$ are correlated. Is that different to $(x+y-y)-z = x-z$ (std.dev=1.414...)? – naught101 Feb 26 '15 at 4:08
• Both the output quoted in your edited question and my answer above say that $x-z$ is a constant (standard deviation 0) and that $x-y$ is a random variable with standard deviation 1.414... Your most recent comment disagrees with this, so I can't make sense of what's you've written. – Brian Borchers Feb 26 '15 at 4:24