Z Tests

One Sample Z Test: Formula, Example, Calculator, SPSS, R, Python and Excel Guide

One Sample Z Test formula example with observed mean, hypothesized mean, known sigma, z statistic, p-value, SPSS, R, Python and Excel workflow
Advertisement
Google AdSense Top placement reserved here

One-Sample Mean Hypothesis Test

One Sample Z Test is used to test whether a sample mean is significantly different from, greater than, or less than a hypothesized population mean when the population standard deviation is known. This guide explains the formula, assumptions, calculator logic, SPSS output, R workflow, Python validation and Excel method using student-por.csv final grade data. The worked example tests whether the mean final grade G3 is greater than 11.5, using known sigma = 3.23.

Advertisement
Google AdSense top placement reserved here

Quick Answer: One Sample Z Test Result

The One Sample Z Test was applied to the numeric variable G3, the final grade score in the student performance dataset. The null hypothesis was μ = 11.5, and the alternative hypothesis was μ > 11.5. Using known population sigma = 3.23, the observed sample mean was 11.9060, and the z statistic was 3.2023.

Sample size649
Observed mean11.9060
Known sigma3.23
Z statistic3.2023

Final result: A one-sample z test showed that the mean final grade was significantly greater than 11.5, z = 3.202, p < .001, x̄ = 11.906, 95% z CI [11.658, 12.155]. Therefore, the null hypothesis was rejected.

Important statistical note: A true one sample z test for a mean requires a known population standard deviation. In this teaching example, sigma = 3.23 is treated as known. If the population standard deviation is not truly known, the correct test is usually a one-sample t test.

Quick Navigation

Use this guide to understand the test, reproduce the analysis and report the result correctly.

What Is a One Sample Z Test?

A One Sample Z Test is a hypothesis test for one population mean. It compares the observed sample mean with a hypothesized population mean. The test is called a z test because the test statistic follows the standard normal distribution when the population standard deviation is known and the sampling conditions are satisfied.

In this example, the numeric variable is G3, the final grade score. The sample contains 649 students. The observed mean final grade is 11.9060. The benchmark mean is 11.5. The research question is: Is the mean final grade significantly greater than 11.5?

The One Sample Z Test is different from the One Proportion Z Test. A one proportion z test is used for a binary outcome such as yes/no. A one sample z test is used for a numeric mean such as a test score, grade, height, income, time, weight or measurement value.

Plain-language meaning: The sample mean G3 score is 11.9060, which is 0.4060 points above the hypothesized mean of 11.5. The z test checks whether this difference is large enough relative to the known standard error.

When Should You Use a One Sample Z Test?

Use a One Sample Z Test when you have one numeric sample, one hypothesized mean and a known population standard deviation. This test is common in quality control, standardized testing, industrial measurement, population benchmark testing and situations where sigma is already established from historical population data.

Research situation Use One Sample Z Test? Reason
Testing whether mean final grade is greater than 11.5 with known sigma Yes One numeric variable, one benchmark mean and assumed known sigma.
Testing whether average machine output differs from a standard value when population sigma is known Yes Quality control often has known process sigma.
Testing a sample mean when sigma is not known No Use a one-sample t test instead.
Testing a yes/no percentage No Use a one proportion z test.
Comparing two group means No Use an independent-samples t test, paired t test or two-sample z test depending on the design.

One Sample Z Test Formula and Hypotheses

The One Sample Z Test formula compares the sample mean with the hypothesized mean using the known population standard deviation:

z = (x-bar - μ0) / (σ / sqrt(n))

Here, x-bar is the observed sample mean, μ0 is the hypothesized population mean, σ is the known population standard deviation and n is the sample size.

Symbol Meaning Value in this example
n Sample size 649
x-bar Observed sample mean 11.906009
μ0 Hypothesized mean 11.500000
σ Known population standard deviation 3.230000
SE σ / sqrt(n) 0.126789
z Standardized test statistic 3.202254

Hypotheses for This Worked Example

Hypothesis Statement Meaning
H0 μ = 11.5 The population mean final grade is 11.5.
H1 μ > 11.5 The population mean final grade is greater than 11.5.

Conditions for One Sample Z Test

The conditions for One Sample Z Test must be checked before reporting the result. The most important condition is that the population standard deviation must be known. If it is estimated from the sample, a one-sample t test is normally preferred.

Condition Requirement Result in this example
Numeric outcome The dependent variable should be numeric. Satisfied. G3 is a numeric final grade.
Known population standard deviation Population sigma should be known, not merely estimated. Assumed for teaching: sigma = 3.23.
Independent observations Each observation should represent a separate student. Treated as satisfied for this dataset workflow.
Large sample or normal population The population should be normal or the sample should be large enough for normal approximation. Satisfied by large sample size, n = 649.
Correct alternative hypothesis Use greater, less or two-sided according to the research question. This example uses H1: μ > 11.5.

