Skip to content

Commit ac10df3

Browse files
committed
Fixed examples
1 parent 48b2c68 commit ac10df3

File tree

7 files changed

+25
-13
lines changed

7 files changed

+25
-13
lines changed

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pdf

examples/covasim_/doubling_beta/causal_test_beta.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ def doubling_beta_CATE_on_csv(observational_data_path: str, simulate_counterfact
4747
past_execution_df = pd.read_csv(observational_data_path)
4848
_, causal_test_engine, causal_test_case = engine_setup(observational_data_path)
4949

50-
linear_regression_estimator = LinearRegressionEstimator(('beta',), 0.032, 0.016,
50+
linear_regression_estimator = LinearRegressionEstimator('beta', 0.032, 0.016,
5151
{'avg_age', 'contacts'}, # We use custom adjustment set
52-
('cum_infections',),
52+
'cum_infections',
5353
df=past_execution_df)
5454

5555
# Add squared terms for beta, since it has a quadratic relationship with cumulative infections
5656
linear_regression_estimator.add_squared_term_to_df('beta')
5757
causal_test_result = causal_test_engine.execute_test(linear_regression_estimator, causal_test_case, 'ate')
5858

5959
# Repeat for association estimate (no adjustment)
60-
no_adjustment_linear_regression_estimator = LinearRegressionEstimator(('beta',), 0.032, 0.016,
60+
no_adjustment_linear_regression_estimator = LinearRegressionEstimator('beta', 0.032, 0.016,
6161
set(),
62-
('cum_infections',),
62+
'cum_infections',
6363
df=past_execution_df)
6464
no_adjustment_linear_regression_estimator.add_squared_term_to_df('beta')
6565
association_test_result = causal_test_engine.execute_test(no_adjustment_linear_regression_estimator, causal_test_case, 'ate')
@@ -79,9 +79,9 @@ def doubling_beta_CATE_on_csv(observational_data_path: str, simulate_counterfact
7979
# Repeat causal inference after deleting all rows with treatment value to obtain counterfactual inferences
8080
if simulate_counterfactuals:
8181
counterfactual_past_execution_df = past_execution_df[past_execution_df['beta'] != 0.032]
82-
counterfactual_linear_regression_estimator = LinearRegressionEstimator(('beta',), 0.032, 0.016,
82+
counterfactual_linear_regression_estimator = LinearRegressionEstimator('beta', 0.032, 0.016,
8383
{'avg_age', 'contacts'},
84-
('cum_infections',),
84+
'cum_infections',
8585
df=counterfactual_past_execution_df)
8686
counterfactual_linear_regression_estimator.add_squared_term_to_df('beta')
8787
counterfactual_causal_test_result = causal_test_engine.execute_test(linear_regression_estimator, causal_test_case, 'ate')

examples/covasim_/vaccinating_elderly/causal_test_vaccine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ def experimental_causal_test_vaccinate_elderly(runs_per_test_per_config: int = 3
8585
minimal_adjustment_set = causal_dag.identification(base_test_case)
8686

8787
# 9. Build statistical model
88-
linear_regression_estimator = LinearRegressionEstimator((vaccine.name,), 1, 0,
88+
linear_regression_estimator = LinearRegressionEstimator(vaccine.name, 1, 0,
8989
minimal_adjustment_set,
90-
(outcome_variable.name,))
90+
outcome_variable.name)
9191

9292
# 10. Execute test and save results in dict
9393
causal_test_result = causal_test_engine.execute_test(linear_regression_estimator, causal_test_case, 'ate')

examples/lr91/causal_test_max_conductances.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ def effects_on_APD90(observational_data_path, treatment_var, control_val, treatm
125125

126126
# 9. Obtain the minimal adjustment set from the causal DAG
127127
minimal_adjustment_set = causal_dag.identification(base_test_case)
128-
linear_regression_estimator = LinearRegressionEstimator((treatment_var.name,), treatment_val, control_val,
128+
linear_regression_estimator = LinearRegressionEstimator(treatment_var.name, treatment_val, control_val,
129129
minimal_adjustment_set,
130-
('APD90',)
130+
'APD90'
131131
)
132132

133133
# 10. Run the causal test and print results

examples/lr91/causal_test_max_conductances_test_suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def causal_testing_sensitivity_analysis():
8282
for base_test_case in causal_test_results:
8383
# Place results of test_suite into format required for plotting
8484
results[base_test_case.treatment_variable.name] = \
85-
{"ate": [result.ate for result in causal_test_results[base_test_case]['LinearRegressionEstimator']],
85+
{"ate": [result.test_value.value for result in causal_test_results[base_test_case]['LinearRegressionEstimator']],
8686
"cis": [result.confidence_intervals for result in
8787
causal_test_results[base_test_case]['LinearRegressionEstimator']]}
8888

examples/poisson-line-process/causal_test_poisson.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ def test_intensity_num_shapes(
118118
)
119119
else:
120120
estimator = LinearRegressionEstimator(
121-
treatment=[treatment],
121+
treatment=treatment,
122122
control_value=causal_test_case.control_value,
123123
treatment_value=causal_test_case.treatment_value,
124124
adjustment_set=set(),
125-
outcome=[outcome],
125+
outcome=outcome,
126126
df=data,
127127
intercept=0,
128128
effect_modifiers=causal_test_case.effect_modifier_configuration,

examples/poisson/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Poisson Line Process Case Study: Statistical Metamorphic Testing
2+
Here we demonstrate how the same test suite as in `poisson-line-process` can be coded using the JSON front end.
3+
4+
## How to run
5+
To run this case study:
6+
1. Ensure all project dependencies are installed by running `pip install .` in the top level directory
7+
(instructions are provided in the project README).
8+
2. Change directory to `causal_testing/examples/poisson`.
9+
3. Run the command `python run_causal_tests.py --data_path data.csv --dag_path dag.dot --json_path causal_tests.json`
10+
11+
This should print a series of causal test results and produce two CSV files. `intensity_num_shapes_results_random_1000.csv` corresponds to table 1, and `width_num_shapes_results_random_1000.csv` relates to our findings regarding the relationship of width and `P_u`.

0 commit comments

Comments
 (0)