14  Hypothesis Testing

Day 1: Framework

Settling In

  • Check Slack for announcements


Motivation

Goal: Make a decision about what’s happening in the population based on what we observe in the data

Example:

summary(mod1)

Call:
lm(formula = fev ~ smoke + height, data = fevdat)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.7505 -0.2660 -0.0041  0.2447  2.1207 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) -5.427620   0.187577 -28.935   <2e-16 ***
smokesmoker  0.006319   0.058686   0.108    0.914    
height       0.131883   0.003081  42.808   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.431 on 651 degrees of freedom
Multiple R-squared:  0.7537,    Adjusted R-squared:  0.7529 
F-statistic: 995.9 on 2 and 651 DF,  p-value: < 2.2e-16


In STAT 155, we talk about how to interpret the test-statistics (t value) and p-values (Pr(>|t|)).

In this class, we’ll explore the following:

  • how are p-values calculated?
  • how do we choose our significance level?
  • how do we know what test statistic to use?



Hypothesis Testing Process

  1. State our hypotheses (\(H_0\), \(H_1\))

  2. Choose a test statistic (\(T\))

  3. Find the distribution of that test statistic under the null hypothesis (\(T \overset{H_0}{\sim} \ ?\))

  4. Choose a significance level (\(\alpha\)) and derive the corresponding critical value (\(t^*\))

  5. Calculate the observed test statistic (\(t\))

  6. Compare the observed test statistic to the critical value, and make a decision



Practice Problems

We’ll do the first one together…

  1. \(Y_1, \dots, Y_n \stackrel{iid}{\sim} N(\mu, \sigma^2)\).

    1. Derive a hypothesis test to test the one-sided hypotheses \(H_0: \mu = 8\) vs \(H_1: \mu > 8\) at the \(\alpha = 0.05\) significance level. Assume \(\sigma^2 = 64\) and we suppose observe \(\bar{Y} = 10\) based on a sample of size \(n = 64\).

    2. Calculate a p-value. Do we make the same decision?

 

Your turn!

  1. Revisit the scenario in Question 1. How will our procedure change if…

    1. we use \(\alpha = 0.01\)?
    2. we use a two-sided alternative hypothesis: \(H_1: \mu \neq 8\)?
    3. we use a different test statistic: \(T_2 = \frac{\bar{Y}-8}{\sigma / \sqrt{n}}\)?
    4. we don’t know \(\sigma^2\)?
  2. Suppose we have a random sample of size \(n\) from a Bernoulli with probability of success \(p\), and we want to test the hypotheses \(H_0: p = 0.5\) vs \(H_1: p \neq 0.5\). Derive a hypothesis test for this scenario, using the test statistic \(T = \frac{\hat{p} - 0.5}{\sqrt{\hat{p}(1-\hat{p})/n}}\) and a significance level of 0.05.

  3. Consider the scenario in Question 3, but suppose the sample size is small. Do you have any concerns about the test you derived above? If so, propose and derive an alternate test.

Solutions See today’s board notes.



Wrapping Up




Day 2: Classical Tests

Settling In

  • Check Slack for announcements



Three Classical Hypothesis Tests

There are three “classical” hypothesis tests for testing the following hypotheses: \[H_0: \theta = \theta_0 \text{ vs } H_1: \theta \neq \theta_0\]

Suppose \(\hat\theta_{MLE}\) is an MLE for \(\theta\). Then…

Wald Test

The Wald test statistic \(\lambda_W\) is given by \[\lambda_W = \left( \frac{\hat\theta_{MLE} - \theta_0}{se(\hat\theta_{MLE})} \right)^2\]

We reject \(H_0\) for large values of \(\lambda_W\).

Intuition:

  • \(\theta_0\) close to observed MLE \(\rightarrow\) small numerator \(\rightarrow\) small \(\lambda_W\) (fail to reject \(H_0\))
  • \(\theta_0\) far from MLE \(\rightarrow\) large numerator \(\rightarrow\) large \(\lambda_W\) (reject \(H_0\))


