```{r setup, include = FALSE, message = FALSE, warning = FALSE}
knitr::opts_chunk$set(echo = TRUE, eval = TRUE)

library(ggplot2)
library(gridExtra)
library(knitr)

```

# Chapter 10: Statistical Inferences About Two Populations

## 10.0 Overview & Selecting the Appropriate Test


* **Learning Objectives:**

  1. Test hypotheses and develop confidence intervals about the difference in two means with known population variances using the $z$ statistic.
  2. Test hypotheses and develop confidence intervals about the difference in two means of independent samples with unknown population variances using the $t$ test.
  3. Test hypotheses and develop confidence intervals about the difference in two dependent (related) populations.
  4. Test hypotheses and develop confidence intervals about the difference in two population proportions.
  5. Test hypotheses about the difference in two population variances using the $F$ distribution.

* **Transition from Single-Sample to Two-Sample Inference:** Chapter 9 focused on one-sample tests: comparing a single sample parameter against an established or hypothesized population benchmark. Chapter 10 extends this inferential framework to structure tests comparing two (2) samples, evaluating whether the observed samples come from the same underlying population or different populations (e.g., *Are two brands of toothpaste equally effective? Do two brands of tires wear differently? Does aluminum produced under two different temperatures have the same tensile strength?*).

* **Parametric Computations vs. Programmatic R Functions:** Demonstration problems presented with summary parameters (sample means, known standard deviations) are evaluated formulaically. When provided with raw observational data, we utilize R's native statistical testing functions (`stats::t.test()`, `stats::var.test()`, and `stats::prop.test()`).

* **Four Selection Criteria:**

  + **Parameter Under Study:** Difference between two means ($\mu_1 - \mu_2$), difference between two proportions ($p_1 - p_2$), or ratio of two variances ($\sigma_1^2 / \sigma_2^2$).
  + **Sampling Structure:** Independent random samples vs. related / matched-pairs samples.
  + **Variance Availability:** Population variances known ($\sigma_1^2, \sigma_2^2$) vs. unknown ($s_1^2, s_2^2$).
  + **Variance Homogeneity:** When population variances are unknown, whether equal variances can be assumed ($\sigma_1^2 = \sigma_2^2$) or must be treated as unequal ($\sigma_1^2 \ne \sigma_2^2$).

---

## 10.1 Inferences About the Difference in Two Means: Independent Samples ($\sigma_1, \sigma_2$ Known)

* **Assumptions:**

  + **Independent Random Samples:** Data drawn randomly and independently from two distinct populations.
  + **Known Variances:** Both population standard deviations ($\sigma_1, \sigma_2$) are established from historical records, accounting audits, or engineering specifications.
  + **Normality / Sample Size:** Populations are normally distributed or both sample sizes are sufficiently large ($n_1 \ge 30, n_2 \ge 30$) under the Central Limit Theorem.

* **Hypothesis Testing:**

  + **Null Hypothesis:** $H_0: \mu_1 - \mu_2 = D_0$ (frequently $D_0 = 0$).
  + **Test Statistic ($z$):**

$$z = \frac{(\bar{x}_1 - \bar{x}_2) - D_0}{\sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}}$$

* **Confidence Interval for $(\mu_1 - \mu_2)$:**

$$(\bar{x}_1 - \bar{x}_2) \pm z_{\alpha/2} \sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}$$

