0
$\begingroup$

If a wooden stick with a length of 1 meter is randomly cut into two sections, what is the correlation coefficient of the length of the two sections?

Refine[Correlation[{x, 1 - x}], 1 > x > 0]

I use the above code and get a result of 1, but the answer is -1, I want to know what's wrong?

$\endgroup$
  • 3
    $\begingroup$ Clear["Global`*"]; x = RandomReal[1, 1000]; y = 1 - x; Correlation[x, y] evaluates to -1. $\endgroup$ – Bob Hanlon Aug 11 at 2:07
7
$\begingroup$

You are confusing a particular sample of size 1 ({x,1-x}) and the bivariate random variable $(X, 1-X)$ where $X\sim U(0,1)$. Also, your use of {x,1-x} doesn't appear to be one of the allowed parameter inputs (unless {x,1-x} is being considered as a matrix).

I don't see why Mathematica gives an answer of 1. It probably should have complained about the input you gave.

The appropriate answer for your question is to treat $X$ and $1-X$ as random variables:

d = TransformedDistribution[{x, 1 - x}, x \[Distributed] UniformDistribution[{0, 1}]];
Correlation[d, 1, 2]
(* -1 *)
| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ "I don't see why Mathematica gives an answer of 1. It probably should have complained about the input you gave." Mathematica is just computing the correlation matrix of a sample of 2 scalar observations. Compare Correlation[{{1}, {2}}] and Correlation[{1, 2}]. Since the observations are 1D, the correlation matrix is 1 x 1 and therefore only has the element 1, which is the diagonal element that's always 1 regardless of the data. $\endgroup$ – Sjoerd Smit Aug 11 at 9:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.