[R] binom.test

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[R] binom.test

Ethan Johnsons
R-experts:

A quick question, please.

>From a lab exp, I got 12 positives out of 50.
To get 90% CI for this , I think binom.test might be the one to be used.
Is there a better way or function to calculate this?

> binom.test(x=12, n=50, p=12/50, conf.level = 0.90)

        Exact binomial test

data:  12 and 50
number of successes = 12, number of trials = 50, p-value = 1
alternative hypothesis: true probability of success is not equal to 0.24
90 percent confidence interval:
 0.1447182 0.3596557
sample estimates:
probability of success
                  0.24

thx much

ej

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: [R] binom.test

Chuck Cleland
Ethan Johnsons wrote:

> R-experts:
>
> A quick question, please.
>
>>From a lab exp, I got 12 positives out of 50.
> To get 90% CI for this , I think binom.test might be the one to be used.
> Is there a better way or function to calculate this?
>
>> binom.test(x=12, n=50, p=12/50, conf.level = 0.90)
>
>         Exact binomial test
>
> data:  12 and 50
> number of successes = 12, number of trials = 50, p-value = 1
> alternative hypothesis: true probability of success is not equal to 0.24
> 90 percent confidence interval:
>  0.1447182 0.3596557
> sample estimates:
> probability of success
>                   0.24

You might consider binconf() in the Hmisc package too:

library(Hmisc)
binconf(12, 50, method="all")
           PointEst    Lower    Upper
Exact          0.24 0.130610 0.381691
Wilson         0.24 0.142974 0.374127
Asymptotic     0.24 0.121621 0.358379

> thx much
>
> ej
>
> ______________________________________________
> [hidden email] 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.

--
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: [R] binom.test

Ted.Harding
In reply to this post by Ethan Johnsons
On 19-Oct-06 Ethan Johnsons wrote:
> R-experts:
>
> A quick question, please.
>
>>From a lab exp, I got 12 positives out of 50.
> To get 90% CI for this , I think binom.test might be
> the one to be used.
> Is there a better way or function to calculate this?

