Tutorials › Multivariate Statistics (Graduate) › Stress Testing Discriminant Rules Across Subgroups

Discriminant Inference and Risk · Tutorial 628 of 975

Stress Testing Discriminant Rules Across Subgroups

Separate the ways subgroup risk can change, calculate the resulting risks, and report uncertainty without hiding sparse-sample limitations.

Advanced 11 min read

What You'll Learn

  • Define subgroup risk and decompose it into prevalence and class-conditional error rates
  • Distinguish changes in subgroup composition from changes in feature distributions
  • Evaluate how measurement degradation can alter a fixed classifier’s error
  • Reconstruct overall risk from subgroup risks using target subgroup proportions
  • Quantify uncertainty for sparse subgroup test samples and identify when stratification matters

Why Stress-Test a Discriminant Rule?

A classifier can have acceptable average performance while making substantially more errors in a particular subgroup. Even within one subgroup, an apparent change in risk can have different causes: the prevalence of the classes may have changed, the features may behave differently within a class, or the measurements supplied to the rule may have become less reliable. These causes call for different interpretations and different checks.

Stress testing means evaluating a fixed discriminant rule under explicitly stated subgroup conditions and changes. It is not a guarantee about every future distribution. The goal is to make the assumptions visible, compare risks under meaningful scenarios, and show how much the available test data support the reported differences.

Subgroup Risk and Its Decomposition

Consider a binary outcome \(Y\in\{0,1\}\), a subgroup label \(S\), and a fixed classification rule \(g\) that predicts either 0 or 1 from the measured feature vector \(X\). Define the error indicator \(I=\mathbf{1}\{g(X)\ne Y\}\). All risks below refer to the distribution under which the rule is being evaluated.

Definition: The risk in subgroup \(s\) is \(R_s=P(g(X)\ne Y\mid S=s)\). Write \(\pi_s=P(Y=1\mid S=s)\), \(e_{1s}=P(g(X)\ne 1\mid Y=1,S=s)\), and \(e_{0s}=P(g(X)\ne 0\mid Y=0,S=s)\). The quantities \(e_{1s}\) and \(e_{0s}\) are the class-conditional error probabilities in that subgroup.

The class-conditional errors describe how the rule behaves among members of each true class. The prevalence \(\pi_s\) describes how frequently class 1 occurs in the subgroup. These are distinct features of the evaluation distribution.

Theorem: For any subgroup with \(P(S=s)>0\), $$ R_s=\pi_s e_{1s}+(1-\pi_s)e_{0s}. $$ If the subgroups \(s=1,\ldots,J\) partition the population, then the overall risk is $$ R=\sum_{s=1}^J P(S=s)R_s. $$

Proof. Partition the event of a classification error according to the two possible values of \(Y\), conditional on \(S=s\). The law of total probability gives $$ P(g(X)\ne Y\mid S=s) =P(g(X)\ne 1\mid Y=1,S=s)P(Y=1\mid S=s) +P(g(X)\ne 0\mid Y=0,S=s)P(Y=0\mid S=s). $$ Since \(P(Y=0\mid S=s)=1-\pi_s\), this is the stated formula. Applying the law of total probability again, now over the subgroup partition, gives \(R=\sum_s P(S=s)R_s\). \(\square\)

The overall risk therefore depends both on subgroup-specific performance and on how common each subgroup is in the target population. Reporting only a pooled test-set error can obscure either part.

Three Distinct Stress Axes

A useful stress test changes one feature of the evaluation conditions at a time before considering combined scenarios. This makes it easier to identify what is driving a risk change.

  • Prevalence shift within a subgroup: change \(\pi_s\) while holding \(e_{1s}\) and \(e_{0s}\) fixed. The class mix changes, but the class-conditional behavior of the rule is assumed not to change.
  • Feature-distribution shift: change the distribution of \(X\) conditional on \(Y\) and \(S\). The rule remains fixed, but \(e_{1s}\), \(e_{0s}\), or both may change. The resulting errors must be evaluated or modeled; they cannot be inferred from prevalence alone.
  • Measurement-quality change: change how the features are measured before applying the same rule. For example, a noisy instrument may record \(X^{\mathrm{obs}}\) instead of \(X\). The rule still acts on its input, but the distribution of that input can change and so can the error probabilities.

