Tutorials › Statistical Learning (Graduate) › Worked Problems in Conditional Distribution Estimation

Conditional Distribution Learning · Tutorial 639 of 989

Worked Problems in Conditional Distribution Estimation

Learn to match conditional-distribution estimands and estimators to the outcome structure, then assess fitted laws with suitable scores and error metrics.

Advanced 12 min read

What You'll Learn

  • Define a conditional law as the target of estimation at a covariate value.
  • Fit and score a Bernoulli conditional model using observed binary outcomes.
  • Estimate Gaussian conditional mean and variance and calculate a density score.
  • Estimate mixture weights for a multimodal conditional distribution.
  • Distinguish point-prediction errors from errors between full conditional laws.
  • Use proper scoring rules and distributional metrics for different estimation goals.

From a Conditional Estimand to an Error Measure

A conditional distribution estimate is useful only when its target and its assessment agree. If the outcome is binary, estimating a success probability may be enough to specify the entire law. For a continuous outcome, a conditional mean alone does not describe spread or multiple modes. A point-prediction error can therefore look small while the estimated distribution is poor, or vice versa.

Let \(X\) be a covariate and \(Y\) an outcome. At a covariate value \(x\), the target is the conditional law of \(Y\) given \(X=x\). In applications with continuous \(X\), this conditional law is defined up to sets of covariate values having probability zero; estimation at a particular \(x\) requires suitable support and regularity for the method being used. The examples below take a fixed covariate value or stratum and focus on choosing an estimand, estimator, and assessment appropriate to its outcome structure.

Definition: The conditional distribution estimand at \(x\) is \(F_x(y)=P(Y\leq y\mid X=x)\). If a conditional density exists, write it as \(f_x(y)\). An estimator \(\hat F_x\), or \(\hat f_x\), is a data-dependent estimate of that law. A parameter such as a conditional success probability or conditional variance is an estimand derived from the law, not necessarily the whole law.

A scoring rule evaluates a forecast distribution using an observed outcome; its expected value under the true law describes its population performance. An error metric instead compares an estimated object with a target object, when that target is available or can be specified for analysis. These purposes are related but not interchangeable: a score is computed from forecasts and outcomes, while a distributional distance directly compares laws.

Worked Example: A Bernoulli Conditional Law

Worked Example: A Bernoulli Conditional Law

Suppose that in a fixed treatment-and-age stratum, \(Y\) indicates whether a patient responds to treatment. The estimand is \(p_x=P(Y=1\mid X=x)\), and the conditional law is Bernoulli with success probability \(p_x\). Among \(n=20\) patients in this stratum, 15 respond and 5 do not. Under an independent Bernoulli model with a common stratum probability, the likelihood is \(L(p_x)=p_x^{15}(1-p_x)^5\). Maximizing it gives \(\hat p_x=15/20=0.75\).

For an individual binary forecast \(q\), the logarithmic loss is \(-\log q\) when \(Y=1\), and \(-\log(1-q)\) when \(Y=0\). The Brier loss is \((Y-q)^2\). To compare forecasts \(q=0.70\) and \(q=0.75\) on a held-out set containing 3 responses and 1 nonresponse, calculate the average logarithmic loss at \(q=0.70\):

$$ -\frac{3}{4}\log(0.70)-\frac{1}{4}\log(0.30) =-(0.75)(-0.356675)-(0.25)(-1.203973) =0.568499\ldots $$

Thus the average loss is \(0.5685\) to four decimal places. At \(q=0.75\), it is

$$ -\frac{3}{4}\log(0.75)-\frac{1}{4}\log(0.25) =(0.75)(0.287682)+(0.25)(1.386294) =0.562335\ldots . $$

The smaller observed log loss favors \(q=0.75\) on this held-out set. The average Brier losses are \(\{3(0.30)^2+1(0.70)^2\}/4=0.1900\) for \(q=0.70\), and \(\{3(0.25)^2+1(0.75)^2\}/4=0.1875\) for \(q=0.75\); they favor the same forecast here. This comparison is a finite-sample result for these four outcomes, not a claim that either score must rank forecasts identically on every sample.

Why Proper Scores Target the Conditional Law

