Comparing Two Population Means

Comparing Two Population Means

Outline

  • Two populations
  • Comparing Two Means
    • Confidence Intervals
    • Hypothesis Tests
  • An experiment
  • What happens if the variances aren’t equal?

Overview

  • Previously, the focus was on a 'reference' value and tests around it.
  • Example: Testing if the body weight of the US adult population has changed over time.
    • Null Hypothesis (H0:µ=177H_0 : µ = 177 lbs)
    • Alternative Hypothesis (HA:µ177H_A : µ \neq 177 lbs)

Two Populations

  • Many questions involve comparing two different populations.
  • Notation: Xg,i is the ithi^{th} unit in the gthg^{th} group, where each group corresponds to a population with its own parameter μg\mu_g.

Null Hypothesis Examples

  • Comparing body weight of US adult population (group 1) to Canadian adult population (group 2).
    • H<em>0:µ</em>1=µ2H<em>0 : µ</em>1 = µ_2
  • Comparing life expectancy of emperor penguins (μ<em>E\mu<em>E) to king penguins (μ</em>K\mu</em>K).
    • H<em>0:µ</em>EµKH<em>0 : µ</em>E \geq µ_K
  • Comparing proportions for each candidate in an election.
    • H<em>0:p</em>1=p2H<em>0 : p</em>1 = p_2

Alternative Hypothesis Examples

  • Comparing body weight of US adult population (group 1) to Canadian adult population (group 2) to see if average weights are different.
    • H<em>A:µ</em>1µ2H<em>A : µ</em>1 \neq µ_2
  • Comparing life expectancy of emperor penguins (μ<em>E\mu<em>E) to king penguins (μ</em>K\mu</em>K) to test if the life expectancy of king penguins is now longer than emperor penguins.
    • HA : µE < µ_K
  • Comparing proportions for each candidate in an election to determine if the result of an election can be called.
    • H<em>A:p</em>1p2H<em>A : p</em>1 \neq p_2

Overview

  • Using CIs and hypothesis testing for comparing two population means or two population proportions.
    • Examples: tensile strength of two procedures for producing steel, proportion of users that click on an ad for two variations on the graphics
  • Focusing on differences in means first.

Notation

  • Mean and variance of population g = 1, 2 are μ<em>g\mu<em>g and σ2</em>g\sigma^2</em>g.
  • Samples from each population:
    • X<em>11,,X</em>1n1X<em>{11}, …, X</em>{1n_1} from population 1
    • X<em>21,,X</em>2n2X<em>{21}, …, X</em>{2n_2} from population 2
  • Sample mean and sample variances:
    • Xˉ<em>g=1n</em>g<em>i=1n</em>gXg,i\bar{X}<em>g = \frac{1}{n</em>g} \sum<em>{i=1}^{n</em>g} X_{g,i}
    • S2<em>g=1n</em>g1<em>i=1n</em>g(X<em>g,iXˉ</em>g)2S^2<em>g = \frac{1}{n</em>g - 1} \sum<em>{i=1}^{n</em>g} (X<em>{g,i} - \bar{X}</em>g)^2

Estimating the Parameter

  • Estimating μ<em>1μ</em>2\mu<em>1 - \mu</em>2 using Xˉ<em>1Xˉ</em>2\bar{X}<em>1 - \bar{X}</em>2.
  • Sampling distribution of Xˉ<em>1Xˉ</em>2\bar{X}<em>1 - \bar{X}</em>2:
    • E[Xˉ<em>1Xˉ</em>2]=E[\bar{X}<em>1 - \bar{X}</em>2] =
  • Variance:
    • Assumptions: uncorrelated samples within each population (Var[Xˉ<em>1\bar{X}<em>1] = , Var[Xˉ</em>2\bar{X}</em>2] = )
  • If n<em>1,n</em>2n<em>1, n</em>2 are large enough:
    • Xˉ1\bar{X}_1 \sim
    • Xˉ2\bar{X}_2 \sim
  • What about Var[Xˉ<em>1Xˉ</em>2\bar{X}<em>1 - \bar{X}</em>2]?

