John Aitchison and Compositional Data Analysis (CoDA)

John Aitchison pioneered compositional data analysis (CoDA) in the 1980s, proving that standard statistical methods (like ordinary least squares, Pearson correlation, and PCA) produce spurious results when applied directly to proportions or market shares that sum to a constant.

Because market shares must sum to 100% (or 1), an increase in one brand’s share mathematically forces at least one other brand’s share to drop—even if the underlying sales had no true behavioral relationship. Aitchison solved this by showing that compositional data live on a curved geometry called the Aitchison simplex ($\mathcal{S}^D$), not in standard flat Euclidean space ($\mathbb{R}^D$).


Core Principles of Aitchison Geometry

Mathematical Operations on the Simplex

Let $\mathbf{x} = (x_1, x_2, \dots, x_D) \in \mathcal{S}^D$ and $\mathbf{y} = (y_1, y_2, \dots, y_D) \in \mathcal{S}^D$ be two $D$-part compositions summing to a constant $\kappa$ (typically $\kappa = 1$ or $100$). The closure operator $\mathcal{C}(\cdot)$ re-normalizes any positive vector $\mathbf{z}$ onto the simplex:

\[\mathcal{C}(\mathbf{z}) = \left( \frac{\kappa \cdot z_1}{\sum_{j=1}^D z_j}, \dots, \frac{\kappa \cdot z_D}{\sum_{j=1}^D z_j} \right)\]

Aitchison’s Log-Ratio Transformations

To use standard regressions, correlations, or machine learning models, Aitchison introduced log-ratio transformations that map market shares from the constrained simplex into unconstrained real space ($-\infty$ to $+\infty$):

Transformation Formula Concept Best Use Case
Additive Log-Ratio (alr) $\ln(x_i / x_D)$ — divides every brand’s share by one chosen reference brand ($x_D$). Regression & market-share modeling (e.g., measuring how marketing spend shifts shares relative to a baseline competitor or “all other brands”).
Centered Log-Ratio (clr) $\ln(x_i / g(\mathbf{x}))$ — divides each brand’s share by the geometric mean $g(\mathbf{x})$ of all brands in that row. Symmetrical comparisons & biplots/PCA, where no single brand should be singled out as the baseline.
Isometric Log-Ratio (ilr) Projects $D$ shares onto $D - 1$ orthogonal contrasts (balances) using a binary partition tree. Rigorous multivariate modeling & clustering, because it preserves exact distances without creating collinearity.

Exact Mathematical Definitions & Inverses

1. Additive Log-Ratio (alr)

Maps $\mathcal{S}^D \to \mathbb{R}^{D-1}$ using component $x_D$ as the denominator: \(\text{alr}(\mathbf{x}) = \left( \ln \frac{x_1}{x_D}, \ln \frac{x_2}{x_D}, \dots, \ln \frac{x_{D-1}}{x_D} \right)\)

Inverse mapping (given $\mathbf{z} = (z_1, \dots, z_{D-1}) \in \mathbb{R}^{D-1}$): \(\text{alr}^{-1}(\mathbf{z}) = \mathcal{C}\left( e^{z_1}, e^{z_2}, \dots, e^{z_{D-1}}, 1 \right)\)

2. Centered Log-Ratio (clr)

Maps $\mathcal{S}^D \to \mathbb{R}^D$ (constrained to a hyperplane summing to $0$) using the geometric mean $g(\mathbf{x}) = \left(\prod_{j=1}^D x_j\right)^{1/D}$: \(\text{clr}(\mathbf{x}) = \left( \ln \frac{x_1}{g(\mathbf{x})}, \ln \frac{x_2}{g(\mathbf{x})}, \dots, \ln \frac{x_D}{g(\mathbf{x})} \right)\)

Inverse mapping (given $\mathbf{z} = (z_1, \dots, z_D)$ with $\sum z_i = 0$): \(\text{clr}^{-1}(\mathbf{z}) = \mathcal{C}\left( e^{z_1}, e^{z_2}, \dots, e^{z_D} \right)\)

3. Isometric Log-Ratio (ilr)

Maps $\mathcal{S}^D \to \mathbb{R}^{D-1}$ isometrically via a $(D-1) \times D$ contrast matrix $\mathbf{\Psi}$ whose rows form an orthonormal basis of the $\text{clr}$ hyperplane ($\mathbf{\Psi}\mathbf{\Psi}^T = \mathbf{I}_{D-1}$ and $\mathbf{\Psi}\mathbf{1}_D = \mathbf{0}$): \(\text{ilr}(\mathbf{x}) = \text{clr}(\mathbf{x}) \mathbf{\Psi}^T\)

