Chapter 11 Comparing Proportions

Many outcomes in the social and behavioral sciences are binary: employed or not employed, voted or did not vote, survived or died, and supported or opposed a proposal. A population proportion is written as \(p\), and its sample estimate is

\[\hat p=\frac{x}{n},\]

where \(x\) is the number of observations with the outcome and \(n\) is the number of observations at risk of having it.

This chapter develops a sequence of methods for binary and categorical outcomes. The method depends on the research design—not merely on the fact that the data appear in a contingency table.

  1. Estimate or test one population proportion.
  2. Compare two independent proportions.
  3. Compare paired or repeated binary outcomes.
  4. Compare proportions across three or more groups.
  5. Test a trend across ordered groups.
  6. Adjust a comparison for strata or a complex survey design.

Throughout the chapter, identify the outcome coded as a “success,” state the comparison direction, report an effect size and confidence interval, and then report the hypothesis test. A small p-value does not tell us whether a difference is large, useful, or causal.

11.1 Binary Outcomes and the Sampling Distribution of \(\hat p\)

For independent Bernoulli trials with a constant probability \(p\), the count of successes \(X\) follows a binomial distribution:

\[P(X=x)=\binom{n}{x}p^x(1-p)^{n-x}.\]

The sample proportion has mean \(p\) and standard error

\[SE(\hat p)=\sqrt{\frac{p(1-p)}{n}}.\]

When \(np\) and \(n(1-p)\) are sufficiently large, the sampling distribution of \(\hat p\) is approximately normal. A common guideline is that both expected counts should be at least 10. This guideline concerns the expected counts, not whether the overall sample exceeds an arbitrary threshold such as 30.

The usual binomial model assumes independent observations and a common probability of success. Clustered observations, repeated observations on the same person, and complex survey samples require methods that account for their design.

11.2 One Population Proportion

11.2.1 Confidence intervals

The familiar Wald interval is

\[\hat p\pm z_{\alpha/2}\sqrt{\frac{\hat p(1-\hat p)}{n}}.\]

Although simple, the Wald interval can have poor coverage when the sample is small or \(\hat p\) is near 0 or 1. The Wilson score interval is a better general-purpose default. An exact Clopper–Pearson interval is also available, but it is often conservative: its actual coverage tends to exceed the nominal confidence level, which produces wider intervals.

For 55 reports of occasional opioid use among 497 students, \(\hat p=0.1106\). The 95% Wilson interval is approximately \((0.0860, 0.1412)\). The interval describes uncertainty in the district’s proportion under the sampling assumptions; it does not measure uncertainty in the national benchmark.

11.2.2 One-proportion hypothesis tests

To compare a population proportion with a benchmark \(p_0\), the hypotheses may be

\[ \begin{array}{ll} H_0:p=p_0,\quad H_A:p\ne p_0 & \text{(two-sided)},\\ H_0:p\le p_0,\quad H_A:p>p_0 & \text{(upper-tailed)},\\ H_0:p\ge p_0,\quad H_A:p<p_0 & \text{(lower-tailed)}. \end{array} \]

The large-sample score statistic uses the null value in its standard error:

\[z=\frac{\hat p-p_0}{\sqrt{p_0(1-p_0)/n}}.\]

Use the exact binomial test when expected counts under the null are small. “Exact” does not mean universally superior: because the binomial distribution is discrete, an exact test can be conservative. For large samples, score tests generally have good behavior without that conservatism.

The observed rate exceeds 0.06 by \(0.0506\). The score test gives \(\chi^2(1)=22.6190\) and \(p<0.0001\); the exact binomial test also gives \(p<0.0001\). Both provide strong evidence against the benchmark. The substantive conclusion should emphasize the size and uncertainty of the difference, not just statistical significance.

11.3 Two Independent Proportions

Two samples are independent when an observation belongs to only one group and membership in one group does not determine membership in the other. Examples include comparing voters in two states or treatment and control groups made up of different people.

