Two-Sample Z-Test for a Difference in Means
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
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_2 | Sample averages of the two groups | same as data |
| s_1, s_2 | Sample standard deviations | same as data |
| n_1, n_2 | Number of observations in each group | count |
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 averages | 0.09 − 0.075 | 1.50% |
| Standard error | sqrt(0.06^2 ÷ 60 + 0.05^2 ÷ 50) | 1.049% |
| z | 0.015 ÷ 0.0104881 | 1.430 |
| Two-sided p-value | 0.1527 | |
| Significant at 5%? (1 | 1 if 0.152661<0.05 else 0 | 0 |
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.