DoubleML 0.8.0__tar.gz → 0.8.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. DoubleML-0.8.2/DoubleML.egg-info/PKG-INFO +162 -0
  2. DoubleML-0.8.2/PKG-INFO +162 -0
  3. {DoubleML-0.8.0 → DoubleML-0.8.2}/README.md +1 -1
  4. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/__init__.py +2 -2
  5. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/datasets.py +123 -71
  6. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/did.py +5 -1
  7. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/did_cs.py +7 -2
  8. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/_utils_did_cs_manual.py +1 -1
  9. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/_utils_did_manual.py +1 -1
  10. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/test_did_cs_external_predictions.py +2 -1
  11. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/test_did_external_predictions.py +2 -1
  12. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/double_ml.py +64 -97
  13. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/qte.py +76 -9
  14. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_qte.py +36 -10
  15. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/_utils_dml_cv_predict.py +5 -20
  16. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_datasets.py +15 -4
  17. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_evaluate_learner.py +15 -12
  18. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_exceptions.py +39 -9
  19. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_multiway_cluster.py +71 -3
  20. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_return_types.py +44 -44
  21. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/_checks.py +109 -0
  22. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/_estimation.py +8 -2
  23. {DoubleML-0.8.0 → DoubleML-0.8.2}/setup.py +3 -3
  24. DoubleML-0.8.0/DoubleML.egg-info/PKG-INFO +0 -159
  25. DoubleML-0.8.0/PKG-INFO +0 -159
  26. {DoubleML-0.8.0 → DoubleML-0.8.2}/DoubleML.egg-info/SOURCES.txt +0 -0
  27. {DoubleML-0.8.0 → DoubleML-0.8.2}/DoubleML.egg-info/dependency_links.txt +0 -0
  28. {DoubleML-0.8.0 → DoubleML-0.8.2}/DoubleML.egg-info/requires.txt +0 -0
  29. {DoubleML-0.8.0 → DoubleML-0.8.2}/DoubleML.egg-info/top_level.txt +0 -0
  30. {DoubleML-0.8.0 → DoubleML-0.8.2}/LICENSE +0 -0
  31. {DoubleML-0.8.0 → DoubleML-0.8.2}/MANIFEST.in +0 -0
  32. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/__init__.py +0 -0
  33. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/__init__.py +0 -0
  34. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/conftest.py +0 -0
  35. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/test_did.py +0 -0
  36. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/test_did_cs.py +0 -0
  37. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/test_did_cs_tune.py +0 -0
  38. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/test_did_tune.py +0 -0
  39. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/double_ml_data.py +0 -0
  40. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/double_ml_framework.py +0 -0
  41. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/double_ml_score_mixins.py +0 -0
  42. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/__init__.py +0 -0
  43. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/cvar.py +0 -0
  44. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/iivm.py +0 -0
  45. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/irm.py +0 -0
  46. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/lpq.py +0 -0
  47. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/pq.py +0 -0
  48. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/ssm.py +0 -0
  49. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/__init__.py +0 -0
  50. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_cvar_manual.py +0 -0
  51. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_iivm_manual.py +0 -0
  52. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_irm_manual.py +0 -0
  53. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_lpq_manual.py +0 -0
  54. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_pq_manual.py +0 -0
  55. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_qte_manual.py +0 -0
  56. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_ssm_manual.py +0 -0
  57. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/conftest.py +0 -0
  58. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_cvar.py +0 -0
  59. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_cvar_tune.py +0 -0
  60. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_iivm.py +0 -0
  61. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_iivm_classifier.py +0 -0
  62. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_iivm_external_predictions.py +0 -0
  63. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_iivm_subgroups.py +0 -0
  64. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_iivm_tune.py +0 -0
  65. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_irm.py +0 -0
  66. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_irm_classifier.py +0 -0
  67. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_irm_external_predictions.py +0 -0
  68. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_irm_tune.py +0 -0
  69. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_irm_weighted_scores.py +0 -0
  70. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_irm_with_missings.py +0 -0
  71. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_lpq.py +0 -0
  72. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_lpq_external_predictions.py +0 -0
  73. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_lpq_tune.py +0 -0
  74. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_pq.py +0 -0
  75. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_pq_external_predictions.py +0 -0
  76. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_pq_tune.py +0 -0
  77. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_qte_exceptions.py +0 -0
  78. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_ssm.py +0 -0
  79. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_ssm_exceptions.py +0 -0
  80. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_ssm_tune.py +0 -0
  81. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/__init__.py +0 -0
  82. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/pliv.py +0 -0
  83. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/plr.py +0 -0
  84. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/__init__.py +0 -0
  85. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/_utils_pliv_manual.py +0 -0
  86. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/_utils_pliv_partial_x_manual.py +0 -0
  87. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/_utils_pliv_partial_xz_manual.py +0 -0
  88. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/_utils_pliv_partial_z_manual.py +0 -0
  89. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/_utils_plr_manual.py +0 -0
  90. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/conftest.py +0 -0
  91. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv.py +0 -0
  92. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_external_predictions.py +0 -0
  93. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_partial_x.py +0 -0
  94. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_partial_x_tune.py +0 -0
  95. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_partial_xz.py +0 -0
  96. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_partial_xz_tune.py +0 -0
  97. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_partial_z.py +0 -0
  98. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_partial_z_tune.py +0 -0
  99. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_tune.py +0 -0
  100. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr.py +0 -0
  101. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_classifier.py +0 -0
  102. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_external_predictions.py +0 -0
  103. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_multi_treat.py +0 -0
  104. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_reestimate_from_scores.py +0 -0
  105. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_rep_cross.py +0 -0
  106. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_set_ml_nuisance_pars.py +0 -0
  107. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_set_smpls_externally.py +0 -0
  108. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_tune.py +0 -0
  109. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/__init__.py +0 -0
  110. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/_utils.py +0 -0
  111. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/_utils_boot.py +0 -0
  112. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/_utils_cluster.py +0 -0
  113. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/_utils_doubleml_sensitivity_manual.py +0 -0
  114. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/conftest.py +0 -0
  115. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_cv_predict.py +0 -0
  116. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_dml_data.py +0 -0
  117. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_exceptions_ext_preds.py +0 -0
  118. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_framework.py +0 -0
  119. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_framework_coverage.py +0 -0
  120. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_framework_exceptions.py +0 -0
  121. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_framework_pval_corrections.py +0 -0
  122. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_model_defaults.py +0 -0
  123. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_nonlinear_cluster.py +0 -0
  124. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_nonlinear_score_mixin.py +0 -0
  125. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_package.py +0 -0
  126. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_scores.py +0 -0
  127. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_sensitivity.py +0 -0
  128. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_sensitivity_cluster.py +0 -0
  129. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_set_ml_nuisance_params.py +0 -0
  130. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_set_sample_splitting.py +0 -0
  131. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/__init__.py +0 -0
  132. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/_plots.py +0 -0
  133. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/blp.py +0 -0
  134. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/dummy_learners.py +0 -0
  135. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/gain_statistics.py +0 -0
  136. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/policytree.py +0 -0
  137. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/resampling.py +0 -0
  138. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/__init__.py +0 -0
  139. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/_utils_blp_manual.py +0 -0
  140. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/_utils_pt_manual.py +0 -0
  141. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/test_blp.py +0 -0
  142. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/test_dummy_learners.py +0 -0
  143. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/test_exceptions_gain_statistics.py +0 -0
  144. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/test_policytree.py +0 -0
  145. {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/test_var_est_and_aggregation.py +0 -0
  146. {DoubleML-0.8.0 → DoubleML-0.8.2}/pytest.ini +0 -0
  147. {DoubleML-0.8.0 → DoubleML-0.8.2}/setup.cfg +0 -0
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.1
2
+ Name: DoubleML
3
+ Version: 0.8.2
4
+ Summary: Double Machine Learning in Python
5
+ Home-page: https://docs.doubleml.org
6
+ Author: Bach, P., Chernozhukov, V., Kurz, M. S., and Spindler, M.
7
+ Maintainer: Malte S. Kurz
8
+ Maintainer-email: malte.simon.kurz@uni-hamburg.de
9
+ License: UNKNOWN
10
+ Project-URL: Documentation, https://docs.doubleml.org
11
+ Project-URL: Source Code, https://github.com/DoubleML/doubleml-for-py
12
+ Project-URL: Bug Tracker, https://github.com/DoubleML/doubleml-for-py/issues
13
+ Platform: UNKNOWN
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: License :: OSI Approved :: BSD License
20
+ Classifier: Operating System :: OS Independent
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+
25
+ # DoubleML - Double Machine Learning in Python <a href="https://docs.doubleml.org"><img src="https://raw.githubusercontent.com/DoubleML/doubleml-for-py/main/doc/logo.png" align="right" width = "120" /></a>
26
+
27
+ [![build](https://github.com/DoubleML/doubleml-for-py/workflows/build/badge.svg)](https://github.com/DoubleML/doubleml-for-py/actions?query=workflow%3Abuild)
28
+ [![PyPI version](https://badge.fury.io/py/DoubleML.svg)](https://badge.fury.io/py/DoubleML)
29
+ [![Conda Version](https://img.shields.io/conda/vn/conda-forge/doubleml.svg)](https://anaconda.org/conda-forge/doubleml)
30
+ [![codecov](https://codecov.io/gh/DoubleML/doubleml-for-py/branch/main/graph/badge.svg?token=0BjlFPgdGk)](https://codecov.io/gh/DoubleML/doubleml-for-py)
31
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/1c08ec7d782c451784293c996537de14)](https://www.codacy.com/gh/DoubleML/doubleml-for-py/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=DoubleML/doubleml-for-py&amp;utm_campaign=Badge_Grade)
32
+ [![Python version](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org/)
33
+
34
+ The Python package **DoubleML** provides an implementation of the double / debiased machine learning framework of
35
+ [Chernozhukov et al. (2018)](https://doi.org/10.1111/ectj.12097).
36
+ It is built on top of [scikit-learn](https://scikit-learn.org) (Pedregosa et al., 2011).
37
+
38
+ Note that the Python package was developed together with an R twin based on [mlr3](https://mlr3.mlr-org.com/).
39
+ The R package is also available on [GitHub](https://github.com/DoubleML/doubleml-for-r) and
40
+ [![CRAN Version](https://www.r-pkg.org/badges/version/DoubleML)](https://cran.r-project.org/package=DoubleML).
41
+
42
+ ## Documentation and Maintenance
43
+
44
+ Documentation and website: [https://docs.doubleml.org/](https://docs.doubleml.org/)
45
+
46
+ **DoubleML** is currently maintained by
47
+ [@MalteKurz](https://github.com/MalteKurz), [@PhilippBach](https://github.com/PhilippBach) and [@SvenKlaassen](https://github.com/SvenKlaassen).
48
+
49
+ Bugs can be reported to the issue tracker at
50
+ [https://github.com/DoubleML/doubleml-for-py/issues](https://github.com/DoubleML/doubleml-for-py/issues).
51
+
52
+ ## Main Features
53
+
54
+ Double / debiased machine learning [(Chernozhukov et al. (2018))](https://doi.org/10.1111/ectj.12097) for
55
+
56
+ - Partially linear regression models (PLR)
57
+ - Partially linear IV regression models (PLIV)
58
+ - Interactive regression models (IRM)
59
+ - Interactive IV regression models (IIVM)
60
+
61
+ The object-oriented implementation of DoubleML is very flexible.
62
+ The model classes `DoubleMLPLR`, `DoubleMLPLIV`, `DoubleMLIRM` and `DoubleIIVM` implement the estimation of the nuisance
63
+ functions via machine learning methods and the computation of the Neyman orthogonal score function.
64
+ All other functionalities are implemented in the abstract base class `DoubleML`.
65
+ In particular functionalities to estimate double machine learning models and to perform statistical inference via the
66
+ methods `fit`, `bootstrap`, `confint`, `p_adjust` and `tune`.
67
+ This object-oriented implementation allows a high flexibility for the model specification in terms of ...
68
+
69
+ - ... the machine learners for the nuisance functions,
70
+ - ... the resampling schemes,
71
+ - ... the double machine learning algorithm,
72
+ - ... the Neyman orthogonal score functions,
73
+ - ...
74
+
75
+ It further can be readily extended with regards to
76
+
77
+ - ... new model classes that come with Neyman orthogonal score functions being linear in the target parameter,
78
+ - ... alternative score functions via callables,
79
+ - ... alternative resampling schemes,
80
+ - ...
81
+
82
+ ![An overview of the OOP structure of the DoubleML package is given in the graphic available at https://github.com/DoubleML/doubleml-for-py/blob/main/doc/oop.svg](https://raw.githubusercontent.com/DoubleML/doubleml-for-py/main/doc/oop.svg)
83
+
84
+ ## Installation
85
+
86
+ **DoubleML** requires
87
+
88
+ - Python
89
+ - sklearn
90
+ - numpy
91
+ - scipy
92
+ - pandas
93
+ - statsmodels
94
+ - joblib
95
+
96
+ To install DoubleML with pip use
97
+
98
+ ```
99
+ pip install -U DoubleML
100
+ ```
101
+
102
+ DoubleML can be installed from source via
103
+
104
+ ```
105
+ git clone git@github.com:DoubleML/doubleml-for-py.git
106
+ cd doubleml-for-py
107
+ pip install --editable .
108
+ ```
109
+
110
+ Detailed [installation instructions](https://docs.doubleml.org/stable/intro/install.html) can be found in the documentation.
111
+
112
+ ## Contributing
113
+ DoubleML is a community effort.
114
+ Everyone is welcome to contribute.
115
+ To get started for your first contribution we recommend reading our
116
+ [contributing guidelines](https://github.com/DoubleML/doubleml-for-py/blob/main/CONTRIBUTING.md)
117
+ and our
118
+ [code of conduct](https://github.com/DoubleML/doubleml-for-py/blob/main/CODE_OF_CONDUCT.md).
119
+
120
+ ## Citation
121
+
122
+ If you use the DoubleML package a citation is highly appreciated:
123
+
124
+ Bach, P., Chernozhukov, V., Kurz, M. S., and Spindler, M. (2022), DoubleML - An
125
+ Object-Oriented Implementation of Double Machine Learning in Python,
126
+ Journal of Machine Learning Research, 23(53): 1-6,
127
+ [https://www.jmlr.org/papers/v23/21-0862.html](https://www.jmlr.org/papers/v23/21-0862.html).
128
+
129
+ Bibtex-entry:
130
+
131
+ ```
132
+ @article{DoubleML2022,
133
+ title = {{DoubleML} -- {A}n Object-Oriented Implementation of Double Machine Learning in {P}ython},
134
+ author = {Philipp Bach and Victor Chernozhukov and Malte S. Kurz and Martin Spindler},
135
+ journal = {Journal of Machine Learning Research},
136
+ year = {2022},
137
+ volume = {23},
138
+ number = {53},
139
+ pages = {1--6},
140
+ url = {http://jmlr.org/papers/v23/21-0862.html}
141
+ }
142
+ ```
143
+
144
+ ## Acknowledgements
145
+
146
+ Funding by the Deutsche Forschungsgemeinschaft (DFG, German Research
147
+ Foundation) is acknowledged – Project Number 431701914.
148
+
149
+ ## References
150
+
151
+ Bach, P., Chernozhukov, V., Kurz, M. S., and Spindler, M. (2022), DoubleML - An
152
+ Object-Oriented Implementation of Double Machine Learning in Python,
153
+ Journal of Machine Learning Research, 23(53): 1-6,
154
+ [https://www.jmlr.org/papers/v23/21-0862.html](https://www.jmlr.org/papers/v23/21-0862.html).
155
+
156
+ Chernozhukov, V., Chetverikov, D., Demirer, M., Duflo, E., Hansen, C., Newey, W. and Robins, J. (2018),
157
+ Double/debiased machine learning for treatment and structural parameters. The Econometrics Journal, 21: C1-C68. doi:[10.1111/ectj.12097](https://doi.org/10.1111/ectj.12097).
158
+
159
+ Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., Blondel, M., Prettenhofer, P., Weiss, R., Dubourg, V., Vanderplas, J., Passos, A., Cournapeau, D., Brucher, M., Perrot, M. and Duchesnay, E. (2011),
160
+ Scikit-learn: Machine Learning in Python. Journal of Machine Learning Research, 12: 2825--2830, [https://jmlr.csail.mit.edu/papers/v12/pedregosa11a.html](https://jmlr.csail.mit.edu/papers/v12/pedregosa11a.html).
161
+
162
+
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.1
2
+ Name: DoubleML
3
+ Version: 0.8.2
4
+ Summary: Double Machine Learning in Python
5
+ Home-page: https://docs.doubleml.org
6
+ Author: Bach, P., Chernozhukov, V., Kurz, M. S., and Spindler, M.
7
+ Maintainer: Malte S. Kurz
8
+ Maintainer-email: malte.simon.kurz@uni-hamburg.de
9
+ License: UNKNOWN
10
+ Project-URL: Documentation, https://docs.doubleml.org
11
+ Project-URL: Source Code, https://github.com/DoubleML/doubleml-for-py
12
+ Project-URL: Bug Tracker, https://github.com/DoubleML/doubleml-for-py/issues
13
+ Platform: UNKNOWN
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: License :: OSI Approved :: BSD License
20
+ Classifier: Operating System :: OS Independent
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+
25
+ # DoubleML - Double Machine Learning in Python <a href="https://docs.doubleml.org"><img src="https://raw.githubusercontent.com/DoubleML/doubleml-for-py/main/doc/logo.png" align="right" width = "120" /></a>
26
+
27
+ [![build](https://github.com/DoubleML/doubleml-for-py/workflows/build/badge.svg)](https://github.com/DoubleML/doubleml-for-py/actions?query=workflow%3Abuild)
28
+ [![PyPI version](https://badge.fury.io/py/DoubleML.svg)](https://badge.fury.io/py/DoubleML)
29
+ [![Conda Version](https://img.shields.io/conda/vn/conda-forge/doubleml.svg)](https://anaconda.org/conda-forge/doubleml)
30
+ [![codecov](https://codecov.io/gh/DoubleML/doubleml-for-py/branch/main/graph/badge.svg?token=0BjlFPgdGk)](https://codecov.io/gh/DoubleML/doubleml-for-py)
31
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/1c08ec7d782c451784293c996537de14)](https://www.codacy.com/gh/DoubleML/doubleml-for-py/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=DoubleML/doubleml-for-py&amp;utm_campaign=Badge_Grade)
32
+ [![Python version](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org/)
33
+
34
+ The Python package **DoubleML** provides an implementation of the double / debiased machine learning framework of
35
+ [Chernozhukov et al. (2018)](https://doi.org/10.1111/ectj.12097).
36
+ It is built on top of [scikit-learn](https://scikit-learn.org) (Pedregosa et al., 2011).
37
+
38
+ Note that the Python package was developed together with an R twin based on [mlr3](https://mlr3.mlr-org.com/).
39
+ The R package is also available on [GitHub](https://github.com/DoubleML/doubleml-for-r) and
40
+ [![CRAN Version](https://www.r-pkg.org/badges/version/DoubleML)](https://cran.r-project.org/package=DoubleML).
41
+
42
+ ## Documentation and Maintenance
43
+
44
+ Documentation and website: [https://docs.doubleml.org/](https://docs.doubleml.org/)
45
+
46
+ **DoubleML** is currently maintained by
47
+ [@MalteKurz](https://github.com/MalteKurz), [@PhilippBach](https://github.com/PhilippBach) and [@SvenKlaassen](https://github.com/SvenKlaassen).
48
+
49
+ Bugs can be reported to the issue tracker at
50
+ [https://github.com/DoubleML/doubleml-for-py/issues](https://github.com/DoubleML/doubleml-for-py/issues).
51
+
52
+ ## Main Features
53
+
54
+ Double / debiased machine learning [(Chernozhukov et al. (2018))](https://doi.org/10.1111/ectj.12097) for
55
+
56
+ - Partially linear regression models (PLR)
57
+ - Partially linear IV regression models (PLIV)
58
+ - Interactive regression models (IRM)
59
+ - Interactive IV regression models (IIVM)
60
+
61
+ The object-oriented implementation of DoubleML is very flexible.
62
+ The model classes `DoubleMLPLR`, `DoubleMLPLIV`, `DoubleMLIRM` and `DoubleIIVM` implement the estimation of the nuisance
63
+ functions via machine learning methods and the computation of the Neyman orthogonal score function.
64
+ All other functionalities are implemented in the abstract base class `DoubleML`.
65
+ In particular functionalities to estimate double machine learning models and to perform statistical inference via the
66
+ methods `fit`, `bootstrap`, `confint`, `p_adjust` and `tune`.
67
+ This object-oriented implementation allows a high flexibility for the model specification in terms of ...
68
+
69
+ - ... the machine learners for the nuisance functions,
70
+ - ... the resampling schemes,
71
+ - ... the double machine learning algorithm,
72
+ - ... the Neyman orthogonal score functions,
73
+ - ...
74
+
75
+ It further can be readily extended with regards to
76
+
77
+ - ... new model classes that come with Neyman orthogonal score functions being linear in the target parameter,
78
+ - ... alternative score functions via callables,
79
+ - ... alternative resampling schemes,
80
+ - ...
81
+
82
+ ![An overview of the OOP structure of the DoubleML package is given in the graphic available at https://github.com/DoubleML/doubleml-for-py/blob/main/doc/oop.svg](https://raw.githubusercontent.com/DoubleML/doubleml-for-py/main/doc/oop.svg)
83
+
84
+ ## Installation
85
+
86
+ **DoubleML** requires
87
+
88
+ - Python
89
+ - sklearn
90
+ - numpy
91
+ - scipy
92
+ - pandas
93
+ - statsmodels
94
+ - joblib
95
+
96
+ To install DoubleML with pip use
97
+
98
+ ```
99
+ pip install -U DoubleML
100
+ ```
101
+
102
+ DoubleML can be installed from source via
103
+
104
+ ```
105
+ git clone git@github.com:DoubleML/doubleml-for-py.git
106
+ cd doubleml-for-py
107
+ pip install --editable .
108
+ ```
109
+
110
+ Detailed [installation instructions](https://docs.doubleml.org/stable/intro/install.html) can be found in the documentation.
111
+
112
+ ## Contributing
113
+ DoubleML is a community effort.
114
+ Everyone is welcome to contribute.
115
+ To get started for your first contribution we recommend reading our
116
+ [contributing guidelines](https://github.com/DoubleML/doubleml-for-py/blob/main/CONTRIBUTING.md)
117
+ and our
118
+ [code of conduct](https://github.com/DoubleML/doubleml-for-py/blob/main/CODE_OF_CONDUCT.md).
119
+
120
+ ## Citation
121
+
122
+ If you use the DoubleML package a citation is highly appreciated:
123
+
124
+ Bach, P., Chernozhukov, V., Kurz, M. S., and Spindler, M. (2022), DoubleML - An
125
+ Object-Oriented Implementation of Double Machine Learning in Python,
126
+ Journal of Machine Learning Research, 23(53): 1-6,
127
+ [https://www.jmlr.org/papers/v23/21-0862.html](https://www.jmlr.org/papers/v23/21-0862.html).
128
+
129
+ Bibtex-entry:
130
+
131
+ ```
132
+ @article{DoubleML2022,
133
+ title = {{DoubleML} -- {A}n Object-Oriented Implementation of Double Machine Learning in {P}ython},
134
+ author = {Philipp Bach and Victor Chernozhukov and Malte S. Kurz and Martin Spindler},
135
+ journal = {Journal of Machine Learning Research},
136
+ year = {2022},
137
+ volume = {23},
138
+ number = {53},
139
+ pages = {1--6},
140
+ url = {http://jmlr.org/papers/v23/21-0862.html}
141
+ }
142
+ ```
143
+
144
+ ## Acknowledgements
145
+
146
+ Funding by the Deutsche Forschungsgemeinschaft (DFG, German Research
147
+ Foundation) is acknowledged – Project Number 431701914.
148
+
149
+ ## References
150
+
151
+ Bach, P., Chernozhukov, V., Kurz, M. S., and Spindler, M. (2022), DoubleML - An
152
+ Object-Oriented Implementation of Double Machine Learning in Python,
153
+ Journal of Machine Learning Research, 23(53): 1-6,
154
+ [https://www.jmlr.org/papers/v23/21-0862.html](https://www.jmlr.org/papers/v23/21-0862.html).
155
+
156
+ Chernozhukov, V., Chetverikov, D., Demirer, M., Duflo, E., Hansen, C., Newey, W. and Robins, J. (2018),
157
+ Double/debiased machine learning for treatment and structural parameters. The Econometrics Journal, 21: C1-C68. doi:[10.1111/ectj.12097](https://doi.org/10.1111/ectj.12097).
158
+
159
+ Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., Blondel, M., Prettenhofer, P., Weiss, R., Dubourg, V., Vanderplas, J., Passos, A., Cournapeau, D., Brucher, M., Perrot, M. and Duchesnay, E. (2011),
160
+ Scikit-learn: Machine Learning in Python. Journal of Machine Learning Research, 12: 2825--2830, [https://jmlr.csail.mit.edu/papers/v12/pedregosa11a.html](https://jmlr.csail.mit.edu/papers/v12/pedregosa11a.html).
161
+
162
+
@@ -5,7 +5,7 @@
5
5
  [![Conda Version](https://img.shields.io/conda/vn/conda-forge/doubleml.svg)](https://anaconda.org/conda-forge/doubleml)
6
6
  [![codecov](https://codecov.io/gh/DoubleML/doubleml-for-py/branch/main/graph/badge.svg?token=0BjlFPgdGk)](https://codecov.io/gh/DoubleML/doubleml-for-py)
7
7
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/1c08ec7d782c451784293c996537de14)](https://www.codacy.com/gh/DoubleML/doubleml-for-py/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=DoubleML/doubleml-for-py&amp;utm_campaign=Badge_Grade)
8
- [![Python version](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11-blue)](https://www.python.org/)
8
+ [![Python version](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue)](https://www.python.org/)
9
9
 
10
10
  The Python package **DoubleML** provides an implementation of the double / debiased machine learning framework of
11
11
  [Chernozhukov et al. (2018)](https://doi.org/10.1111/ectj.12097).
@@ -1,4 +1,4 @@
1
- from pkg_resources import get_distribution
1
+ import importlib.metadata
2
2
 
3
3
  from .double_ml_framework import concat
4
4
  from .double_ml_framework import DoubleMLFramework
@@ -36,4 +36,4 @@ __all__ = ['concat',
36
36
  'DoubleMLPolicyTree',
37
37
  'DoubleMLSSM']
38
38
 
39
- __version__ = get_distribution('doubleml').version
39
+ __version__ = importlib.metadata.version('doubleml')
@@ -1,5 +1,6 @@
1
1
  import pandas as pd
2
2
  import numpy as np
3
+ import warnings
3
4
 
4
5
  from scipy.linalg import toeplitz
5
6
  from scipy.optimize import minimize_scalar
@@ -81,12 +82,12 @@ def fetch_bonus(return_type='DoubleMLData', polynomial_features=False):
81
82
  doi:`10.1111/ectj.12097 <https://doi.org/10.1111/ectj.12097>`_.
82
83
  """
83
84
  url = 'https://raw.githubusercontent.com/VC2015/DMLonGitHub/master/penn_jae.dat'
84
- raw_data = pd.read_csv(url, delim_whitespace=True)
85
+ raw_data = pd.read_csv(url, sep='\s+')
85
86
 
86
87
  ind = (raw_data['tg'] == 0) | (raw_data['tg'] == 4)
87
88
  data = raw_data.copy()[ind]
88
89
  data.reset_index(inplace=True)
89
- data['tg'].replace(4, 1, inplace=True)
90
+ data['tg'] = data['tg'].replace(4, 1)
90
91
  data['inuidur1'] = np.log(data['inuidur1'])
91
92
 
92
93
  # variable dep as factor (dummy encoding)
@@ -895,11 +896,11 @@ def make_did_SZ2020(n_obs=500, dgp_type=1, cross_sectional_data=False, return_ty
895
896
  raise ValueError('Invalid return_type.')
896
897
 
897
898
 
898
- def make_confounded_irm_data(n_obs=500, theta=5.0, cf_y=0.04, cf_d=0.04):
899
+ def make_confounded_irm_data(n_obs=500, theta=0.0, gamma_a=0.127, beta_a=0.58, linear=False, **kwargs):
899
900
  """
900
901
  Generates counfounded data from an interactive regression model.
901
902
 
902
- The data generating process is defined as follows (similar to the Monte Carlo simulation used
903
+ The data generating process is defined as follows (inspired by the Monte Carlo simulation used
903
904
  in Sant'Anna and Zhao (2020)).
904
905
 
905
906
  Let :math:`X= (X_1, X_2, X_3, X_4, X_5)^T \\sim \\mathcal{N}(0, \\Sigma)`, where :math:`\\Sigma` corresponds
@@ -924,14 +925,22 @@ def make_confounded_irm_data(n_obs=500, theta=5.0, cf_y=0.04, cf_d=0.04):
924
925
 
925
926
  .. math::
926
927
 
927
- m(X, A) = P(D=1|X,A) = 0.5 + \\gamma_A \\cdot A
928
+ m(X, A) = P(D=1|X,A) = p(Z) + \\gamma_A \\cdot A
929
+
930
+ where
931
+
932
+ .. math::
933
+
934
+ p(Z) &= \\frac{\\exp(f_{ps}(Z))}{1 + \\exp(f_{ps}(Z))},
935
+
936
+ f_{ps}(Z) &= 0.75 \\cdot (-Z_1 + 0.1 \\cdot Z_2 -0.25 \\cdot Z_3 - 0.1 \\cdot Z_4).
928
937
 
929
938
  and generate the treatment :math:`D = 1\\{m(X, A) \\ge U\\}` with :math:`U \\sim \\mathcal{U}[0, 1]`.
930
939
  Since :math:`A` is independent of :math:`X`, the short form of the propensity score is given as
931
940
 
932
941
  .. math::
933
942
 
934
- P(D=1|X) = 0.5.
943
+ P(D=1|X) = p(Z).
935
944
 
936
945
  Further, generate the outcome of interest :math:`Y` as
937
946
 
@@ -939,7 +948,7 @@ def make_confounded_irm_data(n_obs=500, theta=5.0, cf_y=0.04, cf_d=0.04):
939
948
 
940
949
  Y &= \\theta \\cdot D (Z_5 + 1) + g(Z) + \\beta_A \\cdot A + \\varepsilon
941
950
 
942
- g(Z) &= 210 + 27.4 \\cdot Z_1 +13.7 \\cdot (Z_2 + Z_3 + Z_4)
951
+ g(Z) &= 2.5 + 0.74 \\cdot Z_1 + 0.25 \\cdot Z_2 + 0.137 \\cdot (Z_3 + Z_4)
943
952
 
944
953
  where :math:`\\varepsilon \\sim \\mathcal{N}(0,5)`.
945
954
  This implies an average treatment effect of :math:`\\theta`. Additionally, the long and short forms of
@@ -952,13 +961,13 @@ def make_confounded_irm_data(n_obs=500, theta=5.0, cf_y=0.04, cf_d=0.04):
952
961
  \\mathbb{E}[Y|D, X] &= (\\theta + \\beta_A \\frac{\\mathrm{Cov}(A, D(Z_5 + 1))}{\\mathrm{Var}(D(Z_5 + 1))})
953
962
  \\cdot D (Z_5 + 1) + g(Z).
954
963
 
955
- Consequently, the strength of confounding is determined via :math:`\\gamma_A` and :math:`\\beta_A`.
956
- Both are chosen to obtain the desired confounding of the outcome and Riesz Representer (in sample).
964
+ Consequently, the strength of confounding is determined via :math:`\\gamma_A` and :math:`\\beta_A`, which can be
965
+ set via the parameters ``gamma_a`` and ``beta_a``.
957
966
 
958
- The observed data is given as :math:`W = (Y, D, X)`.
967
+ The observed data is given as :math:`W = (Y, D, Z)`.
959
968
  Further, orcale values of the confounder :math:`A`, the transformed covariated :math:`Z`,
960
- the potential outcomes of :math:`Y`, the coefficients :math:`\\gamma_a`, :math:`\\beta_a`, the
961
- long and short forms of the main regression and the propensity score
969
+ the potential outcomes of :math:`Y`, the long and short forms of the main regression and the propensity score and
970
+ in sample versions of the confounding parameters :math:`cf_d` and :math:`cf_y` (for ATE and ATTE)
962
971
  are returned in a dictionary.
963
972
 
964
973
  Parameters
@@ -968,13 +977,16 @@ def make_confounded_irm_data(n_obs=500, theta=5.0, cf_y=0.04, cf_d=0.04):
968
977
  Default is ``500``.
969
978
  theta : float or int
970
979
  Average treatment effect.
971
- Default is ``5.0``.
972
- cf_y : float
973
- Percentage of the residual variation of the outcome explained by latent/confounding variable.
974
- Default is ``0.04``.
975
- cf_d : float
976
- Percentage gains in the variation of the Riesz Representer generated by latent/confounding variable.
977
- Default is ``0.04``.
980
+ Default is ``0.0``.
981
+ gamma_a : float
982
+ Coefficient of the unobserved confounder in the propensity score.
983
+ Default is ``0.127``.
984
+ beta_a : float
985
+ Coefficient of the unobserved confounder in the outcome regression.
986
+ Default is ``0.58``.
987
+ linear : bool
988
+ If ``True``, the Z will be set to X, such that the underlying (short) models are linear/logistic.
989
+ Default is ``False``.
978
990
 
979
991
  Returns
980
992
  -------
@@ -988,82 +1000,122 @@ def make_confounded_irm_data(n_obs=500, theta=5.0, cf_y=0.04, cf_d=0.04):
988
1000
  doi:`10.1016/j.jeconom.2020.06.003 <https://doi.org/10.1016/j.jeconom.2020.06.003>`_.
989
1001
  """
990
1002
  c = 0.0 # the confounding strength is only valid for c=0
991
- dim_x = 5
1003
+ xi = 0.75
1004
+ dim_x = kwargs.get('dim_x', 5)
1005
+ trimming_threshold = kwargs.get('trimming_threshold', 0.01)
1006
+ var_eps_y = kwargs.get('var_eps_y', 1.0)
1007
+
1008
+ # Specification of main regression function
1009
+ def f_reg(w):
1010
+ res = 2.5 + 0.74*w[:, 0] + 0.25 * w[:, 1] + 0.137*(w[:, 2] + w[:, 3])
1011
+ return res
992
1012
 
1013
+ # Specification of prop score function
1014
+ def f_ps(w, xi):
1015
+ res = xi*(-w[:, 0] + 0.1*w[:, 1] - 0.25*w[:, 2] - 0.1*w[:, 3])
1016
+ return res
993
1017
  # observed covariates
994
1018
  cov_mat = toeplitz([np.power(c, k) for k in range(dim_x)])
995
1019
  x = np.random.multivariate_normal(np.zeros(dim_x), cov_mat, size=[n_obs, ])
996
-
997
1020
  z_tilde_1 = np.exp(0.5*x[:, 0])
998
1021
  z_tilde_2 = 10 + x[:, 1] / (1 + np.exp(x[:, 0]))
999
1022
  z_tilde_3 = (0.6 + x[:, 0] * x[:, 2]/25)**3
1000
1023
  z_tilde_4 = (20 + x[:, 1] + x[:, 3])**2
1001
-
1002
- z_tilde = np.column_stack((z_tilde_1, z_tilde_2, z_tilde_3, z_tilde_4, x[:, 4:]))
1024
+ z_tilde_5 = x[:, 4]
1025
+ z_tilde = np.column_stack((z_tilde_1, z_tilde_2, z_tilde_3, z_tilde_4, z_tilde_5))
1003
1026
  z = (z_tilde - np.mean(z_tilde, axis=0)) / np.std(z_tilde, axis=0)
1004
-
1005
1027
  # error terms and unobserved confounder
1006
- var_eps_y = 5
1007
1028
  eps_y = np.random.normal(loc=0, scale=np.sqrt(var_eps_y), size=n_obs)
1008
-
1009
1029
  # unobserved confounder
1010
1030
  a_bounds = (-1, 1)
1011
1031
  a = np.random.uniform(low=a_bounds[0], high=a_bounds[1], size=n_obs)
1032
+ var_a = np.square(a_bounds[1] - a_bounds[0]) / 12
1012
1033
 
1013
- # get the required impact of the confounder on the propensity score
1014
- possible_coefs = np.arange(0.001, 0.4999, 0.001)
1015
- gamma_a = possible_coefs[(np.arctanh(2*possible_coefs) / (2*possible_coefs)) - 1 - cf_d/(1 - cf_d) >= 0][0]
1016
-
1017
- # compute short and long form of riesz representer
1018
- m_long = 0.5 + gamma_a*a
1019
- m_short = 0.5 * np.ones_like(m_long)
1034
+ # Choose the features used in the models
1035
+ if linear:
1036
+ features_ps = x
1037
+ features_reg = x
1038
+ else:
1039
+ features_ps = z
1040
+ features_reg = z
1020
1041
 
1042
+ p = np.exp(f_ps(features_ps, xi)) / (1 + np.exp(f_ps(features_ps, xi)))
1043
+ # compute short and long form of propensity score
1044
+ m_long = p + gamma_a*a
1045
+ m_short = p
1046
+ # check propensity score bounds
1047
+ if np.any(m_long < trimming_threshold) or np.any(m_long > 1.0 - trimming_threshold):
1048
+ m_long = np.clip(m_long, trimming_threshold, 1.0 - trimming_threshold)
1049
+ m_short = np.clip(m_short, trimming_threshold, 1.0 - trimming_threshold)
1050
+ warnings.warn(f'Propensity score is close to 0 or 1. '
1051
+ f'Trimming is at {trimming_threshold} and {1.0-trimming_threshold} is applied')
1052
+ # generate treatment based on long form
1021
1053
  u = np.random.uniform(low=0, high=1, size=n_obs)
1022
1054
  d = 1.0 * (m_long >= u)
1023
-
1024
- # short and long version of g
1025
- g_partial_reg = 210 + 27.4*z[:, 0] + 13.7*(z[:, 1] + z[:, 2] + z[:, 3])
1026
-
1027
- dx = d * (x[:, 4] + 1)
1028
- d1x = x[:, 4] + 1
1029
- var_dx = np.var(dx)
1030
- cov_adx = np.cov(a, dx)[0, 1]
1031
-
1032
- def f_g(beta_a):
1033
- g_diff = beta_a * (a - cov_adx / var_dx)
1034
- y_diff = eps_y + g_diff
1035
- return np.square(np.mean(np.square(g_diff)) / np.mean(np.square(y_diff)) - cf_y)
1036
- beta_a = minimize_scalar(f_g).x
1037
-
1055
+ # add treatment heterogeneity
1056
+ d1x = z[:, 4] + 1
1057
+ var_dx = np.var(d*(d1x))
1058
+ cov_adx = gamma_a * var_a
1059
+ # Outcome regression
1060
+ g_partial_reg = f_reg(features_reg)
1061
+ # short model
1038
1062
  g_short_d0 = g_partial_reg
1039
1063
  g_short_d1 = (theta + beta_a * cov_adx / var_dx) * d1x + g_partial_reg
1040
1064
  g_short = d * g_short_d1 + (1.0-d) * g_short_d0
1041
-
1065
+ # long model
1042
1066
  g_long_d0 = g_partial_reg + beta_a * a
1043
1067
  g_long_d1 = theta * d1x + g_partial_reg + beta_a * a
1044
1068
  g_long = d * g_long_d1 + (1.0-d) * g_long_d0
1045
-
1046
- y0 = g_long_d0 + eps_y
1047
- y1 = g_long_d1 + eps_y
1048
-
1049
- y = d * y1 + (1.0-d) * y0
1050
-
1051
- oracle_values = {'g_long': g_long,
1052
- 'g_short': g_short,
1053
- 'm_long': m_long,
1054
- 'm_short': m_short,
1055
- 'gamma_a': gamma_a,
1056
- 'beta_a': beta_a,
1057
- 'a': a,
1058
- 'y0': y0,
1059
- 'y1': y1,
1060
- 'z': z}
1061
-
1062
- res_dict = {'x': x,
1063
- 'y': y,
1064
- 'd': d,
1065
- 'oracle_values': oracle_values}
1066
-
1069
+ # Potential outcomes
1070
+ y_0 = g_long_d0 + eps_y
1071
+ y_1 = g_long_d1 + eps_y
1072
+ # Realized outcome
1073
+ y = d * y_1 + (1.0-d) * y_0
1074
+ # In-sample values for confounding strength
1075
+ explained_residual_variance = np.square(g_long - g_short)
1076
+ residual_variance = np.square(y - g_short)
1077
+ cf_y = np.mean(explained_residual_variance) / np.mean(residual_variance)
1078
+ # compute the Riesz representation
1079
+ treated_weight = d / np.mean(d)
1080
+ untreated_weight = (1.0 - d) / np.mean(d)
1081
+ # Odds ratios
1082
+ propensity_ratio_long = m_long / (1.0 - m_long)
1083
+ rr_long_ate = d / m_long - (1.0 - d) / (1.0 - m_long)
1084
+ rr_long_atte = treated_weight - np.multiply(untreated_weight, propensity_ratio_long)
1085
+ propensity_ratio_short = m_short / (1.0 - m_short)
1086
+ rr_short_ate = d / m_short - (1.0 - d) / (1.0 - m_short)
1087
+ rr_short_atte = treated_weight - np.multiply(untreated_weight, propensity_ratio_short)
1088
+ cf_d_ate = (np.mean(1/(m_long * (1 - m_long))) - np.mean(1/(m_short * (1 - m_short)))) / np.mean(1/(m_long * (1 - m_long)))
1089
+ cf_d_atte = (np.mean(propensity_ratio_long) - np.mean(propensity_ratio_short)) / np.mean(propensity_ratio_long)
1090
+ if (beta_a == 0) | (gamma_a == 0):
1091
+ rho_ate = 0.0
1092
+ rho_atte = 0.0
1093
+ else:
1094
+ rho_ate = np.corrcoef((g_long - g_short), (rr_long_ate - rr_short_ate))[0, 1]
1095
+ rho_atte = np.corrcoef((g_long - g_short), (rr_long_atte - rr_short_atte))[0, 1]
1096
+ oracle_values = {
1097
+ 'g_long': g_long,
1098
+ 'g_short': g_short,
1099
+ 'm_long': m_long,
1100
+ 'm_short': m_short,
1101
+ 'gamma_a': gamma_a,
1102
+ 'beta_a': beta_a,
1103
+ 'a': a,
1104
+ 'y_0': y_0,
1105
+ 'y_1': y_1,
1106
+ 'z': z,
1107
+ 'cf_y': cf_y,
1108
+ 'cf_d_ate': cf_d_ate,
1109
+ 'cf_d_atte': cf_d_atte,
1110
+ 'rho_ate': rho_ate,
1111
+ 'rho_atte': rho_atte,
1112
+ }
1113
+ res_dict = {
1114
+ 'x': x,
1115
+ 'y': y,
1116
+ 'd': d,
1117
+ 'oracle_values': oracle_values
1118
+ }
1067
1119
  return res_dict
1068
1120
 
1069
1121
 
@@ -161,7 +161,11 @@ class DoubleMLDID(LinearScoreMixin, DoubleML):
161
161
  return self._trimming_threshold
162
162
 
163
163
  def _initialize_ml_nuisance_params(self):
164
- valid_learner = ['ml_g0', 'ml_g1', 'ml_m']
164
+ if self.score == 'observational':
165
+ valid_learner = ['ml_g0', 'ml_g1', 'ml_m']
166
+ else:
167
+ assert self.score == 'experimental'
168
+ valid_learner = ['ml_g0', 'ml_g1']
165
169
  self._params = {learner: {key: [None] * self.n_rep for key in self._dml_data.d_cols}
166
170
  for learner in valid_learner}
167
171