Skip to content
Pixel
العربية

6-1Unit 6 · Analysis and Communication

Statistical Inference

12 min readStart exercises
In this lesson
  1. The Big Idea
  2. From Sample to Population: What Is Statistical Inference?
  3. Point Estimation and Interval Estimation
  4. The Idea Behind Hypothesis Testing
  5. The Steps of a Hypothesis Test
  6. The Main Hypothesis Tests
  7. Cautions When Interpreting Inference
  8. Try It Yourself
  9. Common Mistakes
  10. Key Points
  11. FAQ

The Big Idea

We usually can't measure or ask everyone in a population, so we take a sample and use its results to say something about the whole population. That is statistical inference. It works in two ways: estimation answers "about how much?", and hypothesis testing answers "do the data give enough evidence against the null hypothesis?". Because a sample is only part of the whole, every answer carries some uncertainty. The real skill is to measure that uncertainty and report it, not to hide it.

From Sample to Population: What Is Statistical Inference?

Statistical inference means using data from a sample to estimate properties of a population or to test claims about it, while taking uncertainty and the conditions of the study design into account. Why a sample? Because studying every single member is often impossible or far too expensive: you can't measure the height of every student in Egypt or survey every customer of an online shop.

The book splits statistical inference into two main approaches:

| Approach | What it does | Example | |---|---|---| | Estimation | Uses sample data to estimate a population property, as a single value or as a range of values | Inferring the average height of the student population from the average height of a sample | | Hypothesis testing | Assesses how strongly the data conflict with the null hypothesis, under a given model and assumptions | Checking whether the data give evidence that two learning methods perform differently |

In both cases we judge the population after seeing only a part of it. So inference always involves uncertainty, and the judgement is made with that uncertainty in mind, not by ignoring it.

Point Estimation and Interval Estimation

Suppose you measured the heights of a sample of students and their average was 168 cm. What can you say about the average height of the whole population? You have two options.

Point estimation: one value

Point estimation estimates a population property with a single value calculated from the sample: "Our best estimate of the population's average height is 168 cm."

Its strength is that it's easy to understand, because it is one number. Its weakness is that the uncertainty is invisible: the number 168 doesn't tell you whether the estimate is very precise or could be far from the truth.

Interval estimation: a range

Interval estimation estimates that a population property lies within a certain range: "The population's average height most likely lies between 166 cm and 170 cm." This range is called a confidence interval.

An interval has a width, so it needs more care to interpret, but its big advantage is that it shows how uncertain we are: a narrow interval means a more precise estimate, a wide one a less precise estimate. Notice that the interval 166 to 170 has its midpoint at 168, the point estimate itself, and a width of 4 cm.

Point estimate, interval estimate and what a confidence level means Two panels. The first is a number line of heights in centimetres from 160 to 176: a single dot at 168 is the point estimate, and a band from 166 to 170 is the interval estimate, or confidence interval. The second illustrates a 95% confidence level: twenty different samples, each with an interval built the same way, and a dashed vertical line for the unknown true population value. Nineteen intervals cross the line in green and one misses it in red. The note says about 95% of the intervals contain the true value; this describes the method, not one particular interval. 1) One value or a range? 160 162 164 166 168 170 172 174 176 cm Interval estimate (confidence interval): 166 to 170 Point estimate: 168 2) What a 95% confidence level means (illustration) True value (unknown) Each row is a new sample, and its interval (same method) Contains the true value Misses it About 95% of the intervals catch the true value: this describes the method
A point estimate is one number that hides uncertainty; an interval shows it. The confidence level describes how often the method succeeds when repeated.

What does a 95% confidence level mean?

Every confidence interval is built at a chosen confidence level, such as 95%. Many students get this wrong, so read carefully:

  • The confidence level describes how well the method for building intervals performs when sampling is repeated.
  • If we took many new samples and built an interval from each one in the same way, about 95% of those intervals would contain the true population value, and a few would miss it.
  • So 95% is not "the probability that this particular interval contains the true value". Once a particular interval is built, it either contains the true value or it doesn't, and we don't know which.
  • The confidence level is chosen before the analysis, according to the purpose of the study.