Let \(p_1\) and \(p_2\) denote the two population proportions. The most direct hypotheses are

\[H_0:p_1-p_2=0\qquad\text{versus}\qquad H_A:p_1-p_2\ne0.\]

11.3.1 The two-proportion z-test

Under \(H_0:p_1=p_2\), estimate the common proportion by pooling successes:

\[\hat p_{pool}=\frac{x_1+x_2}{n_1+n_2}.\]

The test statistic is

\[z=\frac{\hat p_1-\hat p_2}{\sqrt{\hat p_{pool}(1-\hat p_{pool})\left(\frac{1}{n_1}+\frac{1}{n_2}\right)}}.\]

Pooling is appropriate for the null-hypothesis test because the null asserts a common proportion. A confidence interval for \(p_1-p_2\) should instead use the unpooled standard error:

\[SE(\hat p_1-\hat p_2)=\sqrt{\frac{\hat p_1(1-\hat p_1)}{n_1}+\frac{\hat p_2(1-\hat p_2)}{n_2}}.\]

Do not pool the standard error for the confidence interval.

11.3.2 Titanic example

Of 466 female passengers, 339 survived; of 843 male passengers, 161 survived. Define group 1 as female passengers and define success as survival.

The estimated survival proportions are \(0.7274\) and \(0.1909\), giving a risk difference of \(0.5364\). The 95% confidence interval for the difference is approximately \((0.4881, 0.5848)\). The evidence of a difference is overwhelming, but the result describes this manifest and this disaster; it does not establish a universal sex effect in shipwrecks.

For a \(2\times2\) table, the uncorrected Pearson chi-square statistic and the two-proportion z-test are mathematically equivalent:

\[\chi^2_{df=1}=z^2.\]

R’s prop.test() uses a continuity correction by default. Setting correct = FALSE yields the ordinary score test and makes this equivalence transparent.

11.3.3 Effect sizes for a \(2\times2\) table

Suppose the table is arranged as follows:

Group Outcome present Outcome absent Total
1 \(a\) \(b\) \(n_1\)
2 \(c\) \(d\) \(n_2\)

Three effect measures answer different questions.

Risk difference (RD)

\[RD=p_1-p_2.\]

The RD is an absolute difference. For the Titanic data, there were about \(0.5364\) more survivors per passenger in the female group than in the male group. Multiplying by 100 expresses this as a difference of 53.6483 percentage points, not a 53.6483 percent increase.

Risk ratio (RR)

\[RR=\frac{p_1}{p_2}.\]

For the Titanic data, \(RR=3.8090\): the observed female survival proportion was about 3.8090 times the observed male survival proportion.

Odds ratio (OR)

\[OR=\frac{p_1/(1-p_1)}{p_2/(1-p_2)}=\frac{ad}{bc}.\]

For the Titanic data, \(OR=11.3071\). An odds ratio is not a risk ratio. When an outcome is common, as survival was among female passengers, the two can differ dramatically. Odds ratios are central to logistic regression and case-control studies, but risk differences and risk ratios are often easier to communicate.

Report the confidence interval for the effect measure that matches the scientific question. If group 1 is an intervention and group 2 is a control, \(1-RR\) may be called the relative risk reduction when the intervention lowers risk. The number needed to treat is \(NNT=1/|RD|\), but it should be reported only when treatment assignment, follow-up, and causal interpretation are defensible.

11.3.4 A more informative plot

Raw count bars can be misleading when group sizes differ. Plot group proportions with confidence intervals or plot the difference directly.

Titanic survival proportions with 95% Wilson confidence intervals

FIGURE 11.1: Titanic survival proportions with 95% Wilson confidence intervals

11.4 Paired Proportions: McNemar’s Test

The independent-samples test is wrong when the same people are measured twice or when observations are individually matched. For paired binary data, use McNemar’s test.

