Skip to main content
Advanced Statistical Methods

Linear Discriminant Analysis and Hierarchical Cluster Analysis

Published: 2026-08-11
Level: postgraduate
Audience: Postgraduate students in Advanced Statistical Methods

Prerequisite Knowledge

This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.

Previously Covered in This Subject

  • Principal Component Analysis — the geometric idea, the covariance matrix, and the eigenvalue recipe were introduced in Lecture 12 and worked through on a two-dimensional data set in Lecture 13
  • Linear Discriminant Analysis — first introduced in Lecture 12 and developed further in Lecture 13; this lecture applies it to a two-class data set
  • Cluster analysis — the inter-cluster and intra-cluster distance preview from Lecture 13 is developed into full hierarchical cluster analysis here

Linear Discriminant Analysis and Hierarchical Cluster Analysis

14.1 Principal Component Analysis Recap

14.1.1 The Core Idea

Hook — one line before the math. If you are forced to flatten a cloud of points in a plane down onto a single straight line, which line should you pick so that the flattened picture still shows as much as possible of what the original cloud had to say?

Principal component analysis (PCA) is a dimensionality reduction technique. Its main objective is to reduce a higher-dimensional space into a lower-dimensional space, and while doing the reduction you should not lose the maximum amount of information. The whole question reduces to one choice: find the direction onto which, if you project the data, you capture the maximum amount of information — the maximum variation.

Look at a scatter plot and think of the two candidate directions available in it. Along one direction the projected points spread out a lot; along the other direction they barely spread at all. The direction with the bigger spread is the one that carries the information, and that is the direction PCA picks. So the mental model is: PCA searches the space of all directions for the single line that preserves the most variation when the data is squashed onto it.

Intuition + analogy — a photograph of a queue. Picture a queue of people of different heights standing in a row. Photograph them from directly above: everyone looks the same size, and the picture carries almost no height information. Photograph them from the side: the height differences show up at full strength. The people are the data points, the camera angle is the candidate direction, and how well the heights separate in the photo is the variation captured. PCA picks the camera angle that shows the most variation and then takes that photo — it projects the data onto that direction. Where the analogy breaks: a photo can also record extra facts like who stands next to whom, while PCA looks only at spread along a line, and it never uses class labels or any outside information.

A simple way to picture the idea is a two-dimensional scatter plot with two arrows drawn through the cloud of points. Name the horizontal axis and the vertical axis . Arrow 1 runs along the direction where the cloud is long and thin; arrow 2 runs across the direction where the cloud is narrow. Project each point onto arrow 1 by dropping a perpendicular from the point to the arrow: the projected positions are stretched out over a wide interval. Do the same onto arrow 2: the projected positions pile up in a narrow interval. The landmark of the picture is the difference in how far the two sets of projected marks reach. The takeaway: the direction whose projection shows the longer spread holds more variation, and that is the direction PCA keeps.

14.1.2 Eigenvalues and the Share of Variation

To identify which direction has the maximum variation and which has the minimum, you compute the covariance matrix of the data and solve the eigenvalue problem. The eigenvalue equation is written as the covariance matrix minus times the identity matrix , with its determinant set to zero:

Formalize — the eigenvalue equation, symbol by symbol.

  • (sigma) is the covariance matrix of the data: a symmetric matrix for variables, whose entry says how variables and move together (the diagonal entries are the variances of the single variables).
  • (lambda) is a number we are solving for — an eigenvalue (the amount of stretch along a principal direction).
  • is the identity matrix, the diagonal matrix with ones on the diagonal and zeros elsewhere.
  • The vertical bars mean the determinant.

Setting the determinant to zero is the standard trick to find non-zero solutions of the companion equation , which says: find a direction (an eigenvector) that the matrix only stretches, by the factor , and never turns. Setting the determinant to zero forces to be singular, which is exactly the condition for such a direction to exist.

In words: take the covariance matrix of the data, subtract lambda times the identity, and find the values of lambda that make the determinant zero. In a two-dimensional space this gives two possible roots — and — and one is always higher than the other. That comparison between the two roots is always true for eigenvalue problems: in two dimensions you expect exactly two roots, one with a higher value and one with a lower value.

The direction belonging to the highest eigenvalue captures the maximum variation. You can express how much each direction contributes as a percentage of the total variation:

The denominator sums all the eigenvalues, because the total variation of the data is the sum of the variances on the diagonal of , and that sum equals . Each share is so the fraction of the total variation carried by that direction, and the two shares always add to 1 (100 percent).

Worked example — the recap illustration (eigenvalues 21 and 4).

Suppose the two roots come out as and . Then the total is

and the first principal direction contributes

while the second contributes

So PC1 (the first principal component, the projection onto the first eigenvector) carries the maximum variation and PC2 carries the rest. Sense-check: , so the two shares exactly exhaust the total variation — nothing is lost or double-counted. The professor flagged the two root values as assumed for illustration ("let us assume"), so treat 21 and 4 as a worked example rather than fixed constants.

Assumptions & scope — when the eigenvalue recipe works and when it breaks.

  • Symmetry and real roots. The covariance matrix is symmetric, so its eigenvalues are real numbers and never negative; a negative eigenvalue here would signal a mistake in the arithmetic.
  • One eigenvalue per dimension. A covariance matrix gives exactly roots, so a two-dimensional problem gives exactly two roots — the comparison the professor stresses.
  • Comparable scales. The shares are computed on the covariance matrix, so a variable measured in larger units can dominate the first principal direction. Standardizing the variables first changes the result; PCA's answer is only as good as the scales you feed it.
  • Linear directions only. PCA looks for a single straight line; it cannot find curved structures in the data.

