Drag points, rotate vectors and draw random samples to see what the formulas are doing. Pick a topic from the list. Topics follow the course, from Chapter 1 summaries and distances to Chapter 5 tests on a mean vector.
From a data matrix to \(\bar{\mathbf x}\), \(\mathbf S\) and \(\mathbf R\)
Rows are observational units and columns are variables, so \(x_{jk}\) is variable \(k\) for unit \(j\). Each row is one point in the scatter plot. Drag a point, click empty space to add one, or double-click a point to remove it. You can also type into the table.
Three rulers: Euclidean, standardised and Mahalanobis
How far is the point \(P\) from the centre of the cloud? Each distance draws the set of points at the same distance as \(P\). Drag \(P\), reshape the cloud, or change the units of \(x_1\).
Special cases: \(\mathbf S=\mathbf I\) gives \(d_M=d_E\), and a diagonal \(\mathbf S\) gives \(d_M=d_S\). Uses Ch 2's \(\mathbf S^{-1/2}\): \(d_M\) is the ordinary length after whitening.
Euclidean: circlestandardised: axis-aligned ellipseMahalanobis: tilted ellipseThe same picture after multiplying by \(\mathbf S^{-1/2}\). The cloud becomes round and the Mahalanobis ellipse becomes a circle, so \(d_M\) is just the length of the whitened \(P\).
Shape of the cloud and units
\(k\) rescales \(x_1\), e.g. metres → centimetres.
\(\sqrt{s_{11}}\)
\(\sqrt{s_{22}}\)
\(r_{12}\)
\(k\) (units)
Euclidean standardised Mahalanobis
Distance from the centre to \(P\)
Ruler
At \(k=1\)
Now
Euclidean \(d_E\)
Standardised \(d_S\)
Mahalanobis \(d_M\)
Vectors measure, matrices move
On the left, drag the tips of x and y to see length, inner product, angle and projection. On the right, a matrix \(\mathbf A\) acts on the whole plane. Its determinant is how much it scales area, and its eigenvectors are the directions it doesn't turn.
These are the tools the Chapter 3 geometry is built on: the mean as a projection, correlation as \(\cos\theta\), and \(|\mathbf S|\) as a squared volume.
\(\mathbf x\) (drag the tip)\(\mathbf y\) (drag the tip)\(\operatorname{proj}_{\mathbf x}\mathbf y\)
\(\mathbf I\to\mathbf A\)
\(\mathbf A\mathbf e_1\) (column 1)\(\mathbf A\mathbf e_2\) (column 2)image of the unit square, area \(|\det\mathbf A|\)eigenvector lines
The two vectors
snap to a 0.5 grid (easy to check by hand)
Quantity
Value
\(\mathbf x,\ \mathbf y\)
lengths \(L_{\mathbf x},\ L_{\mathbf y}\)
inner product \(\mathbf x'\mathbf y\)
\(\cos\theta\) and \(\theta\)
\(\operatorname{proj}_{\mathbf x}\mathbf y\)
dependent?
Make \(\mathbf x'\mathbf y=0\) for a right angle. Line the vectors up to make them linearly dependent: \(\mathbf y=c\,\mathbf x\), and \(|\cos\theta|=1\).
The matrix \(\mathbf A\)
Read off from the picture
Quadratic forms and positive definiteness
A symmetric \(\mathbf A\) turns every vector into one number, \(Q(\mathbf x)=\mathbf x'\mathbf A\mathbf x\). The shading shows its sign over the plane and the lines are level sets. If \(\mathbf A\) is positive definite, every level set is an ellipse. Drag the point to evaluate \(Q\).
Spectral decomposition \(\mathbf A=\lambda_1\mathbf e_1\mathbf e_1'+\lambda_2\mathbf e_2\mathbf e_2'\) rewrites \(Q\) as a weighted sum of squares. The signs of the weights decide everything. Maximisation lemma: on the unit circle, \(\lambda_2\le Q\le\lambda_1\).
\(Q>0\)\(Q<0\)\(Q=1\)eigenvector axes
Choose a symmetric \(\mathbf A\)
\(a_{11}\)
\(a_{12}\)
\(a_{22}\)
\(Q(\mathbf x)\) for unit vectors \(\mathbf x=(\cos\phi,\sin\phi)\). The curve always lies between \(\lambda_2\) and \(\lambda_1\). If it dips below zero, \(\mathbf A\) is not positive definite.
Transforming a random vector: \(\mathbf Y=\mathbf A\mathbf X+\mathbf b\)
AI Exploration 1, done live. 400 draws of \(\mathbf X\) are pushed through \(\mathbf A\) and shifted by \(\mathbf b\). The formulas predict the new mean and covariance without any data, and the simulation checks them.
\[ E(\mathbf c'\mathbf X)=\mathbf c'\boldsymbol\mu \qquad \operatorname{Var}(\mathbf c'\mathbf X)=\mathbf c'\boldsymbol\Sigma\mathbf c \qquad E(\mathbf A\mathbf X+\mathbf b)=\mathbf A\boldsymbol\mu+\mathbf b \qquad \operatorname{Cov}(\mathbf A\mathbf X+\mathbf b)=\mathbf A\boldsymbol\Sigma\mathbf A' \]
\(\mathbf b\) moves the mean and does nothing to the covariance. If \(\mathbf A\) is rank-deficient, \(\mathbf A\boldsymbol\Sigma\mathbf A'\) is singular and the cloud collapses onto a line. The same rules drive Chapter 3's \(\mathbf b'\bar{\mathbf x}\) and \(\mathbf b'\mathbf S\mathbf b\).
\(\mathbf X\): ellipse of \(\boldsymbol\Sigma\) around \(\boldsymbol\mu\)\(\mathbf Y\): predicted ellipse of \(\mathbf A\boldsymbol\Sigma\mathbf A'\) around \(\mathbf A\boldsymbol\mu+\mathbf b\)× sample mean of the 400 \(\mathbf y\)'s
An \(n\times p\) matrix \(\mathbf X\) is either n points in \(\mathbb R^p\) (rows) or p vectors in \(\mathbb R^n\) (columns). With \(n=3,\ p=2\) the column picture fits in 3-D. Drag the points on the left.
Uses Ch 2: the Cauchy–Schwarz inequality \((\mathbf a'\mathbf b)^2\le(\mathbf a'\mathbf a)(\mathbf b'\mathbf b)\), with equality only when one vector is a multiple of the other (\(r=\pm1\)).
The flat plane spanned by \(\mathbf d_1,\mathbf d_2\) inside \(\mathbb R^5\). The purple segment is the projection of \(\mathbf d_2\) onto \(\mathbf d_1\), with length \(\|\mathbf d_2\|\cos\theta\).The same ten numbers as five points \((d_{1j},d_{2j})\). The dashed line is the least-squares line.
Controls
\(\theta\)
\(\|\mathbf d_2\|/\|\mathbf d_1\|\)
\(\bar{\mathbf x}\) and \(\mathbf S\) are random too
Before the data are collected, each row \(\mathbf X_j\) is a random vector, so \(\bar{\mathbf X}\) and \(\mathbf S\) are random as well. Draw many samples of size \(n\) from \(N_2(\boldsymbol\mu,\boldsymbol\Sigma)\) and check the theorem.
population contour (\(\boldsymbol\Sigma\))latest sampleevery \(\bar{\mathbf x}\) so farcontour of \(\boldsymbol\Sigma/n\)average \(s_{11}\) with divisor \(n-1\) → \(\sigma_{11}\)with divisor \(n\) → \(\tfrac{n-1}{n}\sigma_{11}\)
Population and sample size
\(n\)
\(\sigma_1\)
\(\sigma_2\)
\(\rho_{12}\)
Changing a slider starts a fresh experiment. With n = 2 the divisor-n estimate is off by a factor of ½.
Simulation vs theory · 0 samples
Quantity
Average over samples
Theory
\(\bar{\mathbf x}\)
\(\boldsymbol\mu\) =
\(\mathbf S\)
\(\boldsymbol\Sigma\) =
\(\mathbf S_n\)
\(\tfrac{n-1}{n}\boldsymbol\Sigma\) =
spread of \(\bar{\mathbf x}\)
\(\boldsymbol\Sigma/n\) =
One number for spread: \(|\mathbf S|\) and \(\operatorname{tr}(\mathbf S)\)
Both numbers compress the whole covariance matrix into one value. The ellipse is \((\mathbf x-\bar{\mathbf x})'\mathbf S^{-1}(\mathbf x-\bar{\mathbf x})=c^2\) with \(c=2\). The axes are fixed, so you can compare areas between settings.
Uses Ch 2: determinant \(|\mathbf A|=ad-bc\), and eigenvalues from \(|\mathbf A-\lambda\mathbf I|=0\). The determinant is the product of the eigenvalues and the trace is their sum.
ellipse of \(\mathbf S\), axes of half-length \(c\sqrt{\lambda_1},\ c\sqrt{\lambda_2}\)30 observations with exactly this \(\mathbf S\)
Shape the covariance matrix
\(\sqrt{s_{11}}\)
\(\sqrt{s_{22}}\)
\(r_{12}\)
Textbook Example 3.8 (all have \(|\mathbf S|=9\))
overlay all three Ex. 3.8 ellipses show data
Quantity
Formula
Live value
\(|\mathbf S|\)
\(s_{11}s_{22}-s_{12}^2\)
\(s_{11}s_{22}(1-r_{12}^2)\)
\(\lambda_1\lambda_2\)
\(\operatorname{tr}(\mathbf S)\)
\(s_{11}+s_{22}\)
\(\lambda_1+\lambda_2\)
area
\(\pi c^2\sqrt{|\mathbf S|}\)
Inside \(\mathbf S\): rotate, stretch, rotate back
This tab brings in Chapter 2. The spectral decomposition shows what \(\mathbf S\) does geometrically. Its square root turns a circle into the ellipse from the Generalized variance tab, and its inverse square root turns the data back into a circle.
From Ch 2 (spectral decomposition, square-root matrices, \(\boldsymbol\rho=\mathbf V^{-1/2}\boldsymbol\Sigma\mathbf V^{-1/2}\)) and 3.3 (\(\mathbf R\) from \(\mathbf S\)). The covariance of \(\mathbf A\mathbf x\) is \(\mathbf A\mathbf S\mathbf A'\) (3.4), and that drives everything below.
Step
Choose \(\mathbf S\)
\(\sqrt{s_{11}}\)
\(\sqrt{s_{22}}\)
\(r_{12}\)
The pieces, live
Linear combinations inherit \(\bar{\mathbf x}\) and \(\mathbf S\)
\(y_j=\mathbf b'\mathbf x_j\) turns each observation into one number. For a unit \(\mathbf b\), that number is where the point's shadow lands on the line in direction \(\mathbf b\). Drag the b and c handles.
\[ \bar y=\mathbf b'\bar{\mathbf x} \qquad s_y^2=\mathbf b'\mathbf S\mathbf b \qquad s_{yz}=\mathbf b'\mathbf S\mathbf c \qquad \text{many at once: } \bar{\mathbf y}=\mathbf A\bar{\mathbf x},\ \mathbf S_y=\mathbf A\mathbf S\mathbf A' \qquad \lambda_2\le\frac{\mathbf b'\mathbf S\mathbf b}{\mathbf b'\mathbf b}\le\lambda_1 \]
Sample version of Ch 2's \(E(\mathbf c'\mathbf X)=\mathbf c'\boldsymbol\mu,\ \operatorname{Var}(\mathbf c'\mathbf X)=\mathbf c'\boldsymbol\Sigma\mathbf c\). The bound on the right is the Rayleigh quotient from Ch 2.
projections onto \(\mathbf b\)projections onto \(\mathbf c\)spread curve: \(2\sqrt{\mathbf b'\mathbf S\mathbf b}\) in every direction
As \(\mathbf b\) turns through 180°, \(\mathbf b'\mathbf S\mathbf b\) swings between \(\lambda_2\) and \(\lambda_1\) and never goes outside them. The peak is at \(\mathbf e_1\), the first principal component direction.
The bivariate normal: contours, probability ellipses and conditioning
The density is constant on the ellipses \((\mathbf x-\boldsymbol\mu)'\boldsymbol\Sigma^{-1}(\mathbf x-\boldsymbol\mu)=c^2\), the Mahalanobis circles from Chapter 1. Pick \(c^2\) from \(\chi^2_2\) and the ellipse holds a known probability. Drag the vertical slice to condition on \(X_1\).
Axes of the ellipse: eigenvectors \(\mathbf e_i\) of \(\boldsymbol\Sigma\), half-lengths \(c\sqrt{\lambda_i}\) (Ch 2). For \(p=2\), \(\chi^2_2(\alpha)=-2\ln\alpha\) exactly. Conditional result: Theorem 4.6 with \(\boldsymbol\Sigma_{12}\boldsymbol\Sigma_{22}^{-1}\) reduced to scalars.
probability ellipse \(c^2=\chi^2_2(\alpha)\)slice \(X_1=x_1\)regression line \(E(X_2\mid X_1)\)marginal \(X_2\sim N(\mu_2,\sigma_{22})\)conditional \(X_2\mid X_1=x_1\): the slice, rescaled to area 1
Is it normal? Q-Q plots, \(r_Q\) and the chi-square plot
Pick a data set and run the lecture's checks on it. Drag any point in the scatter plot to make your own outlier, and watch where it lands in each plot.
Reject normality at level \(\alpha\) if \(r_Q\) is below the critical point for \(n\) (Johnson & Wichern Table 4.2). For \(p=2\), \(\chi^2_2\) quantiles are \(-2\ln(1-\text{prob})\). About half the \(d_j^2\) should be below \(\chi^2_2(0.5)=1.39\).
Chi-square plot: ordered \(d_j^2\) against \(\chi^2_2\) quantiles. The line is \(y=x\).
Verdicts
Critical points at \(\alpha=0.05\), interpolated in \(n\).
Box-Cox: choosing a power to make data look normal
Powers below 1 pull in a long right tail, and powers above 1 stretch it out. Slide \(\lambda\) and watch the histogram and Q-Q plot. The likelihood curve underneath picks the best \(\lambda\) for you.
\(\hat\lambda\) maximises \(\ell(\lambda)\). The last term is the Jacobian of the transformation. Without it, small \(\lambda\) would always win by shrinking the variance. The best \(\lambda\) often improves normality but doesn't guarantee it, so always re-check.
Histogram of \(x^{(\lambda)}\) with the normal curve that has the same mean and SD.Q-Q plot of \(x^{(\lambda)}\) with \(r_Q\) and the 5% critical point.
\(\ell(\lambda)\) for \(-1\le\lambda\le2\). Click or drag on the chart to set \(\lambda\).
Choose \(\lambda\)
\(\lambda\)
Live numbers
Hotelling's \(T^2\): testing a mean vector
Drag \(\boldsymbol\mu_0\) (the cross). The joint test rejects \(H_0:\boldsymbol\mu=\boldsymbol\mu_0\) exactly when the cross leaves the purple ellipse. The dashed box is where two separate \(t\)-tests both accept, so the corners of the box are where one-at-a-time tests and the joint test disagree.
Reject at level \(\alpha\) when \(T^2>\frac{(n-1)p}{n-p}F_{p,n-p}(\alpha)\). \(T^2\) is the statistical distance from Ch 1 between \(\bar{\mathbf x}\) and \(\boldsymbol\mu_0\), measured with \(\widehat{\mathrm{Cov}}(\bar{\mathbf X})=\frac1n\mathbf S\) from Ch 3.
\(\boldsymbol\mu_0\) values \(T^2\) accepts\(\boldsymbol\mu_0\) values both \(t\)-tests acceptobservationsdensity of \(\frac{(n-1)p}{n-p}F_{p,n-p}\)rejection region, area \(\alpha\)observed \(T^2\)simulated \(T^2\) under \(H_0\)
Controls
Live numbers
The likelihood ratio test and Wilks' lambda
Fit the data twice: with \(\boldsymbol\mu\) free (spread \(\hat{\boldsymbol\Sigma}\) about \(\bar{\mathbf x}\)) and with \(\boldsymbol\mu\) forced to \(\boldsymbol\mu_0\) (spread \(\hat{\boldsymbol\Sigma}_0\) about \(\boldsymbol\mu_0\)). The wrong centre inflates the spread along \(\bar{\mathbf x}-\boldsymbol\mu_0\). Drag \(\boldsymbol\mu_0\) and compare the two ellipses.
\[ \Lambda^{2/n}=\Big(1+\frac{T^2}{n-1}\Big)^{-1} \qquad -2\ln\Lambda\ \dot\sim\ \chi^2_{\nu-\nu_0}\ \text{ for large } n \]
Theorem 5.1: small \(\Lambda\) means large \(T^2\), so the LRT and Hotelling's test are the same test. Theorem 5.2: for large \(n\), \(-2\ln\Lambda\) is roughly \(\chi^2\) with \(\nu-\nu_0=p\) degrees of freedom, since \(H_0\) fixes the \(p\) means. \(\hat{\boldsymbol\Sigma}\) and \(\hat{\boldsymbol\Sigma}_0\) are the MLEs (divisor \(n\)) from Ch 4.
\(\hat{\boldsymbol\Sigma}\) about \(\bar{\mathbf x}\)\(\hat{\boldsymbol\Sigma}_0\) about \(\boldsymbol\mu_0\)deviations \(\mathbf x_j-\boldsymbol\mu_0\)\(\Lambda^{2/n}\) falls as \(T^2\) grows, so "\(\Lambda\) small" and "\(T^2\) large" mark out the same samples.
exact density of \(-2\ln\Lambda\) under \(H_0\)\(\chi^2_p\) approximation (Theorem 5.2)\(\chi^2_p(\alpha)\) cut-off and the exact tail area beyond it