The Sampling Distribution of Xˉ<em>1Xˉ</em>2\bar{X}<em>1 - \bar{X}</em>2

  • If the two sample means are uncorrelated, then
    • Var[Xˉ<em>1Xˉ</em>2]=σ2<em>1n</em>1+σ2<em>2n</em>2Var[\bar{X}<em>1 - \bar{X}</em>2] = \frac{\sigma^2<em>1}{n</em>1} + \frac{\sigma^2<em>2}{n</em>2}
  • If n<em>1,n</em>230n<em>1, n</em>2 \geq 30, then
    • Xˉ<em>1Xˉ</em>2N(μ<em>1μ</em>2,σ2<em>1n</em>1+σ2<em>2n</em>2)\bar{X}<em>1 - \bar{X}</em>2 \sim N(\mu<em>1 - \mu</em>2, \frac{\sigma^2<em>1}{n</em>1} + \frac{\sigma^2<em>2}{n</em>2})

Variance Assumption

  • Xˉ<em>1Xˉ</em>2N(μ<em>1μ</em>2,σ2<em>1n</em>1+σ2<em>2n</em>2)\bar{X}<em>1 - \bar{X}</em>2 \sim N(\mu<em>1 - \mu</em>2, \frac{\sigma^2<em>1}{n</em>1} + \frac{\sigma^2<em>2}{n</em>2})
  • Assumption: the two populations might have different population means but have the same variance (σ2<em>1=σ2</em>2=σ2\sigma^2<em>1 = \sigma^2</em>2 = \sigma^2).
    • Then: σ2<em>1n</em>1+σ2<em>2n</em>2=σ2(1n<em>1+1n</em>2)\frac{\sigma^2<em>1}{n</em>1} + \frac{\sigma^2<em>2}{n</em>2} = \sigma^2(\frac{1}{n<em>1} + \frac{1}{n</em>2})
    • And: Xˉ<em>1Xˉ</em>2N(μ<em>1μ</em>2,σ2(1n<em>1+1n</em>2))\bar{X}<em>1 - \bar{X}</em>2 \sim N(\mu<em>1 - \mu</em>2, \sigma^2(\frac{1}{n<em>1} + \frac{1}{n</em>2}))

Estimating the Variance

  • Estimating the shared variance σ2\sigma^2 by combining the observed sample variances s2<em>1s^2<em>1 and s2</em>2s^2</em>2.
  • How to combine them into an estimate of σ2\sigma^2?
    • Could consider averaging them: s2=s2<em>1+s2</em>22s^2 = \frac{s^2<em>1 + s^2</em>2}{2}. Potential issue: n<em>1n<em>1 may not equal n</em>2n</em>2.

Pooled Estimate of the Variance

  • Weighted average:
    • s2<em>p=(n</em>11)s2<em>1+(n</em>21)s2<em>2(n</em>1+n22)s^2<em>p = \frac{(n</em>1 - 1)s^2<em>1 + (n</em>2 - 1)s^2<em>2}{(n</em>1 + n_2 - 2)} (pooled sample variance)
  • Example:
    • If n<em>1=14n<em>1 = 14 and n</em>2=14n</em>2 = 14, s2<em>1=10s^2<em>1 = 10 and s2</em>2=8s^2</em>2 = 8, then what is sp2s^2_p?
    • If n<em>1=14n<em>1 = 14 and n</em>2=7n</em>2 = 7, s2<em>1=10s^2<em>1 = 10 and s2</em>2=8s^2</em>2 = 8, then what is sp2s^2_p?
  • R function:
    • pooledVar = function(sampVar1,sampVar2,n1,n2){ ((n1-1)*sampVar1 + (n2-1)*sampVar2)/(n1 + n2 - 2) }

WHAT IS THE APPROPRIATE DISTRIBUTION