Consider 100 people classified before and after a program:

After: Yes After: No
Before: Yes 30 6
Before: No 18 46

The concordant pairs (30 and 46) provide no evidence about change because their responses did not change. McNemar’s test compares only the discordant counts, 6 and 18:

\[H_0:P(\text{Yes to No})=P(\text{No to Yes}).\]

Here, more people changed from No to Yes than from Yes to No. The uncorrected McNemar test gives \(\chi^2(1)=6.0000\) and \(p=0.0143\). With few discordant pairs, use an exact McNemar test rather than the chi-square approximation. This can be obtained with an appropriate package or by applying an exact binomial test to one discordant count conditional on their total.

Conditioning on the 24 discordant pairs, the exact two-sided binomial p-value is \(0.0226\). The exact and large-sample procedures reach the same conclusion here, although their p-values differ.

11.5 Three or More Groups: Pearson’s Chi-square Test

For a table with \(r\) rows and \(c\) columns, Pearson’s statistic is

\[\chi^2=\sum_{i=1}^{r}\sum_{j=1}^{c}\frac{(O_{ij}-E_{ij})^2}{E_{ij}},\]

where

\[E_{ij}=\frac{(\text{row }i\text{ total})(\text{column }j\text{ total})}{n}\]

and \(df=(r-1)(c-1)\).

The same calculation supports two distinct study designs:

  • A test of independence asks whether two categorical variables are associated within one population.
  • A test of homogeneity asks whether the distribution of one categorical outcome is the same across several independently sampled populations or groups.

The arithmetic is identical, but the sampling design and interpretation differ.

The success proportions are \(0.4200\), \(0.5500\), and \(0.6800\). The omnibus test gives \(\chi^2(2)=13.6570\) and \(p=0.0010\). Rejection tells us that at least one differs; it does not identify which pairs differ. All six expected counts are at least 45. The standardized residuals are \(-3.2003\) and \(3.2003\) in the Standard row, 0 in the Moderate row, and \(3.2003\) and \(-3.2003\) in the Intensive row.

11.5.1 Follow-up comparisons and residuals

Two complementary follow-ups are useful:

  1. Standardized Pearson residuals show which cells contribute most to the omnibus statistic. Residuals beyond about \(\pm2\) deserve attention, although they are descriptive diagnostics rather than a substitute for planned comparisons.
  2. Pairwise proportion tests identify differing groups. Adjust for multiple comparisons with a method such as Holm’s procedure.

With Holm adjustment, the Standard–Intensive comparison gives \(p=0.0006\); the Standard–Moderate and Moderate–Intensive comparisons each give \(p=0.1177\). Whenever possible, prespecify the comparisons that answer the research question. Testing every possible pair after seeing the data raises the chance of false-positive findings.

11.5.2 Effect size for larger tables

Cramér’s \(V\) summarizes the strength of a nominal association:

\[V=\sqrt{\frac{\chi^2}{n\min(r-1,c-1)}}.\]

It ranges from 0 to 1, but its substantive meaning depends on the variables, table dimensions, and field. Treat conventional labels such as “small,” “medium,” and “large” as rough context-dependent guides, not universal facts.

For the program example, Cramér’s \(V=0.2133\).

For a \(2\times2\) table, \(V=|\phi|\). A signed phi coefficient is

\[\phi=\frac{ad-bc}{\sqrt{(a+b)(c+d)(a+c)(b+d)}}.\]

The shortcut \(\sqrt{\chi^2/n}\) gives only \(|\phi|\) and therefore loses direction. The sign also depends on the row and column ordering, so always state the coding.

11.6 Sparse Tables and Fisher’s Exact Test

The chi-square approximation can be unreliable when expected cell counts are small. Inspect expected counts—not just observed counts. A traditional warning rule flags a table when any expected count is below 1 or when more than 20% are below 5, although no single cutoff resolves every case.

