Module 4 Review

Putting It All Together

  • Relationships between categorical variables.

  • One-sample proportion.

  • Two-sample proportions.

  • Test for goodness-of-fit.

    • Uniform distribution.
    • Historical distribution.
  • Test for Independence.

Example 1: One-Sample Proportions

  • Rudolph surveys elves in the North Pole Workshop to see if they think his nose is “bright enough for foggy nights.” He believes at least 90% of elves think so, and he wants to test that claim.
rudolph %>% n_pct(nose_bright)
 nose_bright     n (pct)
          No  15 (12.5%)
         Yes 105 (87.5%)

Example 1: One-Sample Proportions

  • Rudolph surveys elves in the North Pole Workshop to see if they think his nose is “bright enough for foggy nights.” He believes at least 80% of elves think so, and he wants to test that claim.

  • Let’s first look at the 95% confidence interval for \pi, the proportion of elves who think Rudolph’s nose is bright enough.

rudolph %>% one_prop_CI(binary = nose_bright,
                        event = "Yes")
p̂= 0.875 (105/120)
95% confidence interval for π: (0.804, 0.9228)
  • Thus, the 95% CI for \pi, the true proportion of elves who think Rudolph’s nose is bright enough for foggy nights, is (0.80, 0.92).

Example 1: One-Sample Proportions

  • Rudolph surveys elves in the North Pole Workshop to see if they think his nose is “bright enough for foggy nights.” He believes at least 90% of elves think so, and he wants to test that claim.

  • Now, let’s test the hypothesis – do at least 85% of elves think Rudolph’s nose is bright enough? Test at the \alpha=0.05 level.

rudolph %>% one_prop_HT(binary = nose_bright,
                        event = "Yes",
                        p = 0.8,
                        alternative = "greater")
One-sample z-test for the population proportion:
Null: H0: π ≤ 0.8
Alternative: H1: π > 0.8
Test statistic: z = 2.05
p-value: p = 0.020
Conclusion: Reject the null hypothesis (p = 0.02 < α = 0.05)

Example 1: One Sample Proportions

  • Hypotheses:
    • H_0: \ \pi \le 0.80
    • H_1: \ \pi > 0.80
  • Test Statistic and p-Value
    • z_0 = 2.05, p = 0.020
  • Rejection Region
    • Reject H_0 if p < \alpha; \alpha = 0.05
  • Conclusion and interpretation
    • Reject H_0 (0.02 < 0.05). There is sufficient evidence to suggest that at least 80% of elves believe Rudolph’s nose is bright enough for foggy nights.

Example 2: Two Sample Proportions

  • Rudolph proposes backup LED antlers for safety. He surveys female and male reindeer about whether they support the LED plan. Rudolph wants to test whether support is higher among female reindeer than male reindeer.
rudolph %>% n_pct(support_led, sex)
# A tibble: 2 × 3
  support_led    Female     Male      
  <chr>          <chr>      <chr>     
1 Do not support 9 (22.5%)  18 (36.0%)
2 Support        31 (77.5%) 32 (64.0%)

Example 2: Two Sample Proportions

  • Rudolph proposes backup LED antlers for safety. He surveys female and male reindeer about whether they support the LED plan. Rudolph wants to test whether support is higher among female reindeer than male reindeer.

  • Let’s find the 90% CI for \pi_{\text{F}}-\pi_{\text{M}}.

rudolph %>% two_prop_CI(binary = support_led,
                        grouping = sex,
                        event = "Support",
                        confidence = 0.90)
Sample proportion (Female): 0.775
Sample proportion (Male): 0.64
Point estimate for the difference in proportions (p̂[Female] − p̂[Male]): 0.135
90% confidence interval for π[Female] − π[Male]: (-0.0208, 0.2908)

Example 2: Two Sample Proportions

  • Rudolph proposes backup LED antlers for safety. He surveys female and male reindeer about whether they support the LED plan. Rudolph wants to test whether support is higher among female reindeer than male reindeer.

  • Let’s now determine if support is indeed higher among female reindeer. Test at the \alpha=0.10 level.

rudolph %>% two_prop_HT(binary = support_led,
                        grouping = sex,
                        event = "Support",
                        alternative = "greater",
                        alpha = 0.1)