* **Slide Examples from Ken Black (9th Edition):**
  + **Example 1: Hypothesis Test on Annual Manager Wages:** Comparing annual salaries of advertising managers (Population 1: $n_1 = 32$, $\bar{x}_1 = \$70.700\text{k}$, known $\sigma_1 = 16.253$) versus auditing managers (Population 2: $n_2 = 34$, $\bar{x}_2 = \$62.187\text{k}$, known $\sigma_2 = 12.900$) at $\alpha = 0.05$ ($z_{\text{crit}} = \pm 1.96$).
    $$z = \frac{(70.700 - 62.187) - 0}{\sqrt{\frac{16.253^2}{32} + \frac{12.900^2}{34}}} = \frac{8.513}{3.626} = 2.35 > 1.96 \implies \text{Reject } H_0 \; (p = 0.0189)$$
    Corresponding 95% Confidence Interval: $8.513 \pm 1.96(3.626) = [1.41, 15.63]$ thousand dollars. Because 0 is not in the interval, $H_0$ is rejected.
  + **Example 2: Confidence Interval on Grocery Coupon Savings:** Estimating weekly coupon savings for middle-income shoppers ($n_1 = 60, \bar{x}_1 = \$5.84, \sigma_1 = \$1.41$) vs. low-income shoppers ($n_2 = 80, \bar{x}_2 = \$2.67, \sigma_2 = \$0.54$) at 98% confidence ($z_{0.01} = 2.33$):
    $$(5.84 - 2.67) \pm 2.33 \sqrt{\frac{1.41^2}{60} + \frac{0.54^2}{80}} = 3.17 \pm 2.33(0.1918) = [\$2.72, \$3.62]$$
  + **Software Note:** While Excel includes this procedure in its Data Analysis Toolpak (`z-Test: Two Sample for Means`), Minitab does not have a native two-sample $z$-test command.

```{r}
two_sample_z_test <- function(x1_bar, x2_bar, n1, n2, sigma1, sigma2, D0 = 0, alpha = 0.05) {
  se <- sqrt((sigma1^2 / n1) + (sigma2^2 / n2))
  z_stat <- ((x1_bar - x2_bar) - D0) / se
  p_val <- 2 * (1 - pnorm(abs(z_stat)))
  ci <- c((x1_bar - x2_bar) - qnorm(1 - alpha / 2) * se,
          (x1_bar - x2_bar) + qnorm(1 - alpha / 2) * se)
  data.frame(
    Difference = round(x1_bar - x2_bar, 4),
    Std_Error = round(se, 4),
    z_Statistic = round(z_stat, 4),
    p_Value = round(p_val, 4),
    CI_Lower = round(ci[1], 4),
    CI_Upper = round(ci[2], 4)
  )
}

wage_test <- two_sample_z_test(x1_bar = 70.700, x2_bar = 62.187, n1 = 32, n2 = 34, sigma1 = 16.253, sigma2 = 12.900, alpha = 0.05)
print(wage_test)

coupon_ci <- two_sample_z_test(x1_bar = 5.84, x2_bar = 2.67, n1 = 60, n2 = 80, sigma1 = 1.41, sigma2 = 0.54, alpha = 0.02)
print(coupon_ci[, c("Difference", "Std_Error", "CI_Lower", "CI_Upper")])
```

---

## 10.2 Inferences About the Difference in Two Means: Independent Samples ($\sigma_1, \sigma_2$ Unknown)

When population standard deviations are unknown, sample standard deviations ($s_1, s_2$) are used, requiring the Student's $t$-distribution.

### Case A: Equal Variances Assumed ($\sigma_1^2 = \sigma_2^2$) — Pooled-Variance $t$-Test

* **Pooled Sample Variance ($s_p^2$):** Weighted average of individual sample variances:

$$s_p^2 = \frac{(n_1 - 1)s_1^2 + (n_2 - 1)s_2^2}{n_1 + n_2 - 2}$$
```{r}
n1 <- 35
x1_bar <- 19.4
s1 <- 1.4
n2 <- 40
x2_bar <- 15.1
s2 <- 1.3
df <- n1 + n2 - 2

sp2 <- ((n1 - 1) * s1^2 + (n2 - 1) * s2^2) / df
se <- sqrt(sp2 * (1 / n1 + 1 / n2))
t_crit <- qt(0.975, df = df)
t_stat_pooled <- ((x1_bar - x2_bar) - 0) / se

ci <- (x1_bar - x2_bar) + c(-1, 1) * t_crit * se
print(sprintf("Pooled s_p^2 = %.4f | t = %.4f (df = %d) | 95%% CI: [%.4f, %.4f]",
              sp2, t_stat_pooled, df, ci[1], ci[2]))
```


