# Confusion about the correlation coefficient [closed]

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?

• Clear["Global*"]; x = RandomReal[1, 1000]; y = 1 - x; Correlation[x, y] evaluates to -1. – Bob Hanlon Aug 11 '20 at 2:07

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).
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}]];

• "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. – Sjoerd Smit Aug 11 '20 at 9:25