Example 2: Two Sample Proportions

rudolph %>% two_prop_HT(binary = support_led,
                        grouping = sex,
                        event = "Support",
                        alternative = "greater",
                        alpha = 0.1)
Two-sample z-test for difference in proportions:

p̂[Female = 0.775 (31/40)
p̂[Male = 0.64 (32/50)
p̂[Female] − p̂[Male] = 0.135

Null: H₀: π[Female] − π[Male] ≤ 0
Alternative: H₁: π[Female] − π[Male] > 0
Test statistic: z = 1.43
p-value: p = 0.076
Conclusion: Reject the null hypothesis (p = 0.076 < α = 0.1)

Example 2: Two Sample Proportions

  • Hypotheses:
    • H_0: \ \pi_{\text{F}} \le \pi_{\text{M}}
    • H_1: \ \pi_{\text{F}} > \pi_{\text{M}}
  • Test Statistic and p-Value
    • z_0 = 1.43, p = 0.076
  • Rejection Region
    • Reject H_0 if p < \alpha; \alpha = 0.10
  • Conclusion and interpretation
    • Reject H_0 (0.07 < 0.10). There is sufficient evidence to suggest that support for LED antlers is higher among female reindeer than male reindeer.

Example 3: Goodness of Fit (Uniform)

  • In the North Pole Wrapping Department, Rudolph wonders whether children are equally likely to request each of six magical gift wrap colors: red, green, blue, yellow, pink, or gold.
rudolph %>% n_pct(wrap_color, rows = 6)
 wrap_color    n (pct)
       Blue 51 (17.0%)
       Gold 50 (16.7%)
      Green 43 (14.3%)
       Pink 47 (15.7%)
        Red 56 (18.7%)
     Yellow 53 (17.7%)

Example 3: Goodness of Fit (Uniform)

  • In the North Pole Wrapping Department, Rudolph wonders whether children are equally likely to request each of six magical gift wrap colors: red, green, blue, yellow, pink, or gold. Let’s test at the \alpha=0.05 level.
rudolph %>% goodness_of_fit(categorical = wrap_color,
                           alpha = 0.05)
Chi-square goodness-of-fit test:
Null: H₀: Observed frequencies match expected proportions
Alternative: H₁: Observed frequencies do not match expected proportions
Test statistic: χ²(5) = 2.08
p-value: p = 0.838
Conclusion: Fail to reject the null hypothesis (p = 0.838 ≥ α = 0.05)

Example 3: Goodness of Fit (Uniform)

  • Hypotheses:
    • H_0: \pi_{\text{R}} = pi_{\text{Gr}} = \pi_{\text{B}} = \pi_{\text{Y}} = \pi_{\text{P}} = \pi_{\text{Go}} = \frac{1}{6}
    • H_1: At least one \pi_i \ne \frac{1}{6}.
  • Test Statistic and p-Value
    • \chi^2_0 = 2.08, p = 0.838
  • Rejection Region
    • Reject H_0 if p < \alpha; \alpha = 0.05
  • Conclusion and interpretation
    • Reject H_0 (0.838 > 0.05). There is not sufficient evidence to suggest that the proportions of gift wrap color are unequal.

Example 4: Goodness of Fit (Historical Distribution)

  • Santa’s forecasting model predicts the distribution of toy requests:

    • Trains: 30%
    • Dolls: 25%
    • Teddy Bears: 20%
    • Games: 25%
  • Rudolph samples 400 letters to Santa and records the most requested toy per letter in order to determine if the observed distribution matches Santa’s forecast.

rudolph %>% n_pct(toy_request, rows = 4)
 toy_request     n (pct)
       Dolls 100 (25.0%)
       Games 130 (32.5%)
 Teddy Bears  83 (20.7%)
      Trains  87 (21.8%)

Example 4: Goodness of Fit (Historical Distribution)

  • Santa’s forecasting model predicts the distribution of toy requests:

    • Trains: 30%
    • Dolls: 25%
    • Teddy Bears: 20%
    • Games: 25%
  • Rudolph samples 400 letters to Santa and records the most requested toy per letter in order to determine if the observed distribution matches Santa’s forecast. Because we want to be super sure, we will test at the \alpha=0.01 level.

rudolph %>% goodness_of_fit(categorical = toy_request,
                           expected = c("Trains" = 0.30, 
                                        "Dolls" = 0.25, 
                                        "Teddy Bears" = 0.20, 
                                        "Games" = 0.25),
                           alpha = 0.01)

Example 4: Goodness of Fit (Historical Distribution)

rudolph %>% goodness_of_fit(categorical = toy_request,
                           expected = c("Trains" = 0.30, 
                                        "Dolls" = 0.25, 
                                        "Teddy Bears" = 0.20, 
                                        "Games" = 0.25),
                           alpha = 0.01)
Chi-square goodness-of-fit test:
Null: H₀: Observed frequencies match expected proportions
Alternative: H₁: Observed frequencies do not match expected proportions
Test statistic: χ²(3) = 18.19
p-value: p < 0.001
Conclusion: Reject the null hypothesis (p = < 0.001 < α = 0.01)

Example 4: Goodness of Fit (Historical Distribution)

  • Hypotheses:
    • H_0: The proportions do not differ from Santa’s expected distribution.
    • H_1: The proportions differ from Santa’s expected distribution.
  • Test Statistic and p-Value
    • \chi^2_0 = 18.19, p < 0.001
  • Rejection Region
    • Reject H_0 if p < \alpha; \alpha = 0.01
  • Conclusion and interpretation
    • Reject H_0 ((<0.001) < 0.10). There is sufficient evidence to suggest that the distribution of toy requests differs from Santa’s expected distribution.

Example 5: Test for Independence

  • Rudolph suspects that a reindeer’s team position (lead, middle, back) might be associated with which Misfit Toy they identify with most: Jack-in-the-Box, Elephant with Polka Dots, or Charlie-in-the-Box.

  • After surveying 120 reindeer, Rudolph wants to test if favorite Misfit Toy depends on team position.

rudolph %>% n_pct(misfit_toy, team)
# A tibble: 3 × 4
  misfit_toy               Lead       Middle     Back      
  <fct>                    <chr>      <chr>      <chr>     
1 Jack-in-the-Box          17 (60.7%) 21 (35.6%) 5 (15.2%) 
2 Elephant with Polka Dots 8 (28.6%)  22 (37.3%) 13 (39.4%)
3 Charlie-in-the-Box       3 (10.7%)  16 (27.1%) 15 (45.5%)

Example 5: Test for Independence

  • Rudolph suspects that a reindeer’s team position (lead, middle, back) might be associated with which Misfit Toy they identify with most: Jack-in-the-Box, Elephant with Polka Dots, or Charlie-in-the-Box.

  • After surveying 120 reindeer, Rudolph wants to test if favorite Misfit Toy depends on team position. Test at the \alpha=0.05 level.

rudolph %>% independence_test(var1 = misfit_toy,
                              var2 = team,
                              alpha = 0.05)
Chi-square test for independence:
Null: H₀: misfit_toy and team are independent
Alternative: H₁: misfit_toy and team depend on one another
Test statistic: χ²(4) = 15.85
p-value: p = 0.003
Conclusion: Reject the null hypothesis (p = 0.003 < α = 0.05)

Example 5: Test for Independence

  • Hypotheses:
    • H_0: A reindeer’s favorite misfit toy does not depend on team position.
    • H_1: A reindeer’s favorite misfit toy depends on team position.
  • Test Statistic and p-Value
    • \chi^2_0 = 15.85, p = 0.003
  • Rejection Region
    • Reject H_0 if p < \alpha; \alpha = 0.05
  • Conclusion and interpretation
    • Reject H_0 (0.003 < 0.05). There is sufficient evidence to suggest that a reindeer’s favorite misfit toy depends on team position.

Wrap Up

  • This module covers the basics of categorical analysis.

  • Key topics include:

    • One-sample proportion inference.
    • Two-sample proportion inference.
    • Chi-square tests for goodness-of-fit (uniform and historical).
    • Chi-square test for independence.
  • Note that we could extend what we know about regression (using continuous outcomes) to categorical outcomes.

    • i.e., we are not limited by the methods in this module.