Skip to content

Commit b4504e1

Browse files
committed
Merge branch 'master' of github.com:DoubleML/doubleml-for-r into 0.0.X
2 parents a3bb6f0 + e147f59 commit b4504e1

17 files changed

+2727
-62
lines changed

.github/workflows/deploy_docu.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Workflow based on https://github.com/r-lib/actions/blob/master/examples/pkgdown.yaml
2+
3+
name: CI deploy documentation
4+
5+
on:
6+
push:
7+
branches:
8+
- master
9+
workflow_dispatch:
10+
release:
11+
types:
12+
- published
13+
14+
jobs:
15+
build:
16+
17+
runs-on: ubuntu-20.04
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
with:
22+
persist-credentials: false
23+
- name: Install SSH Client
24+
uses: webfactory/ssh-agent@v0.4.1
25+
with:
26+
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
27+
28+
- name: Install R
29+
uses: r-lib/actions/setup-r@v1
30+
with:
31+
r-version: 'release'
32+
33+
- uses: r-lib/actions/setup-pandoc@v1
34+
35+
- name: Query dependencies
36+
run: |
37+
install.packages('remotes')
38+
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
39+
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
40+
shell: Rscript {0}
41+
42+
- name: Cache R packages
43+
uses: actions/cache@v2
44+
with:
45+
path: ${{ env.R_LIBS_USER }}
46+
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
47+
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
48+
49+
- name: Install system dependencies package
50+
run: |
51+
while read -r cmd
52+
do
53+
eval sudo $cmd
54+
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
55+
56+
- name: Install system dependencies pkgdown
57+
run: |
58+
while read -r cmd
59+
do
60+
eval sudo $cmd
61+
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04", package="pkgdown"))')
62+
63+
- name: Install additional system dependencies for pkgdown
64+
run: sudo apt-get install libharfbuzz-dev libfribidi-dev
65+
66+
- name: Install dependencies
67+
run: |
68+
remotes::install_deps(dependencies = TRUE)
69+
remotes::install_cran("pkgdown")
70+
shell: Rscript {0}
71+
72+
- name: Install package
73+
run: R CMD INSTALL .
74+
75+
- name: Build docu with pkgdown
76+
run: Rscript -e 'pkgdown::build_site(new_process = FALSE)'
77+
78+
- name: Deploy to dev
79+
if: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }}
80+
uses: JamesIves/github-pages-deploy-action@3.7.1
81+
with:
82+
REPOSITORY_NAME: DoubleML/doubleml.github.io
83+
BRANCH: master
84+
FOLDER: docs/dev
85+
TARGET_FOLDER: r/dev
86+
GIT_CONFIG_NAME: DoubleML Deploy Bot
87+
GIT_CONFIG_EMAIL: DoubleML@users.noreply.github.com
88+
CLEAN: true
89+
SSH: true
90+
91+
- name: Deploy to version
92+
if: ${{ github.event_name == 'release' }}
93+
uses: JamesIves/github-pages-deploy-action@3.7.1
94+
with:
95+
REPOSITORY_NAME: DoubleML/doubleml.github.io
96+
BRANCH: master
97+
FOLDER: docs/dev
98+
TARGET_FOLDER: r/ ${{ github.ref }}
99+
GIT_CONFIG_NAME: DoubleML Deploy Bot
100+
GIT_CONFIG_EMAIL: DoubleML@users.noreply.github.com
101+
CLEAN: true
102+
SSH: true
103+
104+
- name: Deploy to stable
105+
if: ${{ github.event_name == 'release' }}
106+
uses: JamesIves/github-pages-deploy-action@3.7.1
107+
with:
108+
REPOSITORY_NAME: DoubleML/doubleml.github.io
109+
BRANCH: master
110+
FOLDER: docs/dev
111+
TARGET_FOLDER: r/stable
112+
GIT_CONFIG_NAME: DoubleML Deploy Bot
113+
GIT_CONFIG_EMAIL: DoubleML@users.noreply.github.com
114+
CLEAN: true
115+
SSH: true

