$X_1$ and $X_2$ are two binary stochastic variables with simultaneous probabilitydistribution:

$$ \begin{matrix} &X_2=0&X_2=1\\ X_1=0&0.30&0.17\\ X_1=1&0.08&0.45 \end{matrix} $$

I want to calculate the correlation between $X_1$ and $X_2$.

Correlation[{{0.30, 0.17}, {0.08, 0.45}}]

The output I get is {{1,-1},{-1,1}}

The solution I seek is: 0.05011

It should be pretty simple, but I have no idea where I am wrong.


1 Answer 1


You could set this up in symbolic form as a bivariate distribution with pmf $f(x,y)$:

enter image description here

Then, using the mathStatica add-on to Mathematica, the correlation you seek is:

Corr[{x, y}, f]


Note that this is slightly different to the solution you posted,as the numerical value is: 0.501123... (not 0.0501).

You can make Mma do this operation too, by itself, as per:

dist = ProbabilityDistribution[f, {x, 0, 1, 1}, {y, 0, 1, 1}]

where f is the piecewise function above, and then evaluate:


The problem with your use of Correlation[{{0.30, 0.17}, {0.08, 0.45}}] is this ... You could use Correlation[xdata, ydata] to find the sample correlation between xdata and ydata ... but (a) you are not seeking a sample correlation ... you are seeking the population correlation, and (b) {{0.30, 0.17}, {0.08, 0.45}} is not your data ... it represents the pmf or distribution of the population data.

  • $\begingroup$ Great solution. When I try to work futher with the ProbabilityDistribution-function (´dist´), then I cannot use it with Probability[...] I have an example with $X_1$ conditioned $X_1 \neq X_2$. How come? $\endgroup$ Commented Aug 6, 2013 at 11:08
  • $\begingroup$ Would need to see the exact example to be able to comment on that ... $\endgroup$
    – wolfies
    Commented Aug 6, 2013 at 11:17
  • $\begingroup$ How would you calculate: $P(X_1=0|X_1 \neq X_2)$ and $P(X_1=1|X_1 \neq X_2)$. If it is any help. the results are 0.68 and 0.32 $\endgroup$ Commented Aug 6, 2013 at 11:22
  • $\begingroup$ You could continue: Probability[x == 0 \[Conditioned] x != y, {x, y} \[Distributed] dist] ... and ... Probability[x == 1 \[Conditioned] x != y, {x, y} \[Distributed] dist] .. works fine $\endgroup$
    – wolfies
    Commented Aug 6, 2013 at 11:39
  • 1
    $\begingroup$ Checked it in v8 and v9 ->> works fine on both on my Mac. Suggest check your input carefully ... or quit kernel and start from fresh :) $\endgroup$
    – wolfies
    Commented Aug 6, 2013 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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