Likelihood Ratio Test (aka Wilks Test)

The Likelihood Ratio test statistic \(\lambda_{LRT}\) is given by \[\lambda_{LRT} = -2 \log \left( \frac{\sup_{\theta = \theta_0} L(\theta)}{\sup_{\theta \in \Theta}L(\theta)} \right) = -2 \log \left( \frac{L(\theta_0)}{L(\hat\theta_{MLE})} \right),\] where \(\Theta\) is the set of all possible values of \(\theta\).

We reject \(H_0\) for large values of \(\lambda_{LRT}\).

Intuition:

  • \(\theta_0\) close to MLE \(\rightarrow\) numerator similar to denominator \(\rightarrow\) ratio close to 1 \(\rightarrow\) \(\lambda_{LRT}\) close to 0 (fail to reject \(H_0\))
  • \(\theta_0\) far from MLE \(\rightarrow\) numerator much smaller than denominator \(\rightarrow\) ratio close to 0 \(\rightarrow\) \(\lambda_{LRT}\) gets really big (reject \(H_0\))


Score Test

The score test statistic \(\lambda_S\) is given by \[\lambda_S = \frac{[S(\theta_0)]^2}{I(\theta_0)},\] where \(S(\theta) = \frac{\partial}{\partial \theta} \log L(\theta)\) and \(I(\theta) = E\left[ \left( \frac{\partial}{\partial \theta} \log L(\theta)\right)^2 \right]\).

As above, reject \(H_0\) for large values of \(\lambda_S\).

Intuition:

  • \(\theta_0\) close to MLE \(\rightarrow\) \(S(\theta_0)\) close to zero \(\rightarrow\) small \(\lambda_S\) (fail to reject \(H_0\))
  • \(\theta_0\) far from MLE \(\rightarrow\) large \(\lambda_S\) (reject \(H_0\))


Comparison

Similarities

Asymptotically, these three tests are equivalent!

All three test statistics have the same asymptotic distribution:

\[\lambda_W \stackrel{d}{\to} \chi_1^2, \quad \lambda_{LRT} \stackrel{d}{\to} \chi_1^2, \quad \lambda_S \stackrel{d}{\to} \chi_1^2\]

Proof

You’ll prove this is true for a specific case on PS5!

More generally, we can prove this result using a combination of the asymptotic normality of MLEs + Slutsky’s / Continuous Mapping Theorem + Taylor Expansion


Differences

If they’re “equivalent,” why pick one over another?

Wald:

  • easy to compute
  • con: “non-invariant” to reparameterization (PS5)

LRT:

  • uniformly most powerful for simple alternatives (\(H_0: \theta = \theta_0\) vs \(H_1: \theta = \theta_1\))

Score:

  • don’t need the MLE! (helpful if MLE has no closed form, eg logistic regression)



Practice Problems

Suppose \(X_1, \dots, X_n\) are a random sample from a Bernoulli distribution with unknown probability of success \(p\), and we want to test the hypotheses \(H_0: p = 0.5\) vs \(H_1: p \neq 0.5\).

  1. Derive the Wald test statistic.

  2. Derive the LRT statistic.

  3. Derive the score test statistic.

  4. Calculate the p-values for all three tests if \(\hat{p} = 0.4\) and \(n = 300\).

  5. Calculate the p-values for all three tests if \(\hat{p} = 0.4\) and \(n = 95\).

Solutions See today’s board notes.



Wrapping Up

After class today, please work on the following:




Day 3: Errors and Power

Settling In

  • Check Slack for announcements



Errors and Power

Checkpoint Debrief

At your table, DISCUSS:

  1. What’s the difference between type I error and type II error?

  2. Which type of error is most closely connected to the significance level, \(\alpha\)? How are they related?

  3. What is power? Which type of error is most closely connected to the concept of power? How are they related?

