DoubleML / doubleml-for-r

DoubleML - Double Machine Learning in R
https://docs.doubleml.org
Other
132 stars 25 forks source link

[Bug]: Unable to perform ensemble learners #151

Closed JHPark9090 closed 2 years ago

JHPark9090 commented 2 years ago

Describe the bug

Hello, I am very fascinated with this great algorithm for causal machine learning analysis. But when I was trying to test ensemble learners in R, I faced this error indicating that the learner for ml_g and ml_m must be of Class 'LearnerRegr'.

I first got this error when trying it on Interactive IV Model. I also tried it with the exact same codes described on the User Guide website. I posted the link of the page below. https://docs.doubleml.org/stable/examples/R_double_ml_pipeline.html?highlight=ensemble

I tried all kinds of solutions that I could think of, but was unable to go through this error message below. Please help.

Thanks in advance!

Error in private$assert_learner(ml_g, "ml_g", Regr = TRUE, Classif = FALSE) : Invalid learner provided for ml_g: must be of class 'LearnerRegr'

Minimum reproducible code snippet

Initiate new DoubleML object and estimate with graph learner

set.seed(123) obj_dml_plr_sim_pipe_ensemble = DoubleMLPLR$new(dml_data_sim, ml_g = ensemble_pipe_regr, ml_m = ensemble_pipe_regr) Error in private$assert_learner(ml_g, "ml_g", Regr = TRUE, Classif = FALSE) : Invalid learner provided for ml_g: must be of class 'LearnerRegr' obj_dml_plr_sim_pipe_ensemble$fit() Error: object 'obj_dml_plr_sim_pipe_ensemble' not found

Expected Result

Results of the Double ML with ensemble learner

Actual Result

Error in private$assert_learner(ml_g, "ml_g", Regr = TRUE, Classif = FALSE) : Invalid learner provided for ml_g: must be of class 'LearnerRegr'

Versions

sessionInfo() R version 4.1.2 (2021-11-01) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 22000)

Matrix products: default

locale: [1] LC_COLLATE=Korean_Korea.949 LC_CTYPE=Korean_Korea.949 LC_MONETARY=Korean_Korea.949 LC_NUMERIC=C LC_TIME=Korean_Korea.949

attached base packages: [1] splines stats graphics grDevices utils datasets methods base

other attached packages: [1] mlr3pipelines_0.4.0 data.table_1.14.2 mlr3learners_0.5.2 mlr3_0.13.3 DoubleML_0.4.1 sandwich_3.0-1 lmtest_0.9-39 zoo_1.8-9
[9] MASS_7.3-54 glmnet_4.1-3 Matrix_1.3-4 rpart_4.1-15 fastDummies_1.6.3 np_0.60-11 causalweight_1.0.2 ranger_0.13.1
[17] openxlsx_4.2.5 ivreg_0.6-1 forcats_0.5.1 stringr_1.4.0 dplyr_1.0.7 purrr_0.3.4 readr_2.1.1 tidyr_1.1.4
[25] tibble_3.1.6 ggplot2_3.3.5 tidyverse_1.3.1

loaded via a namespace (and not attached): [1] paradox_0.8.0 cubature_2.0.4.4 colorspace_2.0-2 ellipsis_0.3.2 class_7.3-19 rprojroot_2.0.2 fs_1.5.2
[8] rstudioapi_0.13 proxy_0.4-26 listenv_0.8.0 remotes_2.4.2 MatrixModels_0.5-0 mlr3tuning_0.13.0 fansi_0.5.0
[15] mvtnorm_1.1-3 lubridate_1.8.0 xml2_1.3.3 codetools_0.2-18 knitr_1.37 pkgload_1.2.4 Formula_1.2-4
[22] jsonlite_1.7.2 broom_0.7.11 dbplyr_2.1.1 hdm_0.3.1 compiler_4.1.2 httr_1.4.2 backports_1.4.1
[29] assertthat_0.2.1 fastmap_1.1.0 cli_3.1.0 prettyunits_1.1.1 quantreg_5.88 htmltools_0.5.2 tools_4.1.2
[36] igraph_1.2.11 gtable_0.3.0 glue_1.6.0 clusterGeneration_1.3.7 Rcpp_1.0.7 carData_3.0-5 SuperLearner_2.0-28
[43] cellranger_1.1.0 vctrs_0.3.8 iterators_1.0.14 xfun_0.29 ps_1.6.0 globals_0.14.0 testthat_3.1.1
[50] rvest_1.0.2 lifecycle_1.0.1 future_1.24.0 scales_1.1.1 lgr_0.4.3 hms_1.1.1 parallel_4.1.2
[57] SparseM_1.81 readstata13_0.10.0 curl_4.3.2 yaml_2.2.1 gam_1.20.1 stringi_1.7.6 desc_1.4.0
[64] foreach_1.5.2 e1071_1.7-9 checkmate_2.0.0 palmerpenguins_0.1.0 pkgbuild_1.3.1 boot_1.3-28 zip_2.2.0
[71] shape_1.4.6 rlang_0.4.12 pkgconfig_2.0.3 evaluate_0.14 lattice_0.20-45 processx_3.5.2 tidyselect_1.1.1
[78] parallelly_1.31.0 magrittr_2.0.1 R6_2.5.1 generics_0.1.1 nnls_1.4 DBI_1.1.2 pillar_1.6.4
[85] haven_2.4.3 withr_2.4.3 survival_3.2-13 abind_1.4-5 future.apply_1.8.1 modelr_0.1.8 crayon_1.4.2
[92] car_3.0-12 xgboost_1.5.2.1 uuid_1.0-3 utf8_1.2.2 tzdb_0.2.0 rmarkdown_2.11 grid_4.1.2
[99] readxl_1.3.1 callr_3.7.0 mlr3misc_0.10.0 bbotk_0.5.1 reprex_2.0.1 digest_0.6.29 LARF_1.4
[106] munsell_0.5.0 quadprog_1.5-8

packageVersion('DoubleML') [1] ‘0.4.1’ packageVersion('mlr3') [1] ‘0.13.3’

MalteKurz commented 2 years ago

Hi @FWNietzsche,

thanks for your interest in DoubleML. The problem you see is fixed already (#141) but not yet released to CRAN. To use the ensemble learners, you may want to install the current development version from GitHub via remotes::install_github("DoubleML/doubleml-for-r"). The required changes will be contained in the next release to CRAN, so whenever in the future you see a new version available via CRAN you can update DoubleML again.

JHPark9090 commented 2 years ago

@MalteKurz

Thank you very much for your quick & kind reply! I just tried the ensemble model after installing the current version with the code that you mentioned. It works perfectly now. Thanks a million!