For a \(2\times2\) table, Fisher’s exact test conditions on the margins and calculates probabilities from the hypergeometric distribution.

The expected counts are 4.5 and 7.5 in each row, so half are below 5. Fisher’s exact test gives \(p=0.0094\) and a conditional odds-ratio estimate of \(0.0532\), with a 95% interval from \(0.0009\) to \(0.5897\).

Fisher’s test is exact under its conditional model, but it should not simply be described as “more precise.” It can be conservative, and its default odds-ratio estimate is a conditional estimate rather than the sample cross-product ratio. For larger sparse tables, exact calculations or Monte Carlo p-values may be used:

11.7 Ordered Groups: A Test for Trend

An omnibus chi-square test ignores ordering. If groups have a natural order and the scientific hypothesis predicts a monotonic increase or decrease in a binary proportion, a Cochran–Armitage trend test is more focused.

For example, suppose success counts rise across four ordered exposure categories:

Exposure Success No success
Low 12 88
Medium-low 20 80
Medium-high 31 69
High 43 57

The trend test depends on the assigned order and scores. Use it when that ordered alternative was substantively justified before looking at the pattern. A significant trend does not prove linearity and can miss a U-shaped or otherwise nonmonotonic relationship. Plot the group proportions and confidence intervals alongside the test.

11.8 Stratified Comparisons and Confounding

An overall \(2\times2\) association may change after conditioning on a third variable. Simpson’s paradox occurs when an aggregate association reverses or disappears within strata because the groups have different compositions.

For several \(2\times2\) tables representing strata, the Cochran–Mantel–Haenszel (CMH) test evaluates a common association while controlling for the stratifying variable. It also estimates a common odds ratio.

For these illustrative strata, the estimated common odds ratio is \(1.7857\), with a 95% interval from \(0.9402\) to \(3.3914\). The continuity-corrected CMH test gives \(\chi^2(1)=2.5819\) and \(p=0.1081\), so the data remain compatible with no common association.

Before reporting one common odds ratio, inspect stratum-specific estimates. If they differ importantly, the third variable may be an effect modifier rather than merely a confounder, and a single pooled summary can obscure the result. Regression models provide a more flexible way to adjust for several covariates and interactions.

11.9 Complex Survey Data

Data from surveys such as the GSS, BRFSS, and YRBSS often involve weights, stratification, and clustering. Treating them as simple random samples generally produces incorrect standard errors and may bias population estimates if weights are ignored.

Use survey-weighted proportions and a design-adjusted test such as the Rao–Scott chi-square test.

The correct variable names and treatment of missing, refused, and “don’t know” responses must come from the survey’s codebook. Reporting an unweighted Pearson chi-square for a complex survey is not an acceptable substitute merely because the raw sample is large.

11.10 Practical Significance, Power, and Study Planning

11.10.1 Statistical versus practical significance

Large samples can make trivial differences statistically significant, while small samples can leave important differences uncertain. A complete report includes:

  • each group proportion and denominator;
  • an absolute effect such as the risk difference;
  • a relative effect when useful;
  • a confidence interval;
  • the test statistic, degrees of freedom when applicable, and p-value;
  • a substantive interpretation tied to the study design.

Avoid interpreting failure to reject \(H_0\) as proof that the proportions are equal.

11.10.2 Power and sample size

Power depends on the smallest substantively important difference, baseline proportion, significance level, allocation ratio, and test direction. For example, detecting a difference between 0.40 and 0.30 with 80% power in a two-sided test at \(\alpha=0.05\) requires about 356 observations per group under the simple independent-samples assumptions.

Inflate that number for expected attrition, unequal allocation, clustering, or a complex survey design. Do not choose the effect size solely to obtain a convenient sample size.

11.10.3 Equivalence and noninferiority

A nonsignificant difference does not establish that two proportions are practically equivalent. An equivalence test begins with a prespecified margin \(\Delta\) representing the largest difference considered negligible:

\[H_0: p_1-p_2\le-\Delta\ \text{or}\ p_1-p_2\ge\Delta\]

versus

\[H_A:-\Delta<p_1-p_2<\Delta.\]

The two one-sided tests (TOST) procedure declares equivalence when the corresponding confidence interval lies entirely inside \((-\Delta,\Delta)\). A noninferiority test is one-sided and asks whether a new treatment is no worse than a comparator by more than a prespecified margin. The margin must be justified substantively before the data are analyzed.

11.11 Choosing the Appropriate Procedure

Research design and question Primary procedure Effect estimate to emphasize
One sample versus a benchmark Score or exact binomial test \(\hat p-p_0\) and a Wilson interval for \(p\)
Two independent groups Two-proportion score test RD, RR, or OR with a confidence interval
Same people twice or matched pairs McNemar’s test Change among discordant pairs; paired difference
Three or more unordered groups Pearson chi-square Group proportions and Cramér’s \(V\)
Sparse \(2\times2\) table Fisher’s exact test OR and exact-compatible interval
Ordered groups and monotonic hypothesis Cochran–Armitage trend test Proportions across the ordered scores
Several \(2\times2\) strata CMH test Stratum-specific and common ORs
Complex survey sample Rao–Scott/design-based test Weighted proportions and design-based intervals
Claim of practical equivalence Equivalence or noninferiority test CI relative to a prespecified margin

11.12 Reporting and Interpretation

A concise two-group report might read:

The observed outcome proportion was 0.7274 among female Titanic passengers and 0.1909 among male passengers. The estimated risk difference was 0.5364 (95% CI: 0.4881 to 0.5848), and the two-proportion score test rejected equality of the proportions, \(\chi^2(1)=365.8869\), \(p<0.0001\). These data document a large association on this passenger manifest but do not, by themselves, identify a causal mechanism or justify generalization to other disasters.

For observational data, use “associated with” rather than “caused,” “affected,” or “led to” unless the design supports causal inference. Also consider selection bias, nonresponse, measurement error, missing data, clustering, and confounding.

11.13 Optional: Other Measures of Categorical Association

Several legacy measures remain useful in specialized settings but are not substitutes for the core effect estimates above.

  • Goodman–Kruskal’s lambda is a proportional-reduction-in-error measure for nominal variables. It can equal zero even when variables are associated because knowing the predictor may not change the modal prediction.
  • Contingency coefficient \(C\) is nonnegative, and its attainable maximum depends on table dimensions. Cramér’s \(V\) is generally easier to compare across differently sized tables.
  • Goodman–Kruskal’s gamma measures ordinal association from concordant and discordant pairs but ignores ties and can therefore appear large when ties are common.
  • Kendall’s \(\tau_b\) adjusts for ties and is especially suitable for square ordinal tables; \(\tau_c\) adapts the idea to rectangular tables.
  • Somers’ \(D\) is directional and is appropriate when one ordinal variable is explicitly the outcome.

These measures belong most naturally in a broader treatment of nominal and ordinal association. In a chapter focused on comparing proportions, RD, RR, OR, confidence intervals, and design-appropriate tests should receive priority.

11.14 Practice Problems

Problem 1

Radioactive waste, John Wayne, and Hollywood describes a controversial historical claim. Of 220 cast and crew members from The Conqueror, 91 had reportedly been diagnosed with cancer by the early 1980s. Suppose 14% is proposed as the appropriate population benchmark over the same follow-up period. Is the observed proportion higher than 14%? What can and cannot be concluded from this comparison?

Problem 2

Young and Hade studied 12,028 cancer deaths in Ohio. Of these deaths, 6,052 occurred in the week before Christmas and the rest in the week after Christmas. Do these data indicate a before-versus-after imbalance? Do they demonstrate that people can postpone death?

Problem 3