For a binary outcome, a forecast probability \(q\) can be assessed without first estimating a separate outcome model. If the true conditional success probability is \(p\), the expected Brier loss and expected logarithmic loss are minimized by forecasting \(p\). The next result gives the derivations and states the conditions for the logarithmic comparison.

Result: For \(Y\sim\operatorname{Bernoulli}(p)\) and \(q\in[0,1]\), the expected Brier loss is \(p(1-p)+(q-p)^2\). For \(p,q\in(0,1)\), the expected logarithmic loss at \(q\) minus that at \(p\) is \(p\log(p/q)+(1-p)\log\{(1-p)/(1-q)\}\), which is nonnegative and is zero only if \(q=p\). Thus both scores are minimized at the true probability. At boundary values, the logarithmic loss is interpreted as infinite when a forecast assigns zero probability to an event with positive probability.

Derivation. Since \(Y\) is 1 with probability \(p\) and 0 with probability \(1-p\),

$$ E[(Y-q)^2] =p(1-q)^2+(1-p)q^2 =p-2pq+q^2 =p(1-p)+(q-p)^2. $$

The squared term is nonnegative and vanishes exactly at \(q=p\). For the logarithmic score, the expected loss at \(q\) is \(-p\log q-(1-p)\log(1-q)\). Subtracting its value at \(p\) gives the displayed expression. This expression is the Kullback–Leibler divergence between the Bernoulli laws with probabilities \(p\) and \(q\); its nonnegativity follows from the general density result below, or directly from \(\log t\leq t-1\). Equality requires the two Bernoulli laws to agree, hence \(q=p\). \(\square\)

More generally, let \(P\) and \(Q\) have densities \(p\) and \(q\) with respect to the same measure. If both expected negative logarithmic losses under \(P\), \(E_P[-\log p(Y)]\) and \(E_P[-\log q(Y)]\), are finite, then

$$ E_P[-\log q(Y)]-E_P[-\log p(Y)] =E_P\!\left[\log\frac{p(Y)}{q(Y)}\right] =D_{\mathrm{KL}}(P\|Q)\geq 0. $$

Here finiteness ensures the difference is defined. Nonnegativity is Gibbs’ inequality: on the set where \(p>0\), \(q>0\) under the stated finite-loss condition, and \(\log(q/p)\leq q/p-1\). Integrating with respect to \(P\) gives

$$ E_P\!\left[\log\frac{q(Y)}{p(Y)}\right] \leq \int_{\{p>0\}}q\,d\mu-1 \leq 0. $$

The final inequality holds because \(q\) integrates to one over the whole space. This proves the result. \(\square\)

Worked Example: A Gaussian Conditional Law

Worked Example: A Gaussian Conditional Law

At a fixed covariate value \(x\), suppose a working model treats the outcomes as independent draws from \(N(\mu_x,\sigma_x^2)\). The estimand is the pair \((\mu_x,\sigma_x^2)\), or equivalently the full Gaussian conditional law. Five observations in the stratum are \(1,2,3,4,5\). The likelihood maximizers are the sample mean and the variance with denominator \(n\):

$$ \hat\mu_x=\frac{1+2+3+4+5}{5}=3,\qquad \hat\sigma_x^2=\frac{(1-3)^2+(2-3)^2+(3-3)^2+(4-3)^2+(5-3)^2}{5} =\frac{10}{5}=2. $$

The fitted conditional law is \(N(3,2)\), where 2 is the variance. For a held-out outcome \(y=4\), its negative log density, also called the continuous logarithmic score, is

$$ -\log f_x(4) =\frac{1}{2}\log(2\pi\hat\sigma_x^2) +\frac{(4-\hat\mu_x)^2}{2\hat\sigma_x^2} =\frac{1}{2}\log(4\pi)+\frac{1}{4} \approx 1.5155. $$

Density scores can be negative for densities greater than one; that does not make them invalid. If the target law for comparison were \(N(2.8,1.5)\), the fitted mean error would be \(3-2.8=0.2\), and the variance error would be \(2-1.5=0.5\). Those parameter errors describe different features and use different scales. For a full-law comparison, the 2-Wasserstein distance between these one-dimensional Gaussian laws is

$$ W_2^2 =(3-2.8)^2+(\sqrt{2}-\sqrt{1.5})^2 \approx 0.0400+0.0359=0.0759, \qquad W_2\approx 0.2755. $$

