Package 'DoubleML'

Title: Double Machine Learning in R
Description: Implementation of the double/debiased machine learning framework of Chernozhukov et al. (2018) <doi:10.1111/ectj.12097> for partially linear regression models, partially linear instrumental variable regression models, interactive regression models and interactive instrumental variable regression models. 'DoubleML' allows estimation of the nuisance parts in these models by machine learning methods and computation of the Neyman orthogonal score functions. 'DoubleML' is built on top of 'mlr3' and the 'mlr3' ecosystem. The object-oriented implementation of 'DoubleML' based on the 'R6' package is very flexible. More information available in the publication in the Journal of Statistical Software: <doi:10.18637/jss.v108.i03>.
Authors: Philipp Bach [aut, cre], Victor Chernozhukov [aut], Malte S. Kurz [aut], Martin Spindler [aut], Klaassen Sven [aut]
Maintainer: Philipp Bach <[email protected]>
License: MIT + file LICENSE
Version: 1.0.0.9000
Built: 2024-11-22 13:30:23 UTC
Source: https://github.com/doubleml/doubleml-for-r

Help Index


Wrapper for Double machine learning data-backend initialization from data.frame.

Description

Initalization of DoubleMLData from data.frame.

Usage

double_ml_data_from_data_frame(
  df,
  x_cols = NULL,
  y_col = NULL,
  d_cols = NULL,
  z_cols = NULL,
  cluster_cols = NULL,
  use_other_treat_as_covariate = TRUE
)

Arguments

df

(data.frame())
Data object.

x_cols

(NULL, character())
The covariates. If NULL, all variables (columns of data) which are neither specified as outcome variable y_col, nor as treatment variables d_cols, nor as instrumental variables z_cols are used as covariates. Default is NULL.

y_col

(character(1))
The outcome variable.

d_cols

(character())
The treatment variable(s).

z_cols

(NULL, character())
The instrumental variables. Default is NULL.

cluster_cols

(NULL, character())
The cluster variables. Default is NULL.

use_other_treat_as_covariate

(logical(1))
Indicates whether in the multiple-treatment case the other treatment variables should be added as covariates. Default is TRUE.

Value

Creates a new instance of class DoubleMLData.

Examples

df = make_plr_CCDDHNR2018(return_type = "data.frame")
x_names = names(df)[grepl("X", names(df))]
obj_dml_data = double_ml_data_from_data_frame(
  df = df, x_cols = x_names,
  y_col = "y", d_cols = "d")
# Input: Data frame, Output: DoubleMLData object

Wrapper for Double machine learning data-backend initialization from matrix.

Description

Initalization of DoubleMLData from matrix() objects.

Usage

double_ml_data_from_matrix(
  X = NULL,
  y,
  d,
  z = NULL,
  cluster_vars = NULL,
  data_class = "DoubleMLData",
  use_other_treat_as_covariate = TRUE
)

Arguments

X

(matrix())
Matrix of covariates.

y

(numeric())
Vector of outcome variable.

d

(matrix())
Matrix of treatment variables.

z

(matrix())
Matrix of instruments.

cluster_vars

(matrix())
Matrix of cluster variables.

data_class

(character(1))
Class of returned object. By default, an object of class DoubleMLData is returned. Setting data_class = "data.table" returns an object of class data.table.

use_other_treat_as_covariate

(logical(1))
Indicates whether in the multiple-treatment case the other treatment variables should be added as covariates. Default is TRUE.

Value

Creates a new instance of class DoubleMLData.

Examples

matrix_list = make_plr_CCDDHNR2018(return_type = "matrix")
obj_dml_data = double_ml_data_from_matrix(
  X = matrix_list$X,
  y = matrix_list$y,
  d = matrix_list$d)

Abstract class DoubleML

Description

Abstract base class that can't be initialized.

Format

R6::R6Class object.

Active bindings

all_coef

(matrix())
Estimates of the causal parameter(s) for the n_rep different sample splits after calling fit().

all_dml1_coef

(array())
Estimates of the causal parameter(s) for the n_rep different sample splits after calling fit() with dml_procedure = "dml1".

all_se

(matrix())
Standard errors of the causal parameter(s) for the n_rep different sample splits after calling fit().

apply_cross_fitting

(logical(1))
Indicates whether cross-fitting should be applied. Default is TRUE.

boot_coef

(matrix())
Bootstrapped coefficients for the causal parameter(s) after calling fit() and bootstrap().

boot_t_stat

(matrix())
Bootstrapped t-statistics for the causal parameter(s) after calling fit() and bootstrap().

coef

(numeric())
Estimates for the causal parameter(s) after calling fit().

data

(data.table)
Data object.

dml_procedure

(character(1))
A character() ("dml1" or "dml2") specifying the double machine learning algorithm. Default is "dml2".

draw_sample_splitting

(logical(1))
Indicates whether the sample splitting should be drawn during initialization of the object. Default is TRUE.

learner

(named list())
The machine learners for the nuisance functions.

n_folds

(integer(1))
Number of folds. Default is 5.

n_rep

(integer(1))
Number of repetitions for the sample splitting. Default is 1.

params

(named list())
The hyperparameters of the learners.

psi

(array())
Value of the score function ψ(W;θ,η)=ψa(W;η)θ+ψb(W;η)\psi(W;\theta, \eta)=\psi_a(W;\eta) \theta + \psi_b (W; \eta) after calling fit().

psi_a

(array())
Value of the score function component ψa(W;η)\psi_a(W;\eta) after calling fit().

psi_b

(array())
Value of the score function component ψb(W;η)\psi_b(W;\eta) after calling fit().

predictions

(array())
Predictions of the nuisance models after calling fit(store_predictions=TRUE).

models

(array())
The fitted nuisance models after calling fit(store_models=TRUE).

pval

(numeric())
p-values for the causal parameter(s) after calling fit().

score

(character(1), ⁠function()⁠)
A character(1) or ⁠function()⁠ specifying the score function.

se

(numeric())
Standard errors for the causal parameter(s) after calling fit().

smpls

(list())
The partition used for cross-fitting.

smpls_cluster

(list())
The partition of clusters used for cross-fitting.

t_stat

(numeric())
t-statistics for the causal parameter(s) after calling fit().

tuning_res

(named list())
Results from hyperparameter tuning.

Methods

Public methods


Method new()

DoubleML is an abstract class that can't be initialized.

Usage
DoubleML$new()

Method print()

Print DoubleML objects.

Usage
DoubleML$print()

Method fit()

Estimate DoubleML models.

Usage
DoubleML$fit(store_predictions = FALSE, store_models = FALSE)
Arguments
store_predictions

(logical(1))
Indicates whether the predictions for the nuisance functions should be stored in field predictions. Default is FALSE.

store_models

(logical(1))
Indicates whether the fitted models for the nuisance functions should be stored in field models if you want to analyze the models or extract information like variable importance. Default is FALSE.

Returns

self


Method bootstrap()

Multiplier bootstrap for DoubleML models.

Usage
DoubleML$bootstrap(method = "normal", n_rep_boot = 500)
Arguments
method

(character(1))
A character(1) ("Bayes", "normal" or "wild") specifying the multiplier bootstrap method.

n_rep_boot

(integer(1))
The number of bootstrap replications.

Returns

self


Method split_samples()

Draw sample splitting for DoubleML models.

The samples are drawn according to the attributes n_folds, n_rep and apply_cross_fitting.

Usage
DoubleML$split_samples()
Returns

self


Method set_sample_splitting()

Set the sample splitting for DoubleML models.

The attributes n_folds and n_rep are derived from the provided partition.

Usage
DoubleML$set_sample_splitting(smpls)
Arguments
smpls

(list())
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).

Returns

self

Examples
library(DoubleML)
library(mlr3)
set.seed(2)
obj_dml_data = make_plr_CCDDHNR2018(n_obs=10)
dml_plr_obj = DoubleMLPLR$new(obj_dml_data,
                              lrn("regr.rpart"), lrn("regr.rpart"))

# simple sample splitting with two folds and without cross-fitting
smpls = list(list(train_ids = list(c(1, 2, 3, 4, 5)),
                  test_ids = list(c(6, 7, 8, 9, 10))))
dml_plr_obj$set_sample_splitting(smpls)

# sample splitting with two folds and cross-fitting but no repeated cross-fitting
smpls = list(list(train_ids = list(c(1, 2, 3, 4, 5), c(6, 7, 8, 9, 10)),
                  test_ids = list(c(6, 7, 8, 9, 10), c(1, 2, 3, 4, 5))))
dml_plr_obj$set_sample_splitting(smpls)

# sample splitting with two folds and repeated cross-fitting with n_rep = 2
smpls = list(list(train_ids = list(c(1, 2, 3, 4, 5), c(6, 7, 8, 9, 10)),
                  test_ids = list(c(6, 7, 8, 9, 10), c(1, 2, 3, 4, 5))),
             list(train_ids = list(c(1, 3, 5, 7, 9), c(2, 4, 6, 8, 10)),
                  test_ids = list(c(2, 4, 6, 8, 10), c(1, 3, 5, 7, 9))))
dml_plr_obj$set_sample_splitting(smpls)

Method tune()

Hyperparameter-tuning for DoubleML models.

The hyperparameter-tuning is performed using the tuning methods provided in the mlr3tuning package. For more information on tuning in mlr3, we refer to the section on parameter tuning in the mlr3 book.

