Is there some softaware that deals with random variables as objects?

For example, suppose I define some i.i.d. random variables $X_1,\ldots, X_n\in N(0,1)$, where $N(0,1)$ is the normal distribution with mean 0 and variance 1. After that, I could want to calculates something like $$E\Big(\sum_{i,j=1}^nX_iX_j,\Big)$$

In this particular case, I know that $E\Big(\sum_{i,j=1}^nX_iX_j,\Big) = E\Big(\sum_{i=1}^n X_i^2\Big) = \sum_{i=1}^n E(X_i^2) = n$. For more complicated expressions (with others distributions) could happen to be more moments, in this case the program just let the terms uncalculated. Or maybe, if random variables are objects, could be a way to define higher moments.

Anyone knows some software that does this?

Thank you.

PS: Its supposed to be a software that works in a symbolic way, I dont want numeric approximations.


OP wrote:

I know that $E\Big(\sum_{i,j=1}^nX_iX_j,\Big) = E\Big(\sum_{i=1}^n X_i^2\Big)$

While that is correct for the special case of the N(0,1) in your example, some care should be taken by the passing reader to note that it is not generally correct, because $E[X Y] \ne E[X^2]$ (even if $X$ and $Y$ are independent). A more general valid expression would be:

$$E\Big(\sum_{i,j=1}^n X_i X_j\Big) = E\Big [\Big (\sum_{i=1}^n X_i\Big)^2\Big ] $$

To answer your question re software: the mathStatica software package for Mathematica provides a suite of specialised moment of moment functions that provide exactly this functionality (I am one of the authors).

For examples, see Chapter 7 of our book:

  • Rose and Smith, "Mathematical Statistics with Mathematica", Springer, NY

A free download of the chapter is available here:


  • $\begingroup$ I think you misundertand, let me give you some examples to clarify. $$E(\sum_{i,j=1}^2X_iX_j) = E(X_1^2+2X_1X_2+X_2^2) = E(X_1^2)+2E(X_1X_2)+E(X_2^2)$$ but $X_1$ and $X_2$ are iid, so $2E(X_1X_2)=2E(X_1)E(X_2)=2\cdot0\cdot0=0$, therefore $$E(\sum_{i,j=1}^2X_iX_j) = E(X_1^2)+E(X_2^2) =\sum_{i=1}^2 E(X_i^2)$$ For $n=3$ we get $$E(\sum_{i,j=1}^2X_iX_j) = E(X_1^2+2X_1X_2+2X_1X_3+2X_2X_3+X_2^2+X_3^2) =$$ $$= E(X_1^2)+E(X_2^2)+E(X_3^2) = \sum_{i=1}^3 E(X_i^2)$$ $\endgroup$ – Integral Apr 27 '14 at 15:43
  • $\begingroup$ In fact, this should be obvious, because $E(\sum_{i,j=1}^nX_iX_j)$ is just a pairing of random variables. If they have distinct index, by the iid property you can separate them, and the mean is zero, thefore random variables with distinct terms are canceled. If they have the same index, you got $E(X_i^2)$, which is what is left after all. $\endgroup$ – Integral Apr 27 '14 at 15:43
  • $\begingroup$ Pay attention on the indexes, the first sum has $n^2$ terms (i,j=1...n), the second one has $n$ terms (i=1...n). $\endgroup$ – Integral Apr 27 '14 at 15:50
  • $\begingroup$ You are imposing the special case of a standard Normal variable, rather than the more general case (with general solution) to which I am referring. There is no real reason to restrict the analysis here to the standard Normal, as the problem of interest is a general problem with general solution. $\endgroup$ – wolfies Apr 27 '14 at 15:50
  • $\begingroup$ The question is about Normal Distribution. $\endgroup$ – Integral Apr 27 '14 at 15:52

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.