Two Sample Inference

Linear Combination of Random Variables

  • Objective: Compare two proportions or two means by understanding how addition and multiplication affect the mean and variance.
  • Set A Example: Given set A = {98, 99, 100, 101, 102}
    • Sample mean (xˉ\bar{x}): xˉ=Σxin=100\bar{x} = \frac{\Sigma x_i}{n} = 100
    • Sample variance ($s^2$): s2=Σ(xixˉ)2n1=2.5s^2 = \frac{\Sigma (x_i - \bar{x})^2}{n-1} = 2.5
  • Doubling Set A: 2A = {198, 199, 200, 201, 202}
    • New sample mean: xˉ=200\bar{x} = 200
    • New sample variance: s2=10=4×2.5s^2 = 10 = 4 \times 2.5
    • Doubling the values increases the sample variance by a factor of 4.
  • Tripling Set A: 3A = {294, 297, 300, 303, 306}
    • New sample mean: xˉ=300\bar{x} = 300
    • New sample variance: s2=22.5=9×2.5s^2 = 22.5 = 9 \times 2.5
  • Multiplying by -1: -A = {-98, -99, -100, -101, -102}
    • New sample mean: xˉ=100\bar{x} = -100
    • New sample variance: s2=2.5s^2 = 2.5
  • Multiplying by -3:
    • New sample mean: xˉ=300\bar{x} = -300
    • New sample variance: s2=22.5=9×2.5s^2 = 22.5 = 9 \times 2.5
  • Rule for Multiplication: Deriving a rule for calculating the sample mean and variance based on multiplication of the original set.

Effect of Addition on Sample Mean and Variance

  • Adding 100 to all values in set A: Resulting set {198, 199, 200, 201, 202}
    • New sample mean: xˉ=200\bar{x} = 200
    • New sample variance: s2=2.5s^2 = 2.5
  • Doubling and Subtracting: Doubling set A and subtracting 50 from each value.
    • New sample mean: xˉ=150\bar{x} = 150
  • The sample variance would be four times the variance of your original set A. s2=10=4×2.5s^2 = 10 = 4 \times 2.5
  • Rule for Addition: Establishing a rule for calculating the sample mean and variance based on the addition of values to the original set.

Expectation of a Linear Transformation (One Random Variable)

  • Formula: E[aX+c]=a×E[X]+cE[aX + c] = a \times E[X] + c
    • Where:
      • $a$ and $c$ are constants.
      • $X$ is a random variable.
      • E[]E[\cdot] denotes the expected value (mean).

Examples of Linear Transformations (One Variable)

  • Given: E[X]=2E[X] = 2
    • a. Calculate E[5X]E[5X]
      • E[5X]=5×E[X]=5×2=10E[5X] = 5 \times E[X] = 5 \times 2 = 10
    • b. Calculate E[2X+4]E[-2X + 4]
      • E[2X+4]=2×E[X]+4=2×2+4=0E[-2X + 4] = -2 \times E[X] + 4 = -2 \times 2 + 4 = 0
    • c. Calculate E[5]E[5]
      • E[5]=5E[5] = 5

Expectation of a Linear Combination (Two Random Variables)

  • Formula: E[aX+bY+c]=a×E[X]+b×E[Y]+cE[aX + bY + c] = a \times E[X] + b \times E[Y] + c
    • Where:
      • $a$, $b$, and $c$ are constants.
      • $X$ and $Y$ are random variables.
      • E[]E[\cdot] denotes the expected value (mean).

Examples of Linear Transformations (Two Variables)

  • Given: E[X]=2E[X] = 2 and E[Y]=3E[Y] = 3
    • a. Calculate E[XY+1]E[X - Y + 1]
      • E[XY+1]=E[X]E[Y]+1=23+1=0E[X - Y + 1] = E[X] - E[Y] + 1 = 2 - 3 + 1 = 0
    • b. Calculate E[3X2Y+5]E[3X - 2Y + 5]
      • E[3X2Y+5]=3×E[X]2×E[Y]+5=3×22×3+5=5E[3X - 2Y + 5] = 3 \times E[X] - 2 \times E[Y] + 5 = 3 \times 2 - 2 \times 3 + 5 = 5

