Re: Strange statistics function integration
- To: mathgroup at smc.vnet.net
- Subject: [mg59607] Re: [mg59545] Strange statistics function integration
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sat, 13 Aug 2005 03:26:48 -0400 (EDT)
- Reply-to: hanlonr at cox.net
- Sender: owner-wri-mathgroup at wolfram.com
The problem only arises if you use inexact numbers. Exact numbers return
identical results.
Needs["Statistics`"];
PosterioriWithNormalProb1[mu_,sigma_][n_,k_]:=
Binomial[n,k]*Integrate[
x^k*(1-x)^(n-k)*PDF[NormalDistribution[mu,sigma],x],
{x,-Infinity,Infinity}]
PosterioriWithNormalProb2[mu_,sigma_][n_,k_]:=
Binomial[n,k]*Assuming[Element[sigma1,Reals]&&sigma1>0,
Integrate[x^k*(1-x)^(n-k)*
PDF[NormalDistribution[mu1,sigma1],x],
{x,-Infinity,Infinity}]]/.{mu1->mu,sigma1->sigma}
{(v=PosterioriWithNormalProb1[1/2,#][8,0])===
PosterioriWithNormalProb2[1/2,#][8,0],v//N}&/@
{1/10,1/100,1/1000}
{{True, 0.0096998}, {True, 0.0039501313550105}, {True,
0.003906687513125106}}
Bob Hanlon
>
> From: Erich Neuwirth <erich.neuwirth at univie.ac.at>
To: mathgroup at smc.vnet.net
> Date: 2005/08/12 Fri AM 12:07:48 EDT
> Subject: [mg59607] [mg59545] Strange statistics function integration
>
> I am experiencing some very strage effects, and in effect errors,
> with the continuous distributions.
> Here is my code
>
> <<Statistics`ContinuousDistributions`
>
> PosterioriWithNormalProb1[mu_, sigma_][n_, k_] :=
> Binomial[n, k]*Integrate[x^k*(1 -
> x)^(n - k)*PDF[NormalDistribution[mu,
> sigma], x], {x, -Infinity,Infinity}]
>
> PosterioriWithNormalProb2[mu_,sigma_][n_,k_]:=
> Binomial[n,k]*Assuming[Element[
> sigma1,Reals] && sigma1>0 ,Integrate[
> x^k*(1-x)^(n-k)*PDF[NormalDistribution[mu1,sigma1],x],{x,-
> Infinity,Infinity}]]/.{mu1->mu,sigma1->sigma}
>
>
> The difference between these two functions seems to be that
> in the first case integration is done with the symbolic constants
> replaced by numerical values to be substituted before integration, and
> in the second case this substitution happens only after integration.
> Now, the following happens:
>
> In[78]:=
> PosterioriWithNormalProb1[0.5,0.1][8,0]
>
> From In[78]:=
> Integrate::gener: Unable to check convergence
>
> Out[78]=
> 0.0096998
>
> In[79]:=
> PosterioriWithNormalProb2[0.5,0.1][8,0]
>
> Out[79]=
> 0.0096998
>
>
> which seems ok.
> However:
>
> In[81]:=
> PosterioriWithNormalProb1[0.5,0.001][8,0]
>
> From In[81]:=
> Integrate::gener: Unable to check convergence
>
> Out[81]=
> 0.00780941
>
> In[80]:=
> PosterioriWithNormalProb2[0.5,0.001][8,0]
>
> Out[80]=
> 0.00390669
>
>
> In this example, the second result is correct, the first one is wrong.
> Since Mathematica can solve the integration problem
> with symbolic parameters, it is strange that the warning appears
> when concrete numerical paramater are used during integration.
>
> It is also strange that the problem only occurs for some values of sigma.
>
> Can anybody help me understanding what is happening here?
>
>
> Erich Neuwirth
>
>