1.3.9 · D3Probability & Statistics

Worked examples — Covariance and correlation

3,516 words16 min readBack to topic

This page is a case atlas. The parent note gave you the formulas; here we walk through every kind of situation those formulas can meet — every sign, the zero cases, the degenerate cases, the limiting values, a real-world word problem, and an exam twist. Nothing is left as "you'll figure out the rest".

If you have not yet met (the average of a random variable) or (its spread), pause and read 1.3.05-Expectation-and-variance first — every step below leans on them. The idea of two variables having a joint table of probabilities comes from 1.3.08-Joint-and-marginal-distributions, and the notion of "moving together" ties back to 1.3.01-Random-variables.


Two worlds: population vs sample — pin down every symbol

Before any example we must be crystal-clear about which world we are in, because covariance and correlation each have two versions and the page will use both.


The scenario matrix

Now list every distinct case covariance/correlation can present. Each row is a "cell" the reader must handle; each worked example is tagged with the cell it fills and the world it uses.

Cell Situation World Filled by
A Positive: sample Ex 1
B Negative: sample Ex 2
C Limit sample Ex 3
D Limit sample Ex 3
E Zero because independent, population Ex 4
F Zero despite dependence, population Ex 5
G Degenerate constant, undefined sample Ex 6
H Scale change (units trap) sample Ex 7
I Real-world word problem sample Ex 8
J Exam twist: linear transform population Ex 9

Figure s01 is a 2×2 gallery, one panel per cell, with each panel titled by its cell letter and its target , and with the mean-lines drawn in so you can literally see which quadrants the dots fall in. Read it like this:

  • top-left, Cell A (): dots hug a rising trend — most sit in the "both above mean / both below mean" quadrants (products positive).
  • top-right, Cell B (): dots hug a falling trend — opposite quadrants (products negative).
  • bottom-left, Cell E (, independent): a shapeless round blob, no tilt.
  • bottom-right, Cell F (, but a parabola): a perfect ∪ curve — fully determined, yet symmetric left-right so the tilt cancels to zero. That last panel is the trap.

Figure — Covariance and correlation
Alt text: four scatter panels arranged 2×2. Top-left, rising blue cloud labelled Cell A rho positive. Top-right, falling orange cloud labelled Cell B rho negative. Bottom-left, round green blob labelled Cell E rho zero independent. Bottom-right, a red U-shaped parabola labelled Cell F rho zero curve. Dashed grey mean-lines cross each panel dividing it into four quadrants.


Cell A — Positive sample covariance


Cell B — Negative sample covariance


Cells C & D — the extremes

Figure s02 draws both perfect lines used in this example. Look at the blue rising line (Cell C) and the orange falling line (Cell D): every data dot sits exactly on its line — no scatter at all. That perfect fit is what forces (the cosine of the angle between the two centred arrows from the box above) to : perfectly parallel arrows, angle or .

Figure — Covariance and correlation
Alt text: an X-Y plane with two straight lines of four dots each. A blue line rises left-to-right through the points one-three, two-five, three-seven, four-nine, labelled Y equals two X plus one, r equals plus one, Cell C. An orange line falls through one-minus-one, two-minus-three, three-minus-five, four-minus-seven, labelled Y equals minus two X plus one, r equals minus one, Cell D. A grey horizontal axis marks y equals zero.


Cell E — zero because truly independent


Cell F — zero despite perfect dependence


Cell G — degenerate: a constant variable


Cell H — the units trap


Cell I — real-world word problem

Figure s03 plots the four data points below with their mean-lines, so you can see every dot land in the top-right or bottom-left quadrant — the visual signature of a strong positive before any arithmetic.

Figure — Covariance and correlation
Alt text: a scatter of four green dots rising steeply from lower-left to upper-right, at ice-cream sales two-one, four-two, six-four, eight-five. Dashed grey vertical line at mean x equals five and horizontal line at mean y equals three split the plane; every dot sits in the lower-left or upper-right quadrant, signalling positive correlation.


Cell J — exam twist: linear transform


Recall

Recall Population vs sample symbols

Which symbols belong to which world? ::: Population: . Sample: .

Recall Definition of

How is the sample standard deviation built? ::: — the typical distance of -values from .

Recall Does the

affect ? Why does sample correlation not care whether you divide by or ? ::: The appears in numerator and (via the two square roots) in the denominator, so it cancels.

Recall Correlation as a cosine

What geometric object is ? ::: The cosine of the angle between the two centred deviation-arrows; Cauchy–Schwarz forces .

Recall The two flavours of "zero"

Zero correlation from independence vs from nonlinearity — same? ::: No. Independence ⇒ zero, but zero ⇏ independence (Ex 5's ).

Recall Constant variable

What is when one variable never changes? ::: Undefined ( → divide by zero), even though sample covariance is .

Recall Linear transform law

::: ; additive constants drop out, and picks up .

Recall Units

Change units of — what moves, covariance or correlation? ::: Covariance scales; correlation stays fixed (scale-invariant).