Courses / Computer Science XII (HSSC-II) – FBISE Complete SLO-Based Course
4.4 Hypothesis Testing: Null and Alternative Hypotheses, P-values and Conclusions
Unit 4 – Data and Analysis · 90 min read · 9 MCQs to check yourself
StatQuest – p-values: what they are and how to interpret them
1. Hypotheses
A hypothesis is a testable statement about a population.
- Null hypothesis (H₀): “nothing special is happening” – no effect, no difference. The new study technique does not change average marks.
- Alternative hypothesis (H₁ or Hₐ): what the researcher suspects – there is an effect. The new technique increases average marks.
We assume H₀ is true and ask: if H₀ were true, how surprising is our data?
2. Significance level and p-value
- Significance level (α): the cut-off we choose before the test, usually 0.05 (5%). It is the probability of rejecting H₀ when it is actually true (a Type I error) that we are willing to accept.
- P-value: the probability of getting results at least as extreme as ours if H₀ is true.
- p ≤ α → the result is statistically significant → reject H₀ (evidence for H₁).
- p > α → fail to reject H₀ (not enough evidence – which is not the same as proving H₀).
| H₀ actually true | H₀ actually false | |
|---|---|---|
| Reject H₀ | Type I error (false alarm) – probability α | Correct decision |
| Fail to reject H₀ | Correct decision | Type II error (missed effect) |
3. Example – is a coin fair?
H₀: the coin is fair (P(heads) = 0.5). H₁: the coin favours heads (P(heads) > 0.5). α = 0.05. We toss it 100 times and get 60 heads.
Estimating the p-value by simulation: imagine a fair coin tossed 100 times, repeat this 10,000 times, and count how often we get 60 or more heads.
import random
random.seed(42)
observed = 60
trials = 10000
extreme = 0
for _ in range(trials):
heads = sum(random.random() < 0.5 for _ in range(100)) # one experiment with a FAIR coin
if heads >= observed:
extreme += 1
p_value = extreme / trials
print("estimated p-value:", p_value)
print("reject H0" if p_value <= 0.05 else "fail to reject H0")
Output:
estimated p-value: 0.0292
reject H0
A fair coin gives 60 or more heads only about 3 times in 100 experiments, so p ≈ 0.03 < 0.05 → reject H₀: the evidence suggests the coin favours heads. The histogram ties the conclusion to a visual: the observed value sits in the rare red tail.
4. Example – a new study technique (model paper Q4)
A researcher compares two groups of 30 students each, chosen at random: Group A uses the new study technique, Group B studies normally.
- H₀: mean marks of A = mean marks of B (the technique has no effect).
- H₁: mean marks of A > mean marks of B.
- α = 0.05. Results: A averages 74, B averages 68.
Permutation (shuffle) simulation: if the technique made no difference, the group labels would not matter. Shuffle all 60 marks into two random groups many times and see how often the difference is 6 or more.
import random
random.seed(7)
group_a = [74, 81, 69, 77, 72, 85, 70, 66, 79, 73, 76, 71, 68, 80, 75,
78, 67, 74, 72, 83, 70, 76, 69, 75, 73, 77, 71, 79, 72, 68]
group_b = [68, 72, 61, 70, 66, 74, 63, 69, 65, 71, 67, 64, 73, 62, 70,
66, 69, 68, 75, 60, 67, 71, 65, 69, 64, 72, 66, 70, 63, 67]
mean = lambda xs: sum(xs) / len(xs)
observed = mean(group_a) - mean(group_b)
pooled = group_a + group_b
count = 0
for _ in range(10000):
random.shuffle(pooled)
if mean(pooled[:30]) - mean(pooled[30:]) >= observed:
count += 1
print(f"observed difference = {observed:.2f} marks")
print("estimated p-value =", count / 10000)
Output:
observed difference = 6.43 marks
estimated p-value = 0.0
Not one of the 10,000 shuffles produced a difference as large as 6.43, so the estimated p-value is below 1/10,000 – far below 0.05 → reject H₀. Communicate: “Students using the new technique scored about 6 marks higher on average; a difference this large would almost never happen by chance (p < 0.001).” Show a bar chart of the two means (with error bars) or histograms of both groups, and note limits (one school, short period).
5. Common mistakes
- The p-value is not the probability that H₀ is true.
- “Fail to reject H₀” does not prove H₀ – maybe the sample was too small.
- Statistically significant ≠ practically important (a 0.2-mark gain may be significant with a huge sample but useless).
- Decide α before looking at the data.
Short and long questions
1. A researcher is studying the effect of a new study technique on student performance. (a) In the above context define the null and alternative hypotheses. (b) Explain the role of p-values in hypothesis testing. (c) Communicate your findings using data visuals. (2 + 2 + 2)
Model answer
(a) Hypotheses (2):
- H₀ (null): the new study technique has no effect – mean marks of students using it equal mean marks of students who do not (μ_new = μ_old).
- H₁ (alternative): the technique improves performance – μ_new > μ_old.
(b) Role of p-values (2): after collecting marks from randomly assigned groups, the researcher computes the difference in means and its p-value – the probability of seeing a difference at least this large if H₀ were true (estimated with a t-test or a shuffle simulation). The p-value is compared with α = 0.05: if p ≤ 0.05 the difference is statistically significant → reject H₀ and conclude the technique helps; if p > 0.05 → not enough evidence. The p-value measures strength of evidence, not the size or importance of the effect.
(c) Communicating with visuals (2):
- A bar chart of mean marks for both groups with error bars and the p-value written on it (“+6 marks, p < 0.001”).
- Histograms or box plots of both groups to show the whole distributions and spread.
- A histogram of the simulated null distribution with a line at the observed difference, showing it lies in the extreme tail. Add a clear title stating the conclusion and a note on limitations (sample size, one school).
2. A coin is tossed 100 times and lands heads 60 times. In 10,000 simulations of a fair coin, 60 or more heads occurred 284 times. Estimate the p-value and give a conclusion at α = 0.05.
Model answer
H₀: the coin is fair; H₁: the coin favours heads. p-value ≈ 284 / 10,000 = 0.0284. Since 0.0284 < 0.05, reject H₀ – there is significant evidence that the coin is biased towards heads.
3. Explain Type I and Type II errors with an example.
Model answer
Example: testing whether a new drug works (H₀: no effect).
- Type I error: rejecting a true H₀ – concluding the drug works when it does not (false alarm).
- Type II error: failing to reject a false H₀ – concluding no effect when the drug really works (missed effect).
4. What is meant by significance level (α)? Why is 0.05 commonly used?
Model answer
The significance level α is the threshold chosen before the test for rejecting H₀; it equals the probability of a Type I error (rejecting a true H₀) that we accept. 0.05 means we accept a 5% risk of a false alarm – a common balance between being too strict (missing real effects) and too loose (false discoveries).
5. Differentiate between the null hypothesis and the alternative hypothesis with an example.
Model answer
- Null hypothesis (H₀): states no effect/no difference – “The new teaching app does not change average marks.”
- Alternative hypothesis (H₁): states the effect the researcher expects – “The new teaching app increases average marks.” The test assumes H₀ and checks whether the data give strong evidence against it.
6. What is a p-value? How is it used to make a conclusion in a significance test?
Model answer
The p-value is the probability of obtaining results at least as extreme as the observed ones if the null hypothesis is true. Compare it with the significance level α (e.g. 0.05): if p ≤ α, reject H₀ (the result is statistically significant); if p > α, fail to reject H₀ (not enough evidence).
This lesson ends with a quiz of 9 MCQs. Open the lesson on PrepOasis to take it and save your progress.
Previous: 4.3 Data Visualisation and Data Storytelling with SQL and Python · Next: Unit 4 Review, Situational Quiz and Unit Test
All lessons in Computer Science XII (HSSC-II) – FBISE Complete SLO-Based Course