[R] how to find "p" in binomial(n,p)

Rolf Turner r.turner at auckland.ac.nz
Thu Sep 20 01:46:01 CEST 2007


On 20/09/2007, at 11:04 AM, Mike Meredith wrote:

>
> I think the function you need is 'help.search'; try:
>
> help.search("binomial")
>
> and look for something obvious in the 'stats' package. A good deal  
> quicker
> and easier than posting to an internet forum!
>

	I don't think so.  I couldn't find anything useful under help.search 
("binomial"), and
	I'm fairly comfortable with R.

	It seems to me that what is required here is to roll your own.

	I defined a function foo():

		foo <- function(p,n,k,alpha){pbinom(k,n,p)-alpha}

	Then I used uniroot to solve foo(p,n,k,alpha) = 0.

	E.g.

		xxx <- uniroot(foo,c(0,1),n=20,k=15,alpha=0.05)

	Then xxx$root is 0.895913.

	Check this out graphically:

		p <- seq(0,1,length=301)
		y <- foo(p,20,15,0.05)
		plot(p,y,type="l")
		abline(h=0)
		abline(v=xxx$root)

	It looks good.

				cheers,

					Rolf Turner
> Cheers, Mike.
>
>
> cathelf wrote:
>>
>> Dear all,
>>
>> I am trying a find the value "p" in binomial.
>>
>> X ~ Bin(n,p)
>>
>> I want to find the value "p", so that Pr(X <= k) <= alpha
>>
>> Here, n, k and alpha are known. n, k are integers. alpha is  
>> between (0,1).
>>
>> Thanks a lot!
>>
>> Catherine
>>


######################################################################
Attention:\ This e-mail message is privileged and confidenti...{{dropped}}



More information about the R-help mailing list