I want to perform in R the analysis "simultaneous confidence interval for multiple proportions", as illustrated in the article of Agresti et al. (2008) "Simultaneous confidence intervals for comparing binomial parameter", Biometrics 64, 1270-1275.

Unfortunately I did not succed to find any R example, and I have no idea how to implement this process in R.

As a case study, I need to apply such analysis on the following simple prolbem:

I did an experiment in which 12 participants had to choose between 3 conditions when provided with 3 stimuli.

Stimulus  Condition1  Condition2 Condition 3
A            9          1          2
B           10          2          0
C            8          2          2

I want to prove that it is not by chance that Condition 1 is preferred rather than the other two conditions.

Can you please give me an example in R on how to perform such analysis?

In addition I would need to know how would you report such analysis in a paper.

Thanks in advance


1 Answer 1


I just write a function for the Simultaneous Agresti-Caffo Confidence Interval based on Agresti et al. (2008) "Simultaneous confidence intervals for comparing binomial parameter", Biometrics 64, 1270-1275. I hope this helps

ac.sci = function (n1, x1, n2, x2, cl=0.95, k){
    p1 = x1/n1; p2 = x2/n2
    p1.tilde = (x1+1)/(n1+2)
    p2.tilde = (x2+1)/(n2+2)
    Q = qtukey(cl, nmeans=k, df=Inf)
    se = sqrt((p1.tilde*(1-p1.tilde)/(n1+2))+(p2.tilde*(1-p2.tilde)/(n2+2)))
    L = (p1.tilde-p2.tilde) - Q*se/sqrt(2)
    U = (p1.tilde-p2.tilde) + Q*se/sqrt(2)
    result = matrix(data=c(p1-p2, L, U), nrow=1, ncol=3)
    colnames(result) = c("Diff.P.hats", "Lower", "Upper")

Example 1: Condition1 vs. Condition2 given A, where n1 = sum of Stimulus A + B + C of Condition1, and x1 = frequencies of Condition1 given Stimulus A. Similar to n2 and x2 for Condition2. ac.sci(n1 = 27, x1 = 9, n2 = 5, x2 = 1, k=3) the 95% CI = (-0.391, 0.509), since 95% CI contains 0 thus, we can conclude that Condition 1 is not statistically significant different from Condition 2 at a 5% level.

Example2: A vs. B given conditions, where n1 = sum of conditions 1 + 2 + 3 of A, and x1 = frequencies of A given Condition1. Similar to n2 and x2 for B.

ac.sci(n1 = 12, x1 = 9, n2 = 10, x2 = 12, cl=0.95, k = 3)
the 95% CI = (-0.565, -0.172). Since 95% simultaneous Agresti-Caffo CI does not contain 0. Thus, we can conclude that A and B are different.

  • $\begingroup$ Hi, thanks a lot! Regarding the first example why do you check the frequencies of Condition1 given Stimulus A? I am interested in all the stimuli, not only in the effect of stimulus A. My goal is to know if Condition 1 is better than Condition2 and Condition3, GLOBALLY. Please enlighten me! $\endgroup$
    – L_T
    Dec 10, 2011 at 12:50
  • $\begingroup$ In addition, is prop.test the right function implementing the Simultaneous Agresti-Caffo Confidence Interval method? In what does it differ from your implementation? $\endgroup$
    – L_T
    Dec 10, 2011 at 12:51
  • 1
    $\begingroup$ You have three stimulus and these will be an effect on your conditions. You should compare your condition 1 vs. 2 based on Stimulus A, B or C. Do the same thing for Condition 1 vs. 3 and 2 vs. 3. $\endgroup$
    – Tu.2
    Dec 10, 2011 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.