Solutions
    • type I = reject \(H_0\) when \(H_0\) is true

    • type II = fail to reject \(H_0\) when \(H_1\) is true

  1. \(\alpha = \Pr(\text{type I error})\)

    • power = \(\Pr(\text{reject } H_0 \mid H_1 \text{ true} )\)
    • power = 1 - type II error


Why Care?

  • Choosing a significance level
  • Choosing between two or more possible tests
  • Designing a study (power analyses)



Practice Problems

  1. Will \(n = 45\) be a sufficiently large sample to test \(H_0: \mu = 10\) versus \(H_1: \mu \neq 10\) at the \(\alpha =0.05\) level of significance if the experimenter wants the Type II error probability to be no greater than 0.20 when \(\mu = 12\)? Assume that \(\sigma =4\).


  1. Suppose \(n=36\) observations are taken from a Normal distribution where \(\sigma = 8.0\) for the purpose of testing \(H_0:\mu=60\) versus \(H_1: \mu \not=60\) at the \(\alpha = 0.07\) level of significance. The lead investigator skipped statistics class the day decision rules were being discussed and intends to reject \(H_0\) if \(\bar{y}\) falls in the region \((60 - \bar{y}^*, 60+ \bar{y}^*)\).

    1. Explain why this rejection region doesn’t make much sense.

    2. Find \(\bar{y}^*\) that would give you the right level of significance.

    3. What is the power of the test when \(\mu=62\)?

    4. What would the power of the test be when \(\mu=62\) if the rejection region had been defined the correct way?


Solutions
  1. This question is on your problem set this week. Check your answer with a classmate :)


  1. …

(a) This investigator set up their rejection region such that we will reject the null hypothesis if the estimate, \(\bar{y}\) is close to the null value, 60. This is the opposite of what we would usually do!


(b) We need to find \(\bar{y}^*\) that satisfies

\[ \begin{aligned} 0.07 &= P(\bar{y} \in \text{rejection region} \mid H_0)\\ & = P(60 - \bar{y}^* \le \bar{y} \le 60+ \bar{y}^* \mid \mu = 60) \\ & = P(- \bar{y}^* \le \bar{y} - 60 \le\bar{y}^* \mid \mu = 60) \\ & = P(\frac{- \bar{y}^*}{8/\sqrt{36}} \le \frac{\bar{y} - 60}{8/\sqrt{36}} \le \frac{\bar{y}^*}{8/\sqrt{36}}\mid \mu = 60) \\ & = P(-z^* \le \frac{\bar{y} - 60}{8/\sqrt{36}} \le z^* \mid \mu = 60), \end{aligned} \] where \(\frac{\bar{y} - 60}{8/\sqrt{36}} \stackrel{\mu = 60}{\sim} N(0,1)\).

So, we need to find \(-z^*, z^*\) between which a standard Normal distribution falls 7% of the time, or, equivalently, outside which a standard Normal distribution falls 93% of the time.

Since this rejection region is symmetric, this implies that we want to find the value \(-z^*\) below which a standard Normal falls \(\frac{93}{2}\)% of the time, and then the distribution will fall above \(z^*\) the other \(\frac{93}{2}\)% of the time:

## find -z* such that a N(0,1) falls below it (93/2)% of the time
qnorm(.93/2, mean = 0, sd = 1)
[1] -0.08784484
## z*
qnorm(.93/2, mean = 0, sd = 1, lower.tail = F)
[1] 0.08784484

This implies that \(\bar{y}^* = z^*\frac{8}{6} = 0.1171265\).


(c) The power of the test under the alternative \(\mu = 62\) is

\[ \begin{aligned} 1 - \beta &= P(\bar{y} \in \text{rejection region} \mid H_1)\\ & = P(60 - \bar{y}^* \le \bar{y} \le 60+ \bar{y}^* \mid \mu = 62) \\ & = P(60 - 0.117 \le \bar{y} \le 60+ 0.117 \mid \mu = 62), \text{ from (a)} \\ & = P(\bar{y} \le 60+ 0.117 \mid \mu = 62) - P(60 - 0.117 \le \bar{y} \mid \mu = 62), \\ \end{aligned} \]

