Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.}}]]]
share|improve this question

2 Answers 2

up vote 8 down vote accepted

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.

share|improve this answer
    
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. –  Ian Aug 26 '12 at 0:07
    
@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 –  rm -rf Aug 26 '12 at 0:10

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

share|improve this answer
    
and in addition, use NormalDistribution to get an answer for the case in the question –  rm -rf Aug 25 '12 at 23:46
    
@kguler True, that works. Now try using some numerical values that are not trivial. –  Ian Aug 25 '12 at 23:48
    
@R.M Yes, but having to switch the function call programatically when the dimension is 1 is annoying. –  Ian Aug 25 '12 at 23:48
    
@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? –  rm -rf Aug 25 '12 at 23:49
    
@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 –  rm -rf Aug 25 '12 at 23:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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