Stefanie Von Felten
2011-Apr-05 14:26 UTC
[R] Antw: Re: Confidence interval for the difference between proportions - method used in prop.test()
Dear Josh, Thanks for your help! Does your answer mean, that you agree the two methods should do the same, and what I was guessing, despite the small differences? What I prefer about ci.pd is, that the help clearly says which method is implemented, which is not the case for prop.test. But I do not know who has programmed the function. Best wishes Steffi Stefanie von Felten, PhD Statistician Clinical Trial Unit, CTU University Hospital Basel Schanzenstrasse 55 CH-4031 Basel Phone: ++41(0)61 556 54 98>>> Joshua Wiley 05.04.11 15.59 Uhr >>>Hi Stefanie, Just to be clear, we are talking about differences in the third or lower decimal place (at least with R version 2.13.0 alpha (2011-03-17 r54849), Epi_1.1.20). This strikes me as small enough that both functions may be implementing the same method, but maybe slightly different ways of going about it? If you are really concerned and need to know *exactly*, look at the source code for both functions. In case you did not know, if you type the function name at the console with parentheses or any arguments, just like:> prop.test > ci.pdit will show the actual function code. It looks to me like both of them are implemented purely in R, and without even calling any other complex functions (at least based on a quick glance through). This means if you have the Newscomb text, you should be able to sit down and go through the code step by step comparing it. Cheers, Josh FYI, you can use a matrix with prop.test, and then its transpose for ci.pd. ## mymat <- cbind(Successes = c(21, 41), Failures = c(345, 345) - c(21, 41)) require(Epi) results <- list(prop.test(mymat, correct=FALSE), ci.pd(t(mymat))) results[[1]][["conf.int"]] - results[[2]][6:7] On Tue, Apr 5, 2011 at 3:38 AM, Stefanie Von Felten wrote:> Hello, > > Does anyone know which method from Newcombe (1998)* is implemented in prop.test for comparing two proportions? > I would guess it is the method based on the Wilson score (for single proportion), with and without continuity correction for prop.test(..., correct=FALSE) and prop.test(..., correct=TRUE). These methods would correspond to no. 10 and 11 tested in Newcombe, respectively. Can someone confirm this? If not, which other methods are implemented by prop.test? > > * Newcombe R.G. (1998) Two-Sided Confidence Intervals for the Single Proportion: Comparison of Seven Methods. Statistics in Medicine *17*, 857-872. > > There is also the function ci.pd() from the R-package Epi, which should implement method no. 10 from Newcombe. However, prop.test(..., correct=FALSE) and ci.pd do not give the same result if I do the following: > > successes <- c(21, 41) > total <- c(345, 345) > prop.test(successes, total, correct=FALSE) > library(Epi) > ci.pd(matrix(c(successes, total-successes),ncol=2, byrow=TRUE)) > > Can someone explain why? > > Best wishes > Stefanie von Felten > > > Stefanie von Felten, PhD > Statistician > Clinical Trial Unit, CTU > University Hospital Basel > Schanzenstrasse 55 > CH-4031 Basel > > Phone: ++41(0)61 556 54 98 > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ [[alternative HTML version deleted]]
Joshua Wiley
2011-Apr-05 15:03 UTC
[R] Confidence interval for the difference between proportions - method used in prop.test()
Dear Steffi, On Tue, Apr 5, 2011 at 7:26 AM, Stefanie Von Felten <SVonfelten at uhbs.ch> wrote:> Dear Josh, > > Thanks for your help! > > Does your answer mean, that you agree the two methods should do the same, > and what I was guessing, despite the small differences?That would be my guess, but I have not actually read the reference in discussion. Still, the documentation for prop.test uses the same Newcombe reference as ci.pd, so if method 10 is the clear winner, it seems reasonable that prop.test is an implementation of it.> > What I prefer about ci.pd is, that the help clearly says which method is > implemented, which is not the case for prop.test. But I do not know who has > programmed the function.Then for reporting, use ci.pd, and say it is method 10 from Newcombe. You can always check the results with prop.test() which is part of R core so you can be pretty confident whatever it does, it does it correctly (and will be updated if necessary with future releases of R). Sincerely, Josh> > Best wishes > Steffi > > > Stefanie von Felten, PhD > Statistician > Clinical Trial Unit, CTU > University Hospital Basel > Schanzenstrasse 55 > CH-4031 Basel > > Phone: ++41(0)61 556 54 98 >>>> Joshua Wiley <jwiley.psych at gmail.com> 05.04.11 15.59 Uhr >>> > Hi Stefanie, > > Just to be clear, we are talking about differences in the third or > lower decimal place (at least with R version 2.13.0 alpha (2011-03-17 > r54849), Epi_1.1.20). This strikes me as small enough that both > functions may be implementing the same method, but maybe slightly > different ways of going about it? > > If you are really concerned and need to know *exactly*, look at the > source code for both functions. In case you did not know, if you type > the function name at the console with parentheses or any arguments, > just like: > >> prop.test >> ci.pd > > it will show the actual function code. It looks to me like both of > them are implemented purely in R, and without even calling any other > complex functions (at least based on a quick glance through). This > means if you have the Newscomb text, you should be able to sit down > and go through the code step by step comparing it. > > Cheers, > > Josh > > FYI, you can use a matrix with prop.test, and then its transpose for ci.pd. > ## > mymat <- cbind(Successes = c(21, 41), Failures = c(345, 345) - c(21, 41)) > require(Epi) > results <- list(prop.test(mymat, correct=FALSE), ci.pd(t(mymat))) > results[[1]][["conf.int"]] - results[[2]][6:7] > > On Tue, Apr 5, 2011 at 3:38 AM, Stefanie Von Felten <SVonfelten at uhbs.ch> > wrote: >> Hello, >> >> Does anyone know which method from Newcombe (1998)* is implemented in >> prop.test for comparing two proportions? >> I would guess it is the method based on the Wilson score (for single >> proportion), with and without continuity correction for prop.test(..., >> correct=FALSE) and prop.test(..., correct=TRUE). These methods would >> correspond to no. 10 and 11 tested in Newcombe, respectively. Can someone >> confirm this? If not, which other methods are implemented by prop.test? >> >> * Newcombe R.G. (1998) Two-Sided Confidence Intervals for the Single >> Proportion: Comparison of Seven Methods. Statistics in Medicine *17*, >> 857-872. >> >> There is also the function ci.pd() from the R-package Epi, which should >> implement method no. 10 from Newcombe. However, prop.test(..., >> correct=FALSE) and ci.pd do not give the same result if I do the following: >> >> successes <- c(21, 41) >> total <- c(345, 345) >> prop.test(successes, total, correct=FALSE) >> library(Epi) >> ci.pd(matrix(c(successes, total-successes),ncol=2, byrow=TRUE)) >> >> Can someone explain why? >> >> Best wishes >> Stefanie von Felten >> >> >> Stefanie von Felten, PhD >> Statistician >> Clinical Trial Unit, CTU >> University Hospital Basel >> Schanzenstrasse 55 >> CH-4031 Basel >> >> Phone: ++41(0)61 556 54 98 >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at 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. >> > > > > -- > Joshua Wiley > Ph.D. Student, Health Psychology > University of California, Los Angeles > http://www.joshuawiley.com/ >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/