I am trying to find the correlation between Uniform R.V.s using the Correlation command in mathematica, but it seems that either I am implementing it wrong or the software cannot find the answer. My code is pretty straight forward:

Correlation[UniformDistribution[], Sqrt[1-(UniformDistribution[])^2]]

I also tried

Correlation[x, Sqrt[1-(x)^2], x \[Distributed] UniformDistribution[]]

I am aware that I can implement directly the definition of correlation and compute it in terms of expectation, but I was wondering if it was possible directly through this function.

  • 1
    $\begingroup$ The documentation for Correlation says "Correlation[v1,v2] gives the correlation between the vectors v1 and v2... The lists v1 and v2 must be the same length..." and it doesn't look like you are testing this on two vectors of values. If you study the documentation and click on the orange "Details" and study do you come to the same conclusion? $\endgroup$ – Bill Oct 31 '19 at 3:08

Update: A much more compact approach...

dist = TransformedDistribution[{x, Sqrt[1 - x^2]}, x \[Distributed] UniformDistribution[]];

Correlation[dist, 1, 2]
(* (8 - 3 π)/Sqrt[32 - 3 π^2] *)

End of update

I think you want the correlation between $X$ and $\sqrt{1-X^2}$ where $X \sim Uniform(0,1)$.

μX = Mean[UniformDistribution[]]
(* 1/2 *)

varX = Variance[UniformDistribution[]]
(* 1/12 *)

distY = TransformedDistribution[Sqrt[1 - x^2], x \[Distributed] UniformDistribution[]];
μY = Mean[distY]
(* π/4 *)

varY = Variance[distY]
(* 1/48 (32-3 π^2) *)

covXY = Integrate[x Sqrt[1 - x^2], {x, 0, 1}] - μX μY
(* 1/48 (32-3 π^2) *)

ρ = covXY/Sqrt[varX varY] // FullSimplify
(* (8-3 π)/Sqrt[32-3 π^2] *)
ρ // N

As a check consider random samples from a uniform distribution:

n = 100000;
z = RandomVariate[UniformDistribution[], n];
Correlation[z, Sqrt[1 - z^2]]
(* -0.9214182413747128` *)
  • 1
    $\begingroup$ As an aside: this is an example where there is a "perfect" one-to-one relationship with a correlation other than -1 or +1. $\endgroup$ – JimB Oct 31 '19 at 17:02

In general you can get correlation matrix for multivariate symbolic distribution like this:

corr = Correlation[ ProductDistribution[UniformDistribution[], TransformedDistribution[Sqrt[1 - x^2], 
   x \[Distributed] UniformDistribution[]]]]

{{1, 0}, {0, 1}}

I believe you are looking for corr[[2,1]].


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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