Re: [R] how to find "p" in binomial(n,p)
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! 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 > -- View this message in context: http://www.nabble.com/how-to-find-%22p%22-in-binomial%28n%2Cp%29-tf4484227.html#a12787900 Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to find "p" in binomial(n,p)
On 19-Sep-07 23:04:57, 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! > > Cheers, Mike. Well ... help.search("root") ?uniroot ?pbinom n<-10; k<-4; alpha<-0.95; f<-function(p){ pbinom(k,n,p)-alpha } uniroot(f,c(0,1)) ## $root ## [1] 0.2224413 ## $f.root ## [1] -1.588189e-07 ## $iter ## [1] 10 ## $estim.prec ## [1] 6.103516e-05 #Check: pbinom(k,n, 0.2224413) ## [1] 0.948 > > > 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 >> > > -- > View this message in context: > http://www.nabble.com/how-to-find-%22p%22-in-binomial%28n%2Cp%29-tf44842 > 27.html#a12787900 > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 20-Sep-07 Time: 00:34:22 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to find "p" in binomial(n,p)
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}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to find "p" in binomial(n,p)
On Thu, 20 Sep 2007, Rolf Turner wrote: > > 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. After 20-odd years of R, Splus, and S, I'd say I am more enthusiastic than 'comfortable', but trying 'help.search("binomial")' I get: Help files with alias or concept or title matching 'binomial' using fuzzy matching: [stuff omitted] binom.test(stats) Exact Binomial Test And after reading the help page: > binom.test(15,20,conf=.95,alt='less') # Rolf's example Exact binomial test data: 15 and 20 number of successes = 15, number of trials = 20, p-value = 0.994 alternative hypothesis: true probability of success is less than 0.5 95 percent confidence interval: 0.000 0.8959192 ...^... matches Rolf's example sample estimates: probability of success 0.75 > binom.test(4,10,conf=.05,alt='le') # Ted's Example Exact binomial test data: 4 and 10 number of successes = 4, number of trials = 10, p-value = 0.3770 alternative hypothesis: true probability of success is less than 0.5 5 percent confidence interval: 0.000 0.2224411 ...^. matches Ted's Example sample estimates: probability of success 0.4 So, it really can be found using 'help.search'. Although in view of the 'Zen in the Art of Motorcycle Maintenance' effect (if it is only obvious if you know something, then it is not really obvious) I must note that one must recognize that "Pr(X <= k) <= alpha" is the confidence statement. But of course, if one 'knew something' it is help.search("beta") that would be tried. :-) HTH, Chuck > > 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}} > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:[EMAIL PROTECTED] UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.