☰

Type 1 error and Type 2 error

Type 1 Error and Type 2 Error: Definition, Examples and Differences

A smoke alarm that goes off when you burn toast is annoying. A smoke alarm that stays silent during a real fire is dangerous. Both are mistakes, but they are different mistakes, with different costs. Statistical tests make the same two kinds of mistakes, and learning to tell them apart is one of the most useful skills in data science.

Every hypothesis test is a decision made from limited data. You can never be certain, so there are two ways to be wrong. You can see an effect that is not there, which is a Type 1 error, or you can miss an effect that is there, which is a Type 2 error. Which one is worse depends on the situation.

This tutorial explains both errors with clear definitions, easy examples, the numbers that measure them (alpha, beta and power), a simulation that you can run, how the two errors trade off against each other, and how to reduce them. You should know what a null hypothesis is. The first section recaps it.

Type 1 error and Type 2 error explained

A Quick Recap: The Null Hypothesis

A hypothesis test starts with a null hypothesis, written H0 (H zero). It is the default position, usually that nothing special is happening: no difference, no effect, no link. The alternative hypothesis, written H1, says that there is an effect.

You collect data and ask how surprising it would be if H0 were true. If it is very surprising, you reject H0. If not, you fail to reject it. You never prove H0 true. You only fail to find enough evidence against it.

Type 1 Error Definition

A Type 1 error happens when you reject a null hypothesis that is actually true. It is a false positive: you claim an effect, but there is none. The probability of a Type 1 error is called alpha, and it is the significance level that you choose before the test, most often 0.05.

A significance level of 0.05 means that, when H0 is true, you accept a 5 percent chance of wrongly rejecting it.

Why does the Type 1 Error Matter?

You are usually the one who has to defend a claim of a discovery. A Type 1 error means acting on something that is not real: launching a feature that does not help, approving a drug that does not work, or publishing a result that cannot be repeated. The live page heading says why we use a Type 1 error. More exactly, you do not use it. You control it, by choosing alpha.

Example of a Type 1 Error

A criminal trial is a good model. The null hypothesis is that the accused is innocent, and the alternative is that the person is guilty. A Type 1 error is convicting an innocent person. You rejected innocence, which was true. The court sets a high bar, beyond reasonable doubt, to keep this error rare.

Type 1 error example: convicting an innocent person

Type 2 Error Definition

A Type 2 error happens when you fail to reject a null hypothesis that is actually false. It is a false negative: there is a real effect, but your test does not detect it. The probability of a Type 2 error is called beta.

The live page says that a Type 2 error produces a false positive and rejects the alternative hypothesis. That is wrong. It is the other way round, and the false positive belongs to the Type 1 error.

The related idea is power, which is 1 minus beta. Power is the chance that your test finds a real effect when one exists. Researchers usually aim for a power of 0.80 or higher.

Why does the Type 2 Error Matter?

A Type 2 error means missing something real: a drug that works is dropped, a fraud pattern goes unnoticed, or a design improvement is thrown away. It is easy to overlook, because nothing visibly goes wrong. You just never learn what you missed.

Example of a Type 2 Error

In the criminal trial, a Type 2 error is letting a guilty person go free. The null hypothesis of innocence was false, and the court did not reject it.

Now the clinical trial from the live page. A company tests a new cancer drug against an existing one in 9,000 patients. The null hypothesis is that the two drugs are equally effective. If the new drug really is better, but the trial fails to show it, that is a Type 2 error.

The live page says that beta is 2.5 percent, so the probability of a Type 2 error is 2.5 percent. That is correct as a reading of beta. It also means that the power is 97.5 percent, so if a real difference of the size that the trial was planned for exists, there is a 97.5 percent chance that the trial finds it. The size of 9,000 patients is what makes such a high power possible. The page does not say any of this.

The page also claims that equal numbers of patients on each drug show that both drugs work. Equal group sizes are a design choice that gives the test its best power. They say nothing about whether either drug is effective.

Type 1 vs Type 2 Error: The Decision Table

Decision table for Type 1 and Type 2 errors
Decision H0 is true (no real effect) H0 is false (real effect)
You reject H0 Type 1 error, a false positive. Probability is alpha Correct. This is a true positive. Probability is power, 1 minus beta
You fail to reject H0 Correct. A true negative. Probability is 1 minus alpha Type 2 error, a false negative. Probability is beta
Type 1 error and Type 2 error compared
Point Type 1 error Type 2 error
Also called False positive False negative
What happens You find an effect that is not there You miss an effect that is there
Probability Alpha, set by you, often 0.05 Beta, depends on sample size, effect size and alpha
Criminal trial Convict an innocent person Free a guilty person
Smoke alarm Alarm rings, no fire No alarm, real fire
Medical test Healthy person told they are ill Ill person told they are healthy

A memory trick: a Type 1 error means you cried wolf. A Type 2 error means that the wolf came and you did not notice.

See Both Errors in a Simulation

The best way to feel these numbers is to run them. I simulated two groups of 30 people each, with a standard deviation of 10, and ran a T test at alpha 0.05, 10,000 times.

Type 1 Error

First, both groups come from the same population, with a mean of 50. There is no real difference, so any rejection is a Type 1 error. The test rejected 5 percent of the time, which is exactly alpha.

