Skip to content

Commit 1fcda2f

Browse files
committed
Merge branch 'main' of github.com:CITCOM-project/CausalTestingFramework into poisson-process-example
2 parents 5e8334b + 7294150 commit 1fcda2f

File tree

12 files changed

+97
-157
lines changed

12 files changed

+97
-157
lines changed

examples/covasim_/README.md

Lines changed: 0 additions & 127 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Covasim Case Study: Doubling Beta (Infectiousness)
2+
In this case study, we demonstrate how to use the causal testing framework with observational
3+
data collected Covasim to conduct Statistical Metamorphic Testing (SMT) a posteriori. Here, we focus on a set of simple
4+
modelling scenarios that investigate how the infectiousness of the virus (encoded as the parameter beta) affects the
5+
cumulative number of infections over a fixed duration. We also run several causal tests that focus on increasingly
6+
specific causal questions pertaining to more refined metamorphic properties and enabling us to learn more about the
7+
model's behaviour without further executions.
8+
9+
More information about the case study can be found in Section 5.3
10+
(Doubling Beta) of the paper.
11+
12+
## How to run
13+
To run this case study:
14+
1. Ensure all project dependencies are installed by running `pip install .` from the top
15+
level of this directory (instructions are provided in the project README).
16+
2. Change directory to `causal_testing/examples/covasim_/doubling_beta`.
17+
3. Run the command `python causal_test_beta.py`.
18+
19+
This will print out a series of test results covering a range of different causal questions that correspond to those
20+
in Table 3 of the paper.

examples/covasim_/causal_test_beta.py renamed to examples/covasim_/doubling_beta/causal_test_beta.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313
from causal_testing.testing.estimators import LinearRegressionEstimator
1414
from matplotlib.pyplot import rcParams
1515

16-
# Make all graphs publication quality
17-
plt.rcParams["figure.figsize"] = (8, 8)
18-
rc_fonts = {
19-
"font.size": 8,
20-
"figure.figsize": (10, 6),
21-
"text.usetex": True,
22-
"font.family": "serif",
23-
"text.latex.preamble": r"\usepackage{libertine}",
24-
}
25-
rcParams.update(rc_fonts)
16+
# Uncommenting the code below will make all graphs publication quality but requires a suitable latex installation
2617

27-
OBSERVATIONAL_DATA_PATH = "./data/10k_observational_data.csv"
18+
# plt.rcParams["figure.figsize"] = (8, 8)
19+
# rc_fonts = {
20+
# "font.size": 8,
21+
# "figure.figsize": (10, 6),
22+
# "text.usetex": True,
23+
# "font.family": "serif",
24+
# "text.latex.preamble": r"\usepackage{libertine}",
25+
# }
26+
# rcParams.update(rc_fonts)
27+
28+
OBSERVATIONAL_DATA_PATH = "data/10k_observational_data.csv"
2829

2930