What do you mean by "better"? For a symmetrical 2-sided
exact binomial confidence interval, binom.test gives the
result quickly and, to within the precision of pbinom,
correctly (as I've just verified by hand!).

And you can get 1-sided CIs by setting the 'alternative'
option, or asymmetrical CI's by finding the two 1-sided
CIs (e.g. for conf.level = 0.03 and 0.07) that you want.

What do you want to improve on?

>> binom.test(x=12, n=50, p=12/50, conf.level = 0.90)
>
>         Exact binomial test
>
> data:  12 and 50
> number of successes = 12, number of trials = 50, p-value = 1
> alternative hypothesis: true probability of success is not equal to
> 0.24
> 90 percent confidence interval:
>  0.1447182 0.3596557

  r<-12 ; n<-50

  1-pbinom(r-1,n, 0.14471815)
  [1] 0.04999999

  1-pbinom(r-1,n, 0.14471816)
  [1] 0.05000001


  pbinom(r,n, 0.35965569)
  [1] 0.05000001

  pbinom(r,n, 0.35965570)
  [1] 0.05

  pbinom(r,n, 0.35965571)
  [1] 0.04999998


> sample estimates:
> probability of success
>                   0.24
>
> thx much
>
> ej

Best wishes,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <[hidden email]>
Fax-to-email: +44 (0)870 094 0861
Date: 19-Oct-06                                       Time: 16:53:19
------------------------------ XFMail ------------------------------

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: [R] binom.test

Ethan Johnsons
Thx much for the feedback.
It is a big help.

ej

On 10/19/06, Ted Harding <[hidden email]> wrote:

> On 19-Oct-06 Ethan Johnsons wrote:
> > R-experts:
> >
> > A quick question, please.
> >
> >>From a lab exp, I got 12 positives out of 50.
> > To get 90% CI for this , I think binom.test might be
> > the one to be used.
> > Is there a better way or function to calculate this?
>
> What do you mean by "better"? For a symmetrical 2-sided
> exact binomial confidence interval, binom.test gives the
> result quickly and, to within the precision of pbinom,
> correctly (as I've just verified by hand!).
>
> And you can get 1-sided CIs by setting the 'alternative'
> option, or asymmetrical CI's by finding the two 1-sided
> CIs (e.g. for conf.level = 0.03 and 0.07) that you want.
>
> What do you want to improve on?
>
> >> binom.test(x=12, n=50, p=12/50, conf.level = 0.90)
> >
> >         Exact binomial test
> >
> > data:  12 and 50
> > number of successes = 12, number of trials = 50, p-value = 1
> > alternative hypothesis: true probability of success is not equal to
> > 0.24
> > 90 percent confidence interval:
> >  0.1447182 0.3596557
>
>   r<-12 ; n<-50
>
>   1-pbinom(r-1,n, 0.14471815)
>   [1] 0.04999999
>
>   1-pbinom(r-1,n, 0.14471816)
>   [1] 0.05000001
>
>
>   pbinom(r,n, 0.35965569)
>   [1] 0.05000001
>
>   pbinom(r,n, 0.35965570)
>   [1] 0.05
>
>   pbinom(r,n, 0.35965571)
>   [1] 0.04999998
>
>
> > sample estimates:
> > probability of success
> >                   0.24
> >
> > thx much
> >
> > ej
>
> Best wishes,
> Ted.
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <[hidden email]>
> Fax-to-email: +44 (0)870 094 0861
> Date: 19-Oct-06                                       Time: 16:53:19
> ------------------------------ XFMail ------------------------------
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: [R] binom.test

Francisco J. Zagmutt
In reply to this post by Chuck Cleland
You can also plot an uncertainty distribution of p, using an uninformed
prior (uniform(0,1)), using beta(s+1, n-s+1)  i.e.

x <- seq(0.091, 0.469, length=100)
plot(x, dbeta(.x, shape1=13, shape2=39), xlab="x", ylab="Density",
main="Uncertainy distribution for p: beta(a = 12+1, b = 50-12+1)", type="l")

Cheers,

Francisco


Dr. Francisco J. Zagmutt
College of Veterinary Medicine and Biomedical Sciences
Colorado State University



>From: Chuck Cleland <[hidden email]>
>To: Ethan Johnsons <[hidden email]>
>CC: [hidden email]
>Subject: Re: [R] binom.test
>Date: Thu, 19 Oct 2006 11:27:35 -0400
>
>Ethan Johnsons wrote:
> > R-experts:
> >
> > A quick question, please.
> >
> >>From a lab exp, I got 12 positives out of 50.
> > To get 90% CI for this , I think binom.test might be the one to be used.
> > Is there a better way or function to calculate this?
> >
> >> binom.test(x=12, n=50, p=12/50, conf.level = 0.90)
> >
> >         Exact binomial test
> >
> > data:  12 and 50
> > number of successes = 12, number of trials = 50, p-value = 1
> > alternative hypothesis: true probability of success is not equal to 0.24
> > 90 percent confidence interval:
> >  0.1447182 0.3596557
> > sample estimates:
> > probability of success
> >                   0.24
>
>You might consider binconf() in the Hmisc package too:
>
>library(Hmisc)
>binconf(12, 50, method="all")
>            PointEst    Lower    Upper
>Exact          0.24 0.130610 0.381691
>Wilson         0.24 0.142974 0.374127
>Asymptotic     0.24 0.121621 0.358379
>
> > thx much
> >
> > ej
> >
> > ______________________________________________
> > [hidden email] 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.
>
>--
>Chuck Cleland, Ph.D.
>NDRI, Inc.
>71 West 23rd Street, 8th floor
>New York, NY 10010
>tel: (212) 845-4495 (Tu, Th)
>tel: (732) 512-0171 (M, W, F)
>fax: (917) 438-0894
>
>______________________________________________
>[hidden email] 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.

_________________________________________________________________
Stay in touch with old friends and meet new ones with Windows Live Spaces

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: [R] binom.test

Kevin E. Thorpe
In reply to this post by Ethan Johnsons
See also the binconf function in the Hmisc package.

Ethan Johnsons wrote:

> R-experts:
>
> A quick question, please.
>
>>From a lab exp, I got 12 positives out of 50.
> To get 90% CI for this , I think binom.test might be the one to be used.
> Is there a better way or function to calculate this?
>
>> binom.test(x=12, n=50, p=12/50, conf.level = 0.90)
>
>         Exact binomial test
>
> data:  12 and 50
> number of successes = 12, number of trials = 50, p-value = 1
> alternative hypothesis: true probability of success is not equal to 0.24
> 90 percent confidence interval:
>  0.1447182 0.3596557
> sample estimates:
> probability of success
>                   0.24
>
> thx much
>
> ej
>


--
Kevin E. Thorpe
Biostatistician/Trialist, Knowledge Translation Program
Assistant Professor, Department of Public Health Sciences
Faculty of Medicine, University of Toronto
email: [hidden email]  Tel: 416.946.8081  Fax: 416.946.3297

______________________________________________
[hidden email] 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.