Using the standard Helmert sub-matrix contrast, each coordinate $i \in {1, \dots, D-1}$ is a normalized balance: \(z_i = \sqrt{\frac{i}{i+1}} \ln \frac{\left(\prod_{j=1}^i x_j\right)^{1/i}}{x_{i+1}}\)

Inverse mapping (given $\mathbf{z} \in \mathbb{R}^{D-1}$): \(\text{ilr}^{-1}(\mathbf{z}) = \mathcal{C}\left( \exp(\mathbf{z} \mathbf{\Psi}) \right)\)


Handling Exact Zeros (Imputation Math)

Because $\ln(0)$ is undefined, exact zeros (0% market share) must be imputed prior to log-ratio transformation.

Multiplicative Replacement (Martín-Fernández et al., 2003)

Suppose a composition $\mathbf{x}$ has $Z$ zero components ($x_j = 0$ for $j \in \mathcal{I}_0$) and $D - Z$ positive components ($x_j > 0$ for $j \notin \mathcal{I}_0$), summing to $\kappa$. Each zero is replaced by a small threshold $\delta_j$ (typically $\delta_j = 0.65 \times \text{detection limit}$), and non-zero components are multiplicatively rescaled to preserve all ratios among observed shares:

\[r_j = \begin{cases} \delta_j, & \text{if } x_j = 0 \\ x_j \left( 1 - \frac{\sum_{k \in \mathcal{I}_0} \delta_k}{\kappa} \right), & \text{if } x_j > 0 \end{cases}\]

Python Implementation: Core Transformations

Below is a self-contained NumPy implementation covering zero replacement, closure, alr, clr, ilr (with Helmert contrasts), and their exact inverses.

import numpy as np


def closure(x: np.ndarray, kappa: float = 1.0) -> np.ndarray:
    """Normalize rows so each composition sums to kappa."""
    x = np.asarray(x, dtype=float)
    return kappa * x / np.sum(x, axis=-1, keepdims=True)


def multiplicative_replacement(
    x: np.ndarray, delta: float = 1e-4, kappa: float = 1.0
) -> np.ndarray:
    """Replace exact zeros while preserving ratios among non-zero shares."""
    x = closure(x, kappa=kappa)
    is_zero = x == 0
    num_zeros = np.sum(is_zero, axis=-1, keepdims=True)
    scale = 1.0 - (num_zeros * delta) / kappa
    if np.any(scale <= 0):
        raise ValueError("delta is too large for the number of zeros in a row.")
    replaced = np.where(is_zero, delta, x * scale)
    return closure(replaced, kappa=kappa)


def alr(x: np.ndarray, ref_idx: int = -1) -> np.ndarray:
    """Additive Log-Ratio transformation (D -> D-1)."""
    x = np.asarray(x, dtype=float)
    ref = np.take(x, [ref_idx], axis=-1)
    others = np.delete(x, ref_idx, axis=-1)
    return np.log(others / ref)


def alr_inv(z: np.ndarray, ref_idx: int = -1, kappa: float = 1.0) -> np.ndarray:
    """Inverse Additive Log-Ratio transformation (D-1 -> D)."""
    z = np.asarray(z, dtype=float)
    exp_z = np.exp(z)
    if ref_idx < 0:
        ref_idx = z.shape[-1] + 1 + ref_idx
    ones = np.ones((*z.shape[:-1], 1), dtype=float)
    unclosed = np.concatenate(
        [exp_z[..., :ref_idx], ones, exp_z[..., ref_idx:]], axis=-1
    )
    return closure(unclosed, kappa=kappa)


def clr(x: np.ndarray) -> np.ndarray:
    """Centered Log-Ratio transformation (D -> D, rows sum to 0)."""
    x = np.asarray(x, dtype=float)
    log_x = np.log(x)
    return log_x - np.mean(log_x, axis=-1, keepdims=True)


def clr_inv(z: np.ndarray, kappa: float = 1.0) -> np.ndarray:
    """Inverse Centered Log-Ratio transformation (D -> D)."""
    return closure(np.exp(z), kappa=kappa)


def helmert_basis(d: int) -> np.ndarray:
    """Construct a (D-1) x D orthonormal Helmert contrast matrix."""
    psi = np.zeros((d - 1, d), dtype=float)
    for i in range(1, d):
        psi[i - 1, :i] = 1.0 / i
        psi[i - 1, i] = -1.0
        psi[i - 1, :] *= np.sqrt(i / (i + 1.0))
    return psi


