2
$\begingroup$

I am interested in calculating the mean and the variance of a (univariate continuous) random variable whose density function can be actually expressed as a transformation of the density function of another random variable; more precisely, it happens to be a transformation of the doubly noncentral $F$ distribution (NoncentralFRatioDistribution in Mathematica).

As an example, if I try this:

Mean[NoncentralFRatioDistribution[7, 3, 0, 0.5]]

I get:

2.54662

But if I try this:

dist1 := ProbabilityDistribution[Sqrt[PDF[NoncentralFRatioDistribution[7, 3, 0, 0.5], x]],
  {x, 0, \[Infinity]}, Method -> "Normalize"]

and then I ask for the mean of this transformed variable:

Mean[dist1]

I get:

Mean[ProbabilityDistribution[
  0.188114 Sqrt[
   PDF[NoncentralFRatioDistribution[7, 3, 0, 
     0.5], \[FormalX]]], {\[FormalX], 0, \[Infinity]}]]

Is it that the expected behaviour of Mathematica 11.1? Am I doing something wrong? What else can I try?

$\endgroup$
  • $\begingroup$ As shown in the answers below, one applies the transformation to the random variable and not the density function. $\endgroup$ – JimB Sep 7 '17 at 17:06
6
$\begingroup$

First, we define your distribution using TransformedDistribution:

dist1 = TransformedDistribution[Sqrt[x], x \[Distributed] NoncentralFRatioDistribution[7., 3., 0., 0.5]]

Now, we can get the mean using N:

N@Mean@dist1
(* 1.23037 *)
$\endgroup$
  • $\begingroup$ Wow! I still have to read it twice, but thank you! $\endgroup$ – Vicent Sep 7 '17 at 9:36
  • 1
    $\begingroup$ There is also the shortcut NExpectation[Sqrt[x], x \[Distributed] NoncentralFRatioDistribution[7., 3., 0., 0.5]]. $\endgroup$ – Sjoerd Smit Sep 7 '17 at 10:19
  • $\begingroup$ @Mathe172 Why is N@Mean working better than the sentence Mean (at least in the examples I've been trying)? $\endgroup$ – Vicent Sep 7 '17 at 14:57
  • 1
    $\begingroup$ @Vicent I wondered about that myself... I assume MMA somehow wants to give you an "exact" result, which it cannot do. N forces it to evaluate it numerically, which gives it more freedom in what to do. But this is just a guess - I could be completely wrong. $\endgroup$ – Lukas Lang Sep 7 '17 at 17:17
3
$\begingroup$
f = NoncentralFRatioDistribution[7, 3, 0, 0.5];
td = TransformedDistribution[Sqrt[x], x \[Distributed] f];

You can simulate:

rv = RandomVariate[td, 100000] // Mean
rvf = Mean@Sqrt[RandomVariate[f, 100000]]

or explicitly calculate:

NIntegrate[x PDF[td, x], {x, 0, Infinity}]

or use N@Mean@td

Outputs: 1.236, 1.22386, 1.23037, 1.23037

$\endgroup$

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.