One Sample Z Test vs T Test: The z test is suitable only when sigma is known. If sigma is unknown and you are using the sample standard deviation, use a one-sample t test. This post includes a reference t test in SPSS for transparency, but the main worked example remains the one-sample z test with known sigma treated as 3.23.

Advertisement
Google AdSense middle placement reserved here

Dataset and Variable Used

This tutorial uses the student-por.csv student performance dataset. The main variable is G3, the final grade. The test compares the sample mean of G3 with the hypothesized mean μ0 = 11.5.

Item Value used Explanation
Dataset student-por.csv Student performance dataset used for R, Python and SPSS verification.
Main variable G3 Final grade score.
Sample size 649 All 649 cases have valid G3 values.
Observed mean 11.906009 Mean final grade in the sample.
Hypothesized mean 11.5 Benchmark value used in the null hypothesis.
Known sigma 3.23 Population standard deviation assumed for the z test workflow.

External dataset source: UCI Machine Learning Repository: Student Performance dataset.

Verified R, Python and SPSS Results

The One Sample Z Test was reproduced in R, Python and SPSS. The corrected SPSS workflow used the cleaned file spss_ready_data.csv, which imported G3 correctly with 649 valid cases. The SPSS result matches the R and Python outputs.

Main One Sample Z Test Result

Statistic Verified value Interpretation
Valid N 649 All G3 cases were valid after Python cleaning and SPSS import.
Observed mean 11.906009 The sample mean final grade is above 11.5.
Sample SD 3.230656 Shown descriptively; the z test uses known sigma = 3.23.
Hypothesized mean μ0 11.500000 The benchmark mean in H0.
Known sigma 3.230000 Population SD assumed for the one-sample z test.
Standard error 0.126789 Calculated as sigma divided by square root of n.
Z statistic 3.202254 The sample mean is 3.202 standard errors above μ0.
Right-tailed p-value 0.000682 Report as p < .001; reject H0.
Two-sided p-value 0.001364 Also significant at α = .05.

Confidence Interval

Interval Lower bound Upper bound Interpretation
Two-sided 95% z CI 11.657508 12.154510 The entire interval is above 11.5, supporting the greater-than conclusion.

Descriptive Group Context

Group Mean G3 N Standard deviation Interpretation
GP school 12.5768 423 2.62564 Higher mean final grade in this descriptive group comparison.
MS school 10.6504 226 3.83399 Lower mean final grade than GP in this dataset.
Female students 12.2533 383 3.12415 Higher mean final grade than male students descriptively.
Male students 11.4060 266 3.32069 Lower mean final grade than female students descriptively.

Important: The school and sex tables are descriptive context only. The main hypothesis test in this article is the overall one-sample z test for the mean of G3 against μ0 = 11.5.

R Charts for One Sample Z Test

The R workflow produced visual explanations of the G3 distribution, confidence interval, z statistic, assumptions, numeric-variable context, group means and p-value summary.

1. G3 Distribution with Mean and Hypothesized Mean

G3 distribution with observed mean and hypothesized mean for One Sample Z Test
R chart showing the distribution of G3, with the observed mean and hypothesized mean marked.

The distribution chart shows how final grades are spread across the sample. The observed mean is slightly to the right of the hypothesized mean of 11.5. This difference becomes statistically significant because the sample size is large and the standard error is small.

2. Confidence Interval vs Null Mean

Confidence interval compared with null mean for One Sample Z Test
R chart showing the observed mean and its 95% z confidence interval compared with μ0.

The confidence interval lies above the hypothesized mean. This supports the same conclusion as the z test: the mean final grade is significantly greater than 11.5.

3. Z Statistic Normal Curve

Normal curve and z statistic for One Sample Z Test
R normal curve showing z = 3.202 in the right tail.

The z statistic is 3.202, which falls in the right tail of the standard normal distribution. The right-tailed p-value is 0.000682, so it is reported as p < .001.

4. One Sample Z Test Condition Check

One Sample Z Test condition check with known sigma and sample size
R chart showing the large sample size and the known sigma used for the z test.

The condition chart highlights two key points: the sample size is large, and sigma is treated as known. The large sample size supports the normal approximation, while the known sigma condition is essential for calling this a z test.

5. Candidate Numeric Variable Means

Candidate numeric variable means for One Sample Z Test dataset context
R chart showing mean values for selected numeric variables.