def ilr(x: np.ndarray) -> np.ndarray:
    """Isometric Log-Ratio transformation (D -> D-1) using Helmert contrasts."""
    c = clr(x)
    psi = helmert_basis(x.shape[-1])
    return c @ psi.T


def ilr_inv(z: np.ndarray, kappa: float = 1.0) -> np.ndarray:
    """Inverse Isometric Log-Ratio transformation (D-1 -> D)."""
    z = np.asarray(z, dtype=float)
    psi = helmert_basis(z.shape[-1] + 1)
    return clr_inv(z @ psi, kappa=kappa)

Market Share Forecasting Example (Simplex Regression & Time Series)

To forecast a $D$-part market share vector $\mathbf{y}t \in \mathcal{S}^D$ using exogenous drivers $\mathbf{X}_t$ (such as ad spend, relative price, or promotional intensity) and lagged shares, we map $\mathbf{y}_t$ into $\mathbb{R}^{D-1}$ via ilr (or alr), fit a multivariate regression or Vector Autoregression (VAR), and map the forecast $\hat{\mathbf{z}}{T+h}$ back onto the simplex via $\text{ilr}^{-1}$:

\[\mathbf{z}_t = \text{ilr}(\mathbf{y}_t) = \mathbf{B}_0 + \mathbf{B}_1 \mathbf{z}_{t-1} + \mathbf{B}_2 \mathbf{X}_t + \boldsymbol{\varepsilon}_t, \qquad \hat{\mathbf{y}}_{T+h} = \text{ilr}^{-1}(\hat{\mathbf{z}}_{T+h})\]

Why This Beats Naive Forecasting

Python Forecasting Workflow (Dynamic Simplex Regression)

import numpy as np

# Assuming closure, multiplicative_replacement, ilr, ilr_inv from above are defined


def forecast_market_shares():
    rng = np.random.default_rng(42)
    n_periods = 36  # 36 months of historical data
    brands = ["Brand A", "Brand B", "Brand C", "Other"]

    # Simulate true underlying latent utilities driven by Brand A promo spend & trend
    t = np.arange(n_periods)
    promo_a = rng.uniform(0.0, 1.0, size=n_periods)  # Exogenous driver

    # True composition generated on the simplex
    u_a = 0.8 + 0.015 * t + 0.65 * promo_a + rng.normal(0, 0.05, n_periods)
    u_b = 0.5 - 0.005 * t - 0.10 * promo_a + rng.normal(0, 0.05, n_periods)
    u_c = 0.1 + 0.002 * t + rng.normal(0, 0.05, n_periods)
    u_other = np.zeros(n_periods)

    raw_shares = closure(np.exp(np.column_stack([u_a, u_b, u_c, u_other])))

    # Step 1: Clean zeros (if any) and transform historical shares to ILR space (T x 3)
    clean_shares = multiplicative_replacement(raw_shares, delta=1e-4)
    z = ilr(clean_shares)

    # Step 2: Build lagged feature matrix for dynamic regression (ARX on the simplex)
    # Predict z_t from [intercept, z_{t-1}, promo_a_t]
    y_train = z[1:]
    X_train = np.column_stack([
        np.ones(n_periods - 1),
        z[:-1],
        promo_a[1:],
    ])

    # Fit multivariate OLS in unconstrained ILR space: B_hat = (X^T X)^(-1) X^T Y
    B_hat, _, _, _ = np.linalg.lstsq(X_train, y_train, rcond=None)

    # Step 3: Multi-step recursive forecast (next 4 quarters/months)
    future_promos = [0.2, 0.9, 0.4, 0.1]  # Planned Brand A promo schedule
    z_curr = z[-1]
    forecasts = []

    for p in future_promos:
        x_next = np.concatenate([[1.0], z_curr, [p]])
        z_next = x_next @ B_hat
        y_next = ilr_inv(z_next)  # Map back onto the simplex
        forecasts.append(y_next)
        z_curr = z_next

    forecasts = np.array(forecasts)

    print("Last Observed Shares (%):")
    print(dict(zip(brands, np.round(clean_shares[-1] * 100, 2))))
    print("\n4-Period Ahead Market Share Forecasts (%):")
    for step, (p, row) in enumerate(zip(future_promos, forecasts), start=1):
        share_str = ", ".join(f"{b}: {val*100:5.2f}%" for b, val in zip(brands, row))
        print(f"t+{step} (Promo={p:.1f}) -> {share_str} | Sum={row.sum()*100:.1f}%")


if __name__ == "__main__":
    forecast_market_shares()

Key Modeling Notes for Forecasting


Description for Footnoted

“compositional market share data constrained to the $D$-part Aitchison simplex, analyzed using log-ratio transformations to avoid spurious correlation.”