Understand the idea
LDA answers 'which group does this observation most likely belong to?' by treating each known class as its own cluster of points in predictor space (penguin species as clusters of bill and flipper measurements, say), with each cluster centered on its own mean but all clusters assumed to have the SAME shape and spread. To classify a new point, LDA measures how close it sits to each class's center (accounting for that shared spread) and picks whichever class it is closest to, with a bonus for classes that are simply more common to begin with.
Beyond just classifying, LDA also finds the best 'discriminant' directions: specific combinations of your predictors, weighted just right, that separate the known classes as much as possible. Plotting observations on the first one or two of these directions (LD1, LD2) often gives the clearest 2-D picture available of how well-separated your classes really are, better than plotting any two raw predictors against each other.
It is easy to confuse LDA with PCA because both produce 'components' from your predictors, but they answer completely different questions. PCA finds directions of maximum TOTAL variance with no idea which rows belong to which group. LDA specifically finds directions that best separate GROUPS YOU ALREADY KNOW ABOUT: it needs the class labels; PCA does not.
Linear discriminant analysis is also called Fisher's discriminant analysis. Each row gets discriminant scores: its positions along the directions that best separate the groups. Wilks' lambda measures how much of the spread the groups leave unexplained, so values near 0 mean the groups separate well.
Practitioner explanation
KernelStats fits Fisher's LDA with a single shared covariance matrix Sigma across classes, discriminant function delta_k(x) = x'*Sigma^-1*mu_k - 0.5*mu_k'*Sigma^-1*mu_k + log(pi_k), with priors either PROPORTIONAL to observed class frequencies (default: appropriate when the sample reflects the population) or EQUAL across classes (appropriate for an imbalanced sample where future cases will not be, or when missing a rare class is costly). Headline accuracy is always seeded k-fold cross-validated, with in-sample accuracy shown only as the optimistic comparison; the confusion matrix and per-class precision/recall are surfaced as more informative than one pooled accuracy number, since they reveal WHICH classes get confused with each other.
Two assumption checks are ACTUALLY COMPUTED, each with an honestly stated limitation: (1) multivariate normality within each class is screened via Shapiro-Wilk on every class x predictor cell, Bonferroni-corrected, reporting the worst cell, explicitly stated to test only the MARGINALS (a rejection is evidence against multivariate normality, but a pass clears only the marginals, not the true joint distribution); (2) equal covariance matrices across classes is checked with Box's M test, judged at the stricter alpha = .001 specifically because Box's M is known to be hypersensitive (rejecting on trivial departures at ordinary sample sizes), a documented, deliberate departure from the conventional .05 threshold, with QDA named as the direct remedy when it fails badly.
Wilks' lambda (the ratio of within-class to total scatter, 0=perfectly separated means, 1=no separation) is reported via Rao's approximate F, the same statistic a one-way MANOVA of the predictors on the class factor would produce, and the product states plainly that this is an APPROXIMATION, not an exact small-sample test, and that it tests only whether class CENTROIDS differ at all, saying nothing about how much the classes actually overlap or how good the resulting classifier is (a significant Wilks' lambda is fully compatible with heavy overlap and a high error rate).
When to use it
Consider it when
Predicting which of two or more known classes an observation belongs to, from numeric predictors that are roughly multivariate normal within each class with a similar spread across classes, or when the linear combinations of predictors that best separate the classes are of interest in their own right.
Use caution when
Classes have clearly different spreads/covariance structures (Box's M fails badly; use QDA instead), predictors are far from normal within classes even after checking, or the classification boundary is expected to be genuinely non-linear (LDA can only produce straight-line/plane boundaries).
Formulas and symbols
Linear discriminant function
mu_k the mean of class k, Sigma the single shared covariance matrix, pi_k the prior probability of class k. The observation is assigned to the class with the largest delta_k.
Wilks' lambda
W the within-class scatter matrix, T the total scatter matrix. 0 = perfectly separated class means; 1 = no separation. Reported via Rao's approximate F, not an exact test.
Confusion matrix (in-sample) and per-class recall/precision
Computed from the fitted model's own IN-SAMPLE predictions (the card labels it so), which makes these per-class figures optimistic; the seeded k-fold cross-validated accuracy is the honest headline.
Assumptions and checks
- Normality (of residuals, not of the raw data). LDA's linear decision boundaries are derived assuming each predictor is approximately normally distributed WITHIN each class; strong non-normality (skew, heavy tails) in one or more predictors makes the boundary and the reported classification accuracy less trustworthy, especially with small classes.
In KernelStats: Shapiro-Wilk per predictor within each class, reported directly on the card, with predictors named and skipped when there are too few or too many rows to test.
- Homogeneity of variance (homoscedasticity). LDA assumes every class shares the SAME covariance matrix (spread and correlation among predictors); when classes have genuinely different covariance structures, LDA's shared linear boundary is the wrong shape and QDA's per-class boundaries fit better.
In KernelStats: Box's M test, reported directly on the card at a stricter alpha = .001 (Box's M is hypersensitive to large samples); reported honestly as 'could not be computed' when a class has too few rows or a singular covariance, rather than a false pass.
- With a severely imbalanced or very small class (fewer rows than roughly 3x the number of predictors), the covariance estimate for that class is noisy, which distorts the shared covariance matrix the boundary depends on and can make the reported accuracy an unreliable summary.
In KernelStats: Checked directly: the card reports the largest/smallest class ratio (flagged above 3:1) and the smallest class's row count relative to the number of predictors (flagged below a 3x rows-per-predictor ratio).
- Independence of observations. Rows must be independent (no repeated measures of the same subject in different rows); violated independence distorts both the fitted boundary and the cross-validated accuracy estimate.
In KernelStats: Not checked by KernelStats: stated directly as a standing 'Independent observations' reminder.
Alternatives
- Quadratic Discriminant Analysis. Box's M test shows classes have meaningfully different covariance structures: QDA allows each class its own covariance matrix, at the cost of more parameters to estimate.
- Logistic Regression. You have exactly two classes and do not want to assume multivariate normality of the predictors: logistic regression makes a weaker distributional assumption.
- Principal Component Analysis. You want directions of maximum total variance among the predictors without reference to any class labels, rather than directions that specifically separate known groups.
Worked example
Scenario
Classifying three penguin species from bill length, bill depth, flipper length, and body mass, with proportional priors and 5-fold cross-validation.
Result
In-sample accuracy = 98.8%, 5-fold cross-validated accuracy = 98.5% (fold SD 1.3 points); Wilks' lambda = 0.019, Rao's F(8, 672) = 528.9, p < .001; the in-sample confusion matrix shows the four errors are all between Adelie and Chinstrap, never involving Gentoo. Box's M rejects equal covariances (chi-square(20) = 76.8, p < .001).
Interpretation
The close in-sample/CV agreement suggests the model generalizes well, and the confusion matrix pinpoints which two species are hardest to tell apart, information a single pooled accuracy number would hide. The Box's M rejection says the shared-covariance assumption is strained; with classes this large, comparing against QDA's cross-validated accuracy is the sensible check.
Dataset: penguins.csv
Common misconceptions
Misconception
LDA and PCA are essentially the same dimension-reduction technique.
Correction
PCA finds directions of maximum TOTAL variance in the predictors with no knowledge of group membership. LDA specifically requires known class labels and finds directions that maximize SEPARATION BETWEEN those known classes relative to within-class spread: a fundamentally different objective that can produce a very different, and often more useful, low-dimensional picture when the goal is classification rather than pure variance compression.
Misconception
A significant Wilks' lambda proves the classifier will perform well.
Correction
Wilks' lambda (via Rao's approximate F) only tests whether the class CENTROIDS differ at all: it says nothing about how much the classes overlap in practice. Class means can differ significantly while the classes still overlap heavily, producing a high real-world error rate despite the significant test.
Read more: Misconception: statistical significance means practical importance
References
- The use of multiple measurements in taxonomic problems, Fisher, R. A. (1936), Annals of Eugenics, 7(2), 179-188.
- An Introduction to Statistical Learning with Applications in R (2nd ed.), Chapter 4, James, G., Witten, D., Hastie, T. and Tibshirani, R. (2021).