Usage
DoubleML$tune(
  param_set,
  tune_settings = list(n_folds_tune = 5, rsmp_tune = mlr3::rsmp("cv", folds = 5), measure
    = NULL, terminator = mlr3tuning::trm("evals", n_evals = 20), algorithm =
    mlr3tuning::tnr("grid_search"), resolution = 5),
  tune_on_folds = FALSE
)
Arguments
param_set

(named list())
A named list with a parameter grid for each nuisance model/learner (see method learner_names()). The parameter grid must be an object of class ParamSet.

tune_settings

(named list())
A named list() with arguments passed to the hyperparameter-tuning with mlr3tuning to set up TuningInstance objects. tune_settings has entries

  • terminator (Terminator)
    A Terminator object. Specification of terminator is required to perform tuning.

  • algorithm (Tuner or character(1))
    A Tuner object (recommended) or key passed to the respective dictionary to specify the tuning algorithm used in tnr(). algorithm is passed as an argument to tnr(). If algorithm is not specified by the users, default is set to "grid_search". If set to "grid_search", then additional argument "resolution" is required.

  • rsmp_tune (Resampling or character(1))
    A Resampling object (recommended) or option passed to rsmp() to initialize a Resampling for parameter tuning in mlr3. If not specified by the user, default is set to "cv" (cross-validation).

  • n_folds_tune (integer(1), optional)
    If rsmp_tune = "cv", number of folds used for cross-validation. If not specified by the user, default is set to 5.

  • measure (NULL, named list(), optional)
    Named list containing the measures used for parameter tuning. Entries in list must either be Measure objects or keys to be passed to passed to msr(). The names of the entries must match the learner names (see method learner_names()). If set to NULL, default measures are used, i.e., "regr.mse" for continuous outcome variables and "classif.ce" for binary outcomes.

  • resolution (character(1))
    The key passed to the respective dictionary to specify the tuning algorithm used in tnr(). resolution is passed as an argument to tnr().

tune_on_folds

(logical(1))
Indicates whether the tuning should be done fold-specific or globally. Default is FALSE.

Returns

self


Method summary()

Summary for DoubleML models after calling fit().

Usage
DoubleML$summary(digits = max(3L, getOption("digits") - 3L))
Arguments
digits

(integer(1))
The number of significant digits to use when printing.


Method confint()

Confidence intervals for DoubleML models.

Usage
DoubleML$confint(parm, joint = FALSE, level = 0.95)
Arguments
parm

(numeric() or character())
A specification of which parameters are to be given confidence intervals among the variables for which inference was done, either a vector of numbers or a vector of names. If missing, all parameters are considered (default).

joint

(logical(1))
Indicates whether joint confidence intervals are computed. Default is FALSE.

level

(numeric(1))
The confidence level. Default is 0.95.

Returns

A matrix() with the confidence interval(s).


Method learner_names()

Returns the names of the learners.

Usage
DoubleML$learner_names()
Returns

character() with names of learners.


Method params_names()

Returns the names of the nuisance models with hyperparameters.

Usage
DoubleML$params_names()
Returns

character() with names of nuisance models with hyperparameters.


Method set_ml_nuisance_params()

Set hyperparameters for the nuisance models of DoubleML models.

Note that in the current implementation, either all parameters have to be set globally or all parameters have to be provided fold-specific.

Usage
DoubleML$set_ml_nuisance_params(
  learner = NULL,
  treat_var = NULL,
  params,
  set_fold_specific = FALSE
)
Arguments
learner

(character(1))
The nuisance model/learner (see method params_names).

treat_var

(character(1))
The treatment varaible (hyperparameters can be set treatment-variable specific).

params

(named list())
A named list() with estimator parameters. Parameters are used for all folds by default. Alternatively, parameters can be passed in a fold-specific way if option fold_specificis TRUE. In this case, the outer list needs to be of length n_rep and the inner list of length n_folds.

set_fold_specific

(logical(1))
Indicates if the parameters passed in params should be passed in fold-specific way. Default is FALSE. If TRUE, the outer list needs to be of length n_rep and the inner list of length n_folds. Note that in the current implementation, either all parameters have to be set globally or all parameters have to be provided fold-specific.

Returns

self


Method p_adjust()

Multiple testing adjustment for DoubleML models.

Usage
DoubleML$p_adjust(method = "romano-wolf", return_matrix = TRUE)
Arguments
method

(character(1))
A character(1)("romano-wolf", "bonferroni", "holm", etc) specifying the adjustment method. In addition to "romano-wolf", all methods implemented in p.adjust() can be applied. Default is "romano-wolf".

return_matrix

(logical(1))
Indicates if the output is returned as a matrix with corresponding coefficient names.

Returns

numeric() with adjusted p-values. If return_matrix = TRUE, a matrix() with adjusted p_values.


Method get_params()

Get hyperparameters for the nuisance model of DoubleML models.

Usage
DoubleML$get_params(learner)
Arguments
learner

(character(1))
The nuisance model/learner (see method params_names())

Returns

named list()with paramers for the nuisance model/learner.


Method clone()

The objects of this class are cloneable with this method.

Usage
DoubleML$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other DoubleML: DoubleMLIIVM, DoubleMLIRM, DoubleMLPLIV, DoubleMLPLR

Examples

## ------------------------------------------------
## Method `DoubleML$set_sample_splitting`
## ------------------------------------------------

library(DoubleML)
library(mlr3)
set.seed(2)
obj_dml_data = make_plr_CCDDHNR2018(n_obs=10)
dml_plr_obj = DoubleMLPLR$new(obj_dml_data,
                              lrn("regr.rpart"), lrn("regr.rpart"))

# simple sample splitting with two folds and without cross-fitting
smpls = list(list(train_ids = list(c(1, 2, 3, 4, 5)),
                  test_ids = list(c(6, 7, 8, 9, 10))))
dml_plr_obj$set_sample_splitting(smpls)

# sample splitting with two folds and cross-fitting but no repeated cross-fitting
smpls = list(list(train_ids = list(c(1, 2, 3, 4, 5), c(6, 7, 8, 9, 10)),
                  test_ids = list(c(6, 7, 8, 9, 10), c(1, 2, 3, 4, 5))))
dml_plr_obj$set_sample_splitting(smpls)

# sample splitting with two folds and repeated cross-fitting with n_rep = 2
smpls = list(list(train_ids = list(c(1, 2, 3, 4, 5), c(6, 7, 8, 9, 10)),
                  test_ids = list(c(6, 7, 8, 9, 10), c(1, 2, 3, 4, 5))),
             list(train_ids = list(c(1, 3, 5, 7, 9), c(2, 4, 6, 8, 10)),
                  test_ids = list(c(2, 4, 6, 8, 10), c(1, 3, 5, 7, 9))))
dml_plr_obj$set_sample_splitting(smpls)

Double machine learning data-backend for data with cluster variables

Description

Double machine learning data-backend for data with cluster variables.

DoubleMLClusterData objects can be initialized from a data.table. Alternatively DoubleML provides functions to initialize from a collection of matrix objects or a data.frame. The following functions can be used to create a new instance of DoubleMLClusterData.

Super class

DoubleML::DoubleMLData -> DoubleMLClusterData

Active bindings

cluster_cols

(character())
The cluster variable(s).

x_cols

(NULL, character())
The covariates. If NULL, all variables (columns of data) which are neither specified as outcome variable y_col, nor as treatment variables d_cols, nor as instrumental variables z_cols, nor as cluster variables cluster_cols are used as covariates. Default is NULL.

n_cluster_vars

(integer(1))
The number of cluster variables.

Methods

Public methods


Method new()

Creates a new instance of this R6 class.

Usage
DoubleMLClusterData$new(
  data = NULL,
  x_cols = NULL,
  y_col = NULL,
  d_cols = NULL,
  cluster_cols = NULL,
  z_cols = NULL,
  use_other_treat_as_covariate = TRUE
)
Arguments
data

(data.table, data.frame())
Data object.

x_cols

(NULL, character())
The covariates. If NULL, all variables (columns of data) which are neither specified as outcome variable y_col, nor as treatment variables d_cols, nor as instrumental variables z_cols are used as covariates. Default is NULL.

y_col

(character(1))
The outcome variable.

d_cols

(character())
The treatment variable(s).

cluster_cols

(character())
The cluster variable(s).

z_cols

(NULL, character())
The instrumental variables. Default is NULL.

use_other_treat_as_covariate

(logical(1))
Indicates whether in the multiple-treatment case the other treatment variables should be added as covariates. Default is TRUE.


Method print()

Print DoubleMLClusterData objects.

Usage
DoubleMLClusterData$print()

Method set_data_model()

Setter function for data_model. The function implements the causal model as specified by the user via y_col, d_cols, x_cols, z_cols and cluster_cols and assigns the role for the treatment variables in the multiple-treatment case.

Usage
DoubleMLClusterData$set_data_model(treatment_var)
Arguments
treatment_var

(character())
Active treatment variable that will be set to treat_col.


Method clone()

The objects of this class are cloneable with this method.

Usage
DoubleMLClusterData$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

library(DoubleML)
dt = make_pliv_multiway_cluster_CKMS2021(return_type = "data.table")
obj_dml_data = DoubleMLClusterData$new(dt,
  y_col = "Y",
  d_cols = "D",
  z_cols = "Z",
  cluster_cols = c("cluster_var_i", "cluster_var_j"))

Double machine learning data-backend

Description

Double machine learning data-backend.

DoubleMLData objects can be initialized from a data.table. Alternatively DoubleML provides functions to initialize from a collection of matrix objects or a data.frame. The following functions can be used to create a new instance of DoubleMLData.

Active bindings

all_variables

