Skip to content

Commit 8a4499d

Browse files
committed
docs
1 parent 92e5fd0 commit 8a4499d

4 files changed

Lines changed: 38 additions & 39 deletions

File tree

docs/source/background.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ Background
8383

8484
<div style="margin-top: 30px;"></div>
8585

86-
The Causal Testing Framework primarily consists of the following 2 components: 1) Causal Specification and 2) Causal Test Case.
86+
The Causal Testing Framework primarily consists of the following 3 components: 1) Modelling Scenario, 2) Causal Graph, and 2) Causal Test Case.
8787

8888
#.
89-
:doc:`Causal Specification <../modules/causal_specification>`\ : To apply graphical causal inference techniques for testing, we need a *causal specification*.
90-
This takes the form of a directed acyclic graph (DAG) that depicts causal relationships amongst inputs and outputs and a set of constraints over input variables that capture the modelling scenario of interest.
89+
:doc:`Causal Graph <../modules/causal_specification>`\ : To apply graphical causal inference techniques for testing, we need a *specification*.
90+
For this, we must specify the variables that are relevant to the modelling scenario of interest, and any constraints over them.
91+
We must also specify the expected causal relationships between the variables as a directed acyclic graph (DAG).
9192

9293

9394
#.

docs/source/modules/causal_specification.rst

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,46 @@
22
Causal Specification
33
=====================
44

5-
- In causal testing, our units of interest are specific usage **scenarios** of the system-under-test. For example,
6-
when testing an epidemiological computational model, one scenario could focus on the simulation of the spread of a virus in a crowded indoors space.
7-
For this scenario, our causal specification will describe how a number of interventions should **cause** some outputs to change e.g. opening a window should reduce the spread of the virus by some factor.
8-
9-
- In order to isolate the causal effect of the defined interventions, the user needs to express the anticipated cause-effect relationships amongst the inputs and outputs involved in the scenario.
10-
This is achieved using a causal DAG, a simple dot and arrow graph that does not contain any cycles where nodes are random variables that represent the
11-
inputs and outputs in the scenario-under-test, and edges represent causality. For example, ``window --> infection_prob`` encodes the belief that opening or closing the
12-
window should cause the probability of infection to change.
13-
14-
- A causal specification is simply the combination of these components: a series of requirements for the scenario-under-test and a causal DAG representing causality
15-
amongst the inputs and outputs.
16-
17-
- Collectively, the components of the causal specification provide both contextual information in the form of constraints and requirements, as well as causal information in the form of a causal DAG.
18-
It's these components that are used to design statistical experiments that can answer causal questions about the scenario-under-test.
5+
As in traditional software testing, the specification defines the expected behaviour of the system.
6+
In causal testing, this is made up of two components: the modelling scenario and the causal graph.
7+
These components are then used to design statistical experiments that can answer causal questions about the system-under-test.
198

209
1. Modelling Scenario
21-
----------------------
10+
---------------------
2211

23-
- Each scenario is defined as a series of constraints placed over a set of input variables. A constraint is simply a mapping
24-
from an input variable to a specific value or distribution that characterises the scenario in question.
25-
For example, a scenario simulating the spread of a virus in a crowded indoors space would likely place a constraint over the size of room,
26-
the number of windows, and the number of people in the room.
12+
- In causal testing, our units of interest are specific usage **scenarios** of the system-under-test.
13+
For example, when testing an epidemiological computational model, one scenario could focus on the simulation of the spread of a virus through a population.
14+
For this scenario, we may then test how a number of interventions should **cause** some outputs to change e.g. vaccinations should reduce the total number of deaths.
15+
16+
- Each scenario is defined as a series of constraints placed over a set of input variables.
17+
A constraint is simply a mapping from an input variable to a specific value or distribution that characterises the scenario in question.
18+
For example, a scenario simulating the spread of a virus would likely place constraints on the location, population demographics, and who is vaccinated.
2719