This chart shows why G3 is a good teaching variable for a one-sample mean test. It is numeric, meaningful and directly interpretable as a final grade score.

6. Mean G3 by School

Mean G3 by school for One Sample Z Test context
R chart comparing mean G3 by school.

The school chart provides descriptive context. GP has a higher mean final grade than MS in this dataset. This is not the main one-sample z test, but it helps readers understand the dataset structure.

7. Mean G3 by Sex

Mean G3 by sex for One Sample Z Test context
R chart comparing mean G3 by sex.

The sex chart shows that female students have a higher mean final grade than male students descriptively. Again, this is contextual and not the main hypothesis test.

8. P-Value Summary

P-value summary for One Sample Z Test
R chart comparing the p-values with alpha = .05.

The p-value summary makes the decision clear. The main right-tailed p-value is far below .05, so the null hypothesis is rejected.

9. Formula Summary Panel

Formula summary for One Sample Z Test
R formula panel showing n, x-bar, μ0, sigma, standard error, z and p-value.

The formula panel connects the raw result to the calculation. It shows how the mean difference is divided by the known-sigma standard error to produce the z statistic.

Python Validation Charts for One Sample Z Test

The Python workflow independently validates the same result. It reproduces the observed mean, confidence interval, normal curve, assumptions, group context and formula summary.

1. Python Observed Mean vs Hypothesized Mean

Python observed mean versus hypothesized mean for One Sample Z Test
Python chart comparing the observed G3 mean with the hypothesized mean.

This chart gives the simplest visual explanation of the test. The observed mean is higher than the benchmark mean of 11.5. The z test determines whether this difference is statistically meaningful.

2. Python G3 Distribution with Mean and μ0

Python G3 distribution with mean and hypothesized mean for One Sample Z Test
Python histogram showing G3 distribution with observed mean and hypothesized mean.

The Python distribution chart confirms the same pattern as R. The sample mean is above the null mean, and the large sample size makes the difference precise enough to be significant.

3. Python Confidence Interval vs Null Mean

Python confidence interval compared with null mean for One Sample Z Test
Python chart showing the 95% z confidence interval for the observed mean.

The confidence interval is approximately [11.6575, 12.1545]. Since the whole interval is above 11.5, it supports the greater-than conclusion.

4. Python Z Statistic Normal Curve

Python normal curve and z statistic for One Sample Z Test
Python normal curve showing z = 3.202 in the right tail.

The Python normal curve shows the right-tail area beyond z = 3.202. This right-tail area is the main p-value for the alternative hypothesis μ > 11.5.

5. Python One Sample Z Test Condition Check

Python One Sample Z Test condition check
Python chart showing known sigma and sample size condition information.

The condition chart reinforces the major teaching point: this test is a z test because sigma is treated as known. With an unknown population standard deviation, a one-sample t test should usually be used.

6. Python Candidate Numeric Variable Means

Python candidate numeric variable means for One Sample Z Test
Python chart showing means of selected numeric variables in the dataset.

This chart helps readers see that the dataset contains several numeric variables, but G3 is the best main example because it is an interpretable final-grade outcome.

7. Python Mean G3 by School

Python mean G3 by school for One Sample Z Test context
Python chart showing mean final grade by school.

The Python school chart confirms the same descriptive group pattern as SPSS and R. GP has a higher mean final grade than MS in this dataset.

8. Python Mean G3 by Sex

Python mean G3 by sex for One Sample Z Test context
Python chart showing mean final grade by sex.

The Python sex chart confirms that female students have a higher mean G3 than male students descriptively. This chart is included for context, not as the main z test.

9. Python P-Value Summary

Python p-value summary for One Sample Z Test
Python chart showing the right-tailed and two-sided p-values.

The p-value chart confirms that the right-tailed p-value is below .001. The two-sided p-value is also significant at .001364.

10. Python Formula Summary Panel

Python formula summary for One Sample Z Test
Python formula panel showing n, x-bar, μ0, sigma, SE, z and p-value.

The formula panel validates every numerical part of the test. It shows that the result is driven by x-bar = 11.9060, μ0 = 11.5, sigma = 3.23, SE = 0.126789 and z = 3.202.

How to Run One Sample Z Test in SPSS, R, Python and Excel

One Sample Z Test in SPSS

SPSS has a built-in one-sample t test, but not a direct menu table for a one-sample z test for a mean. Therefore, the clean SPSS method is to import spss_ready_data.csv, aggregate the sample mean and sample size, enter the known sigma, and manually compute the z statistic and p-value.

* One Sample Z Test in SPSS using cleaned CSV.