These axes can occur together. A scenario should say which quantities are changed and which are being held fixed; otherwise, a risk difference has no clear interpretation. The earlier material on prior-probability shift and covariate shift gives related weighting tools, but stress testing across subgroups also requires reporting subgroup-specific results and the conditions under which they were computed.

Worked Example: Prevalence Changes with Fixed Error Rates

A fixed rule is tested in subgroup A. Its false-negative probability is \(e_{1A}=0.20\), and its false-positive probability is \(e_{0A}=0.10\). Compare subgroup risk when the class-1 prevalence is \(0.30\) and \(0.60\), assuming the two class-conditional error probabilities remain unchanged.

At prevalence \(0.30\), $$ R_A=0.30(0.20)+0.70(0.10)=0.06+0.07=0.13. $$ At prevalence \(0.60\), $$ R_A=0.60(0.20)+0.40(0.10)=0.12+0.04=0.16. $$

The risk rises by \(0.03\), or three percentage points, even though the rule’s class-conditional error probabilities have not changed. The increase is due entirely to the larger weight on class 1, which has the higher error probability here. It would be misleading to describe this particular increase as evidence that the rule became worse within either class.

Result: If \(e_{1s}\) and \(e_{0s}\) are fixed, changing prevalence from \(\pi_s\) to \(\pi_s'\) changes risk by $$ R_s(\pi_s')-R_s(\pi_s)=(\pi_s'-\pi_s)(e_{1s}-e_{0s}). $$ Thus, the risk increases with prevalence exactly when \(e_{1s}>e_{0s}\), decreases when \(e_{1s}<e_{0s}\), and is unchanged when the two errors are equal.

Derivation. Subtract the two risk expressions: $$ \big[\pi_s'e_{1s}+(1-\pi_s')e_{0s}\big] -\big[\pi_se_{1s}+(1-\pi_s)e_{0s}\big] =(\pi_s'-\pi_s)e_{1s}-(\pi_s'-\pi_s)e_{0s}. $$ Factoring gives the stated identity. Since the prevalence difference is positive when prevalence rises, the sign of the risk change is the sign of \(e_{1s}-e_{0s}\). \(\square\)

Worked Example: Feature Shift Changes Class-Conditional Errors

In a subgroup, a rule predicts class 1 when the measured score \(X\) exceeds 1. Under the reference conditions, \(X\mid Y=1\) is \(N(1.5,1)\) and \(X\mid Y=0\) is \(N(0,1)\). In a changed environment, suppose only the class-1 score distribution shifts to \(N(1.0,1)\); the class-0 distribution and the prevalence \(\pi=0.40\) are unchanged. Compute the risks, using \(\Phi\) for the standard normal distribution function and \(\Phi(1)\approx0.8413\), \(\Phi(0.5)\approx0.6915\).

Under the reference conditions, a class-1 observation is missed when \(X\le 1\). Standardizing gives $$ e_1=P(X\le1\mid Y=1)=\Phi\left(\frac{1-1.5}{1}\right)=\Phi(-0.5)=1-\Phi(0.5)\approx0.3085. $$ A class-0 observation is incorrectly classified as 1 when \(X>1\), so $$ e_0=P(X>1\mid Y=0)=1-\Phi\left(\frac{1-0}{1}\right)=1-\Phi(1)\approx0.1587. $$ The reference risk is therefore $$ R=0.40(0.3085)+0.60(0.1587)=0.1234+0.09522=0.21862. $$

