Data Science Interview Prep: Q59
Z-test versus T-test: When and How to Use Them in Hypothesis Testing. (Category: Statistics)
How do you decide whether to use a Z-test or a t-test for evaluating population means, and what are the key differences between them?
Solution:
1. Overview of Z-test.
The Z-test is an appropriate hypothesis test for evaluating claims about a population mean when the population is normally distributed and the population variance (σ²) is known. It is used to determine whether a sample mean is significantly different from a specified population mean. Depending on your research question, the Z-test can be set up as a two-tailed test (to detect any difference) or a one-tailed test (to detect whether the sample mean is significantly greater than or less than the hypothesized mean). The Z-test relies on the standard normal distribution, which has a mean of 0 and a standard deviation of 1. The test statistic, called the Z-statistic, measures how many standard deviations the sample mean is from the hypothesized population mean, assuming the null hypothesis is true.
The formula for a Z-statistic with known population variance is given below:
To test a hypothesis, the Z-statistic is compared with the critical Z-value corresponding to the significance of the test. The table below shows the critical Z-values for the most common levels of significance:
If the absolute value of the Z-statistic is greater than the critical Z-value, you may reject the null hypothesis and conclude that your result is statistically significant.
When the sample size is large (n ≥ 30) and the population variance is unknown, the Z-statistic is:
Note: The sample standard deviation, s, in Equation (2) is only acceptable in a Z-test if the sample size is large (n ≥ 30) and the population variance is unknown.
However, the t-test is considered the more conservative measure when the population variance is unknown. This is because, unlike the z-test which relies on the normal distribution and assumes the variance is known, the t-test uses the t-distribution, which is specifically designed to account for the uncertainty that comes from estimating the variance using sample data.
The t-distribution differs from the normal distribution in one key way: it has heavier tails. These heavier tails reflect the greater variability we expect in sample statistics when the population variance is not known and must be estimated. In smaller samples, this estimation is especially unreliable, which increases the uncertainty in our statistical inferences. The heavier tails of the t-distribution mathematically adjust for this by allowing more probability in the outer regions of the distribution. This means extreme values are considered more likely under the t-distribution than under the normal distribution.
As a result, the t-test becomes more cautious in making conclusions. It produces wider confidence intervals, which signal less certainty about the true value of the population mean, and it yields higher p-values, meaning stronger evidence is required to reject the null hypothesis. In practical terms, the t-test is less likely to detect a statistically significant difference unless the data provides clear and strong evidence. This makes it a more conservative test—it errs on the side of not rejecting the null hypothesis unless it is clearly justified.
This conservatism serves a purpose: it helps control for the increased risk of Type I errors, or false positives, which is especially important when working with small sample sizes. As the sample size increases, our estimate of the population variance becomes more accurate, and the t-distribution starts to resemble the normal distribution. Consequently, the difference between the t-test and the z-test diminishes in large samples. But when the sample size is limited and the variance is unknown, the t-test remains the more cautious and statistically appropriate choice.
2. Overview of t-test.
The t-test is an appropriate hypothesis test for evaluating claims about a population mean when the population variance (σ²) is unknown. It is used to determine whether a sample mean is significantly different from a specified population mean or whether the means of two groups differ. Depending on your research question, the t-test can be set up as a two-tailed test (to detect any difference) or a one-tailed test (to detect whether the sample mean is significantly greater than or less than the hypothesized mean). The t-test relies on the t-distribution, which accounts for additional uncertainty due to estimating the population variance from the sample. The test statistic, called the t-statistic, measures how many estimated standard errors the sample mean is from the hypothesized population mean, assuming the null hypothesis is true.
You use the t-test if the population variance is unknown and either of the following conditions exist:
The sample size is large (n ≥ 30).
The sample size is small (n < 30), but the distribution of the population is normal or approximately normal.
If the sample size is small and the distribution is non-normal, the usual parametric tests (like the t-test) may not be valid. This is exactly when non-parametric tests become valuable — because they do not assume normality and are more robust to non-normal data, especially with small samples.
The computed value for the test statistic based on the t-distribution is known as the t-statistic.
The formula for a t-statistic with n - 1 degrees if freedom is given below:
To conduct a t-test, the calculated t-statistic is compared to a critical t-value at the chosen significance level, using the appropriate degrees of freedom (typically n−1). Like the Z-test, if the absolute value of the t-statistic exceeds the critical t-value, you can reject the null hypothesis and conclude that the result is statistically significant.
3. When do you use the Z-test vs. t-test?
You use the Z-test when:
The population variance (σ²) is known.
The sample size is large (n ≥ 30). This is because the Central Limit Theorem tells us that, with a large enough sample, the sampling distribution of the mean will be approximately normal, even if the underlying population isn’t.
If the sample size is large (n ≥ 30), you can also safely use a Z-test even if the population variance is unknown, because the t-distribution approaches the normal (Z) distribution as the degrees of freedom (n - 1) increase.
Additionally, you can use a Z-test for a population proportion (but not a t-test), provided the following conditions hold:
np0 ≥ 10 and n(1 - p0) ≥ 10, where p0 is the hypothesized population proportion under the null hypothesis. This ensures there are enough expected successes and failures to approximate a normal distribution, which is required for the Z-test on proportions.
You use the t-test when:
The population variance (σ²) is unknown and the sample size is large (n ≥ 30).
The sample size is small (n < 30), but the population distribution is normal (or approximately normal) and the population variance is unknown.
If the sample is small and the distribution is non-normal, parametric tests like the t-test may be invalid. In such cases, non-parametric tests are preferred since they don’t assume normality and handle small, non-normal samples better.
Below is a summary table comparing the criteria for using the Z-test and t-test:
We hope you found the article both enlightening and valuable! For more insightful content delivered straight to your inbox, simply enter your email address below and hit the subscribe button. Stay tuned for future updates!
Reference:
Z-test versus t-test: https://stats.stackexchange.com/questions/85804/choosing-between-z-test-and-t-test