Skip to content

Commit 270e77b

Browse files
committed
remove boot coefs from irm model
1 parent 4a3278c commit 270e77b

10 files changed

+48
-99
lines changed

doubleml/irm/tests/_utils_iivm_manual.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ def iivm_orth(g_hat0, g_hat1, m_hat, r_hat0, r_hat1, u_hat0, u_hat1, w_hat0, w_h
205205
def boot_iivm(y, d, z, thetas, ses, all_g_hat0, all_g_hat1, all_m_hat, all_r_hat0, all_r_hat1,
206206
all_smpls, score, bootstrap, n_rep_boot,
207207
n_rep=1, apply_cross_fitting=True, normalize_ipw=True):
208-
all_boot_theta = list()
209208
all_boot_t_stat = list()
210209
for i_rep in range(n_rep):
211210
smpls = all_smpls[i_rep]
@@ -215,17 +214,15 @@ def boot_iivm(y, d, z, thetas, ses, all_g_hat0, all_g_hat1, all_m_hat, all_r_hat
215214
test_index = smpls[0][1]
216215
n_obs = len(test_index)
217216
weights = draw_weights(bootstrap, n_rep_boot, n_obs)
218-
boot_theta, boot_t_stat = boot_iivm_single_split(
217+
boot_t_stat = boot_iivm_single_split(
219218
thetas[i_rep], y, d, z,
220219
all_g_hat0[i_rep], all_g_hat1[i_rep], all_m_hat[i_rep], all_r_hat0[i_rep], all_r_hat1[i_rep],
221220
smpls, score, ses[i_rep], weights, n_rep_boot, apply_cross_fitting, normalize_ipw)
222-
all_boot_theta.append(boot_theta)
223221
all_boot_t_stat.append(boot_t_stat)
224222

225-
boot_theta = np.hstack(all_boot_theta)
226223
boot_t_stat = np.hstack(all_boot_t_stat)
227224

228-
return boot_theta, boot_t_stat
225+
return boot_t_stat
229226

230227

231228
def boot_iivm_single_split(theta, y, d, z, g_hat0_list, g_hat1_list, m_hat_list, r_hat0_list, r_hat1_list,
@@ -234,7 +231,6 @@ def boot_iivm_single_split(theta, y, d, z, g_hat0_list, g_hat1_list, m_hat_list,
234231
u_hat0, u_hat1, w_hat0, w_hat1, g_hat0, g_hat1, m_hat, r_hat0, r_hat1 = compute_iivm_residuals(
235232
y, d, g_hat0_list, g_hat1_list, m_hat_list, r_hat0_list, r_hat1_list, smpls)
236233

237-
m_hat_adj = np.full_like(m_hat, np.nan, dtype='float64')
238234
if normalize_ipw:
239235
m_hat_adj = _normalize_ipw(m_hat, d)
240236
else:
@@ -258,6 +254,6 @@ def boot_iivm_single_split(theta, y, d, z, g_hat0_list, g_hat1_list, m_hat_list,
258254
+ np.divide(np.multiply(z, w_hat1), m_hat_adj)
259255
- np.divide(np.multiply(1.-z, w_hat0), 1.-m_hat_adj))
260256

261-
boot_theta, boot_t_stat = boot_manual(psi, J, smpls, se, weights, n_rep, apply_cross_fitting)
257+
boot_t_stat = boot_manual(psi, J, smpls, se, weights, n_rep, apply_cross_fitting)
262258

263-
return boot_theta, boot_t_stat
259+
return boot_t_stat

doubleml/irm/tests/_utils_irm_manual.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ def irm_orth(g_hat0, g_hat1, m_hat, p_hat, u_hat0, u_hat1, d, score):
174174
def boot_irm(y, d, thetas, ses, all_g_hat0, all_g_hat1, all_m_hat, all_p_hat,
175175
all_smpls, score, bootstrap, n_rep_boot,
176176
n_rep=1, apply_cross_fitting=True, normalize_ipw=True):
177-
all_boot_theta = list()
178177
all_boot_t_stat = list()
179178
for i_rep in range(n_rep):
180179
smpls = all_smpls[i_rep]
@@ -184,17 +183,15 @@ def boot_irm(y, d, thetas, ses, all_g_hat0, all_g_hat1, all_m_hat, all_p_hat,
184183
test_index = smpls[0][1]
185184
n_obs = len(test_index)
186185
weights = draw_weights(bootstrap, n_rep_boot, n_obs)
187-
boot_theta, boot_t_stat = boot_irm_single_split(
186+
boot_t_stat = boot_irm_single_split(
188187
thetas[i_rep], y, d,
189188
all_g_hat0[i_rep], all_g_hat1[i_rep], all_m_hat[i_rep], all_p_hat[i_rep], smpls,
190189
score, ses[i_rep], weights, n_rep_boot, apply_cross_fitting, normalize_ipw)
191-
all_boot_theta.append(boot_theta)
192190
all_boot_t_stat.append(boot_t_stat)
193191

194-
boot_theta = np.hstack(all_boot_theta)
195192
boot_t_stat = np.hstack(all_boot_t_stat)
196193

197-
return boot_theta, boot_t_stat
194+
return boot_t_stat
198195

199196

200197
def boot_irm_single_split(theta, y, d, g_hat0_list, g_hat1_list, m_hat_list, p_hat_list,
@@ -233,9 +230,9 @@ def boot_irm_single_split(theta, y, d, g_hat0_list, g_hat1_list, m_hat_list, p_h
233230
np.multiply(p_hat, (1.-m_hat_adj))) \
234231
- theta * np.divide(d, p_hat)
235232

236-
boot_theta, boot_t_stat = boot_manual(psi, J, smpls, se, weights, n_rep_boot, apply_cross_fitting)
233+
boot_t_stat = boot_manual(psi, J, smpls, se, weights, n_rep_boot, apply_cross_fitting)
237234

238-
return boot_theta, boot_t_stat
235+
return boot_t_stat
239236

240237

241238
def fit_sensitivity_elements_irm(y, d, all_coef, predictions, score, n_rep):

doubleml/irm/tests/test_iivm.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,15 @@ def dml_iivm_fixture(generate_data_iivm, learner, score, normalize_ipw, trimming
9292

9393
for bootstrap in boot_methods:
9494
np.random.seed(3141)
95-
boot_theta, boot_t_stat = boot_iivm(y, d, z, res_manual['thetas'], res_manual['ses'],
96-
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
97-
res_manual['all_m_hat'], res_manual['all_r_hat0'], res_manual['all_r_hat1'],
98-
all_smpls, score, bootstrap, n_rep_boot,
99-
normalize_ipw=normalize_ipw)
95+
boot_t_stat = boot_iivm(y, d, z, res_manual['thetas'], res_manual['ses'],
96+
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
97+
res_manual['all_m_hat'], res_manual['all_r_hat0'], res_manual['all_r_hat1'],
98+
all_smpls, score, bootstrap, n_rep_boot,
99+
normalize_ipw=normalize_ipw)
100100

101101
np.random.seed(3141)
102102
dml_iivm_obj.bootstrap(method=bootstrap, n_rep_boot=n_rep_boot)
103-
res_dict['boot_coef' + bootstrap] = dml_iivm_obj.boot_coef
104103
res_dict['boot_t_stat' + bootstrap] = dml_iivm_obj.boot_t_stat
105-
res_dict['boot_coef' + bootstrap + '_manual'] = boot_theta
106104
res_dict['boot_t_stat' + bootstrap + '_manual'] = boot_t_stat
107105

108106
return res_dict
@@ -125,9 +123,6 @@ def test_dml_iivm_se(dml_iivm_fixture):
125123
@pytest.mark.ci
126124
def test_dml_iivm_boot(dml_iivm_fixture):
127125
for bootstrap in dml_iivm_fixture['boot_methods']:
128-
assert np.allclose(dml_iivm_fixture['boot_coef' + bootstrap],
129-
dml_iivm_fixture['boot_coef' + bootstrap + '_manual'],
130-
rtol=1e-9, atol=1e-4)
131126
assert np.allclose(dml_iivm_fixture['boot_t_stat' + bootstrap],
132127
dml_iivm_fixture['boot_t_stat' + bootstrap + '_manual'],
133128
rtol=1e-9, atol=1e-4)

doubleml/irm/tests/test_iivm_classifier.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,15 @@ def dml_iivm_classifier_fixture(generate_data_iivm_binary, learner, score, norma
8484

8585
for bootstrap in boot_methods:
8686
np.random.seed(3141)
87-
boot_theta, boot_t_stat = boot_iivm(y, d, z, res_manual['thetas'], res_manual['ses'],
88-
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
89-
res_manual['all_m_hat'], res_manual['all_r_hat0'], res_manual['all_r_hat1'],
90-
all_smpls, score, bootstrap, n_rep_boot,
91-
normalize_ipw=normalize_ipw)
87+
boot_t_stat = boot_iivm(y, d, z, res_manual['thetas'], res_manual['ses'],
88+
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
89+
res_manual['all_m_hat'], res_manual['all_r_hat0'], res_manual['all_r_hat1'],
90+
all_smpls, score, bootstrap, n_rep_boot,
91+
normalize_ipw=normalize_ipw)
9292

9393
np.random.seed(3141)
9494
dml_iivm_obj.bootstrap(method=bootstrap, n_rep_boot=n_rep_boot)
95-
res_dict['boot_coef' + bootstrap] = dml_iivm_obj.boot_coef
9695
res_dict['boot_t_stat' + bootstrap] = dml_iivm_obj.boot_t_stat
97-
res_dict['boot_coef' + bootstrap + '_manual'] = boot_theta
9896
res_dict['boot_t_stat' + bootstrap + '_manual'] = boot_t_stat
9997

10098
return res_dict
@@ -117,9 +115,6 @@ def test_dml_iivm_se(dml_iivm_classifier_fixture):
117115
@pytest.mark.ci
118116
def test_dml_iivm_boot(dml_iivm_classifier_fixture):
119117
for bootstrap in dml_iivm_classifier_fixture['boot_methods']:
120-
assert np.allclose(dml_iivm_classifier_fixture['boot_coef' + bootstrap],
121-
dml_iivm_classifier_fixture['boot_coef' + bootstrap + '_manual'],
122-
rtol=1e-9, atol=1e-4)
123118
assert np.allclose(dml_iivm_classifier_fixture['boot_t_stat' + bootstrap],
124119
dml_iivm_classifier_fixture['boot_t_stat' + bootstrap + '_manual'],
125120
rtol=1e-9, atol=1e-4)

doubleml/irm/tests/test_iivm_subgroups.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,15 @@ def dml_iivm_subgroups_fixture(generate_data_iivm, learner, score, normalize_ipw
104104

105105
for bootstrap in boot_methods:
106106
np.random.seed(3141)
107-
boot_theta, boot_t_stat = boot_iivm(y, d, z, res_manual['thetas'], res_manual['ses'],
108-
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
109-
res_manual['all_m_hat'], res_manual['all_r_hat0'], res_manual['all_r_hat1'],
110-
all_smpls, score, bootstrap, n_rep_boot,
111-
normalize_ipw=normalize_ipw)
107+
boot_t_stat = boot_iivm(y, d, z, res_manual['thetas'], res_manual['ses'],
108+
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
109+
res_manual['all_m_hat'], res_manual['all_r_hat0'], res_manual['all_r_hat1'],
110+
all_smpls, score, bootstrap, n_rep_boot,
111+
normalize_ipw=normalize_ipw)
112112

113113
np.random.seed(3141)
114114
dml_iivm_obj.bootstrap(method=bootstrap, n_rep_boot=n_rep_boot)
115-
res_dict['boot_coef' + bootstrap] = dml_iivm_obj.boot_coef
116115
res_dict['boot_t_stat' + bootstrap] = dml_iivm_obj.boot_t_stat
117-
res_dict['boot_coef' + bootstrap + '_manual'] = boot_theta
118116
res_dict['boot_t_stat' + bootstrap + '_manual'] = boot_t_stat
119117

120118
return res_dict
@@ -137,9 +135,6 @@ def test_dml_iivm_subgroups_se(dml_iivm_subgroups_fixture):
137135
@pytest.mark.ci
138136
def test_dml_iivm_subgroups_boot(dml_iivm_subgroups_fixture):
139137
for bootstrap in dml_iivm_subgroups_fixture['boot_methods']:
140-
assert np.allclose(dml_iivm_subgroups_fixture['boot_coef' + bootstrap],
141-
dml_iivm_subgroups_fixture['boot_coef' + bootstrap + '_manual'],
142-
rtol=1e-9, atol=1e-4)
143138
assert np.allclose(dml_iivm_subgroups_fixture['boot_t_stat' + bootstrap],
144139
dml_iivm_subgroups_fixture['boot_t_stat' + bootstrap + '_manual'],
145140
rtol=1e-9, atol=1e-4)

doubleml/irm/tests/test_iivm_tune.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,15 @@ def dml_iivm_fixture(generate_data_iivm, learner_g, learner_m, learner_r, score,
157157

158158
for bootstrap in boot_methods:
159159
np.random.seed(3141)
160-
boot_theta, boot_t_stat = boot_iivm(y, d, z, res_manual['thetas'], res_manual['ses'],
161-
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
162-
res_manual['all_m_hat'], res_manual['all_r_hat0'], res_manual['all_r_hat1'],
163-
all_smpls, score, bootstrap, n_rep_boot,
164-
normalize_ipw=normalize_ipw)
160+
boot_t_stat = boot_iivm(y, d, z, res_manual['thetas'], res_manual['ses'],
161+
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
162+
res_manual['all_m_hat'], res_manual['all_r_hat0'], res_manual['all_r_hat1'],
163+
all_smpls, score, bootstrap, n_rep_boot,
164+
normalize_ipw=normalize_ipw)
165165

166166
np.random.seed(3141)
167167
dml_iivm_obj.bootstrap(method=bootstrap, n_rep_boot=n_rep_boot)
168-
res_dict['boot_coef' + bootstrap] = dml_iivm_obj.boot_coef
169168
res_dict['boot_t_stat' + bootstrap] = dml_iivm_obj.boot_t_stat
170-
res_dict['boot_coef' + bootstrap + '_manual'] = boot_theta
171169
res_dict['boot_t_stat' + bootstrap + '_manual'] = boot_t_stat
172170

173171
return res_dict
@@ -190,9 +188,6 @@ def test_dml_iivm_se(dml_iivm_fixture):
190188
@pytest.mark.ci
191189
def test_dml_iivm_boot(dml_iivm_fixture):
192190
for bootstrap in dml_iivm_fixture['boot_methods']:
193-
assert np.allclose(dml_iivm_fixture['boot_coef' + bootstrap],
194-
dml_iivm_fixture['boot_coef' + bootstrap + '_manual'],
195-
rtol=1e-9, atol=1e-4)
196191
assert np.allclose(dml_iivm_fixture['boot_t_stat' + bootstrap],
197192
dml_iivm_fixture['boot_t_stat' + bootstrap + '_manual'],
198193
rtol=1e-9, atol=1e-4)

doubleml/irm/tests/test_irm.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,18 @@ def dml_irm_fixture(generate_data_irm, learner, score, normalize_ipw, trimming_t
109109

110110
for bootstrap in boot_methods:
111111
np.random.seed(3141)
112-
boot_theta, boot_t_stat = boot_irm(y, d, res_manual['thetas'], res_manual['ses'],
113-
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
114-
res_manual['all_m_hat'], res_manual['all_p_hat'],
115-
all_smpls, score, bootstrap, n_rep_boot,
116-
normalize_ipw=normalize_ipw)
112+
boot_t_stat = boot_irm(y, d, res_manual['thetas'], res_manual['ses'],
113+
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
114+
res_manual['all_m_hat'], res_manual['all_p_hat'],
115+
all_smpls, score, bootstrap, n_rep_boot,
116+
normalize_ipw=normalize_ipw)
117117

118118
np.random.seed(3141)
119119
dml_irm_obj.bootstrap(method=bootstrap, n_rep_boot=n_rep_boot)
120120
np.random.seed(3141)
121121
dml_irm_obj_ext.bootstrap(method=bootstrap, n_rep_boot=n_rep_boot)
122-
res_dict['boot_coef' + bootstrap] = dml_irm_obj.boot_coef
123122
res_dict['boot_t_stat' + bootstrap] = dml_irm_obj.boot_t_stat
124-
res_dict['boot_coef' + bootstrap + '_manual'] = boot_theta
125123
res_dict['boot_t_stat' + bootstrap + '_manual'] = boot_t_stat
126-
res_dict['boot_coef' + bootstrap + '_ext'] = dml_irm_obj_ext.boot_coef
127124
res_dict['boot_t_stat' + bootstrap + '_ext'] = dml_irm_obj_ext.boot_t_stat
128125

129126
# sensitivity tests
@@ -163,12 +160,6 @@ def test_dml_irm_se(dml_irm_fixture):
163160
@pytest.mark.ci
164161
def test_dml_irm_boot(dml_irm_fixture):
165162
for bootstrap in dml_irm_fixture['boot_methods']:
166-
assert np.allclose(dml_irm_fixture['boot_coef' + bootstrap],
167-
dml_irm_fixture['boot_coef' + bootstrap + '_manual'],
168-
rtol=1e-9, atol=1e-4)
169-
assert np.allclose(dml_irm_fixture['boot_coef' + bootstrap],
170-
dml_irm_fixture['boot_coef' + bootstrap + '_ext'],
171-
rtol=1e-9, atol=1e-4)
172163
assert np.allclose(dml_irm_fixture['boot_t_stat' + bootstrap],
173164
dml_irm_fixture['boot_t_stat' + bootstrap + '_manual'],
174165
rtol=1e-9, atol=1e-4)

doubleml/irm/tests/test_irm_classifier.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,15 @@ def dml_irm_classifier_fixture(generate_data_irm_binary, learner, score, normali
8383

8484
for bootstrap in boot_methods:
8585
np.random.seed(3141)
86-
boot_theta, boot_t_stat = boot_irm(y, d, res_manual['thetas'], res_manual['ses'],
87-
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
88-
res_manual['all_m_hat'], res_manual['all_p_hat'],
89-
all_smpls, score, bootstrap, n_rep_boot,
90-
normalize_ipw=normalize_ipw)
86+
boot_t_stat = boot_irm(y, d, res_manual['thetas'], res_manual['ses'],
87+
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
88+
res_manual['all_m_hat'], res_manual['all_p_hat'],
89+
all_smpls, score, bootstrap, n_rep_boot,
90+
normalize_ipw=normalize_ipw)
9191

9292
np.random.seed(3141)
9393
dml_irm_obj.bootstrap(method=bootstrap, n_rep_boot=n_rep_boot)
94-
res_dict['boot_coef' + bootstrap] = dml_irm_obj.boot_coef
9594
res_dict['boot_t_stat' + bootstrap] = dml_irm_obj.boot_t_stat
96-
res_dict['boot_coef' + bootstrap + '_manual'] = boot_theta
9795
res_dict['boot_t_stat' + bootstrap + '_manual'] = boot_t_stat
9896

9997
return res_dict
@@ -116,9 +114,6 @@ def test_dml_irm_se(dml_irm_classifier_fixture):
116114
@pytest.mark.ci
117115
def test_dml_irm_boot(dml_irm_classifier_fixture):
118116
for bootstrap in dml_irm_classifier_fixture['boot_methods']:
119-
assert np.allclose(dml_irm_classifier_fixture['boot_coef' + bootstrap],
120-
dml_irm_classifier_fixture['boot_coef' + bootstrap + '_manual'],
121-
rtol=1e-9, atol=1e-4)
122117
assert np.allclose(dml_irm_classifier_fixture['boot_t_stat' + bootstrap],
123118
dml_irm_classifier_fixture['boot_t_stat' + bootstrap + '_manual'],
124119
rtol=1e-9, atol=1e-4)

doubleml/irm/tests/test_irm_tune.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,15 @@ def dml_irm_fixture(generate_data_irm, learner_g, learner_m, score, normalize_ip
123123

124124
for bootstrap in boot_methods:
125125
np.random.seed(3141)
126-
boot_theta, boot_t_stat = boot_irm(y, d, res_manual['thetas'], res_manual['ses'],
127-
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
128-
res_manual['all_m_hat'], res_manual['all_p_hat'],
129-
all_smpls, score, bootstrap, n_rep_boot,
130-
normalize_ipw=normalize_ipw)
126+
boot_t_stat = boot_irm(y, d, res_manual['thetas'], res_manual['ses'],
127+
res_manual['all_g_hat0'], res_manual['all_g_hat1'],
128+
res_manual['all_m_hat'], res_manual['all_p_hat'],
129+
all_smpls, score, bootstrap, n_rep_boot,
130+
normalize_ipw=normalize_ipw)
131131

132132
np.random.seed(3141)
133133
dml_irm_obj.bootstrap(method=bootstrap, n_rep_boot=n_rep_boot)
134-
res_dict['boot_coef' + bootstrap] = dml_irm_obj.boot_coef
135134
res_dict['boot_t_stat' + bootstrap] = dml_irm_obj.boot_t_stat
136-
res_dict['boot_coef' + bootstrap + '_manual'] = boot_theta
137135
res_dict['boot_t_stat' + bootstrap + '_manual'] = boot_t_stat
138136

139137
return res_dict
@@ -156,9 +154,6 @@ def test_dml_irm_se(dml_irm_fixture):
156154
@pytest.mark.ci
157155
def test_dml_irm_boot(dml_irm_fixture):
158156
for bootstrap in dml_irm_fixture['boot_methods']:
159-
assert np.allclose(dml_irm_fixture['boot_coef' + bootstrap],
160-
dml_irm_fixture['boot_coef' + bootstrap + '_manual'],
161-
rtol=1e-9, atol=1e-4)
162157
assert np.allclose(dml_irm_fixture['boot_t_stat' + bootstrap],
163158
dml_irm_fixture['boot_t_stat' + bootstrap + '_manual'],
164159
rtol=1e-9, atol=1e-4)

0 commit comments

Comments
 (0)