.github/workflows/deploy_pkg.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Workflow based on https://github.com/r-lib/actions/tree/master/examples#standard-ci-workflow
2+
name: CI deploy package
3+
4+
on:
5+
release:
6+
types:
7+
- published
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- uses: r-lib/actions/setup-r@v1
17+
with:
18+
r-version: 'release'
19+
20+
- uses: r-lib/actions/setup-pandoc@v1
21+
22+
- name: Query dependencies
23+
run: |
24+
install.packages('remotes')
25+
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
26+
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
27+
shell: Rscript {0}
28+
29+
- name: Cache R packages
30+
uses: actions/cache@v2
31+
with:
32+
path: ${{ env.R_LIBS_USER }}
33+
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
34+
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
35+
36+
- name: Install system dependencies
37+
run: |
38+
while read -r cmd
39+
do
40+
eval sudo $cmd
41+
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
42+
43+
- name: Install dependencies
44+
run: |
45+
remotes::install_deps(dependencies = TRUE)
46+
shell: Rscript {0}
47+
48+
- name: Build package
49+
run: |
50+
R CMD build .
51+
52+
- uses: actions/upload-artifact@v2
53+
with:
54+
name: DoubleML-pkg
55+
path: DoubleML_*.tar.gz

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: DoubleML
22
Type: Package
3-
Title: Double Machine Learning
4-
Version: 0.0.1
3+
Title: Double Machine Learning in R
4+
Version: 0.0.2
55
Authors@R: c(
66
person("Philipp", "Bach", email = "philipp.bach@uni-hamburg.de", role="aut"),
77
person("Victor", "Chernozhukov", role="aut"),

R/double_ml.R

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,24 @@ DoubleML = R6::R6Class("DoubleML", public = list(
208208
checkmate::assert_count(n_rep_boot, positive = TRUE)
209209

210210
private$initialize_boot_arrays(n_rep_boot)
211-
211+
212212
for (i_rep in 1:self$n_rep) {
213213
private$i_rep = i_rep
214214

215+
if (self$apply_cross_fitting) {
216+
n_obs = self$data$n_obs
217+
} else {
218+
smpls = private$get__smpls()
219+
test_ids = smpls$test_ids
220+
test_index = test_ids[[1]]
221+
n_obs = length(test_index)
222+
}
223+
weights = draw_weights(method, n_rep_boot, n_obs)
224+
215225
for (i_treat in 1:self$data$n_treat) {
216226
private$i_treat = i_treat
217-
218-
boot_res = private$compute_bootstrap(method, n_rep_boot)
227+
228+
boot_res = private$compute_bootstrap(weights, n_rep_boot)
219229
boot_coef = boot_res$boot_coef
220230
boot_t_stat = boot_res$boot_t_stat
221231
private$set__boot_coef(boot_coef)
@@ -295,7 +305,7 @@ DoubleML = R6::R6Class("DoubleML", public = list(
295305
#' A nested `list()`. The outer lists needs to provide an entry per repeated sample splitting (length of the list is set as `n_rep`). The inner list is a named `list()` with names `train_ids` and `test_ids`. The entries in `train_ids` and `test_ids` must be partitions per fold (length of `train_ids` and `test_ids` is set as `n_folds`).
296306
#'
297307
#' @return self
298-
set_samples = function(smpls) {
308+
set_sample_splitting = function(smpls) {
299309
checkmate::assert_list(smpls)
300310
self$n_rep = length(smpls)
301311
n_folds_each_train_smpl = vapply(smpls, function(x) length(x$train_ids), integer(1L))
@@ -845,7 +855,7 @@ private = list(
845855

846856
invisible(self)
847857
},
848-
compute_bootstrap = function(method, n_rep_boot) {
858+
compute_bootstrap = function(weights, n_rep_boot) {
849859
dml_procedure = self$dml_procedure
850860
smpls = private$get__smpls()
851861
test_ids = smpls$test_ids
@@ -857,19 +867,6 @@ private = list(
857867
n_obs = length(test_index)
858868
}
859869

860-
if (method == "Bayes") {
861-
weights = stats::rexp(n_rep_boot * n_obs, rate = 1) - 1
862-
} else if (method == "normal") {
863-
weights = stats::rnorm(n_rep_boot * n_obs)
864-
} else if (method == "wild") {
865-
weights = stats::rnorm(n_rep_boot * n_obs)/sqrt(2) + (stats::rnorm(n_rep_boot * n_obs)^2 - 1)/2
866-
} else {
867-
stop("invalid boot method")
868-
}
869-
870-
# for alignment with the functional (loop-wise) implementation we fill by row
871-
weights = matrix(weights, nrow = n_rep_boot, ncol = n_obs, byrow=TRUE)
872-
873870
if (self$apply_cross_fitting) {
874871
if (dml_procedure == "dml1") {
875872
boot_coefs = boot_t_stat = matrix(NA, nrow = n_rep_boot, ncol = self$n_folds)

R/helper.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,25 @@ resample_dml = function(task, learner, resampling, store_models = FALSE){
178178
}
179179

180180

181+
# helper to draw weights in multiplier bootstrap
182+
draw_weights = function(method, n_rep_boot, n_obs) {
183+
if (method == "Bayes") {
184+
weights = stats::rexp(n_rep_boot * n_obs, rate = 1) - 1
185+
} else if (method == "normal") {
186+
weights = stats::rnorm(n_rep_boot * n_obs)
187+
} else if (method == "wild") {
188+
weights = stats::rnorm(n_rep_boot * n_obs)/sqrt(2) + (stats::rnorm(n_rep_boot * n_obs)^2 - 1)/2
189+
} else {
190+
stop("invalid boot method")
191+
}
192+
weights = matrix(weights, nrow = n_rep_boot, ncol = n_obs, byrow=TRUE)
193+
return(weights)
194+
}
195+
196+
197+
198+
199+
181200
format.perc = function (probs, digits) {
182201
paste(format(100 * probs, trim = TRUE, scientific = FALSE, digits = digits),
183202
"%" ) }

README.Rmd

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ output: github_document
44

55
<!-- README.md is generated from README.Rmd. Please edit that file -->
66

7-
# DoubleML - Double Machine Learning in python and R
7+
# DoubleML - Double Machine Learning in R
88

99
The R package **DoubleML** provides an implementation of the double / debiased machine learning framework of [Chernozhukov et al. (2018)](https://arxiv.org/abs/1608.00060). It is built on top of [mlr3](https://mlr3.mlr-org.com/) and the [mlr3 ecosystem](https://github.com/mlr-org/mlr3/wiki/Extension-Packages) (Lang et al., 2019).
1010

@@ -44,6 +44,8 @@ It further can be readily extended with regards to
4444
* ... alternative resampling schemes,
4545
* ...
4646

47+
![OOP structure of the DoubleML package](man/figures/oop.svg?raw=true)
48+
4749
## Installation
4850

4951
**DoubleML** requires
@@ -69,6 +71,26 @@ remotes::install_github("DoubleML/doubleml-for-r")
6971
```
7072

7173

74+
## Citation
75+
76+
If you use the DoubleML package a citation is highly appreciated:
77+
78+
Bach, P., Chernozhukov, V., Kurz, M. S., and Spindler, M. (2020),
79+
DoubleML - Double Machine Learning in R.
80+
URL: [https://github.com/DoubleML/doubleml-for-r](https://github.com/DoubleML/doubleml-for-r),
81+
R-Package version 0.1.0.
82+
83+
Bibtex-entry:
84+
85+
```
86+
@Manual{DoubleML2020,
87+
title = {DoubleML - Double Machine Learning in R},
88+
author = {Bach, P., Chernozhukov, V., Kurz, M. S., and Spindler, M.},
89+
year = {2020},
90+
note = {URL: \url{https://github.com/DoubleML/doubleml-for-r}, R-Package version 0.1.0}
91+
}
92+
```
93+
7294
## References
7395

7496
* Chernozhukov, V., Chetverikov, D., Demirer, M., Duflo, E., Hansen, C., Newey, W. and Robins, J. (2018), Double/debiased machine learning for treatment and structural parameters. The Econometrics Journal, 21: C1-C68. [doi:10.1111/ectj.12097](doi:10.1111/ectj.12097).

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<!-- README.md is generated from README.Rmd. Please edit that file -->
33

4-
# DoubleML - Double Machine Learning in python and R
4+
# DoubleML - Double Machine Learning in R
55

66
The R package **DoubleML** provides an implementation of the double /
77
debiased machine learning framework of [Chernozhukov et
@@ -60,6 +60,8 @@ It further can be readily extended with regards to
6060
- … alternative resampling schemes,
6161
-
6262

63+
![OOP structure of the DoubleML package](man/figures/oop.svg?raw=true)
64+
6365
## Installation
6466

6567
**DoubleML** requires
@@ -85,6 +87,23 @@ Until then we recommend to install from source via
8587
remotes::install_github("DoubleML/doubleml-for-r")
8688
```
8789

90+
## Citation
91+
92+
If you use the DoubleML package a citation is highly appreciated:
93+
94+
Bach, P., Chernozhukov, V., Kurz, M. S., and Spindler, M. (2020),
95+
DoubleML - Double Machine Learning in R. URL:
96+
<https://github.com/DoubleML/doubleml-for-r>, R-Package version 0.1.0.
97+
98+
Bibtex-entry:
99+
100+
@Manual{DoubleML2020,
101+
title = {DoubleML - Double Machine Learning in R},
102+
author = {Bach, P., Chernozhukov, V., Kurz, M. S., and Spindler, M.},
103+
year = {2020},
104+
note = {URL: \url{https://github.com/DoubleML/doubleml-for-r}, R-Package version 0.1.0}
105+
}
106+
88107
## References
89108

90109
- Chernozhukov, V., Chetverikov, D., Demirer, M., Duflo, E., Hansen,

man/DoubleML.Rd

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/DoubleMLIIVM.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)