Classification and Diagnostic Analysis
Cluster Analysis
Cluster analysis sorts people into groups with similar profiles.
Cluster analysis takes several measures from each person and sorts people into groups whose members have similar profiles, when the groups aren't known in advance.
Do college students fall into distinct motivation profiles, and what does each profile look like? Two hundred fifty college students rated their intrinsic motivation, extrinsic motivation and amotivation for their studies on 1-to-7 scales and logged their weekly study hours.
- Estimates
- Groups of people with similar profiles
- Observations
- Independent
- Parametric
- No
- Headline Statistic
- \bar{s}
- Key Estimate
- Average Silhouette Width
The Basics
When to Use It
Use it when you have several continuous measures from each person, you suspect people fall into a few types or profiles on them, and you don't know in advance who belongs where or how many types there are. It's a person-centered question: not how the measures relate across everyone, but which combinations of scores go together in people. Vansteenkiste et al. (2009) and Ratelle et al. (2007) clustered students on types of academic motivation. For example:
- Do college students fall into distinct motivation profiles, and what does each profile look like?
- Do patients in a depression clinic form subgroups on sleep, appetite, anxiety and anhedonia symptom scores?
- Do children's scores on working memory, inhibition and processing speed tasks show distinct cognitive profiles?
This page uses the usual two-stage recipe. First a hierarchical method, Ward's method, starts with everyone alone and merges the two most similar groups, one merge at a time, into a tree; you cut the tree where it shows a clear number of groups. Then a partitioning method, k-means, lets each person move to the nearest group's average, which fixes early merges the tree can't undo.
Vocabulary You Need
Definition Cluster
A group of people (or other cases) whose scores on a set of measures are, on the whole, more alike than they are like other groups' scores. A cluster is described by its center, the members' average on each measure, which is its profile. Clusters are found from the data rather than defined in advance, so they're a summary of how the scores are spread out, not proof that distinct types of people exist: a clustering method returns clusters even from data with no groups at all. Called profiles, types or subgroups in some fields. Glossary →
Definition Distance Measure (d_{ij})
How far apart two people's sets of scores are. The usual choice is Euclidean distance, the straight-line distance: square the gap on each measure, add them up and take the square root, so large gaps count heavily. Squared Euclidean distance skips the square root; city-block (Manhattan) distance adds the absolute gaps; correlation-based distances compare the shape of two profiles and ignore their level; Gower's distance handles a mix of numeric and categorical measures. Every distance depends on the measures' units, so measures on different scales are usually standardized first. Also called a dissimilarity; its opposite is a similarity. Glossary →
Definition Dendrogram
The tree a hierarchical clustering draws. Each case starts as a leaf at the bottom; every merge joins two branches at a height that shows how costly the merge was (for Ward's method, how much it added to the within-cluster spread). Cutting the tree with a horizontal line gives one cluster for each branch the line crosses. Long vertical stretches with no merges mean well-separated groups, so a big jump in merge height suggests stopping just below it. Only the heights carry information: the left-to-right order of the leaves is arbitrary, and two cases drawn side by side may be far apart. Glossary →
Definition k-Means Clustering
A partitioning method that splits cases into a chosen number k of clusters by making the within-cluster sum of squares, the total squared distance of cases from their cluster's center, as small as possible. The usual algorithm alternates two steps: assign each case to its nearest center, then move each center to the average of its cases, until no case changes cluster (Lloyd's algorithm; R's default, Hartigan and Wong's, also checks single moves). It finds a good solution near where it started, not necessarily the best one, so the result depends on the starting centers: start from another method's solution, such as Ward's, or from many random starts with a fixed seed. Like Ward's method, it favors compact, round clusters of similar spread. Glossary →
Definition Silhouette Width (s)
For one case, a is its average distance to the other members of its own cluster and b its average distance to the members of the nearest other cluster; its silhouette width is s = (b − a) / max(a, b) (Rousseeuw, 1987). Near 1, the case sits well inside its cluster; near 0, it lies between two clusters; below 0, it's closer to another cluster than to its own. Averaged over all cases, it summarizes a whole solution, and it can be compared across numbers of clusters: the k with the highest average is a common choice, and that highest average is called the silhouette coefficient. It rewards compact, well-separated clusters, so it can favor too few clusters when groups overlap. Glossary →
Definition Number of Clusters (k)
How many groups a cluster analysis splits the cases into. Most methods need it given, or leave you to cut a tree at some height, and they will return k groups for any k, from any data. So k is a decision: compare the solutions for several values on the average silhouette width (the k with the highest is a common choice), look for a big jump in a dendrogram's merge heights, check the same numbers on structureless data, and ask whether the groups make sense. Report the neighboring values too. Glossary →
Assumptions
1. The Right Variables Your variables capture the differences the groups should reflect, and little else.
- What It Means
- A cluster analysis finds groups only on the variables you give it, and each variable counts equally in the distances. Irrelevant variables add noise that blurs real groups; several measures of the same thing give that thing extra weight. The variables you want to compare the groups on afterward (outcomes, validators) should stay out.
- Applies To
- Variables
- How to Check
- By reasoning, not by a test. Can you say why each variable belongs in the profile? Look at the correlations: variables correlating very highly are near-duplicates. Check that no outcome you plan to compare the clusters on is among them.
- How Much It Matters
- A lot. The clusters can only differ on what you measured, and an irrelevant or redundant variable counts as much as any other. Three motivation scales chosen from self-determination theory keep the profiles interpretable; adding, say, five overlapping extrinsic items would pull the solution toward extrinsic motivation.
If It's Violated
- Design Change Pick the variables that define the profiles you care about before clustering, and keep outcomes you want to compare the clusters on out of the clustering.
- Correction Average highly correlated measures of one construct into a single score, so no construct gets extra weight by being measured several times.
2. Comparable Scales Each variable counts as much in the distances as you intend it to.
- What It Means
- Distances add up gaps across variables in their own units, so a variable with a larger spread counts for more. Unless the units are the same and the difference in spread is meaningful, the variables need to be put on one scale, usually z-scores, before any distance is computed.
- Applies To
- Variables
- How to Check
- Compare the variables' units and standard deviations. If they differ, standardize; if you don't, say why raw units are the right yardstick.
- How Much It Matters
- A lot, for any distance-based method. Unstandardized, a variable measured in larger units (minutes rather than hours) dominates every distance. Here all three scales run 1 to 7 with similar SDs, so standardizing changes little, but it's still what makes each count equally. It has a cost: a variable that separates the groups well has a larger SD, because the gaps between groups add to it, so z-scores trim its weight. Here clustering the raw scores gives the same three clusters.
If It's Violated
- Transformation Convert each variable to z-scores before computing distances, and say you did.
- Proceed with Caveat If the variables share a meaningful unit and differences in spread matter, cluster the raw scores and say why.
3. Compact, Similar Groups The groups you're looking for are roughly round and similarly spread.
- What It Means
- Methods built on the within-cluster sum of squares, such as k-means and Ward's method, look for compact groups around a center, of similar spread in every direction. They split long, curved or very unequal groups and can merge a small group into a large one. The method doesn't check this; it just returns the best round groups it can find.
- Applies To
- Joint distribution
- How to Check
- Plot the variables in pairs, colored by cluster, and look for stretched or curved clouds. Compare cluster sizes and within-cluster SDs, and look at each cluster's average silhouette: a cluster with many negative silhouettes is a poor fit.
- How Much It Matters
- Some. Ward's method and k-means look for round, similarly spread groups, and they will split a long, curved or very uneven group into pieces. With three overlapping motivation profiles of similar spread they fit well; if one profile were tiny or stretched, they could misplace it.
If It's Violated
- Alternative Test A mixture model lets each profile have its own spread and gives each person a probability of belonging to each profile, with fit indices for choosing the number (Spurk et al., 2020). There's no page for it yet; in R, the mclust and tidyLPA packages fit it.
- Proceed with Caveat Plot the variables in pairs by cluster, and check each cluster's size and silhouette before interpreting it.
4. No Extreme Outliers No single case is far enough from the rest to drive the result.
- What It Means
- A few points far from the rest can pull a statistic around on their own, so it describes those few points more than everyone else. In a test, that can create an effect that isn't there or hide one that is.
- Applies To
- Observations
- How to Check
- Plot the data and look for points far from the rest. With two or more variables, flag cases with large squared Mahalanobis distances across them: points can be ordinary on each variable but unusual in combination. Check each against the raw records, and compare the result with and without it.
- How Much It Matters
- Some. A mean-based method lets a few extreme profiles drag a center toward them, or form a tiny cluster of their own. With 250 students on 1-to-7 scales there's no room for wild values, but check the smallest clusters and the most negative silhouettes.
If It's Violated
- Robust Estimation Use k-medoids (R's cluster::pam), whose centers are real people and are pulled less by outliers.
- Proceed with Caveat Rerun without the flagged cases and report whether the profiles change.
Limitations
This Is Not Your Test If…
- You already know the groups and want to compare them ANOVA Family →
- You want to sort items into factors, not people into groups Exploratory Factor Analysis (EFA) →
- You want to predict a known category from other measures Multinomial Regression →
- You want to know how well a score separates two known groups ROC Curve Analysis →
- You're tracking how people move between states over time Markov Models →
What It Doesn't Tell You
- Whether the types are real. Clustering always returns clusters: asked for three, it found three even in shuffled scores with no profiles. A silhouette of .45, a replication in each half and an outside variable make these three profiles believable, not proven.
- That three is the right number. Three won on the silhouette and the tree, but it's a choice among defensible options, and different variables, a different method or another sample could favor two or four.
- What each student really is. A student like number 1, with a silhouette of only .11, sits between two profiles; a hard label hides that. k-means gives no probability of membership.
- Why the profiles differ in study hours. Intrinsically driven students study more, but the design can't say whether motivation drives studying or something else drives both.
- Who else. The profiles describe these 250 students on these three scales; students elsewhere, or measured with other scales, may sort differently.
Common Mistakes
-
Don'tCluster raw scores measured on different scales.
InsteadStandardize first, or say why raw units are the right yardstick.
-
Don'tTest whether the clusters differ on the variables used to build them.
InsteadValidate them on variables the clustering never saw, and in a second sample.
-
Don'tKeep the number of clusters that gives the most interesting story.
InsteadDecide with the silhouette, the tree's jumps and interpretability together, and report the alternatives.
-
Don'tLeave SPSS's default linkage (between-groups) on without choosing it.
InsteadPick the linkage that matches the groups you expect (Ward's for compact profiles), and report it.
-
Don'tReport clusters without saying how they were found.
InsteadName the variables, the standardization, the distance, the method and how you chose k (Clatworthy et al., 2005).
-
Don'tTreat the clusters you found as proof that distinct types of people exist.
InsteadCall them profiles in this sample, show how well separated they are, and check that they come back in new data.
-
Don'tJudge how similar two cases are by how close together they sit along the bottom of a dendrogram.
InsteadRead the height at which their branches join; the left-to-right order is arbitrary.
-
Don'tRun k-means once from random starting centers and treat the answer as the solution.
InsteadGive it good starting centers (such as Ward's) or many random starts with a fixed seed, and say which.
-
Don'tRead a silhouette above .50 as proof that the groups are real, or below .50 as proof they aren't.
InsteadRead it as how well separated these clusters are, and back it with replication and outside variables.
Result Decoder
Interpretation Guidelines
Benchmarks Average Silhouette Width
-
s ≤ .25
No Substantial Structure
No substantial structure has been found: the clusters are about as close to one another as to their own members.
-
.26–.50
Weak
The structure is weak and could be artificial; try additional methods and check that the clusters replicate.
-
.51–.70
Reasonable
A reasonable structure has been found: most cases sit clearly closer to their own cluster.
-
.71–1.00
Strong
A strong structure has been found: the clusters are compact and well apart.
Kaufman and Rousseeuw's “subjective interpretation” of the silhouette coefficient, from experience, as Struyf, Hubert and Rousseeuw (1997) report it for partitioning methods. They are conventions, not tests; overlapping but real groups, common with psychological measures, often land in the weak band, and structureless data can too.
How It's Reported
Equation Form
Last three Ward merge heights h = 7.19, 19.52, 24.61; 68% of the variation between clusters; three clusters (n = 99, 89 and 62); average silhouette width s̄ = .45 (two clusters: .39); shuffled data s̄ = .27; one normal cloud with the scales' correlations s̄ = .28; study hours η² = .24; split-half agreement 97.6%
Table 1. Cluster Sizes and Centers
| n | Intrinsic M | Extrinsic M | Amotivation M | Intrinsic z | Extrinsic z | Amotivation z | |
|---|---|---|---|---|---|---|---|
| Intrinsically Driven | 99 | 5.62 | 3.25 | 1.61 | 0.93 | −0.67 | −0.75 |
| Extrinsically Driven | 89 | 4.03 | 5.52 | 2.44 | −0.26 | 1.12 | −0.09 |
| Amotivated | 62 | 2.91 | 3.44 | 4.21 | −1.10 | −0.52 | 1.32 |
| All Students | 250 | 4.38 | 4.10 | 2.55 |
Note. N = 250. Clusters from k-means (Lloyd's algorithm) started at the centers of Ward's three-cluster solution, on z-scores of the three scales. Raw means are on the 1-to-7 scales; standardized means are in standard deviations from the whole sample's mean, so 0 is average.
Table 2. Choosing the Number of Clusters
| Average Silhouette | Within-Cluster SS | Share between Clusters | Smallest Cluster n | Silhouette, Shuffled Data (Median) | |
|---|---|---|---|---|---|
| 2 clusters | .39 | 431.4 | .42 | 107 | .25 |
| 3 clusters | .45 | 242.7 | .68 | 62 | .27 |
| 4 clusters | .34 | 219.4 | .71 | 44 | .29 |
| 5 clusters | .29 | 190.8 | .74 | 41 | .29 |
| 6 clusters | .26 | 171.5 | .77 | 20 | .29 |
Note. Each row is its own solution: Ward's tree cut at k clusters, refined by k-means. Average silhouette widths run from −1 to 1; higher means better-separated clusters. Within-cluster SS is out of a total of 747 (3 scales × 249). It falls as k grows, so look for the elbow, where it stops falling steeply: here it drops by 189 from two clusters to three, then by only 23 to four. The last column repeats the whole procedure on structureless data, 50 times: each scale's z-scores shuffled separately, which keeps every score but breaks up the profiles; the median of the 50 average silhouettes is shown.
Table 3. Checking the Three Clusters
| Average Silhouette | Study Hours M | Study Hours SD | |
|---|---|---|---|
| Intrinsically Driven | .55 | 11.10 | 3.58 |
| Extrinsically Driven | .38 | 8.24 | 3.58 |
| Amotivated | .41 | 6.14 | 3.43 |
Note. Each cluster's average silhouette width, and weekly study hours, which the clustering never saw. Study hours differ across clusters with η² = .24.
Full Text (APA Style)
We standardized the three motivation scales and clustered the 250 students by Ward's method on Euclidean distances, then refined the solution with k-means (Lloyd's algorithm; Lloyd, 1982) starting from Ward's cluster centers. Three clusters gave the highest average silhouette width, .45, against .39 for two and .34 for four (Table 2), and the largest jump in Ward's merge heights came after three clusters. By Kaufman and Rousseeuw's conventions that is a weak structure, so we checked it further. 68% of the variation in the standardized scores lay between the three clusters. The same procedure gave a median average silhouette of only .27 (never above .30) on 50 data sets with each scale shuffled separately, and .28 (never above .31) on 50 samples from a single normal cloud with the scales' observed correlations. An intrinsically driven cluster (n = 99) scored high on intrinsic motivation (M = 5.62) and low on extrinsic motivation (3.25) and amotivation (1.61); an extrinsically driven cluster (n = 89) was high on extrinsic motivation (5.52) and near average on the other two; and an amotivated cluster (n = 62) was high on amotivation (4.21) and low on intrinsic motivation (2.91; Table 1). Clustering each half of the sample (the first and last 125 rows, on whole-sample z-scores) separately reproduced the profiles: the second half's students were placed the same way by the first half's centers in 122 of 125 cases (97.6%). The clusters also differed on weekly study hours, which played no part in forming them (M = 11.10, 8.24 and 6.14 hours; η² = .24 from a one-way ANOVA, F(2, 247) = 39.39, with a noncentral-F 95% CI [.15, .33]; Welch's test, which doesn't assume equal spreads, F(2, 152.1) = 39.9, p < .001). Cluster membership predicted study hours better than the three scales as continuous predictors did (R² = .24 vs .20; adding the clusters to the scales, F(2, 244) = 6.76, p = .001).
- Name every choice: the variables, the standardization, the distance, the method, the starting centers and the software.
- Say how you chose the number of clusters, and give the silhouette (or other index) for the neighboring numbers too.
- Give each cluster's size and center in raw units, so readers can see what the profiles look like on the original scales.
- Validate the clusters on variables that played no part in forming them, and treat the cluster names as your interpretation.
Reading Each Piece
The equation form above, piece by piece.
| h = 7.19, 19.52, 24.61 | The last three merges of Ward's tree, from four clusters down to one. Merges up to three clusters are cheap (7.19 and lower); the next merge is drawn almost three times as high (and adds over seven times as much within-cluster spread), the dendrogram's clearest sign that three groups are there. |
| 68% of the variation between clusters | 68% of the variation in the three standardized scores lies between the clusters; the other 32% is how members of a cluster still differ. Some share is guaranteed by the clustering itself, which is why it's compared with structureless data: about .43 with each scale shuffled, and .50 for a single normal cloud with the scales' correlations (medians of 50 data sets each). |
| n = 99, 89, 62 | Three profiles: intrinsically driven (99 students: high intrinsic, low extrinsic and amotivation), extrinsically driven (89: high extrinsic, 1.12 SD above average, near average otherwise) and amotivated (62: amotivation 1.32 SD above average, intrinsic motivation 1.10 SD below). Table 1 has every center. |
| s̄ = .45 (k = 3) | On average, students are moderately closer to their own cluster than to the next one, and three clusters separate them better than two or four. By Kaufman and Rousseeuw's conventions, .45 is weak structure that could be artificial, which is typical of real, overlapping profiles and the reason for the checks that follow. Benchmarks ↑ |
| Shuffled data: s̄ = .27 | Clustering always returns clusters. Shuffling each scale separately keeps all 750 scores but destroys the profiles; asked for three clusters, the same procedure still finds three, with a median average silhouette of .27 over 50 shuffles, and silhouettes that rise with k, to about .29 for four to six clusters. Because shuffling also breaks the correlations between the scales, a stricter baseline is one normal cloud with the same correlations: median .28, never above .31. Our .45 is clearly above both. Benchmarks ↑ |
| Study hours η² = .24 | The profiles line up with how much students study: about 11 hours a week in the intrinsically driven cluster, 8 in the extrinsically driven one and 6 in the amotivated one, and 24% of the variation in study hours lines up with the clusters. That shows the profiles relate to something outside the clustering, but any summary of the three scales would: study hours correlate .40 with intrinsic motivation. The sharper question is whether the profiles predict more than the scores they came from. Here they do, as expected for data simulated from profiles: the three scales as continuous predictors predict 20% of the variation, the profiles 24%, and adding the scales to the profiles raises that by less than 0.1 percentage points. It's a correlation, not a sign that motivation profiles cause studying. |
| Split-half agreement 97.6% | The same three profiles come back when each half is clustered on its own, with centers within about 0.2 SD of each other, and only 3 of 125 students change profile. Replication within one sample is a minimum; a new sample is the real test. |
Calculations
The Running Example
The motivation-profiles study: 250 college students, three motivation scales each, sorted into groups with similar profiles; weekly study hours held back as a check.
There's no hypothesis to test. The targets are the number of profiles, which students belong to each, and what each profile looks like (its center on the three scales). Silhouette widths, a comparison with shuffled data, a split-half replication and study hours are checks on those answers, not tests.
What Your Data Should Look Like
One row per person and one numeric column per clustering variable, with no missing values. Most software drops anyone with a missing value; say how many, or impute first and say how. Keep variables you'll use to check the clusters afterward (here, study hours) in separate columns and out of the clustering. The cluster column below is what the analysis adds; your file starts without it.
| student | intrinsic | extrinsic | amotivation | study_hours | cluster |
|---|---|---|---|---|---|
| 1 | 4.06 | 4.13 | 3.57 | 10.5 | amotivated |
| 2 | 5.88 | 3.84 | 1.23 | 5.5 | intrinsic |
| 3 | 6.46 | 4.34 | 2.11 | 10.0 | intrinsic |
| 4 | 4.35 | 5.38 | 3.67 | 6.3 | extrinsic |
| 5 | 4.79 | 3.37 | 2.18 | 11.4 | intrinsic |
| 6 | 3.81 | 4.09 | 1.34 | 5.4 | extrinsic |
| … 244 more rows | |||||
| M | SD | 1 | 2 | 3 | |
|---|---|---|---|---|---|
| 1. Intrinsic | 4.38 | 1.33 | |||
| 2. Extrinsic | 4.10 | 1.27 | −.20 | ||
| 3. Amotivation | 2.55 | 1.26 | −.62 | −.04 | |
| 4. Study Hours | 8.85 | 4.05 | .40 | −.13 | −.38 |
N = 250.
Correlations are Pearson r.
Simulated data.
Napkin Math
The whole test, one idea at a time. Under each heading, a line says why the step matters, and the green note reads the equation in plain English with the motivation-profiles study's numbers. Collapse all to read just the headings: they tell the whole story on their own.
-
1. Put the Three Scales on the Same Footing
A distance adds up gaps on every variable, so a variable with a bigger spread would count for more. Converting each scale to z-scores makes one standard deviation worth the same on all three.
z_i = \dfrac{x_i - \bar{x}}{s} =\dfrac{4.06 - 4.38}{1.33}= −0.24
z_{\text{ext}} = 0.02
z_{\text{amot}} = 0.81
s_{\text{int}} = 1.33
s_{\text{ext}} = 1.27
s_{\text{amot}} = 1.26
x_i is student 1's intrinsic motivation, 4.06; \bar{x} is the class average, 4.38, and s the spread, 1.33. (4.06 − 4.38) ÷ 1.33 = −0.24: a quarter of an SD below average. With the other two scales' SDs of 1.27 and 1.26, student 1 is at 0.02 (extrinsic) and 0.81 (amotivation).
-
2. Measure How Far Apart Two Students Are
Clustering starts from one number per pair of students saying how different their profiles are. Euclidean distance is the straight-line distance between two points, one per student, in a space with one axis per scale.
d_{ij} = \sqrt{\sum_{v} (z_{iv} - z_{jv})^2} =\sqrt{(-0.24 - 1.13)^2 + (0.02 + 0.21)^2 + (0.81 + 1.05)^2}= 2.32
\bar{d} = 2.24
z_{1v} and z_{2v} are students 1 and 2 on each scale v. The squared gaps are 1.87 (intrinsic), 0.05 (extrinsic) and 3.47 (amotivation); they add to 5.39, and √5.39 = 2.32. Most of the distance comes from amotivation, where student 1 is high and student 2 low. \bar{d}, the average over all 31,125 pairs of students, is 2.24.
-
3. Build a Tree by Joining the Closest Groups One at a Time
Ward's method starts with every student alone and, 249 times, merges the two groups whose union adds least to the spread within groups. Plotting each merge at a height that shows its cost gives the dendrogram. A big jump in height means the groups being joined are far apart: stop before it. Ward's is one of several linkage rules, which set how far apart two groups are. Single linkage uses their closest members and tends to chain people into long strings; complete linkage uses their farthest members; average linkage (SPSS's default, "between-groups") averages all pairs. Ward's is the usual choice for compact profiles.
h_{3 \to 2} = \sqrt{2\,\Delta_{3 \to 2}} =\sqrt{2 \times 190.5}= 19.52
h_{4 \to 3} = 7.19
h_{2 \to 1} = 24.61
W_{\text{Ward}} = 253.8
T = 747
\Delta is the rise in the within-cluster sum of squares a merge causes, \Delta_{AB} = \frac{n_A n_B}{n_A + n_B}\lVert \bar{\mathbf{z}}_A - \bar{\mathbf{z}}_B \rVert^2 for groups A and B, where \bar{\mathbf{z}}_A is group A's center (its mean z-score on each scale) and \lVert \bar{\mathbf{z}}_A - \bar{\mathbf{z}}_B \rVert^2 is the squared distance between the two centers (step 2's distance, without the square root); the tree draws it at height h = \sqrt{2\Delta}. Going from four clusters to three costs a height of 7.19, but going from three to two jumps to 19.52: 19.52² ÷ 2 = 190.5, which would lift the within-cluster sum of squares from 253.8 to 444.3. The tree says three.
-
4. Let Each Student Move to the Nearest Center
Ward's merges can't be undone, so a student placed early stays put even if a later center suits them better. k-means (MacQueen, 1967; here Lloyd's version, Lloyd, 1982; reviewed by Steinley, 2006) fixes that: start from the three Ward centers, move every student to the nearest center, recompute the centers, and repeat until no one moves.
W = \sum_{c=1}^{k} \sum_{i \in c} \lVert \mathbf{z}_i - \bar{\mathbf{z}}_c \rVert^2 =253.75 \;\rightarrow\; 242.73= 242.73
\text{moved} = 14
1 - W/T = .675
1 - W/T \text{ (shuffled, median)} = .43
1 - W/T \text{ (one normal cloud, median)} = .50
W adds up every student's squared distance from their cluster's center \bar{\mathbf{z}}_c. Starting from Ward's three clusters, 14 students ended up with a nearer center and W fell from 253.75 to 242.73; by the third pass no one moved. 1 − 242.73 ÷ 747 = .675 of the variation now lies between the clusters.
-
5. Describe Each Cluster by Its Average Profile
A cluster's center is just its members' mean on each scale. Read the three means together as a profile, in raw units to see what they mean on the questionnaire and in z-scores to see how far from average they are.
\bar{x}_{cv} = \dfrac{1}{n_c} \sum_{i \in c} x_{iv} =\dfrac{556.11}{99}= 5.62
\bar{z}_{\text{int}} = 0.93
\bar{z}_{\text{ext}}^{(2)} = 1.12
\bar{z}_{\text{amot}}^{(3)} = 1.32
n_1 = 99
n_2 = 89
n_3 = 62
\bar{x}_{cv} is the average raw score on scale v of the n_c = 99 students in the first cluster: their intrinsic-motivation scores add to 556.11, so 556.11 ÷ 99 = 5.62 on the 1-to-7 scale. The same average taken over z-scores, \bar{z}_{cv}, puts the center in SDs: 0.93 above average on intrinsic motivation, 0.67 and 0.75 below on the other two. We call them intrinsically driven; the name is our reading of the profile.
-
6. Check How Well One Student Fits Their Cluster
A student is well placed if they're much closer to their own cluster than to any other. The silhouette width compares the two distances for each student, on a scale from −1 to 1.
s_i = \dfrac{b_i - a_i}{\max(a_i,\, b_i)} =\dfrac{1.665 - 1.489}{1.665}= .11
a_1 = 1.489
b_1 = 1.665
d(1, \text{intrinsic}) = 2.199
a_i is student 1's average distance to the other 61 members of the amotivated cluster, 1.489; b_i is their average distance to the nearest other cluster, the extrinsically driven one, 1.665. (1.665 − 1.489) ÷ 1.665 = .11: student 1 is only slightly closer to their own cluster and sits near the border.
-
7. Average the Fit over Everyone and Compare Other Numbers of Clusters
The average silhouette width summarizes a whole solution. Computing it for two to six clusters, each its own Ward-plus-k-means solution, shows which number separates the students best; running the same procedure on shuffled data shows what no profiles at all would give.
\bar{s} = \dfrac{1}{n}\sum_i s_i =k = 2{:}\ .39,\quad k = 3{:}\ .45,\quad k = 4{:}\ .34= .45
\bar{s}_{k=2} = .39
\bar{s}_{\text{shuffled}} = .27
\max \bar{s}_{\text{shuffled}} = .30
\bar{s}_{\text{normal cloud}} = .28
\max \bar{s}_{\text{normal cloud}} = .31
\bar{s} averages the 250 students' s_i. Three clusters give .45, the highest of any k from 2 to 6 (two give .39, four .34). The same steps on 50 data sets with each scale shuffled separately, same scores but no profiles, give a median of .27 for three clusters and never more than .30. Shuffling also removes the correlations between the scales, which makes it a lenient baseline; 50 samples from one normal cloud with the scales' correlations and no subgroups give a median of .28, never more than .31.
-
8. Check the Clusters against Something They Weren't Built From
Differences on the three motivation scales are guaranteed, since the clustering was built to find them. A fair check uses a variable the clustering never saw, here weekly study hours.
\eta^2 = \dfrac{SS_{\text{between}}}{SS_{\text{between}} + SS_{\text{within}}} =\dfrac{989.2}{989.2 + 3101.5}= .24
\bar{h}_1 = 11.10 hours
\bar{h}_2 = 8.24 hours
\bar{h}_3 = 6.14 hours
SS_{\text{between}} = 989.2 is how far the three clusters' mean study hours (11.10, 8.24 and 6.14) sit from the overall 8.85, counted once per student; SS_{\text{within}} = 3101.5 is how much students vary around their own cluster's mean. 989.2 ÷ 4090.8 = .24.
-
9. See Whether the Same Profiles Come Back in Each Half
Clusters worth naming should reappear in new data. Split the students in two (here the first and last 125 rows of the file; a random split is better), cluster each half on its own with the same Ward-plus-k-means steps on the whole sample's z-scores, then ask whether the first half's centers sort the second half's students the way the second half's own clustering did.
\text{agreement} = \dfrac{\#\{\text{same cluster}\}}{n_{\text{half}}} =\dfrac{122}{125}\text{same} = 122
\text{agreement} = .976
n_{\text{half}} is the 125 students in the second half. Placed by the nearest of the first half's three centers, 122 of them land in the same profile as their own half's clustering gave them: 122 ÷ 125 = .976. Clusters in each half are matched by profile (ordered by their intrinsic-motivation center). The result depends a little on the split: odd versus even rows gives 119 of 125 (95.2%). Corrected for chance agreement, the adjusted Rand index for this split is .93 (1 is perfect agreement, 0 is what chance gives).
Run It in Software
The code below reads the running example's data from data.csv; save it in the same folder you run the code from.
SPSS (version 30, as documented by IBM)
SPSS runs the two stages as two procedures and computes no silhouette, so use R or Python (below) to compare numbers of clusters.
- Standardize: Analyze → Descriptive Statistics → Descriptives, move the three scales in, check Save standardized values as variables. SPSS adds Zintrinsic, Zextrinsic and Zamotivation.
- Ward's tree: Analyze → Classify → Hierarchical Cluster. Move the three z-score variables into Variables. Under Method, choose Ward's method with Squared Euclidean distance; under Plots, check Dendrogram; under Save, save membership for a single solution of 3 clusters (SPSS adds CLU3_1).
- Ward's centers: Analyze → Compare Means → Means, with the three z-scores as dependent variables and CLU3_1 as the independent variable. These are the starting centers for k-means.
- k-means: the simplest route is to paste the syntax below (Analyze → Classify → K-Means Cluster would need the centers saved as a data file first), with Ward's centers from step 3 typed into INITIAL, one cluster at a time. MXITER(100) with CONVERGE(0) iterates until no center moves; KMEANS(NOUPDATE) recomputes the centers once per pass, as this page does.
Or paste this syntax:
DESCRIPTIVES VARIABLES=intrinsic extrinsic amotivation /SAVE.
CLUSTER Zintrinsic Zextrinsic Zamotivation
/METHOD WARD
/MEASURE SEUCLID
/PRINT SCHEDULE
/PLOT DENDROGRAM
/SAVE CLUSTER(3).
MEANS TABLES=Zintrinsic Zextrinsic Zamotivation BY CLU3_1.
QUICK CLUSTER Zintrinsic Zextrinsic Zamotivation
/CRITERIA=CLUSTER(3) MXITER(100) CONVERGE(0)
/INITIAL=( .8420 -.6368 -.7467
-.2279 1.2699 -.0862
-1.0303 -.4297 1.2313)
/METHOD=KMEANS(NOUPDATE)
/PRINT INITIAL ANOVA
/SAVE CLUSTER.
Reading the Output
Read the Agglomeration Schedule for a big jump in the coefficients near the end, then Final Cluster Centers, then Number of Cases in each Cluster.
Ward's three clusters have 105, 76 and 69 students and the starting centers in the INITIAL line (the Means table, rounded). SPSS's agglomeration coefficients are on its own scale, not R's heights; what matters is where they jump.
Final Cluster Centers (z-scores)
| 1 | 2 | 3 | |
|---|---|---|---|
| Zintrinsic | .93 | −.26 | −1.10 |
| Zextrinsic | −.67 | 1.12 | −.52 |
| Zamotivation | −.75 | −.09 | 1.32 |
Number of Cases in each Cluster: 99, 89 and 62. The clusters are numbered in the order of the INITIAL centers; name each from its profile. CLU3_1's numbering for Ward's clusters may not match the order shown here, so type the centers into INITIAL in whatever order your Means table shows. Leave the ANOVA table's F and p aside: the Command Syntax Reference calls these tests “descriptive only,” since cases are assigned to clusters to maximize those very differences.
Output laid out from this page's computed results, not captured from a live run; labels and layout may differ slightly in your version.
R
library(cluster)
motivation <- read.csv("data.csv")
z <- scale(motivation[, c("intrinsic", "extrinsic", "amotivation")])
# Ward's method, then the heights of the last four merges
tree <- hclust(dist(z), method = "ward.D2")
round(tail(tree$height, 4), 2)
plot(tree, labels = FALSE) # the dendrogram
# Ward's tree cut at k, then k-means from Ward's centers
ward_kmeans <- function(z, k) {
start <- aggregate(z, list(cutree(hclust(dist(z), method = "ward.D2"), k)), mean)[, -1]
kmeans(z, centers = start, algorithm = "Lloyd", iter.max = 100)
}
avg_sil <- function(z, k) summary(silhouette(ward_kmeans(z, k)$cluster, dist(z)))$avg.width
# Silhouette for k = 2 to 6
round(sapply(2:6, function(k) avg_sil(z, k)), 3)
# The three-cluster solution
fit <- ward_kmeans(z, 3)
fit$size
round(fit$centers, 2)
round(fit$betweenss / fit$totss, 3)
aggregate(motivation[, c("intrinsic", "extrinsic", "amotivation", "study_hours")],
list(cluster = fit$cluster), function(v) round(mean(v), 2))
summary(silhouette(fit$cluster, dist(z)))
# Structureless data: each scale shuffled on its own, 50 times
set.seed(2026)
null <- replicate(50, avg_sil(apply(z, 2, sample), 3))
round(c(median = median(null), max = max(null)), 3)
# Split half: rows 1-125 and 126-250, each clustered on its own; place the second
# half by the first half's centers and count agreements (labels matched by profile)
first <- ward_kmeans(z[1:125, ], 3)
second <- ward_kmeans(z[126:250, ], 3)
placed <- apply(z[126:250, ], 1, function(x) which.min(colSums((t(first$centers) - x)^2)))
sum(apply(table(placed, second$cluster), 1, max))
[1] 6.78 7.19 19.52 24.61
[1] 0.394 0.455 0.344 0.288 0.256
[1] 62 99 89
intrinsic extrinsic amotivation
1 -1.10 -0.52 1.32
2 0.93 -0.67 -0.75
3 -0.26 1.12 -0.09
[1] 0.675
cluster intrinsic extrinsic amotivation study_hours
1 1 2.91 3.44 4.21 6.14
2 2 5.62 3.25 1.61 11.10
3 3 4.03 5.52 2.44 8.24
Silhouette of 250 units in 3 clusters from silhouette.default(x = fit$cluster, dist = dist(z)) :
Cluster sizes and average silhouette widths:
62 99 89
0.4137407 0.5454208 0.3830182
Individual silhouette widths:
Min. 1st Qu. Median Mean 3rd Qu. Max.
-0.04493 0.37289 0.50267 0.45495 0.57179 0.68554
median max
0.271 0.292
[1] 122
The silhouettes come from the cluster package (Maechler et al., 2026). ward.D2 is the version of Ward's method that works on unsquared distances, the same criterion as SPSS's Ward with squared Euclidean distance (Murtagh & Legendre, 2014). R numbers the clusters in the order cutree found them: 1 is the amotivated cluster, 2 the intrinsically driven one and 3 the extrinsically driven one. algorithm = "Lloyd" matches this page; R's default, Hartigan and Wong's algorithm, gives the same three clusters here but slightly different solutions for four to six (silhouettes .347, .305 and .257), which doesn't change the choice of three. The smallest silhouette, −.04, belongs to one of two students who fit a neighboring cluster slightly better. The shuffled-data median (.271, maximum .292) differs a little from the page's .27 and .30 because R's random shuffles aren't the page's; any 50 shuffles give about the same answer.
Output from a real run: R 4.6.1 (cluster 2.1.8.2), run 2026-09-29.
Python
import pandas as pd
from scipy.cluster.hierarchy import linkage, fcluster
from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score
motivation = pd.read_csv("data.csv")
cols = ["intrinsic", "extrinsic", "amotivation"]
z = (motivation[cols] - motivation[cols].mean()) / motivation[cols].std() # z-scores
tree = linkage(z, method="ward") # Ward's method
print(tree[-4:, 2].round(2)) # heights of the last four merges
for k in range(2, 7):
ward = fcluster(tree, k, criterion="maxclust")
start = z.groupby(ward).mean().values
km = KMeans(k, init=start, n_init=1, algorithm="lloyd").fit(z)
print(k, round(silhouette_score(z, km.labels_), 3))
ward = fcluster(tree, 3, criterion="maxclust")
km = KMeans(3, init=z.groupby(ward).mean().values, n_init=1, algorithm="lloyd").fit(z)
print(pd.Series(km.labels_).value_counts().sort_index().tolist())
print(motivation.groupby(km.labels_)[cols + ["study_hours"]].mean().round(2))
[ 6.78 7.19 19.52 24.61]
2 0.394
3 0.455
4 0.344
5 0.288
6 0.256
[99, 62, 89]
intrinsic extrinsic amotivation study_hours
0 5.62 3.25 1.61 11.10
1 2.91 3.44 4.21 6.14
2 4.03 5.52 2.44 8.24
scipy's ward linkage gives the same heights as R's ward.D2. Pass the Ward centers as init with n_init=1; without them, scikit-learn starts from random centers (k-means++) and the answer can depend on the random seed.
Output from a real run: Python 3.9.6 (scipy 1.13.1, scikit-learn 1.6.1, pandas 2.3.3), run 2026-09-29.
Impact
Effect Size
Cluster analysis has no single effect size. Three numbers together say how strong the grouping is: the average silhouette width, how clearly students sit in their own cluster; the share of the variation that lies between clusters; and, for meaning, how far apart the cluster centers are in standard deviations.
68% of the variation in the three motivation scores lies between the profiles, and the profiles sit more than a standard deviation apart on the scale that defines each: on intrinsic motivation, the intrinsically driven cluster is 1.19 SD above the extrinsically driven one and 2.03 above the amotivated one; on amotivation, the amotivated cluster is 1.41 SD above the extrinsically driven one. But the silhouette of .45 says the profiles overlap: many students sit between two.
The share between clusters is guaranteed to be large, because the clustering chose the groups to make it so; compare it with structureless data, not with zero: about .43 with each scale shuffled, and .50 for a single normal cloud with the scales' correlations (medians of 50 data sets each). Whether the profiles matter is a question about students: here, a gap of about five study hours a week between the intrinsically driven and amotivated clusters.
Benchmarks Average Silhouette Width at a Glance
Uncertainty
Cluster analysis isn't a significance test. It sorts people and describes the groups; it doesn't ask whether they could be chance, and there is no p. The checks that take the place of a test are comparisons and replications:
- Against no structure. Shuffling each variable separately keeps every score but destroys the profiles. A solution worth reporting should separate people clearly better than the same procedure does on many shuffled data sets. Shuffling also removes the correlations between the variables, so it's a lenient baseline; a stricter one simulates a single normal cloud with the same correlations. The gap statistic formalizes this idea by comparing the within-cluster spread with that of reference data that have no clusters (Tibshirani et al., 2001).
- Against new data. Cluster part of the sample, or a second sample, and see whether the same profiles come back.
- Against outside variables. Compare the clusters on something they weren't built from, and ask whether they predict it better than the continuous scores they came from.
Three clusters gave an average silhouette of .45. Across 50 shuffles, three clusters gave a median of .27 and never more than .30; 50 normal clouds with the scales' correlations gave a median of .28 and never more than .31. The profiles came back in each half of the sample (122 of 125 students placed the same way), and they differed on study hours, which the clustering never saw (η² = .24). They also predicted study hours better than the three scales did as continuous predictors (24% of the variation against 20%).
Don't run an ANOVA or MANOVA on the clustering variables to show the clusters differ. The clustering chose the groups to make those differences as large as possible, so the p-values are meaningless. A test on an outside variable, like study hours, is legitimate.
Precision and Sample Size
Power is the chance that a study detects an effect that's really there. For cluster analysis, the effect is groups that really exist, and detecting them depends far more on how well separated they are than on how many people you have. In simulations, Dalmaijer et al. (2022) found that about 20 to 30 people per expected subgroup was enough when the groups' centers were far apart (Δ = 4, where Δ is the distance between two groups' centers with every variable in within-group SDs; the closest two of our simulated profiles are about 3.3 apart), that adding people beyond that didn't help, and that overlapping groups often went undetected however large the sample. For partly overlapping groups they recommend fuzzy clustering or mixture models (such as latent profile analysis), which detected them more often.
Our three profiles overlap: an average silhouette of .45 is below the .50 that Dalmaijer et al. treated as detecting clusters, even though we simulated three real groups. With 62 to 99 students per cluster, sample size isn't what limits us; separation is. Adding a fourth, well-chosen motivation scale that differs between profiles would help more than doubling the sample.
Plan for separation: choose variables on which you expect the groups to differ strongly, aim for at least 20 to 30 people in the smallest group you expect, and set aside a second sample (or half of this one) to replicate the solution. There's no calculator for this test.
Other Info
Follow-Up and Post Hoc Tests
None. This page estimates rather than tests, so there are no follow-up comparisons to run.
References
-
Ward, J. H., Jr. (1963). Hierarchical grouping to optimize an objective function. Journal of the American Statistical Association, 58(301), 236–244.
https://doi.org/10.1080/01621459.1963.10500845
“By repeating this process until only one group remains, the complete hierarchical structure and a quantitative estimate of the loss associated with each stage in the grouping can be obtained.” (Abstract, p. 236)
- MacQueen, J. (1967). Some methods for classification and analysis of multivariate observations. In L. M. Le Cam & J. Neyman (Eds.), Proceedings of the Fifth Berkeley Symposium on Mathematical Statistics and Probability (Vol. 1, pp. 281–297). University of California Press. https://projecteuclid.org/proceedings/berkeley-symposium-on-mathematical-statistics-and-probability/Proceedings-of-the-Fifth-Berkeley-Symposium-on-Mathematical-Statistics-and/Chapter/Some-methods-for-classification-and-analysis-of-multivariate-observations/bsmsp/1200512992
- Lloyd, S. P. (1982). Least squares quantization in PCM. IEEE Transactions on Information Theory, 28(2), 129–137. https://doi.org/10.1109/TIT.1982.1056489
- Murtagh, F., & Legendre, P. (2014). Ward's hierarchical agglomerative clustering method: Which algorithms implement Ward's criterion? Journal of Classification, 31(3), 274–295. https://doi.org/10.1007/s00357-014-9161-z
- Rousseeuw, P. J. (1987). Silhouettes: A graphical aid to the interpretation and validation of cluster analysis. Journal of Computational and Applied Mathematics, 20, 53–65. https://doi.org/10.1016/0377-0427(87)90125-7
- Kaufman, L., & Rousseeuw, P. J. (1990). Finding groups in data: An introduction to cluster analysis. Wiley. https://doi.org/10.1002/9780470316801
-
Struyf, A., Hubert, M., & Rousseeuw, P. J. (1997). Clustering in an object-oriented environment. Journal of Statistical Software, 1(4), 1–30.
https://doi.org/10.18637/jss.v001.i04
“The user can then select that value of k yielding the highest average silhouette width, over all k, which we call the silhouette coefficient.” (p. 10)
“Experience has led to the subjective interpretation of the silhouette coefficient (SC) as listed in Table 2. This interpretation does not depend on the number of objects.” (p. 10)
“The structure is weak and could be artificial, try additional methods.” (p. 10, Table 2)
-
Steinley, D. (2006). K-means clustering: A half-century synthesis. British Journal of Mathematical and Statistical Psychology, 59(1), 1–34.
https://doi.org/10.1348/000711005X48266
“different methods of choosing the number of clusters and initialization, variable preprocessing, and data reduction schemes are discussed” (Abstract)
-
Tibshirani, R., Walther, G., & Hastie, T. (2001). Estimating the number of clusters in a data set via the gap statistic. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 63(2), 411–423.
https://doi.org/10.1111/1467-9868.00293
“The technique uses the output of any clustering algorithm (e.g. K-means or hierarchical), comparing the change in within-cluster dispersion with that expected under an appropriate reference null distribution.” (Abstract)
-
Spurk, D., Hirschi, A., Wang, M., Valero, D., & Kauffeld, S. (2020). Latent profile analysis: A review and “how to” guide of its application within vocational behavior research. Journal of Vocational Behavior, 120, Article 103445.
https://doi.org/10.1016/j.jvb.2020.103445
“Compared to traditional, non-latent clustering methods (e.g., k-means clustering, hierarchical clustering), LPA treats profile membership as an unobserved categorical variable, where its value indicates which profile an individual belongs to with a certain degree of probability.” (Section 1, A brief introduction to latent profile analysis, p. 2)
-
Dalmaijer, E. S., Nord, C. L., & Astle, D. E. (2022). Statistical power for cluster analysis. BMC Bioinformatics, 23, Article 205.
https://doi.org/10.1186/s12859-022-04675-1
“Overall, we recommend that researchers (1) only apply cluster analysis when large subgroup separation is expected, (2) aim for sample sizes of N = 20 to N = 30 per expected subgroup” (Abstract, Conclusions)
-
Clatworthy, J., Buick, D., Hankins, M., Weinman, J., & Horne, R. (2005). The use and reporting of cluster analysis in health psychology: A review. British Journal of Health Psychology, 10(3), 329–358.
https://doi.org/10.1348/135910705X25697
“Details of the similarity measure and the computer program used were most frequently omitted.” (Abstract, Results)
-
Vansteenkiste, M., Sierens, E., Soenens, B., Luyckx, K., & Lens, W. (2009). Motivational profiles from a self-determination perspective: The quality of motivation matters. Journal of Educational Psychology, 101(3), 671–688.
https://doi.org/10.1037/a0015083
“Both in high school students (Study 1) and college students (Study 2), a cluster analysis revealed 4 motivational profiles” (Abstract)
- Ratelle, C. F., Guay, F., Vallerand, R. J., Larose, S., & Senécal, C. (2007). Autonomous, controlled, and amotivated types of academic motivation: A person-oriented analysis. Journal of Educational Psychology, 99(4), 734–746. https://doi.org/10.1037/0022-0663.99.4.734
-
Maechler, M., Rousseeuw, P., Struyf, A., Hubert, M., & Hornik, K. (2026). cluster: Cluster analysis basics and extensions (R package version 2.1.8.2) [Computer software].
https://CRAN.R-project.org/package=cluster
“Observations with a large s(i) (almost 1) are very well clustered, a small s(i) (around 0) means that the observation lies between two clusters, and observations with a negative s(i) are probably placed in the wrong cluster.” (silhouette help page, Details)
-
Lakens, D. (2013). Calculating and reporting effect sizes to facilitate cumulative science: A practical primer for t-tests and ANOVAs. Frontiers in Psychology, 4, 863.
https://doi.org/10.3389/fpsyg.2013.00863
“Cohen (1988) has provided benchmarks to define small (η2 = 0.01), medium (η2 = 0.06), and large (η2 = 0.14) effects.” (Eta-squared in between and within-subjects comparisons)
Spot an error? Something still confusing? Tell us at support@statsforpsychology.com.