A visual reading of the share: draw a bar with the total variation 25, then split the bar into a block of height 21 and a block of height 4. The 21-block is more than five times as tall as the 4-block. That lopsided split is the picture to keep: when one eigenvalue dominates, a single projection direction preserves most of the information, and the reduced data is nearly lossless.

Pitfalls — the traps students fall into.

  1. Confusing eigenvalue with eigenvector. tells you how much variation a direction holds; the eigenvector tells you which way the direction points. The share formula uses the eigenvalues, not the eigenvectors.
  2. Forgetting the denominator. The share is over all eigenvalues — dividing by only one of them gives a meaningless 100 percent.
  3. Ignoring scale. If you mix variables on wildly different units, the biggest-unit variable silently decides the principal direction.
  4. Treating the share as a classification guarantee. The share measures variation only; it says nothing about whether classes can be told apart after projection. That blind spot is exactly the reason the next section exists.

Exam note. The final session of the course is a revision session: how you may expect the question paper, and how much of the comprehensive examination can be covered — the remaining coverage will be notified separately. For PCA and LDA, the covariance matrix will be given to you in the exam; you will not be asked to compute scatter matrices by hand. Expect interpretation questions in the style of the mid-semester exam: reading matrices, explaining what the eigenvalues and the discriminant direction mean, and explaining why PCA is not suited to classification problems.

Beyond the exam, this is the practical reason PCA is used for compression and exploration while LDA-type methods are used when the downstream goal is classification. Compression with PCA means keeping only the top few principal directions: image compression stores the projections onto the few largest-eigenvalue directions instead of every pixel, face recognition systems build "eigenfaces" from the leading eigenvectors of a face-image covariance matrix, and the same eigenvalue logic returns later in discriminant analysis, where the ratio of between-group to within-group variation is summarized by an eigenvalue.

Recap + bridge. PCA keeps the single direction of maximum variation, and the share formula tells you how much of the total variation that direction holds. But maximum variation is not the same as class separation — the next section shows PCA failing exactly there, and introduces linear discriminant analysis (LDA) as the fix.

14.2 Linear Discriminant Analysis

14.2.1 Why PCA Falls Short for Classification

Hook — the failure you should see coming. You reduced your two-dimensional data to one dimension with PCA and kept about 91 percent of the variation. So why can you still not tell the two classes apart on the projected line?

PCA has a blind spot: it is not useful for classification problems. If your main objective is to classify, PCA will not work for you — yes, it reduces the data from a higher dimension to a lower dimension, but at the end you have no clarity about how to separate the two classes. Project all the points of a two-class data set onto the max-variation line and you see both classes mixed along the same line, with no obvious way to tell them apart.

What you actually want for classification is the opposite emphasis: find the direction along which, if you project all the points, you can easily see the separability between the classes. Project onto that line, and a single cutoff value does the job — points above the cutoff are one class, points below are the other. That is exactly what linear discriminant analysis (LDA) is for: it focuses on finding the feature subspace that maximizes the separability between the classes.

Intuition + analogy — photographing two mixed teams. Imagine two sports teams of different heights mixed together in one crowd, and you want one photograph that lets you count the teams apart. PCA's instinct is to photograph from the side — the angle of maximum height variation. But if both teams contain tall and short players, the side view mixes them hopelessly. The useful angle is different: find the viewing direction from which one team appears as a tight block and the other as a separate tight block. The camera angle is the projection direction, the two teams are the two classes, and the separation you see is what LDA optimizes. Where the analogy breaks: a photographer uses shirts, faces, and other cues; LDA works only from the numeric coordinates, and it needs to know the class of every point in the training data before it can choose the direction.

So the target changes from "maximum variation" to "maximum separability". The professor's statement of the goal: you must manage two kinds of variation — the variation within each class and the variation between the classes — and build a mathematical expression that minimizes the within-class variation while maximizing the between-class separation. The line that satisfies both ends gives the best possible separation.

Dimension PCA LDA
Objective Maximize the variation captured after projection Maximize the separability between classes
Class labels Ignored — PCA does not use them Required — the means and scatters are computed per class
Number of directions Up to principal components for variables At most discriminant directions for classes (one for two classes)
Typical use Compression, exploration, denoising Classification, feature extraction for a classifier

The one-line "when to pick which": use PCA when the goal is to summarize variation, and use LDA when the goal is to separate known classes — a single projected line with a cutoff does the classification job.

This is the practical reason PCA is used for compression and exploration while LDA-type methods are used when the downstream goal is classification. In credit scoring, a bank projects applicant features onto a discriminant direction to separate defaulters from payers; in medical diagnostics, the same idea separates sick from healthy patients on a single score. The textbook Research Methodology: Concepts and Cases runs its discriminant analysis chapter on exactly this kind of problem — predicting which restaurant a customer chooses between two rivals.

14.2.2 The Worked Data Set

To make the idea concrete, the lecture uses a small two-class data set. There are two classes, class 1 and class 2, with five data points each. Class 1 is the point set

The five points of class 2 were written on the board and read off from the scatter diagram, but the spoken list is too garbled to reconstruct; only its mean survives intact. That loss does not cripple the analysis: the LDA recipe that follows uses the class means and the within-class scatter matrices, not the raw points, and both are available.

The class means are the working quantities:

Worked example — the two class means.

Class 1 has the five points . The mean of the -values:

and the mean of the -values:

So . The spoken calculation was shown in full in the lecture — "one three four five seven is four" for the -coordinate, and "two plus five plus three plus six plus five by five is four point two" for the -coordinate. Class 2's mean is . Sense-check: both means sit in the middle of their own point clouds — near the center of the class-1 cluster, far to the right, which is exactly where the class-2 points were drawn on the board.

14.2.3 PCA Applied to the Combined Data

