Hypothesis Testing with Two Groups

Chapter 10: Hypothesis Testing with Two Groups

10.1 Getting Ready

  • This chapter focuses on hypothesis testing for comparing means and proportions between population subgroups.

  • Data Set: Load the anes20.rda data set in R.

  • Required R Libraries: Ensure the following libraries are attached:

    • DescTools

    • Hmisc

    • gplots

    • descr

    • effectsize

10.2 Testing Hypotheses about Two Means

  • Hypothesis Testing Goal: Compare differences between two sample means rather than testing hypotheses about the overall population support.

  • Example: Exploring support differences across demographics like sex, race, and location impacts.

  • Gender Gap Analysis: Focus on how men and women differ in political attitudes, illustrated with the feeling thermometer rating for feminists.

    • Feeling Thermometer Rating: A scale from 0 (negative feelings) to 100 (positive feelings).

    • Expectations: Women are expected to rate feminists higher due to the intrinsic connection of feminism to women's rights.

10.2.1 Generating Subgroup Means

  • Use the aggregate function to examine mean levels of support:

    • Function Format: aggregate(dependent, by=list(independent), FUN=stat_you_want).

    • Implementation for Gender Gap:
      r anes20$Rsex <- factor(anes20$V201600) levels(anes20$Rsex) <- c("Male", "Female") anes20$femFT <- anes20$V202160 agg_femFT <- aggregate(anes20$femFT, by=list(anes20$Rsex), FUN=(mean), na.rm=TRUE)

    • The resulting output shows:

    • Male mean rating: 54.54

    • Female mean rating: 62.55

    • Conclusion: Women view feminists more positively than men by approximately 8 points.

10.3 Hypothesis Testing with Two Means

  • Null Hypothesis (H0): There is no relationship; population group means are equal: H_0: ext{μ}_1 = ext{μ}_2.

  • Alternative Hypotheses (H1):

    • Two-tailed: H_1: ext{μ}_1
      eq ext{μ}_2.

    • One-tailed (negative): H_1: ext{μ}_1 < ext{μ}_2.

    • One-tailed (positive): H_1: ext{μ}_1 > ext{μ}_2.

  • The task is to determine if the observed subgroup means differ significantly, not merely due to random variation.

10.3.1 A Theoretical Example

  • Logic of Hypothesis Testing: If H0 is true (no difference), we assess the likelihood of obtaining a sample difference

  • Transforming Differences: Convert sample difference into a t-score. For a sample:

    • t-score formula:
      t = \frac{\bar{x}1 - \bar{x}_2 - (\mu_1 - \mu_2)}{S{\bar{x}_1 - \bar{x}_2}}

  • As the sample size increases, the t-distribution resembles the z-distribution, with critical values transitioning from 1.645 for one-tailed tests to 1.96 for two-tailed tests based on degrees of freedom.

10.3.2 Empirical Example Application

  • Applying the earlier findings on the feminist feeling thermometer for gender difference:

  • Null Hypothesis: H_0: \mu_W = \mu_M

  • Expected Direction: H_1: \mu_W > \mu_M.

  • t-score Calculation:

    • t-score formula adapted:
      t = \frac{\bar{x}W - \bar{x}_M}{S{\bar{x}_1 - \bar{x}_2}}

    • For example calculations using R:
      r t = -12.89 # example t-score calculated

  • Critical Value Comparison:

    • If the absolute t exceeds the critical value (-1.645), reject the null hypothesis.

  • R Command for T-Test:

    • t.test(anes20$femFT ~ anes20$Rsex) produces:

    • t = -13, df = 7111, p-value < 2e-16.

10.3.3 Calculating Effect Size

  • Importance of assessing practical significance vs statistical significance; introduce Cohen’s D as a measure of effect size:

    • D = \frac{\bar{x}1 - \bar{x}_2}{S{pooled}}

    • Comparison yields:

    • Feminist Feeling Thermometer: D = -0.2993

    • Big Business: D = 0.0494.

  • Effect Size Interpretation:

    • A small effect size for feminist feelings indicates limited practical implications in comparison to larger differences seen in that dimension vs. attitudes towards big business.

10.4 Difference in Proportions

  • Methodology for examining proportions between two groups:

  • Exploratory example on abortion attitudes, particularly respondents viewing abortion as illegal:

    • Null Hypothesis: H_0: \text{proportion of males}
      eq \text{proportion of females}.

  • Sample Statistics: Proportion of males (0.1041) vs females (0.1074) suggests trivial differences; perform hypothesis testing on these proportions with a test similar to two means comparing.

  • Findings: Hypothesis test indicates no significant difference leading to a failure to reject H0.

10.5 Plotting Mean Differences

  • Comparisons can be visually represented through various plots:

    • Use Boxplots for distributions and Barplots for mean comparisons.

  • R Syntax for Plots:

    • barplot() and plotmeans() to visualize data clearly and aptly, labeling x/y axes accordingly.

  • Implications of Scale: Important to understand scaling issues, particularly when interpreting results from graphs and making judgments on statistical significance.

10.6 What’s Next?

  • Move from comparing two groups to more complex analysis such as ANOVA in the next chapter for scenarios with multiple subgroups, expanding the model utilized in this chapter.

10.7 Exercises

  • Conceptual Questions: Examine hypotheses on expenditures based on class status.

  • Statistical Application Problems: Identify educational attainment vs. COVID-19 cases using practical R commands and analyses to illustrate learning.