(character())
All variables available in the dataset.

d_cols

(character())
The treatment variable(s).

data

(data.table)
Data object.

data_model

(data.table)
Internal data object that implements the causal model as specified by the user via y_col, d_cols, x_cols and z_cols.

n_instr

(NULL, integer(1))
The number of instruments.

n_obs

(integer(1))
The number of observations.

n_treat

(integer(1))
The number of treatment variables.

other_treat_cols

(NULL, character())
If use_other_treat_as_covariate is TRUE, other_treat_cols are the treatment variables that are not "active" in the multiple-treatment case. These variables then are internally added to the covariates x_cols during the fitting stage. If use_other_treat_as_covariate is FALSE, other_treat_cols is NULL.

treat_col

(character(1))
"Active" treatment variable in the multiple-treatment case.

use_other_treat_as_covariate

(logical(1))
Indicates whether in the multiple-treatment case the other treatment variables should be added as covariates. Default is TRUE.

x_cols

(NULL, character())
The covariates. If NULL, all variables (columns of data) which are neither specified as outcome variable y_col, nor as treatment variables d_cols, nor as instrumental variables z_cols are used as covariates. Default is NULL.

y_col

(character(1))
The outcome variable.

z_cols

(NULL, character())
The instrumental variables. Default is NULL.

Methods

Public methods


Method new()

Creates a new instance of this R6 class.

Usage
DoubleMLData$new(
  data = NULL,
  x_cols = NULL,
  y_col = NULL,
  d_cols = NULL,
  z_cols = NULL,
  use_other_treat_as_covariate = TRUE
)
Arguments
data

(data.table, data.frame())
Data object.

x_cols

(NULL, character())
The covariates. If NULL, all variables (columns of data) which are neither specified as outcome variable y_col, nor as treatment variables d_cols, nor as instrumental variables z_cols are used as covariates. Default is NULL.

y_col

(character(1))
The outcome variable.

d_cols

(character())
The treatment variable(s).

z_cols

(NULL, character())
The instrumental variables. Default is NULL.

use_other_treat_as_covariate

(logical(1))
Indicates whether in the multiple-treatment case the other treatment variables should be added as covariates. Default is TRUE.


Method print()

Print DoubleMLData objects.

Usage
DoubleMLData$print()

Method set_data_model()

Setter function for data_model. The function implements the causal model as specified by the user via y_col, d_cols, x_cols and z_cols and assigns the role for the treatment variables in the multiple-treatment case.

Usage
DoubleMLData$set_data_model(treatment_var)
Arguments
treatment_var

(character())
Active treatment variable that will be set to treat_col.


Method clone()

The objects of this class are cloneable with this method.

Usage
DoubleMLData$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

library(DoubleML)
df = make_plr_CCDDHNR2018(return_type = "data.table")
obj_dml_data = DoubleMLData$new(df,
  y_col = "y",
  d_cols = "d")

Double machine learning for interactive IV regression models

Description

Double machine learning for interactive IV regression models.

Format

R6::R6Class object inheriting from DoubleML.

Details

Interactive IV regression (IIVM) models take the form

Y=0(D,X)+ζY = \ell_0(D,X) + \zeta,

Z=m0(X)+VZ = m_0(X) + V,

with E[ζX,Z]=0E[\zeta|X,Z]=0 and E[VX]=0E[V|X] = 0. YY is the outcome variable, D{0,1}D \in \{0,1\} is the binary treatment variable and Z{0,1}Z \in \{0,1\} is a binary instrumental variable. Consider the functions g0g_0, r0r_0 and m0m_0, where g0g_0 maps the support of (Z,X)(Z,X) to RR and r0r_0 and m0m_0, respectively, map the support of (Z,X)(Z,X) and XX to (ϵ,1ϵ)(\epsilon, 1-\epsilon) for some ϵ(1,1/2)\epsilon \in (1, 1/2), such that

Y=g0(Z,X)+ν,Y = g_0(Z,X) + \nu,

D=r0(Z,X)+U,D = r_0(Z,X) + U,

Z=m0(X)+V,Z = m_0(X) + V,

with E[νZ,X]=0E[\nu|Z,X]=0, E[UZ,X]=0E[U|Z,X]=0 and E[VX]=0E[V|X]=0. The target parameter of interest in this model is the local average treatment effect (LATE),

θ0=E[g0(1,X)]E[g0(0,X)]E[r0(1,X)]E[r0(0,X)].\theta_0 = \frac{E[g_0(1,X)] - E[g_0(0,X)]}{E[r_0(1,X)] - E[r_0(0,X)]}.

Super class

DoubleML::DoubleML -> DoubleMLIIVM

Active bindings

subgroups

(named list(2))
Named list(2) with options to adapt to cases with and without the subgroups of always-takers and never-takes. The entry always_takers(logical(1)) speficies whether there are always takers in the sample. The entry never_takers (logical(1)) speficies whether there are never takers in the sample.

trimming_rule

(character(1))
A character(1) specifying the trimming approach.

trimming_threshold

(numeric(1))
The threshold used for timming.

Methods

Public methods

Inherited methods

Method new()

Creates a new instance of this R6 class.

Usage
DoubleMLIIVM$new(
  data,
  ml_g,
  ml_m,
  ml_r,
  n_folds = 5,
  n_rep = 1,
  score = "LATE",
  subgroups = list(always_takers = TRUE, never_takers = TRUE),
  dml_procedure = "dml2",
  trimming_rule = "truncate",
  trimming_threshold = 1e-12,
  draw_sample_splitting = TRUE,
  apply_cross_fitting = TRUE
)
Arguments
data

(DoubleMLData)
The DoubleMLData object providing the data and specifying the variables of the causal model.

ml_g

(LearnerRegr, LearnerClassif, Learner, character(1))
A learner of the class LearnerRegr, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. For binary treatment outcomes, an object of the class LearnerClassif can be passed, for example lrn("classif.cv_glmnet", s = "lambda.min"). Alternatively, a Learner object with public field task_type = "regr" or task_type = "classif" can be passed, respectively, for example of class GraphLearner.
ml_g refers to the nuisance function g0(Z,X)=E[YX,Z]g_0(Z,X) = E[Y|X,Z].

ml_m

(LearnerClassif, Learner, character(1))
A learner of the class LearnerClassif, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. Alternatively, a Learner object with public field task_type = "classif" can be passed, for example of class GraphLearner. The learner can possibly be passed with specified parameters, for example lrn("classif.cv_glmnet", s = "lambda.min").
ml_m refers to the nuisance function m0(X)=E[ZX]m_0(X) = E[Z|X].

ml_r

(LearnerClassif, Learner, character(1))
A learner of the class LearnerClassif, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. Alternatively, a Learner object with public field task_type = "classif" can be passed, for example of class GraphLearner. The learner can possibly be passed with specified parameters, for example lrn("classif.cv_glmnet", s = "lambda.min").
ml_r refers to the nuisance function r0(Z,X)=E[DX,Z]r_0(Z,X) = E[D|X,Z].

n_folds

(integer(1))
Number of folds. Default is 5.

n_rep

(integer(1))
Number of repetitions for the sample splitting. Default is 1.

score

(character(1), ⁠function()⁠)
A character(1) ("LATE" is the only choice) specifying the score function. If a ⁠function()⁠ is provided, it must be of the form ⁠function(y, z, d, g0_hat, g1_hat, m_hat, r0_hat, r1_hat, smpls)⁠ and the returned output must be a named list() with elements psi_a and psi_b. Default is "LATE".

subgroups

(named list(2))
Named list(2) with options to adapt to cases with and without the subgroups of always-takers and never-takes. The entry always_takers(logical(1)) speficies whether there are always takers in the sample. The entry never_takers (logical(1)) speficies whether there are never takers in the sample. Default is list(always_takers = TRUE, never_takers = TRUE).

dml_procedure

(character(1))
A character(1) ("dml1" or "dml2") specifying the double machine learning algorithm. Default is "dml2".

trimming_rule

(character(1))
A character(1) ("truncate" is the only choice) specifying the trimming approach. Default is "truncate".

trimming_threshold

(numeric(1))
The threshold used for timming. Default is 1e-12.

draw_sample_splitting

(logical(1))
Indicates whether the sample splitting should be drawn during initialization of the object. Default is TRUE.

apply_cross_fitting

(logical(1))
Indicates whether cross-fitting should be applied. Default is TRUE.


Method clone()

The objects of this class are cloneable with this method.

Usage
DoubleMLIIVM$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other DoubleML: DoubleML, DoubleMLIRM, DoubleMLPLIV, DoubleMLPLR

Examples

library(DoubleML)
library(mlr3)
library(mlr3learners)
library(data.table)
set.seed(2)
ml_g = lrn("regr.ranger",
  num.trees = 100, mtry = 20,
  min.node.size = 2, max.depth = 5)
ml_m = lrn("classif.ranger",
  num.trees = 100, mtry = 20,
  min.node.size = 2, max.depth = 5)
ml_r = ml_m$clone()
obj_dml_data = make_iivm_data(
  theta = 0.5, n_obs = 1000,
  alpha_x = 1, dim_x = 20)
dml_iivm_obj = DoubleMLIIVM$new(obj_dml_data, ml_g, ml_m, ml_r)
dml_iivm_obj$fit()
dml_iivm_obj$summary()


## Not run: 
library(DoubleML)
library(mlr3)
library(mlr3learners)
library(mlr3tuning)
library(data.table)
set.seed(2)
ml_g = lrn("regr.rpart")
ml_m = lrn("classif.rpart")
ml_r = ml_m$clone()
obj_dml_data = make_iivm_data(
  theta = 0.5, n_obs = 1000,
  alpha_x = 1, dim_x = 20)