The Idea Behind Hypothesis Testing

Sometimes we don't want an estimate; we want to judge a claim: "Does the new learning method really raise average scores?" This is where hypothesis testing comes in. It is a procedure that uses data to assess the evidence against the null hypothesis; it does not prove a hypothesis true or false with certainty.

The two hypotheses

| Hypothesis | Meaning | Example (a new learning method) | |---|---|---| | Null hypothesis (H0) | The starting point we test, usually "no difference" or "no relationship" | There is no difference in average score between the two methods | | Alternative hypothesis (H1) | Describes the difference or relationship the question is interested in; we look for evidence for it when the data don't fit H0 well enough | The new method gives a higher average score |

How the reasoning goes

We temporarily assume H0 is true and ask: if H0 really were true, how unusual would the result we saw, or a more extreme one, be? A suitable test measures this. The less compatible the result is with H0, the stronger the statistical evidence against it.

In the end there are only two possible verdicts on the null hypothesis:

  • Reject H0: the data give enough evidence against it.
  • Do not reject H0: the data don't give enough evidence against it.

The Steps of a Hypothesis Test

A hypothesis test follows four steps in this order:

  1. State the null hypothesis H0 and the alternative hypothesis H1 to fit the question, before looking at the result.
  2. Set the significance level α in advance. Common values are 0.05 and 0.01.
  3. Choose a suitable test, check its assumptions, then compute the p-value from the data.
  4. Compare the p-value with the significance level and make a decision.

The p-value and the significance level

  • p-value: the probability of getting a result as extreme as the observed one or more extreme, assuming H0 is true and according to the test's model. The smaller it is, the less compatible the result is with H0. But it is not the probability that H0 is true.
  • Significance level (α): the threshold the researcher sets in advance for deciding to reject H0. It is linked to the probability of a Type I error under the test's conditions.

Put simply: p comes from the data, while α is set by the researcher before the data as the dividing line.

The decision rule

| Condition | Decision | |---|---| | p ≤ α | Reject H0. The result is statistically significant at the chosen α, but this does not prove H1 with certainty | | p > α | Do not reject H0. We cannot claim statistical significance |

Worked example: the new learning method

A school claims that a new learning method gives a higher average score than the traditional method. How do we test the claim?

Hypothesis-testing steps with the new learning method example Four steps from top to bottom for the example: does the new learning method give a higher average score than the traditional one? Step 1: state the hypotheses before seeing the result; null hypothesis H0: no difference in average scores, alternative hypothesis H1: the new method has a higher average. Step 2: set the significance level in advance, alpha = 0.05. Step 3: choose a suitable test, check its assumptions and compute the p-value from the data, p = 0.02. Step 4: compare and decide; 0.02 is less than or equal to 0.05, so reject H0; the result is statistically significant without proving H1 with certainty. At the bottom, the decision rule: if p ≤ alpha, reject H0; if p > alpha, do not reject H0. 1 State the hypotheses before seeing results H0: no difference in average score H1: the new method has a higher average 2 Set the significance level in advance α = 0.05 The bar is fixed before seeing the data 3 Choose the test and compute the p-value p = 0.02 after checking the test's assumptions 4 Compare and decide 0.02 ≤ 0.05 → reject H0 Significant, but not proof of H1 Decision rule (Arabic edition) p ≤ α → reject H0 p > α → do not reject H0
The four steps with the book's example: the hypotheses and the significance level are fixed before seeing the result.
  • Step 1: H0: "There is no difference in average score between the two methods." H1: "The new method gives a higher average." Notice that we put the opposite of the claim in H0 and test it.
  • Step 2: We set α = 0.05 before seeing the result.
  • Step 3: The data give a p-value of p = 0.02.
  • Step 4: Since 0.02 ≤ 0.05, we reject H0. The result is statistically significant: the data give evidence that the new method has a higher average score, but this is not certain proof.

The Main Hypothesis Tests

Which test you use depends on the purpose of the analysis and the type of data. The book highlights two tests. You don't need to calculate them, only to know when each one is used:

| Test | Main use | Example | |---|---|---| | t-test | A family of tests for comparing means in particular situations; the lesson's example compares the means of two groups | Does students' average test score differ between a new learning method and the traditional one? | | Chi-squared test | Test of independence: checks whether there is a relationship between two categorical variables in a contingency table | In survey results, is there a relationship between gender and favourite school subject? |

An easy way to tell them apart: if the data are numbers whose mean you compare (scores, times, heights) between two groups, think t-test. If the data are categories you count (gender, governorate, favourite subject) and you ask whether two of them are related, think chi-squared test.

Cautions When Interpreting Inference

Type I and Type II errors

Because we judge from a sample, there is always a chance that our decision is wrong. There are two kinds of error:

| Error | What happened | In everyday terms | |---|---|---| | Type I error | We rejected H0 when it was actually true | A false alarm: we said "there's a difference" when there isn't one | | Type II error | We did not reject H0 when it was actually false | A missed discovery: we said "no evidence" when the difference is real |

The two types of error in hypothesis testing A two-by-two table. The columns are reality: the null hypothesis is actually true, or it is actually false. The rows are our decision: reject H0, or do not reject H0. Rejecting H0 when it is true is a Type I error, a false alarm. Not rejecting H0 when it is false is a Type II error, a missed discovery. The other two cells are correct decisions. Below: with sample size and design fixed, lowering alpha reduces Type I errors but may increase Type II errors; a larger sample or better design can sometimes reduce both. Reality (never known for sure) H0 actually true H0 actually false Our decision Reject H0 Do not reject H0 Type I error False alarm Correct decision ✓ Correct decision ✓ Type II error Missed discovery Sample size and design fixed: lower α → fewer Type I, possibly more Type II A larger sample or better design can sometimes reduce both
A Type I error is a false alarm; a Type II error is a missed discovery.

How the two errors are linked (a trade-off): if the sample size, study design and other factors stay the same, lowering α (say from 0.05 to 0.01) makes rejection harder, so the chance of a Type I error goes down, but the chance of a Type II error may go up. We aren't stuck, though: improving the design or increasing the sample size can sometimes reduce both.

Don't misread the p-value

The book warns against three misunderstandings of p:

  1. The p-value is not "the probability that H0 is true". It is the probability of a result this extreme or more if we assume H0 is true.
  2. A small p-value does not mean the effect is large. The difference could be tiny and the sample huge.
  3. The "p versus α" decision is a procedural rule of the test. On its own it doesn't prove the result is correct, doesn't show it matters in practice, and doesn't settle scientific truth.

Statistical significance is not practical importance

A statistically significant result is one where we rejected H0 at the chosen α. A practically important result is one where the difference is large enough to make a real-world difference. These are different things.

The book's example: an experiment compares two website designs, new and old, using click-rate data from 100,000 people. The new design's click rate is only 0.1 percentage points higher. Because the data set is so large, this tiny difference is likely to be statistically significant. But is a 0.1-point difference worth the cost of changing the website? Does it bring real profit or a better user experience? That has to be judged from a separate point of view: cost, benefit, size of the effect and user experience.

To sum up: statistical inference is a powerful way to draw conclusions from data, but it is a judgement tool that carries uncertainty. So don't stop at the p-value; also look at the size of the effect, the confidence interval, the study design and the cost of the decision.

Try It Yourself

Try
A/B test: real difference or chance? And does it matter?
A
B
Rate A
0.4%
Rate B
0.5%
Difference (B − A) · percentage points
+0.1
p-value
0.0182
Two-proportion z-test (two-sided, normal approximation)
p̂ = (200 + 250) / (50,000 + 50,000) = 0.0045
SE = √(p̂(1 − p̂)(1/50,000 + 1/50,000)) = 0.000423
z = (0.005 − 0.004) / SE = 2.362
p = 2 × (1 − Φ(|z|)) = 0.0182 ≤ α = 0.05
Likely statistically significant at α = 0.05 (p ≤ α): reject H0.
Statistically significant does not mean practically important: is the difference worth the cost?

Try this in the calculator: enter visitors and clicks for two designs, then increase the number of visitors while keeping the two rates roughly the same. Watch how a very small difference can become "likely significant" as the sample grows, then ask yourself: does this difference actually matter to the site owner?

