Search code examples
rstatisticsprobabilityconfidence-interval

Confidence interval for binomial data in R?


I know that I need mean and s.d to find the interval, however, what if the question is:

For a survey of 1,000 randomly chosen workers, 520 of them are female. Create a 95% confidence interval for the proportion of workers who are female based on the survey.

How do I find mean and s.d for that?


Solution

  • You can also use prop.test from package stats, or binom.test

    prop.test(x, n, conf.level=0.95, correct = FALSE)
    
            1-sample proportions test without continuity correction
    
    data:  x out of n, null probability 0.5
    X-squared = 1.6, df = 1, p-value = 0.2059
    alternative hypothesis: true p is not equal to 0.5
    95 percent confidence interval:
     0.4890177 0.5508292
    sample estimates:
       p 
    0.52 
    

    You may find interesting the article TWO-SIDED CONFIDENCE INTERVALS FOR THE SINGLE PROPORTION: COMPARISON OF SEVEN METHODS, where in Table 1 on page 861 are given different confidence intervals, for a single proportion, calculated using seven methods (for selected combinations of n and r). Using prop.test you can get the results found in rows 3 and 4 of the table, while binom.test returns what you see in row 5.