Of 6,252 men, 3,192 died in the week before Christmas. Of 5,776 women, 2,858 died in the week before Christmas. Estimate and test the sex difference. Report a risk difference and confidence interval.

Problem 4

The following counts summarize traffic stops from the Stanford Open Policing Project:

Group Stops Searches Hits Search rate Hit rate
Minority 69,883 3,533 1,475 0.0505 0.4174
Non-Minority 159,808 3,759 1,828 0.0235 0.4862
  1. Compare search rates. (b) Compare hit rates. (c) Report absolute and relative effects. (d) Explain why these descriptive comparisons do not, by themselves, identify a causal mechanism.

Problem 5

Suppose 15.9% of first-time college enrollees nationally are first-generation students. At one university, 1,362 of 6,000 new students were first-generation students. Test the university’s claim and report an interval estimate.

Problem 6

Using the YRBSS data and its codebook, examine the association between drinking and driving and texting and driving. Account for the survey design if the required design variables are available. Report weighted proportions, a design-adjusted test, and an effect-size summary.

Problem 7

Using GSS data, test whether educational attainment is associated with confidence in the scientific community. Distinguish an unordered omnibus association from a prespecified ordered trend, and account for the survey design.

Problem 8

Using BRFSS data, examine how body-mass-index category varies with education and income. Use the codebook to identify missing values and survey-design variables. Report weighted conditional percentages, appropriate design-adjusted tests, and clear plots.

Problem 9

A program records whether each of 100 participants supports a policy before and after an informational session. The paired table is:

After: Support After: Oppose
Before: Support 30 6
Before: Oppose 18 46

Choose and conduct the appropriate test. Explain why an independent two-proportion test is inappropriate.

Problem 10

Success counts for four ordered exposure groups are 12/100, 20/100, 31/100, and 43/100. Test the prespecified hypothesis of an increasing trend. Then explain what the trend test would fail to reveal if the true pattern were U-shaped.

Problem 11

A treatment-control comparison is reported separately for younger and older adults. Explain how you would decide whether to report a CMH common odds ratio, stratum-specific odds ratios, or a regression model with an interaction.

Problem 12

Researchers want to show that two delivery methods have completion rates differing by no more than 0.05. Explain why a nonsignificant test of \(H_0:p_1=p_2\) is insufficient. State the equivalence hypotheses and describe the confidence-interval decision rule.

Click here to see the answers

1. \(\hat p=91/220=0.4136\). An exact upper-tail test against \(p_0=0.14\) gives \(p<0.0001\). The observed cohort proportion is higher than the proposed benchmark. This does not establish that filming exposure caused cancer: the comparison lacks a contemporaneous comparable control group, and age, smoking, selection, follow-up, diagnosis, and the suitability of the 14% benchmark all matter.

2. \(\hat p=6052/12028=0.5031\). An exact two-sided test of \(p=0.5\) gives \(p=0.4941\), with a 95% exact interval of approximately \((0.4941,0.5121)\). The data do not support a systematic before-versus-after imbalance. They also cannot directly test whether particular individuals postponed death.

3. The before-Christmas proportions are \(0.5105\) for men and \(0.4948\) for women. The estimated difference is \(0.0157\), with a 95% interval of approximately \((-0.0021,0.0336)\); \(p=0.0843\). At \(\alpha=0.05\), the data do not provide sufficient evidence of a sex difference. This is not proof that the proportions are identical.

4. Minority drivers were searched at a higher observed rate but searches of minority drivers had a lower observed hit rate. The search-rate RD is about \(0.0270\) and the risk ratio is about \(2.1493\). The hit-rate RD is about \(-0.0688\) and the risk ratio is about \(0.8585\). These are important disparities, but causal conclusions require information about driving behavior, location, officer assignment, stop thresholds, policy, and other possible confounders. Infra-marginality also limits a simple hit-rate interpretation.