* **Test Statistic ($t$):**

$$t = \frac{(\bar{x}_1 - \bar{x}_2) - D_0}{\sqrt{s_p^2 \left(\frac{1}{n_1} + \frac{1}{n_2}\right)}} \quad \text{with } df = n_1 + n_2 - 2$$

* **Confidence Interval:**

$$(\bar{x}_1 - \bar{x}_2) \pm t_{\alpha/2, df} \sqrt{s_p^2 \left(\frac{1}{n_1} + \frac{1}{n_2}\right)}$$

### Case B: Unequal Variances ($\sigma_1^2 \ne \sigma_2^2$) — Welch's Satterthwaite $t$-Test

* **Test Statistic ($t$):**

$$t = \frac{(\bar{x}_1 - \bar{x}_2) - D_0}{\sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}}$$

* **Degrees of Freedom ($df$):** Computed using the Welch–Satterthwaite approximation:

$$df = \frac{\left(\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}\right)^2}{\frac{(s_1^2 / n_1)^2}{n_1 - 1} + \frac{(s_2^2 / n_2)^2}{n_2 - 1}}$$

* **Slide Examples from Ken Black (9th Edition):**
  + **Example 1: Hernandez Manufacturing Company Training Program (Table 10.2):** Management tests knowledge scores for new employees assigned to traditional 3-day lecture training (Method A: $n_1 = 15$) vs. an experimental 2-day DVD program (Method B: $n_2 = 12$) at $\alpha = 0.05$ ($df = 25, t_{\text{crit}} = \pm 2.060$).
    $$\bar{x}_1 = 47.73, \; s_1^2 = 19.495 \quad \text{vs.} \quad \bar{x}_2 = 56.50, \; s_2^2 = 18.273$$
    $$s_p^2 = \frac{14(19.495) + 11(18.273)}{25} = 18.957 \implies t = \frac{47.73 - 56.50}{\sqrt{18.957(1/15 + 1/12)}} = -5.20$$
    Because $-5.20 < -2.060$, reject $H_0$. Method B scores are $>8$ points higher, justifying adoption of the shorter training curriculum.
  + **Example 2: Conscientiousness Personality Study (Table 10.3):** Comparing conscientiousness between phone survey respondents ($n_1 = 9, \bar{x}_1 = 37.09, s_1 = 1.727$) and average Americans ($n_2 = 10, \bar{x}_2 = 34.99, s_2 = 1.253$).
    With $df = 17$ and $t_{0.005, 17} = 2.898$, the 99% CI is $2.10 \pm 2.898(0.6868) = [0.11, 4.09]$.

```{r}
method_a <- c(56, 50, 52, 44, 52, 47, 47, 53, 45, 48, 42, 51, 42, 43, 44)
method_b <- c(59, 54, 55, 65, 52, 57, 64, 53, 53, 56, 53, 57)

pooled_t <- t.test(method_a, method_b, var.equal = TRUE, alternative = "two.sided")
print(pooled_t)

welch_t <- t.test(method_a, method_b, var.equal = FALSE, alternative = "two.sided")
print(welch_t)

na <- length(method_a)
nb <- length(method_b)
va <- var(method_a)
vb <- var(method_b)
df_welch_manual <- (va / na + vb / nb)^2 / (((va / na)^2 / (na - 1)) + ((vb / nb)^2 / (nb - 1)))
t_welch_manual <- (mean(method_a) - mean(method_b)) / sqrt(va / na + vb / nb)
print(sprintf("Welch manual -> t = %.4f | df = %.4f", t_welch_manual, df_welch_manual))

n_c1 <- 9
xbar_c1 <- 37.09
s_c1 <- 1.727
n_c2 <- 10
xbar_c2 <- 34.99
s_c2 <- 1.253
df_c <- n_c1 + n_c2 - 2
sp2_c <- ((n_c1 - 1) * s_c1^2 + (n_c2 - 1) * s_c2^2) / df_c
se_c <- sqrt(sp2_c * (1 / n_c1 + 1 / n_c2))
ci_c <- (xbar_c1 - xbar_c2) + c(-1, 1) * qt(0.995, df = df_c) * se_c
print(sprintf("Conscientiousness 99%% CI (df = %d): [%.2f, %.2f]", df_c, ci_c[1], ci_c[2]))
```

