# When to Use Z-test vs T-test: Differences, Examples When it comes to statistical tests, z-test and t-test are two of the most commonly used. But what is the difference between z-test and t-test? And when should you use Z-test vs T-test? In this blog post, we will answer all these questions and more! We will start by explaining the difference between z-test and t-test in terms of their formulas. Then we will go over some examples so that you can see how each test is used in practice. As data scientists, it is important to understand the difference between z-test and t-test so that you can choose the right test for your data. Let’s get started!

## Difference between Z-test and T-test

Z-test is a statistical hypothesis testing technique which is used to test the null hypothesis in relation to the following given that the population’s standard deviation is known and the data belongs to normal distribution:

• There is no difference between the sample and the population. Or, the difference between the sample and the population mean is not statistically significant. This hypothesis can be tested using one-sample Z-test for means. In other words, one-sample Z-test for means can be used to test the hypothesis that the sample belongs to the population. In this test, the mean of the sample is compared against the population mean in the sampling distribution. The standard error in the formula given below is the standard deviation of sample mean in the sampling distribution. The formula for Z-statistics for one-sample Z-test for means is the following. Read greater details in this blog, one-sample Z-test for means.

Z = (X̄ – µ)/SE

= (X̄ – µ)/σ/√n, , where SE is the standard error, is the sample mean, µ is the population mean, σ is the population standard deviation and the n is the sample size

T-test is a statistical hypothesis technique which is used to test the null hypothesis in relation to the following given the population standard deviation is unknown, data belongs to normal distribution, and the sample size is small (size less than 30)

• There is no difference between the sample and the population given the population standard deviation is known and the sample size is small. This is very much similar to one-sample Z-test for means. Greater details can be read in this blog, one-sample t-test for means. The formula for t-statistics look like the following. Note that the sample mean is compared with the population mean as like in one sample Z-test. However, the difference lies in how the standard error is calculated as the ratio of standard deviation of the sample and the square root of the sample size.

T = (X̄ – μ) / SE

= (X̄ – μ) / S/√n, where SE is the standard error, is the sample mean, µ is the population mean, S is the sample standard deviation and the n is the sample size. Note the difference between the Z-statistics and T-statistics in one-sample Z-test and one-sample T-test in relation to usage of population standard deviation σ in case of Z-test while sample standard deviation, S in case of T-test.

Other differences between the Z-test and T-test are the following:

• While Z-test makes use of Z-distribution or standard normal distribution, T-test makes use of T-distribution.
• While T-test makes use of degree of freedoms for calculation of T-statistics, Z-test don’t need the determination of degrees of freedom.
• For independent samples with equal variance, use t-statistics instead of z-tests as z-test only applies when populations don’t differ too much in their respective standard deviations.

## When to use Z-test vs T-test?

The following is a simplistic diagram which specifies when to use Z-test vs T-test: Note some of the following in the above diagram:

• If the population standard deviation is known and the sample size is greater than 30, Z-test is recommended to be used.
• If the population standard deviation is known, and the size of the sample is less than or equal to 30, T-test is recommended
• If the population standard deviation is unknown, T-test is recommended.

## Summary

The z-test and t-test are different statistical hypothesis tests that help determine whether there is a difference between two population means or proportions. The z-statistic is used to test for the null hypothesis in relation to whether there is a difference between the populations means or proportions given the population standard deviation is known, data belongs to normal distribution, and sample size is larger enough (greater than 30). T-tests are used when the population standard deviation is unknown, the data belongs to normal distribution and the sample size is small (lesser than 30). • • • 