dml_iivm_obj = DoubleMLIIVM$new(obj_dml_data, ml_g, ml_m, ml_r)
param_grid = list(
  "ml_g" = paradox::ps(
    cp = paradox::p_dbl(lower = 0.01, upper = 0.02),
    minsplit = paradox::p_int(lower = 1, upper = 2)),
  "ml_m" = paradox::ps(
    cp = paradox::p_dbl(lower = 0.01, upper = 0.02),
    minsplit = paradox::p_int(lower = 1, upper = 2)),
  "ml_r" = paradox::ps(
    cp = paradox::p_dbl(lower = 0.01, upper = 0.02),
    minsplit = paradox::p_int(lower = 1, upper = 2)))
# minimum requirements for tune_settings
tune_settings = list(
  terminator = mlr3tuning::trm("evals", n_evals = 5),
  algorithm = mlr3tuning::tnr("grid_search", resolution = 5))
dml_iivm_obj$tune(param_set = param_grid, tune_settings = tune_settings)
dml_iivm_obj$fit()
dml_iivm_obj$summary()

## End(Not run)

Double machine learning for interactive regression models

Description

Double machine learning for interactive regression models.

Format

R6::R6Class object inheriting from DoubleML.

Details

Interactive regression (IRM) models take the form

Y=g0(D,X)+UY = g_0(D,X) + U,

D=m0(X)+VD = m_0(X) + V,

with E[UX,D]=0E[U|X,D]=0 and E[VX]=0E[V|X] = 0. YY is the outcome variable and D{0,1}D \in \{0,1\} is the binary treatment variable. We consider estimation of the average treamtent effects when treatment effects are fully heterogeneous. Target parameters of interest in this model are the average treatment effect (ATE),

θ0=E[g0(1,X)g0(0,X)]\theta_0 = E[g_0(1,X) - g_0(0,X)]

and the average treament effect on the treated (ATTE),

θ0=E[g0(1,X)g0(0,X)D=1]\theta_0 = E[g_0(1,X) - g_0(0,X)|D=1].

Super class

DoubleML::DoubleML -> DoubleMLIRM

Active bindings

trimming_rule

(character(1))
A character(1) specifying the trimming approach.

trimming_threshold

(numeric(1))
The threshold used for timming.

Methods

Public methods

Inherited methods

Method new()

Creates a new instance of this R6 class.

Usage
DoubleMLIRM$new(
  data,
  ml_g,
  ml_m,
  n_folds = 5,
  n_rep = 1,
  score = "ATE",
  trimming_rule = "truncate",
  trimming_threshold = 1e-12,
  dml_procedure = "dml2",
  draw_sample_splitting = TRUE,
  apply_cross_fitting = TRUE
)
Arguments
data

(DoubleMLData)
The DoubleMLData object providing the data and specifying the variables of the causal model.

ml_g

(LearnerRegr, LearnerClassif, Learner, character(1))
A learner of the class LearnerRegr, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. For binary treatment outcomes, an object of the class LearnerClassif can be passed, for example lrn("classif.cv_glmnet", s = "lambda.min"). Alternatively, a Learner object with public field task_type = "regr" or task_type = "classif" can be passed, respectively, for example of class GraphLearner.
ml_g refers to the nuisance function g0(X)=E[YX,D]g_0(X) = E[Y|X,D].

ml_m

(LearnerClassif, Learner, character(1))
A learner of the class LearnerClassif, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. Alternatively, a Learner object with public field task_type = "classif" can be passed, for example of class GraphLearner. The learner can possibly be passed with specified parameters, for example lrn("classif.cv_glmnet", s = "lambda.min").
ml_m refers to the nuisance function m0(X)=E[DX]m_0(X) = E[D|X].

n_folds

(integer(1))
Number of folds. Default is 5.

n_rep

(integer(1))
Number of repetitions for the sample splitting. Default is 1.

score

(character(1), ⁠function()⁠)
A character(1) ("ATE" or ATTE) or a ⁠function()⁠ specifying the score function. If a ⁠function()⁠ is provided, it must be of the form ⁠function(y, d, g0_hat, g1_hat, m_hat, smpls)⁠ and the returned output must be a named list() with elements psi_a and psi_b. Default is "ATE".

trimming_rule

(character(1))
A character(1) ("truncate" is the only choice) specifying the trimming approach. Default is "truncate".

trimming_threshold

(numeric(1))
The threshold used for timming. Default is 1e-12.

dml_procedure

(character(1))
A character(1) ("dml1" or "dml2") specifying the double machine learning algorithm. Default is "dml2".

draw_sample_splitting

(logical(1))
Indicates whether the sample splitting should be drawn during initialization of the object. Default is TRUE.

apply_cross_fitting

(logical(1))
Indicates whether cross-fitting should be applied. Default is TRUE.


Method clone()

The objects of this class are cloneable with this method.

Usage
DoubleMLIRM$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other DoubleML: DoubleML, DoubleMLIIVM, DoubleMLPLIV, DoubleMLPLR

Examples

library(DoubleML)
library(mlr3)
library(mlr3learners)
library(data.table)
set.seed(2)
ml_g = lrn("regr.ranger",
  num.trees = 100, mtry = 20,
  min.node.size = 2, max.depth = 5)
ml_m = lrn("classif.ranger",
  num.trees = 100, mtry = 20,
  min.node.size = 2, max.depth = 5)
obj_dml_data = make_irm_data(theta = 0.5)
dml_irm_obj = DoubleMLIRM$new(obj_dml_data, ml_g, ml_m)
dml_irm_obj$fit()
dml_irm_obj$summary()

## Not run: 
library(DoubleML)
library(mlr3)
library(mlr3learners)
library(mlr3uning)
library(data.table)
set.seed(2)
ml_g = lrn("regr.rpart")
ml_m = lrn("classif.rpart")
obj_dml_data = make_irm_data(theta = 0.5)
dml_irm_obj = DoubleMLIRM$new(obj_dml_data, ml_g, ml_m)

param_grid = list(
  "ml_g" = paradox::ps(
    cp = paradox::p_dbl(lower = 0.01, upper = 0.02),
    minsplit = paradox::p_int(lower = 1, upper = 2)),
  "ml_m" = paradox::ps(
    cp = paradox::p_dbl(lower = 0.01, upper = 0.02),
    minsplit = paradox::p_int(lower = 1, upper = 2)))

# minimum requirements for tune_settings
tune_settings = list(
  terminator = mlr3tuning::trm("evals", n_evals = 5),
  algorithm = mlr3tuning::tnr("grid_search", resolution = 5))
dml_irm_obj$tune(param_set = param_grid, tune_settings = tune_settings)
dml_irm_obj$fit()
dml_irm_obj$summary()

## End(Not run)

Double machine learning for partially linear IV regression models

Description

Double machine learning for partially linear IV regression models.

Format

R6::R6Class object inheriting from DoubleML.

Details

Partially linear IV regression (PLIV) models take the form

YDθ0=g0(X)+ζY - D\theta_0 = g_0(X) + \zeta,

Z=m0(X)+VZ = m_0(X) + V,

with E[ζZ,X]=0E[\zeta|Z,X]=0 and E[VX]=0E[V|X] = 0. YY is the outcome variable variable, DD is the policy variable of interest and ZZ denotes one or multiple instrumental variables. The high-dimensional vector X=(X1,,Xp)X = (X_1, \ldots, X_p) consists of other confounding covariates, and ζ\zeta and VV are stochastic errors.

Super class

DoubleML::DoubleML -> DoubleMLPLIV

Active bindings

partialX

(logical(1))
Indicates whether covariates XX should be partialled out.

partialZ

(logical(1))
Indicates whether instruments ZZ should be partialled out.

Methods

Public methods

Inherited methods

Method new()

Creates a new instance of this R6 class.

Usage
DoubleMLPLIV$new(
  data,
  ml_l,
  ml_m,
  ml_r,
  ml_g = NULL,
  partialX = TRUE,
  partialZ = FALSE,
  n_folds = 5,
  n_rep = 1,
  score = "partialling out",
  dml_procedure = "dml2",
  draw_sample_splitting = TRUE,
  apply_cross_fitting = TRUE
)
Arguments
data

(DoubleMLData)
The DoubleMLData object providing the data and specifying the variables of the causal model.

ml_l

(LearnerRegr, Learner, character(1))
A learner of the class LearnerRegr, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. Alternatively, a Learner object with public field task_type = "regr" can be passed, for example of class GraphLearner. The learner can possibly be passed with specified parameters, for example lrn("regr.cv_glmnet", s = "lambda.min").
ml_l refers to the nuisance function l0(X)=E[YX]l_0(X) = E[Y|X].

ml_m

(LearnerRegr, Learner, character(1))
A learner of the class LearnerRegr, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. Alternatively, a Learner object with public field task_type = "regr" can be passed, for example of class GraphLearner. The learner can possibly be passed with specified parameters, for example lrn("regr.cv_glmnet", s = "lambda.min").
ml_m refers to the nuisance function m0(X)=E[ZX]m_0(X) = E[Z|X].

ml_r

(LearnerRegr, Learner, character(1))
A learner of the class LearnerRegr, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. Alternatively, a Learner object with public field task_type = "regr" can be passed, for example of class GraphLearner. The learner can possibly be passed with specified parameters, for example lrn("regr.cv_glmnet", s = "lambda.min").
ml_r refers to the nuisance function r0(X)=E[DX]r_0(X) = E[D|X].

