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.
- DoubleML-0.8.2/DoubleML.egg-info/PKG-INFO +162 -0
- DoubleML-0.8.2/PKG-INFO +162 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/README.md +1 -1
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/__init__.py +2 -2
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/datasets.py +123 -71
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/did.py +5 -1
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/did_cs.py +7 -2
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/_utils_did_cs_manual.py +1 -1
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/_utils_did_manual.py +1 -1
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/test_did_cs_external_predictions.py +2 -1
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/test_did_external_predictions.py +2 -1
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/double_ml.py +64 -97
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/qte.py +76 -9
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_qte.py +36 -10
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/_utils_dml_cv_predict.py +5 -20
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_datasets.py +15 -4
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_evaluate_learner.py +15 -12
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_exceptions.py +39 -9
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_multiway_cluster.py +71 -3
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_return_types.py +44 -44
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/_checks.py +109 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/_estimation.py +8 -2
- {DoubleML-0.8.0 → DoubleML-0.8.2}/setup.py +3 -3
- DoubleML-0.8.0/DoubleML.egg-info/PKG-INFO +0 -159
- DoubleML-0.8.0/PKG-INFO +0 -159
- {DoubleML-0.8.0 → DoubleML-0.8.2}/DoubleML.egg-info/SOURCES.txt +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/DoubleML.egg-info/dependency_links.txt +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/DoubleML.egg-info/requires.txt +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/DoubleML.egg-info/top_level.txt +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/LICENSE +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/MANIFEST.in +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/__init__.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/__init__.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/conftest.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/test_did.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/test_did_cs.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/test_did_cs_tune.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/did/tests/test_did_tune.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/double_ml_data.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/double_ml_framework.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/double_ml_score_mixins.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/__init__.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/cvar.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/iivm.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/irm.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/lpq.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/pq.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/ssm.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/__init__.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_cvar_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_iivm_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_irm_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_lpq_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_pq_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_qte_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/_utils_ssm_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/conftest.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_cvar.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_cvar_tune.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_iivm.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_iivm_classifier.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_iivm_external_predictions.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_iivm_subgroups.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_iivm_tune.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_irm.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_irm_classifier.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_irm_external_predictions.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_irm_tune.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_irm_weighted_scores.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_irm_with_missings.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_lpq.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_lpq_external_predictions.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_lpq_tune.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_pq.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_pq_external_predictions.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_pq_tune.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_qte_exceptions.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_ssm.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_ssm_exceptions.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/irm/tests/test_ssm_tune.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/__init__.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/pliv.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/plr.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/__init__.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/_utils_pliv_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/_utils_pliv_partial_x_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/_utils_pliv_partial_xz_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/_utils_pliv_partial_z_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/_utils_plr_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/conftest.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_external_predictions.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_partial_x.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_partial_x_tune.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_partial_xz.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_partial_xz_tune.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_partial_z.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_partial_z_tune.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_pliv_tune.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_classifier.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_external_predictions.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_multi_treat.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_reestimate_from_scores.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_rep_cross.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_set_ml_nuisance_pars.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_set_smpls_externally.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/plm/tests/test_plr_tune.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/__init__.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/_utils.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/_utils_boot.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/_utils_cluster.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/_utils_doubleml_sensitivity_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/conftest.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_cv_predict.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_dml_data.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_exceptions_ext_preds.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_framework.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_framework_coverage.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_framework_exceptions.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_framework_pval_corrections.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_model_defaults.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_nonlinear_cluster.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_nonlinear_score_mixin.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_package.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_scores.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_sensitivity.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_sensitivity_cluster.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_set_ml_nuisance_params.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/tests/test_set_sample_splitting.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/__init__.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/_plots.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/blp.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/dummy_learners.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/gain_statistics.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/policytree.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/resampling.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/__init__.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/_utils_blp_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/_utils_pt_manual.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/test_blp.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/test_dummy_learners.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/test_exceptions_gain_statistics.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/test_policytree.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/doubleml/utils/tests/test_var_est_and_aggregation.py +0 -0
- {DoubleML-0.8.0 → DoubleML-0.8.2}/pytest.ini +0 -0
- {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
|
+
[](https://github.com/DoubleML/doubleml-for-py/actions?query=workflow%3Abuild)
|
|
28
|
+
[](https://badge.fury.io/py/DoubleML)
|
|
29
|
+
[](https://anaconda.org/conda-forge/doubleml)
|
|
30
|
+
[](https://codecov.io/gh/DoubleML/doubleml-for-py)
|
|
31
|
+
[](https://www.codacy.com/gh/DoubleML/doubleml-for-py/dashboard?utm_source=github.com&utm_medium=referral&utm_content=DoubleML/doubleml-for-py&utm_campaign=Badge_Grade)
|
|
32
|
+
[](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
|
+
[](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
|
+

|
|
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
|
+
|
DoubleML-0.8.2/PKG-INFO
ADDED
|
@@ -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
|
+
[](https://github.com/DoubleML/doubleml-for-py/actions?query=workflow%3Abuild)
|
|
28
|
+
[](https://badge.fury.io/py/DoubleML)
|
|
29
|
+
[](https://anaconda.org/conda-forge/doubleml)
|
|
30
|
+
[](https://codecov.io/gh/DoubleML/doubleml-for-py)
|
|
31
|
+
[](https://www.codacy.com/gh/DoubleML/doubleml-for-py/dashboard?utm_source=github.com&utm_medium=referral&utm_content=DoubleML/doubleml-for-py&utm_campaign=Badge_Grade)
|
|
32
|
+
[](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
|
+
[](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
|
+

|
|
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
|
[](https://anaconda.org/conda-forge/doubleml)
|
|
6
6
|
[](https://codecov.io/gh/DoubleML/doubleml-for-py)
|
|
7
7
|
[](https://www.codacy.com/gh/DoubleML/doubleml-for-py/dashboard?utm_source=github.com&utm_medium=referral&utm_content=DoubleML/doubleml-for-py&utm_campaign=Badge_Grade)
|
|
8
|
-
[](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
|
-
|
|
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__ =
|
|
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,
|
|
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
|
|
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=
|
|
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 (
|
|
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) =
|
|
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) =
|
|
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) &=
|
|
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
|
-
|
|
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,
|
|
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
|
|
961
|
-
|
|
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 ``
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
Default is ``0.
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
Default is ``0.
|
|
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
|
-
|
|
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,
|
|
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
|
-
#
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
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
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
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
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
y = d *
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
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
|
-
|
|
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
|
|