Try
Steps of a hypothesis test
The school canteen wants to know whether its average daily sales changed after adding a new meal. Put the steps of the test in order.
1. Set the significance level in advance, say α = 0.05
2. State H0: average sales did not change, and H1: the average changed, before seeing any results
3. Compare p with α: if p ≤ α reject H0, otherwise do not reject it
4. Choose a suitable test, check its assumptions and compute the p-value from the sales data
5. Interpret carefully: is the difference big enough to matter to the canteen in practice?
Use the up and down buttons to move each step, then press Check.
Try
False alarm or missed discovery?
In each situation the null hypothesis H0 says: “there is no difference or effect”. Is it a Type I error or a Type II error?
Items (8)
Tap an item to select it, then tap the category it belongs to.
Nothing here yet
Nothing here yet

Common Mistakes

"p = 0.02 means there's a 2% chance the null hypothesis is true"

The p-value is calculated assuming H0 is true, so it can't be the probability that H0 is true.

p = 0.02 means: if H0 were true, getting a result this extreme or more would be rare (about 2% under the test's model), so it is evidence against H0.

"We didn't reject H0, so we proved it's true"

Not rejecting only means the evidence wasn't strong enough. The difference may be real and the sample small, which is a Type II error.

Say "we do not reject H0" or "the result is not statistically significant", never "H0 has been proved".

"It's statistically significant, so it matters and we should act on it at once"

With huge data, a tiny difference, like 0.1 percentage points, can become statistically significant.

Statistical significance and practical importance are different. Practical importance is judged by the size of the effect and the cost and benefit of the decision.

"A 95% confidence interval means the true value is inside this interval with 95% probability"

According to the book, the confidence level describes the method for building intervals, not a probability for one particular interval.

If we repeated the sampling and built intervals the same way many times, about 95% of them would contain the true value.

"The smaller p is, the bigger the effect"

A small p can come from a large effect, or from a small effect with a huge sample.

p measures how strongly the data conflict with H0. The size of the effect is looked at separately, for example the difference itself or the confidence interval.

Key Points

  • Statistical inference: using sample data to estimate population properties or test claims about them, while accounting for uncertainty. Its two approaches are estimation and hypothesis testing.
  • A point estimate is one easy-to-read value that hides uncertainty; an interval estimate is a range, called a confidence interval, that shows it.
  • A confidence level (e.g. 95%) describes how the interval-building method performs when repeated, and is chosen before the analysis.
  • A hypothesis test assesses the evidence against the null hypothesis H0 (no difference or no relationship) versus the alternative hypothesis H1, and proves neither with certainty.
  • The steps: hypotheses, then α in advance, then compute p, then decide: p ≤ α reject H0, p > α do not reject H0 (Arabic edition).
  • A t-test compares means; a chi-squared test checks for a relationship between two categorical variables.
  • Type I error: rejecting a true H0. Type II error: not rejecting a false H0. Lowering α reduces the first and may increase the second.
  • p is not the probability that H0 is true, a small p doesn't mean a big effect, and statistical significance is not practical importance.

FAQ

What's the difference between the p-value and the significance level α?

α is set by the researcher in advance, before seeing the data, as the cut-off for rejecting H0, such as 0.05. The p-value is calculated from the data: the probability of a result this extreme or more if H0 were true. Then you compare them: if p ≤ α, reject H0.

Why do we say "do not reject H0" instead of "accept H0"?

Because not having enough evidence against H0 doesn't prove it is true. There may be a real difference that the sample was too small to detect, which is called a Type II error. It's like a court saying "not guilty" rather than "proven innocent".

Does the significance level always have to be 0.05?

No. The book's common values are 0.05 and 0.01, and the level is chosen in advance to suit the purpose. If a false alarm would be very costly, choose a smaller α, keeping in mind that this may raise the chance of a Type II error if the sample and design stay the same.

How do I know whether to use a t-test or a chi-squared test?

Look at the type of data and the question. If you are comparing the mean of numeric values between two groups, such as average scores under two teaching methods, it's a t-test. If you are checking whether two categorical variables are related, such as gender and favourite subject, it's a chi-squared test.

Done reading? Test yourself