What is the Appropriate Distribution

  • Recall: Form for a standardized random variable?
  • Recall: Xˉ<em>1Xˉ</em>2N(μ<em>1μ</em>2,σ2(1n<em>1+1n</em>2))\bar{X}<em>1 - \bar{X}</em>2 \sim N(\mu<em>1 - \mu</em>2, \sigma^2(\frac{1}{n<em>1} + \frac{1}{n</em>2}))
  • Estimate σ2(1n<em>1+1n</em>2)\sigma^2(\frac{1}{n<em>1} + \frac{1}{n</em>2}) with s2<em>p(1n</em>1+1n2)s^2<em>p(\frac{1}{n</em>1} + \frac{1}{n_2})
    • (Xˉ<em>1Xˉ</em>2)(μ<em>1μ</em>2)s2<em>p(1n</em>1+1n<em>2)t(n</em>1+n22)\frac{(\bar{X}<em>1 - \bar{X}</em>2) - (\mu<em>1 - \mu</em>2)}{\sqrt{s^2<em>p(\frac{1}{n</em>1} + \frac{1}{n<em>2})}} \sim t(n</em>1 + n_2 - 2)
    • (Approximately holds if n<em>1,n</em>230n<em>1, n</em>2 \geq 30)
  • Punchline: Use a 't' distribution for confidence intervals/hypothesis tests for the difference of two means.

Confidence Intervals for μ<em>1μ</em>2\mu<em>1 - \mu</em>2

  • If:
    • σ2<em>1=σ2</em>2\sigma^2<em>1 = \sigma^2</em>2
    • Xˉ<em>1Xˉ</em>2\bar{X}<em>1 - \bar{X}</em>2 is normal (primarily: n<em>1,n</em>230n<em>1, n</em>2 \geq 30)
  • Then a (1α)100%(1 - \alpha)100\% CI for μ<em>1μ</em>2\mu<em>1 - \mu</em>2 is:
    • Xˉ<em>1Xˉ</em>2±t<em>α/2(n</em>1+n<em>22)s2</em>p(1n<em>1+1n</em>2)\bar{X}<em>1 - \bar{X}</em>2 \pm t<em>{\alpha/2}(n</em>1 + n<em>2 - 2)\sqrt{s^2</em>p(\frac{1}{n<em>1} + \frac{1}{n</em>2})}

Example

  • Comparing two catalysts in terms of the mean yield of a chemical process.
    • n1=32n_1 = 32 chemical processes with catalyst 1
    • n2=35n_2 = 35 chemical processes with catalyst 2
  • Experimental results:
    • Catalyst 1: xˉ<em>1=45.0313\bar{x}<em>1 = 45.0313 and s</em>1=3.1976s</em>1 = 3.1976
    • Catalyst 2: xˉ<em>2=50.4000\bar{x}<em>2 = 50.4000 and s</em>2=2.7246s</em>2 = 2.7246
  • Construct a 97% CI for μ<em>1μ</em>2\mu<em>1 - \mu</em>2.
    • What assumptions are needed for the validity of the CI?
    • Result: [-6.974882, -3.762618]
  • Another Example With Raw data:
    • x1 = c(48, 43, 46, 40, 41, 46, 50, 41, 50, 42, 40, 44, 44, 49, 45, 49, 46, 48, 44, 44, 48, 48, 44, 44, 41, 49, 48, 40, 43, 42, 45, 49)
    • x2 = c(54, 50, 48, 48, 54, 53, 51, 50, 53, 52, 53, 51, 52, 50, 54, 51, 47, 54, 50, 52, 46, 46, 50, 50, 45, 47, 47, 52, 50, 51, 50, 52, 51, 55, 45)
  • R code:
    • t.test(x1,x2, var.equal=TRUE, conf.level = .97)
    • 97 percent confidence interval: -6.974882 -3.762618

