Skip to main content

Causal AI | Counterfactuals tutorial

In this tutorial we demonstrate the process of Counterfactual analysis. Counterfactual analysis can also be though of as Causal What If? analysis.

info

For more information on Counterfactual analysis and Causal AI in general, see the article Introduction to Causal AI.

Open the model

We will use the Counterfactuals BOW sample network installed with Bayes Server. This example can be found in the Book of Why | Judea Pearl, Dana Mackenzie 2018, p273.

This network can be used to determine whether, when salary is based on experience and education level (and luck? Connections, etc…), was it worth doing a PhD?

info

We can't simply change education level, because we would be ignoring the fact that an individual would otherwise have a different experience level, etc...

  • Launch Bayes Server, and on the Start page click the network entitled 'Counterfactuals BOW' in the Sample networks pane.
info

If the Start page is not set to display on start up, or has been closed, click the Start page button, on the Application tab.

Counterfactuals BOW sample network

Evidence

First enter evidence for an individual (or sub-population). In this example, we are following the example in the Book of Why, so we must enter the following evidence for Alice.

  • Experience=6
  • Education=0
  • Salary=81000.

Alice

Abduction

  • Select the Causal toolbar tab, and click Abduction to launch the Abduction dialog.
info

This allows us to calculate the characteristic variables Uex and Us, and will also remove the original evidence. Characteristic variables capture what is unique about the individual or sub-population (in this case Alice).

  • Select Uex and Us and add them to the characteristic variables pane.

Abduction dialog

  • Click Run.

Abduction results

  • Click Close

  • When prompted whether to apply characteristic evidence, click Yes.

info

This will set evidence on the characteristic variables, and remove evidence on the Abduction evidence variables.

Network after abduction

Intervention

  • Set intervention evidence on Education to 1 ( Do(Education=1))
info

To quickly set intervention evidence, you can hold down Shift and click a node chart or checkbox (depending on the display).

  • Check that the evidence is displayed in Red.

Network after intervention

Query

  • Query Salary which now has the value 76000.
info

If a node is already being queried (the default when opened) you can hover over the Salary chart, or you can double click in Query explorer.

Result

The resulting salary of 76000 matches the example in the book, and suggests that had Alice done a PhD she would now be earning 76000 instead of 81000.

info

Had we simply incorrectly set Education=1 for Alice, along with experience of 6 years, the resulting salary would be 85000, which is very different.