Variance of a Linear Transformation (One Random Variable)

  • Formula: Var[aX+c]=a2×Var[X]Var[aX + c] = a^2 \times Var[X]
    • Where:
      • $a$ and $c$ are constants.
      • $X$ is a random variable.
      • Var[]Var[\cdot] denotes the variance.

Examples of Variance Transformations (One Variable)

  • Given: Var[X]=2Var[X] = 2
    • a. Calculate Var[2X+4]Var[2X + 4]
      • Var[2X+4]=22×Var[X]=4×2=8Var[2X + 4] = 2^2 \times Var[X] = 4 \times 2 = 8
    • b. Calculate Var[X7]Var[-X - 7]
      • Var[X7]=(1)2×Var[X]=1×2=2Var[-X - 7] = (-1)^2 \times Var[X] = 1 \times 2 = 2

Variance of a Linear Combination (Two Random Variables)

  • Formula: Var[aX+bY+c]=a2×Var[X]+b2×Var[Y]+2abCov(X,Y)Var[aX + bY + c] = a^2 \times Var[X] + b^2 \times Var[Y] + 2abCov(X, Y)
    • Where:
      • $a$, $b$, and $c$ are constants.
      • $X$ and $Y$ are random variables.
      • Var[]Var[\cdot] denotes the variance.
      • $Cov(X, Y)$ is the covariance between $X$ and $Y$, measuring their joint variability.

Practice with Variance Calculations

  • Given: Var[X]=2Var[X] = 2, Var[Y]=3Var[Y] = 3, and Cov(X,Y)=0Cov(X, Y) = 0
    • a. Calculate Var[2X+3Y+4]Var[2X + 3Y + 4]
    • b. Calculate Var[XY]Var[X - Y]
    • c. Calculate Var[3XY+1]Var[-3X - Y + 1]

Applying Expectation Properties to Proportions

  • Estimating p<em>1p</em>2p<em>1 - p</em>2 using p^<em>1p^</em>2\hat{p}<em>1 - \hat{p}</em>2
    • a. E[p^<em>1]=p</em>1E[\hat{p}<em>1] = p</em>1
    • b. E[p^<em>2]=p</em>2E[\hat{p}<em>2] = p</em>2
    • c. Expected value of the difference: E[p^<em>1p^</em>2]=E[p^<em>1]E[p^</em>2]=p<em>1p</em>2E[\hat{p}<em>1 - \hat{p}</em>2] = E[\hat{p}<em>1] - E[\hat{p}</em>2] = p<em>1 - p</em>2
    • d. If \hat{p}1 - \hat{p}2 > 0, then p^1\hat{p}_1 is larger.
    • e. If p^<em>1p^</em>2=0\hat{p}<em>1 - \hat{p}</em>2 = 0, the proportions are the same.

Applying Variance Properties to Proportions

  • Estimating p<em>1p</em>2p<em>1 - p</em>2 using p^<em>1p^</em>2\hat{p}<em>1 - \hat{p}</em>2
    • a. Variance of p^<em>1\hat{p}<em>1: p^</em>1(1p^<em>1)n</em>1\frac{\hat{p}</em>1(1 - \hat{p}<em>1)}{n</em>1}
    • b. Variance of p^<em>2\hat{p}<em>2: p^</em>2(1p^<em>2)n</em>2\frac{\hat{p}</em>2(1 - \hat{p}<em>2)}{n</em>2}
    • c. Variance of the difference (assuming zero covariance):
      Var(p^<em>1p^</em>2)=Var(p^<em>1)+Var(p^</em>2)p^<em>1(1p^</em>1)n<em>1+p^</em>2(1p^<em>2)n</em>2Var(\hat{p}<em>1 - \hat{p}</em>2) = Var(\hat{p}<em>1) + Var(\hat{p}</em>2) \approx \frac{\hat{p}<em>1(1 - \hat{p}</em>1)}{n<em>1} + \frac{\hat{p}</em>2(1 - \hat{p}<em>2)}{n</em>2}
    • d. Standard deviation of the difference (assuming zero covariance):
      p^<em>1(1p^</em>1)n<em>1+p^</em>2(1p^<em>2)n</em>2\sqrt{\frac{\hat{p}<em>1(1 - \hat{p}</em>1)}{n<em>1} + \frac{\hat{p}</em>2(1 - \hat{p}<em>2)}{n</em>2}}