Type 2 Error

Second, the groups have means of 50 and 55. There is a real difference, half a standard deviation. The test failed to find it 52.8 percent of the time, so beta is about 0.53, and the power is only 0.47. The theoretical power for this setup is 0.478, which matches. With 30 people per group, you would miss this real effect more than half the time.

Simulation results from 10,000 runs
Setup Result of 10,000 runs
No real difference, rejections 5.0 percent, equal to alpha
Real difference of 5, misses (beta) 52.8 percent
Real difference of 5, detections (power) 47.2 percent

The Trade Off Between the Two Errors

You cannot reduce both errors at once with the same data. Making the test stricter, with a smaller alpha, cuts false positives but raises false negatives. The numbers below are for the same setup, with 30 people per group and a real difference of half a standard deviation.

Alpha, power and beta for 30 people per group
Alpha Power Beta
0.01 0.244 0.756
0.05 0.478 0.522
0.10 0.606 0.394

A stricter alpha of 0.01 makes the test miss the real effect about three times in four. A looser alpha of 0.10 finds more real effects, but also gives more false alarms.

Which Error is Worse?

It depends on the cost, and you must decide before the test.

  • When a false positive is costly, such as approving an unsafe drug or convicting a person, use a small alpha.
  • When a miss is costly, such as screening for a serious disease or detecting fraud, accept a larger alpha and aim for high power.

How to Reduce the Errors?

  • Increase the sample size. This is the only way to cut beta without raising alpha. For a half standard deviation difference, you need 64 people per group for 80 percent power, and 86 for 90 percent.
  • Choose alpha on purpose. Do not use 0.05 just because everyone does.
  • Use a better design. Less noisy measurements and matched groups raise power.
  • Decide the effect size that matters before the test. Power is only defined for an effect of a given size.
  • Correct for many tests. If you run 20 independent tests at alpha 0.05 and nothing is real, the chance of at least one false positive is 1 minus 0.95 to the power 20 = 0.64. Methods such as the Bonferroni correction control this.

Where this Shows Up in Data Science

  • A and B tests. A false positive ships a change that does nothing. A false negative drops a good one.
  • Classification models. False positives and false negatives in a confusion matrix are the same two ideas.
  • Spam and fraud filters. The cost of each error differs, so the threshold is set to match.

Run the Simulation in Python

I ran the code below, and the output is real. It takes a few seconds.

python
import numpy as np
from scipy import stats
from statsmodels.stats.power import TTestIndPower

rng = np.random.default_rng(2)
trials = 10000
n = 30

rejects = 0
for _ in range(trials):
    a = rng.normal(50, 10, n)
    b = rng.normal(50, 10, n)
    if stats.ttest_ind(a, b).pvalue < 0.05:
        rejects += 1
print("Type 1 error rate (alpha 0.05):", round(rejects / trials, 3))

misses = 0
for _ in range(trials):
    a = rng.normal(50, 10, n)
    b = rng.normal(55, 10, n)
    if stats.ttest_ind(a, b).pvalue >= 0.05:
        misses += 1
beta = misses / trials
print("Type 2 error rate (beta):", round(beta, 3), " Power:", round(1 - beta, 3))

pw = TTestIndPower()
print("Theory power:", round(float(pw.power(effect_size=0.5, nobs1=30, alpha=0.05)), 3))
print("Per group for 80 percent power:", int(np.ceil(pw.solve_power(effect_size=0.5, power=0.8, alpha=0.05))))
output
Type 1 error rate (alpha 0.05): 0.05
Type 2 error rate (beta): 0.528  Power: 0.472
Theory power: 0.478
Per group for 80 percent power: 64

Common Mistakes to Avoid

Common mistakes and fixes
Mistake Fix
Calling a Type 2 error a false positive It is a false negative
Saying that a non significant result proves no effect It may be a Type 2 error. Check the power
Choosing alpha after seeing the data Set it before the test
Using a small sample and trusting a negative result Small samples have low power
Running many tests and reporting the one that worked Correct for multiple tests
Mixing up alpha and the p value Alpha is your chosen limit. The p value comes from the data
Thinking beta and alpha add up to 1 They are separate. Power is 1 minus beta

Practice Questions

  1. A spam filter marks a real email from your bank as spam. Is this a Type 1 or a Type 2 error? Take the null hypothesis as the email is not spam.
  2. A medical test has a power of 0.90. What is beta?
  3. You run 10 independent tests at alpha 0.05, and none of the effects are real. What is the chance of at least one false positive?
  4. Name one way to lower beta without raising alpha.

Answers: 1) A Type 1 error, because you rejected a true null hypothesis. 2) Beta = 1 minus 0.90 = 0.10. 3) 1 minus 0.95 to the power 10 = 0.40. 4) Increase the sample size. These are my own answers, so please recheck them before publishing.

Remember the two sentences: a Type 1 error is a false alarm, and a Type 2 error is a miss. Decide which one costs more before you run the test, set alpha and your sample size to match, and never treat a not significant result as proof of nothing.

Popular Tags:

Type 1 error and Type 2 error formula type 1 error and type 2 error in data science type 1 error and type 2 error in statistics Type 1 error and Type 2 error tutorial type 1 error and type 2 error with examples