Why Binary and Ordinal Features Need a Separate Decision
Omics blocks may contain more than continuous measurements. A feature can indicate whether a molecule was detected, record a binary assay call, or encode an ordered category such as an ordinal severity grade. These values can be included in a mixed-type block, but scaling them is not automatic: the numerical operation may implicitly assign weights or meanings that the encoding did not originally have.
The earlier material on within-block centering and feature scaling and the comparison of standard, Pareto, and robust scaling establish the general role of scale parameters. Here the key question is narrower: when is it reasonable to treat a binary or ordinal feature as numeric, and when is it better to retain an indicator representation? Standardization itself does not require normality. The important assumptions concern what the codes mean, whether the feature varies, and whether the resulting influence is appropriate for the analysis.
If the feature is observed for all \(n\) samples, standardization gives it sample mean zero and sample variance one. This is a numerical rescaling, not a claim that the feature is continuous, normally distributed, or measured on an interval scale. In particular, coding ordered categories as 1, 2, 3, and so on treats the numerical gaps between adjacent categories as equal. That assumption needs subject-matter justification.
Binary Features: Prevalence Determines the Standardized Values
For a binary feature \(x_i\in\{0,1\}\), let \(\hat{p}\) be the observed proportion of 1s. Its mean is \(\bar{x}=\hat{p}\). The sample standard deviation depends directly on prevalence, so standardizing the feature does not give the same numerical transformation across different prevalence levels.
The formula follows because \(x_i^2=x_i\) for binary values. Thus \(\sum_i x_i^2=n\hat{p}\), and the sum of squared deviations is \(n\hat{p}-n\hat{p}^2=n\hat{p}(1-\hat{p})\). Dividing by \(n-1\) gives the stated sample variance. When the 1 category is rare, its standardized value can be large in magnitude; this may give a rare call substantial influence in analyses sensitive to feature scale. At \(\hat{p}=0\) or \(1\), \(s=0\), so standardization is undefined.
Worked Example: Standardizing a Binary Detection Call
Suppose a hypothetical assay records detection as 1 and non-detection as 0 for eight samples. The observed values are \(1,1,0,0,0,0,0,0\). Assume the call is consistently defined across samples and there are no missing values.
There are two detections, so \(\hat{p}=2/8=0.25\) and \(\bar{x}=0.25\). The sample variance and standard deviation are
Each 1 receives \(z=(1-0.25)/0.46291=1.620\), while each 0 receives \(z=(0-0.25)/0.46291=-0.5401\). These values are in standard-deviation units of this feature, not in assay units. Standardization preserves which samples have a detection, but the transformed scale reflects the observed prevalence.
It can be reasonable to standardize a binary feature when the analysis expects numerical inputs on comparable sample-variance scales and the resulting weighting is intentional. Retaining 0/1 values is often preferable when those codes are already interpretable, when the feature should have a chosen fixed contribution, or when standardizing a rare indicator would make its positive value disproportionately large. Centering without dividing by \(s\) changes the feature’s origin but not the difference between its two values; whether centering is needed depends on the downstream method.
Worked Example: A Rare Indicator and Its Scaling Consequence
In a hypothetical block, a binary feature is positive in 2 of 100 samples and negative in the other 98. The assay definition is consistent, with no missing values, but the positive category is uncommon.
Here \(\hat{p}=0.02\), so
A positive sample has \(z=(1-0.02)/0.1407=6.965\), and a negative sample has \(z=(0-0.02)/0.1407=-0.1421\). The standardized positive value is large because the feature varies little across the 100 samples, not because the assay produced an unusually high measurement. If a downstream analysis is sensitive to large feature values, this scaling may be undesirable. Retaining the 0/1 indicator, or choosing another encoding based on the scientific aim, avoids that particular rescaling; it does not make the feature more informative or resolve uncertainty in the rare calls.
Ordinal Features: Order Does Not Guarantee Equal Spacing
Ordinal categories have a meaningful ordering, but their category labels do not by themselves define distances. Standardizing successive integer codes is defensible when treating adjacent category changes as comparable is a reasonable working approximation for the analysis. It is not justified merely because the categories can be numbered. If equal spacing is not credible, retain category indicators or use a representation designed around the category structure rather than treating the codes as interval measurements.
Worked Example: Standardizing an Ordinal Rating
Consider six hypothetical samples with ordered ratings \(1,1,2,3,3,4\). The ratings are coded in order, and for this calculation we assume that equal steps between codes are an acceptable approximation. There are no missing ratings.
The sum is 14 and the sum of squares is 40, so \(\bar{x}=14/6=2.3333\). The sample variance and standard deviation are
Using the exact mean \(14/6\) and this standard deviation, the standardized values for ratings 1, 2, 3, and 4 are respectively
Thus the six transformed observations, in their original sample order, are \(-1.101,-1.101,-0.2753,0.5507,0.5507,1.377\). The arithmetic is correct for the chosen codes. Whether this transformation is meaningful still depends on the equal-spacing assumption: if the step from rating 1 to 2 is not comparable to the step from 3 to 4, the standardized values may imply more than the categories support.
Retaining Indicators and Choosing an Encoding
For a binary feature, the 0/1 encoding is already an indicator representation. Standardizing it applies a feature-specific shift and multiplier; it does not create new information. The practical choice is whether the analysis should use that raw binary scale or the sample-standardized scale. For a categorical feature with more than two levels, one-hot encoding creates a separate 0/1 indicator for each category. This represents category membership without assigning numerical gaps between category labels.
One-hot encoding has trade-offs. If all category indicators are included, they sum to one for every complete observation, so they are linearly dependent with an intercept in a linear model. Omitting a reference category avoids that particular redundancy in such models, though the coding then expresses categories relative to the reference. Independently standardizing indicators can also magnify rare categories because each has its own prevalence-dependent standard deviation. Retaining indicators in their 0/1 form avoids that magnification, but their influence still depends on the analysis and the other features.
| Representation | Useful when | Important caution |
|---|---|---|
| Binary 0/1 | The categories have a natural indicator meaning and a fixed unscaled coding is intended. | Its variance may differ substantially from that of continuous features. |
| Standardized binary | A numerical method needs comparable sample variances and this weighting is acceptable. | Rare positive categories can receive large standardized values. |
| Standardized ordinal codes | Order is meaningful and equal spacing is a reasonable approximation. | Integer codes impose spacing that may not be supported by the measurement. |
| One-hot category indicators | Category membership matters, but numeric spacing between category codes is not justified. | Rare levels can be highly variable after standardization; all indicators may be redundant with an intercept. |
The choice is therefore not a universal rule that every feature must have sample variance one. A mixed-type block may intentionally retain binary indicators while standardizing continuous measurements, provided the encoding and relative influence are documented and suitable for the downstream method. Conversely, when using a method whose behavior depends strongly on numeric scale, retaining raw indicators without considering their scale is not automatically neutral.
Assumptions, Diagnostics, and Failure Modes
Before scaling, verify that the coding is consistent across samples, that categories are correctly ordered where appropriate, and that missing values have not been silently treated as a category or as zero. Compute means and standard deviations from the observed values under a clearly stated missing-data rule. If a feature is constant in the fitting data, \(s=0\) and standardization cannot be performed; remove or separately handle it rather than dividing by zero.
For ordinal variables, examine category frequencies and the meaning of adjacent levels. Sparse or empty categories can make an indicator representation unstable, while collapsing categories changes the scientific definition and should not be done solely to obtain more convenient scaling. For binary features, report prevalence as well as the chosen encoding so that unusually large standardized positive values are interpretable.
When an analysis has training and test samples, estimate \(\bar{x}\), \(s\), and any category decisions using the training data, then apply those same values to the test data. Recomputing the parameters on the test set changes the transformation and can leak information into model evaluation. If a test value falls outside the training categories, define its handling in advance; do not silently assign it a numerical score that was never specified.
Confirm which category is coded 0 or 1, verify category order, and identify missing or constant features.
For ordinal codes, decide whether equal gaps are a defensible approximation. For binary features, decide whether prevalence-based standardization is intended.
Use raw indicators, standardized binary values, standardized ordinal scores, or category indicators according to the intended interpretation and analysis.
Inspect category frequencies, resulting means and standard deviations, and any large values caused by rare categories before integrating the block.
A common mistake is to standardize every numeric-looking column and conclude that all features now have equivalent meaning because each has variance one. The correction is that standardization equalizes a sample variance, not the validity of the coding or the scientific importance of a feature. A code of 1 may mean “detected,” while an ordinal code of 1 may mean the lowest category; equal numerical variance does not make those measurements interchangeable. Likewise, leaving all indicators unscaled is a choice, not a guarantee that they will have equal influence.
Check Your Understanding
Answer each question, then compare with the solutions.
- A binary feature is observed in 10 samples and is positive in 5. What are its sample mean and sample standard deviation?
- Why can standardizing a rare binary feature produce a large positive standardized value?
- An ordinal feature has categories “low,” “moderate,” and “high.” What assumption is made by coding them 1, 2, and 3 and standardizing those codes?
- Why might one-hot indicators be preferred to numeric category codes for a nominal feature? Name one caution when using all indicators in a linear model with an intercept.
Solutions. (1) The mean is \(\hat{p}=5/10=0.5\). The sample standard deviation is \(s=\sqrt{(10/9)(0.5)(0.5)}=\sqrt{5/18}=0.5270\). (2) The feature has small sample variance when positives are rare, so dividing the positive value’s deviation from the mean by a small \(s\) yields a large standardized value. (3) It assumes that the ordered categories can reasonably be treated as equally spaced: the low-to-moderate change is treated as the same size as the moderate-to-high change. (4) One-hot indicators represent membership without asserting numerical gaps between labels. If every indicator is included, their sum is one for each complete observation, creating linear dependence with an intercept.