2820
- Requirements for this scenario should describe how a particular intervention
29-
(e.g. opening the window, changing the number of people, changing the size of the room etc.) is expected to cause a particular outcome (number of infections, deaths, R0 etc.) to change.
21+
(e.g.changing the number of people, changing who is vaccinated, etc.) is expected to cause a particular outcome (number of infections, deaths, R0, etc.) to change.
3022
The way these requirements are expressed is up to the user, however, it is essential that they focus on the expected effect of an intervention.
3123

32-
2. Causal DAG
33-
--------------
24+
2. Causal Graph
25+
---------------
3426

27+
To isolate the causal effect of the defined interventions, the user needs to express the anticipated cause-effect relationships amongst the inputs and outputs involved in the scenario.
28+
This is done using a directed acyclic graph (DAG) in which nodes represent variables in the system and edges represent causal effects.
3529
In order to apply CI techniques, we need to capture causality amongst the inputs and outputs in the scenario-under-test.
3630
Therefore, for each scenario, the user must define a causal DAG.
37-
As an example, consider the DAG shown below for the `Poisson Line Process example. <https://github.com/CITCOM-project/CausalTestingFramework/tree/main/examples/poisson-line-process>`_
38-
Here, the model has three inputs: ``width``, ``height``, and ``intensity``.
39-
These inputs control the number of lines (``num_lines_abs``) and polygons (``num_shapes_abs``) that are drawn, which then feed into the numbers of lines (``num_lines_unit``) and polygons (``num_shapes_unit``) per unit area.
40-
Note though that the ``num_lines_abs`` does not have a direct causal effect on ``num_shapes_unit``, since the number of polygons per unit area is defined entirely by the total number of polygons and the area of the sampling window.
31+
32+
As an example, consider the DAG shown below for the `vaccinating the elderly example. <https://github.com/CITCOM-project/CausalTestingFramework/tree/main/examples/covasim_/vaccinating_elderly>`_
33+
This modelling scenario has two inputs `vaccine` and `max_doses` and three outputs `cum_vaccinations`, `cum_vaccinated`, and `cum_infections`.
34+
We do not expect `max_doses` to have a causal effect on any of the outputs since this remains constant throughout modelling scenario.
4135

4236
.. container:: zoom-container
4337

44-
.. image:: ../../../examples/poisson-line-process/dag.png
38+
.. image:: ../../../examples/covasim_/vaccinating_elderly/dag.png
4539
:class: zoomable-image
46-
:alt: Schematic diagram of the Poisson Line Process DAG
40+
:alt: Causal DAG of the vaccinating the elderly modelling scenario
4741

48-
.. literalinclude:: ../../../examples/poisson-line-process/dag.dot
42+
.. literalinclude:: ../../../examples/covasim_/vaccinating_elderly/dag.dot
4943
:language: graphviz
50-
:caption: **Figure:** Example Causal DAG for the Poisson line process example.
44+
:caption: **Figure:** Example Causal DAG for the vaccinating the elderly example.
5145

5246
.. raw:: html
5347

docs/source/modules/causal_testing.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Causal Testing
44
A ``causal test`` or ``causal test case`` is the expected change in an outcome that applying an intervention to the input should cause.
55
In this context, an intervention is simply a function which manipulates the input configuration of the scenario-under-test in a way that is expected to cause a change to some outcome.
66
Programmatically, the data structure of causal tests can either be a ``.json`` file or hard-coded (e.g. our :doc:`tutorials <../tutorials>` contain examples of how to
7-
encode your causal tests). Moreover, by ``causal testing`` we refer to the overall process and execution of using the ``causal specification`` and ``causal test case(s)``, including statistical estimators,
7+
encode your causal tests). Moreover, by ``causal testing`` we refer to the overall process and execution of using the ``modelling scenario``, ``causal graph``, and ``causal test case(s)``, including statistical estimators,
88
to determine whether each test case passes or fails relative to the test oracle.
99

