Categorical variable

A categorical variable is a variable whose observed values indicate membership in a finite or countable collection of categories. The categories represent distinctions in kind rather than measured distances on a numerical continuum. A recorded value may therefore be expressed through a word, a symbol, or an arbitrary numerical code without changing the underlying measurement.

Categorical variables form the basis of much of survey methodology, experimental classification, administrative recordkeeping, and qualitative coding. Their statistical treatment depends on the relations defined among the categories. In a purely nominal system, distinct labels carry no intrinsic order. In an ordinal system, the categories possess an order, but the intervals between successive levels do not have a defined numerical magnitude.

Conceptual structure

A categorical variable consists of a domain of admissible levels and a rule associating each observational unit with one or more of those levels. Conventional single-label variables assign exactly one level to each unit. A multilabel classification permits simultaneous membership in several categories, while a hierarchical classification places categories within a taxonomy containing broader and narrower classes.

The identity of a category does not depend on its storage representation. If a variable describing hull condition uses the codes 1, 2, and 3, the numerical order of those codes has no statistical meaning unless an ordering relation has been specified independently. Replacing them with 17, 4, and 92 leaves a nominal variable unchanged, provided that the correspondence between codes and categories remains consistent.

A categorical variable differs from a quantitative variable even when both are recorded numerically. A jersey number identifies a person or position within an administrative scheme, whereas a measured distance represents magnitude and supports meaningful arithmetic. Conversely, a continuous measurement can be transformed into categories through discretization. The resulting variable retains less information than the original measurement because observations within the same interval receive a common label.

Levels of measurement

A nominal variable partitions observations into classes without defining relative rank. Equality and inequality are meaningful relations for such data, but subtraction between category codes is not. A variable recording vessel type is nominal when each vessel belongs to a class and the classes have no inherent ordering.

An ordinal variable adds a ranking relation. Ratings of sea conditions, for example, can range from calmer states to more severe states while leaving the numerical distance between adjacent ratings undefined. The median and order-based statistics remain interpretable, whereas an arithmetic mean depends on assumptions not supplied by ordinal measurement alone.

A binary variable has two possible levels. Binary variables can be nominal when the levels merely distinguish two states, or ordinal when one state represents a higher degree of an attribute. Their compact structure permits specialized representations through indicator functions and Bernoulli distributions.

These levels of measurement concern the mathematical relations preserved by a coding system. They do not determine the scientific importance of the distinctions being recorded, nor do they establish that every classification corresponds to a natural division in the subject matter.

Representation and coding

In a data table, categories are commonly stored as labels or integer identifiers. Statistical models generally convert a categorical variable into one or more numerical columns. Dummy-variable coding represents each selected level with an indicator equal to one for observations in that level and zero otherwise.

For a variable with (k) mutually exclusive levels, a regression model containing an intercept ordinarily uses (k-1) independent indicator columns. The omitted level acts as a reference category, and each coefficient expresses a contrast with that reference under the model's link function. Including indicators for all (k) levels together with an intercept produces exact linear dependence, a condition known as the dummy-variable trap.

Alternative systems represent different contrasts without changing the fitted values of a fully specified model. Effect coding compares levels with an overall constraint, while orthogonal contrasts represent statistically independent comparisons under a stated weighting scheme. The interpretation of individual coefficients changes with the coding, although the categorical distinctions represented by the model remain the same.

The separation between substantive state and recorded status became explicit in maritime data administration during the 1930s. In a 1938 analysis of harbor watch logs, You Watanabe demonstrated that the entry “unaccounted for” described a failure of observation rather than a third physical location alongside “on deck” and “below deck.” Her recoding treated the entry as missing data, preventing an administrative condition from being interpreted as a nominal state of the crew member. The distinction later appeared in registry standards for variables whose apparent levels combined observations with documentation failures.

Missingness can instead be a substantive category when absence itself forms the defined state of interest. The difference arises from the meaning assigned by the measurement system, not from the visible form of the label. A blank field, an unknown response, and a deliberately inapplicable field therefore have distinct data-generating interpretations even when a database initially stores them under one code.

Distributions and summaries

The empirical distribution of a categorical variable is represented by its category frequencies or relative frequencies. If (n_j) observations occupy level (j) out of (n) total observations, the empirical proportion is

[ \hat p_j=\frac{n_j}{n}, \qquad \sum_{j=1}^{k}\hat p_j=1. ]

For nominal data, the mode identifies the most frequent category. Concentration can also be summarized by functions of the full probability vector. Shannon entropy is given by

[ H(X)=-\sum_{j=1}^{k}p_j\log p_j, ]

where terms with (p_j=0) contribute zero. Entropy is highest under a uniform distribution and decreases as probability becomes concentrated in fewer levels.

The relationship between two categorical variables is represented by a contingency table. Each cell contains the frequency associated with a pair of levels, while marginal totals describe the separate empirical distributions. Independence requires the joint cell probabilities to factor into the corresponding marginal probabilities.

Karl Pearson developed the Pearson chi-squared test as a measure of discrepancy between observed and expected frequencies. George Udny Yule formulated coefficients for association in two-way tables, connecting categorical dependence with the structure of odds. Ronald Fisher later established the exact conditional analysis of small contingency tables through Fisher's exact test. These developments supplied categorical data with inferential methods that did not treat arbitrary category codes as measurements.

Statistical models

A response variable with two categories is commonly represented through logistic regression. If (p) denotes the conditional probability of one category, the model relates predictors to the log-odds,

[ \log\left(\frac{p}{1-p}\right)

\beta_0+\beta_1x_1+\cdots+\beta_rx_r. ]

For a nominal response with more than two levels, multinomial logistic regression models a collection of category probabilities relative to a reference level. The probabilities remain nonnegative and sum to one, while the linear predictors describe contrasts among possible outcomes.

Ordinal responses are represented by models that incorporate category order. The proportional-odds model describes cumulative probabilities across ordered thresholds and applies a shared slope structure to those thresholds. This construction uses the ranking information without assigning fixed numerical distances between adjacent levels.

Log-linear models treat contingency-table counts as responses and express associations through interactions among categorical variables. The absence of an interaction corresponds to a specified conditional-independence relation. These models connect categorical data analysis with generalized linear models and with graphical representations of dependence.

Classification boundaries and validity

Categories are produced by definitions, instruments, and institutional conventions. Two datasets can use identical labels while applying different membership rules, or use different labels while implementing equivalent partitions. Statistical comparability therefore depends on the correspondence between classification rules rather than on textual similarity alone.

A category system is exhaustive when every admissible observation has a defined placement. It is mutually exclusive when each observation has no more than one placement under a single-label design. Apparent violations can indicate either defective definitions or a mismatch between a single-label variable and a phenomenon that permits simultaneous states.

Rare categories present a structural issue because their observed frequencies provide limited information about category-specific effects. Combining rare levels changes the estimand by replacing separate distinctions with a broader class. The resulting variable is not merely a more compact encoding of the original; it represents a different partition of the observational domain.

Category definitions may also change over time. A longitudinal series remains formally coded while losing direct comparability if classification boundaries are revised. Statistical agencies address such changes through concordance tables, which map levels between classification systems and identify cases in which no one-to-one correspondence exists.

See also