Confidence Interval for the Difference of Two Proportions

  • Formula: (p^<em>1p^</em>2)±z<em>α/2p^</em>1(1p^<em>1)n</em>1+p^<em>2(1p^</em>2)n2(\hat{p}<em>1 - \hat{p}</em>2) \pm z<em>{\alpha/2} \sqrt{\frac{\hat{p}</em>1(1 - \hat{p}<em>1)}{n</em>1} + \frac{\hat{p}<em>2(1 - \hat{p}</em>2)}{n_2}}
    • Assumptions:
      • n<em>130n<em>1 \geq 30 and n</em>230n</em>2 \geq 30
      • n<em>1p^</em>15n<em>1\hat{p}</em>1 \geq 5 and n<em>2p^</em>25n<em>2\hat{p}</em>2 \geq 5
      • n<em>1(1p^</em>1)5n<em>1(1 - \hat{p}</em>1) \geq 5 and n<em>2(1p^</em>2)5n<em>2(1 - \hat{p}</em>2) \geq 5

Confidence Interval Example

  • Scenario: Comparing the proportion of men (p<em>1p<em>1) and women (p</em>2p</em>2) taking vitamins.
    • Men: n<em>1=100n<em>1 = 100, 72 take vitamins, p^</em>1=0.72\hat{p}</em>1 = 0.72
    • Women: n<em>2=200n<em>2 = 200, 122 take vitamins, p^</em>2=0.61\hat{p}</em>2 = 0.61
    • a. 95% confidence interval for p<em>1p</em>2p<em>1 - p</em>2:
      0.720.61±1.960.72(10.72)100+0.61(10.61)200[0.0010,0.2210]0.72 - 0.61 \pm 1.96 \sqrt{\frac{0.72(1 - 0.72)}{100} + \frac{0.61(1 - 0.61)}{200}} \approx [-0.0010, 0.2210]
    • b. Interpretation: We are 95% confident that p<em>1p</em>2p<em>1 - p</em>2 is between -0.0010 and 0.2210.

Practice: Confidence Interval for Energy Drink vs. Coffee

  • Scenario: Comparing high blood pressure rates between energy drink and coffee consumers.
    • Energy drinks: n1=120n_1 = 120, 40 have high blood pressure.
    • Coffee: n2=80n_2 = 80, 17 have high blood pressure.
    • Task:
      • a. Calculate the 95% confidence interval for the difference p<em>energyp</em>coffeep<em>{energy} - p</em>{coffee}.
      • b. Interpret the confidence interval.

Applying Expectation Properties to Means

  • 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
    • a. E[xˉ<em>1]=μ</em>1E[\bar{x}<em>1] = \mu</em>1
    • b. E[xˉ<em>2]=μ</em>2E[\bar{x}<em>2] = \mu</em>2
    • c. Expected value of the difference: E[xˉ<em>1xˉ</em>2]=E[xˉ<em>1]E[xˉ</em>2]=μ<em>1μ</em>2E[\bar{x}<em>1 - \bar{x}</em>2] = E[\bar{x}<em>1] - E[\bar{x}</em>2] = \mu<em>1 - \mu</em>2
    • d. If \bar{x}1 - \bar{x}2 < 0, then xˉ2\bar{x}_2 is larger.
    • e. If xˉ<em>1xˉ</em>2=0\bar{x}<em>1 - \bar{x}</em>2 = 0, the sample means are the same.

Applying Variance Properties to Means

  • 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
    • a. Variance of xˉ<em>1\bar{x}<em>1 (approximated using s</em>1s</em>1): s<em>12n</em>1\frac{s<em>1^2}{n</em>1}
    • b. Variance of xˉ<em>2\bar{x}<em>2 (approximated using s</em>2s</em>2): s<em>22n</em>2\frac{s<em>2^2}{n</em>2}
    • c. Variance of the difference:
      Var(xˉ<em>1xˉ</em>2)=Var(xˉ<em>1)+Var(xˉ</em>2)s<em>12n</em>1+s<em>22n</em>2Var(\bar{x}<em>1 - \bar{x}</em>2) = Var(\bar{x}<em>1) + Var(\bar{x}</em>2) \approx \frac{s<em>1^2}{n</em>1} + \frac{s<em>2^2}{n</em>2}
    • d. Standard deviation of the difference:
      s<em>12n</em>1+s<em>22n</em>2\sqrt{\frac{s<em>1^2}{n</em>1} + \frac{s<em>2^2}{n</em>2}}