---

## 10.3 Inferences for Two Related Populations (Matched-Pairs $t$-Test)

* **Context & Requirements:** Matched pairs, pre-test/post-test designs, repeated measures, or naturally paired subjects (e.g., twins, siblings, spouses). Samples must be dependent, and sample sizes must be strictly identical ($n_1 = n_2 = n$).

* **Concept:** Eliminates extraneous subject-to-subject variability by converting paired observations into a single sample of differences:

$$d_i = x_{1i} - x_{2i}$$

* **Sample Metrics of Differences:**

  + **Mean Difference ($\bar{d}$):** $\bar{d} = \frac{\sum d_i}{n}$
  + **Standard Deviation of Differences ($s_d$):** $s_d = \sqrt{\frac{\sum (d_i - \bar{d})^2}{n - 1}}$

* **Hypothesis Testing:**

  + **Null Hypothesis:** $H_0: \mu_d = D_0$ (frequently directional: $H_0: \mu_d \le 0$ or two-tailed $H_0: \mu_d = 0$).
  + **Test Statistic ($t$):**

$$t = \frac{\bar{d} - D_0}{\frac{s_d}{\sqrt{n}}} \quad \text{with } df = n - 1$$

* **Confidence Interval for Paired Differences:**

$$\bar{d} \pm t_{\alpha/2, n-1} \left(\frac{s_d}{\sqrt{n}}\right)$$

* **Slide Examples from Ken Black (9th Edition):**
  + **Example 1: Common Stock P/E Ratios Across Two Years (Tables 10.5 & 10.6):** A researcher samples $n = 9$ firms from the *Handbook of Common Stocks* to test whether P/E ratios changed significantly between Year 1 and Year 2 at $\alpha = 0.01$ ($df = 8, t_{\text{crit}} = \pm 3.355$).
    $$\bar{d} = -5.033, \quad s_d = 21.599 \implies t = \frac{-5.033 - 0}{21.599 / \sqrt{9}} = -0.70$$
    Since $-3.355 < -0.70 < 3.355$, fail to reject $H_0$ ($p = 0.504$). There is insufficient evidence of a shift in P/E ratios.
  + **Example 2: Indianapolis New-House Sales Confidence Interval:** Estimating the annual difference in new-house sales per firm across 18 real estate agencies between May 2015 and May 2016 ($n = 18, \bar{d} = -3.389, s_d = 3.274$).
    With $df = 17$ and $t_{0.005, 17} = 2.898$, the 99% CI is $-3.389 \pm 2.898(0.7717) = [-5.625, -1.153]$ houses per firm.
  + **Demonstration Problem 10.5 (p. 341):** Testing consumer ratings before and after a video campaign ($n = 7, \alpha = 0.05$, directional test `alternative = "greater"`).