Before building LDA, the lecture first shows why PCA fails on this exact data. Ignore the class labels for the moment — that is what PCA does, since it has no use for class information. Pool the whole data set (both classes together) into a single matrix, compute the covariance matrix, and solve the eigenvalue equation, exactly as in the previous session. For this problem the two eigenvalues come out as

Worked example — what PCA captures, and why it is not enough.

The share of the total variation carried by the first direction is

so about 91 percent of the variation lies along the highest-eigenvalue direction — comfortably above the "more than 85 percent" the lecture estimates, and the same story as the 21-and-4 recap in the previous section.

The eigenvector belonging to the highest eigenvalue (26.28) is the direction along which you capture the maximum amount of variation. The class notes record this eigenvector as "71" — read as the direction : seven units across for one unit up. Remember that an eigenvector is only a direction, so it may be multiplied by any constant without changing the line it points along; , and all describe the same direction, which is why the raw recorded number matters less than the ratio of its components.

Now put the class labels back and look at the projection: there are mismatches between the two classes. The projection captured the maximum variation but still cannot classify — you cannot find the best discriminant value or the best discriminant line that separates the two classes. Sense-check: variation and separation are different goals. PCA only promises the projected points spread out as much as possible; it never promised that one class would land on one side and the other class on the other side. This is the potential problem you face when you go only with PCA.

14.2.4 Within-Class Scatter: S1 and S2

To get a separating direction you must manage two kinds of variation: the variation within each class, and the variation between the classes. The mathematical target is to build an expression that minimizes the within-class variation and at the same time maximizes the separation between the classes. The line that satisfies both ends gives the best possible separation.

The within-class scatter matrix of class 1 measures its internal spread. The verbal description: a sum over the class-1 points of times transposed:

Formalize — every symbol, and why the formula looks like that.

  • is the -th data point written as a column vector, so in two dimensions .
  • is the class-1 mean vector, also a column.
  • is the deviation vector of point from its class center — how far, and in which direction, the point sits away from the middle of its class.
  • The superscript transposes a vector: the column becomes the row .
  • Multiplying the column by its own transpose, , gives a outer-product matrix , so every term of the sum is a matrix.
  • The sum runs over , the five points of class 1, so is a matrix.

In plain words: take each class-1 point, subtract the class mean to get a deviation column vector, multiply the column by its own transpose — that turns it into a 2 by 2 matrix — and add all five matrices. A point exactly at the class mean contributes a zero matrix; a point far away contributes a big matrix. So is bigger when class 1 is spread out more — it is the matrix version of "how scattered is this class".

Worked computation of , with .

The five deviation vectors are:

  • :
  • :
  • :
  • :
  • :

Each deviation vector is transposed and multiplied by itself (column times row), giving five outer products:

The first matrix is the one worked in full in the lecture: , , , . Adding all five entries position by position:

So the within-class scatter of class 1 is . Sense-check: the diagonal entries are sums of squared deviations, so they can never be negative; 20 and 10.8 are both positive, and the off-diagonal 10 is the shared spread of the two coordinates — smaller than the square root of the product , as a valid scatter matrix requires.

The class-2 scatter matrix is built the same way: take every point of class 2, subtract , form the outer products, and add them. Only the top-left entry is readable from the lecture — it comes out as 30. The remaining entries can be recovered consistently from the lecture's own final result (the discriminant direction computed in section 14.2.6), so that every stated number in this lecture is mutually consistent:

Reconstruction of — consistent with the lecture's stated results.

Write the unknown entries as . Then the total within-class scatter is

with and . The lecture's final direction satisfies with . Using the formula for inverting a 2 by 2 matrix, the components of are

Setting and gives two equations; solving them (the negative root of the resulting quadratic makes negative, which is impossible for a sum of squares, so it is discarded) yields and . So

Sense-check: recomputing the direction from the reconstructed matrix reproduces the professor's result — — and the lower-right entry 12.74 is a positive sum of squares, so the reconstruction is consistent with every number stated in the lecture. Treat these as recovered values, not as fixed constants; the exam always gives you the matrices directly.

One thing worth noticing: in all of these matrices the (1,2) and (2,1) entries are the same. The scatter matrices are symmetric, exactly like the covariance matrix. Reading them the same way, the diagonal entries are variances and the off-diagonal entries measure the combined variation between the two variables (the entries can be labelled , where ). In the previous session the covariance matrix was simply given; here the approach of building the scatter matrices step by step was shown — but note there are many equivalent approaches to arrive at these values. In particular, the sample covariance matrix of a class is the scatter matrix divided by : for class 1, . The scatter matrix keeps the same information without the division, which is why it appears directly in the formulas.

Exam note. For this course you are not expected to calculate these scatter matrices by hand in the exam — the covariance (and scatter) values will be given to you. What you should be ready for is the interpretation part, in the same style as the mid-semester exam: reading a matrix, saying which entry is a variance and which is the combined variation, and explaining what the symmetry means.

14.2.5 Total Within-Class Scatter

The total within-class scatter combines both classes. The verbal description: is simply plus :

For the top-left entry this is . With the reconstructed , the full sum is

The interpretation is a pooled version of the per-class reading: the diagonal holds the total within-class variance of each variable (50 for the -coordinate, about 23.5 for the -coordinate), and the off-diagonal holds the total combined variation. is the "how scattered are the points inside their own classes" budget of the whole problem, summed over both classes.

14.2.6 The Discriminant Direction and the Projection

Now the key formula: the vector along which projecting the data gives the best possible separation is

The verbal description: the discriminant direction is the inverse of the total within-class scatter matrix times the difference of the class means. Every part earns its place: shrinks directions in which the classes are internally spread out, and points from the center of class 2 toward the center of class 1.

