MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Calculate n in binomial distribution

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101626] Re: Calculate n in binomial distribution
  • From: ADL <alberto.dilullo at tiscali.it>
  • Date: Fri, 10 Jul 2009 23:27:58 -0400 (EDT)
  • References: <h229dp$i0v$1@smc.vnet.net> <h3768k$fb1$1@smc.vnet.net>

I also think there is a bug, but it is in NMinimize.
In fact, the Help says: "If Minimize is given an expression containing
approximate numbers, it automatically calls NMinimize".
Actually, you can check that:
     Minimize[{(cf[n, 2/10, 7] - 3/10)^2, n > 0}, {n}, Integers]
will return unevaluated and Minimize cannot even deal with this
expression.

Moreover, the following can be seen: [$Version=7.0 for Microsoft
Windows (32-bit) (February 18, 2009]:

In[1]:= cf[n_, p_, k_] = CDF[BinomialDistribution[n, p], k];

In[2]:= NMinimize[{(cf[n, 2/10, 7] - 3/10)^2, n > 0}, {n}]
Out[2]= {6.63109378289971*10^-23,{n->44.8977440651266}}
(*OK*)

In[3]:= NMinimize[{(cf[n, 2/10, 7] - 3/10)^2, n > 1}, {n}]
Out[3]= {0.489999957269396,{n->1.36847214846574}}
(*Surprising !*)

In[4]:= NMinimize[{(cf[n, 2/10, 7] - 3/10)^2, n > 2}, {n}]
Out[4]= {0.489999990680824,{n->3.47886234486239}}
(*Surprising !*)

In[5]:= NMinimize[{(cf[n, 2/10, 7] - 3/10)^2, n > 5}, {n}]
Out[5]= {2.77333911991762*10^-32,{n->44.8977440654531}}
(*OK*)

In[6]:= NMinimize[{(cf[n, 2/10, 7] - 3/10)^2, n > 7}, {n}]
            (*Produces a Beep and crashes the Kernel !*)

New Kernel:

In[1]:= cf[n_, p_, k_] = CDF[BinomialDistribution[n, p], k];

In[2]:= NMinimize[{(cf[n, 2/10, 7] - 3/10)^2, n < 100}, {n}]
Out[2]= {2.77333911991762*10^-32,{n->44.8977440654531}}
(*OK*)


So:
1) NMinimize just explores a small region around the limit of the
inequality n>M for M>0, but looks everywhere when n>0 is specified (so
that two differen algorithms are used)

2) Appears to works more reproducibly if an upper limit is specified
(e.g. n<M)

3) Has some inexplicable serious internal problem for some situations
(e.g. n>7)


Some comments by WRI specialist on this behavior could be helpful.

ADL



On Jul 10, 12:47 pm, dh <d... at metrohm.com> wrote:
> Hi Peter,
>
> I think there is a bug in Minimize for the Integer domain. Consider:
>
> Minimize[(x - 6.1)^2, x, Integers]  giving: {1.21, {x -> 5}}
>
> Minimize[(x - 6.)^2, x, Integers]   giving: {1., {x -> 5}}
>
> Minimize[(x - 6)^2, x, Integers]    giving: {0, {x -> 6}}
>
> Minimize seems to have problems mixing integers and reals. I think you
>
> should report this to Wolfram.
>
> Daniel
>
>
>
> Peter Breitfeld wrote:
> > Suppose I have the following distribution:
>
> > cf[n_,p_,k_]=CDF[BinomialDistribution[n,p],k]
>
> > Now I want to calculate n so that the biggest n such that e.g.
>
> > cf[n,0.2,7]<0.3
>
> > I made a ListPlot
>
> > ListPlot[Abs[cf[#,0.2,7]-0.3]&/@Range[60]], where I see, that a value o=
f
> > about n=46 gives an approximation nearest to 0.3
>
> > To get this value of n I tried
>
> > Minimize[{Abs[cf[n,0.2,7]-0.3],n>7},n,Integers]
>
> > Out:  {0.699765, {n->11}}
>
> > which is obviously wrong.
>
> > Why?
>
> > Is it, because Abs isn't differentiable at the peak?
>
> > I tried other ways too, like Reduce NMinimize, FindMinimum, but no succ=
ess.



  • Prev by Date: Re: Add syntax highlighting to own command
  • Next by Date: Re: 2dFFT & image processing
  • Previous by thread: Re: Re: Calculate n in binomial distribution
  • Next by thread: Re: Calculate n in binomial distribution