```{r}
year_1 <- c(8.9, 38.1, 43.0, 34.0, 34.5, 15.2, 20.3, 19.9, 61.9)
year_2 <- c(12.7, 45.4, 10.0, 27.2, 22.8, 24.1, 32.3, 40.1, 106.5)

diffs <- year_1 - year_2
d_bar <- mean(diffs)
s_d <- sd(diffs)
t_pe_manual <- d_bar / (s_d / sqrt(length(diffs)))
print(sprintf("P/E Paired Manual -> d_bar = %.3f | s_d = %.3f | t = %.4f", d_bar, s_d, t_pe_manual))

pe_test <- t.test(year_1, year_2, paired = TRUE, conf.level = 0.99)
print(pe_test)

n_indy <- 18
dbar_indy <- -3.389
sd_indy <- 3.274
ci_indy <- dbar_indy + c(-1, 1) * qt(0.995, df = n_indy - 1) * (sd_indy / sqrt(n_indy))
print(sprintf("Indianapolis New-House Sales 99%% CI (df = %d): [%.3f, %.3f]",
              n_indy - 1, ci_indy[1], ci_indy[2]))

before <- c(32, 11, 21, 17, 30, 38, 14)
after <- c(39, 15, 35, 13, 41, 39, 22)

paired_test <- t.test(x = after, y = before, paired = TRUE, alternative = "greater")
print(paired_test)
```

---

## 10.4 Statistical Inferences About Two Population Proportions ($p_1 - p_2$)

* **Assumptions:** Independent random samples with adequate sample sizes: $n_1 p_1 \ge 5$, $n_1(1-p_1) \ge 5$, $n_2 p_2 \ge 5$, and $n_2(1-p_2) \ge 5$.

* **Hypothesis Testing:**

  + Under $H_0: p_1 - p_2 = 0$, both groups share a common population proportion ($p$). Compute the **pooled sample proportion ($\bar{p}$)**:

$$\bar{p} = \frac{x_1 + x_2}{n_1 + n_2} = \frac{n_1 \hat{p}_1 + n_2 \hat{p}_2}{n_1 + n_2}, \quad \bar{q} = 1 - \bar{p}$$

  + **Test Statistic ($z$):**

$$z = \frac{(\hat{p}_1 - \hat{p}_2) - 0}{\sqrt{\bar{p}\bar{q}\left(\frac{1}{n_1} + \frac{1}{n_2}\right)}}$$

* **Confidence Interval for $(p_1 - p_2)$:**

  + Uses unpooled individual sample proportions:

$$(\hat{p}_1 - \hat{p}_2) \pm z_{\alpha/2} \sqrt{\frac{\hat{p}_1(1 - \hat{p}_1)}{n_1} + \frac{\hat{p}_2(1 - \hat{p}_2)}{n_2}}$$

* **Slide Examples from Ken Black (9th Edition):**
  + **Example 1: Consumer vs. CEO Ethical Perceptions:** Testing whether a significantly higher proportion of consumers than CEOs believe fear of getting caught or losing one's job strongly influences ethical behavior.
    Consumers ($n_1 = 755, \hat{p}_1 = 0.57$) vs. CEOs ($n_2 = 616, \hat{p}_2 = 0.50$) at $\alpha = 0.10$ ($z_{\text{crit}} = 1.28$).
    $$\bar{p} = \frac{755(0.57) + 616(0.50)}{755 + 616} = 0.539 \implies z = \frac{0.57 - 0.50}{\sqrt{(0.539)(0.461)(1/755 + 1/616)}} = 2.59$$
    Because $z = 2.59 > 1.28$ ($p = 0.0048 < 0.10$), reject $H_0$. Consumers are significantly more likely to cite fear as an ethical driver.
  + **Example 2: Supermarket Shopper Demographics:** Estimating the difference in the proportion of male shoppers between morning ($n_1 = 400, x_1 = 48 \implies \hat{p}_1 = 0.12$) and after-5 p.m. ($n_2 = 480, x_2 = 187 \implies \hat{p}_2 \approx 0.39$) at 98% confidence ($z_{0.01} = 2.33$):
    $$(0.12 - 0.39) \pm 2.33 \sqrt{\frac{0.12(0.88)}{400} + \frac{0.39(0.61)}{480}} = -0.27 \pm 0.064 = [-0.334, -0.206]$$

