Why Missing Predictors Change a Distance Analysis
A distance between two observations summarizes how different they are across the predictors being compared. If a predictor is missing for one observation, its contribution to that comparison is unknown. The analyst must decide whether to omit affected observations, fill in missing values, or calculate each distance using only predictors observed for that pair. These choices can change both the number of observations in the analysis and the similarities represented in a distance matrix.
The methods below assume that the selected predictors are numeric and have already been prepared for distance calculation. In particular, when Euclidean distance is used, predictor scales should be appropriate to the analysis; missing-value handling does not correct a poor choice of scale.
None of these methods is automatically best. Complete-case analysis discards information and may change which observations remain. Imputation creates values that were not observed. Pairwise handling preserves more observations, but different pairs may be compared on different subsets of predictors. The resulting distances therefore need to be interpreted in light of the method used.
Three Ways to Handle Missing Values
Suppose there are \(p\) selected numeric predictors. Under complete-case analysis, an observation is retained only if all \(p\) values are present. In R, `complete.cases()` can identify such rows, and `na.omit()` can remove rows containing missing values in the variables being analyzed. The retained set is easy to describe, but it may be small. It may also differ systematically from the original set if missingness is associated with observed characteristics.
With imputation, each missing value is replaced before distances are calculated. For example, a predictor's observed mean can be substituted for missing values in that predictor. This produces a complete matrix, but a filled-in value is not an additional observation. Mean imputation can make observations with missing values appear more average on that predictor and can reduce the apparent spread. Other imputation methods make different assumptions; the choice should be specified rather than treated as a neutral data-cleaning step.
For pairwise Euclidean distances, let \(M_{ij}\) be the set of predictors observed for both observations \(i\) and \(j\), and let \(m_{ij}\) be the number of such predictors. A common adjusted distance is
Here \(p\) is the total number of selected predictors. The adjustment scales the observed sum of squared differences to account for predictors not shared by that pair. If there are no shared observed predictors, \(m_{ij}=0\), and this formula does not define a distance. In base R, the Euclidean method of `dist()` uses this type of adjustment when coordinates are missing. Always check the function's documented behavior rather than assuming that missing values are handled as intended.
Why Pairwise Rescaling Is Used
The adjustment has a simple justification under a particular idealized setup. Suppose the \(p\) coordinate-wise squared differences for a pair are viewed as comparable contributions, and the \(m_{ij}\) observed contributions are representative of all \(p\). The mean observed squared difference is their sum divided by \(m_{ij}\). Multiplying that average by \(p\) estimates the total squared difference across all \(p\) coordinates:
Taking the square root gives the adjusted Euclidean distance. This explains the rescaling; it does not guarantee that the estimate is accurate. It is most defensible when the observed coordinates provide a reasonable representation of the unobserved ones. If the missing predictors are systematically different, or a pair shares very few predictors, the adjusted value can be a poor guide to overall similarity. Moreover, different pairs can be compared on different coordinates, so the resulting distances need not behave like ordinary Euclidean distances in one common complete space.
Worked Example: Comparing All Three Methods
Four hypothetical service regions are described by three prepared numeric predictors, \(x_1,x_2,x_3\). Which distances are available under complete-case analysis, mean imputation, and pairwise handling? For pairwise handling, use the rescaling formula above.
| Region | \(x_1\) | \(x_2\) | \(x_3\) |
|---|---|---|---|
| A | 0 | 0 | Missing |
| B | 2 | 0 | 4 |
| C | 0 | Missing | 1 |
| D | 2 | 3 | 2 |
Method 1: complete cases. B and D have values for all three predictors. A is incomplete because \(x_3\) is missing, and C is incomplete because \(x_2\) is missing. Thus, 2 of the 4 regions remain. Their distance is
The method gives one pairwise distance among the retained regions; it gives no distances involving A or C.
Method 2: mean imputation. The observed mean of \(x_1\) is \((0+2+0+2)/4=1\), and \(x_1\) has no missing values. The observed mean of \(x_2\) is \((0+0+3)/3=1\), so replace C's missing \(x_2\) by 1. The observed mean of \(x_3\) is \((4+1+2)/3=7/3\), so replace A's missing \(x_3\) by \(7/3\). In particular, the imputed rows are A \((0,0,7/3)\) and C \((0,1,1)\).
The imputed distance between A and C is
All four regions now have complete rows, but this distance depends on the imputed values. It is not a distance calculated solely from observed A–C measurements.
Method 3: pairwise handling. For A and C, the only shared predictor is \(x_1\). Their values match on that predictor, so the observed sum of squared differences is zero. With \(p=3\) and \(m_{AC}=1\), the adjusted distance is \(\sqrt{(3/1)\times 0}=0\). This zero does not establish that the regions are alike overall: the pair shares just one predictor. For a comparison with more observed difference, A and D share \(x_1\) and \(x_2\), with squared differences \(0\) and \(9\). Thus
B and D share all three predictors, so their pairwise distance is \(\sqrt{13}\approx3.606\), the same as in the complete-case calculation. The key check is that A and C share only the first predictor; the missing entries do not count as shared coordinates. The three methods retain or compare different information, so their resulting distance matrices are not interchangeable.
Worked Example: The Rescaling Trap
Two hypothetical facilities have records on four standardized predictors. The differences on their two shared observed predictors are \(1\) and \(-2\); the other two predictors are not observed for both facilities. Calculate the adjusted pairwise Euclidean distance and identify the error in omitting the adjustment.
There are \(p=4\) selected predictors and \(m=2\) shared observed predictors. The sum of squared observed differences is
Applying the rescaling gives
The common mistake is to report \(\sqrt{5}\approx2.236\), which is the unadjusted distance using only the two shared coordinates. The adjusted answer is \(\sqrt{10}\), because the specified method multiplies the squared sum by \(p/m=2\) before taking the square root. As a check, if all four predictors were shared, the factor would be \(4/4=1\), and no adjustment would be needed.
Worked Example: Deciding What the R Workflow Retains
A hypothetical analyst has two prepared numeric measures for five districts. The goal is to describe their similarity, not to estimate a predictive model. The analyst wants to compare the consequences of complete cases, column-mean imputation, and pairwise distances.
| District | Measure 1 | Measure 2 |
|---|---|---|
| U | 0 | 1 |
| V | 2 | Missing |
| W | 1 | 3 |
| X | Missing | 2 |
| Y | 3 | 4 |
Complete cases. U, W, and Y have both measures observed, so 3 of 5 districts remain. The distance between U and W is
V and X are excluded from a complete-case distance matrix based on these two measures.
Mean imputation. The observed mean of Measure 1 is \((0+2+1+3)/4=1.5\). The observed mean of Measure 2 is \((1+3+2+4)/4=2.5\). Thus V becomes \((2,2.5)\) and X becomes \((1.5,2)\). Their imputed distance is
This distance is fully calculable after imputation, but both coordinates include imputed values. It should not be described as a comparison based entirely on observed measurements.
Pairwise handling. U and V share only Measure 1, with a difference of \(0-2=-2\). Here \(p=2\), \(m=1\), and
As a check on the adjustment, U and W share both measures, so their pairwise distance remains \(\sqrt{5}\approx2.236\). Before using an R distance matrix, the analyst should identify which rows each method retains, confirm the missing-value behavior, and record whether imputation or pairwise adjustment was used. The numerical result alone does not reveal those choices.