Formalize — the inverse, then the product.

For a 2 by 2 matrix , the inverse is

The quantity is the determinant. The inverse exists only when the determinant is not zero — for a scatter matrix built from real points it is positive unless one variable is a constant or a copy of the other. The and entries swap sign, which is why the inverse of a symmetric matrix is symmetric again.

The lecture applies this formula to directly, identifying with the four entries of : , , , .

Next, the difference of the means:

The intuition behind the formula: you are minimizing the within-class scatter and maximizing the separation between the classes — the farther apart the class means are, the easier the separation. If the two means coincided, the difference vector would be zero and no direction could separate the classes; if they are far apart, the difference vector points straight from one class center to the other.

Worked example — inverting and multiplying.

Determinant:

Inverse:

Multiply by the mean difference:

So . This resolves the garbled spoken result ("minus 0.2 to 1, 0.24"): the natural reading is the vector , and the numeric computation confirms it. Sense-check: the direction points mostly leftward () and slightly upward (), exactly the way from the class-2 cloud (mean at ) back toward the class-1 cloud (mean at ).

Where does the formula come from? The lecture notes that the derivation uses calculus, Jacobians, and partial derivatives and does not show it. Here is the argument in full. The goal is a direction such that the projected points are far apart between classes and tightly packed within classes. Projecting the data onto sends each point to the scalar . The projected class means are , and the projected within-class scatter is (projecting a scatter matrix squeezes it along ). The separation between the projected class means, squared, is

where is the between-class scatter matrix (a rank-one matrix built from the mean-difference vector). Fisher's criterion packs both goals into one ratio — between-class separation on top, within-class scatter on the bottom:

Maximizing means making the numerator (separation) as large as possible relative to the denominator (internal spread). Differentiating with the quotient rule and setting the derivative to zero:

which simplifies to the generalized eigenvalue problem

Now use the shape of : multiplying it by any vector always returns a multiple of , because

and the bracket is just a number. So the left side of the eigenvalue equation is parallel to the mean difference, and so must be parallel to it too: for some number . Multiply both sides by and ignore the irrelevant scale (a direction does not care about length):

which is exactly the professor's formula. The text Research Methodology states the same idea in words — the estimation principle is that the variance between the groups relative to the variance within the group should be maximized.

One convenient property: the length of does not matter. may be multiplied by any constant and nothing changes — the direction of the line stays the same, because every projected score is scaled by the same factor and the ordering of points on the line is untouched. Scaling by 100 turns the vector into , drawn in the lecture as a direction with components about . When you see a textbook or software report a discriminant vector with different numbers, compare the direction, not the digits.

The projection: draw class 1 as circles and class 2 as triangles in the scatter plot. If you project along the maximum-eigenvalue direction, the projection gives mismatches — triangles and circles fall on top of each other. Project along instead, and among all possible directions this one gives the best possible separation: the projected scores of the two classes occupy two separated intervals on the line.

Worked example — the projection and the cutoff.

Project the five class-1 points onto . For a point , the score is :

The five class-1 scores sit in the interval about . The projected class means are

so the class-1 cloud centers near and the class-2 cloud centers near — a gap of more than 1.5 units on the projected line. A threshold near separates them: points above the threshold are class 1, points below are class 2. Sense-check: every one of the five class-1 scores lies above , and the class-2 center lies far below it, so the cutoff cleanly separates the classes on this data — the property PCA could not deliver.

That threshold choice is a separate decision — a common default is the midpoint between the projected class means — but the direction itself is what LDA delivers. A final note on conventions: different textbooks treat LDA with different notations and approaches; the route shown here — within-class scatter matrices, their sum, and — is one standard way. The textbook, for example, works with an unstandardized discriminant function of the form and reports the between-to-within ratio as an eigenvalue; the two views describe the same separation, dressed in different notation.

Assumptions & scope — when this formula applies and when it breaks.

  • must be invertible. You need more observations than variables (roughly ), and no variable may be a constant or a perfect copy of another. If is singular, the formula collapses; standard practice is to reduce or regularize the features first.
  • Pooled within-class scatter. assumes the two classes have similar internal spreads, so that pooling them into one matrix is honest. If one class is far more scattered than the other, the pooled matrix over-weights the wider class and the separation degrades; a quadratic boundary would do better.
  • Scale sensitivity. Like PCA, the direction depends on the units of the variables; the discriminant vector and its threshold are only meaningful for the scales used.
  • The threshold is not part of the direction. LDA gives ; deciding the cutoff value is a second step that depends on how you weigh misclassification of the two classes.

Pitfalls — common traps.

  1. Reaching for PCA on a classification problem. PCA optimizes variation, not separation; the lecture's own example shows the two classes mixed on the max-variation line. Always ask what the downstream goal is before picking the technique.
  2. Confusing scatter with covariance. The scatter matrix is the covariance sum of outer products without the factor; the same numbers appear in both, and mixing the two scales quietly changes every later result.
  3. Caring about the length of . The direction is scale-free — multiplying by any constant changes nothing. Comparing discriminant vectors digit-by-digit across sources is meaningless.
  4. Assuming the threshold comes free with LDA. The direction maximizes separation; the cutoff on the projected line is a separate choice, and different cutoffs trade different misclassification errors.

Recap + bridge. LDA finds the direction that maximizes between-class separation relative to within-class scatter, and a single threshold on the projected line classifies the data — fixing exactly what PCA could not. The next section turns the problem around: when the class labels do not exist at all, clustering lets the data itself discover the groups.

14.3 Hierarchical Cluster Analysis

14.3.1 Cluster Analysis: Source and Approach

Hook — grouping without a map. This time there are no class labels at all: no one has told you who is similar to whom. Can the data itself decide which of the 25 respondents belong together?

