2
$\begingroup$

First, I'm a little disappointed that Mathematica balks at:

Mean[TruncatedDistribution[{{0, Infinity}},MultinormalDistribution[{0}, {{1}}]]] 

Second, is the numerical computation of means from truncated multinormal distributions so hard? Is anyone aware of a package that implements the algorithm of Leppard and Tallis (1989) (see here for FORTRAN code) or anything like it?

Edit: rm asked for an example that fails to compute:

Mean[TruncatedDistribution[{{0, Infinity}, {0, Infinity}}, MultinormalDistribution[{0.5, 1.5}, {{1., 0.3}, {0.3, 1.}}]]] 
$\endgroup$

2 Answers 2

11
$\begingroup$

If you want to do serious statistical work, I would suggest to not use Mean and instead use specialized functions that work on distributions, such as Expectation and NExpectation. Although the documentation says that Mean[dist] gives the mean of the symbolic distribution, I suspect they meant it for basic distributions such as NormalDistribution, BinomialDistribution, etc., which were all there when Mean was written. Mean was last modified in version 6 and most probably is not aware of newer functions such as TruncatedDistribution, MultinormalDistribution, etc., which were all introduced in version 8.

So the equivalent code for your example is:

NExpectation[{x, y}, {x, y} \[Distributed] TruncatedDistribution[ {{0, Infinity}, {0, Infinity}}, MultinormalDistribution[{0.5, 1.5}, {{1., 0.3}, {0.3, 1.}}] ] ] (* {1.02198, 1.74957} *) 

Using Expectation offers more flexibility than Mean, because you can now calculate the expectations of arbitrary quantities:

NExpectation[{Sin[x], y^3}, {x, y} \[Distributed] TruncatedDistribution[ {{0, Infinity}, {0, Infinity}}, MultinormalDistribution[{0.5, 1.5}, {{1., 0.3}, {0.3, 1.}}] ] ] (* {0.650673, 9.70065} *) 

NExpectation still does not work with MultinormalDistribution with a single dimension... I don't know why exactly, but personally I would never use a Multi-something function to mean just 1 (which is the opposite of multi). I would suggest using a Switch and use NormalDistribution when you have a MultinormalDistribution of dimension 1.

$\endgroup$
2
  • $\begingroup$ Thanks. NExpectation is a big improvement. Although I'm getting NIntegrate::slwcon messages for my application, it's at least attempting an answer with 3 and 4 dimensions. $\endgroup$ Commented Aug 26, 2012 at 0:07
  • $\begingroup$ @Ian I also added some info on why you shouldn't use Mean. I don't think Mean knows about any of these distributions and probably cannot handle it $\endgroup$ Commented Aug 26, 2012 at 0:10
5
$\begingroup$

The following works:

 Mean[TruncatedDistribution[{{0, Infinity}, {0, Infinity}}, MultinormalDistribution[{0, 0}, {{1, 0}, {0, 1}}]]] (* {Sqrt[2/\[Pi]], Sqrt[2/\[Pi]]}*) 

Note the syntax of arguments for MultinormalDistribution (it needs a vector for means and a matrix for variance), and for TruncatedDistribution (it needs a list of lists, one list of truncation limits for each dimension).

Example:

 Mean[TruncatedDistribution[{{0, Infinity}, {0, Infinity}}, MultinormalDistribution[{0, 0}, {{1, \[Rho]}, {\[Rho], 1}}]]] 

enter image description here

$\endgroup$
5
  • $\begingroup$ and in addition, use NormalDistribution to get an answer for the case in the question $\endgroup$ Commented Aug 25, 2012 at 23:46
  • $\begingroup$ @kguler True, that works. Now try using some numerical values that are not trivial. $\endgroup$ Commented Aug 25, 2012 at 23:48
  • $\begingroup$ @R.M Yes, but having to switch the function call programatically when the dimension is 1 is annoying. $\endgroup$ Commented Aug 25, 2012 at 23:48
  • 2
    $\begingroup$ @Ian Instead of making us waste time guessing at non-trivial values that might or might not work, why not just update your question with what didn't work for you? $\endgroup$ Commented Aug 25, 2012 at 23:49
  • $\begingroup$ @Ian Well, there's always Switch... note that I'm only mentioning it as an alternative. I suspect the reason might be due to the fact that Mean sees the dimension as 1 and calculates the expectation of x, when technically, it should be the expectation of {x}. You can also see this issue arise when you use PDF with your truncated distribution $\endgroup$ Commented Aug 25, 2012 at 23:52

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.