5. \(\hat p=1362/6000=0.2270\). An exact two-sided test against 0.159 gives \(p<0.0001\), and the 95% exact interval is approximately \((0.2164,0.2378)\). The university proportion is higher than the benchmark by \(0.0680\).

6. Recode missing and refused responses using the codebook. If design variables are available, create a survey design object, estimate weighted conditional proportions, and use a Rao–Scott test. An ordinary Pearson test answers a simple-random-sample question and generally understates uncertainty for clustered survey data.

7. Use a design-adjusted omnibus test for general association. Use an ordered trend test only if category scores and a monotonic hypothesis are justified in advance. Because GSS data use a complex design, report weighted percentages and design-based uncertainty.

8. Treat education, income, and BMI codes according to the BRFSS codebook, including special missing values. Use weighted stacked-percentage or dot-and-interval plots and Rao–Scott tests. If an ordered trend is of interest, state how categories are scored and do not assume an omnibus association is monotonic.

9. Use McNemar’s test because the measurements are paired. Only the discordant cells, 6 and 18, inform change. Without a continuity correction, \(\chi^2=6.0000\) and \(p=0.0143\). An independent test would incorrectly treat the 200 measurements as if they came from unrelated people.

10. Use a Cochran–Armitage trend test with the prespecified ordering. The increasing observed proportions support an increasing trend. The test targets a monotonic linear-score component; a U-shaped relationship could have little net trend even when the groups differ strongly, so inspect a plot and consider an omnibus test too.

11. First compute and plot stratum-specific effects. A common CMH odds ratio is reasonable when the stratum-specific odds ratios are sufficiently similar and adjustment for the stratifier answers the question. Important heterogeneity suggests effect modification; report stratum-specific effects or fit a model with an interaction. Also consider sparse cells and whether additional confounders require regression.

12. Failure to reject equality may simply reflect low power. Let \(\Delta=0.05\). Equivalence uses \(H_0:p_1-p_2\le-0.05\) or \(p_1-p_2\ge0.05\) against \(H_A:-0.05<p_1-p_2<0.05\). Conclude equivalence only if the appropriate confidence interval lies wholly inside \((-0.05,0.05)\).

Show optional R code
# Problems 1, 2, and 5
binom.test(91, 220, p = 0.14, alternative = "greater")
binom.test(6052, 12028, p = 0.50)
binom.test(1362, 6000, p = 0.159)

# Problem 3
prop.test(c(3192, 2858), c(6252, 5776), correct = FALSE)

# Problem 4: searches among stops
prop.test(c(3533, 3759), c(69883, 159808), correct = FALSE)
c(3533 / 69883, 3759 / 159808)
(3533 / 69883) - (3759 / 159808)
(3533 / 69883) / (3759 / 159808)

# Problem 4: hits among searches
prop.test(c(1475, 1828), c(3533, 3759), correct = FALSE)
c(1475 / 3533, 1828 / 3759)
(1475 / 3533) - (1828 / 3759)
(1475 / 3533) / (1828 / 3759)

# Problem 9
paired <- matrix(c(30, 6, 18, 46), nrow = 2, byrow = TRUE)
mcnemar.test(paired, correct = FALSE)
binom.test(6, 24, p = 0.5)

# Problem 10
trend <- matrix(c(12, 88, 20, 80, 31, 69, 43, 57),
                nrow = 4, byrow = TRUE)
DescTools::CochranArmitageTest(trend)
chisq.test(trend)

# Complex-survey template for Problems 6--8
library(survey)
des <- svydesign(ids = ~psu, strata = ~stratum, weights = ~weight,
                 nest = TRUE, data = dat)
svyby(~I(outcome == "Yes"), ~group, des, svymean, na.rm = TRUE)
svychisq(~outcome + group, des, statistic = "F")

# Problem 11: stratified 2 x 2 tables
mantelhaen.test(tab_2_by_2_by_stratum)