Skip to content
Log in

Theory

Pythagoras in statistics: distances and errors in quadrature

Euclidean and Manhattan distance, why independent errors add as squares, the pooled SE of a z-test vs the unpooled SE of an interval, and how to read the Wilson and Newcombe interval formulas.

~9 min read · 9 exercises · 250 points

Before you start

The shortcut across

You know Pythagoras from school, and statistics at Klasna uses the same rule far more often than it admits, though no triangle appears in a test report.

You'll use it for distances between learners described by two numbers, and then for errors: why independent uncertainties combine by adding squares rather than plain values, and what that means for the error of a difference.

Pythagoras as a distance between learners

In a right triangle, c² = a² + b²: legs of 3 and 4 give a diagonal of √(9 + 16) = 5. Statistics uses this school rule far more often than it admits, and the first place is distance.

Seen from above, a cat heads diagonally across a rectangular rug toward an orange bowl in the far corner; a dotted line along the edges marks the longer way round.
The diagonal is shorter than the two sides added together.

Describe each learner by numbers, for example lessons a month and homework minutes a week. A is (6, 30), B is (9, 34). The differences, 3 and 4, are the legs, and the straight-line Euclidean distance is the diagonal: √(3² + 4²) = 5.

Learner A at (6, 30) and learner B at (9, 34): the Euclidean distance is the diagonal, √(3² + 4²) = 5; the Manhattan distance follows the grid, 3 + 4 = 7.
Straight line or grid: two ways to measure how far apart two learners are.

With more features only the number of squares grows: d = √Σ(xᵢ − yᵢ)². Subtract feature by feature, square, add, and take one root at the end.

dEuclid=∑i(xi−yi)2dManhattan=∑i∣xi−yi∣d_{\text{Euclid}} = \sqrt{\sum_i (x_i - y_i)^2} \qquad d_{\text{Manhattan}} = \sum_i |x_i - y_i|
Euclidean: the straight line, any number of features. Manhattan: along the grid; |x| is the absolute value, the number without its sign.

Two cautions. The root comes last: rooting each square and adding gives 3 + 4 = 7, a different measure. And the features need comparable scales: if one is in minutes and the other in lessons, the minutes dominate the sum. That's why clustering usually standardizes features first, which Standardizing in this module explains.

  • Do
    d = √(6² + 8²) = √100 = 10: square, add, then one root.
  • Don't
    Compare learners on raw minutes and raw lesson counts together.

    The feature with the bigger numbers swamps the distance.

Manhattan distance and the absolute value

The Manhattan distance measures along the grid instead of across it, like walking city blocks: add up the size of each difference and ignore its sign. d = Σ|xᵢ − yᵢ|.

Formula: Euclidean: the straight line, any number of features. Manhattan: along the grid; |x| is the absolute value, the number without its sign. · shown above

The bars |x| mean the absolute value: the number without its sign. |−4| = 4 and |4| = 4. Without the bars, differences in opposite directions would cancel, just as deviations from a mean do.

For learners A (6, 30) and B (9, 34): |9 − 6| + |34 − 30| = 3 + 4 = 7, against 5 along the straight line. The Manhattan distance is never shorter than the Euclidean one; the two are equal only when the points differ in a single feature.

Which one to use is a modelling choice. The Euclidean distance, through its squares, punishes one big difference more. The Manhattan distance treats every unit of difference alike, so one odd feature sways it less. Both need features on comparable scales.

  • Do
    |7 − 3| + |4 − 10| = 4 + 6 = 10.
  • Don't
    (7 − 3) + (4 − 10) = −2.

    Without absolute values opposite differences cancel.

Independent errors add in quadrature

The SE of a difference between two independent groups is not the sum of their SEs. Say variant A converts at 8% with SE 0.5 pp and B at 10.6% with SE 1.2 pp. The SE of B − A is

√(0.5² + 1.2²) = √(0.25 + 1.44) = √1.69 = 1.3 pp, not 1.7.

Why? The two errors are random and independent. When A happens to be measured too high, B is as likely to be too low as too high, so the errors partly cancel. What adds up exactly is the variance: 0.25 + 1.44 = 1.69. The SE, its square root, adds like the sides of a right triangle. This is called adding in quadrature.

A right triangle with legs SE_A = 0.6 pp and SE_B = 0.8 pp has a hypotenuse of 1.0 pp, the SE of the difference; adding the legs would give 1.4 pp.
Independent errors combine like the sides of a right triangle.

It changes decisions. With the plain sum, the 2.6 pp gap is 2.6 ÷ 1.7 ≈ 1.5 SEs and gets waved off as noise; with the right SE it is 2.6 ÷ 1.3 = 2 SEs.

  • Do
    SE_diff = √(0.5² + 1.2²) = 1.3 pp.
  • Don't
    SE_diff = 0.5 + 1.2 = 1.7 pp.

    Adding SEs assumes the errors always push the same way.

One rule for independent uncertainties: σ_total = √Σσ²

The same Pythagoras works for any sum of independent uncertain pieces, not only for test groups. If tasks run one after another and each has its own independent uncertainty σ, the uncertainty of the total is

σ_total = √(σ₁² + σ₂² + …).

Two tasks with σ = 3 and 4 days: √(9 + 16) = 5 days, not 7. Square each, add, and take one root at the end.

The total always lands above the largest piece and below the plain sum. Notice how one big piece dominates: with σ = 1, 1 and 5 days, √(1 + 1 + 25) ≈ 5.2, barely more than the biggest piece alone. To shrink a combined uncertainty, work on the largest source first; trimming the small ones hardly moves it.