Confidence Interval for the Difference of Two Means

  • Formula: xˉ<em>1xˉ</em>2±t<em>α/2,ν^s</em>12n<em>1+s</em>22n2\bar{x}<em>1 - \bar{x}</em>2 \pm t<em>{\alpha/2, \hat{\nu}} \sqrt{\frac{s</em>1^2}{n<em>1} + \frac{s</em>2^2}{n_2}}
    • Degrees of freedom: ν^=min(n<em>11,n</em>21)\hat{\nu} = min(n<em>1 - 1, n</em>2 - 1)

Discussion on Degrees of Freedom Calculation

  • Conservative estimate: ν^=min(n<em>11,n</em>21)\hat{\nu} = min(n<em>1 - 1, n</em>2 - 1)
  • Satterthwaite's degrees of freedom: ν^<em>Satterthwaite=(s</em>12n<em>1+s</em>22n<em>2)2(s</em>12n<em>1)2n</em>11+(s<em>22n</em>2)2n21\hat{\nu}<em>{Satterthwaite} = \frac{\left(\frac{s</em>1^2}{n<em>1} + \frac{s</em>2^2}{n<em>2}\right)^2}{\frac{\left(\frac{s</em>1^2}{n<em>1}\right)^2}{n</em>1 - 1} + \frac{\left(\frac{s<em>2^2}{n</em>2}\right)^2}{n_2 - 1}}
    • Justification: min(n<em>11,n</em>21)ν^<em>Satterthwaiten</em>1+n22min(n<em>1 - 1, n</em>2 - 1) \leq \hat{\nu}<em>{Satterthwaite} \leq n</em>1 + n_2 - 2

Example: Hypertension Drug Trial

  • Scenario: Evaluating the effectiveness of a hypertension drug in lowering systolic blood pressure (SBP).
    • Drug: n<em>1=16n<em>1 = 16, xˉ</em>1=125\bar{x}</em>1 = 125, s1=10s_1 = 10
    • Placebo: n<em>2=14n<em>2 = 14, xˉ</em>2=138\bar{x}</em>2 = 138, s2=20s_2 = 20
    • a. 95% confidence interval for μ<em>1μ</em>2\mu<em>1 - \mu</em>2:
      125138±tα/2,1310216+20214[25.75,0.25]125 - 138 \pm t_{\alpha/2, 13} \sqrt{\frac{10^2}{16} + \frac{20^2}{14}} \approx [-25.75, -0.25]
    • b. Interpretation: We are 95% confident that the difference in population means μ<em>Drugμ</em>Placebo\mu<em>{Drug} - \mu</em>{Placebo} is between -25.75 and -0.25.

Practice: Corn Stalk Height Comparison

  • Scenario: Examining the difference in corn stalk height between Iowa and Nebraska.
    • Iowa: n<em>1=15n<em>1 = 15, xˉ</em>1=155\bar{x}</em>1 = 155 cm, s1=16s_1 = 16
    • Nebraska: n<em>2=20n<em>2 = 20, xˉ</em>2=145\bar{x}</em>2 = 145 cm, s2=10s_2 = 10
    • Task:
      • a. Calculate the 95% confidence interval for μ<em>Iowaμ</em>Nebraska\mu<em>{Iowa} - \mu</em>{Nebraska}.
      • b. Interpret the confidence interval.

How to Write a Hypothesis for 2-Samples

  • Null Hypothesis: H<em>0:μ</em>1μ<em>2=0H<em>0: \mu</em>1 - \mu<em>2 = 0 or H</em>0:μ<em>1=μ</em>2H</em>0: \mu<em>1 = \mu</em>2
  • Possible Alternate Hypotheses:
    • H<em>a:μ</em>1μ<em>2>0H<em>a: \mu</em>1 - \mu<em>2 > 0 or H</em>a:μ<em>1>μ</em>2H</em>a: \mu<em>1 > \mu</em>2
    • H<em>a:μ</em>1μ<em>2<0H<em>a: \mu</em>1 - \mu<em>2 < 0 or H</em>a:μ<em>1<μ</em>2H</em>a: \mu<em>1 < \mu</em>2
    • H<em>a:μ</em>1μ<em>20H<em>a: \mu</em>1 - \mu<em>2 \neq 0 or H</em>a:μ<em>1μ</em>2H</em>a: \mu<em>1 \neq \mu</em>2
  • Same approach applies to hypothesis testing about two proportions.

