Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Computing Conditional Means for Discrete Groups

Welcome. This course begins with the ordinary case in which conditioning really does mean selecting a literal group from a population. It is deliberately familiar territory: if a regressor takes a small set of categories, then is just the average outcome among units in category .

That elementary interpretation is the benchmark for the whole course. We will first make it exact for discrete , then ask why the same argument breaks when is continuous. The later measure-theoretic construction will preserve what matters here: conditional expectation should represent the mean outcome in every group identifiable from .


Conditioning means restricting attention to a subpopulation

Let describe a grouping variable and let be a numerical outcome. For example:

  • could be a liquidity regime, classified as low, medium, or high;
  • could be an order’s implementation shortfall in basis points.

When is discrete, the event

is a genuine population subgroup. Provided that subgroup has positive probability,

we can form a conditional distribution of within it:

This is simply a renormalisation. The joint probability is the share of the whole population that is both in group and has outcome . Dividing by the share in group converts those whole-population shares into proportions that sum to one within that group.

The conditional mean is then the ordinary expectation, but calculated using this within-group probability distribution:

Equivalently,

The numerator has an especially useful interpretation:

It is the unconditional contribution to expected made by the subgroup . Dividing by the subgroup’s probability turns that whole-population contribution into its average outcome:

So, in the discrete case, “given ” has no mystery at all. It means: retain the units for which , and average their -values.

It is worth separating this from a causal claim. The quantity describes an association or prediction-relevant group average. It does not, on its own, say what would happen if we intervened to make .

2.2 Bivariate Distributions | Introduction to Computational ...

Read the relevant discrete-conditioning material from Introduction to Computational Finance and Financial Econometrics with R. It develops the same idea using a joint table of simplified stock returns, so the probability calculations can be read as proportions within return-defined groups.

Read subsection “2.2.1 Discrete random variables” to see how a joint probability table is constructed, beginning with the joint table. Then read “2.2.1.2 Conditional Distributions” and the beginning of “2.2.1.3 Conditional expectation and conditional variance,” through Definition 2.17 and Example 2.43’s conditional-mean calculations. Focus on the change from joint probabilities to within-group probabilities, and on the weighted-average calculation of the conditional mean; conditional variance is not needed yet.


A discrete trading example

Suppose is a discrete liquidity classification for an order:

where , , and denote low, medium, and high liquidity stress. Let be implementation shortfall, taking the stylised values , , or basis points. The joint population distribution is:

Liquidity regime bps bps bps

Each interior entry is a joint probability. For instance,

It says that 15% of all orders are both in the high-stress regime and incur 10 bps of shortfall. It does not say that 15% of high-stress orders incur 10 bps.

To obtain the latter, condition on . The high-stress group comprises 25% of all orders, so its conditional distribution is:

Those probabilities now sum to one because they describe only the high-stress subpopulation.

The conditional mean is the average shortfall within that group:

Thus, the population mean implementation shortfall among high-stress orders is 7.6 bps.

The direct “total divided by group size” calculation gives the same result:

Imagine a population of 10,000 orders matching these probabilities. There would be 2,500 high-stress orders: 200 with 0 bps shortfall, 800 with 5 bps, and 1,500 with 10 bps. Their total shortfall would be 19,000 bps, and their literal arithmetic average would be:

The probability calculation is simply the population-level version of this group average.

Conditional expectation -- Example 1

Watch “Conditional expectation -- Example 1” by Lawrence Leemis. It gives a compact worked calculation from a discrete joint PMF: first isolate the relevant group, then calculate its conditional distribution, then average within it.

Watch the setup to identify the target quantity and the joint table. Then watch conditioning, paying attention to the marginal probability in the denominator: it is the size of the selected X-group. Finish with averaging, where the conditional probabilities become weights in the group mean.


From several group means to a conditional-mean function

The previous calculation gives one number, . Repeating it for each possible value of gives:

Group
bps
bps
bps

For low stress, for example,

The mapping

is the conditional mean function or, in regression language, the population regression function. In this discrete example it is simply a lookup table: enter the observed liquidity regime and retrieve that group’s population mean shortfall.

There are three closely related expressions worth keeping distinct:

is one unconditional population mean.

is one particular group mean.

is shorthand for the random quantity that takes the value appropriate to the realised group. In this example,

This notation is natural: before you observe , you do not yet know which conditional mean applies. Once is observed, the relevant group mean is determined.

The unconditional mean is recovered by averaging the group means using the group probabilities:

This is the law of total expectation in the discrete setting. It says that the overall average is a weighted average of subgroup averages. The weights are not arbitrary: large groups contribute more to the population average than small groups.

The decomposition also clarifies what conditioning adds. Without liquidity information, the best single summary of the population is 5 bps. With the discrete -information, the relevant average varies from roughly 3.14 bps to 7.6 bps. Conditioning replaces one pooled average with averages tailored to identifiable groups.


The sample analogue, and the denominator that matters

In a dataset of observations , the empirical counterpart of the population conditional mean is exactly the group average:

provided at least one observation belongs to group .

The denominator is the number of observations in the group. The numerator is their total -value. Hence the formula is simply “sum within group divided by count within group.”

The population formula has the same structure:

Here, is the population analogue of the sample group proportion. This is why discrete conditioning is so intuitively secure: both in data and in the population model, there is a nonempty group over which an average can be taken.

There is one condition that should not be treated as a technical footnote:

If a supposed category has zero population probability, there is no population subgroup to average over, and the ratio definition is undefined. In a discrete model, that usually just means is outside the support of , or is an impossible state.

The next lesson considers a more consequential case: is continuous, so every exact numerical value has probability zero even though such values can be observed. The familiar group-average formula then presents a problem. The rest of the course is about retaining the substantive meaning of conditional averages without pretending that this ratio still works point by point.


Key takeaways

For a discrete conditioning variable , is the population mean of within the genuine subgroup :

It can also be written as a ratio of the subgroup’s total expected outcome to its population share:

As varies, these group means form the conditional-mean function . Their probability-weighted average recovers .

Next, we will isolate the exact point at which this elementary reasoning fails for a continuous regressor: the event no longer has positive probability, so the literal “select the group and average it” definition cannot be used unchanged.

Can't find a good explanation? Sign up and we'll make it for you

Sign up