Re: Calculate n in binomial distribution
- To: mathgroup at smc.vnet.net
- Subject: [mg101243] Re: [mg101212] Calculate n in binomial distribution
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sat, 27 Jun 2009 06:06:59 -0400 (EDT)
- Reply-to: hanlonr at cox.net
cf[n_, p_, k_] = CDF[BinomialDistribution[n, p], k];
You mean the smallest n such that cf[n, 0.2, 7] < 0.3 or the largest n such that cf[n, 0.2, 7] > 0.3
For largest n such that cf[n, 0.2, 7] > 0.3
Floor[n /. FindRoot[cf[n, 0.2, 7] == 0.3, {n, 40}]]
44
For smallest n such that cf[n, 0.2, 7] < 0.3
Ceiling[n /. FindRoot[cf[n, 0.2, 7] == 0.3, {n, 40}]]
45
cf[#, 0.2, 7] & /@ {44, 45}
{0.322925,0.297457}
Bob Hanlon
---- Peter Breitfeld <phbrf at t-online.de> 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 of
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 success.
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de