After the shift, the class-1 mean is 1.0, so $$ e_1'=P(X\le1\mid Y=1)=\Phi(0)=0.5. $$ The class-0 error remains \(e_0'=0.1587\). Hence $$ R'=0.40(0.5)+0.60(0.1587)=0.20+0.09522=0.29522. $$

The increase is about \(0.0766\). Unlike the preceding example, prevalence did not change: the increase comes from a changed class-conditional feature distribution that raises the false-negative probability. The calculation depends on the stated normal models; it is not established merely by observing a shift in a score summary.

Worked Example: Degraded Measurement Changes the Rule’s Input

Let the true feature be \(Z\in\{0,1\}\), and let the fixed rule predict the observed feature value: \(g(X^{\mathrm{obs}})=X^{\mathrm{obs}}\). In a subgroup, suppose \(P(Y=1)=0.40\), \(P(Z=1\mid Y=1)=0.80\), and \(P(Z=1\mid Y=0)=0.20\). Initially the measurement is perfect, so \(X^{\mathrm{obs}}=Z\). In a degraded setting, the measurement independently flips \(Z\) with probability \(0.10\), conditional on \(Z,Y\). Compare risks.

With perfect measurement, the false-negative probability is \(1-0.80=0.20\), and the false-positive probability is \(0.20\). Thus $$ R_{\mathrm{perfect}}=0.40(0.20)+0.60(0.20)=0.08+0.12=0.20. $$

Under degraded measurement, among class-1 observations, a false negative occurs either when \(Z=0\) and it is not flipped, or when \(Z=1\) and it is flipped: $$ e_1'=0.20(0.90)+0.80(0.10)=0.18+0.08=0.26. $$ Among class-0 observations, a false positive occurs either when \(Z=1\) and it is not flipped, or when \(Z=0\) and it is flipped: $$ e_0'=0.20(0.90)+0.80(0.10)=0.18+0.08=0.26. $$ The new risk is $$ R_{\mathrm{degraded}}=0.40(0.26)+0.60(0.26)=0.104+0.156=0.26. $$

Risk rises by \(0.06\). The rule itself was not changed; the distribution of its measured input was. In a real assessment, the flip mechanism would need supporting data or a clearly identified sensitivity assumption.

Reconstructing Overall Risk for a Target Population

Test samples may not represent the target population’s subgroup proportions. For example, an evaluation may deliberately include equal numbers from several subgroups to obtain useful subgroup estimates. In that case, the raw pooled error rate describes the test design, not necessarily the target population.

If \(w_s=P_{\mathrm{target}}(S=s)\) are known target subgroup proportions and \(R_s\) are risks estimated under the relevant target conditions, the standardized overall risk is $$ R_{\mathrm{target}}=\sum_{s=1}^J w_sR_s,\qquad \sum_{s=1}^J w_s=1. $$ This is an aggregation identity, not a method for correcting a change in the class-conditional feature distributions. If those distributions differ between the test data and target, additional assumptions or data are needed to estimate the target subgroup risks.

Worked Example: Equal Subgroup Sampling and Target Weights

An evaluation samples 100 observations from each of two subgroups. It observes 8 errors in subgroup A and 20 in subgroup B, giving estimated risks \(0.08\) and \(0.20\). The target population is 70% subgroup A and 30% subgroup B. Compare the test-set pooled error with the target-standardized estimate.

The test has 28 errors among 200 observations, so its pooled error rate is $$ \widehat R_{\mathrm{test}}=\frac{8+20}{100+100}=\frac{28}{200}=0.14. $$ The target-standardized estimate is $$ \widehat R_{\mathrm{target}}=0.70(0.08)+0.30(0.20)=0.056+0.060=0.116. $$ The two values differ because the balanced test assigns each subgroup weight \(0.50\), whereas the target assigns weights \(0.70\) and \(0.30\). The standardized value is appropriate only if the subgroup risk estimates apply to the target conditions being described.

Uncertainty When Subgroup Samples Are Sparse