ml_g

(LearnerRegr, Learner, character(1))
A learner of the class LearnerRegr, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. Alternatively, a Learner object with public field task_type = "regr" can be passed, for example of class GraphLearner. The learner can possibly be passed with specified parameters, for example lrn("regr.cv_glmnet", s = "lambda.min").
ml_g refers to the nuisance function g0(X)=E[YDθ0X]g_0(X) = E[Y - D\theta_0|X]. Note: The learner ml_g is only required for the score 'IV-type'. Optionally, it can be specified and estimated for callable scores.

partialX

(logical(1))
Indicates whether covariates XX should be partialled out. Default is TRUE.

partialZ

(logical(1))
Indicates whether instruments ZZ should be partialled out. Default is FALSE.

n_folds

(integer(1))
Number of folds. Default is 5.

n_rep

(integer(1))
Number of repetitions for the sample splitting. Default is 1.

score

(character(1), ⁠function()⁠)
A character(1) ("partialling out" or "IV-type") or a ⁠function()⁠ specifying the score function. If a ⁠function()⁠ is provided, it must be of the form ⁠function(y, z, d, l_hat, m_hat, r_hat, g_hat, smpls)⁠ and the returned output must be a named list() with elements psi_a and psi_b. Default is "partialling out".

dml_procedure

(character(1))
A character(1) ("dml1" or "dml2") specifying the double machine learning algorithm. Default is "dml2".

draw_sample_splitting

(logical(1))
Indicates whether the sample splitting should be drawn during initialization of the object. Default is TRUE.

apply_cross_fitting

(logical(1))
Indicates whether cross-fitting should be applied. Default is TRUE.


Method set_ml_nuisance_params()

Set hyperparameters for the nuisance models of DoubleML models.

Note that in the current implementation, either all parameters have to be set globally or all parameters have to be provided fold-specific.

Usage
DoubleMLPLIV$set_ml_nuisance_params(
  learner = NULL,
  treat_var = NULL,
  params,
  set_fold_specific = FALSE
)
Arguments
learner

(character(1))
The nuisance model/learner (see method params_names).

treat_var

(character(1))
The treatment varaible (hyperparameters can be set treatment-variable specific).

params

(named list())
A named list() with estimator parameters. Parameters are used for all folds by default. Alternatively, parameters can be passed in a fold-specific way if option fold_specificis TRUE. In this case, the outer list needs to be of length n_rep and the inner list of length n_folds.

set_fold_specific

(logical(1))
Indicates if the parameters passed in params should be passed in fold-specific way. Default is FALSE. If TRUE, the outer list needs to be of length n_rep and the inner list of length n_folds. Note that in the current implementation, either all parameters have to be set globally or all parameters have to be provided fold-specific.

Returns

self


Method tune()

Hyperparameter-tuning for DoubleML models.

The hyperparameter-tuning is performed using the tuning methods provided in the mlr3tuning package. For more information on tuning in mlr3, we refer to the section on parameter tuning in the mlr3 book.

Usage
DoubleMLPLIV$tune(
  param_set,
  tune_settings = list(n_folds_tune = 5, rsmp_tune = mlr3::rsmp("cv", folds = 5), measure
    = NULL, terminator = mlr3tuning::trm("evals", n_evals = 20), algorithm =
    mlr3tuning::tnr("grid_search"), resolution = 5),
  tune_on_folds = FALSE
)
Arguments
param_set

(named list())
A named list with a parameter grid for each nuisance model/learner (see method learner_names()). The parameter grid must be an object of class ParamSet.

tune_settings

(named list())
A named list() with arguments passed to the hyperparameter-tuning with mlr3tuning to set up TuningInstance objects. tune_settings has entries

  • terminator (Terminator)
    A Terminator object. Specification of terminator is required to perform tuning.

  • algorithm (Tuner or character(1))
    A Tuner object (recommended) or key passed to the respective dictionary to specify the tuning algorithm used in tnr(). algorithm is passed as an argument to tnr(). If algorithm is not specified by the users, default is set to "grid_search". If set to "grid_search", then additional argument "resolution" is required.

  • rsmp_tune (Resampling or character(1))
    A Resampling object (recommended) or option passed to rsmp() to initialize a Resampling for parameter tuning in mlr3. If not specified by the user, default is set to "cv" (cross-validation).

  • n_folds_tune (integer(1), optional)
    If rsmp_tune = "cv", number of folds used for cross-validation. If not specified by the user, default is set to 5.

  • measure (NULL, named list(), optional)
    Named list containing the measures used for parameter tuning. Entries in list must either be Measure objects or keys to be passed to passed to msr(). The names of the entries must match the learner names (see method learner_names()). If set to NULL, default measures are used, i.e., "regr.mse" for continuous outcome variables and "classif.ce" for binary outcomes.

  • resolution (character(1))
    The key passed to the respective dictionary to specify the tuning algorithm used in tnr(). resolution is passed as an argument to tnr().

tune_on_folds

(logical(1))
Indicates whether the tuning should be done fold-specific or globally. Default is FALSE.

Returns

self


Method clone()

The objects of this class are cloneable with this method.

Usage
DoubleMLPLIV$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other DoubleML: DoubleML, DoubleMLIIVM, DoubleMLIRM, DoubleMLPLR

Examples

library(DoubleML)
library(mlr3)
library(mlr3learners)
library(data.table)
set.seed(2)
ml_l = lrn("regr.ranger", num.trees = 100, mtry = 20, min.node.size = 2, max.depth = 5)
ml_m = ml_l$clone()
ml_r = ml_l$clone()
obj_dml_data = make_pliv_CHS2015(alpha = 1, n_obs = 500, dim_x = 20, dim_z = 1)
dml_pliv_obj = DoubleMLPLIV$new(obj_dml_data, ml_l, ml_m, ml_r)
dml_pliv_obj$fit()
dml_pliv_obj$summary()


## Not run: 
library(DoubleML)
library(mlr3)
library(mlr3learners)
library(mlr3tuning)
library(data.table)
set.seed(2)
ml_l = lrn("regr.rpart")
ml_m = ml_l$clone()
ml_r = ml_l$clone()
obj_dml_data = make_pliv_CHS2015(
  alpha = 1, n_obs = 500, dim_x = 20,
  dim_z = 1)
dml_pliv_obj = DoubleMLPLIV$new(obj_dml_data, ml_l, ml_m, ml_r)
param_grid = list(
  "ml_l" = paradox::ps(
    cp = paradox::p_dbl(lower = 0.01, upper = 0.02),
    minsplit = paradox::p_int(lower = 1, upper = 2)),
  "ml_m" = paradox::ps(
    cp = paradox::p_dbl(lower = 0.01, upper = 0.02),
    minsplit = paradox::p_int(lower = 1, upper = 2)),
  "ml_r" = paradox::ps(
    cp = paradox::p_dbl(lower = 0.01, upper = 0.02),
    minsplit = paradox::p_int(lower = 1, upper = 2)))

# minimum requirements for tune_settings
tune_settings = list(
  terminator = mlr3tuning::trm("evals", n_evals = 5),
  algorithm = mlr3tuning::tnr("grid_search", resolution = 5))
dml_pliv_obj$tune(param_set = param_grid, tune_settings = tune_settings)
dml_pliv_obj$fit()
dml_pliv_obj$summary()

## End(Not run)

Double machine learning for partially linear regression models

Description

Double machine learning for partially linear regression models.

Format

R6::R6Class object inheriting from DoubleML.

Details

Partially linear regression (PLR) models take the form

Y=Dθ0+g0(X)+ζ,Y = D\theta_0 + g_0(X) + \zeta,

D=m0(X)+V,D = m_0(X) + V,

with E[ζD,X]=0E[\zeta|D,X]=0 and E[VX]=0E[V|X] = 0. YY is the outcome variable variable and DD is the policy variable of interest. The high-dimensional vector X=(X1,,Xp)X = (X_1, \ldots, X_p) consists of other confounding covariates, and ζ\zeta and VV are stochastic errors.

Super class

DoubleML::DoubleML -> DoubleMLPLR

Methods

Public methods

Inherited methods

Method new()

Creates a new instance of this R6 class.

Usage
DoubleMLPLR$new(
  data,
  ml_l,
  ml_m,
  ml_g = NULL,
  n_folds = 5,
  n_rep = 1,
  score = "partialling out",
  dml_procedure = "dml2",
  draw_sample_splitting = TRUE,
  apply_cross_fitting = TRUE
)
Arguments
data

(DoubleMLData)
The DoubleMLData object providing the data and specifying the variables of the causal model.

ml_l

(LearnerRegr, Learner, character(1))
A learner of the class LearnerRegr, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. Alternatively, a Learner object with public field task_type = "regr" can be passed, for example of class GraphLearner. The learner can possibly be passed with specified parameters, for example lrn("regr.cv_glmnet", s = "lambda.min").
ml_l refers to the nuisance function l0(X)=E[YX]l_0(X) = E[Y|X].

ml_m

(LearnerRegr, LearnerClassif, Learner, character(1))
A learner of the class LearnerRegr, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. For binary treatment variables, an object of the class LearnerClassif can be passed, for example lrn("classif.cv_glmnet", s = "lambda.min"). Alternatively, a Learner object with public field task_type = "regr" or task_type = "classif" can be passed, respectively, for example of class GraphLearner.
ml_m refers to the nuisance function m0(X)=E[DX]m_0(X) = E[D|X].