where \(\bar{y} \stackrel{\mu = 62}{\sim} N(62, \frac{8^2}{36})\).

Thus, the power is:

## calculate power
pnorm(60+0.117, mean = 62, sd = 8/6) - pnorm(60-0.117, mean = 62, sd = 8/6)
[1] 0.02276674

This is very small!


(d) To do this test correctly, we reject \(H_0\) if \(\bar{y} \not\in (60 - \bar{y}^*, 60+ \bar{y}^*)\). To find the power of this test when \(\mu = 62\), we first need to find the value of \(\bar{y}^*\) that gives us the right level of significance:

\[ \begin{aligned} 0.07 & = P(\bar{y} \not\in (60 - \bar{y}^*, 60+ \bar{y}^*) \mid \mu = 60) \\ \implies 0.93 & = P(\bar{y} \in (60 - \bar{y}^*, 60+ \bar{y}^*) \mid \mu = 60) \\ & = P(60 - \bar{y}^* < \bar{y} < 60 + \bar{y}^* \mid \mu = 60) \\ & = P(\frac{- \bar{y}^*}{8/\sqrt{36}} \le \frac{\bar{y} - 60}{8/\sqrt{36}} \le \frac{\bar{y}^*}{8/\sqrt{36}}\mid \mu = 60) \\ & = P(-z^* \le \frac{\bar{y} - 60}{8/\sqrt{36}} \le z^* \mid \mu = 60), \end{aligned} \]

where, as before, we have \(\frac{\bar{y} - 60}{8/\sqrt{36}} \stackrel{H_0}{\sim} N(0,1)\).

To find \(-z^*,z^*\) we now need to find the values between which a standard Normal falls 93% of the time (or, equivalently, outside which a standard Normal falls 7% of the time).

This means that we need to find \(-z^*\) below which a standard Normal falls \(\frac{7}{2}\)% of the time, and \(z^*\) above which a standard Normal falls the other \(\frac{7}{2}\)% of the time:

# find -z* such that a N(0,1) falls below it (7/2)% of the time
qnorm(0.07/2, mean = 0, sd = 1)
[1] -1.811911
# find z* such that a N(0,1) falls above it (7/2)% of the time
qnorm(0.07/2, mean = 0, sd = 1, lower.tail = F)
[1] 1.811911

This implies that our critical value is \(\bar{y}^* = z^*\frac{8}{6} = 2.4158809\).

Now that we have \(\bar{y}^*\), we can find the power of this test under the alternative \(\mu = 62\):

\[ \begin{aligned} 1 - \beta &= P(\bar{y} \in \text{rejection region} \mid H_1)\\ \implies \beta & = P(\bar{y} \not\in \text{rejection region} \mid H_1)\\ & = P(\bar{y} \in (60 - \bar{y}^*, 60+ \bar{y}^*) \mid H_1) \\ & = P(60 - \bar{y}^* \le \bar{y} \le 60+ \bar{y}^* \mid \mu = 62) \\ & = P(60 - 2.4216 \le \bar{y} \le 60+ 2.4216 \mid \mu = 62) \\ & = P(\bar{y} \le 60+ 2.4216 \mid \mu = 62) - P(\bar{y} \le 60 - 2.4216 \mid \mu = 62), \end{aligned} \]

where, as above, \(\bar{y} \stackrel{\mu = 62}{\sim} N(62, \frac{8^2}{36})\). Thus \(\beta\) is

## calculate beta (1 - power)
pnorm(60+2.4216, mean = 62, sd = 8/6) - pnorm(60-2.4216, mean = 62, sd = 8/6)
[1] 0.6236184

which implies that the power \(1-\beta = 0.3763816\). This is much higher than the power of the initially proposed test!



Wrapping Up

