Help the Stat Consulting Group by giving a gift

Introduction to the Practice of Statistics by Moore and McCabe

Chapter 8: Inference for Proportions

Example 8.1, page 587 can be solved with theciicommand. We supply the sample size (N) and the number of successes (X) and we get the confidence interval forpas shown in the book.

cii 17096 3314-- Binomial Exact -- Variable | Obs Mean Std. Err. [95% Conf. Interval] ---------+------------------------------------------------------------- | 17096 .1938465 .0030234 .1879441 .1998532

Example 8.2, page 589-590 shows how to test whether the probability of getting a head was really .5 given 2048 heads in 4040 flips. We compute the observed probability of a head as 2048/4040=.5069 and useprtestias shown below.

prtesti 4040 .5069 .5One-sample test of proportion x: Number of obs = 4040 ------------------------------------------------------------------------------ Variable | Mean Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- x | .5069 .0078657 64.4443 0.0000 .4914835 .5223165 ------------------------------------------------------------------------------ Ho: proportion(x) = .5 Ha: x < .5 Ha: x ~= .5 Ha: x > .5 z = 0.877 z = 0.877 z = 0.877 P < z = 0.8098 P > |z| = 0.3804 P > z = 0.1902

Example 8.3, page 591 is illustrated below, and it is much like example 8.2.

prtesti 4040 .4931 .5One-sample test of proportion x: Number of obs = 4040 ------------------------------------------------------------------------------ Variable | Mean Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- x | .4931 .0078657 62.6898 0.0000 .4776835 .5085165 ------------------------------------------------------------------------------ Ho: proportion(x) = .5 Ha: x < .5 Ha: x ~= .5 Ha: x > .5 z = -0.877 z = -0.877 z = -0.877 P < z = 0.1902 P > |z| = 0.3804 P > z = 0.8098

Example 8.4, page 591 shows how to get a confidence interval for the proportion of heads.

cii 4040 2048, level(99)-- Binomial Exact -- Variable | Obs Mean Std. Err. [99% Conf. Interval] ---------+------------------------------------------------------------- | 4040 .5069307 .0078657 .4865486 .5272972

We skip examples 8.5-8.7.

Example 8.8 and 8.9, page 603 and 606 are illustrated below. This shows how to get a confidence interval for the difference of 2 proportions, illustrated below in Stata. Note that you supply

N1thenp1thenN2thenp2. This also tests whether the two proportions are equal (as shown in example 8.9). (Note that our copy of the book shows the Z=9.34, but we obtain Z=9.304, so this appears to be a misprint).

prtesti 7180 .227 9916 .17Two-sample test of proportion x: Number of obs = 7180 y: Number of obs = 9916 ------------------------------------------------------------------------------ Variable | Mean Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- x | .227 .0049436 45.9183 0.0000 .2173108 .2366892 y | .17 .0037722 45.0665 0.0000 .1626066 .1773934 ---------+-------------------------------------------------------------------- diff | .057 .0062184 .0448122 .0691878 | under Ho: .0061268 9.3034 0.0000 ------------------------------------------------------------------------------ Ho: proportion(x) - proportion(y) = diff = 0 Ha: diff < 0 Ha: diff ~= 0 Ha: diff > 0 z = 9.303 z = 9.303 z = 9.303 P < z = 1.0000 P > |z| = 0.0000 P > z = 0.0000

Example 8.10, page 607 can be solved with theiri(incidence rate, immediate) command. Note that we supply the# male binge drinkersthen# female binge drinkersthen# malesthen# females.

iri 1630 1684 7180 9916| Exposed Unexposed | Total -----------------+------------------------+---------- Cases | 1630 1684 | 3314 Person-time | 7180 9916 | 17096 -----------------+------------------------+---------- | | Incidence Rate | .2270195 .1698265 | .1938465 | | | Point estimate | [95% Conf. Interval] |------------------------+---------------------- Inc. rate diff. | .057193 | .043509 .0708769 Inc. rate ratio | 1.336773 | 1.247998 1.431833 (exact) Attr. frac. ex. | .2519297 | .1987167 .3015944 (exact) Attr. frac. pop | .1239123 | +----------------------------------------------- (midp) Pr(k>=1630) = 0.0000 (exact) (midp) 2*Pr(k>=1630) = 0.0000 (exact)

Example 8.11, page 608 can also be solved with theiricommand as illustrated below. The confidence interval is slightly different from the book, probably due to rounding.

iri 55 21 3338 2676| Exposed Unexposed | Total -----------------+------------------------+---------- Cases | 55 21 | 76 Person-time | 3338 2676 | 6014 -----------------+------------------------+---------- | | Incidence Rate | .0164769 .0078475 | .0126372 | | | Point estimate | [95% Conf. Interval] |------------------------+---------------------- Inc. rate diff. | .0086294 | .0031315 .0141273 Inc. rate ratio | 2.099632 | 1.249441 3.655221 (exact) Attr. frac. ex. | .523726 | .1996418 .7264188 (exact) Attr. frac. pop | .3790123 | +----------------------------------------------- (midp) Pr(k>=55) = 0.0014 (exact) (midp) 2*Pr(k>=55) = 0.0027 (exact)

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.