Learning Guides
Hypothesis Testing Using Z-Test: Complete Guide
Quick answer: Learn the Z-test for hypothesis testing, including when to use it, the null and alternative hypothesis, calculating the Z-statistic, and interpreting the p-value.
What is a Z-Test?
A Z-test is a statistical hypothesis test used to determine whether a sample mean differs significantly from a known population mean, or whether two sample means differ from each other, when the population standard deviation is known and the sample size is reasonably large, typically above 30.
Null and Alternative Hypothesis
The null hypothesis (H0) usually states there is no real difference. The alternative hypothesis (H1) states that a real difference does exist. The test calculates how likely the observed data would be if the null hypothesis were actually true.
The Z-Statistic Formula
Z = (sample_mean - population_mean) / (population_std_dev / sqrt(sample_size))
A Worked Example
Suppose a training company claims its average course completion time is 40 hours with a known population standard deviation of 5 hours. A sample of 50 recent students completed the course in an average of 42 hours. Is this difference statistically significant?
import numpy as np
from scipy import stats
sample_mean = 42
population_mean = 40
population_std = 5
n = 50
z_statistic = (sample_mean - population_mean) / (population_std / np.sqrt(n))
p_value = 2 * (1 - stats.norm.cdf(abs(z_statistic)))
print(f"Z-statistic: {z_statistic:.2f}, p-value: {p_value:.4f}")
Interpreting the Result
If the resulting p-value is below the chosen significance level, commonly 0.05, the difference is considered statistically significant, meaning it is unlikely to have occurred by random chance alone, and the null hypothesis is rejected.
One-Tailed vs Two-Tailed Tests
A two-tailed test checks whether the sample mean differs from the population mean in either direction. A one-tailed test checks for a difference in one specific direction only, such as testing whether completion time is specifically higher, not just different. The choice depends on the actual business or research question being asked.
Z-Test vs T-Test
| Z-test | T-test |
|---|---|
| Population standard deviation is known | Population standard deviation is unknown, estimated from the sample |
| Typically used with large samples (n > 30) | Commonly used with smaller samples |
In practice, the population standard deviation is rarely known with certainty, which is why the t-test is used far more often than the Z-test in real world analysis.
Common Interview Questions
When would you use a Z-test instead of a t-test?
When the population standard deviation is genuinely known and the sample size is reasonably large, conditions that are actually fairly uncommon in most real world business analysis.
What does a p-value below 0.05 mean in a Z-test?
It means the observed difference is unlikely to have occurred by random chance alone under the null hypothesis, leading to rejection of the null hypothesis at the standard 5 percent significance level.
FAQ
Frequently Asked Questions
What is a Z-test used for?
It tests whether a sample mean differs significantly from a known population mean, when the population standard deviation is known and the sample size is reasonably large.
What is the difference between a Z-test and a t-test?
A Z-test requires a known population standard deviation and is used with larger samples. A t-test is used when the population standard deviation is unknown and estimated from the sample, which is far more common in practice.
What does the p-value tell you in a Z-test?
It indicates the probability of observing a difference this large or larger if the null hypothesis were true. A p-value below 0.05 typically leads to rejecting the null hypothesis.
What is the difference between a one-tailed and two-tailed Z-test?
A two-tailed test checks for a difference in either direction. A one-tailed test checks for a difference in one specific direction only, based on the actual question being asked.
Keep Reading
Related Articles
Learning Guides
INNER JOIN in SQL with Examples: Complete Beginner's Guide
Learn INNER JOIN in SQL with practical examples, syntax, interview questions, and real-world use cases. A complete beginner-friendly SQL JOI
Learning Guides
OUTER JOIN in SQL: Complete Guide with Examples for Beginners
Master OUTER JOIN in SQL with practical examples and real-world scenarios. Learn LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, syntax, use cases,
Learning Guides
Multi-Row Functions in SQL: Complete Guide with Examples
Learn multi-row (aggregate) functions in SQL including SUM, AVG, COUNT, MIN, MAX, GROUP BY and HAVING, with practical examples, NULL handlin