Hypothesis tests for μ<em>1μ</em>2\mu<em>1 - \mu</em>2

  • Follows the same overall structure as other tests.
  • Specify reference value Δ<em>0\Delta<em>0 and α\alpha (often Δ</em>0=0\Delta</em>0 = 0).
  • Tests:
    • H<em>0:µ</em>1µ<em>2=Δ</em>0H<em>0 : µ</em>1 - µ<em>2 = \Delta</em>0 vs H<em>A:µ</em>1µ<em>2Δ</em>0H<em>A : µ</em>1 - µ<em>2 \neq \Delta</em>0
    • H<em>0:µ</em>1µ<em>2Δ</em>0H<em>0 : µ</em>1 - µ<em>2 \geq \Delta</em>0 vs H<em>A:µ</em>1µ<em>2<Δ</em>0H<em>A : µ</em>1 - µ<em>2 < \Delta</em>0
    • H<em>0:µ</em>1µ<em>2Δ</em>0H<em>0 : µ</em>1 - µ<em>2 \leq \Delta</em>0 vs H<em>A:µ</em>1µ<em>2>Δ</em>0H<em>A : µ</em>1 - µ<em>2 > \Delta</em>0
  • Observed test statistic:
    • T<em>obs=xˉ</em>1xˉ<em>2Δ</em>0s2<em>p(1n</em>1+1n2)T<em>{obs} = \frac{\bar{x}</em>1 - \bar{x}<em>2 - \Delta</em>0}{\sqrt{s^2<em>p(\frac{1}{n</em>1} + \frac{1}{n_2})}}
    • Compared to the t(n<em>1+n</em>22)t(n<em>1 + n</em>2 - 2) distribution.
  • Catalyst Example using a significance level α=0.03\alpha = 0.03:
    • Tobs=7.4166T_{obs} = -7.4166, p-value = 3.173e103.173e-10

An Experiment

  • Do students that sit in front have a different average height than the back?
  • Confidence Interval
  • Hypothesis Test

Key assumption behind pooling

  • σ2<em>1=σ2</em>2=σ2    σ2<em>1n</em>1+σ2<em>2n</em>2=σ2(1n<em>1+1n</em>2)\sigma^2<em>1 = \sigma^2</em>2 = \sigma^2 \implies \frac{\sigma^2<em>1}{n</em>1} + \frac{\sigma^2<em>2}{n</em>2} = \sigma^2(\frac{1}{n<em>1} + \frac{1}{n</em>2})
  • Estimate σ2\sigma^2 with the pooled sample variance:
    • s2<em>p=(n</em>11)s2<em>1+(n</em>21)s2<em>2(n</em>1+n22)s^2<em>p = \frac{(n</em>1 - 1)s^2<em>1 + (n</em>2 - 1)s^2<em>2}{(n</em>1 + n_2 - 2)}
  • What happens if we don’t make this assumption?

Unequal variances

  • Since Var[Xˉ<em>1Xˉ</em>2]=σ2<em>1n</em>1+σ2<em>2n</em>2Var[\bar{X}<em>1 - \bar{X}</em>2] = \frac{\sigma^2<em>1}{n</em>1} + \frac{\sigma^2<em>2}{n</em>2}, estimate it by plugging in the sample variances directly:
    • s2<em>1n</em>1+s2<em>2n</em>2\frac{s^2<em>1}{n</em>1} + \frac{s^2<em>2}{n</em>2}
  • Observed test statistic:
    • T<em>obs=xˉ</em>1xˉ<em>2Δ</em>0s2<em>1n</em>1+s2<em>2n</em>2T<em>{obs} = \frac{\bar{x}</em>1 - \bar{x}<em>2 - \Delta</em>0}{\sqrt{\frac{s^2<em>1}{n</em>1} + \frac{s^2<em>2}{n</em>2}}}

Welch’s test: Unequal variances

  • Equal variances: the correct distribution is t(n<em>1+n</em>22)t(n<em>1 + n</em>2 - 2)
  • Unequal variances: the correct distribution is still a t, but the degrees of freedom is harder to calculate:
    • df=(s2<em>1n</em>1+s2<em>2n</em>2)2(s2<em>1n</em>1)2n<em>11+(s2</em>2n<em>2)2n</em>21df = \frac{(\frac{s^2<em>1}{n</em>1} + \frac{s^2<em>2}{n</em>2})^2}{\frac{(\frac{s^2<em>1}{n</em>1})^2}{n<em>1 - 1} + \frac{(\frac{s^2</em>2}{n<em>2})^2}{n</em>2 - 1}}
  • R syntax:
    • t.test(x1,x2, var.equal=TRUE) (Equal variances)
    • t.test(x1,x2) (Unequal variances)
  • Punchline: Just omit the ‘var.equal = TRUE’ argument