Hypothesis Testing Examples

  • a. Claim: Mean workout time for men > women. P-value = 0.4358
    • H<em>0:μ</em>M=μWH<em>0: \mu</em>M = \mu_W
    • Ha: \muM > \mu_W
    • Conclusion: Fail to reject H0H_0. Not enough evidence to suggest men work out more.
  • b. Claim: Mean time to finish statistics homework = math homework. P-value = 10710^{-7}
    • H<em>0:μ</em>S=μMH<em>0: \mu</em>S = \mu_M
    • H<em>a:μ</em>SμMH<em>a: \mu</em>S \neq \mu_M
    • Conclusion: Reject H0H_0. There is enough evidence to suggest the mean times are different.

Hypothesis Testing Practice

  • a. Claim: Mean points in professional football = college football. P-value = 0.1438
  • b. Claim: Mean fast food spending now > 10 years ago. P-value = 1.43 × 102310^{-23}

Test Statistic for 2-Sample Means

  • Formula: t = \frac{\bar{x}1 - \bar{x}2 - (\mu1 - \mu2)0}{\sqrt{\frac{s1^2}{n1} + \frac{s2^2}{n_2}}}}
    • xˉi\bar{x}_i = Sample mean for i = 1,2
    • si2s_i^2 = Sample variance for i = 1,2
    • nin_i = Sample size for i = 1,2
    • (μ<em>1μ</em>2)0(μ<em>1 - μ</em>2)_0 = Hypothesized difference of the two means

Example: Corn Stalk Height Hypothesis Test

  • Scenario: Testing the claim that Iowa corn grows taller than Nebraska corn.
    • Iowa: n<em>1=15n<em>1 = 15, xˉ</em>1=155\bar{x}</em>1 = 155 cm, s1=16s_1 = 16
    • Nebraska: n<em>2=20n<em>2 = 20, xˉ</em>2=145\bar{x}</em>2 = 145 cm, s2=10s_2 = 10
    • a. Hypotheses: H<em>0:μ</em>I=μ<em>NH<em>0: \mu</em>I = \mu<em>N, H</em>a:μ<em>I>μ</em>NH</em>a: \mu<em>I > \mu</em>N
    • b. Test statistic: t=155145016215+102202.13t = \frac{155 - 145 - 0}{\sqrt{\frac{16^2}{15} + \frac{10^2}{20}}} \approx 2.13
    • c. P-value: 1t.dist(2.13,14,TRUE)0.02571 - t.dist(2.13, 14, TRUE) \approx 0.0257
    • d. Conclusion: Reject H0H_0. Enough evidence to suggest Iowa corn is taller.

Using Satterthwaite Degrees of Freedom

  • Continuing the corn stalk height example.
    • a. Calculate the p-value using Satterthwaite's degrees of freedom:
      ν^Satterthwaite=(16215+10220)2(16215)2151+(10220)220122\hat{\nu}_{Satterthwaite} = \frac{\left(\frac{16^2}{15} + \frac{10^2}{20}\right)^2}{\frac{\left(\frac{16^2}{15}\right)^2}{15 - 1} + \frac{\left(\frac{10^2}{20}\right)^2}{20 - 1}} \approx 22
      p1t.dist(2.13,22,TRUE)0.0223p \approx 1 - t.dist(2.13, 22, TRUE) \approx 0.0223

Practice: Alex vs. Brian Game Scores

  • Scenario: Testing if Alex's mean score equals Brian's mean score over 6 games each.
    • Task:
      • a. State the null and alternate hypotheses.
      • b. Calculate the test statistic.
      • c. Determine the p-value.
      • d. Draw a conclusion.

Installing Data Analysis ToolPak for Windows

  • Step 1: Click on "File" followed by "Options"
  • Step 2: Click "Add-ins"
  • Step 3: Click "Go"
  • Step 4: Check "Analysis ToolPak"
  • Step 5: Click "OK." Double check it worked. Click "Data" followed by "Data Analysis"
  • We can use this for "T-Test: Two Sample Assuming Unequal Variances"