1
1
"""This module contains the CausalTestResult class, which is a container for the results of a causal test, and the
2
2
TestValue dataclass.
3
3
"""
4
- from typing import Any , Union
4
+ from typing import Any
5
5
from dataclasses import dataclass
6
6
7
+ from causal_testing .testing .estimators import Estimator
7
8
from causal_testing .specification .variable import Variable
8
9
9
10
@@ -22,21 +23,14 @@ class CausalTestResult:
22
23
23
24
def __init__ (
24
25
self ,
25
- treatment : Variable ,
26
- outcome : Variable ,
27
- treatment_value : Union [int , float , str ],
28
- control_value : Union [int , float , str ],
29
- adjustment_set : set ,
26
+ estimator : Estimator ,
30
27
test_value : TestValue ,
31
28
confidence_intervals : [float , float ] = None ,
32
29
effect_modifier_configuration : {Variable : Any } = None ,
33
30
):
34
- self .treatment = treatment
35
- self .outcome = outcome
36
- self .treatment_value = treatment_value
37
- self .control_value = control_value
38
- if adjustment_set :
39
- self .adjustment_set = adjustment_set
31
+ self .estimator = estimator
32
+ if estimator .adjustment_set :
33
+ self .adjustment_set = estimator .adjustment_set
40
34
else :
41
35
self .adjustment_set = set ()
42
36
self .test_value = test_value
@@ -50,10 +44,10 @@ def __init__(
50
44
def __str__ (self ):
51
45
base_str = (
52
46
f"Causal Test Result\n ==============\n "
53
- f"Treatment: { self .treatment [0 ]} \n "
54
- f"Control value: { self .control_value } \n "
55
- f"Treatment value: { self .treatment_value } \n "
56
- f"Outcome: { self .outcome [0 ]} \n "
47
+ f"Treatment: { self .estimator . treatment [0 ]} \n "
48
+ f"Control value: { self .estimator . control_value } \n "
49
+ f"Treatment value: { self .estimator . treatment_value } \n "
50
+ f"Outcome: { self .estimator . outcome [0 ]} \n "
57
51
f"Adjustment set: { self .adjustment_set } \n "
58
52
f"{ self .test_value .type } : { self .test_value .value } \n "
59
53
)
@@ -67,10 +61,10 @@ def to_dict(self):
67
61
:return: Dictionary containing contents of causal_test_result
68
62
"""
69
63
base_dict = {
70
- "treatment" : self .treatment [0 ],
71
- "control_value" : self .control_value ,
72
- "treatment_value" : self .treatment_value ,
73
- "outcome" : self .outcome [0 ],
64
+ "treatment" : self .estimator . treatment [0 ],
65
+ "control_value" : self .estimator . control_value ,
66
+ "treatment_value" : self .estimator . treatment_value ,
67
+ "outcome" : self .estimator . outcome [0 ],
74
68
"adjustment_set" : self .adjustment_set ,
75
69
"test_value" : self .test_value ,
76
70
}
@@ -94,7 +88,7 @@ def ci_high(self):
94
88
def summary (self ):
95
89
"""Summarise the causal test result as an intuitive sentence."""
96
90
print (
97
- f"The causal effect of changing { self .treatment [0 ]} = { self .control_value } to "
98
- f"{ self .treatment [0 ]} ' = { self .treatment_value } is { self .test_value .value } (95% confidence intervals: "
99
- f"{ self .confidence_intervals } )."
91
+ f"The causal effect of changing { self .estimator . treatment [0 ]} = { self . estimator .control_value } to "
92
+ f"{ self .estimator . treatment [0 ]} ' = { self .estimator . treatment_value } is { self .test_value .value } "
93
+ f"(95% confidence intervals: { self .confidence_intervals } )."
100
94
)
0 commit comments