R has several functions that do confidence intervals and tests
of significance for proportions. They are not done exactly as our
textbook recommends, in particular they do not do the plus four
intervals. But they do something reasonable.
We redo Example 18.6 in the textbook.
We use the R function prop.test
(on-line
help)
The interval
95 percent confidence interval: 0.4969264 0.8040596
does not agree with either interval in the textbook,
Rweb:> 0.667 + c(-1,1) * 0.148 [1] 0.519 0.815 Rweb:> 0.651 + c(-1,1) * 0.142 [1] 0.509 0.793
but isn't that much different either.
The performance of the interval that prop.test
calculates
is presented on our performance page.
We redo Example 18.8 in the textbook.
We use the R function binom.test
(on-line
help)
The P-value
Rweb:> binom.test(2048, 4040, p = 0.5)
Exact binomial test
data: 2048 and 4040
number of successes = 2048, number of trials = 4040, p-value = 0.3869
alternative hypothesis: true probability of success is not equal to 0.5
is not exactly the same as given in the textbook because R does an exact calculation using the binomial distribution rather than an approximate calculation using the normal distribution. In this case R is right and the book is wrong. Exact is better than approximate.
We redo Examples 19.2 and 19.3 in the textbook.
We use the R function prop.test
(on-line
help)
The interval
95 percent confidence interval: 0.01710674 0.36364418
does not agree with either interval in the textbook,
but isn't that much different either.
We redo Examples 19.4 and 19.5 in the textbook.
We use the R function prop.test
(on-line
help)
The P-value
Rweb:> prop.test(c(91, 117), c(149, 236))
2-sample test for equality of proportions with continuity correction
data: c(91, 117) out of c(149, 236)
X-squared = 4.4092, df = 1, p-value = 0.03575
alternative hypothesis: two.sided
is not exactly the same as given in the textbook because R does a
continuity correction. One could get the answer in the book by
using the optional argument correct = FALSE
, but there
is no point to that.