Cluster analysis (grouping objects into classes when the classes are unknown) is a classification technique built on a simple idea: similarity is measured over several variables, and objects are grouped so that the emerging groups are homogeneous inside and heterogeneous between. The lecture introduces hierarchical cluster analysis through a worked survey example taken from the textbook Research Methodology: Concepts and Cases by Deepak Chawla and Neena Sodi. That book works the whole example through SPSS, which is paid software; the practice here uses R instead, which is open source — the point being that nobody should have to spend time on paid tools. If you already own the book and already work with SPSS, you can follow the example there; otherwise the same analysis is shown here with R.

This SPSS-versus-R split mirrors common industry practice — many classic textbooks are written around paid statistical suites, while the open-source ecosystem offers equivalent workflows at no cost. Analysts routinely re-run textbook examples in free software to learn the method without a license.

14.3.2 The Nano Sample Survey Data

The example is the Nano sample survey: a study of purchase intention for the Nano car from Tata Motors, conducted on 200 two-wheeler owners in the National Capital Region. The study captured their attitudes and demographic profiles. For the in-class exercise the analysis uses 25 respondents who answered 9 attitude questions, each measured on a 5-point Likert scale — a Likert scale (a rating scale where people state their agreement with a statement on points 1 to 5, from strong disagreement to strong agreement). The variables labelled 1a through 1i are the attitudinal variables; the remaining variables in the survey are demographic profiles, and they are set aside for this analysis — demographic profiles would be dealt with in a different way and interpreted with different techniques.

The nine attitude statements, as read out in the lecture:

  1. I think in India we have been able to achieve technological standard of high order
  2. Made in India
  3. Value for money
  4. Convenience over style
  5. Do not waste expenditure
  6. No compromise on safety
  7. Saver not spender
  8. Try new things
  9. Be a part of changing the world

The first statement was garbled in the recording (the spoken words "LA stands for Indian technology, high order" point to it), and the reference textbook confirms the wording above: the same survey's attitudinal table lists "I think in India we have been able to achieve technological standard of high order" as the first statement.

The first respondent's answers were: 5, 5, 3, 2, 3, 3, 4, 1, 1. The full data set is a 25 by 9 matrix of scores between 1 and 5, one row per respondent, one column per question. With intuition you can already guess that respondents with similar answers should cluster together; the whole exercise is to justify that grouping from the data itself.

Inputs & outputs of the analysis.

  • Inputs: the score matrix (25 respondents, 9 attitude questions, integer values from 1 to 5) plus the choice of distance measure and linkage method.
  • Outputs: the distance matrix (, symmetric, zeros on the diagonal), the agglomeration schedule (24 rows, one per merging stage), the dendrogram, and — in R — the merge and height vectors that reproduce the schedule.

14.3.3 Distance Matrix and the Most Similar Pair

Hierarchical cluster analysis grows clusters by repeatedly joining the most similar items: the two people whose distance is the minimum. The distance measure used here is the Euclidean distance — the straight-line length between two points in the space of the answers. The general formula:

Formalize — every symbol.

  • and are two respondents written as vectors over the attitude questions, so and .
  • and are their scores on question .
  • The sum runs over all nine questions, to .
  • The square root at the end keeps the distance in the original "score units".

In plain words: for each question, take the difference of the two answers, square it, add the nine squared differences, and take the square root. Two respondents with identical patterns get distance 0; the more their answers differ, the larger the distance. The shorter the distance, the greater the similarity.

The lecture does not bother scanning the entire distance matrix by hand — the software computes it behind the screen, and the graphical representation uses this same formula — so you read the output instead of recomputing.

Worked example — Euclidean distance on tiny inputs.

From the textbook's two-variable illustration: person A scores (1, 2) and person B scores (5, 2) on two variables. Then

A third person C with scores (6, 2) gives and . So B and C are the most similar pair — the smallest distance wins. Sense-check: B and C differ only in the first variable, by 1 point, while A differs from both by 4 or 5 points, so the smallest distance belongs to the pair that agrees most.

In the survey itself, the distance matrix for the 25 respondents shows, among all pairs, that respondents 3 and 8 have distance 0: their response patterns are identical. That makes 3 and 8 the most similar pair. The procedure then repeats — find the next most similar pair, compare it with the ones already found, and continue merging.

