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:


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:


I get:

  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?

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

2 Answers 2


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:

(* 1.23037 *)
  • $\begingroup$ Wow! I still have to read it twice, but thank you! $\endgroup$
    – Vicent
    Commented Sep 7, 2017 at 9:36
  • 1
    $\begingroup$ There is also the shortcut NExpectation[Sqrt[x], x \[Distributed] NoncentralFRatioDistribution[7., 3., 0., 0.5]]. $\endgroup$ Commented Sep 7, 2017 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
    Commented Sep 7, 2017 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
    Commented Sep 7, 2017 at 17:17
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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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