GET DATA
 /TYPE=TXT
 /FILE='D:\low kda score priority basis posts\first post\One Sample Z Test\spss_ready_data.csv'
 /ENCODING='UTF8'
 /DELCASE=LINE
 /DELIMITERS=","
 /QUALIFIER='"'
 /ARRANGEMENT=DELIMITED
 /FIRSTCASE=2
 /VARIABLES=
 school A240 sex A240 age F12.4 address A240 famsize A240 Pstatus A240
 Medu F12.4 Fedu F12.4 Mjob A240 Fjob A240 reason A240 guardian A240
 traveltime F12.4 studytime F12.4 failures F12.4 schoolsup A240 famsup A240
 paid A240 activities A240 nursery A240 higher A240 internet A240 romantic A240
 famrel F12.4 freetime F12.4 goout F12.4 Dalc F12.4 Walc F12.4
 health F12.4 absences F12.4 G1 F12.4 G2 F12.4 G3 F12.4.
EXECUTE.

AGGREGATE
 /OUTFILE=* MODE=ADDVARIABLES
 /BREAK=
 /N_G3=N(G3)
 /MEAN_G3=MEAN(G3)
 /SD_G3=SD(G3).

COMPUTE mu0 = 11.5.
COMPUTE known_sigma = 3.23.
COMPUTE se_known = known_sigma / SQRT(N_G3).
COMPUTE z_statistic = (MEAN_G3 - mu0) / se_known.
COMPUTE p_value_right = 1 - CDF.NORMAL(z_statistic, 0, 1).
COMPUTE p_value_two_sided = 2 * (1 - CDF.NORMAL(ABS(z_statistic), 0, 1)).
EXECUTE.

LIST VARIABLES=N_G3 MEAN_G3 SD_G3 mu0 known_sigma se_known z_statistic p_value_right p_value_two_sided
 /CASES=FROM 1 TO 1.

One Sample Z Test in R

In R, the one sample z test can be calculated manually from the mean, known sigma and sample size.

student <- read.csv("student-por.csv")

x <- as.numeric(student$G3)
x <- x[!is.na(x)]

n <- length(x)
xbar <- mean(x)
mu0 <- 11.5
known_sigma <- 3.23

se_known <- known_sigma / sqrt(n)
z_value <- (xbar - mu0) / se_known

p_value_right <- pnorm(z_value, lower.tail = FALSE)
p_value_two_sided <- 2 * pnorm(-abs(z_value))

ci_low <- xbar - qnorm(.975) * se_known
ci_high <- xbar + qnorm(.975) * se_known

n
xbar
se_known
z_value
p_value_right
p_value_two_sided
ci_low
ci_high

One Sample Z Test in Python

Python can reproduce the same test with pandas for data handling and SciPy for the standard normal p-value.

import pandas as pd
import math
from scipy.stats import norm

student = pd.read_csv("student-por.csv")

x = pd.to_numeric(student["G3"], errors="coerce").dropna()

n = len(x)
xbar = x.mean()
mu0 = 11.5
known_sigma = 3.23

se_known = known_sigma / math.sqrt(n)
z_value = (xbar - mu0) / se_known

p_value_right = norm.sf(z_value)
p_value_two_sided = 2 * norm.sf(abs(z_value))

ci_low = xbar - norm.ppf(.975) * se_known
ci_high = xbar + norm.ppf(.975) * se_known

print(n, xbar, se_known, z_value, p_value_right, p_value_two_sided, ci_low, ci_high)

One Sample Z Test in Excel

Excel is a good way to understand the calculator logic behind a one sample z test. Suppose G3 values are in cells A2:A650.

Excel task Formula Meaning
Sample size =COUNT(A2:A650) Returns n = 649.
Sample mean =AVERAGE(A2:A650) Returns x-bar = 11.906009.
Known sigma 3.23 Population standard deviation assumed for the z test.
Standard error =3.23/SQRT(649) Returns 0.126789.
Z statistic =(11.906009-11.5)/(3.23/SQRT(649)) Returns about 3.202254.
Right-tailed p-value =1-NORM.S.DIST(3.202254,TRUE) Returns about 0.000682.
Two-sided p-value =2*(1-NORM.S.DIST(ABS(3.202254),TRUE)) Returns about 0.001364.
95% CI lower =11.906009-NORM.S.INV(0.975)*(3.23/SQRT(649)) Returns about 11.657508.
95% CI upper =11.906009+NORM.S.INV(0.975)*(3.23/SQRT(649)) Returns about 12.154510.

One Sample Z Test Calculator Logic

A One Sample Z Test calculator usually asks for the sample mean, hypothesized mean, known population standard deviation, sample size and alternative hypothesis. For this example, the inputs are:

