0
$\begingroup$

I would like to find the Mean and Variance expressions for a Poisson-Lognormal Distribution

$$f(x;\mu,\sigma)=\frac{1}{x!\sigma\sqrt{2\pi}}\int_{0}^{\infty}\lambda^{x-1} e^{-\lambda} e^{\frac{(log(\lambda-\mu)^2}{2\sigma^2} }\text{d}\lambda$$

I have been checking the Expectation[] command to find the expected value of predefined Mathematica pdfs but I do not know how to apply to this expression, and to find the $Var(X)=E[X^2]-E[X]^2$.

$\endgroup$
  • $\begingroup$ What didn't work with Expectation? Please show what you tried. Your LaTeX display seems to be in error. $(\log(\lambda-\mu)^2$ should probably be $-(\log(\lambda)-\mu)^2$. $\endgroup$ – JimB Sep 15 at 22:28
2
$\begingroup$

I suspect that you will need to use numeric techniques.

Clear["Global`*"]

f[x_Integer?NonNegative,
  μ_?(NumericQ[#] && Element[#, Reals] &),
  σ_?(NumericQ[#] && # > 0 &)] := NIntegrate[
   E^-λ λ^(x - 
       1) E^(-(Log[λ] - μ)^2/(2 σ^2)),
   {λ, 0, ∞}]/(Sqrt[2 π] σ x!)

mean[μ_?(NumericQ[#] && Element[#, Reals] &),
  σ_?(NumericQ[#] && # > 0 &)] := mean[μ, σ] =
  NSum[x*f[x, μ, σ], {x, 0, ∞}, NSumTerms -> 50, 
   WorkingPrecision -> $MachinePrecision]

var[μ_?(NumericQ[#] && Element[#, Reals] &),
  σ_?(NumericQ[#] && # > 0 &)] := var[μ, σ] =
  Module[{m = mean[μ, σ]},
   NSum[(x - m)^2*f[x, μ, σ], {x, 0, ∞}, NSumTerms -> 50,
     WorkingPrecision -> $MachinePrecision]]

mean[0, 1]

(* 1.6487197 *)

var[0, 1]

(* 6.318 *)
$\endgroup$
  • $\begingroup$ @BobHanion Thank you. Both mean[0,1] and var[0,1]` gives me ComplexInfinity as a result. $\endgroup$ – pablo Sep 17 at 8:59
  • $\begingroup$ I just pasted the code above into a notebook and executed it with the same result as shown above. I am running v12.0.0 on a Mac. Which version are you using? $\endgroup$ – Bob Hanlon Sep 17 at 13:47
  • $\begingroup$ @BobHanion I am running the 11.0.0 installed on a Mac too. That could be the issue. $\endgroup$ – pablo Sep 17 at 15:34
  • $\begingroup$ On my Mac, code works with v11.3. The problem is present with v11.2. Perhaps you can upgrade to v11.3 $\endgroup$ – Bob Hanlon Sep 17 at 16:42
  • $\begingroup$ @BonHanion I have downloades a 12.0 trial versioin and works fine. I suppose I should upgrade soon. I would ask you how I could get the \sigma such that mean[2.32, \sigma]==23?. $\endgroup$ – pablo Sep 17 at 17:16

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.