The notes for the topics on this page can be found in the lecture 3 folder on Canvas.

R

The prop_test function in the catfun package provides both approximated confidence intervals and exact confidence intervals for single proportions. For more information run ?prop_test in the R console. Another possible function is BinomCI() in the DescTools package.

library(catfun)

prop_test(2, 6, method = "wald", conf.level = .95)
## 2  out of  6,  null probability =  0.5
## ---------------------------------------- 
## Observed proportion: 0.3333 
## Confidence interval method: wald 
## Confidence interval: 0 0.7105286 
## 
## Exact limits: 0.04327187 0.7772219 
## 
## Test that 0.3333 = 0.5 
## ---------------------------------------- 
## Chi-squared: 0.6666667 
## Degrees freedom: 1 
## p-value: 0.41422

SAS

To create confidence intervals for a single proportion in SAS use the frequency procedure.

The syntax is:

proc freq data = <dataset>; 
  table <variable name> / binomial(p = <null value>) alpha = <alpha level>; 
  weight <weighting variable if summary data>; 
run; 

The following example tests if the proportion 0.33 (2/6) is equal to 0.5 in the population. Because this is summary level data, we include a weight statement and indicate that the variable loss contains the counts.

data followup1; 
  input loss; 
  cards; 
  2
  4
  ;
run; 

title 'Loss to Follow-up Exact CI Example'; 
proc freq data = followup1 order = data; 
  table loss / binomial(p = 0.5) alpha = 0.05; 
  weight loss; 
run; 
##                                    Loss to Follow-up Exact CI Example
## 
##                                            The FREQ Procedure
## 
##                                                         Cumulative    Cumulative
##                        loss    Frequency     Percent     Frequency      Percent
##                        ---------------------------------------------------------
##                           2           2       33.33             2        33.33  
##                           4           4       66.67             6       100.00  
## 
## 
##                                           Binomial Proportion
##                                                 loss = 2
## 
##                                     Proportion                0.3333
##                                     ASE                       0.1925
##                                     95% Lower Conf Limit      0.0000
##                                     95% Upper Conf Limit      0.7105
##                                                                     
##                                     Exact Conf Limits               
##                                     95% Lower Conf Limit      0.0433
##                                     95% Upper Conf Limit      0.7772
## 
##                                       Test of H0: Proportion = 0.5
## 
##                                     ASE under H0              0.2041
##                                     Z                        -0.8165
##                                     One-sided Pr <  Z         0.2071
##                                     Two-sided Pr > |Z|        0.4142
## 
##                                             Sample Size = 6