Calculator input Value Explanation
Sample mean x-bar 11.906009 Observed mean of G3.
Hypothesized mean μ0 11.5 Benchmark mean.
Known sigma 3.23 Population standard deviation used for z test.
Sample size n 649 Number of valid observations.
Alternative Greater than Right-tailed test: μ > 11.5.

The calculator should return approximately SE = 0.126789, z = 3.202254, right-tailed p = 0.000682 and 95% z CI = [11.657508, 12.154510].

How to Report One Sample Z Test

A good report should include the test name, variable, sample size, sample mean, hypothesized mean, known sigma, standard error, z statistic, p-value, confidence interval and decision.

APA-style reporting: A one-sample z test showed that the mean final grade was significantly greater than 11.5, z = 3.202, p < .001, x̄ = 11.906, 95% z CI [11.658, 12.155]. The null hypothesis was rejected. This result assumes the population standard deviation is known and equal to 3.23.

Plain-language reporting: The average final grade in the sample was 11.906, which was significantly higher than the benchmark value of 11.5 when sigma was treated as known.

Common Mistakes in One Sample Z Test

1. Using a z test when sigma is unknown

The most common mistake is using a one sample z test when the population standard deviation is not known. If sigma is estimated from the sample, a one-sample t test is usually the correct test.

2. Confusing sample SD with known sigma

The sample SD is a descriptive statistic. Known sigma is a population value used in the denominator of the z statistic. In this article, sigma = 3.23 is treated as known for teaching purposes.

3. Using the wrong alternative hypothesis

The p-value depends on the alternative hypothesis. This example uses a right-tailed test because the question asks whether the mean is greater than 11.5.

4. Reporting p = .000

If software displays .000, write p < .001. In this example, the right-tailed p-value is 0.000682, which is correctly reported as p < .001.

5. Treating descriptive group charts as the main test

The school and sex charts are descriptive context only. The main hypothesis test is the overall mean of G3 against μ0 = 11.5.

Download SPSS Output and Verification Files

The SPSS output PDF verifies the cleaned-data import, descriptive statistics, reference t test, group means, manual one-sample z test result and formula components.

External References

This guide uses verified R, Python and SPSS outputs together with standard statistical documentation and software references. These resources help readers understand one-sample mean testing, z statistics, p-values and confidence intervals.

FAQs About One Sample Z Test

What is a One Sample Z Test?

A One Sample Z Test is a hypothesis test used to compare one observed sample mean with a hypothesized population mean when the population standard deviation is known.

When should I use a One Sample Z Test?

Use it when you have one numeric sample, one benchmark mean, independent observations and a known population standard deviation.

What was the result in this example?

The result was n = 649, x-bar = 11.906009, known sigma = 3.23, z = 3.202254 and right-tailed p = 0.000682, reported as p < .001.

What is the formula for a One Sample Z Test?

The formula is z = (x-bar − μ0) / (σ / sqrt(n)).

What is x-bar in a One Sample Z Test?

x-bar is the observed sample mean. In this example, x-bar = 11.906009.

What is μ0 in a One Sample Z Test?

μ0 is the hypothesized population mean under the null hypothesis. In this example, μ0 = 11.5.

What is known sigma in a One Sample Z Test?

Known sigma is the population standard deviation used in the z-test formula. In this teaching example, sigma = 3.23 is treated as known.

What are the conditions for a One Sample Z Test?

The outcome should be numeric, observations should be independent, the population standard deviation should be known, and the population should be normal or the sample should be large enough for normal approximation.

Is One Sample Z Test the same as One Sample T Test?

No. A one sample z test uses known population sigma, while a one sample t test uses the sample standard deviation when sigma is unknown.

Can I run a One Sample Z Test in Excel?

Yes. Excel can calculate x-bar, standard error, z statistic, p-value and confidence interval using AVERAGE, COUNT, SQRT, NORM.S.DIST and NORM.S.INV.

How do I report the p-value when it is very small?

Report very small p-values as p < .001. In this example, the right-tailed p-value is 0.000682, so p < .001 is appropriate.

What does the result mean in plain language?

It means the mean final grade in the sample is significantly greater than 11.5, assuming the population standard deviation is known and equal to 3.23.

Advertisement
Google AdSense bottom placement reserved here

Advertisement
Google AdSense Bottom placement reserved here

Need Data Analysis Help?

Send your project details and get ethical tutoring, interpretation or dashboard support.

Request Data Analysis Help

About the author

Online Internet Cafe publishes practical guides for statistics, research methods, data analysis tools and ethical project support.

Related articles

Leave a Reply

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

Request QuoteWhatsApp