Skip to main content

Two-Sample Z-Test for a Difference in Means

BeginnerData, Statistics & Computational SkillsAlso known as: quantitative foundations, compare two strategies, difference in average returns, p-value

Finds: whether two averages differ by more than chance.

When to use it: Use it to judge whether two averages really differ or the gap is plausibly noise, such as two funds, two strategies, or two periods. It assumes independent groups and large samples (roughly 30 or more each). A small p-value says the gap is hard to explain by chance; it does not say the gap is large or that it will persist. Testing many strategies and reporting the best inflates false positives.

The formula

z\displaystyle z=xˉ1−xˉ2s12/n1+s22/n2\displaystyle =\frac{\bar{x}_{1}-\bar{x}_{2}}{\sqrt{s_{1}^{2}/n_{1}+s_{2}^{2}/n_{2}}}

In words: z = (average of group 1 − average of group 2) / sqrt(sd1^2 / n1 + sd2^2 / n2); two-sided p-value = 2 x (1 − N(|z|))

What each symbol means

x-bar_1, x-bar_2Sample averages of the two groupssame as data
s_1, s_2Sample standard deviationssame as data
n_1, n_2Number of observations in each groupcount

Worked example

Strategy A averaged 9% a year over 60 observations with a standard deviation of 6%. Strategy B averaged 7.5% over 50 observations with a standard deviation of 5%.

Difference in averages0.09 − 0.0751.50%
Standard errorsqrt(0.06^2 ÷ 60 + 0.05^2 ÷ 50)1.049%
z0.015 ÷ 0.01048811.430
Two-sided p-value0.1527
Significant at 5%? (11 if 0.152661<0.05 else 00
The answer

The difference is 1.50% with a standard error of 1.049%, so z is 1.430 and the two-sided p-value is 0.1527. At the usual 5% level the gap 0.

Want every formula on a few pages?Get the free Cheat Sheet (PDF) →

Calculator

z1.430
Two-sided p-value0.1527

Keep going