```{r}
eth_x <- c(round(755 * 0.57), round(616 * 0.50))
eth_n <- c(755, 616)
p1_eth <- eth_x[1] / eth_n[1]
p2_eth <- eth_x[2] / eth_n[2]
p_bar_eth <- sum(eth_x) / sum(eth_n)
z_eth_manual <- (p1_eth - p2_eth) / sqrt(p_bar_eth * (1 - p_bar_eth) * (1 / eth_n[1] + 1 / eth_n[2]))
prop_eth <- prop.test(x = eth_x, n = eth_n, alternative = "greater", correct = FALSE)
print(prop_eth)
print(sprintf("Pooled p_bar = %.3f | Manual z = %.4f", p_bar_eth, z_eth_manual))

shop_x <- c(48, 187)
shop_n <- c(400, 480)
p1_shop <- shop_x[1] / shop_n[1]
p2_shop <- shop_x[2] / shop_n[2]
se_shop <- sqrt(p1_shop * (1 - p1_shop) / shop_n[1] + p2_shop * (1 - p2_shop) / shop_n[2])
ci_shop_manual <- (p1_shop - p2_shop) + c(-1, 1) * qnorm(0.99) * se_shop
prop_shop <- prop.test(x = shop_x, n = shop_n, conf.level = 0.98, correct = FALSE)
print(prop_shop)
print(sprintf("Manual unpooled 98%% CI: [%.4f, %.4f]", ci_shop_manual[1], ci_shop_manual[2]))
```

---

## 10.5 Testing Hypotheses About Two Population Variances ($F$-Test)

* **Purpose & Applications:** Evaluates whether two populations have equal variance ($\sigma_1^2 = \sigma_2^2$), commonly used to evaluate relative risk in finance, to compare process consistency in manufacturing, or to test equal variance assumptions prior to pooling $t$-tests.

* **Distribution & Assumptions:**
  + **$F$-Distribution:** Defined by numerator degrees of freedom ($df_1 = \nu_1 = n_1 - 1$) and denominator degrees of freedom ($df_2 = \nu_2 = n_2 - 1$). Strictly positive and right-skewed.
  + **Strict Normality:** Highly sensitive to departures from normality; populations must be normally distributed.

* **Test Statistic ($F$):**

$$F = \frac{s_1^2}{s_2^2}$$

* **Slide Examples from Ken Black (9th Edition):**
  + **Example 1: Metal Sheet Thickness Consistency (Two Machines):** Machine 1 ($n_1 = 10, s_1^2 = 0.11378$) and Machine 2 ($n_2 = 12, s_2^2 = 0.02023$) are compared for 22 mm sheet thickness consistency at $\alpha = 0.05$ ($df_1 = 9, df_2 = 11$).
    Upper critical value: $F_{0.025, 9, 11} = 3.59$. Lower critical value: $F_{0.975, 9, 11} \approx 0.28$.
    $$F = \frac{0.11378}{0.02023} = 5.62 > 3.59 \implies \text{Reject } H_0$$
    Machine 1 produces significantly greater variability; operators should investigate Machine 1 for root cause maintenance.
  + **Demonstration Problem 10.7 (p. 359):** Runzheimer International study on basic goods expenditures across the US vs. Manhattan ($F = 8.087, p = 0.0072$).

```{r}
s1_sq <- 0.11378
s2_sq <- 0.02023
f_stat_mach <- s1_sq / s2_sq
p_val_mach <- 2 * pf(f_stat_mach, df1 = 9, df2 = 11, lower.tail = FALSE)
print(sprintf("Machine Thickness F-Ratio: %.2f | p-value: %.4f", f_stat_mach, p_val_mach))

across_us <- c(18500, 19250, 16400, 20750, 17600, 21800, 14750)
manhattan <- c(23000, 21900, 22500, 21200, 21000, 22800, 23100, 21300)

var_test_result <- var.test(x = across_us, y = manhattan, ratio = 1, alternative = "greater", conf.level = 0.99)
print(var_test_result)
```

