# Confidence intervals for proportions (prevalence)

I have some data on a sample of $n=1776$ hospitals. For each hospital there is a total number of patients (patients), and a number of patients diagnosed with a particular condition (diagnosed). Do I take the mean of this proportion,diagnosed/patients, for all hospitals in the sample, $\hat{\mu}$, and calculate a 95% confidence interval as $\hat{\mu} \pm 1.96\sigma / \sqrt{n}$ or as $\hat{\mu} \pm 1.96 \sqrt{\hat{\mu}(1-\hat{\mu})/n}$ ? Or.... ?

Update

[Following comments from whuber]. Additionally, the data are broken down into 2 age groups (young and old) and 3 risk scores. That is, all 1776 hospitals have total numbers of patients as follows:

               younger patients       older patients

Low risk            A                      D

Medium risk         B                      E

High risk           C                      F


...and similarly for the numbers of patients with the condition.

So, for each combination of age group and risk score, I would like to estimate the mean prevalence and a confidence interval for it.

Here is some summary of the data

Risk   age    mean   sd      n
1      u50    0.37   0.19    1776
2      u50    0.49   0.25    1776
3      u50    0.54   0.26    1776
1      o50    0.45   0.36    1776
2      o50    0.52   0.42    1776
3      o50    0.67   0.41    1776

• Consider providing some simple summary stats of your data, because you ought to get different kinds of replies depending on how large these fractions and numbers of patients tend to be. – whuber Sep 26 '12 at 21:05
• @whuber I have added some stats. Is this what you had in mind ? I am sorry if I am misunderstanding you. – Joe King Sep 26 '12 at 21:59
• Yes, Joe, that's right. Your other comment to a reply is also telling: the presence of some small and even zero ratios for individual hospitals is important to know. Your entry for risk=2, age=o50 is interesting, because the large SD of 0.42 compared to the mean of 0.52 is consistent only with data where about half of the hospitals are at or near zero and the other half are at or near 100%! (This presumes the ratios cannot exceed 100% individually: there are no multiple diagnoses for the same patient.) – whuber Sep 26 '12 at 22:04

require(boot)
quantile(boot.obj$t, c(.025,.975))  You can repeat this for each of your 6 subsets of data. • Thank you ! I don't know that much about bootstrapping, but the result of running this code on my data seems very encouraging ! – Joe King Sep 28 '12 at 15:58 Joe, Check to see if (sample size)*(proportion diagnosed) >= 5 for each hospital or group of hospitals by age/risk score. If so, then the normal dbn closely approximates the binomial dbn and the 95% CI = p_hat +/- 1.96*(p_hat*(1-p_hat)/n)^0.5 formula may be used. For a better approximation, use the Wilson score interval (see http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval). Robert • Thank you ! (sample size)*(proportion diagnosed) is less than 5 for some hospitals, but there are relatively few of these.... – Joe King Sep 28 '12 at 15:56 Updated Regression Approach Here's a way that might work. You can "expand" your data to patient level, so each row corresponds to a patient, who is either diagnosed or not. It might look like this: hospital age risk diagnosed 1 1 0 1 1 0 1 0 1 1 2 1 Then you estimate a binary model, such as a probit, where your dependent variables are dummies for the risk-age group interactions. You may also want to cluster on the hospital. Then you can calculate the predictive margins for each risk-age dummy. This will not work You can hack this in a regression context by simple linear model of$\log(y)$on a constant, and exponentiating the coefficients and CIs. This will give you geometric mean and its CI, which is appropriate mean to use since you are dealing with rates. Since all your$\mu$s are greater than zero, taking logs won't cost you any data. Here's an example in Stata: . sysuse auto,clear (1978 Automobile Data) . generate logprice=log(price) . regress logprice, eform(GM) Source | SS df MS Number of obs = 74 -------------+------------------------------ F( 0, 73) = 0.00 Model | 0 0 . Prob > F = . Residual | 11.2235331 73 .153747029 R-squared = 0.0000 -------------+------------------------------ Adj R-squared = 0.0000 Total | 11.2235331 73 .153747029 Root MSE = .39211 ------------------------------------------------------------------------------ logprice | GM Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | 5656.907 257.8496 189.56 0.000 5165.664 6194.866 ------------------------------------------------------------------------------ . means price Variable | Type Obs Mean [95% Conf. Interval] -------------+---------------------------------------------------------- price | Arithmetic 74 6165.257 5481.914 6848.6 | Geometric 74 5656.907 5165.664 6194.865 | Harmonic 74 5296.672 4928.901 5723.75 ------------------------------------------------------------------------  Note that the geometric mean matches the regression output very nicely. I learned about this from Roger Newson's Stata Tip #1. • Because it's possible that some observed rates will be zero, and those are useful data, it seems that taking logarithms cannot quite be the right thing to do. – whuber Sep 26 '12 at 21:23 • I'm really sorry, but I don't understand ! But thanks anyway ! – Joe King Sep 26 '12 at 21:32 • @whuber I vividly recall that the all the$\mu\$s were between 0.3 and 0.8, but that seems to have disappeared in the edit (or I made it up). You are certainly correct that this will not work if that's not the case. – Dimitriy V. Masterov Sep 26 '12 at 21:37