3031
def doubling_beta_CATE_on_csv(observational_data_path: str, simulate_counterfactuals: bool = False,
@@ -121,13 +122,13 @@ def doubling_beta_CATEs(observational_data_path: str, simulate_counterfactual: b
121122

122123
# Split df into two age ranges
123124
younger_population_df = past_execution_df.loc[past_execution_df['avg_age'] <= mid_age]
124-
younger_population_df.to_csv("./data/bessemer/younger_population.csv")
125+
younger_population_df.to_csv("./data/younger_population.csv")
125126
older_population_df = past_execution_df.loc[past_execution_df['avg_age'] > mid_age]
126-
older_population_df.to_csv("./data/bessemer/older_population.csv")
127+
older_population_df.to_csv("./data/older_population.csv")
127128

128129
# Repeat analysis on age-specific strata
129-
separated_observational_data_paths = ["./data/bessemer/younger_population.csv",
130-
"./data/bessemer/older_population.csv"]
130+
separated_observational_data_paths = ["./data/younger_population.csv",
131+
"./data/older_population.csv"]
131132

132133
for col, separated_observational_data_path in enumerate(separated_observational_data_paths):
133134
age_data_results_dict = doubling_beta_CATE_on_csv(separated_observational_data_path, simulate_counterfactual,
@@ -146,13 +147,13 @@ def doubling_beta_CATEs(observational_data_path: str, simulate_counterfactual: b
146147

147148
# Save dfs to csv
148149
low_contacts_df = age_stratified_df.loc[age_stratified_df['contacts'] <= mid_contacts]
149-
low_contacts_df.to_csv(f"./data/bessemer/low_contacts_avg_age_{age_stratified_df_avg_age}.csv")
150+
low_contacts_df.to_csv(f"./data/low_contacts_avg_age_{age_stratified_df_avg_age}.csv")
150151
high_contacts_df = age_stratified_df.loc[age_stratified_df['contacts'] > mid_contacts]
151-
high_contacts_df.to_csv(f"./data/bessemer/high_contacts_avg_age_{age_stratified_df_avg_age}.csv")
152+
high_contacts_df.to_csv(f"./data/high_contacts_avg_age_{age_stratified_df_avg_age}.csv")
152153

153-
contact_observational_data_paths = [f"./data/bessemer/low_contacts_avg_age_"
154+
contact_observational_data_paths = [f"./data/low_contacts_avg_age_"
154155
f"{age_stratified_df_avg_age}.csv",
155-
f"./data/bessemer/high_contacts_avg_age_"
156+
f"./data/high_contacts_avg_age_"
156157
f"{age_stratified_df_avg_age}.csv"]
157158

158159
# Compute the CATE for each age-contact group
@@ -181,7 +182,7 @@ def doubling_beta_CATEs(observational_data_path: str, simulate_counterfactual: b
181182

182183
def identification(observational_data_path):
183184
# 1. Read in the Causal DAG
184-
causal_dag = CausalDAG('./dag.dot')
185+
causal_dag = CausalDAG('dag.dot')
185186

186187
# 2. Create variables
187188
pop_size = Input('pop_size', int)
File renamed without changes.
File renamed without changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Covasim Case Study: Prioritising Vaccination for the Elderly
2+
In this case study, we demonstrate how to use causal testing to determine whether prioritising the elderly
3+
has the expected effect on a series of vaccine-related outcomes. Specifically, cumulative infections, vaccines (number
4+
of doses administered), vaccinated (number of agents vaccinated), and maximum doses per agent. As explained in Section
5+
5.3 (Prioritising the elderly for vaccination), we expect that changing the Pfizer vaccine to additionally prioritise
6+
the elderly should cause vaccines and vaccinated to decrease (more restrictive policy), infections to increase (less
7+
are vaccinated), and no change to the maximum doses since this should always be 2.
8+
9+
This case study directly executes Covasim under two input configurations that differ only in their vaccine input: one
10+
is the default Pfizer vaccine, the other is the same vaccine but additionally sub-targeting the elderly using a method
11+
provided in the Covasim vaccine tutorial. We execute each of these input configurations 30 times and repeat this for
12+
four test cases: one focusing on each of the four previously mentioned outputs.
13+
14+
Further details are provided in Section 5.3 (Prioritising the elderly for vaccination) of the paper.
15+
16+
## How to run
17+
To run this case study:
18+
1. Ensure all project dependencies are installed by running `pip install .` from the top
19+
level of this directory (instructions are provided in the project README).
20+
2. Additionally, in order to run Covasim, install version 3.07 by running `pip install covasim==3.0.7`.
21+
3. Change directory to `causal_testing/examples/covasim_/vaccinating_elderly`.
22+
4. Run the command `python causal_test_vaccine.py`.
23+
24+
This will run Covasim as described above and print out the causal test results for the effect of each input on each
25+
output.

examples/covasim_/causal_test_vaccine.py renamed to examples/covasim_/vaccinating_elderly/causal_test_vaccine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def experimental_causal_test_vaccinate_elderly(runs_per_test_per_config: int = 3
2525
"""
2626

2727
# 1. Read in the Causal DAG
28-
causal_dag = CausalDAG('./vaccine_dag.dot')
28+
causal_dag = CausalDAG('dag.dot')
2929

3030
# 2. Create variables
3131
pop_size = Input('pop_size', int)

0 commit comments

Comments
 (0)