---

## Quick Reference Summary Table

| Parameter Compared | Test Name | Key Assumptions | Test Statistic | Distribution | R Function |
| :--- | :--- | :--- | :--- | :--- | :--- |
| **Means ($\mu_1 - \mu_2$)** | 2-Sample $z$-Test | Independent; $\sigma_1, \sigma_2$ known; normal or $n_1, n_2 \ge 30$ | $z = \frac{(\bar{x}_1 - \bar{x}_2) - D_0}{\sqrt{\frac{\sigma_1^2}{n_1} + \frac{\sigma_2^2}{n_2}}}$ | Standard Normal ($z$) | `two_sample_z_test()` |
| **Means ($\mu_1 - \mu_2$)** | Pooled 2-Sample $t$-Test | Independent; $\sigma_1^2 = \sigma_2^2$ unknown; populations normal | $t = \frac{(\bar{x}_1 - \bar{x}_2) - D_0}{\sqrt{s_p^2(1/n_1 + 1/n_2)}}$ | Student's $t$ ($df = n_1 + n_2 - 2$) | `t.test(..., var.equal = TRUE)` |
| **Means ($\mu_1 - \mu_2$)** | Welch's Unpooled $t$-Test | Independent; $\sigma_1^2 \ne \sigma_2^2$ unknown; populations normal | $t = \frac{(\bar{x}_1 - \bar{x}_2) - D_0}{\sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}}$ | Student's $t$ (Welch $df$) | `t.test(..., var.equal = FALSE)` |
| **Mean Diff ($\mu_d$)** | Paired $t$-Test | Related / matched pairs; differences normally distributed | $t = \frac{\bar{d} - D_0}{s_d / \sqrt{n}}$ | Student's $t$ ($df = n - 1$) | `t.test(..., paired = TRUE)` |
| **Proportions ($p_1 - p_2$)** | 2-Proportion $z$-Test | Independent; $n_i p_i \ge 5$ and $n_i (1-p_i) \ge 5$ | $z = \frac{(\hat{p}_1 - \hat{p}_2)}{\sqrt{\bar{p}\bar{q}(1/n_1 + 1/n_2)}}$ | Standard Normal ($z$) | `prop.test(..., correct = FALSE)` |
| **Variances ($\sigma_1^2 / \sigma_2^2$)** | Two-Variance $F$-Test | Independent; both populations strictly normal | $F = s_1^2 / s_2^2$ | $F$ ($df_1 = n_1 - 1, df_2 = n_2 - 1$) | `var.test()` |

---

## Ethical Considerations in Comparative Inferential Analysis

* **Validating Distributional Assumptions:** Verifying that data satisfy underlying distributional requirements (especially strict normality for the $F$-test and adequate sample sizes for proportion approximations) before interpreting test statistics.
* **Pre-Specifying Hypotheses:** Defining the null and alternative hypotheses, directional status (one-tailed vs. two-tailed), and significance level ($\alpha$) prior to data inspection to prevent "p-hacking" or post-hoc justification.
* **Reporting Effect Sizes & Confidence Intervals:** Presenting confidence intervals alongside $p$-values to communicate the practical magnitude and uncertainty of observed differences, avoiding over-reliance on bare statistical significance.
* **Preserving Study Design Integrity:** Accurately distinguishing between independent and paired designs. Treating paired data as independent artificially alters the variance estimate and degrees of freedom, undermining inferential validity.

---

## Navigation & Practice {-}

* **Practice & Exercises:** [Week 7 Practice & Exercises (Jupyter Notebook)](https://colab.research.google.com/github/telpirion/CumulativeStudyGuide/blob/main/Week7.ipynb)
* **Next Lesson:** [Week 8 Study Guide — Analysis of Variance & Simple Linear Regression](Week8.html)


