Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Fundamentals of Hypothesis Testing

Hello! Welcome to the final lesson in our module on Statistical Estimation Theory.

In our previous lessons, we focused on parameter estimation, where our goal was to find the "best" value for an unknown parameter using methods like Maximum Likelihood (MLE) and Maximum a Posteriori (MAP). Today, we shift our focus to a different but related pillar of statistical inference: hypothesis testing. Instead of asking "what is the value of this parameter?", hypothesis testing helps us answer questions like "is it plausible that this parameter is equal to a specific value?".

Your learning outcome for this lesson is to formulate the statistical hypothesis testing framework, including null/alternative hypotheses and Type I/II errors. This framework is the bedrock for making data-driven decisions and is fundamental to interpreting the results of many machine learning models.

1. Formulating Hypotheses

At its core, a statistical hypothesis is a claim or statement about a property of a population, which we can translate into a statement about a parameter . Hypothesis testing provides a formal procedure for deciding between two competing hypotheses.

To understand the formal definitions, let's start with a foundational resource.

557: mathematical statistics ii hypothesis testing

This document from McGill University provides a concise and mathematically precise introduction to the terminology of hypothesis testing. It will give you the formal language we'll use throughout the lesson.

Please read the first page of this PDF, up to the end of the bulleted list (ending with 'The complement of R will be written R’'). Focus on the definitions of the null and alternative hypotheses (H_0, H_1) and how they partition the parameter space \Theta.

As the reading explains, we always have two competing hypotheses:

  • The Null Hypothesis (): This is the default assumption, the status quo, or the statement of "no effect." It often represents a skeptical position. For example, if we're testing a new drug, would be that the drug has no effect. In a parametric model, this corresponds to the parameter belonging to a specific set, . A simple hypothesis specifies an exact value, e.g., . A composite hypothesis specifies a range, e.g., .

  • The Alternative Hypothesis ( or ): This is the claim we wish to find evidence for. It is the competing, mutually exclusive statement to the null hypothesis. It corresponds to the parameter belonging to the set . For the simple null , an alternative could be one-sided () or two-sided ().

The logic of hypothesis testing is analogous to a criminal trial: the defendant is presumed innocent () unless the prosecution can provide evidence "beyond a reasonable doubt" to prove guilt (). We start by assuming is true and only reject it if our observed data is highly unlikely under that assumption.

2. Decisions and Errors

Once we've set up our hypotheses, we collect data and make one of two possible decisions:

  1. Reject in favor of .
  2. Fail to reject .

It's crucial to note that we never "accept" the null hypothesis. We either find enough evidence to reject it, or we don't. Failing to reject simply means the data was not strong enough to convince us to abandon the default position.

Since the true state of nature is unknown to us, our decision can either be correct or incorrect. This leads to four possible outcomes, which are best understood visually.

Errors in Hypothesis Testing Matrix
This matrix illustrates the four possible outcomes of a hypothesis test. A correct decision is made when we reject a false null hypothesis or fail to reject a true one. An error occurs when our decision does not match reality.

This leads us to the formal definitions of the two types of errors we can make:

  • Type I Error: Rejecting the null hypothesis () when it is actually true. This is a "false positive." In the trial analogy, this is convicting an innocent person.
  • Type II Error: Failing to reject the null hypothesis () when it is actually false. This is a "false negative." In the trial analogy, this is acquitting a guilty person.

The following video provides an excellent summary of these concepts.

Type I Errors, Type II Errors, and the Power of the Test

This video from jbstatistics clearly explains Type I and Type II errors using both the formal definitions and the criminal trial analogy, which will help solidify your understanding.

Watch the video from the beginning until 03:45. Pay close attention to the 2x2 table presented and how it relates to the criminal trial analogy.

3. Quantifying Errors: Significance, Power, , and

In a statistical framework, we want to control the probabilities of making these errors. These probabilities are given special names:

  • Significance Level (): The probability of making a Type I error, given that the null hypothesis is true.

    As the experimenter, you choose the value of before conducting the test. It represents the risk you are willing to take of making a false positive claim. Common choices are or . Setting means you are willing to accept a 5% chance of incorrectly rejecting a true null hypothesis.

  • Beta (): The probability of making a Type II error, given that the alternative hypothesis is true.

    Unlike , is not a single value. It depends on the specific, true value of the parameter under . For instance, it's harder to detect a small effect (true mean is 51 when ) than a large effect (true mean is 70), so would be higher in the first case.

  • Power of the Test (1 - ): This is the probability of correctly rejecting a false null hypothesis.

    Power is the probability that our test will successfully detect an effect that is actually there. We generally want tests with high power.

