1

I am trying to reproduce the results from a paper in Mathematica. This task involves $K$ double integrals of the form

$$\int f(x,y)g(x)dx,$$

where $f(x,y)$ is a bivariate normal density with mean $(-4.08, -3.41)$ and diagonal covariance matrix with diagonal $(1/10,1/21)$, and $g(x)$ is a normal density with mean $\beta_0+\beta_1\xi$ and variance $\sigma_e^2$ (all of them known). I want to obtain this integral as a function of $\xi$.

Sigma = {{1/10, 0}, {0, 1/21}}

    {β0, β1, σe} = \
{-2.3, 0.5, 0.0005}



    f[ξ_] := 
 NIntegrate[
  PDF[MultinormalDistribution[{-4.08, -3.41}, Sigma], {η, ξ}]*
   PDF[NormalDistribution[β0 + β1*ξ, σe], \
η], {η, -∞, ∞}]

   Plot[f[t], {t, -10, 10}]

This code returns a $0$ for all values of $\xi$, while the true value should not be $0$.

How can I obtain this integral? What seems to be the problem? Is it the precision? Any ideas would be greatly appreciated.

My impression so far is that the $\sigma_e$ is very small and therefore the densities involved in the integration are very concentrated. This makes difficult the automatic integration.

M6299
  • 1,471
  • 1
  • 13
  • 20
Roman
  • 13
  • 3
  • You have not defined ratex and ratey. – Jonathan Shock May 28 '13 at 23:11
  • @JonathanShock Thank you for pointing this out. I have defined these variables and included some explanation. – Roman May 28 '13 at 23:14
  • Take a look at the function you are trying to integrate. It is enormously small. You will have to be extremely careful with the precision in this calculation. – Jonathan Shock May 28 '13 at 23:17
  • @JonathanShock Indeed, I have included a comment on this (last paragraph). Maybe this is why the automatic integration (-Inf,Inf) is not identifying a proper integration range. – Roman May 28 '13 at 23:19

1 Answers1

4

The problem is the numerical precision that is required for this calculation.

Thankfully the integral can be performed analytically and then the plot can be created. It is actually easier perhaps in this case to create a ListPlot though you can do it with a LogPlot too:

f[ξ_]=Integrate[
PDF[MultinormalDistribution[{-4.08, -3.41}, Sigma], {η, ξ}]*PDF[NormalDistribution[β0 + β1*ξ, σe], \
η], {η, -∞, ∞}]
{#, Log[f[#]]} & /@ Range[-10, 10, 0.1];
ListLinePlot[%]

Result of integral

M6299
  • 1,471
  • 1
  • 13
  • 20
Jonathan Shock
  • 3,015
  • 15
  • 24