0
$\begingroup$

Is there a direct command in Mathematica that computes the covariance between two random variables?

Hence, instead of typing

Expectation[f(x)*g(y),{y~some distribution,x~some distribution}] - 
Expectation[f(x),{y~some distribution,x~some distribution}]*
Expectation[g(y),{y~some distribution,x~some distribution}]

Is there a command that archieves the same by typing simply

Covariance[{f(x),g(y)},{y~some distribution,x~some distribution}]

I have tried to use the following function:

CoVar[RVfuncs_, dist_] := 
Expectation[RVfuncs[[1]]*RVfuncs[[2]], 
dist] - (Expectation[RVfuncs[[1]], dist]*Expectation[RVfuncs[[2]], dist])

It works, but it is much slower than writing out the three "Expectation" parts.

$\endgroup$
  • $\begingroup$ The covariance between 2 random variables whose distributions are specified as in your examples will always be 0. You need to specify a multivariate distribution, such as Covariance[BinormalDistribution[{m1, m2}, {sd1, sd2}, corr], 1, 2] $\endgroup$ – Rojo Oct 31 '13 at 16:27
  • $\begingroup$ How about the case x = y $\endgroup$ – Breugem Oct 31 '13 at 16:33
  • $\begingroup$ I don't understand what you mean. If you tell Mathematica that {x~someDist, y~someDist}, it assumes they are independent, so unless someDist is a delta, you don't get x=y, and in such case I would think the covariance is indeterminate $\endgroup$ – Rojo Oct 31 '13 at 16:43
  • $\begingroup$ About your edit and your CoVar function, what exactly is slower? $\endgroup$ – Rojo Oct 31 '13 at 16:44
  • $\begingroup$ Ok thanks I see your point. I will rephrase the question $\endgroup$ – Breugem Oct 31 '13 at 16:45

Your Answer

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

Browse other questions tagged or ask your own question.