Sure, let’s walk through an example of a Z-test.

Imagine we’re working for a company that manufactures light bulbs. The company claims that its light bulbs have an average lifespan of 1,500 hours. We suspect this might not be accurate, so we conduct a test. We take a sample of 50 light bulbs and find that the average lifespan is 1,480 hours with a standard deviation of 100 hours.

Our null hypothesis, , is that the average lifespan of the light bulbs is 1,500 hours, as the company claims. The alternative hypothesis, , is that the average lifespan is not 1,500 hours.

Let’s conduct a Z-test to test our hypothesis. The Z-statistic is calculated as follows:

where:

  •  is the sample mean (1,480 hours in our case),
  • is the population mean (1,500 hours according to the company),
  • is the standard deviation of the sample (100 hours),
  • is the sample size (50 light bulbs).

We’ll use a significance level of 0.05. If our calculated Z-score is beyond the critical Z-score (approximately ±1.96 for a two-tailed test with  ), we’ll reject the null hypothesis.

Let’s calculate.

import math

# given values
sample_mean = 1480 # sample mean
pop_mean = 1500 # population mean
std_dev = 100 # standard deviation
n = 50 # sample size

# calculate z-score
z = (sample_mean - pop_mean) / (std_dev / math.sqrt(n))
z
RESULT
-1.4142135623730951

The calculated Z-score is approximately -1.41.

When we compare this value with the critical Z-score (±1.96 for a two-tailed test at the 0.05 significance level), we find that -1.41 is within the range -1.96 to 1.96.

Hence, we fail to reject the null hypothesis. This means that the sample data does not provide enough evidence to conclude that the company’s claim about the average lifespan of the light bulbs is incorrect.

Please note that “failing to reject” the null hypothesis is not the same as “accepting” it. We are simply saying that based on the sample data we have, we do not have enough evidence to reject the null hypothesis.

Leave a Reply

Your email address will not be published. Required fields are marked *

DeepNeuron