There is an inherent trade-off between and . Making it harder to reject (i.e., decreasing ) will naturally make it more likely that we'll fail to reject a false (i.e., increasing ).

Let's continue with the same video to see how these probabilities are defined.

Type I Errors, Type II Errors, and the Power of the Test

This next segment of the video defines \alpha, eta, and Power, and discusses the trade-off between them.

Watch from 03:45 to 08:04. Focus on the definitions of \alpha, eta, and Power, and especially the inverse relationship between \alpha and eta.

4. Visualizing the Framework: Test Statistics and Critical Regions

How do we actually decide whether to reject ? We calculate a test statistic, , from our data. This is a single number that summarizes the evidence. Then, we compare this statistic to a pre-defined critical region (or rejection region), .

  • If our test statistic falls inside the critical region , we reject .
  • If falls outside , we fail to reject .

The critical region is defined such that the probability of our test statistic falling into it, assuming is true, is exactly .

The following video provides a brilliant visualization of how , , and the critical region all fit together in a concrete example.

Calculating Power and the Probability of a Type II Error (A One-Tailed Example)

This video from jbstatistics, while focused on calculating power, provides an excellent visual demonstration of the concepts we've discussed. We will watch specific parts to see the framework in action.

Please watch two specific segments: 00:59 to 03:45: This part shows how the significance level \alpha is used to define the critical value and the rejection region for the test statistic. Notice how the area of this region under the null distribution equals \alpha. 03:45 to 06:20: This segment visualizes the probability of a Type II error, eta. It shows a second distribution for a specific true alternative. Observe how eta is the area under this alternative distribution that falls outside the rejection region.

Watching those segments should make the abstract definitions much more concrete. You can see two sampling distributions:

  1. The distribution of the test statistic if is true. The critical region is the tail(s) of this distribution with a total area of .
  2. The distribution of the test statistic if is true (for a specific parameter value). The area of this distribution that overlaps with the rejection region is the power, and the area that falls outside is .
Test your understanding!

A data scientist at a software company wants to test if a new button design on their website increases the user click-through rate. The current rate is 10%. They run an A/B test.

  1. Formulate the null () and alternative () hypotheses.
  2. Describe what a Type I error would be in this context. What is a business consequence?
  3. Describe what a Type II error would be in this context. What is a business consequence?
Show answer
  1. Hypotheses: Let be the true click-through rate for the new button.

    • (or ). The new button has no effect or makes things worse.
    • . The new button increases the click-through rate.
  2. Type I Error: Rejecting when it is true. This means concluding that the new button is better when, in reality, it is not.

    • Consequence: The company spends time and money implementing a new button design that does not actually improve user engagement, wasting resources that could have been used elsewhere.
  3. Type II Error: Failing to reject when it is false. This means concluding that the new button has no effect when, in reality, it is better.

    • Consequence: The company misses an opportunity to improve its website and potentially increase revenue or user satisfaction. They stick with the inferior design.

Conclusion

Today you have built the foundational vocabulary and conceptual structure of statistical hypothesis testing. This is a cornerstone of scientific inquiry and data-driven decision-making.

Key Takeaways:

  • Hypothesis testing involves a choice between a null hypothesis () and an alternative hypothesis ().
  • We can make two types of errors:
    • Type I Error: Rejecting a true . The probability of this is the significance level, .
    • Type II Error: Failing to reject a false . The probability of this is .
  • The power of a test () is its ability to correctly detect a true effect.
  • The decision is made by comparing a test statistic to a critical region, whose size is determined by .

Preview of the Next Lesson:
With this lesson, you have now concluded our modules on the mathematical foundations of linear algebra, calculus, optimization, probability, and statistics. You've explored the two main branches of inference: parameter estimation and hypothesis testing.

In our next module, we will begin applying all these powerful mathematical tools to build and understand our first machine learning model: Linear Regression. You will see how concepts like gradients, matrix operations, and probabilistic assumptions come together to create a predictive model.

Can't find a good explanation? Sign up and we'll make it for you

Sign up