The example distinguishes fitting from assessment: the maximum-likelihood variance uses denominator \(n\), whereas an unbiased sample-variance estimate uses denominator \(n-1\). The appropriate choice depends on the estimation procedure and target; they are not interchangeable formulas.

Worked Example: A Multimodal Conditional Law

Worked Example: A Multimodal Conditional Law

Suppose a conditional outcome has two separated modes, represented by the mixture \(f_x(y)=w_x g_L(y)+(1-w_x)g_R(y)\), where \(g_L\) is uniform on \([-2.2,-1.8]\), and \(g_R\) is uniform on \([1.8,2.2]\). The component densities are known; the target is the mixing weight \(w_x\), which also determines the full law. In 10 observations, 7 fall in the left interval and 3 in the right. Each observation contributes a factor \(w_x/0.4\) if it falls left, and \((1-w_x)/0.4\) if it falls right. Therefore the likelihood is

$$ L(w_x)=\left(\frac{w_x}{0.4}\right)^7 \left(\frac{1-w_x}{0.4}\right)^3 =0.4^{-10}w_x^7(1-w_x)^3. $$

The log-likelihood, apart from its constant term, is \(7\log w_x+3\log(1-w_x)\). Its derivative is \(7/w_x-3/(1-w_x)\), which vanishes at \(10w_x=7\), so \(\hat w_x=0.7\). Its second derivative is \(-7/w_x^2-3/(1-w_x)^2<0\) for \(0<w_x<1\), confirming a maximum.

At \(y=-2.1\), the fitted density is \(0.7/0.4=1.75\), so the negative log density is \(-\log(1.75)\approx-0.5596\). At \(y=2.0\), the density is \(0.3/0.4=0.75\), and the score is \(-\log(0.75)\approx0.2877\). For a density score, a negative value is possible and is not an error.

If the true mixing weight is \(0.6\), the estimated and true CDFs differ by \(0.1\) at zero: the CDF there equals the left-mode weight. The 1-Wasserstein distance is \(4|0.7-0.6|=0.4\). To see this, couple the common mass in each component identically; the remaining mass \(0.1\) must move between the two component intervals. Its least possible mean travel distance is the difference between their means, \(2-(-2)=4\), giving cost \(0.1(4)=0.4\). This metric captures the separation of the modes, whereas the weight error alone is \(0.1\).

Choosing What to Estimate and How to Assess It

The examples illustrate a practical sequence. First specify whether the target is a scalar feature, such as a conditional mean, or the whole law. Then select a model and estimator that represent the outcome structure. Finally, choose an assessment matched to the target: a proper score for observed outcomes, a parameter error for a parameter target, or a distributional metric for a law target.

Outcome structureNatural estimandPossible assessment
Binary, BernoulliConditional probability \(p_x\)Logarithmic or Brier score; probability error if the target is known
Approximately GaussianConditional mean and variance, or full Gaussian lawContinuous logarithmic score; parameter errors or Wasserstein distance
Separated modes or mixtureMixing weights and component laws, or full mixture lawHeld-out log score; CDF or Wasserstein error when the target law is available

A common mistake is to assess a full conditional distribution solely by the error in its mean. For example, two distributions can have the same mean while one is concentrated near that mean and the other has two distant modes. A mean-only error is then zero even though the laws differ. The correction is to define the estimand before choosing the metric: use mean error when the mean is the target, but use a distributional score or distance when the full conditional law is the target.

Key takeaway: The outcome structure determines a useful model, but the scientific target determines what counts as estimation error. Match the estimand, fitting method, and assessment; do not treat a point estimate as a substitute for a conditional law.

Check Your Understanding

Work through these questions by identifying the target before choosing a calculation.

  1. In a Bernoulli stratum with 12 successes among 30 observations, what is the maximum-likelihood estimate of the success probability?
  2. Why does the expected Brier loss favor the true Bernoulli probability even when that probability is not known to the forecaster?
  3. For Gaussian outcomes, why should the variance with denominator \(n\) not automatically be described as an unbiased variance estimate?
  4. In the two-component mixture example, what does a mixing-weight error omit that the Wasserstein distance can reflect?
  5. Give an example of two conditional laws with the same mean but different distributional shape. Why would mean error fail to distinguish them?
Clinical Biostats