[R] Confidence interval for the difference between proportions - method used in prop.test()

Joshua Wiley jwiley.psych at gmail.com
Tue Apr 5 15:59:02 CEST 2011


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/



More information about the R-help mailing list