Project plans, budgets built from several estimates and measurements with several error sources all combine this way, as long as the pieces are independent.

  • Do
    σ = 1, 1 and 5 days → √27 ≈ 5.2 days: cut the 5 first.
  • Don't
    "Three tasks ± 2, 3 and 6 days, so the plan is ± 11 days."

    For independent tasks the total is √(4 + 9 + 36) = 7 days.

Quadrature needs independence

Adding in quadrature rests on one assumption: the pieces are independent, so their errors partly cancel. When that fails, so does the shortcut.

Example: two tasks of a Klasna course launch, writing the lessons and recording the videos, both depend on the same overloaded tutor. If the tutor falls ill, both slip together. Their errors push the same way, nothing cancels, and the combined uncertainty moves toward the plain sum: with σ = 3 and 4 days, closer to 7 than to 5.

The reverse also happens: errors that tend to push in opposite directions cancel more than independence allows, and the total falls below the quadrature figure.

So before using √Σσ², ask one question: could one cause move several pieces at once? Shared people, a shared supplier, the same seasonal dip. If yes, quadrature understates the risk. Treat the linked pieces as one, or add them plainly for a cautious bound.

  • Do
    "Both tasks depend on one tutor, so I'll budget ± 7 days for the pair, not ± 5."
  • Don't
    Combine the delays of tasks with a shared cause by √Σσ² without asking.

    Linked errors don't cancel, so quadrature understates the risk.

Pooled or unpooled SE for two shares

In a conversion test two versions of the same Pythagoras appear, and they answer different questions.

  • The z-test asks "what if A and B really convert the same?". Under that assumption both groups share one rate, estimated by pooling: p̄ = all conversions ÷ all users. SE_test = √(p̄(1 − p̄)(1/n₁ + 1/n₂)).
  • The interval for the difference asks "how big is the gap?". It doesn't assume equal rates, so each group keeps its own: SE_interval = √(p₁(1 − p₁)/n₁ + p₂(1 − p₂)/n₂).
SEtest=pˉ(1−pˉ)(1n1+1n2)SEinterval=p1(1−p1)n1+p2(1−p2)n2SE_{\text{test}} = \sqrt{\bar{p}(1-\bar{p})\left(\tfrac{1}{n_1} + \tfrac{1}{n_2}\right)} \qquad SE_{\text{interval}} = \sqrt{\tfrac{p_1(1-p_1)}{n_1} + \tfrac{p_2(1-p_2)}{n_2}}
Both are Pythagoras: a square root of a sum of two variances. The test assumes the rates are equal; the interval doesn't.

Both are the square root of a sum of two variances, quadrature again; only the rates inside differ. When the rates are close, so are the numbers: with 2,000 users each at 10% and 12%, both come out at about 0.99 pp. They drift apart when the rates are far apart.

A reading rule for reports: the pooled SE belongs to the test's yes/no verdict, the unpooled one to the range of the effect. Adding the two groups' SEs is never right.

  • Do
    For the z-test, pool: p̄ = (200 + 240) ÷ 4,000 = 0.11.
  • Don't
    Use the pooled SE to state how big the lift is.

    The range of the effect uses each group's own rate.

Reading Wilson's interval

The simple interval p ± z·√(p(1 − p)/n) misbehaves for small shares or small samples: it can even dip below 0%. Wilson's interval fixes that, and product analytics reports it often. You don't need to derive it, only to recognize its three parts:

  • a centre nudged toward 50%: p + z²/(2n) instead of p;
  • an SE with a small correction: √(p(1 − p)/n + z²/(4n²));
  • everything divided by 1 + z²/n, which shrinks it slightly.
p+z22n⏞center, nudged±zp(1−p)n+z24n2⏞SE with a correction1+z2n\frac{\overbrace{p + \frac{z^2}{2n}}^{\text{center, nudged}} \pm z\overbrace{\sqrt{\frac{p(1-p)}{n} + \frac{z^2}{4n^2}}}^{\text{SE with a correction}}}{1 + \frac{z^2}{n}}
For p = 5%, n = 400, z = 1.96: about 3.3% to 7.6%, centered near 5.4% rather than 5%.

For p = 5%, n = 400 and z = 1.96 the centre moves to about 5.4%, and the interval runs from about 3.3% to 7.6%. It isn't symmetric around 5%: it reaches further up than down, because a share can't go below 0.

With large n the corrections fade (z²/n becomes tiny) and Wilson nearly matches the simple interval. The nudge matters most exactly where the simple one fails: rare events and small tests.

  • Do
    "5% conversion, Wilson 95% interval 3.3%–7.6%."
  • Don't
    "1% conversion on 50 users: interval −1.8% to 3.8%."

    A share below zero is the simple interval failing; Wilson stays above 0.

Newcombe: Wilson widths combined by Pythagoras

For the difference between two shares, Newcombe's interval reuses two Wilson intervals. Each group gets its own Wilson interval, and the distance from its estimate to an end of that interval is a one-sided width, w_A and w_B. The groups are independent, so the widths combine by Pythagoras: √(w_A² + w_B²).

With widths of 0.6 and 0.8 pp, the combined width is √(0.36 + 0.64) = 1.0 pp, not 1.4. Same shape, new inputs. Whenever you see a square root of a sum of squares, read it as "independent pieces combined".

How it fits together: Pythagoras gives straight-line distances between learners, the SE of a difference, the uncertainty of a chain of tasks and the Newcombe width, always for independent pieces. The next lesson divides by such spreads to put different numbers on one scale: z, CV, effect size and r.

  • Do
    Widths 0.6 and 0.8 pp → √(0.36 + 0.64) = 1.0 pp.
  • Don't
    Widths 0.6 and 0.8 pp → 1.4 pp for the difference.

    That's the plain sum; independent widths combine in quadrature.

Ready to practise?

Answer the lesson's exercises and earn 250 points the first time you finish it.

Start the exercises