Introduction to Statistics (MAT/SST 115.03 2008S)

R Notes for Topic 21: Comparing Two Proportions

21-3 e

Here are the computations

pT = 163/9726
pR = 167/9745
pc = (163+165)/(9726+9745)

Think about how many decimal places are appropriate. For example, for pT, should you use 0.017, 0.0168, 0.01676, or even more decimal places? Will it make a difference?

21-3 f

You should try using the Test of Significance Calculator applet first. Afterwards, compute the test statistic using R. We'll explore different approximations to see if we always get the same value.

Using three places after the decimal.


Using four places after the decimal.


Using five places after the deimal.


Using the original calculations, unmodified.


What do these differences suggest to you?

21-4 d

Let's do the first row first. You can certainly use the applet, although, as you've just seen, it does approximate a bit too much. So, let's also explore how to do the computation in R.

pw = .71
pm = .81
nw = 100
nm = 100
pc = (pw*nw+pm*nm)/(nw+nm)
z = (pw-pm)/sqrt(pc*(1-pc)*(1/nw+1/nm))

note that you'll get somewhat different answers than the answer key for two reasons: First, we are using more digits of accuracy (whether or not that's a good idea). Second, we are using Pr(Z < z) while the answer key seems to be using 2*Pr(Z < |z|).

For the second line, we don't need to write quite as much. Basically, we chance nw and nm and then recalculate.

nw = 200
nm = 200
pc = (pw*nw+pm*nm)/(nw+nm)
z = (pw-pm)/sqrt(pc*(1-pc)*(1/nw+1/nm))

You should be able to figure out what to change for the last line of the table.

21-5 a

Once again, we can use the applet or R to compute the test statistic.

pw = 559/1835
pm = 1195/2681
nw = 1835
nm = 2681
pc = (559+1195)/(1835+2681)
z = (pw-pm)/sqrt(pc*(1-pc)*(1/nw+1/nm))

Given your hypothesis and that test statistic, you should be able to figure out the p-value.


At this point, you should be able to figure out the computations on your own. Grab one of us if you need help.

Creative Commons License

Samuel A. Rebelsky,

Copyright (c) 2007-8 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License. To view a copy of this license, visit or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.