ml_g

(LearnerRegr, Learner, character(1))
A learner of the class LearnerRegr, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. Alternatively, a Learner object with public field task_type = "regr" can be passed, for example of class GraphLearner. The learner can possibly be passed with specified parameters, for example lrn("regr.cv_glmnet", s = "lambda.min").
ml_g refers to the nuisance function g0(X)=E[YDθ0X]g_0(X) = E[Y - D\theta_0|X]. Note: The learner ml_g is only required for the score 'IV-type'. Optionally, it can be specified and estimated for callable scores.

n_folds

(integer(1))
Number of folds. Default is 5.

n_rep

(integer(1))
Number of repetitions for the sample splitting. Default is 1.

score

(character(1), ⁠function()⁠)
A character(1) ("partialling out" or "IV-type") or a ⁠function()⁠ specifying the score function. If a ⁠function()⁠ is provided, it must be of the form ⁠function(y, d, l_hat, m_hat, g_hat, smpls)⁠ and the returned output must be a named list() with elements psi_a and psi_b. Default is "partialling out".

dml_procedure

(character(1))
A character(1) ("dml1" or "dml2") specifying the double machine learning algorithm. Default is "dml2".

draw_sample_splitting

(logical(1))
Indicates whether the sample splitting should be drawn during initialization of the object. Default is TRUE.

apply_cross_fitting

(logical(1))
Indicates whether cross-fitting should be applied. Default is TRUE.


Method set_ml_nuisance_params()

Set hyperparameters for the nuisance models of DoubleML models.

Note that in the current implementation, either all parameters have to be set globally or all parameters have to be provided fold-specific.

Usage
DoubleMLPLR$set_ml_nuisance_params(
  learner = NULL,
  treat_var = NULL,
  params,
  set_fold_specific = FALSE
)
Arguments
learner

(character(1))
The nuisance model/learner (see method params_names).

treat_var

(character(1))
The treatment varaible (hyperparameters can be set treatment-variable specific).

params

(named list())
A named list() with estimator parameters. Parameters are used for all folds by default. Alternatively, parameters can be passed in a fold-specific way if option fold_specificis TRUE. In this case, the outer list needs to be of length n_rep and the inner list of length n_folds.

set_fold_specific

(logical(1))
Indicates if the parameters passed in params should be passed in fold-specific way. Default is FALSE. If TRUE, the outer list needs to be of length n_rep and the inner list of length n_folds. Note that in the current implementation, either all parameters have to be set globally or all parameters have to be provided fold-specific.

Returns

self


Method tune()

Hyperparameter-tuning for DoubleML models.

The hyperparameter-tuning is performed using the tuning methods provided in the mlr3tuning package. For more information on tuning in mlr3, we refer to the section on parameter tuning in the mlr3 book.

Usage
DoubleMLPLR$tune(
  param_set,
  tune_settings = list(n_folds_tune = 5, rsmp_tune = mlr3::rsmp("cv", folds = 5), measure
    = NULL, terminator = mlr3tuning::trm("evals", n_evals = 20), algorithm =
    mlr3tuning::tnr("grid_search"), resolution = 5),
  tune_on_folds = FALSE
)
Arguments
param_set

(named list())
A named list with a parameter grid for each nuisance model/learner (see method learner_names()). The parameter grid must be an object of class ParamSet.

tune_settings

(named list())
A named list() with arguments passed to the hyperparameter-tuning with mlr3tuning to set up TuningInstance objects. tune_settings has entries

  • terminator (Terminator)
    A Terminator object. Specification of terminator is required to perform tuning.

  • algorithm (Tuner or character(1))
    A Tuner object (recommended) or key passed to the respective dictionary to specify the tuning algorithm used in tnr(). algorithm is passed as an argument to tnr(). If algorithm is not specified by the users, default is set to "grid_search". If set to "grid_search", then additional argument "resolution" is required.

  • rsmp_tune (Resampling or character(1))
    A Resampling object (recommended) or option passed to rsmp() to initialize a Resampling for parameter tuning in mlr3. If not specified by the user, default is set to "cv" (cross-validation).

  • n_folds_tune (integer(1), optional)
    If rsmp_tune = "cv", number of folds used for cross-validation. If not specified by the user, default is set to 5.

  • measure (NULL, named list(), optional)
    Named list containing the measures used for parameter tuning. Entries in list must either be Measure objects or keys to be passed to passed to msr(). The names of the entries must match the learner names (see method learner_names()). If set to NULL, default measures are used, i.e., "regr.mse" for continuous outcome variables and "classif.ce" for binary outcomes.

  • resolution (character(1))
    The key passed to the respective dictionary to specify the tuning algorithm used in tnr(). resolution is passed as an argument to tnr().

tune_on_folds

(logical(1))
Indicates whether the tuning should be done fold-specific or globally. Default is FALSE.

Returns

self


Method clone()

The objects of this class are cloneable with this method.

Usage
DoubleMLPLR$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other DoubleML: DoubleML, DoubleMLIIVM, DoubleMLIRM, DoubleMLPLIV

Examples

library(DoubleML)
library(mlr3)
library(mlr3learners)
library(data.table)
set.seed(2)
ml_g = lrn("regr.ranger", num.trees = 10, max.depth = 2)
ml_m = ml_g$clone()
obj_dml_data = make_plr_CCDDHNR2018(alpha = 0.5)
dml_plr_obj = DoubleMLPLR$new(obj_dml_data, ml_g, ml_m)
dml_plr_obj$fit()
dml_plr_obj$summary()


## Not run: 
library(DoubleML)
library(mlr3)
library(mlr3learners)
library(mlr3tuning)
library(data.table)
set.seed(2)
ml_l = lrn("regr.rpart")
ml_m = ml_l$clone()
obj_dml_data = make_plr_CCDDHNR2018(alpha = 0.5)
dml_plr_obj = DoubleMLPLR$new(obj_dml_data, ml_l, ml_m)

param_grid = list(
  "ml_l" = paradox::ps(
    cp = paradox::p_dbl(lower = 0.01, upper = 0.02),
    minsplit = paradox::p_int(lower = 1, upper = 2)),
  "ml_m" = paradox::ps(
    cp = paradox::p_dbl(lower = 0.01, upper = 0.02),
    minsplit = paradox::p_int(lower = 1, upper = 2)))

# minimum requirements for tune_settings
tune_settings = list(
  terminator = mlr3tuning::trm("evals", n_evals = 5),
  algorithm = mlr3tuning::tnr("grid_search", resolution = 5))
dml_plr_obj$tune(param_set = param_grid, tune_settings = tune_settings)
dml_plr_obj$fit()
dml_plr_obj$summary()

## End(Not run)

Data set on financial wealth and 401(k) plan participation.

Description

Preprocessed data set on financial wealth and 401(k) plan participation. The raw data files are preprocessed to reproduce the examples in Chernozhukov et al. (2020). An internet connection is required to sucessfully download the data set.

Usage

fetch_401k(
  return_type = "DoubleMLData",
  polynomial_features = FALSE,
  instrument = FALSE
)

Arguments

return_type

(character(1))
If "DoubleMLData", returns a DoubleMLData object. If "data.frame" returns a data.frame(). If "data.table" returns a data.table(). Default is "DoubleMLData".

polynomial_features

(logical(1))
If TRUE polynomial freatures are added (see replication file of Chernozhukov et al. (2018)).

instrument

(logical(1))
If TRUE, the returned data object contains the variables e401 and p401. If return_type = "DoubleMLData", the variable e401 is used as an instrument for the endogenous treatment variable p401. If FALSE, p401 is removed from the data set.

Details

Variable description, based on the supplementary material of Chernozhukov et al. (2020):

  • net_tfa: net total financial assets

  • e401: = 1 if employer offers 401(k)

  • p401: = 1 if individual participates in a 401(k) plan

  • age: age

  • inc: income

  • fsize: family size

  • educ: years of education

  • db: = 1 if individual has defined benefit pension

  • marr: = 1 if married

  • twoearn: = 1 if two-earner household

  • pira: = 1 if individual participates in IRA plan

  • hown: = 1 if home owner

The supplementary data of the study by Chernozhukov et al. (2018) is available at https://academic.oup.com/ectj/article/21/1/C1/5056401#supplementary-data.

Value

A data object according to the choice of return_type.

References

Abadie, A. (2003), Semiparametric instrumental variable estimation of treatment response models. Journal of Econometrics, 113(2): 231-263.

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.


Data set on the Pennsylvania Reemployment Bonus experiment.

Description

Preprocessed data set on the Pennsylvania Reemploymnent Bonus experiment. The raw data files are preprocessed to reproduce the examples in Chernozhukov et al. (2020). An internet connection is required to sucessfully download the data set.

Usage

fetch_bonus(return_type = "DoubleMLData", polynomial_features = FALSE)

Arguments

return_type

(character(1))
If "DoubleMLData", returns a DoubleMLData object. If "data.frame" returns a data.frame(). If "data.table" returns a data.table(). Default is "DoubleMLData".

polynomial_features

(logical(1))
If TRUE polynomial freatures are added (see replication file of Chernozhukov et al. (2018)).

Details

