@@ -81,33 +81,48 @@ def test_program_11_2(self):
81
81
"""Test whether our linear regression implementation produces the same results as program 11.2 (p. 141)."""
82
82
df = self .chapter_11_df
83
83
linear_regression_estimator = LinearRegressionEstimator ("treatments" , None , None , set (), "outcomes" , df )
84
- model = linear_regression_estimator ._run_linear_regression ()
85
84
ate , _ = linear_regression_estimator .estimate_coefficient ()
86
85
87
- self .assertEqual (round (model .params ["Intercept" ] + 90 * model .params ["treatments" ], 1 ), 216.9 )
86
+ self .assertEqual (
87
+ round (
88
+ linear_regression_estimator .model .params ["Intercept" ]
89
+ + 90 * linear_regression_estimator .model .params ["treatments" ],
90
+ 1 ,
91
+ ),
92
+ 216.9 ,
93
+ )
88
94
89
95
# Increasing treatments from 90 to 100 should be the same as 10 times the unit ATE
90
- self .assertTrue (all (round (model .params ["treatments" ], 1 ) == round (ate_single , 1 ) for ate_single in ate ))
96
+ self .assertTrue (
97
+ all (
98
+ round (linear_regression_estimator .model .params ["treatments" ], 1 ) == round (ate_single , 1 )
99
+ for ate_single in ate
100
+ )
101
+ )
91
102
92
103
def test_program_11_3 (self ):
93
104
"""Test whether our linear regression implementation produces the same results as program 11.3 (p. 144)."""
94
105
df = self .chapter_11_df .copy ()
95
106
linear_regression_estimator = LinearRegressionEstimator (
96
107
"treatments" , None , None , set (), "outcomes" , df , formula = "outcomes ~ treatments + I(treatments ** 2)"
97
108
)
98
- model = linear_regression_estimator ._run_linear_regression ()
99
109
ate , _ = linear_regression_estimator .estimate_coefficient ()
100
110
self .assertEqual (
101
111
round (
102
- model .params ["Intercept" ]
103
- + 90 * model .params ["treatments" ]
104
- + 90 * 90 * model .params ["I(treatments ** 2)" ],
112
+ linear_regression_estimator . model .params ["Intercept" ]
113
+ + 90 * linear_regression_estimator . model .params ["treatments" ]
114
+ + 90 * 90 * linear_regression_estimator . model .params ["I(treatments ** 2)" ],
105
115
1 ,
106
116
),
107
117
197.1 ,
108
118
)
109
119
# Increasing treatments from 90 to 100 should be the same as 10 times the unit ATE
110
- self .assertTrue (all (round (model .params ["treatments" ], 3 ) == round (ate_single , 3 ) for ate_single in ate ))
120
+ self .assertTrue (
121
+ all (
122
+ round (linear_regression_estimator .model .params ["treatments" ], 3 ) == round (ate_single , 3 )
123
+ for ate_single in ate
124
+ )
125
+ )
111
126
112
127
def test_program_15_1A (self ):
113
128
"""Test whether our linear regression implementation produces the same results as program 15.1 (p. 163, 184)."""
@@ -149,9 +164,9 @@ def test_program_15_1A(self):
149
164
# for term_a, term_b in terms_to_product:
150
165
# linear_regression_estimator.add_product_term_to_df(term_a, term_b)
151
166
152
- model = linear_regression_estimator ._run_linear_regression ()
153
- self .assertEqual (round (model .params ["qsmk" ], 1 ), 2.6 )
154
- self .assertEqual (round (model .params ["qsmk:smokeintensity" ], 2 ), 0.05 )
167
+ linear_regression_estimator .estimate_coefficient ()
168
+ self .assertEqual (round (linear_regression_estimator . model .params ["qsmk" ], 1 ), 2.6 )
169
+ self .assertEqual (round (linear_regression_estimator . model .params ["qsmk:smokeintensity" ], 2 ), 0.05 )
155
170
156
171
def test_program_15_no_interaction (self ):
157
172
"""Test whether our linear regression implementation produces the same results as program 15.1 (p. 163, 184)
@@ -266,10 +281,10 @@ def test_program_11_2_with_robustness_validation(self):
266
281
"""Test whether our linear regression estimator, as used in test_program_11_2 can correctly estimate robustness."""
267
282
df = self .chapter_11_df .copy ()
268
283
linear_regression_estimator = LinearRegressionEstimator ("treatments" , 100 , 90 , set (), "outcomes" , df )
269
- model = linear_regression_estimator ._run_linear_regression ()
284
+ linear_regression_estimator .estimate_coefficient ()
270
285
271
286
cv = CausalValidator ()
272
- self .assertEqual (round (cv .estimate_robustness (model )["treatments" ], 4 ), 0.7353 )
287
+ self .assertEqual (round (cv .estimate_robustness (linear_regression_estimator . model )["treatments" ], 4 ), 0.7353 )
273
288
274
289
def test_gp (self ):
275
290
df = pd .DataFrame ()
@@ -291,7 +306,7 @@ def test_gp_power(self):
291
306
linear_regression_estimator .gp_formula (seed = 1 , max_order = 0 )
292
307
self .assertEqual (
293
308
linear_regression_estimator .formula ,
294
- "Y ~ I(2.0 *X**2 + 3.8205100524608823e-31 ) - 1" ,
309
+ "Y ~ I(1.9999999999999999 *X**2 - 1.0043240235058056e-116*X + 2.6645352591003757e-15 ) - 1" ,
295
310
)
296
311
ate , (ci_low , ci_high ) = linear_regression_estimator .estimate_ate_calculated ()
297
312
self .assertEqual (round (ate [0 ], 2 ), - 2.00 )
0 commit comments