1010
Getting Started
@@ -33,17 +33,21 @@ Example: Testing Virus Spread in a Classroom
3333
In the following sections, we describe the end-to-end process of ``causal testing`` for a hypothetical epidemiological computational model in which we are testing the model within a classroom scenario.
3434
In particular, suppose we're interested in how various precautions, such as hand-washing and mask-wearing, can prevent the spread of a virus within a classroom.
3535

36-
1. Specification
36+
1. Modelling Scenario
3737
----------------
3838

39-
For our causal specification, suppose we define the scenario with the following constraints:
39+
For our modelling scenario, suppose we define the scenario with the following constraints:
4040

4141
* ``n_people ~ Uniform(20, 30)`` (There are between 20 and 30 people in the classroom).
4242
* ``environment = Grid(x,y ~ Uniform(20, 40))`` (The classroom is square grid of between 20x20 and 40x40 units).
4343
* ``n_infected_t0 = 1`` (One person is infected initially).
4444
* ``precaution = None`` (No precautions taken).
4545
We also specify the output we are interested in as ``n_infected_t5``\ , the number of people infected after five days of daily one hour lessons.
4646

47+
48+
2. Causal Graph
49+
----------------
50+
4751
Then, we create a simple causal directed acyclic graph (DAG), which represents causality amongst these variables:
4852

4953
.. raw:: html
@@ -135,7 +139,7 @@ Then, we create a simple causal directed acyclic graph (DAG), which represents c
135139
136140
137141
138-
2. Causal Test Cases
142+
3. Causal Test Cases
139143
--------------------
140144

141145
We then define a number of causal test cases to apply to the scenario-under-test. For example, supposing we expect mask wearing and hand washing to have a preventative effect:
@@ -147,14 +151,14 @@ We then define a number of causal test cases to apply to the scenario-under-test
147151

148152
- To run these test cases observationally, we need *valid* observational data for the scenario-under-test. This means we can only use executions with between 20 and 30 people, a square environment of size betwen 20x20 and 40x40, and where a single person was initially infected. In addition, this data must contain executions both with and without the intervention. Next, we need to identify any sources of bias in this data and determine a procedure to counteract them. This is achieved automatically using graphical causal inference techniques that identify a set of variables that can be adjusted to obtain a causal estimate. Finally, for any categorical biasing variables, we need to make sure we have executions corresponding to each category otherwise we have a positivity violation (i.e. missing data). In the worst case, this at least guides the user to an area of the system-under-test that should be executed.
149153

150-
3. Causal Testing
154+
4. Causal Testing
151155
-----------------
152156

153157
- After obtaining suitable test data, we can now apply causal inference. First, as described above, we use our causal graph to identify a set of adjustment variables that mitigate all bias in the data. Next, we use statistical models to adjust for these variables (implementing the statistical procedure necessary to isolate the causal effect) and obtain the desired causal estimate. Depending on the statistical model used, we can also generate 95% confidence intervals (or confidence intervals at any confidence level for that matter).
154158

155159
- In our example, the causal DAG tells us it is necessary to adjust for ``environment`` in order to obtain the causal effect of ``precaution`` on ``n_infected_t5``. Supposing the relationship is linear, we can employ a linear regression model of the form ``n_infected_t5 ~ p0*precaution + p1*environment`` to carry out this adjustment. If we use experimental data, only a single environment is used by design and therefore the adjustment has no impact. However, if we use observational data, the environment may vary and therefore this adjustment will look at the causal effect within different environments and then provide a weighted average, which turns out to be the partial coefficient ``p0``.
156160

157-
4. Test Oracle Procedure
161+
5. Test Oracle Procedure
158162
-------------------------
159163

160164
- After conducting causal inference, all that remains is to ascertain whether the causal effect is expected or not. In our example, this is simply a case of checking whether the causal effect on ``n_infected_t5`` falls within the specified range. However, in the future, we may wish to implement more complex oracles.
23.2 KB
Loading

0 commit comments

Comments
 (0)