Concept Debrief

  • A “good” hypothesis test has low type I error, low type II error, and high power.

  • Type I error is influenced by the significance level (\(\alpha\)).

  • Power and type II error are influenced by:

    • the rejection region (which comes from our choice of \(\alpha\))
    • the true value of the parameter under \(H_1\)
    • the sample size
    • the variability of data
  • In applied analysis, it is common practice to calculate the power of your study before collecting data and use this to help choose a sample size. (But in order to do this, you need to make assumptions about all of the factors listed above!)


After Class Today…




Day 4: Neyman-Pearson Lemma

Settling In

  • Check Slack for announcements
  • Turn in PS5 on the side table



Review: Power

DISCUSS at your table:

  1. What is power? (In words and mathematical notation)

  2. Does a “good” test have large (close to 1) or small (close to 0) power?

  3. Suppose we are interested in testing the hypotheses \(H_0: \theta = \theta_0\) vs \(H_1: \theta \neq \theta_0\). Come up with a test that will have power exactly equal to 1, and another that will have power exactly equal to 0.



Uniformly Most Powerful Tests

Power Function
The power function of a hypothesis test is defined \[ \gamma(\theta) = \Pr(\mathbf{X} \in R \mid \theta) = \begin{cases} \Pr(\text{T1E}) & \text{ if } \theta \in \Theta_0 \\ \text{power} & \text{ if } \theta \in \Theta_0^c \end{cases} \]


Uniformly Most Powerful
Let \(\mathcal{C}\) represent the class of all level \(\alpha\) tests, ie \[ \mathcal{C} = \{\gamma(\theta) : \sup_{\theta \in \Theta_0} \gamma(\theta) = \alpha \}. \] A hypothesis test, with power function \(\gamma^*(\theta)\), is a uniformly most powerful level \(\alpha\) test if \(\gamma^*(\theta) \in \mathcal{C}\) and \(\gamma^*(\theta) \ge \gamma\prime(\theta)\) for all \(\theta \in \Theta_0^C\) and all \(\gamma\prime(\theta) \in \mathcal{C}\).

Intuition: A hypothesis test is “uniformly most powerful” if, when compared to all other tests with the same significance level \(\alpha\), it has higher power for all values of the parameter under the alternative hypothesis. (This should remind you of of UMVUEs!)


Q: Can we always find a uniformly most powerful test?

A: In general, no. But in some scenarios, yes!



Neyman-Pearson Lemma

Suppose we are interested in testing the “simple” hypotheses \(H_0: \theta = \theta_0\) vs \(H_1: \theta = \theta_1\).

The Neyman-Pearson Lemma tells us that the simplified likelihood ratio test with test statistic \(\lambda_{LRT} = \frac{L(\theta_1)}{L(\theta_0)}\) (where we reject \(H_0\) for large values of \(\lambda\)) is a UMP test in this scenario.

Proof Check out Section 7.4 of the MATH/STAT 355 Notes. This is a fun proof and uses a similar technique to the proof of Chebyshev’s Inequality!



Putting it All Together

The end of the semester is quickly approaching! This is our final day of “required” content. (The next few class periods will cover “bonus” topics.)

We’ve covered a lot this semester. How does it all connect??

Activity

Create a study guide for one of the following topics:

  1. estimation techniques: MLE, least squares, and MOM
  2. finite sample properties: bias, variance, MSE
  3. finite sample properties (cont): efficiency and sufficiency
  4. asymptotic properties of estimators: asymptotically unbiased, consistency, asymptotic normality, asymptotic efficiency
  5. confidence intervals
  6. hypothesis testing

For your topic, consider:

  • definitions (mathematical notation + intuitive explanations)
  • important theorems
  • proof or derivation techniques
  • examples (make a list of corresponding videos, in-class practice problems, homework problems, past quiz problems, etc)
  • make a concept map!
    • connections between the various definitions, theorems, and techniques
    • connections to other topics

Format is up to you! Use the whiteboards, create a google doc, etc.



Wrapping Up