Variance along linear projections (wᵀx) and Principal Component Analysis Demo

Choose a dataset
All datasets are standardised so x and y have mean 0 and variance 1.
θ = 45.0°
w = (0.707, 0.707)
n = 800
C = (1/n) Σ (xᵢ − μ)(xᵢ − μ)ᵀ
Numeric
-
-
-
-
Pretty print
[ - -; - - ]
Var along w (raw)
-
Var along w (wᵀCw)
-
|difference|
-
Var along w⊥ (raw)
-
Overall variance (trace(C))
-
Mean (x, y)
-
Std (x, y)
-
w = (cos θ, sin θ), w⊥ = (−sin θ, cos θ), Var(wᵀX) = wᵀCw, trace(C) = C₁₁ + C₂₂
Instructions
  • Select a dataset with the buttons at the top.
  • Move the slider to change θ and watch the projection and the variance curve update.
  • Toggle “Show orthogonal direction” to display w⊥ on the scatter and its variance curve on the plot.
  • Use “Centre” to illustrate when the identity Var(wᵀX) = wᵀCw holds for the covariance shown.
  • Toggle “Whiten/Decorrelate” to apply whitening (decorrelate and unit-variance) after centring.
  • The scatter plot uses equal axis scaling (square aspect) to avoid geometric distortion.
(c) Fayyaz Minhas
Scatter: equal scaling on x and y, direction w through μ, projected points on the line, dotted connectors
Variance vs θ (y-axis shows range), with current θ marked