Variable description, based on the supplementary material of Chernozhukov et al. (2020):

  • abdt: chronological time of enrollment of each claimant in the Pennsylvania reemployment bonus experiment.

  • tg: indicates the treatment group (bonus amount - qualification period) of each claimant.

  • inuidur1: a measure of length (in weeks) of the first spell of unemployment

  • inuidur2: a second measure for the length (in weeks) of

  • female: dummy variable; it indicates if the claimant's sex is female (=1) or male (=0).

  • black: dummy variable; it indicates a person of black race (=1).

  • hispanic: dummy variable; it indicates a person of hispanic race (=1).

  • othrace: dummy variable; it indicates a non-white, non-black, not-hispanic person (=1).

  • dep1: dummy variable; indicates if the number of dependents of each claimant is equal to 1 (=1).

  • dep2: dummy variable; indicates if the number of dependents of each claimant is equal to 2 (=1).

  • q1-q6: six dummy variables indicating the quarter of experiment during which each claimant enrolled.

  • recall: takes the value of 1 if the claimant answered “yes” when was asked if he/she had any expectation to be recalled

  • agelt35: takes the value of 1 if the claimant's age is less than 35 and 0 otherwise.

  • agegt54: takes the value of 1 if the claimant's age is more than 54 and 0 otherwise.

  • durable: it takes the value of 1 if the occupation of the claimant was in the sector of durable manufacturing and 0 otherwise.

  • nondurable: it takes the value of 1 if the occupation of the claimant was in the sector of nondurable manufacturing and 0 otherwise.

  • lusd: it takes the value of 1 if the claimant filed in Coatesville, Reading, or Lancaster and 0 otherwise.

  • These three sites were considered to be located in areas characterized by low unemployment rate and short duration of unemployment.

  • husd: it takes the value of 1 if the claimant filed in Lewistown, Pittston, or Scranton and 0 otherwise.

  • These three sites were considered to be located in areas characterized by high unemployment rate and short duration of unemployment.

  • muld: it takes the value of 1 if the claimant filed in Philadelphia-North, Philadelphia-Uptown, McKeesport, Erie, or Butler and 0 otherwise.

  • These three sites were considered to be located in areas characterized by moderate unemployment rate and long duration of unemployment."

The supplementary data of the study by Chernozhukov et al. (2018) is available at https://academic.oup.com/ectj/article/21/1/C1/5056401#supplementary-data.

The supplementary data of the study by Bilias (2000) is available at https://www.journaldata.zbw.eu/dataset/sequential-testing-of-duration-data-the-case-of-the-pennsylvania-reemployment-bonus-experiment.

Value

A data object according to the choice of return_type.

References

Bilias Y. (2000), Sequential Testing of Duration Data: The Case of Pennsylvania ‘Reemployment Bonus’ Experiment. Journal of Applied Econometrics, 15(6): 575-594.

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.

Examples

library(DoubleML)
df_bonus = fetch_bonus(return_type = "data.table")
obj_dml_data_bonus = DoubleMLData$new(df_bonus,
  y_col = "inuidur1",
  d_cols = "tg",
  x_cols = c(
    "female", "black", "othrace", "dep1", "dep2",
    "q2", "q3", "q4", "q5", "q6", "agelt35", "agegt54",
    "durable", "lusd", "husd"
  )
)
obj_dml_data_bonus

Generates data from a interactive IV regression (IIVM) model.

Description

Generates data from a interactive IV regression (IIVM) model. The data generating process is defined as

di=1{αxZ+vi>0},d_i = 1\left\lbrace \alpha_x Z + v_i > 0 \right\rbrace,

yi=θdi+xiβ+ui,y_i = \theta d_i + x_i' \beta + u_i,

ZBernoulli(0.5)Z \sim \textstyle{Bernoulli} (0.5) and

(uivi)N(0,(10.30.31)).\left(\begin{array}{c} u_i \\ v_i \end{array} \right) \sim \mathcal{N}\left(0, \left(\begin{array}{cc} 1 & 0.3 \\ 0.3 & 1 \end{array} \right) \right).

The covariates :xiN(0,Σ)x_i \sim \mathcal{N}(0, \Sigma), where Σ\Sigma is a matrix with entries Σkj=0.5jk\Sigma_{kj} = 0.5^{|j-k|} and β\beta is a dim_x-vector with entries βj=1j2\beta_j=\frac{1}{j^2}.

The data generating process is inspired by a process used in the simulation experiment of Farbmacher, Gruber and Klaaßen (2020).

Usage

make_iivm_data(
  n_obs = 500,
  dim_x = 20,
  theta = 1,
  alpha_x = 0.2,
  return_type = "DoubleMLData"
)

Arguments

n_obs

(integer(1))
The number of observations to simulate.

dim_x

(integer(1))
The number of covariates.

theta

(numeric(1))
The value of the causal parameter.

alpha_x

(numeric(1))
The value of the parameter αx\alpha_x.

return_type

(character(1))
If "DoubleMLData", returns a DoubleMLData object. If "data.frame" returns a data.frame(). If "data.table" returns a data.table(). If "matrix" a named list() with entries X, y, d and z is returned. Every entry in the list is a matrix() object. Default is "DoubleMLData".

References

Farbmacher, H., Guber, R. and Klaaßen, S. (2020). Instrument Validity Tests with Causal Forests. MEA Discussion Paper No. 13-2020. Available at SSRN:doi:10.2139/ssrn.3619201.


Generates data from a interactive regression (IRM) model.

Description

Generates data from a interactive regression (IRM) model. The data generating process is defined as

di=1{exp(cdxiβ)1+exp(cdxiβ)>vi},d_i = 1\left\lbrace \frac{\exp(c_d x_i' \beta)}{1+\exp(c_d x_i' \beta)} > v_i \right\rbrace,

yi=θdi+cyxiβdi+ζi,y_i = \theta d_i + c_y x_i' \beta d_i + \zeta_i,

with viU(0,1)v_i \sim \mathcal{U}(0,1), ζiN(0,1)\zeta_i \sim \mathcal{N}(0,1) and covariates xiN(0,Σ)x_i \sim \mathcal{N}(0, \Sigma), where Σ\Sigma is a matrix with entries Σkj=0.5jk\Sigma_{kj} = 0.5^{|j-k|}. β\beta is a dim_x-vector with entries βj=1j2\beta_j = \frac{1}{j^2} and the constancts cyc_y and cdc_d are given by

