One Sample Z Test Calculator
Test a sample mean against a known population mean when σ is known, or a sample proportion against a hypothesised proportion. Paste comma-separated data or summary statistics and get the z statistic, p-value, critical value, confidence interval, effect size, power, four charts and copy-ready APA results.
⚡ 0. Quick Answer
A one sample z test calculator checks whether a sample mean differs from a hypothesised population mean μ0 when the population standard deviation σ is known, using z = (x̄ − μ0) ÷ (σ ÷ √n).
For 16 leaves with x̄ = 52.44 mm, μ0 = 50 and σ = 4, z = 2.44 and the two-tailed p = 0.0148, so the mean is significantly above 50 mm. The same test works for one proportion with z = (p̂ − p0) ÷ √(p0(1 − p0) ÷ n).
Rule of thumb: reject H0 at α = 0.05 when |z| > 1.96 (two-tailed) or z > 1.645 (one-tailed). Use it only when σ is truly known and n ≥ 30 or the data are normal. If σ comes from your own sample, use the one-sample t test.
Key takeaways
- The one sample z test compares one sample mean with a fixed value when σ is known in advance.
- The test statistic counts how many standard errors (σ ÷ √n) the sample mean sits from μ0.
- Critical values are fixed: ±1.960 two-tailed and 1.645 one-tailed at α = 0.05, whatever the sample size.
- For a one sample proportion z test, check that n·p0 and n(1 − p0) are both at least 10.
- Always report z, p, the confidence interval and Cohen’s d together, because a tiny effect can be significant in a large sample.
📚 1. What Is a One Sample Z Test?
A one sample z test is a hypothesis test that asks one question: is the mean of the population my sample came from equal to a stated value μ0? It can be used when the population standard deviation σ is already known from earlier work, a standard, or the way a test is scaled. Because σ is known, the test statistic follows the standard normal distribution exactly when the data are normal, and approximately for large samples through the central limit theorem.
What it actually measures: the distance between the sample mean and μ0, expressed in standard errors. One standard error is σ ÷ √n, the typical amount a sample mean of size n wobbles around the true mean. A z of 2.44 says the sample mean sits 2.44 standard errors from the null value, which is rare if the null value is true.
A worked one-liner: 16 leaves give x̄ = 52.4375 mm. With μ0 = 50 and σ = 4, the standard error is 4 ÷ √16 = 1, so z = (52.4375 − 50) ÷ 1 = 2.4375 and the two-tailed p = 0.0148.
Two versions in one tool. The z test for one sample mean uses σ. The one sample z test for proportions tests whether a population proportion p equals p0, using the standard error √(p0(1 − p0) ÷ n). The proportion version needs no σ because the spread of a proportion is set by p0 itself.
Who uses it: quality engineers checking a filling line with a long-run σ, psychologists testing IQ scores scaled to σ = 15, pollsters testing whether support differs from 50%, clinicians comparing a ward with a national rate, and ecologists comparing a plot with a regional benchmark where the spread is well documented.
| Feature | One sample z test | One sample t test |
|---|---|---|
| Spread used | Known population σ | Sample SD s, estimated from the data |
| Reference distribution | Standard normal | t with n − 1 degrees of freedom |
| Critical value at α = 0.05, two-tailed | 1.960 for every n | 2.131 at n = 16, 2.045 at n = 30 |
| Works for proportions | Yes, the one proportion z test | No |
| Use when | σ is known, or a proportion with n·p0 ≥ 10 | σ is unknown, which is most real data |
🧮 2. Set Up Your Data
Type one value per cell. Each column becomes a group, and the column name is editable. Empty cells are ignored.
📊 3. Results
🧠 4. Interpretation of Results, In Detail
Sub-sections 4.1 to 4.5 fill in automatically with your numbers after you press Run. Sub-sections 4.6 to 4.10 explain how to read any one sample z test result.
4.1 What your result says
Run the analysis above to fill this paragraph with your own numbers. ___
4.2 Reading the p-value correctly
Run the analysis above to fill this paragraph with your own numbers. ___
4.3 The confidence interval tells you more than the decision
Run the analysis above to fill this paragraph with your own numbers. ___
4.4 Effect size: is the difference big enough to matter?
Run the analysis above to fill this paragraph with your own numbers. ___
4.5 Power and the sample size you would need
Run the analysis above to fill this paragraph with your own numbers. ___
4.6 Why the critical value never changes with n
In a t test the critical value shrinks as n grows, because the sample SD becomes a better estimate of σ. In a z test σ is known, so there is nothing to estimate and the cut-offs stay fixed: 1.960 two-tailed and 1.645 one-tailed at α = 0.05. What changes with n is the standard error. Quadruple the sample and the standard error halves, so the same raw difference produces a z twice as large.
4.7 One-tailed or two-tailed: decide before you look
A one-tailed test puts all of α in one tail, so it rejects H0 sooner, at z = 1.645 instead of 1.96, but only in the direction you predicted. Choosing the tail after seeing the data doubles your real false-positive rate. Use a one-tailed test only when a result in the other direction would lead to exactly the same action as no result, as in a quality check that only cares if the defect rate is too high.
4.8 Statistical significance versus practical importance
With 1,600 exam scripts, a mean of 506 against 500 with σ = 100 gives z = 2.40 and p = 0.016. That is significant, but Cohen’s d is 0.06, a shift of six points on a scale with a spread of one hundred. Always pair the p-value with the raw difference, the interval and the effect size, and ask a subject expert whether the gap matters.
4.9 What a non-significant result does and does not mean
“Fail to reject H0” means the data are compatible with μ0. It does not prove that μ equals μ0. A small study can miss a real effect, which is why this tool reports observed power and the n needed for 80% power. If the confidence interval is wide and includes both trivial and important values, the honest conclusion is that the study was inconclusive.
4.10 When the known σ is wrong
The whole test rests on σ. If the true spread is larger than the value you entered, the standard error is too small, z is inflated and you get false positives. The assumption panel compares your sample SD with σ using a chi-square test. A sample SD far from σ is a sign that the stated σ does not apply to this population, and the one-sample t test is the safer choice.
4.11 Decision guide
| You see | What to conclude | What to report |
|---|---|---|
| p < α, CI excludes μ0, d ≥ 0.5 | A real and meaningful difference | z, p, CI and d, in the direction of the effect |
| p < α, d < 0.2 | Real but probably trivial | Stress the effect size and the raw difference |
| p just above α, power < 50% | Inconclusive, the study was too small | The CI and the n needed for 80% power |
| p > α, narrow CI around μ0 | Good evidence the mean is close to μ0 | The CI, which rules out large differences |
| Assumption panel shows a concern | The p-value may be wrong | Run the t test, sign test or exact binomial test instead |
✍ 5. How to Write Your Results in Research
📌 Key conventions for this style
- Italicise z, p, M and d. Report z to two decimals.
- Give exact p to three decimals, and write p < .001 below that. No leading zero on p.
- State the tail and that σ was known, and where σ came from.
- Always add the effect size and the confidence interval.
📌 Key conventions for this style
- Justify the source of σ in the Methods chapter. Examiners always ask.
- State the hypotheses, α and the tail before the result.
- Mention the assumption checks and their outcome.
- Name the software and version used.
📌 Key conventions for this style
- Never write z, p or Greek letters.
- Say “too large to be chance” rather than “significant”.
- Give the units every time a number appears.
- Explain the range of likely values in plain words.
📌 Key conventions for this style
- Keep each heading to one line.
- Use the same decimals in every row.
- Put the effect size next to the p-value, not in a separate box.
- On a poster, place chart 1 or chart 3 beside this block.
📌 Key conventions for this style
- Fix μ0, σ, α, the tail and n before collecting data.
- Report any deviation from the plan.
- Give the n needed for 80% power so others can replicate.
- Share the raw data or the summary statistics.
5.1 Methods wording
Name the test, the tail, α, μ0 and the source of σ: “A two-tailed one-sample z test (α = 0.05) compared the sample mean with μ0 = 50 mm, using σ = 4 mm from long-term records.” For proportions, say “a one-sample z test for a proportion compared p̂ with p0 = 0.50” and state whether a continuity correction was used.
5.2 The results sentence
Lead with the direction and size of the difference, then the statistics in brackets: the mean or proportion, z, p, the effect size and the interval. Readers should be able to understand the finding without the brackets.
5.3 Tables and figures
In a table, use columns for n, x̄ or p̂, μ0 or p0, z, p, d or h and the CI. Chart 1 (z on the normal curve) suits teaching; chart 3 (the forest plot) suits papers with several groups.
5.4 The discussion sentence
Interpret the interval, not just the decision: “the data are consistent with an increase of between 0.5 and 4.4 mm, a medium effect that is large enough to matter for the growth model.”
5.5 Reporting checklist
- ✓ Hypotheses and tail stated
- ✓ Source of σ given (mean test) or n·p0 condition met (proportion test)
- ✓ z to two decimals and exact p
- ✓ Effect size with its label
- ✓ Confidence interval with its level
- ✓ Multiple-group correction named, if used
∑ 6. Formulas Used
🔀 7. One Sample Z Test Calculation Flowchart, Step by Step
This flowchart shows how the one sample z test is calculated, step by step, from a raw column of numbers to a reportable decision. Every box uses the same worked example as the Excel, R and Python sections: 16 leaf lengths in mm, tested against μ0 = 50 mm with a known σ of 4 mm.
Check any box yourself: the Excel sheet in Section 9, the R script in Section 10 and the Python script in Section 11 all return x̄ = 52.4375, z = 2.4375 and p = 0.0148 for this dataset.
📝 8. How to Use This Calculator
- Choose what you are testing. Pick a mean with known population σ, or a proportion, in the "What are you testing?" box.
- Enter your data. Paste comma-separated numbers into the group box, in the format 52, 48, 55, 61, 47. Newlines, tabs and spaces also work, so a column copied from Excel is fine.
- Or switch to summary statistics. Set Data format to Summary statistics and type the sample mean and n, or the number of successes x and n for a proportion.
- Name each group. Click the group name and type something meaningful such as Clinic A. It flows into the tables, charts and reports.
- Add more groups or upload a file. Press Add group, or use the Upload tab and click the columns you want. Every selected column becomes its own group.
- Set the null value and sigma. Type the hypothesised mean μ0 and the known σ, or the hypothesised proportion p0.
- Pick the tail and alpha. Choose two-tailed, right-tailed or left-tailed, and the significance level, before you look at the result.
- Press Run One Sample Z Test. Nothing is computed until you press Run. Changing any setting clears the old results.
- Read the cards, table and assumption checks. Start with the decision line, then the confidence interval and effect size, then the assumption panel.
- Copy a report or export. Section 5 fills five reporting styles with your numbers. Download Doc gives a text report and Download PDF a printable one.
Worked example: load sample 1, keep μ0 = 50, σ = 4, two-tailed, α = 0.05, and press Run. You should see z = 2.44, p = 0.0148 and the 95% CI [50.48, 54.40].
📈 9. How to Run a One Sample Z Test in Excel
Excel has a Z.TEST function, but it trips up almost everyone: it returns a one-tailed p-value for the upper tail, and if you leave out σ it quietly uses the sample SD instead. The safest way is to build the test from AVERAGE, SQRT and NORM.S.DIST, which shows every step and gives exactly the same answer as this calculator.
=2*(1-NORM.S.DIST(ABS((AVERAGE(A2:A17)-50)/(4/SQRT(COUNT(A2:A17)))),TRUE)) for the two-tailed p-value. It returns 0.0148.9.1 The functions you need
| You want | Excel function | Note |
|---|---|---|
| n | =COUNT(A2:A17) | COUNT skips blanks and text, COUNTA does not |
| Sample mean | =AVERAGE(A2:A17) | Ignores blank cells |
| Standard error | =C3/SQRT(C4) | σ in C3, n in C4 |
| z statistic | =(C5-C2)/C6 | Mean minus μ0, over SE |
| Two-tailed p | =2*(1-NORM.S.DIST(ABS(C7),TRUE)) | TRUE means the cumulative area |
| Right-tailed p | =1-NORM.S.DIST(C7,TRUE) | H1: μ greater than μ0 |
| Left-tailed p | =NORM.S.DIST(C7,TRUE) | H1: μ less than μ0 |
| Critical z | =NORM.S.INV(0.975) | 1.96 for α = 0.05 two-tailed |
| Built-in test | =Z.TEST(A2:A17,50,4) | Upper one-tailed p only, see the warning below |
| Cohen’s d | =(C5-C2)/C3 | No built-in function |
=Z.TEST(A2:A17,50,4) returns 0.0074, the area to the right of z, not the two-tailed p of 0.0148. For a two-tailed p use =2*MIN(Z.TEST(A2:A17,50,4),1-Z.TEST(A2:A17,50,4)). If you leave out the third argument, Excel replaces σ with STDEV.S of the data, which turns the test into a t test with the wrong distribution. The Analysis ToolPak has no one-sample z test at all; its “z-Test: Two Sample for Means” is a different test.9.2 Step by step
1 Put your numbers in one column
Paste the 16 leaf lengths down column A with a label in A1. Formulas ignore the header automatically.
The 16 measurements sit in A2:A17. Only the first eight rows are shown here.
2 Type μ0 and σ, then count n
Put the null mean in C2 and the known σ in C3. Count the values in C4 with COUNT, never by hand.
=COUNT(A2:A17)C2 holds μ0 = 50, C3 holds σ = 4 and C4 returns n = 16.
3 Find the mean and the standard error
The mean goes in C5 and the standard error, σ divided by the square root of n, in C6.
=AVERAGE(A2:A17)=C3/SQRT(C4)C5 = 52.4375 and C6 = 1.0000.
4 Compute z
Subtract μ0 from the mean and divide by the standard error.
=(C5-C2)/C6C7 = 2.4375, so the mean sits 2.44 standard errors above 50.
5 Turn z into a two-tailed p-value
NORM.S.DIST with TRUE gives the area to the left of z. One minus that, doubled, is the two-tailed p.
=2*(1-NORM.S.DIST(ABS(C7),TRUE))C8 = 0.0148, below 0.05, so H0 is rejected.
6 Add the 95% confidence interval
The interval is the mean plus or minus the critical z times the standard error.
=C5-NORM.S.INV(0.975)*C6=C5+NORM.S.INV(0.975)*C6C9 = 50.4775 and C10 = 54.3975. The interval does not contain 50.
9.3 The awkward cases
A proportion. With 280 successes in 500 and p0 = 0.5, z is =(280/500-0.5)/SQRT(0.5*(1-0.5)/500), which returns 2.6833, and the two-tailed p is =2*(1-NORM.S.DIST(ABS(2.6833),TRUE)) = 0.0073. Because p0 = 0.5 is symmetric, the exact two-tailed binomial p is =2*(1-BINOM.DIST(279,500,0.5,TRUE)) = 0.0083, a useful check that the normal approximation is close. The classic mistake is putting p̂ instead of p0 inside the square root.
Summary statistics only. If you have x̄, n and σ but not the raw data, type them into C5, C4 and C3 directly and the remaining formulas work unchanged.
A one-tailed test. Use =1-NORM.S.DIST(C7,TRUE) for H1: μ > μ0 and =NORM.S.DIST(C7,TRUE) for H1: μ < μ0. Never halve the two-tailed p when z points the wrong way.
9.4 Why your Excel answer might differ from R or Python
| Situation | What happens | Fix |
|---|---|---|
Z.TEST without σ | Excel uses STDEV.S, so the result is not a z test with known σ | Always pass σ as the third argument |
Z.TEST read as two-tailed | It is upper one-tailed, half the two-tailed p when z is positive | Use the 2*MIN(...) formula in 9.1 |
Python statsmodels ztest | It estimates σ from the sample SD, there is no known-σ argument | Compute z by hand with scipy.stats.norm, as in Section 11 |
R has no base z.test() | BSDA::z.test(x, mu = 50, sigma.x = 4) exists in a package | Use the base-R script in Section 10, which agrees to every decimal |
| Blank cells or text | COUNT and AVERAGE skip them silently, so n shrinks | Check that C4 matches the number of rows you expect |
| Zeros typed for missing data | Counted as real values and drag the mean down | Leave missing cells blank |
| Rounding shown vs stored | A displayed 2.44 may be 2.4375 underneath | Reference cells, never retype rounded values |
Proportion test in R prop.test | Applies a continuity correction by default and reports chi-square = z² | Use correct = FALSE to match the standard z test |
9.5 Charting the result in Excel
Select A2:A17 and insert a Scatter chart with the values on the x axis and a constant y, then add two vertical lines for the mean and μ0 as extra series. For a normal-curve figure, fill a column with z from −4 to 4 in steps of 0.1, compute =NORM.S.DIST(B2,FALSE) beside it and insert a Scatter with Smooth Lines. Remove the gridlines and label the axes with units, the two changes that make the chart publication-ready.
9.6 Excel errors you will probably hit
| Error | Cause | Fix |
|---|---|---|
#DIV/0! | n is 0 or σ is blank, so the SE divides by zero | Check C3 and C4 |
#NUM! | NORM.S.INV given a probability of 0 or 1, or a negative under SQRT | Use 0.975, not 97.5 |
#VALUE! | A number stored as text inside a formula reference | Use Data, Text to Columns, or VALUE() |
#NAME? | Old Excel without NORM.S.DIST | Use NORMSDIST(z) in Excel 2007 and earlier |
📈 10. How to Run a One Sample Z Test in R
Base R has t.test() but no z.test(), because a known σ is rare in practice. The good news is that a one sample z test in R takes four lines with pnorm() and qnorm(). The script below is complete: it computes z, the p-value for any tail, the confidence interval, Cohen’s d and power, prints a plain-English verdict, and saves one publication-ready figure at 300 dpi.
Rscript. Change only the x <- c(...) line, plus mu0 and sigma.10.1 The complete script
R, base only, saves z_test_plot.png
# ============================================================
# One sample z test with one publication-ready figure
# StatsUnlock - https://statsunlock.com/one-sample-z-test-calculator/
# Base R only, nothing to install
# ============================================================
# ---- 1. Your data: change only this line --------------------
x <- c(52, 48, 55, 61, 47, 50, 58, 53, 49, 56, 51, 54, 46, 57, 50, 52)
# x <- read.csv("leaves.csv")$length_mm
x <- x[!is.na(x)] # drop missing values
mu0 <- 50 # hypothesised mean
sigma <- 4 # KNOWN population SD, not sd(x)
alpha <- 0.05
tail <- "two" # "two", "greater" or "less"
# ---- 2. The test ---------------------------------------------
n <- length(x)
xbar <- mean(x)
se <- sigma / sqrt(n)
z <- (xbar - mu0) / se
p <- switch(tail,
two = 2 * pnorm(-abs(z)),
greater = pnorm(z, lower.tail = FALSE),
less = pnorm(z))
zc <- qnorm(1 - alpha / 2)
ci <- xbar + c(-1, 1) * zc * se
d <- (xbar - mu0) / sigma
power <- pnorm(zc - d * sqrt(n), lower.tail = FALSE) + pnorm(-zc - d * sqrt(n))
n80 <- ceiling(((zc + qnorm(0.80)) / d)^2)
# ---- 3. Printed summary --------------------------------------
cat(sprintf("n = %d, mean = %.4f, sample SD = %.4f\n", n, xbar, sd(x)))
cat(sprintf("SE = %.4f, z = %.4f, p (%s) = %.4f\n", se, z, tail, p))
cat(sprintf("95%% CI = [%.4f, %.4f], Cohen's d = %.4f\n", ci[1], ci[2], d))
cat(sprintf("power = %.4f, n for 80%% power = %d\n", power, n80))
size <- if (abs(d) < 0.5) "small" else if (abs(d) < 0.8) "medium" else "large"
if (p < alpha) {
cat(sprintf("Verdict: p is below %.2f and d is %.2f (%s), so the mean differs from %g.\n", alpha, d, size, mu0))
} else {
cat(sprintf("Verdict: p is %.3f, above %.2f, so there is no evidence the mean differs from %g.\n", p, alpha, mu0))
}
# ---- 4. One 300 dpi figure -----------------------------------
set.seed(1) # reproducible jitter
png("z_test_plot.png", width = 3000, height = 1200, res = 300)
par(mfrow = c(1, 2), mar = c(4.2, 4.2, 2.5, 1))
g <- seq(-4, 4, length.out = 400)
plot(g, dnorm(g), type = "l", lwd = 2, col = "#2563eb",
xlab = "z", ylab = "Density", main = "z on the standard normal curve")
hi <- g[g >= zc]; polygon(c(zc, hi, 4), c(0, dnorm(hi), 0), col = "#fdba74", border = NA)
lo <- g[g <= -zc]; polygon(c(-4, lo, -zc), c(0, dnorm(lo), 0), col = "#fdba74", border = NA)
abline(v = z, col = "#7c3aed", lwd = 3)
legend("topleft", legend = sprintf("z = %.2f", z), bty = "n")
stripchart(x, method = "jitter", pch = 19, col = "#16a34a", ylim = c(0.5, 1.5),
xlab = "Leaf length (mm)", main = "Data, mean and 95% CI")
abline(v = xbar, col = "#7c3aed", lwd = 3)
abline(v = mu0, col = "#ea580c", lwd = 2, lty = 2)
segments(ci[1], 0.6, ci[2], 0.6, col = "#0d9488", lwd = 6)
dev.off()Expected output: n = 16, mean = 52.4375, SE = 1.0000, z = 2.4375, p (two) = 0.0148, 95% CI = [50.4775, 54.3975], Cohen’s d = 0.6094, power = 0.6835, n for 80% power = 22.
10.2 What each part does
| Line or function | What it does, and why it is there |
|---|---|
| x <- c(...) | Builds the data vector. Swap in read.csv() for a file, and keep x[!is.na(x)] because mean() returns NA if one value is missing. |
| sigma <- 4 | The known population SD. Never set it to sd(x); that is a t test. |
| se <- sigma / sqrt(n) | The standard error of the mean under the known σ. |
| pnorm(-abs(z)) | Lower-tail area beyond |z|. Doubling it gives the two-tailed p. |
| pnorm(z, lower.tail = FALSE) | Upper-tail area, more accurate than 1 - pnorm(z) for large z. |
| qnorm(1 - alpha / 2) | The critical value, 1.959964 for α = 0.05. |
| power <- ... | Power of the two-tailed test if the true effect equals the observed d. |
| png(..., res = 300) | Opens a 300 dpi file; dev.off() closes and writes it. |
10.3 What the figure shows
The left panel is the standard normal curve with the 2.5% rejection tails shaded orange and the observed z of 2.44 as a purple line inside the upper tail. The right panel shows the 16 leaves as jittered points, the sample mean in purple, μ0 = 50 as a dashed orange line and the 95% CI as a teal bar that stops short of 50.
10.4 Common R problems and fixes
| Problem | Fix |
|---|---|
could not find function "z.test" | Base R has none. Use this script or install.packages("BSDA"). |
Result matches t.test(), not this page | You used sd(x) as sigma. Use the known value. |
| p is exactly 0 | Print with format.pval(p); R gives about 1e-300 before underflow. |
prop.test() p differs from the z test | Add correct = FALSE; its chi-square equals z squared. |
| Figure is blank | You forgot dev.off(), or ran the script line by line in a different folder. |
| NA in the mean | Keep the x[!is.na(x)] line. |
10.5 Useful one-liners
BSDA::z.test(x, mu = 50, sigma.x = 4) # packaged one sample z test
prop.test(280, 500, p = 0.5, correct = FALSE) # proportion z test (X-squared = z^2)
binom.test(280, 500, p = 0.5) # exact check for a proportion
pnorm(2.4375, lower.tail = FALSE) # right-tailed p from a z value
qnorm(c(0.95, 0.975, 0.995)) # critical values 1.645, 1.960, 2.576
ceiling(((qnorm(0.975) + qnorm(0.8)) / 0.5)^2) # n for 80% power at d = 0.5
sapply(split(df$y, df$site), function(v) (mean(v) - 50) / (4 / sqrt(length(v)))) # z per site📈 11. How to Run a One Sample Z Test in Python
SciPy has no ready-made one-sample z test with a known σ, and the ztest in statsmodels estimates σ from your data, which is not the same test. The script below computes the one sample z test directly with scipy.stats.norm, prints a verdict, and saves one 300 dpi figure. It matches this calculator, Excel and R to every decimal.
x = np.array([...]) line and the mu0, sigma line.Install with pip install numpy scipy matplotlib if you do not already have them.
11.1 The complete script
Python 3, saves z_test_plot.png
# ============================================================
# One sample z test with one publication-ready figure
# StatsUnlock - https://statsunlock.com/one-sample-z-test-calculator/
# ============================================================
import numpy as np
from scipy import stats
import matplotlib
matplotlib.use("Agg") # remove this line in Jupyter
import matplotlib.pyplot as plt
# ---- 1. Your data: change only this line --------------------
x = np.array([52, 48, 55, 61, 47, 50, 58, 53, 49, 56, 51, 54, 46, 57, 50, 52], dtype=float)
# import pandas as pd; x = pd.read_csv("leaves.csv")["length_mm"].to_numpy(dtype=float)
x = x[~np.isnan(x)] # drop missing values
mu0, sigma, alpha = 50.0, 4.0, 0.05 # null mean, KNOWN population SD, alpha
tail = "two" # "two", "greater" or "less"
# ---- 2. The test ---------------------------------------------
n = x.size
xbar = x.mean()
se = sigma / np.sqrt(n)
z = (xbar - mu0) / se
if tail == "two":
p = 2 * stats.norm.sf(abs(z))
elif tail == "greater":
p = stats.norm.sf(z)
else:
p = stats.norm.cdf(z)
zc = stats.norm.ppf(1 - alpha / 2)
ci = (xbar - zc * se, xbar + zc * se)
d = (xbar - mu0) / sigma
power = stats.norm.sf(zc - d * np.sqrt(n)) + stats.norm.cdf(-zc - d * np.sqrt(n))
n80 = int(np.ceil(((zc + stats.norm.ppf(0.80)) / d) ** 2))
# ---- 3. Printed summary --------------------------------------
print(f"n = {n}, mean = {xbar:.4f}, sample SD = {x.std(ddof=1):.4f}")
print(f"SE = {se:.4f}, z = {z:.4f}, p ({tail}) = {p:.4f}")
print(f"95% CI = [{ci[0]:.4f}, {ci[1]:.4f}], Cohen's d = {d:.4f}")
print(f"power = {power:.4f}, n for 80% power = {n80}")
size = "small" if abs(d) < 0.5 else ("medium" if abs(d) < 0.8 else "large")
if p < alpha:
print(f"Verdict: p is below {alpha} and d is {d:.2f} ({size}), so the mean differs from {mu0}.")
else:
print(f"Verdict: p is {p:.3f}, above {alpha}, so there is no evidence the mean differs from {mu0}.")
# ---- 4. One 300 dpi figure -----------------------------------
rng = np.random.default_rng(1) # seeded jitter, reproducible
fig, ax = plt.subplots(1, 2, figsize=(10, 4))
g = np.linspace(-4, 4, 400)
ax[0].plot(g, stats.norm.pdf(g), color="#2563eb", lw=2)
ax[0].fill_between(g, stats.norm.pdf(g), where=abs(g) >= zc, color="#fdba74")
ax[0].axvline(z, color="#7c3aed", lw=2.5, label=f"z = {z:.2f}")
ax[0].set(title="z on the standard normal curve", xlabel="z", ylabel="Density")
ax[0].legend(frameon=False)
ax[1].scatter(x, rng.uniform(0.2, 0.8, n), color="#16a34a", alpha=0.7)
ax[1].axvline(xbar, color="#7c3aed", lw=2.5, label=f"mean = {xbar:.2f}")
ax[1].axvline(mu0, color="#ea580c", ls="--", lw=2, label=f"mu0 = {mu0:g}")
ax[1].hlines(0.05, ci[0], ci[1], color="#0d9488", lw=5, label="95% CI")
ax[1].set(title="Data, mean and 95% CI", xlabel="Leaf length (mm)", yticks=[], ylim=(0, 1))
ax[1].legend(frameon=False, fontsize=8)
fig.tight_layout()
fig.savefig("z_test_plot.png", dpi=300, bbox_inches="tight")Printed output: n = 16, mean = 52.4375, sample SD = 4.1947; SE = 1.0000, z = 2.4375, p (two) = 0.0148; 95% CI = [50.4775, 54.3975], Cohen’s d = 0.6094; power = 0.6835, n for 80% power = 22.
11.2 What each part does
| Line or function | What it does, and why it is there |
|---|---|
| dtype=float | Avoids integer surprises and lets np.isnan work. |
| x[~np.isnan(x)] | Drops missing values, because np.mean returns nan if any value is nan. |
| stats.norm.sf(abs(z)) | Survival function, the upper tail. More accurate than 1 - cdf far out in the tail. |
| stats.norm.ppf(1 - alpha / 2) | Critical value, 1.959964 at α = 0.05. |
| x.std(ddof=1) | The sample SD, printed only to compare with σ. NumPy’s default ddof=0 is the population formula. |
| default_rng(1) | Seeded jitter so the figure is identical every run. |
| savefig(dpi=300) | Writes the figure at print resolution. |
11.3 What the figure shows
The same two panels as the R figure: the observed z of 2.44 inside the shaded upper rejection region of the standard normal curve, and the raw leaf lengths with the sample mean, μ0 and the 95% confidence interval, which lies entirely above 50 mm.
11.4 Common Python problems and fixes
| Problem | Fix |
|---|---|
statsmodels ztest gives a different z | It uses the sample SD. Compute z with the known σ as in the script. |
proportions_ztest differs from this page | It uses p̂ in the SE by default. Pass prop_var=0.5 (your p0) to use the null SE. |
| p prints as 0.0 | Use stats.norm.logsf(z) or format with :.3e. |
| Figure window never appears | Remove matplotlib.use("Agg") and add plt.show(). |
ModuleNotFoundError: scipy | Run pip install scipy in the same environment as Python. |
11.5 Useful one-liners
from statsmodels.stats.proportion import proportions_ztest
proportions_ztest(280, 500, value=0.5, prop_var=0.5) # proportion z test, null SE
from scipy.stats import binomtest; binomtest(280, 500, 0.5) # exact check for a proportion
stats.norm.sf(2.4375) # right-tailed p from z
stats.norm.ppf([0.95, 0.975, 0.995]) # 1.645, 1.960, 2.576
int(np.ceil(((stats.norm.ppf(0.975) + stats.norm.ppf(0.8)) / 0.5) ** 2)) # n for 80% power, d = 0.5
df.groupby("site")["y"].apply(lambda v: (v.mean() - 50) / (4 / np.sqrt(len(v)))) # z per siteRun it with python script.py from a terminal. In Jupyter, drop the matplotlib.use("Agg") and savefig lines and add plt.show().
📋 12. Reference Tables
12.1 Critical z values
| α | Two-tailed (±) | One-tailed | Confidence level |
|---|---|---|---|
| 0.10 | 1.645 | 1.282 | 90% |
| 0.05 | 1.960 | 1.645 | 95% |
| 0.01 | 2.576 | 2.326 | 99% |
| 0.001 | 3.291 | 3.090 | 99.9% |
What to conclude: reject H0 when |z| passes the value in your row. These never change with n, unlike t critical values. Values from the standard normal quantile function (Wichura, 1988).
12.2 z to p-value lookup
| |z| | Two-tailed p | One-tailed p |
|---|---|---|
| 1.000 | 0.3173 | 0.1587 |
| 1.282 | 0.1998 | 0.0999 |
| 1.500 | 0.1336 | 0.0668 |
| 1.645 | 0.1000 | 0.0500 |
| 1.960 | 0.0500 | 0.0250 |
| 2.000 | 0.0455 | 0.0228 |
| 2.326 | 0.0200 | 0.0100 |
| 2.500 | 0.0124 | 0.0062 |
| 2.576 | 0.0100 | 0.0050 |
| 3.000 | 0.0027 | 0.0013 |
| 3.291 | 0.0010 | 0.0005 |
What to conclude: the one-tailed p is exactly half the two-tailed p when z points in the predicted direction. The worked example, z = 2.4375, sits between 2.326 and 2.500, so its two-tailed p of 0.0148 lies between 0.0200 and 0.0124.
12.3 Cohen’s d bands and the sample size for 80% power
| d | Label | n for 80% power, two-tailed α = 0.05 | n, one-tailed |
|---|---|---|---|
| 0.1 | Negligible | 785 | 619 |
| 0.2 | Small | 197 | 155 |
| 0.3 | Small | 88 | 69 |
| 0.5 | Medium | 32 | 25 |
| 0.8 | Large | 13 | 10 |
| 1.0 | Large | 8 | 7 |
What to conclude: halving the effect you want to detect roughly quadruples the sample you need. From n = ((zα/2 + zβ) ÷ d)², bands from Cohen (1992).
12.4 Power at d = 0.5 for different n
| n | 10 | 20 | 30 | 50 | 100 |
|---|---|---|---|---|---|
| Power, two-tailed α = 0.05 | 0.353 | 0.609 | 0.782 | 0.942 | 0.999 |
What to conclude: a study of 10 detects a medium effect only about one time in three. A non-significant result from such a study tells you very little.
12.5 z versus t critical values, two-tailed α = 0.05
| n | 5 | 10 | 15 | 30 | 60 | 120 | ∞ |
|---|---|---|---|---|---|---|---|
| t critical (df = n − 1) | 2.776 | 2.262 | 2.145 | 2.045 | 2.001 | 1.980 | 1.960 |
| z critical | 1.960 | 1.960 | 1.960 | 1.960 | 1.960 | 1.960 | 1.960 |
What to conclude: using z when σ is really estimated makes the bar too low, most of all in small samples. At n = 10 the correct cut-off is 2.262, not 1.960, so a z test would produce too many false positives.
12.6 Minimum n for the one proportion z test (n·p0 ≥ 10 and n(1 − p0) ≥ 10)
| p0 | 0.50 | 0.30 | 0.20 | 0.10 | 0.05 | 0.03 | 0.01 |
|---|---|---|---|---|---|---|---|
| Minimum n | 20 | 34 | 50 | 100 | 200 | 334 | 1000 |
What to conclude: rare outcomes need large samples before the normal approximation is safe. Below these sizes, report the exact binomial p shown in the results table (Brown, Cai and DasGupta, 2001).
📈 13. Example Results
Eight worked one sample z test examples with solutions, from the textbook case to a test that should not be used. Every example is also a built-in sample dataset in Section 2, so you can load it and check the numbers yourself.
Leaf length in a botany practical
The worked example used in every section of this page.
Sixteen leaves measured to the nearest mm. Herbarium records give a regional mean of 50 mm with σ = 4 mm.
| Statistic | Value | Note |
|---|---|---|
| x̄ | 52.4375 mm | Sample mean |
| SE | 1.0000 | 4 ÷ √16 |
| z | 2.4375 | Two-tailed |
| p | 0.0148 | Below 0.05 |
| 95% CI | [50.48, 54.40] | Excludes 50 |
| d | 0.61 | Medium |
What it means: Leaves at this site are longer than the regional benchmark by about 2.4 mm, a medium effect.
How to write it: Mean leaf length (M = 52.44 mm) was significantly greater than 50 mm, z = 2.44, p = .015, d = 0.61.
IQ after a reading programme
IQ is scaled to σ = 15, the classic known-sigma case.
Thirty pupils finished a reading programme. Does their mean IQ exceed the population mean of 100? Right-tailed test.
| Statistic | Value | Note |
|---|---|---|
| x̄ | 106.17 | Sample mean |
| SE | 2.7386 | 15 ÷ √30 |
| z | 2.2517 | Right-tailed |
| p | 0.0122 | Below 0.05 |
| 95% CI | [100.80, 111.53] | Above 100 |
| d | 0.41 | Small to medium |
What it means: The programme group scores about 6 IQ points higher than the population, a small to medium effect.
How to write it: Pupils in the programme scored higher than the population mean of 100 (M = 106.17), z = 2.25, p = .012, one-tailed, d = 0.41.
Cereal box fill weight
A result just inside α that needs careful wording.
Thirty-six boxes from line 2. The machine has a long-run σ of 3 g and a target of 500 g.
| Statistic | Value | Note |
|---|---|---|
| x̄ | 498.96 g | Sample mean |
| SE | 0.5000 | 3 ÷ √36 |
| z | −2.0889 | Two-tailed |
| p | 0.0367 | Just below 0.05 |
| 95% CI | [497.98, 499.94] | Just below 500 |
| d | −0.35 | Small |
What it means: Boxes are underfilled by about 1 g. Significant at 0.05 but not at 0.01, so repeat the check before adjusting the machine.
How to write it: Mean fill weight (M = 498.96 g) was significantly below the 500 g target, z = −2.09, p = .037, d = −0.35.
Systolic blood pressure at Clinic A
Not significant, and the interval explains why.
Twenty-five patients compared with a reference of 120 mmHg and σ = 15 mmHg.
| Statistic | Value | Note |
|---|---|---|
| x̄ | 122.40 mmHg | Sample mean |
| SE | 3.0000 | 15 ÷ 5 |
| z | 0.8000 | Two-tailed |
| p | 0.4237 | Far above 0.05 |
| 95% CI | [116.52, 128.28] | Contains 120 |
| Power | 0.12 | Very low |
What it means: There is no evidence the clinic differs from 120 mmHg, but the interval is wide, so a difference of up to 8 mmHg cannot be ruled out.
How to write it: Mean systolic pressure (M = 122.40 mmHg) did not differ from 120 mmHg, z = 0.80, p = .424, 95% CI [116.52, 128.28].
Tree diameter in a forest plot
Only ten trees, so normality matters.
Ten trees in plot 7 compared with a regional mean of 30 cm and σ = 6 cm. One tree is only 12.9 cm.
| Statistic | Value | Note |
|---|---|---|
| x̄ | 33.40 cm | Sample mean |
| SE | 1.8974 | 6 ÷ √10 |
| z | 1.7920 | Two-tailed |
| p | 0.0731 | Above 0.05 |
| Skew | −1.56 | Strong left skew |
| s vs σ | 8.57 vs 6 | Spread larger than assumed |
What it means: Not significant, and the assumption panel flags skew and a sample SD well above σ. With n = 10 the result is fragile in both directions.
How to write it: Mean diameter (M = 33.40 cm) did not differ significantly from 30 cm, z = 1.79, p = .073; with n = 10 and marked skew this result should be treated as preliminary.
National exam scores, 1,600 scripts
A huge n makes a tiny gap significant.
District mean of 506 against a national mean of 500 with σ = 100, entered as summary statistics.
| Statistic | Value | Note |
|---|---|---|
| x̄ | 506.00 | Sample mean |
| SE | 2.5000 | 100 ÷ 40 |
| z | 2.4000 | Two-tailed |
| p | 0.0164 | Below 0.05 |
| 95% CI | [501.10, 510.90] | Excludes 500 |
| d | 0.06 | Negligible |
What it means: The district is genuinely a little above the national mean, but six points on a 100-point spread is unlikely to matter for policy.
How to write it: District scores (M = 506) were significantly higher than the national mean of 500, z = 2.40, p = .016, but the effect was negligible, d = 0.06.
Hospital length of stay, skewed data
What a bad fit for the z test looks like.
Twelve patients, two with long stays of 9 and 14 days. Compared with 4 days and an assumed σ of 2.5.
| Statistic | Value | Note |
|---|---|---|
| x̄ | 4.42 days | Pulled up by two long stays |
| Median | 3.00 days | Below 4 |
| z | 0.5774 | Two-tailed |
| p | 0.5637 | Not significant |
| K² normality p | 0.0004 | Strongly non-normal |
| Outliers | 2 | 9 and 14 days |
What it means: With n = 12 and heavy right skew the normal model fails. Use the median with a sign test or Wilcoxon signed-rank test instead.
How to write it: Because length of stay was strongly right-skewed (skewness = 2.19, n = 12), the median (3 days) was reported and tested with a sign test instead of a z test.
Voter support poll
A one sample proportion z test with an exact cross-check.
280 of 500 respondents support a proposal. Is support different from 50%?
| Statistic | Value | Note |
|---|---|---|
| p̂ | 0.5600 | 280 ÷ 500 |
| SE under H0 | 0.02236 | √(0.25 ÷ 500) |
| z | 2.6833 | Two-tailed |
| p | 0.0073 | Below 0.01 |
| Wilson 95% CI | [0.516, 0.603] | Excludes 0.5 |
| Exact binomial p | 0.0083 | Agrees |
What it means: A majority supports the proposal. The exact test agrees, and the Wilson interval puts support between about 52% and 60%.
How to write it: Support (56.0%, 280 of 500) was significantly higher than 50%, z = 2.68, p = .007, h = 0.12, 95% Wilson CI [0.516, 0.603].
🧪 14. Data Collection Protocol
Study design: the one sample z test assumes one simple random sample of independent observations, measured on an interval or ratio scale (or as success and failure for a proportion), from a population whose standard deviation is known before the data are collected.
- Fix the null value before collecting data for the one sample z test. Write down μ0 or p0 and where it comes from: a standard, a target, a census figure or a published benchmark.
- Document the source of σ. Name the record, the time span and the population it describes. If you cannot, plan a one-sample t test instead.
- Choose the tail and α in advance. A one-tailed one sample z test is only valid if the direction was chosen before seeing the data.
- Calculate the sample size for your one sample z test. Use n = ((zα/2 + zβ) ÷ d)². For a medium effect, d = 0.5, you need 32 for 80% power.
- Randomise selection. Pick units with a random number table or software, not by convenience. A biased sample makes every p-value meaningless.
- Keep observations independent. One measurement per unit. Repeated readings of the same unit must be averaged first.
- Use the same instrument and units as the source of σ. A different scale or method changes the spread.
- Record missing values as blanks, never as 0.
- For proportions, define success precisely and check that n·p0 and n(1 − p0) will both reach 10.
- Write the outlier rule in advance and keep every genuine value.
| sample_id | site | length_mm | supports (0/1) |
|---|---|---|---|
| L001 | Plot 7 | 52 | 1 |
| L002 | Plot 7 | 48 | 0 |
| L003 | Plot 7 | 55 | 1 |
Minimum sample: n ≥ 30 when the population shape is unknown; smaller n only when the population is known to be normal. For proportions, see Table 12.6. Pre-registration: record μ0, σ, the tail, α and n on OSF or in your protocol before data collection.
Common mistakes that make the data unusable: taking σ from the same sample, mixing two populations with different spreads, measuring the same unit twice, and choosing the tail after looking at the mean.
🎯 15. When to Use a One Sample Z Test
Use the one sample z test when:
- ✓ You compare one sample mean with a fixed value and σ is known from outside the sample.
- ✓ The data are roughly normal, or n is at least 30.
- ✓ You test one proportion against p0 and n·p0 and n(1 − p0) are both 10 or more.
- ✓ Observations are independent, one per unit.
Do not use it when:
- ✗ σ is unknown and estimated from the sample: use the one-sample t test.
- ✗ You compare two groups: use the two sample z test or an independent t test.
- ✗ The data are small and skewed: use the sign test or Wilcoxon signed-rank test.
- ✗ A rare proportion fails the n·p0 ≥ 10 rule: use the exact binomial test.
- ✗ The same units are measured twice: use a paired t test.
Real-world examples:
- Manufacturing: is the mean fill weight on target, given the machine’s long-run σ?
- Psychology: do pupils on a programme score above the IQ norm of 100, with σ = 15?
- Polling: does support for a proposal differ from 50%?
- Ecology: is mean body mass in a population different from a regional reference with a well-documented spread?
One sample vs two sample z test: the one sample version compares one group with a fixed number; the two sample version compares two groups with each other. Decision tree: one group and a fixed value? Then is σ known? Yes, z test. No, t test. Data skewed and small? Sign or Wilcoxon test. Counting successes? Proportion z test, or exact binomial when n·p0 is below 10.
🔧 16. Troubleshooting and Common Errors
My z test and t test give different p-values
Cause: The t test uses the sample SD and a t distribution; the z test uses your known σ and the normal curve.
Fix: That is expected. Keep the z test only if σ really is known from outside the sample.
Excel Z.TEST gives half my p-value
Cause: Z.TEST returns the upper one-tailed p.
Fix: Use =2*MIN(Z.TEST(r,μ0,σ),1-Z.TEST(r,μ0,σ)) for two-tailed.
statsmodels ztest disagrees with this page
Cause: It replaces σ with the sample SD.
Fix: Compute z with the known σ as in Section 11.
R prop.test gives a different p for a proportion
Cause: Its continuity correction is on by default.
Fix: Add correct = FALSE, or switch the correction on here to match.
The assumption panel says s does not agree with σ
Cause: The spread in your sample is far from the σ you entered.
Fix: Check the source of σ. If it does not apply, use the t test.
p shows as < 0.0001
Cause: z is very large.
Fix: Report p < .001 in APA style; the exact value is in the Doc export.
Fewer values were read than I pasted
Cause: Text, units or stray symbols were ignored.
Fix: Read the "ignored" list under the box and clean those entries.
The proportion z test and exact test disagree
Cause: n·p0 or n(1 − p0) is small, so the normal approximation is poor.
Fix: Report the exact binomial p from the results table.
Results disappeared after I changed a setting
Cause: Any change clears results so you never read stale numbers.
Fix: Press Run again.
My uploaded column does not appear
Cause: Fewer than 80% of its cells are numeric.
Fix: Remove text notes from the column, or paste the values instead.
⚖ 17. Assumptions and Limitations
Assumptions
- σ is known. Check: name its source. If it fails: when the true spread is larger than σ, the SE is too small and p-values are too small, giving false positives; when it is smaller, the test is too conservative.
- Independence. Check: the design, one unit per value. If it fails: clustered data shrink the real information, so p-values are too small.
- Normal sampling distribution. Check: n ≥ 30, or the K² test and skewness in the panel. If it fails with small n: one tail is over-stated and the other under-stated, so one-tailed p-values are the most biased.
- Random sampling. Check: how units were chosen. If it fails: the estimate is biased in an unknown direction, and no p-value can correct it.
- For proportions, n·p0 ≥ 10 and n(1 − p0) ≥ 10. Check: the panel. If it fails: the z test is usually too liberal for rare outcomes, as in the defect-rate sample dataset in Section 2, where z gives p = 0.039 but the exact test gives 0.060.
Limitations
- Known σ is rare in real research. For most data the one-sample t test is the right tool.
- The test compares one group with one number. For two groups use the two sample z test or independent samples t test.
- It is sensitive to outliers because it uses the mean. For robust inference use the Wilcoxon signed-rank test or a bootstrap interval.
- A p-value is not the probability that H0 is true. For that question use a Bayesian test with a Bayes factor.
- The proportion z test is approximate. For small or extreme samples use the exact binomial test.
🏁 18. Conclusion
A one sample z test calculator answers one clear question: is the population mean, or proportion, equal to a stated value? It works by counting how many standard errors the sample estimate sits from the null value. When σ is genuinely known, the standard normal curve gives an exact p-value with fixed critical values of 1.960 and 1.645.
In the worked example, 16 leaves with a mean of 52.44 mm against a benchmark of 50 mm and σ = 4 gave z = 2.44 and p = 0.0148, with a 95% interval of 50.48 to 54.40 mm and a medium effect of d = 0.61. That is the complete story: the decision, the size and the uncertainty.
The biggest risk is not the arithmetic but the inputs. A σ borrowed from the sample, a tail chosen after looking, or a rare proportion with too few cases will each give a confident but wrong answer. The assumption panel exists to catch exactly these problems.
Run your own data above, read the assumption checks before the p-value, and copy one of the five reporting templates. Then come back to this one sample z test calculator whenever you need to test a mean with known σ or a single proportion. Run the analysis above to replace this summary with your own results. ___
❓ 19. Frequently Asked Questions
Q1. What is a one sample z test?
A one sample z test is a hypothesis test that checks whether a population mean equals a stated value μ0 when the population standard deviation σ is known. It turns the gap between the sample mean and μ0 into a z score, z = (x̄ − μ0) ÷ (σ ÷ √n), and compares it with the standard normal distribution.
Q2. What is the one sample z test formula?
For a mean, z = (x̄ − μ0) ÷ (σ ÷ √n). For a proportion, z = (p̂ − p0) ÷ √(p0(1 − p0) ÷ n). The two-tailed p-value is 2 × (1 − Φ(|z|)), where Φ is the standard normal cumulative distribution.
Q3. When do you use a one sample z test?
Use it when you compare one sample with a fixed value, the population standard deviation is known from outside the sample, and the data are normal or n is at least 30. Use the proportion version when testing one proportion with n·p0 and n(1 − p0) both at least 10.
Q4. What are the conditions for a one sample z test?
There are four: a random sample, independent observations, a known population σ, and a normal sampling distribution, which holds if the population is normal or n ≥ 30. For proportions the condition is n·p0 ≥ 10 and n(1 − p0) ≥ 10.
Q5. What is the difference between a one sample t test and a z test?
The z test uses a known population σ and the standard normal distribution. The t test estimates the spread with the sample SD and uses the t distribution with n − 1 degrees of freedom. When σ is unknown, which is most real data, the t test is correct.
Q6. What does calculating the one sample z test serve to give you?
It gives you a z score showing how many standard errors your sample mean lies from the hypothesised mean, and a p-value showing how surprising that distance would be if the null hypothesis were true. Together they decide whether to reject H0.
Q7. The one sample z test is used to compare the what?
The one sample z test is used to compare the mean of a single sample with a known or hypothesised population mean, when the population standard deviation is known. The proportion version compares a sample proportion with a hypothesised population proportion.
Q8. How do you do a one sample z test step by step?
State H0 and H1 and choose α. Compute the sample mean and the standard error σ ÷ √n. Calculate z = (x̄ − μ0) ÷ SE. Find the p-value from the normal curve. Reject H0 if p < α, then report z, p, the confidence interval and Cohen’s d.
Q9. What is a one sample z test for proportions?
It tests whether a population proportion equals p0 using z = (p̂ − p0) ÷ √(p0(1 − p0) ÷ n). For example, 280 supporters out of 500 gives p̂ = 0.56, z = 2.68 and p = 0.0073 against p0 = 0.5. Check that n·p0 and n(1 − p0) are at least 10.
Q10. What is an example of a one sample z test?
Sixteen leaves have a mean length of 52.44 mm. The regional mean is 50 mm with σ = 4 mm. The standard error is 4 ÷ √16 = 1, so z = 2.44 and the two-tailed p = 0.0148. The mean is significantly larger than 50 mm.
Q11. How do you do a one sample z test in Excel?
Compute the mean with AVERAGE, the standard error as σ/SQRT(COUNT(range)), z as (mean − μ0)/SE, and the two-tailed p with =2*(1-NORM.S.DIST(ABS(z),TRUE)). Excel’s Z.TEST returns only the upper one-tailed p, so double it carefully.
Q12. How do you run a one sample z test in R?
Base R has no z.test function. Compute z <- (mean(x) - mu0) / (sigma / sqrt(length(x))) and p <- 2 * pnorm(-abs(z)). The BSDA package offers z.test(x, mu = 50, sigma.x = 4) as a one-liner.
Q13. How do you run a one sample z test in Python?
Compute z = (x.mean() - mu0) / (sigma / np.sqrt(len(x))) and p = 2 * scipy.stats.norm.sf(abs(z)). Avoid statsmodels ztest for a known σ, because it estimates σ from the sample.
Q14. Consider a one sample two sided z test: when do you reject H0?
In a two-sided one sample z test you reject H0 when |z| is larger than the critical value: 1.645 at α = 0.10, 1.960 at α = 0.05 and 2.576 at α = 0.01. Equivalently, reject when the two-tailed p-value is below α.
Q15. What is the difference between a one sample and two sample z test?
A one sample z test compares one sample mean with a fixed value μ0. A two sample z test compares the means of two independent samples with each other, using both known standard deviations in the standard error.
Q16. What is the purpose of a one sample z test?
Its purpose is to decide whether a sample provides enough evidence that the population mean, or proportion, differs from a stated value such as a target, a standard or a historical benchmark.
Q17. Can I use a z test if n is less than 30?
Yes, if σ is known and the population itself is normal. With small n and skewed data the p-value becomes unreliable, so use the sign test or Wilcoxon signed-rank test, or the t test if σ is unknown.
Q18. What is the critical value for a one sample z test?
At α = 0.05 the critical value is ±1.960 for a two-tailed test and 1.645 for a one-tailed test. At α = 0.01 it is ±2.576 two-tailed and 2.326 one-tailed. These values do not depend on the sample size.
Q19. How do I report a one sample z test in APA format?
Give the mean, σ and n, then z to two decimals, the exact p, the effect size and the confidence interval, for example: M = 52.44, σ = 4, n = 16, z = 2.44, p = .015, d = 0.61, 95% CI [50.48, 54.40].
Q20. What effect size goes with a one sample z test?
Cohen’s d = (x̄ − μ0) ÷ σ for means and Cohen’s h = 2·asin√p̂ − 2·asin√p0 for proportions. Values of 0.2, 0.5 and 0.8 are small, medium and large.
📑 20. Cite This Tool
StatsUnlock. (2026). One sample z test calculator [Interactive statistical tool]. https://statsunlock.com/one-sample-z-test-calculator/@misc{statsunlock_ztest_2026, title={One Sample Z Test Calculator}, author={{StatsUnlock}}, year={2026}, note={Interactive statistical tool}, url={https://statsunlock.com/one-sample-z-test-calculator/}}A two-tailed one-sample z test was computed with the StatsUnlock One Sample Z Test Calculator (2026). The sample mean (n = 16) was compared with μ0 = 50 using a known population SD of σ = 4. Significance was set at α = 0.05, and the 95% confidence interval and Cohen’s d are reported.🔗 21. Related Tools
The right test when σ is unknown and has to be estimated from your sample.
Open the tool →Compare the means of two independent groups with known standard deviations.
Open the tool →A dedicated tool for testing a single proportion against p0.
Open the tool →Turn any z, t, chi-square or F statistic into a p-value.
Open the tool →Standardise single values against a mean and standard deviation.
Open the tool →Look up z, t, chi-square and F cut-offs for any α and tail.
Open the tool →Build intervals for a mean or proportion at any confidence level.
Open the tool →Plan the sample size you need before collecting data.
Open the tool →📖 22. Glossary of Terms
- Alpha (α)
- The false-positive rate you accept, chosen before the test. Usually 0.05.
- Alternative hypothesis (H1)
- The claim that the population value differs from, or is above or below, the null value.
- Central limit theorem
- The rule that sample means are close to normally distributed for large n, whatever the population shape.
- Cohen’s d
- The difference between the sample mean and μ0 divided by σ. It measures size, not significance.
- Cohen’s h
- An effect size for proportions based on the arcsine of their square roots.
- Confidence interval
- A range of population values that are compatible with the data at a chosen level, such as 95%.
- Continuity correction
- A 0.5 adjustment that makes a normal approximation to counts slightly more conservative.
- Critical value
- The z beyond which H0 is rejected, such as 1.96 for a two-tailed test at α = 0.05.
- Exact binomial test
- A test for one proportion that uses the binomial distribution directly, with no normal approximation.
- Holm correction
- A step-down method that adjusts p-values when several groups are tested, controlling the chance of any false positive.
- Known σ
- A population standard deviation that comes from outside the sample, such as a standard or long-run record.
- Null hypothesis (H0)
- The claim that the population mean equals μ0, or the proportion equals p0.
- One-tailed test
- A test with all of α in one tail, used when only one direction matters.
- p-value
- The probability of a result at least as extreme as yours if H0 were true.
- Population
- The whole group you want to make a statement about.
- Power
- The chance that the test rejects H0 when a real effect of a given size exists.
- Sample proportion (p̂)
- The number of successes divided by the sample size.
- Standard error
- The standard deviation of the sample mean across repeated samples, σ ÷ √n.
- Standard normal distribution
- The bell curve with mean 0 and standard deviation 1 that z follows under H0.
- Two-tailed test
- A test that splits α between both tails, used when a difference in either direction matters.
- Wilson interval
- A confidence interval for a proportion that stays between 0 and 1 and covers well even for small samples.
- z statistic
- The number of standard errors between the sample estimate and the null value.
📚 23. References
These peer-reviewed references support the methods used in this one sample z test calculator: the normal test statistic and its quantiles, confidence intervals for proportions, effect sizes and power, and good practice in reporting p-values.
- Agresti, A., & Coull, B. A. (1998). Approximate is better than “exact” for interval estimation of binomial proportions. The American Statistician, 52(2), 119–126. https://doi.org/10.1080/00031305.1998.10480550
- Altman, D. G., & Bland, J. M. (1995). Absence of evidence is not evidence of absence. BMJ, 311(7003), 485. https://doi.org/10.1136/bmj.311.7003.485
- Amrhein, V., Greenland, S., & McShane, B. (2019). Scientists rise up against statistical significance. Nature, 567(7748), 305–307. https://doi.org/10.1038/d41586-019-00857-9
- Benjamin, D. J., Berger, J. O., Johannesson, M., et al. (2018). Redefine statistical significance. Nature Human Behaviour, 2(1), 6–10. https://doi.org/10.1038/s41562-017-0189-z
- Bland, J. M., & Altman, D. G. (1995). Multiple significance tests: The Bonferroni method. BMJ, 310(6973), 170. https://doi.org/10.1136/bmj.310.6973.170
- Brown, L. D., Cai, T. T., & DasGupta, A. (2001). Interval estimation for a binomial proportion. Statistical Science, 16(2), 101–133. https://doi.org/10.1214/ss/1009213286
- Cohen, J. (1992). A power primer. Psychological Bulletin, 112(1), 155–159. https://doi.org/10.1037/0033-2909.112.1.155
- Cumming, G., Fidler, F., & Vaux, D. L. (2007). Error bars in experimental biology. Journal of Cell Biology, 177(1), 7–11. https://doi.org/10.1083/jcb.200611141
- du Prel, J.-B., Hommel, G., Röhrig, B., & Blettner, M. (2009). Confidence interval or p-value? Part 4 of a series on evaluation of scientific publications. Deutsches Ärzteblatt International, 106(19), 335–339. https://doi.org/10.3238/arztebl.2009.0335
- Faul, F., Erdfelder, E., Lang, A.-G., & Buchner, A. (2007). G*Power 3: A flexible statistical power analysis program for the social, behavioral, and biomedical sciences. Behavior Research Methods, 39(2), 175–191. https://doi.org/10.3758/BF03193146
- Ghasemi, A., & Zahediasl, S. (2012). Normality tests for statistical analysis: A guide for non-statisticians. International Journal of Endocrinology and Metabolism, 10(2), 486–489. https://doi.org/10.5812/ijem.3505
- Greenland, S., Senn, S. J., Rothman, K. J., Carlin, J. B., Poole, C., Goodman, S. N., & Altman, D. G. (2016). Statistical tests, P values, confidence intervals, and power: A guide to misinterpretations. European Journal of Epidemiology, 31(4), 337–350. https://doi.org/10.1007/s10654-016-0149-3
- Kwak, S. G., & Kim, J. H. (2017). Central limit theorem: The cornerstone of modern statistics. Korean Journal of Anesthesiology, 70(2), 144–156. https://doi.org/10.4097/kjae.2017.70.2.144
- Lakens, D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: A practical primer for t-tests and ANOVAs. Frontiers in Psychology, 4, 863. https://doi.org/10.3389/fpsyg.2013.00863
- Lumley, T., Diehr, P., Emerson, S., & Chen, L. (2002). The importance of the normality assumption in large public health data sets. Annual Review of Public Health, 23, 151–169. https://doi.org/10.1146/annurev.publhealth.23.100901.140546
- Newcombe, R. G. (1998). Two-sided confidence intervals for the single proportion: Comparison of seven methods. Statistics in Medicine, 17(8), 857–872. https://doi.org/10.1002/(SICI)1097-0258(19980430)17:8<857::AID-SIM777>3.0.CO;2-E
- Sullivan, G. M., & Feinn, R. (2012). Using effect size, or why the P value is not enough. Journal of Graduate Medical Education, 4(3), 279–282. https://doi.org/10.4300/JGME-D-12-00156.1
- Wasserstein, R. L., & Lazar, N. A. (2016). The ASA statement on p-values: Context, process, and purpose. The American Statistician, 70(2), 129–133. https://doi.org/10.1080/00031305.2016.1154108
- Wichura, M. J. (1988). Algorithm AS 241: The percentage points of the normal distribution. Journal of the Royal Statistical Society, Series C (Applied Statistics), 37(3), 477–484. https://doi.org/10.2307/2347330
- Wilson, E. B. (1927). Probable inference, the law of succession, and statistical inference. Journal of the American Statistical Association, 22(158), 209–212. https://doi.org/10.1080/01621459.1927.10502953
