This page is the drill floor for Correlation Analysis and Multicollinearity . We take every situation the topic can hand you — perfect positive, perfect negative, zero, degenerate (constant) features, a real word problem, and an exam trap — and grind each one to a checked number.
Nothing here uses a symbol you have not met. But a handful of symbols do a lot of work, so let us pin them down before the first example, in plain words.
Definition The symbols we lean on
x ˉ (read "x-bar") = the average of the x -values. Add them up, divide by how many. It is the "balance point" of the numbers.
y ˉ (read "y-bar") = exactly the same idea for the y -values: the average of the Y list, its balance point.
r = the correlation coefficient : a single number between − 1 and + 1 that says how tightly two features move together in a straight line. + 1 = lockstep up, − 1 = perfect see-saw, 0 = no straight-line link.
VIF j = Variance Inflation Factor for feature number j (the subscript j just names which feature we are examining — feature 1, feature 2, ...). It says how many times more uncertain we become about that feature's effect because the other features already explain it. 1 = perfectly clean, big = redundant. Its formula is built in Example 6 before we use it.
Intuition The one picture behind everything
For each sample i , compute two things: how far x i sits from its average (x i − x ˉ ) and how far y i sits from its average (y i − y ˉ ). Multiply them. If a point is up-right or down-left of both averages, the product is positive (they agree). If up-left or down-right, negative (they disagree). Correlation is just the normalized average of these agreement scores . Hold that picture — every example below is that picture with different dots.
The figure below draws this for five dots. The dashed lavender lines are the two averages x ˉ and y ˉ ; they split the plane into four boxes. Green dots sit in an "agree" box (both above average, or both below) and add a positive product; coral dots sit in a "disagree" box and add a negative product. Correlation is the running total of these green-minus-coral contributions, then rescaled to land in [ − 1 , 1 ] .
Every problem this topic throws lives in one of these cells. The examples that follow are labelled with the cell they cover.
Cell
Scenario class
What makes it tricky
Covered by
A
Perfect positive (r = + 1 )
Scaled copy of a feature
Ex 1
B
Perfect negative (r = − 1 )
Reflected copy — sign of numerator flips
Ex 2
C
Genuinely zero (r = 0 )
Numerator cancels; watch for nonlinear traps
Ex 3
D
Partial / mixed sign
Real messy data, $0<
r
E
Degenerate input
A constant feature → division by zero
Ex 5
F
Limiting behaviour
R j 2 → 1 so VIF → ∞
Ex 6
G
Real-world word problem
Translate business words → numbers
Ex 7
H
Exam twist
High individual r but a hidden third feature; condition number
Ex 8
X = [ 10 , 20 , 30 , 40 ] , Y = [ 3 , 6 , 9 , 12 ] . Find r X Y .
Forecast: Y is exactly 0.3 × X . Before computing — guess the value of r . (Write it down.)
Step 1 — averages. x ˉ = 4 10 + 20 + 30 + 40 = 25 , y ˉ = 4 3 + 6 + 9 + 12 = 7.5 .
Why this step? Everything is measured relative to the average , so we need the balance point first.
Step 2 — deviations. x − x ˉ = [ − 15 , − 5 , 5 , 15 ] , y − y ˉ = [ − 4.5 , − 1.5 , 1.5 , 4.5 ] .
Why this step? These are the "distances from balance point" — the raw material of the agreement picture.
Step 3 — the three sums.
S x y = ( − 15 ) ( − 4.5 ) + ( − 5 ) ( − 1.5 ) + ( 5 ) ( 1.5 ) + ( 15 ) ( 4.5 ) = 67.5 + 7.5 + 7.5 + 67.5 = 150
S xx = 225 + 25 + 25 + 225 = 500 , S y y = 20.25 + 2.25 + 2.25 + 20.25 = 45
Why this step? S x y is total agreement; S xx , S y y measure each feature's own spread so we can strip out units.
Step 4 — combine. r = 500 45 150 = 22500 150 = 150 150 = 1.0 .
Why this step? Dividing the agreement sum by the two spreads strips out units and forces the answer into [ − 1 , 1 ] ; only then is the number comparable across feature pairs.
Verify: Every deviation pair has the same sign (both negative, then both positive), so every product is positive → maximum possible agreement → r = 1 . Matches the forecast. Because Y = 0.3 X is a straight line with positive slope, r must be exactly + 1 , and scaling by 0.3 cancels in the normalization.
X = [ 1 , 2 , 3 , 4 , 5 ] , Y = [ 10 , 8 , 6 , 4 , 2 ] . Find r X Y .
Forecast: As X climbs, Y falls in lockstep. Sign of r ? Magnitude?
Step 1 — averages. x ˉ = 3 , y ˉ = 6 .
Step 2 — deviations. x − x ˉ = [ − 2 , − 1 , 0 , 1 , 2 ] , y − y ˉ = [ 4 , 2 , 0 , − 2 , − 4 ] .
Why this step? Notice they are mirror images — where X is below average, Y is above.
Step 3 — sums.
S x y = ( − 2 ) ( 4 ) + ( − 1 ) ( 2 ) + 0 + ( 1 ) ( − 2 ) + ( 2 ) ( − 4 ) = − 8 − 2 + 0 − 2 − 8 = − 20
S xx = 4 + 1 + 0 + 1 + 4 = 10 , S y y = 16 + 4 + 0 + 4 + 16 = 40
Why this step? Now every agreement product is negative (opposite signs), so S x y is negative — the see-saw signature.
Step 4 — combine. r = 10 40 − 20 = 400 − 20 = 20 − 20 = − 1.0 .
Why this step? The same normalization as before; here it delivers exactly − 1 because the negative agreement is as strong as it can possibly get.
Verify: Y = 12 − 2 X (check: X = 1 → 10 , ✓). A negative-slope straight line forces r = − 1 . The only difference from Ex 1 is the sign of the numerator — the picture is the same triangle, reflected.
The figure below shows the two extremes side by side: on the left the perfect up-slope (r = + 1 ), on the right the perfect down-slope (r = − 1 ). Every dot lies exactly on the lavender line, which is what "perfect" means — no wobble at all.
X = [ − 2 , − 1 , 0 , 1 , 2 ] , Y = [ 4 , 1 , 0 , 1 , 4 ] (that is Y = X 2 ). Find r X Y .
Forecast: Y clearly depends on X — but does linear correlation see it? Guess r .
Step 1 — averages. x ˉ = 0 , y ˉ = 5 4 + 1 + 0 + 1 + 4 = 2 .
Step 2 — deviations. x − x ˉ = [ − 2 , − 1 , 0 , 1 , 2 ] , y − y ˉ = [ 2 , − 1 , − 2 , − 1 , 2 ] .
Step 3 — numerator.
S x y = ( − 2 ) ( 2 ) + ( − 1 ) ( − 1 ) + ( 0 ) ( − 2 ) + ( 1 ) ( − 1 ) + ( 2 ) ( 2 ) = − 4 + 1 + 0 − 1 + 4 = 0
Why this step? The left half contributes − 4 + 1 = − 3 ; the right half contributes − 1 + 4 = + 3 . They cancel by symmetry .
Step 4 — combine. r = 10 ⋅ S y y 0 = 0 .
Why this step? Once the numerator is 0 , the normalization cannot change it — any nonzero spread divided into zero stays zero, so r = 0 regardless of S y y .
Verify (the trap): r = 0 does not mean "unrelated" — here Y is perfectly determined by X ! Pearson r only detects straight-line links. This is the single most tested misconception. See Linear Regression Assumptions for why we still care about linearity.
r = 0 ≠ independent
A zero correlation rules out a linear relationship only. A U-shape, a circle, or Y = ∣ X ∣ can all give r = 0 while being tightly related. Always eyeball a scatter plot.
X = [ 1 , 2 , 3 , 4 , 5 ] , Y = [ 2 , 1 , 4 , 3 , 5 ] . Find r X Y .
Forecast: Y roughly rises with X but wobbles. Guess r between 0 and 1 .
Step 1 — averages. x ˉ = 3 , y ˉ = 5 2 + 1 + 4 + 3 + 5 = 3 .
Step 2 — deviations. x − x ˉ = [ − 2 , − 1 , 0 , 1 , 2 ] , y − y ˉ = [ − 1 , − 2 , 1 , 0 , 2 ] .
Step 3 — sums.
S x y = ( − 2 ) ( − 1 ) + ( − 1 ) ( − 2 ) + ( 0 ) ( 1 ) + ( 1 ) ( 0 ) + ( 2 ) ( 2 ) = 2 + 2 + 0 + 0 + 4 = 8
S xx = 10 , S y y = 1 + 4 + 1 + 0 + 4 = 10
Step 4 — combine. r = 10 10 8 = 10 8 = 0.8 .
Why this step? Normalizing turns the raw agreement 8 into a comparable score; because the two spreads are equal (S xx = S y y = 10 ) the denominator is simply 10 , landing r at 0.8 — strong but not perfect.
Verify: 0 < 0.8 < 1 ✓ — a strong-but-imperfect positive link. The "4 at X = 3 then 3 at X = 4 " wobble is exactly what stops it reaching 1 . Sanity: ∣ r ∣ ≤ 1 always holds (Cauchy–Schwarz). This is the everyday case in real datasets.
X = [ 7 , 7 , 7 , 7 ] (a constant column), Y = [ 1 , 2 , 3 , 4 ] . Find r X Y .
Forecast: X never changes. Can "how they move together" even be defined? Guess.
Step 1 — averages. x ˉ = 7 , y ˉ = 2.5 .
Step 2 — deviations. x − x ˉ = [ 0 , 0 , 0 , 0 ] . Every deviation is zero .
Why this step? If X never leaves its average, it has no "distance from balance point" to contribute — the raw material of correlation is missing.
Step 3 — sums. S xx = 0 + 0 + 0 + 0 = 0 , and S x y = 0 too.
Step 4 — combine. r = 0 ⋅ S y y 0 = 0 0 — undefined .
Why this step? σ X = 0 , so we are dividing by zero. Correlation asks "when X is above its average, what does Y do?" — but X is never above its average. The question is meaningless.
Verify: A constant feature carries no information and must be dropped before any correlation or regression. In code, libraries return NaN here. This is the degenerate/zero-variance case — always screen for it first. Related: Feature Selection removes such columns.
Common mistake Zero-variance columns crash the math
Any feature that is constant makes σ = 0 , so r and VIF both blow up (division by zero). Detect and delete these before building the correlation matrix.
Before the numbers, we owe two definitions this example depends on.
R j 2 and the VIF formula
R 2 (read "R-squared") is the fraction of a feature's variation that other features can reproduce , a number between 0 and 1 . Run a regression that tries to predict feature X j from all the other features; R j 2 is how much of X j 's wiggle that prediction captures. R j 2 = 0 means the others tell you nothing about X j ; R j 2 = 1 means X j is a perfect linear combination of them (fully redundant).
The Variance Inflation Factor is then defined as
VIF j = 1 − R j 2 1 .
Why this shape? 1 − R j 2 is the slice of X j that is still its own — the genuinely new information. When that slice shrinks toward 0 , dividing by it makes VIF blow up: little new information ⇒ huge uncertainty about that feature's coefficient.
Feature X 3 is regressed on the other features, giving R 3 2 = 0.98 . Then a data update pushes it to R 3 2 = 0.999 . Track VIF 3 .
Forecast: As R 3 2 → 1 , does VIF stay finite? Guess the two values.
Step 1 — VIF at R 3 2 = 0.98 .
VIF 3 = 1 − 0.98 1 = 0.02 1 = 50
Why this step? 1 − R 3 2 is the "fraction of X 3 that is still its own." When only 2% is unique, the variance is inflated 50 × .
Step 2 — VIF at R 3 2 = 0.999 .
VIF 3 = 1 − 0.999 1 = 0.001 1 = 1000
Why this step? We shrank the unique slice from 2% to 0.1% — a 20 × smaller denominator — so VIF jumps 20 × , from 50 to 1000 .
Step 3 — the limit. As R 3 2 → 1 − , 1 − R 3 2 → 0 + , so VIF 3 → + ∞ .
Why this step? Perfect collinearity means X 3 is a linear combo of the others — the design matrix becomes singular and the coefficient's variance literally explodes.
Verify: Standard-error inflation is VIF : at R 3 2 = 0.98 that is 50 ≈ 7.07 × ; at 0.999 it is 1000 ≈ 31.6 × . Both exceed the VIF > 10 "severe" threshold. Fixes: drop the feature, or shrink with Ridge Regression / Lasso Regression . See Variance-Bias Tradeoff .
The figure plots the VIF curve. Notice how flat it is on the left (VIF barely above 1 for R j 2 up to about 0.7 ) and how it rockets upward near the right wall R j 2 = 1 — the coral line marks the VIF = 10 "severe" cutoff, and both green dots sit far above it.
A café tracks 6 days: temperature (°C) T = [ 10 , 15 , 20 , 25 , 30 , 35 ] and iced-coffee sales (cups) S = [ 20 , 35 , 50 , 65 , 80 , 95 ] . The owner asks: "Is heat driving sales, and how strongly?"
Forecast: Every + 5 °C adds exactly + 15 cups. Guess r .
Step 1 — averages. T ˉ = 6 10 + 15 + 20 + 25 + 30 + 35 = 22.5 , S ˉ = 6 20 + 35 + 50 + 65 + 80 + 95 = 57.5 .
Step 2 — deviations. T − T ˉ = [ − 12.5 , − 7.5 , − 2.5 , 2.5 , 7.5 , 12.5 ] , S − S ˉ = [ − 37.5 , − 22.5 , − 7.5 , 7.5 , 22.5 , 37.5 ] .
Why this step? Notice S -deviations = 3 × T -deviations exactly — the tell-tale of a perfect line.
Step 3 — sums.
S T S = ( − 12.5 ) ( − 37.5 ) + ( − 7.5 ) ( − 22.5 ) + ( − 2.5 ) ( − 7.5 ) + ( 2.5 ) ( 7.5 ) + ( 7.5 ) ( 22.5 ) + ( 12.5 ) ( 37.5 )
= 468.75 + 168.75 + 18.75 + 18.75 + 168.75 + 468.75 = 1312.5
S T T = 156.25 + 56.25 + 6.25 + 6.25 + 56.25 + 156.25 = 437.5 , S S S = 3 2 ⋅ S T T = 9 ⋅ 437.5 = 3937.5
Step 4 — combine. r = 437.5 3937.5 1312.5 = 1722656.25 1312.5 = 1312.5 1312.5 = 1.0 .
Why this step? Because every S -deviation is exactly 3 × the matching T -deviation, the denominator collapses to the same 1312.5 as the numerator, forcing r = 1 — the signature of a perfect straight line whatever the slope.
Verify: S = 3 T − 10 (check T = 10 → 20 ✓). Perfect line ⇒ r = 1 . Business caution: correlation is not causation — a heatwave could also lengthen café opening hours. But statistically heat and sales move in perfect lockstep here.
This example uses two new words. Let us earn them first.
Definition Singular values and the condition number
κ
Think of the data matrix X as stretching space along a few perpendicular directions. The singular values σ m a x and σ m i n are the biggest and smallest stretch factors it applies — how long the longest and shortest axes of the stretched cloud are. If some direction gets squashed to nothing, its stretch factor is σ m i n = 0 .
The condition number (Greek letter κ , "kappa") is their ratio:
κ = σ m i n σ m a x .
Why this ratio? It measures how lopsided the stretch is. κ ≈ 1 means a nicely round, well-behaved data cloud; a huge κ means one direction is almost flat — tiny input errors get amplified enormously when we invert. If σ m i n = 0 the cloud is truly flat in some direction and κ = ∞ : the matrix is singular (non-invertible).
Three features: X 1 = [ 1 , 2 , 3 , 4 ] , X 2 = [ 2 , 4 , 6 , 8 ] , and X 3 = X 1 + X 2 = [ 3 , 6 , 9 , 12 ] . Individually r 12 = 1 . A student says "just drop X 2 and we're fine." Trap: is the remaining { X 1 , X 3 } set clean? What does the condition number say?
Forecast: Guess whether X 3 adds new information after dropping X 2 .
Step 1 — check r 13 . x ˉ 1 = 2.5 , x ˉ 3 = 7.5 ; deviations [ − 1.5 , − 0.5 , 0.5 , 1.5 ] and [ − 4.5 , − 1.5 , 1.5 , 4.5 ] .
S 13 = ( − 1.5 ) ( − 4.5 ) + ( − 0.5 ) ( − 1.5 ) + ( 0.5 ) ( 1.5 ) + ( 1.5 ) ( 4.5 ) = 6.75 + 0.75 + 0.75 + 6.75 = 15
S 11 = 2.25 + 0.25 + 0.25 + 2.25 = 5 , S 33 = 20.25 + 2.25 + 2.25 + 20.25 = 45
r 13 = 5 45 15 = 225 15 = 15 15 = 1.0
Why this step? Because X 3 = 3 X 1 (once X 2 = 2 X 1 is substituted), X 3 is still a scaled copy — dropping X 2 did not remove the collinearity.
Step 2 — condition number of { X 1 , X 3 } . Since X 3 = 3 X 1 , the two columns are linearly dependent, so the smaller singular value σ m i n = 0 , giving
κ = σ m i n σ m a x = 0 σ m a x = ∞.
Why this step? A zero smallest singular value = a flat, squashed column space — X T X is singular and cannot be inverted. See Condition Number and Covariance Matrix .
Step 3 — the real fix. Keep exactly one of { X 1 , X 2 , X 3 } . They span a single direction; two of them are redundant.
Verify: r 13 = 1 ✓ confirms the student's fix failed. κ = ∞ ✓ confirms singularity. Sanity in coefficient space: if X 1 , X 3 both enter, infinitely many ( β 1 , β 3 ) pairs give the same prediction (since β 1 X 1 + β 3 ⋅ 3 X 1 = ( β 1 + 3 β 3 ) X 1 ) — the classic un-identifiability of perfect multicollinearity. Principal Component Analysis (PCA) would collapse these into one component automatically.
The figure draws X 1 and X 3 as arrows: they point in exactly the same direction (just different lengths), so the data cloud is a flat line — the visual meaning of κ = ∞ .
Recall Which cell of the matrix does each result live in?
r = + 1 from a scaled copy (Y = 0.3 X ) ::: Cell A (perfect positive)
r = − 1 from a reflected feature (Y = 12 − 2 X ) ::: Cell B (perfect negative)
r = 0 but Y = X 2 (nonlinear) ::: Cell C (linear-only blindness)
r = 0.8 , a strong-but-imperfect real link ::: Cell D (partial / mixed)
A constant column giving undefined r ::: Cell E (degenerate, σ = 0 )
VIF → ∞ as R j 2 → 1 ::: Cell F (limiting behaviour)
A perfect café temperature-vs-sales line (r = 1 ) ::: Cell G (real-world word problem)
Dropping one collinear feature still leaves r = 1 , κ = ∞ ::: Cell H (hidden collinearity)
Mnemonic The correlation pipeline
S pread first (S xx , S y y ), A greement second (S x y ), N ormalize last (r = S x y / S xx S y y ) — "SAN itize your features."
Recall What does
VIF mean physically?
The factor by which a coefficient's standard error is inflated ::: e.g. VIF = 6.67 ⇒ 6.67 ≈ 2.58 × less certain about that effect.
Recall Why does dropping one of three perfectly collinear features not always fix multicollinearity?
Because the survivor may still be a scaled copy of the one you kept ::: e.g. X 3 = 3 X 1 , so r = 1 and κ = ∞ persist — you must keep exactly one.