liveBook · Manning

Conditional expectation

As explained in Causal AI

A conditional expectation is the expected value of a quantity given observed values or events.

Conditional expectation estimates an outcome after conditioning on observed evidence, such as E(U(Y)|X=x). It answers which option looks best among cases sharing that observed value, not necessarily which option would cause the best outcome. section 12.2.4

Distinguish the two decision quantities:

  • E(U(Y)|X=x) conditions on cases where X equals x and can reflect confounding or selection. section 12.2.4
  • E(U(Y_X=x)) evaluates an intervention that sets X to x and represents the causal decision target. section 12.2.4
  • Optimizing the conditional expectation can agree with the causal answer, but parameter changes can make the two recommendations diverge. section 12.2.4

Investment choice

After changing one success-probability parameter, conditioning favors debt: E(U(Y)|X=debt)=57000 versus 53000 for equity. Intervention reverses the choice: E(U(Y_X=debt))=39000 versus 44000 for equity. A level-2 causal query therefore requires the interventional quantity. section 12.2.4

Listing 12.5 Calculate E(U(Y)|X=x) and E(U(YX=x))
def get_expectation(marginal):     #1
    u_values = marginal.state_names["U"]    #1
    probs = marginal.values    #1
    expectation = sum([x * p for x, p in zip(u_values, probs)])   #1
    return expectation    #1

infer = VariableElimination(model)     #2
marginal_u_given_debt = infer.query( #2
    variables=['U'], evidence={'X': 'debt'})     #2
marginal_u_given_equity = infer.query( #2
    variables=['U'], evidence={'X': 'equity'})    #2
e_u_given_x_debt = get_expectation(marginal_u_given_debt)    #2
e_u_given_x_equity = get_expectation(marginal_u_given_equity)    #2
print("E(U(Y)|X=debt)=", e_u_given_x_debt)    #2
print("E(U(Y)|X=equity)=", e_u_given_x_equity)     #2

int_model_x_debt = do(model, {"X": "debt"})     #3
infer_debt = VariableElimination(int_model_x_debt)    #3
marginal_u_given_debt = infer_debt.query(variables=['U'])    #3
expectation_u_given_debt = get_expectation(marginal_u_given_debt)    #3
print("E(U(Y_{X=debt}))=", expectation_u_given_debt)     #3
int_model_x_equity = do(model, {"X": "equity"})     #3
infer_equity = VariableElimination(int_model_x_equity)     #3
marginal_u_given_equity = infer_equity.query(variables=['U'])    #3
expectation_u_given_equity = get_expectation(marginal_u_given_equity)     #3
print("E(U(Y_{X=equity}))=", expectation_u_given_equity)     #3

Computes conditional and interventional expectations with pgmpy inference, a utility-marginal helper, and do-based model variants. section 12.2.4

How Causal AI covers it

How deep it goes
Contrasts conditioning with intervention, computes utility expectations, and demonstrates divergence after changing one probability parameter.
Examples
Uses a debt-versus-equity investment model, utility outcomes, changed success probabilities, and pgmpy inference code.
What it assumes
Assumes familiarity with expected utility and probability tables while distinguishing observational evidence from causal intervention.
What you can do after
Diagnose decision errors by comparing evidence-conditioned expectations with do-based interventional expectations in pgmpy.
How it connects
Connects conditional expectation to causal inference, interventions, Bayesian networks, utility, and reinforcement learning.

Also explained in

Compare how 2 books explain conditional expectation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Causal AI. The section links point to the parts of the book it draws on.