Closed MalteKurz closed 2 years ago
@PhilippBach Thanks for the review. I adapted the code accordingly. Additionally, I also adapted the corresponding Python PR such that the newly introduced warning is also present there. I also checked your suggested new unit test: I opened a corresponding PR in order to integrate it into this PR and added a comment with a suggestion / extension, see https://github.com/DoubleML/doubleml-for-r/pull/162.
Description
PLR
score='partialling out'
(Equation (4.4) in Chernozhukov et al. (2018)) are not affected by the changes in this PR. However, the naming of the nuisance parameter is changed fromml_g
toml_l
(analogously predictionsg_hat
have been renamed tol_hat
, etc.) to be better in line with Chernozhukov et al. (2018). To make the transition to the new naming smooth, depreciation warnings have been added (see below for an overview of the API changes and examples for the depreciation warnings).score='IV-type'
(Equation (4.3) in Chernozhukov et al. (2018)) the implementation now follows the approach described on pp. C31-C33 in Chernozhukov et al. (2018). This means that an initial estimate fortheta_0
is obtained via the'partialling out'
score. Then an estimate forg_0(X)
is obtained by regressingY - theta_0 * D
onX
. Therefore, an additional learner (not needed to evaluate the score) needs to be provided, i.e., the nuisance functionl_0(X)
(needed for the preliminarytheta_0
estimate) is estimated with learnerml_l
andg_0(X)
with learnerml_g
. To make the transition to the new API (additional learner) smooth, depreciation warnings have been added (see below for an overview of the API changes and examples for the depreciation warnings). Especially, if onlyml_g
is specified but notml_l
, thenml_g = clone(ml_l)
is being used and a warning is being thrown.PLIV
score='partialling out'
(Equation (4.8) in Chernozhukov et al. (2018)) are not affected by the changes in this PR. However, the naming of the nuisance parameter is changed fromml_g
toml_l
(analogously predictionsg_hat
tol_hat
, etc.) to be better in line with Chernozhukov et al. (2018). To make the transition to the new naming smooth, depreciation warnings have been added (see below for examples).score='IV-type'
(Equation (4.7) in Chernozhukov et al. (2018)) is now available for the PLIV model. The estimation of the nuisance parts follows the approach described on p. C33 in Chernozhukov et al. (2018). This means that an initial estimate fortheta_0
is obtained via the'partialling out'
score. Then an estimate forg_0(X)
is obtained by regressingY - theta_0 * D
onX
. Therefore, two additional learners (not needed to evaluate the score) need to be provided, i.e., the nuisance functionsl_0(X)
andr_0(X)
(needed for the preliminarytheta_0
estimate) are estimated with learnerml_l
andml_r
.g_0(X)
is estimated with learnerml_g
.API changes
PLR
DoubleMLPLR$new(obj_dml_data, ml_g, ml_m [, ...])
toDoubleMLPLR$new(obj_dml_data, ml_l, ml_m, ml_g [, ...])
.score='partialling out'
ml_l
&ml_m
are needed.score='IV-type'
ml_l
,ml_m
&ml_g
.function()
s as scoreml_l
&ml_m
are mandatory andml_g
optional.function()
is provided asscore
, it must be of the formfunction(y, d, l_hat, m_hat, g_hat, smpls)
(previouslyfunction(y, d, g_hat, m_hat, smpls)
).PLIV
DoubleMLPLIV$new(obj_dml_data, ml_g, ml_m, ml_r [, ...])
toDoubleMLPLIV$new(obj_dml_data, ml_g, ml_m, ml_r, ml_g [, ...])
.score='partialling out'
ml_l
,ml_m
&ml_r
are needed.score='IV-type'
ml_l
,ml_m
,ml_r
&ml_g
.function()
s as scoreml_l
,ml_m
&ml_r
are mandatory andml_g
optional.function()
is provided asscore
, it must be of the formfunction(y, z, d, l_hat, m_hat, r_hat, g_hat, smpls)
(previouslyfunction(y, z, d, g_hat, m_hat, r_hat, smpls)
).Depreciation warnings for the API changes for
DoubleMLPLR
andDoubleMLPLIV
score='partialling out'
and if the learners are provided as positional arguments, nothing changed.-- >Note however that, if, besides the learner, other arguments have also been provided as positional arguments, the changed API causes exceptions because the additional learner was added as fourth (PLR) / fifth (PLIV) argument
score='partialling out'
and keyword argumentsml_g
andml_m
(old API naming), the learner provided forml_g
is used forml_l
and a warning is issued.score='IV-type'
and keyword argumentsml_g
andml_m
(old API naming), the learner provided forml_g
is also used forml_l
and a warning is issued. (Note it is first redirected toml_l
and then cloned toml_g
)score='IV-type'
and only two learners as positional arguments, the learner provided forml_g
is used forml_l
and a warning is issued.score='partialling out'
, the methodsset_ml_nuisance_params
andtune
redirectml_g
toml_l
.Miscellaneous
score
is set to afunction()
, it will in the future be called with keyword-arguments only (instead of positional arguments). This way is "safer" and in some way indirectly checks (up to a certain degree) that the signature of the function is as expected (see docu entry of the argumentscore
for the expected signature). This was implemented for all model classes PLR, PLIV, IRM & IIVMPR Checklist
R CMD check
and all (unit) tests (see our contributing guidelines for details).