Skip to content

BCompare groups · Guide test 006

One sample z test for a mean

Compares a population mean with a target using known variance or a justified large sample standard error.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

In One-sample t-test (or z test), set Known population SD (z test).

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · One-sample z test

25
0.40

The population mean the data come from.

1.0
0.00

The value H₀ says the mean equals.

0.050

Alternative

The statistic's distribution if the design's true effect is real.

Your data

Drag a point or use ↑/↓ to change it
μ₀ = 0.00Sample · n = 25 · mean 0.34

If H₀ were true

z = 1.69
  1. The reference: how z varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .091).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

z=xˉ−μ0σ/nz = \dfrac{\bar x - \mu_0}{\sigma / \sqrt{n}}

With your numbers

z=0.34−01/25=1.69z = \dfrac{0.34 - 0}{1 / \sqrt{25}} = 1.69
xˉ\bar x
the sample mean
μ0\mu_0
the value H₀ claims
σ\sigma
the population SD, known in advance (rarely true in practice)
nn
the sample size

The verdict

z = 1.69, p = .091, d = 0.34

p > α = .050: compatible with H₀

Effect size: standardized difference d = 0.338

z counts how many standard errors the sample mean sits from μ0. Knowing σ is the whole point: estimate it from the data and you need the t test instead.

Statistic
1.692
p-value
0.0906
One-sample z test on Sample: n = 25: z = 1.69, p = .091, d = 0.34. The p-value is above α = .050, so the data are compatible with H0.

One-sample z test on Sample: n = 25: z = 1.69, p = .091, d = 0.34. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: μ=μ0; H1: μ≠μ0, μ>μ0, or μ<μ0.

Assumptions

Observations are independent with a common mean. Known population variance and normal observations give exact inference; a suitable central limit theorem gives an approximation for large samples.

Formula

z=xˉ−μ0σ/nz=\frac{\bar x-\mu_0}{\sigma/\sqrt n}

Parameters and notation

n is the sample size; x̄ is its mean; μ0 is the target; σ is known population standard deviation. Using an estimated standard error makes this a large sample z procedure.

Structure of the method

Compute the sample mean, subtract the specified target, and divide by the known population standard deviation over square-root sample size. A normal population gives an exact standard-normal pivot; otherwise the same calculation needs a justified central-limit approximation for the actual sampling process.

Estimated and nuisance parameters

The sample mean estimates the target population mean. In the genuinely known-variance version, sigma is supplied independently and is not re-estimated from these observations. If the standard error is estimated, that estimation uncertainty changes the claim from an exact known-sigma test to an approximation.

Settings and design choices

Specify the target mean, sigma source, one- or two-sided alternative, alpha, sampling plan, and any sequential monitoring rule. There is no optimization or neural architecture. Sample size is a design choice affecting power; it should not be increased repeatedly until significance without a valid sequential protocol.

Fitting and adaptation

Recalculate the mean and standard error for a new independent sample while preserving the prespecified target. If the reference variance drifts or is estimated from a small historical dataset, incorporate that uncertainty or use an appropriate t/model-based method rather than retaining an unjustified known-sigma claim.

Sensitivity and robustness

Heavy tails, dependence, survey weights, and unequal inclusion probabilities can defeat the simple sigma/square-root-n denominator. A sample-size rule such as n greater than thirty is not a distributional guarantee. Report the mean difference in physical units and sensitivity to the assumed sigma.

How to use and calibrate

Compute z and compare with a standard normal distribution. For a two sided test p=2Φ(−|z|). Report x̄−μ0 and a confidence interval.

Example application

With n=100, known σ=10, x̄=52, and μ0=50, z=2 and the two sided p value is about 0.0455.

Interpretation and pitfalls

Watch out

A standard deviation estimated from a small sample should usually lead to a t test. Independence and representative sampling matter more than a mechanical “n greater than 30” rule.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Population standard deviation sigma is known; estimating it from x changes the test.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
x = np.array([4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0])
y = np.array([4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9])
sigma=1; mu0=5
z=(x.mean()-mu0)/(sigma/np.sqrt(len(x)))
print(z,2*stats.norm.sf(abs(z)))
Output
0.9486832980505132 0.34278171114791167
R

Validated — Executed successfully in the validation environment · needs Base/standard library

x <- c(4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0)
y <- c(4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9)
sigma <- 1; mu0 <- 5; z <- (mean(x)-mu0)/(sigma/sqrt(length(x)))
print(c(z=z,p=2*pnorm(-abs(z))))
Output
        z         p 
0.9486833 0.3427817

Sources

Statistics guide v4 (historical):
R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 006, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT006.