What is a one-sample z-test?
A one-sample z-test is performed to check whether the difference between the population mean and the sample mean is statistically significant. For example, let’s say the average weight of a class of students is known to be 50 kg. In a particular year, the weights of the students of the class are measured and the average weight is found to be 52 kg. If we want to know whether the difference in the mean weights is statistically significant, we can perform a one-sample Z-test.
This test can be performed when the standard deviation of the population is known and the test statistic under the null hypothesis can be approximated by a normal distribution. Also, the sample size should be sufficiently large, usually more than or equal to 30.
How to calculate the test statistic in a one-sample z-test?
A z-score can be calculated using the following formula:
How to calculate the test statistic for a one-sample z-test using Python?
The test statistic for a one-sample z-test can be calculated using Python using the following code:
import numpy D = [102.4502852, 101.47561459, 99.27940105, 100.77693863, 102.73502774, 97.59395299, 97.18690695, 101.82846362, 98.58161117, 98.46340124, 98.53757088, 100.88048796, 99.56121938, 105.84680455, 92.77313179, 99.40285498, 105.4891317, 102.88286575, 96.44793538, 93.82130758, 103.1808137, 106.86320712, 101.66205785, 94.79902808, 90.00296523, 97.24459541, 104.19236957, 96.9550612, 94.06118967, 96.20057025, 99.35729444, 103.99843456, 96.43199551, 100.95166524, 98.53785432, 107.12521493, 91.5673998, 97.67862846, 104.18322797, 94.24536305] population_sigma = 5 sample_size = len(D) population_mean = 100 sample_mean = numpy.mean(D) z_score = (sample_mean - population_mean)/(population_sigma/math.sqrt(sample_size)) print(z_score)
Here, D contains the data (here, the heights of students in cm). The population mean is 100. And the population sigma is 5. We …
0 Comments