| Income $ per capita | Illiteracy % | Life exp. years | Murder per 100k | HS grad % | Frost days | |
|---|---|---|---|---|---|---|
| 1 Alabama | 3,624 | 2.1 | 69.0 | 15.1 | 41.3 | 20 |
| 2 Alaska | 6,315 | 1.5 | 69.3 | 11.3 | 66.7 | 152 |
| 3 Arizona | 4,530 | 1.8 | 70.5 | 7.8 | 58.1 | 15 |
| 4 Arkansas | 3,378 | 1.9 | 70.7 | 10.1 | 39.9 | 65 |
| 5 California | 5,114 | 1.1 | 71.7 | 10.3 | 62.6 | 20 |
| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
| 43 Texas | 4,188 | 2.2 | 70.9 | 12.2 | 47.4 | 35 |
| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
| 50 Wyoming | 4,566 | 0.6 | 70.3 | 6.9 | 62.9 | 173 |
Vectors are bold: \(\mathbf x_1\) is the first observation; plain \(x_1\) is the first variable. The prime \('\) is the transpose.
A \(50\times 6\) data matrix \(\mathbf X\) (Rโs state.x77, 1970s): the sample.
All 300 numbers at once, standardised \(z_{tj}=(x_{tj}-\bar x_j)/s_j\): how many standard deviations a state is above (purple) or below (orange) the average.
Which state stands out? Single extreme values are easy to spot; unusual combinations are not. We answer at the end.
Euclidean distance: lay a ruler between the two points. By Pythagoras:
\[\lVert \mathbf x_s-\mathbf x_t\rVert=\sqrt{\sum_{j=1}^p (x_{sj}-x_{tj})^2}\]
In vector form, with \(a'b=\sum_j a_jb_j\) (inner product):
\[\lVert \mathbf x_s-\mathbf x_t\rVert=\sqrt{(\mathbf x_s-\mathbf x_t)'(\mathbf x_s-\mathbf x_t)}\]
Same formula for any \(p\). It depends on the units: the variable with the widest range dominates.
Binary: a nominal variable with two categories (coded 0/1, its mean is a share). Count: ratio-scaled, whole numbers only.
Numbers on a scale: means, covariances, axes, sizes. Categories: count, colour or split.
island <- factor(c("Dream", "Biscoe",
"Dream", "Torgersen"))
levels(island) # stored once
## [1] "Biscoe" "Dream" "Torgersen"
as.integer(island) # codes per row
## [1] 2 1 2 3A factor stores the categories once (its levels) and a whole-number code per observation.
NAordered = TRUE for ordinal