cy=Ry2(1Ry2)βΣβ,c_y = \sqrt{\frac{R_y^2}{(1-R_y^2) \beta' \Sigma \beta}},

cd=(π2/3)Rd2(1Rd2)βΣβ.c_d = \sqrt{\frac{(\pi^2 /3) R_d^2}{(1-R_d^2) \beta' \Sigma \beta}}.

The data generating process is inspired by a process used in the simulation experiment (see Appendix P) of Belloni et al. (2017).

Usage

make_irm_data(
  n_obs = 500,
  dim_x = 20,
  theta = 0,
  R2_d = 0.5,
  R2_y = 0.5,
  return_type = "DoubleMLData"
)

Arguments

n_obs

(integer(1))
The number of observations to simulate.

dim_x

(integer(1))
The number of covariates.

theta

(numeric(1))
The value of the causal parameter.

R2_d

(numeric(1))
The value of the parameter Rd2R_d^2.

R2_y

(numeric(1))
The value of the parameter Ry2R_y^2.

return_type

(character(1))
If "DoubleMLData", returns a DoubleMLData object. If "data.frame" returns a data.frame(). If "data.table" returns a data.table(). If "matrix" a named list() with entries X, y, d and z is returned. Every entry in the list is a matrix() object. Default is "DoubleMLData".

References

Belloni, A., Chernozhukov, V., Fernández-Val, I. and Hansen, C. (2017). Program Evaluation and Causal Inference With High-Dimensional Data. Econometrica, 85: 233-298.


Generates data from a partially linear IV regression model used in Chernozhukov, Hansen and Spindler (2015).

Description

Generates data from a partially linear IV regression model used in Chernozhukov, Hansen and Spindler (2015). The data generating process is defined as

zi=Πxi+ζi,z_i = \Pi x_i + \zeta_i,

di=xiγ+ziδ+ui,d_i = x_i'\gamma + z_i'\delta + u_i,

yi=αdi+xiβ+ϵi,y_i = \alpha d_i + x_i'\beta + \epsilon_i,

with

(εiuiζixi)N(0,(10.6000.6100000.25Ipnz0000Σ))\left(\begin{array}{c} \varepsilon_i \\ u_i \\ \zeta_i \\ x_i \end{array} \right) \sim \mathcal{N}\left(0, \left(\begin{array}{cccc} 1 & 0.6 & 0 & 0 \\ 0.6 & 1 & 0 & 0 \\ 0 & 0 & 0.25 I_{p_n^z} & 0 \\ 0 & 0 & 0 & \Sigma \end{array} \right) \right)

where Σ\Sigma is a pnx×pnxp_n^x \times p_n^x matrix with entries Σkj=0.5jk\Sigma_{kj} = 0.5^{|j-k|} and IpnzI_{p_n^z} is the pnz×pnzp^z_n \times p^z_n identity matrix. β=γ\beta=\gamma iis a pnxp^x_n-vector with entries βj=1j2\beta_j = \frac{1}{j^2}, δ\delta is a pnzp^z_n-vector with entries δj=1j2\delta_j = \frac{1}{j^2} and Π=(Ipnz,Opnz×(pnxpnz))\Pi = (I_{p_n^z}, O_{p_n^z \times (p_n^x - p_n^z)}).

Usage

make_pliv_CHS2015(
  n_obs,
  alpha = 1,
  dim_x = 200,
  dim_z = 150,
  return_type = "DoubleMLData"
)

Arguments

n_obs

(integer(1))
The number of observations to simulate.

alpha

(numeric(1))
The value of the causal parameter.

dim_x

(integer(1))
The number of covariates.

dim_z

(integer(1))
The number of instruments.

return_type

(character(1))
If "DoubleMLData", returns a DoubleMLData object. If "data.frame" returns a data.frame(). If "data.table" returns a data.table(). If "matrix" a named list() with entries X, y, d and z is returned. Every entry in the list is a matrix() object. Default is "DoubleMLData".

Value

A data object according to the choice of return_type.

References

Chernozhukov, V., Hansen, C. and Spindler, M. (2015), Post-Selection and Post-Regularization Inference in Linear Models with Many Controls and Instruments. American Economic Review: Papers and Proceedings, 105 (5): 486-90.


Generates data from a partially linear IV regression model with multiway cluster sample used in Chiang et al. (2021).

Description

Generates data from a partially linear IV regression model with multiway cluster sample used in Chiang et al. (2021). The data generating process is defined as

Zij=Xijξ0+Vij,Z_{ij} = X_{ij}' \xi_0 + V_{ij},

Dij=Zijπ10+Xijπ20+vij,D_{ij} = Z_{ij}' \pi_{10} + X_{ij}' \pi_{20} + v_{ij},

Yij=Dijθ+Xijζ0+εij,Y_{ij} = D_{ij} \theta + X_{ij}' \zeta_0 + \varepsilon_{ij},

with

Xij=(1ω1Xω2X)αijX+ω1XαiX+ω2XαjX,X_{ij} = (1 - \omega_1^X - \omega_2^X) \alpha_{ij}^X + \omega_1^X \alpha_{i}^X + \omega_2^X \alpha_{j}^X,

εij=(1ω1εω2ε)αijε+ω1εαiε+ω2εαjε,\varepsilon_{ij} = (1 - \omega_1^\varepsilon - \omega_2^\varepsilon) \alpha_{ij}^\varepsilon + \omega_1^\varepsilon \alpha_{i}^\varepsilon + \omega_2^\varepsilon \alpha_{j}^\varepsilon,

vij=(1ω1vω2v)αijv+ω1vαiv+ω2vαjv,v_{ij} = (1 - \omega_1^v - \omega_2^v) \alpha_{ij}^v + \omega_1^v \alpha_{i}^v + \omega_2^v \alpha_{j}^v,

Vij=(1ω1Vω2V)αijV+ω1VαiV+ω2VαjV,V_{ij} = (1 - \omega_1^V - \omega_2^V) \alpha_{ij}^V + \omega_1^V \alpha_{i}^V + \omega_2^V \alpha_{j}^V,

and αijX,αiX,αjXN(0,Σ)\alpha_{ij}^X, \alpha_{i}^X, \alpha_{j}^X \sim \mathcal{N}(0, \Sigma) where Σ\Sigma is a px×pxp_x \times p_x matrix with entries Σkj=sXjk\Sigma_{kj} = s_X^{|j-k|}.

Further

(αijεαijv),(αiεαiv),(αjεαjv)N(0,(1sεvsεv1))\left(\begin{array}{c} \alpha_{ij}^\varepsilon \\ \alpha_{ij}^v \end{array}\right), \left(\begin{array}{c} \alpha_{i}^\varepsilon \\ \alpha_{i}^v \end{array}\right), \left(\begin{array}{c} \alpha_{j}^\varepsilon \\ \alpha_{j}^v \end{array}\right) \sim \mathcal{N}\left(0, \left(\begin{array}{cc} 1 & s_{\varepsilon v} \\ s_{\varepsilon v} & 1 \end{array}\right) \right)

and αijV,αiV,αjVN(0,1)\alpha_{ij}^V, \alpha_{i}^V, \alpha_{j}^V \sim \mathcal{N}(0, 1).

Usage

make_pliv_multiway_cluster_CKMS2021(
  N = 25,
  M = 25,
  dim_X = 100,
  theta = 1,
  return_type = "DoubleMLClusterData",
  ...
)

Arguments

N

(integer(1))
The number of observations (first dimension).

M

(integer(1))
The number of observations (second dimension).

dim_X

(integer(1))
The number of covariates.

theta

(numeric(1))
The value of the causal parameter.

return_type

(character(1))
If "DoubleMLClusterData", returns a DoubleMLClusterData object. If "data.frame" returns a data.frame(). If "data.table" returns a data.table(). If "matrix" a named list() with entries X, y, d, z and cluster_vars is returned. Every entry in the list is a matrix() object. Default is "DoubleMLClusterData".

...

Additional keyword arguments to set non-default values for the parameters π10=1.0\pi_{10}=1.0, ωX=ωε=ωV=ωv=(0.25,0.25)\omega_X = \omega_{\varepsilon} = \omega_V = \omega_v = (0.25, 0.25), sX=sεv=0.25s_X = s_{\varepsilon v} = 0.25, or the pxp_x-vectors ζ0=π20=ξ0\zeta_0 = \pi_{20} = \xi_0 with default entries ζ0)j=0.5j\zeta_{0})_j = 0.5^j.

Value

A data object according to the choice of return_type.

References

Chiang, H. D., Kato K., Ma, Y. and Sasaki, Y. (2021), Multiway Cluster Robust Double/Debiased Machine Learning, Journal of Business & Economic Statistics, doi:10.1080/07350015.2021.1895815, https://arxiv.org/abs/1909.03489.


Generates data from a partially linear regression model used in Chernozhukov et al. (2018)

Description

Generates data from a partially linear regression model used in Chernozhukov et al. (2018) for Figure 1. The data generating process is defined as

di=m0(xi)+s1vi,d_i = m_0(x_i) + s_1 v_i,

yi=αdi+g0(xi)+s2ζi,y_i = \alpha d_i + g_0(x_i) + s_2 \zeta_i,

with viN(0,1)v_i \sim \mathcal{N}(0,1) and ζiN(0,1),\zeta_i \sim \mathcal{N}(0,1),. The covariates are distributed as xiN(0,Σ)x_i \sim \mathcal{N}(0, \Sigma), where Σ\Sigma is a matrix with entries Σkj=0.7jk\Sigma_{kj} = 0.7^{|j-k|}. The nuisance functions are given by

m0(xi)=a0xi,1+a1exp(xi,3)1+exp(xi,3),m_0(x_i) = a_0 x_{i,1} + a_1 \frac{\exp(x_{i,3})}{1+\exp(x_{i,3})},

g0(xi)=b0exp(xi,1)1+exp(xi,1)+b1xi,3,g_0(x_i) = b_0 \frac{\exp(x_{i,1})}{1+\exp(x_{i,1})} + b_1 x_{i,3},

with a0=1a_0=1, a1=0.25a_1=0.25, s1=1s_1=1, b0=1b_0=1, b1=0.25b_1=0.25, s2=1s_2=1.

Usage

make_plr_CCDDHNR2018(
  n_obs = 500,
  dim_x = 20,
  alpha = 0.5,
  return_type = "DoubleMLData"
)

Arguments

n_obs

(integer(1))
The number of observations to simulate.

dim_x

(integer(1))
The number of covariates.

alpha

(numeric(1))
The value of the causal parameter.

return_type

(character(1))
If "DoubleMLData", returns a DoubleMLData object. If "data.frame" returns a data.frame(). If "data.table" returns a data.table(). If "matrix" a named list() with entries X, y and d is returned. Every entry in the list is a matrix() object. Default is "DoubleMLData".

Value

A data object according to the choice of return_type.

References

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.


Generates data from a partially linear regression model used in a blog article by Turrell (2018).

Description

Generates data from a partially linear regression model used in a blog article by Turrell (2018). The data generating process is defined as

di=m0(xib)+vi,d_i = m_0(x_i' b) + v_i,

yi=θdi+g0(xib)+ui,y_i = \theta d_i + g_0(x_i' b) + u_i,

with viN(0,1)v_i \sim \mathcal{N}(0,1), uiN(0,1)u_i \sim \mathcal{N}(0,1), and covariates xiN(0,Σ)x_i \sim \mathcal{N}(0, \Sigma), where Σ\Sigma is a random symmetric, positive-definite matrix generated with clusterGeneration::genPositiveDefMat(). bb is a vector with entries bj=1jb_j=\frac{1}{j} and the nuisance functions are given by

m0(xi)=12πsinh(γ)cosh(γ)cos(xiν),m_0(x_i) = \frac{1}{2 \pi} \frac{\sinh(\gamma)}{\cosh(\gamma) - \cos(x_i-\nu)},

g0(xi)=sin(xi)2.g_0(x_i) = \sin(x_i)^2.

Usage

make_plr_turrell2018(
  n_obs = 100,
  dim_x = 20,
  theta = 0.5,
  return_type = "DoubleMLData",
  nu = 0,
  gamma = 1
)

Arguments

n_obs

(integer(1))
The number of observations to simulate.

dim_x

(integer(1))
The number of covariates.

theta

(numeric(1))
The value of the causal parameter.

return_type

(character(1))
If "DoubleMLData", returns a DoubleMLData object. If "data.frame" returns a data.frame(). If "data.table" returns a data.table(). If "matrix" a named list() with entries X, y and d is returned. Every entry in the list is a matrix() object. Default is "DoubleMLData".

nu

(numeric(1))
The value of the parameter ν\nu. Default is 0.

gamma

(numeric(1))
The value of the parameter γ\gamma. Default is 1.

Value

A data object according to the choice of return_type.

References

Turrell, A. (2018), Econometrics in Python part I - Double machine learning, Markov Wanderer: A blog on economics, science, coding and data. https://aeturrell.com/blog/posts/econometrics-in-python-parti-ml/.