For a fixed rule evaluated on independent test observations representative of a subgroup, let \(K_s\) be the number of errors among \(n_s\) observations. Conditional on the evaluation conditions, \(K_s\) has a binomial distribution with error probability \(R_s\). The point estimate \(K_s/n_s\) can be highly uncertain when \(n_s\) is small, especially when there are few observations from one true class.

A Wilson score interval is a useful derivation-based interval for a binomial probability. For \(K=k\), \(n\) trials, \(\hat p=k/n\), and a standard normal quantile \(z=z_{1-\alpha/2}\), it is $$ \left[ \frac{\hat p+z^2/(2n)-z\sqrt{\hat p(1-\hat p)/n+z^2/(4n^2)}}{1+z^2/n}, \quad \frac{\hat p+z^2/(2n)+z\sqrt{\hat p(1-\hat p)/n+z^2/(4n^2)}}{1+z^2/n} \right]. $$ This interval is obtained by inverting the binomial score test. In particular, retaining values \(p\in[0,1]\) for which $$ \frac{|\hat p-p|}{\sqrt{p(1-p)/n}}\le z $$ and squaring gives $$ (n+z^2)p^2-(2n\hat p+z^2)p+n\hat p^2\le0. $$ The two roots of this quadratic are the displayed endpoints, so the interval follows by solving the score inequality. This is a score interval, not an exact finite-sample coverage guarantee; with very sparse counts, report an exact binomial interval as well or instead.

For subgroup risk, the direct binomial interval is appropriate only when the test observations represent the subgroup distribution of interest. If sampling was stratified by the true class, estimate the two class-conditional errors separately and combine them using the target prevalence: $$ \widehat R_s=\hat\pi_s\hat e_{1s}+(1-\hat\pi_s)\hat e_{0s}. $$ A class with very few test observations produces a correspondingly uncertain error estimate. State the class counts and the prevalence source; a precise-looking weighted risk does not remove uncertainty in its components. If reporting intervals for multiple subgroup risks, account for the multiplicity, for example by allocating a total error probability across the subgroup intervals. If the rule was selected or tuned using the same observations, ordinary fixed-rule binomial intervals do not automatically account for that selection; evaluation must respect the training and test separation.

Common Pitfalls and Reporting Practice

  • Comparing pooled error rates under different subgroup mixes. A difference may reflect different subgroup weights rather than changed subgroup performance. Report subgroup risks and, when relevant, risks standardized to a common target mix.
  • Calling every risk change a prevalence effect. Prevalence adjustment holds class-conditional error rates fixed. A feature-distribution or measurement change can alter those rates, and must be assessed separately.
  • Treating a small subgroup estimate as precise. Always show the subgroup sample size and uncertainty. If the evaluation is class-stratified, also show the numbers in each true class.
  • Interpreting an assumed stress scenario as observed evidence. State which distributions, flip rates, prevalence values, or target weights are estimated from data and which are hypothetical sensitivity inputs.

A clear report names the fixed rule, the subgroup definitions, the evaluation conditions, the target subgroup weights if an overall risk is reported, and uncertainty alongside the point estimates. This lets readers distinguish a change in composition from a change in conditional performance, while keeping conclusions proportional to the test sample size.

Check Your Understanding

Use the definitions and calculations in this tutorial to answer the following questions.

  1. If a subgroup’s class-1 prevalence rises while both class-conditional errors stay fixed, what determines whether its risk rises or falls?
  2. Why can a pooled test error be inappropriate when test sampling deliberately gives equal numbers to subgroups?
  3. A classifier’s false-negative rate changes after an instrument is replaced, but prevalence is stable. Which stress axis is implicated, and what additional evidence would help interpret the change?
  4. Why should a test with only a few class-1 observations report the class-1 count when estimating subgroup risk?
  5. What assumption permits a direct binomial interval for subgroup risk, and why might that assumption fail under class-stratified sampling?
Clinical Biostats