Scope — the caution about scales. Euclidean distance is not scale-invariant: changing the unit of one variable (say, rescaling one question's answers from 1–5 to 1–50) changes which pairs look most similar, and the variable with the bigger units dominates the distance. Here all nine questions use the same 1-to-5 scale, so the measure is fair without extra work. If variables were measured on very different units, the data should be standardized first — though standardization can shrink the very differences that separate the groups, so the textbook advises designing the questionnaire so that all scales have roughly the same range. Two related measures exist for completeness: the squared Euclidean distance (same ordering, faster, and the most common choice in clustering software) and the Manhattan (city-block) distance, the sum of absolute differences.

14.3.4 Two Ways to Identify Clusters

The lecture gives two equivalent ways to read the finished analysis once the agglomeration schedule is complete:

  1. Generate the dendrogram and identify the clusters.
  2. Generate the agglomeration schedule and identify the clusters.

Either one gives the same answer about which clusters exist. The word agglomeration means building up: the schedule is the written record of the merges — which cluster joined which, stage by stage — and the dendrogram is the same record drawn as a diagram. After identifying the clusters, the next questions are which clusters can be retained and which can be dropped, and finally how to interpret and label the clusters — that is the part that is required from your side.

14.3.5 Reading the Agglomeration Schedule

The agglomeration schedule records, stage by stage, which clusters are combined at each step. Two columns, usually labelled V1 and V2, name the clusters merged at that stage. The sign convention:

  • A negative value, say , means the 3rd leaf — an original respondent — is merged.
  • A positive value, say , means the cluster that was formed at stage 2 is merged.

Formalize — the minus/plus convention in one line. In the schedule, a negative entry says "merge the single original respondent "; a positive entry says "merge the cluster that was created at stage ". So minus points to a leaf of the grouping, plus points to a previously formed branch.

Worked stages from the lecture.

  • Stage 1: V1 = , V2 = — merge respondents 3 and 8, because they form the most similar pair (their distance is 0). The coefficient (height) at this stage is 0 and the difference from the previous stage is 0.
  • Stage 2: V1 = , V2 = — merge respondents 6 and 11.
  • Stage 3: V1 = , V2 = — merge respondent 21 into the cluster formed at stage 2, so respondent 21 joins to make .

So a minus sign means "merge a single leaf", and a positive number means "merge the cluster that already exists from that earlier stage". Sense-check: stage 3's second column is the small positive , not a large negative number — reading it as "respondent 2" would be wrong; it points back at the stage-2 cluster , exactly as the merge result shows.

Counting the clusters: 25 respondents start as 25 individual clusters. After stage 1 there are 24 clusters (23 singletons plus one pair). After stage 2 there are 23 clusters, and so on. The schedule is the complete summary of the merging process: for objects it has rows, one per merge, ending with a single cluster holding everyone.

To see how the numbers in the schedule arise, the textbook walks through a miniature version with five consumers (cases 1, 24, 4, 7, 18) and their Euclidean distance matrix. The closest pair is case 1 and case 24 at distance 1.0, so stage 1 merges A(1) and B(24). The next closest pair is case 7 and case 18 at distance 2.0, so stage 2 merges D(7) and E(18). Now the clusters are , , and the singleton C(4). Under average linkage, the distance between cluster and C is the average of the individual distances: , so stage 3 merges C into at coefficient 5.5. Finally joins the rest at the average distance , and the four-stage merging is complete. This is the same machinery the software runs on all 25 respondents, and it explains why the coefficients on the schedule can be fractional numbers.

14.3.6 Choosing the Number of Clusters

The agglomeration schedule also carries the coefficients (heights) at each stage and a difference column between successive coefficients. To choose the number of clusters you read the differences:

  • Start from the last coefficient — the stage where all objects have been grouped into a single cluster (stage 24).
  • Subtract the coefficient of the second-last stage (stage 23). The lecture reads this difference as about 34 minus 21, giving 13.43 — the level of the two-cluster solution.
  • The next difference, at the three-cluster level, is 15.93.
  • The next difference after that is small: 0.58.

Worked example — the biggest jump decides.

The differences between successive coefficients read from the lecture:

The maximum variation happens when moving from the two-cluster to the three-cluster solution. That is the signal: three clusters are enough for the analysis — you can divide the 25 respondents into three similar groups, label them, and address each one. Sense-check: the jump to three clusters is the largest, and the jump after it collapses to 0.58, so adding a fourth cluster buys almost nothing; the structure of the data stops at three groups.

The judgment behind the cut. Choosing where to cut involves some personal interest or personal bias, but the majority convention is to cut where the huge difference appears. And even a small jump in the differences is not unusual — a small jump can still carry meaningful information, so do not dismiss it out of hand. The small 0.58 difference after the three-cluster level still deserves attention when you read the schedule; it only means that below three clusters the data is already well summarized.

For comparison, the textbook's SPSS run on the same Nano survey reports coefficients 59.222, 40.667, 11.800 and 8.50 at the final four stages, giving differences 18.55, 28.867 and 3.5 — different numbers from the R output, because different software runs produce different coefficient values, but the pattern is the same: the maximum jump happens when moving from two to three clusters, so the three-cluster solution is recommended again.

14.3.7 The Dendrogram

The other way to assess the number of clusters is to physically observe the dendrogram — the tree graph built from the distance matrix, drawn with heights at every merge. You can read a dendrogram vertically or horizontally; both work. Observing the tree gives the same conclusion as the difference column of the schedule.

A picture of the dendrogram for the survey: name the horizontal axis "respondents (case numbers 1 to 25)" and the vertical axis "height (the coefficient at which clusters merge)". The 25 respondents sit along the base as leaves; each merge draws a branch at the height of its coefficient; pairs that are very similar (like 3 and 8, distance 0) join near the bottom, and bigger groups join higher up. The landmark is the height of the top merges: two large branches meet at a high coefficient, then one of them splits much lower — the big gap between the top merge and the merges below it is the same "big difference" that the schedule showed. The takeaway: the number of tall, well-separated branches you can count below the gap is the number of clusters.

Worked example — reading the tree.

For this survey, reading the tree shows three groups among the 25 respondents: cluster 1 holds respondents 1, 4, 9, 23, 24, 12 and 14; the remaining individuals fall into cluster 2 and cluster 3. This is one way of assessing that three clusters are adequate to address the problem — either through the agglomeration schedule or through the dendrogram. Sense-check: the schedule's coefficient differences and the tree's branch heights tell the same story, so two independent readings of the same output agree on three clusters.

14.3.8 Cluster Analysis in R

The whole analysis is a few R lines:

data <- read.csv(file.choose(), header = TRUE)
d <- dist(data)
fit <- hclust(d, method = "average")
plot(fit)
fit[["merge"]]
fit[["height"]]

Step by step — what each line does.

  • read.csv(file.choose(), header = TRUE) reads the survey data; file.choose() lets you pick the file interactively, and header = TRUE says the first row holds variable names. (This is the standard argument name in R's read.csv; the lecture's spoken description was garbled, and "header = TRUE" is the natural reading that matches the R documentation.)
  • dist(data) computes the distance matrix — by default the Euclidean distance over the nine questions, giving the matrix of pairwise distances.
  • hclust(d, method = "average") runs the hierarchical clustering on the distance matrix with average linkage — the linkage method the textbook also uses for this Nano example. Average linkage defines the distance between two clusters as the average of all pairwise distances between their members, which is what the five-consumer walkthrough above computed by hand.
  • plot(fit) draws the dendrogram, vertically or horizontally.
  • fit[["merge"]] reproduces the whole agglomeration schedule stage by stage — the V1, V2 columns of every merge, with the same sign convention: negative entries name original respondents, positive entries name clusters formed at earlier stages.
  • fit[["height"]] gives the height (coefficient) at every stage — the numbers whose differences decide how many clusters to keep.

In the R output shown in the lecture, the first stage merges respondents 23 and 24 because of their similarity, then 6 and 7, and so on. Notice that this differs from the 3-and-8 pair read earlier from the printed distance matrix: both pairs have distance 0, and when several pairs tie at the minimum distance, the software's tie-breaking decides which one is reported first. The textbook's SPSS schedule for the same survey starts with yet another zero-distance pair (18 and 25). All three outputs are consistent — the ties are real ties — and only the order of reporting differs.

So the complete workflow is: read the data first, then compute the distance matrix, then plot the dendrogram, and read off merge and height — those outputs cover the entire analysis part of cluster analysis.

A note on cost: for respondents there are pairwise distances to compute, and the schedule has rows. In general the distance matrix costs about operations for questions, and the agglomeration loop runs stages, so a naive implementation can reach work in the worst case. That is why hierarchical clustering is comfortable for hundreds of respondents but heavy for millions of records.

When to use it — and the alternative. Hierarchical clustering is the right tool when you want the full family tree of groupings (a dendrogram for every possible number of clusters) and when the sample is small enough that the schedule is readable — the 25 respondents here are ideal. Its main alternative is K-means (non-hierarchical) clustering, which starts from a pre-specified number of clusters and moves points between them; K-means scales far better but requires you to choose in advance and returns flat groups only. Common practice, as the textbook notes, combines the two: use hierarchical clustering to decide how many clusters exist, then run K-means with that number for the final solution.

Exam note. You do not need R for the exam — no requirement to run any software. The relevant outputs — the distance matrix, the agglomeration schedule, the coefficients with their differences, and the dendrogram — will be given to you, and your job is to interpret them: reading the minus/plus convention in the schedule, choosing the number of clusters from the biggest coefficient difference, and reading the clusters off the dendrogram.

14.3.9 Interpretation and Profiling of Clusters

The cluster problem is not yet solved completely at this point. The next session will go back to this same simple data set, walk through the R output again, and then discuss the interpretation and profiling — the labeling — of the three clusters, finishing the topic. After that comes a review session, which consolidates everything discussed in the course rather than dumping new information. Along the way, remember that different research problems may need different variable sets: demographic profiles, for example, would be interpreted with different techniques than the attitudinal variables used here.

14.3.10 Student Questions and Answers

The class raised two questions during the discussion; both were answered on the spot and are worth keeping:

Q: Is the reference book for this example available to us?

A: Yes, the book is available. It covers this exact Nano example, but every step of the analysis runs through SPSS. Since SPSS is paid and R is open source, the practice here uses R — the book remains a good reference if you already work with SPSS.

The second question was about how the clusters appear visually. The professor's answer pointed forward to the graphical outputs — which is exactly the material the session then worked through:

Q: How do we represent the clusters on a graph?

A: The same merging process appears in three graphical forms: the distance matrix, the dendrogram, and the agglomeration schedule. The session continues with exactly this — the distance matrix first, then the tree, then the schedule — so the graph representation is the topic that follows.

Between the two answers: the first is a practical question about sources (book versus software), the second about output formats (matrix, tree, schedule) — two different confusions, so both are kept as separate exchanges rather than merged.

Exam Guidance Summary

The professor's exam guidance across the session, gathered in one place:

What to expect in the comprehensive examination.

  • The final session of the course is a revision session: how you may expect the question paper, and how much of the comprehensive examination can be covered — the remaining coverage will be notified separately. A review session will go through everything discussed rather than adding new material.
  • For PCA and LDA: the covariance matrix will be given to you in the exam; you will not be asked to compute the scatter matrices by hand. Expect interpretation questions in the style of the mid-semester exam — reading matrices, explaining what the eigenvalues and the discriminant direction mean, and why PCA is not suited to classification problems.
  • For cluster analysis: you do not need R. The relevant outputs — the distance matrix, the agglomeration schedule, the coefficients with their differences, and the dendrogram — will be provided, and you will interpret them: reading the minus/plus convention in the schedule, choosing the number of clusters from the biggest coefficient difference, and reading the clusters off the dendrogram.
  • Overall, interpretation-heavy questions are what to expect, in line with the mid-semester pattern.

The recurring theme is worth stating in plain words: the computations belong to the software, and the exam tests whether you can read the outputs, explain the reasoning behind them, and connect them to the concepts — variation shares in PCA, the discriminant direction in LDA, and the cluster structure in hierarchical cluster analysis.

Key Industry Applications

The session's techniques appear in real practice in three places worth remembering:

Market research — the Tata Motors Nano study. The Nano sample survey is a real purchase-intention study: 200 two-wheeler owners in the National Capital Region were surveyed about the Nano car from Tata Motors, and the cluster analysis segments the 25 respondents into similar attitude groups. Once the three clusters are profiled and labeled, the marketing team can design a separate offer, message, or product positioning for each group — the standard market-segmentation workflow that cluster analysis powers across industries.

The open-source shift — SPSS versus R. The textbook runs the Nano example in SPSS, paid software; the practice here uses R so that no paid software is required. This mirrors a broad industry trend: statistical suites that once required licenses now have free, equally capable open-source counterparts, so practitioners can reproduce textbook analyses at no cost and companies can run the same workflows without per-seat fees.

PCA and LDA in practice — two different jobs. PCA for dimensionality reduction keeps the maximum variation and is used for compression, exploration, and denoising; LDA is used where the goal is class separation, such as credit scoring, diagnostics, and churn prediction. Different textbooks and software packages follow different LDA conventions, so the approach shown here — within-class scatter matrices, their sum, and — is one standard route among several, and the direction it produces is the same one the others find.

ASM Lecture 14 notes · Linear Discriminant Analysis and Hierarchical Cluster Analysis

Advanced Statistical Methods· postgraduate· 2026-08-11

Sections Breakdown

1Principal Component Analysis Recap

Recap of PCA: projecting data onto the direction of maximum variation, found through the covariance matrix eigenvalue equation, with the eigenvalue shares of total variation.

2Linear Discriminant Analysis

Why PCA falls short for classification; the within-class scatter matrices S1 and S2, their sum S_W, and the discriminant direction w = S_W^-1(mu1 - mu2) with a single threshold on the projected line.

3Hierarchical Cluster Analysis

Euclidean distances, the agglomeration schedule, the dendrogram, choosing the number of clusters from coefficient differences, and cluster analysis in R on the Nano survey data.

4Exam Guidance Summary

Professor's exam guidance: matrices and cluster outputs are provided, and questions are interpretation-heavy in the style of the mid-semester exam.

5Key Industry Applications

Real-world uses: the Tata Motors Nano market-research study, the SPSS-to-R open-source shift, and the PCA-versus-LDA division of labour.

Postgraduate students in Advanced Statistical Methods

Exam Revision Notes

Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.

Principal Component Analysis Recap

Must-know: PCA projects data onto the direction of maximum variation; the covariance matrix's eigenvalue equation det(Sigma - lambda I) = 0 gives the roots, and each root's share of total variation is lambda_j divided by the sum of all eigenvalues.

⚠️ Top pitfall: Confusing eigenvalues (how much variation) with eigenvectors (which direction), or forgetting that the share formula divides by the sum of all eigenvalues; eigenvalues are never negative for a covariance matrix.

Self-check: With eigenvalues 21 and 4, what percentage of the total variation does the first principal direction carry?

Connects to: Linear Discriminant Analysis.

Linear Discriminant Analysis

Must-know: The discriminant direction is w = S_W^-1(mu1 - mu2): invert the total within-class scatter matrix and multiply by the difference of the class means; w is scale-free, and a single threshold on the projected line separates the classes. Covariance/scatter matrices are given in the exam; interpretation questions are expected.

⚠️ Top pitfall: Using PCA for classification (it optimizes variation, not separation); confusing scatter matrices with covariance matrices (scatter = (n-1) x covariance); caring about the length of w (any scaling keeps the same direction).

Self-check: With class means (4, 4.2) and (10, 3.2), what is the mean-difference vector, and what direction does it point?

Connects to: Principal Component Analysis, Hierarchical Cluster Analysis.

Hierarchical Cluster Analysis

Must-know: Cluster outputs are given in the exam (distance matrix, agglomeration schedule, coefficient differences, dendrogram) and you interpret them: negative V1/V2 entries merge a leaf, positive entries merge an earlier-stage cluster; the number of clusters is chosen at the biggest coefficient difference (three clusters for the Nano data); the dendrogram gives the same answer.

⚠️ Top pitfall: Misreading a positive schedule entry as a respondent number (it is a stage-2 cluster); forgetting that Euclidean distance is not scale-invariant; dismissing small coefficient jumps (0.58) that can still carry information; expecting one canonical first merge when ties at distance 0 are broken arbitrarily by the software.

Self-check: In the agglomeration schedule, what does V1 = -3, V2 = -8 mean, and what does V1 = -21, V2 = 2 mean?

Connects to: Linear Discriminant Analysis.

Exam Guidance Summary

Must-know: Exam pattern: covariance and scatter matrices are given (no hand computation), cluster outputs are given (no R), and the questions are interpretation-heavy in the style of the mid-semester exam; the last session is a revision session covering how to expect the question paper.

⚠️ Top pitfall: Preparing to compute scatter matrices or run R by hand in the exam — both are given as outputs; the exam tests interpretation.

Self-check: In the exam, will you compute the scatter matrices yourself, or will they be provided?

Key Industry Applications

Must-know: PCA is the tool for compression and exploration; LDA is the tool for class separation; cluster analysis segments customers into profiled groups for marketing; open-source R reproduces textbook SPSS workflows at no cost.

⚠️ Top pitfall: Choosing PCA when the goal is classification, or assuming only paid software can run the analysis.

Self-check: Which technique would a bank use to separate defaulters from payers on a single score, and why?

Connects to: Principal Component Analysis, Linear Discriminant Analysis, Hierarchical Cluster Analysis.

Was this lecture useful?

Loading comments…
🤖

BitsNotes AI Assistant

Subject Notes Assistant

Configure AI Chat

Choose how to access the chatbot
Have your own API key?

Switch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.

🔑 Enter API key above to fetch live models from provider, or enter model name manually.
OpenAI-Compatible API Support

Choose any provider preset (Gemini, DeepSeek, Kimi, GLM, MiniMax, Qwen, OpenAI, Groq, Ollama, etc.) or enter a custom endpoint URL.

Security & Privacy First

Your API key is sent directly from your browser to your specified provider. BitsNotes servers never store or see your key.