Skip to content

Commit 02b4725

Browse files
committed
All examples run
1 parent 940f278 commit 02b4725

File tree

6 files changed

+14
-208
lines changed

6 files changed

+14
-208
lines changed

examples/covasim_/doubling_beta/causal_test_beta.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,20 @@ def doubling_beta_CATE_on_csv(observational_data_path: str, simulate_counterfact
5050
linear_regression_estimator = LinearRegressionEstimator('beta', 0.032, 0.016,
5151
{'avg_age', 'contacts'}, # We use custom adjustment set
5252
'cum_infections',
53-
df=past_execution_df)
53+
df=past_execution_df,
54+
formula="cum_infections ~ beta + np.power(beta, 2) + avg_age + contacts")
5455

5556
# Add squared terms for beta, since it has a quadratic relationship with cumulative infections
56-
linear_regression_estimator.add_squared_term_to_df('beta')
57+
# linear_regression_estimator.add_squared_term_to_df('beta')
5758
causal_test_result = causal_test_engine.execute_test(linear_regression_estimator, causal_test_case, 'ate')
5859

5960
# Repeat for association estimate (no adjustment)
6061
no_adjustment_linear_regression_estimator = LinearRegressionEstimator('beta', 0.032, 0.016,
6162
set(),
6263
'cum_infections',
63-
df=past_execution_df)
64-
no_adjustment_linear_regression_estimator.add_squared_term_to_df('beta')
64+
df=past_execution_df,
65+
formula="cum_infections ~ beta + np.power(beta, 2)")
66+
# no_adjustment_linear_regression_estimator.add_squared_term_to_df('beta')
6567
association_test_result = causal_test_engine.execute_test(no_adjustment_linear_regression_estimator, causal_test_case, 'ate')
6668

6769
# Store results for plotting
@@ -82,8 +84,9 @@ def doubling_beta_CATE_on_csv(observational_data_path: str, simulate_counterfact
8284
counterfactual_linear_regression_estimator = LinearRegressionEstimator('beta', 0.032, 0.016,
8385
{'avg_age', 'contacts'},
8486
'cum_infections',
85-
df=counterfactual_past_execution_df)
86-
counterfactual_linear_regression_estimator.add_squared_term_to_df('beta')
87+
df=counterfactual_past_execution_df,
88+
formula="cum_infections ~ beta + np.power(beta, 2) + avg_age + contacts")
89+
# counterfactual_linear_regression_estimator.add_squared_term_to_df('beta')
8790
counterfactual_causal_test_result = causal_test_engine.execute_test(linear_regression_estimator, causal_test_case, 'ate')
8891
results_dict['counterfactual'] = {'ate': counterfactual_causal_test_result.test_value.value,
8992
'cis': counterfactual_causal_test_result.confidence_intervals,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
intensity_num_shapes_results_random_1000.csv
2+
width_num_shapes_results_random_1000.csv

examples/poisson-line-process/causal_test_poisson.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,18 @@ def test_intensity_num_shapes(
117117
effect_modifiers=causal_test_case.effect_modifier_configuration,
118118
)
119119
else:
120+
square_terms = [f"np.power({t}, 2)" for t in square_terms]
121+
inverse_terms = [f"np.float_power({t}, -1)" for t in inverse_terms]
120122
estimator = LinearRegressionEstimator(
121123
treatment=treatment,
122124
control_value=causal_test_case.control_value,
123125
treatment_value=causal_test_case.treatment_value,
124126
adjustment_set=set(),
125127
outcome=outcome,
126128
df=data,
127-
intercept=0,
128129
effect_modifiers=causal_test_case.effect_modifier_configuration,
130+
formula=f"{outcome} ~ {treatment} + {'+'.join(square_terms + inverse_terms + list([e.name for e in causal_test_case.effect_modifier_configuration]))} -1"
129131
)
130-
for t in square_terms:
131-
estimator.add_squared_term_to_df(t)
132-
for t in inverse_terms:
133-
estimator.add_inverse_term_to_df(t)
134132

135133
# 10. Execute the test
136134
causal_test_result = causal_test_engine.execute_test(

examples/poisson-line-process/intensity_num_shapes_results_random_1000.csv

Lines changed: 0 additions & 41 deletions
This file was deleted.

examples/poisson-line-process/width_num_shapes_results_random_1000.csv

Lines changed: 0 additions & 154 deletions
This file was deleted.

examples/poisson/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@ To run this case study:
77
(instructions are provided in the project README).
88
2. Change directory to `causal_testing/examples/poisson`.
99
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)