Double machine learning for partially linear IV regression models
Source:R/double_ml_pliv.R
DoubleMLPLIV.Rd
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
\(Y - D\theta_0 = g_0(X) + \zeta\),
\(Z = m_0(X) + V\),
with \(E[\zeta|Z,X]=0\) and \(E[V|X] = 0\). \(Y\) is the outcome variable variable, \(D\) is the policy variable of interest and \(Z\) denotes one or multiple instrumental variables. The high-dimensional vector \(X = (X_1, \ldots, X_p)\) consists of other confounding covariates, and \(\zeta\) and \(V\) are stochastic errors.
See also
Other DoubleML:
DoubleML
,
DoubleMLIIVM
,
DoubleMLIRM
,
DoubleMLPLR
Super class
DoubleML::DoubleML
-> DoubleMLPLIV
Active bindings
partialX
(
logical(1)
)
Indicates whether covariates \(X\) should be partialled out.partialZ
(
logical(1)
)
Indicates whether instruments \(Z\) should be partialled out.
Methods
Inherited methods
DoubleML::DoubleML$bootstrap()
DoubleML::DoubleML$confint()
DoubleML::DoubleML$fit()
DoubleML::DoubleML$get_params()
DoubleML::DoubleML$learner_names()
DoubleML::DoubleML$p_adjust()
DoubleML::DoubleML$params_names()
DoubleML::DoubleML$print()
DoubleML::DoubleML$set_sample_splitting()
DoubleML::DoubleML$split_samples()
DoubleML::DoubleML$summary()
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
)
TheDoubleMLData
object providing the data and specifying the variables of the causal model.ml_l
(
LearnerRegr
,Learner
,character(1)
)
A learner of the classLearnerRegr
, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. Alternatively, aLearner
object with public fieldtask_type = "regr"
can be passed, for example of classGraphLearner
. The learner can possibly be passed with specified parameters, for examplelrn("regr.cv_glmnet", s = "lambda.min")
.ml_l
refers to the nuisance function \(l_0(X) = E[Y|X]\).ml_m
(
LearnerRegr
,Learner
,character(1)
)
A learner of the classLearnerRegr
, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. Alternatively, aLearner
object with public fieldtask_type = "regr"
can be passed, for example of classGraphLearner
. The learner can possibly be passed with specified parameters, for examplelrn("regr.cv_glmnet", s = "lambda.min")
.ml_m
refers to the nuisance function \(m_0(X) = E[Z|X]\).ml_r
(
LearnerRegr
,Learner
,character(1)
)
A learner of the classLearnerRegr
, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. Alternatively, aLearner
object with public fieldtask_type = "regr"
can be passed, for example of classGraphLearner
. The learner can possibly be passed with specified parameters, for examplelrn("regr.cv_glmnet", s = "lambda.min")
.ml_r
refers to the nuisance function \(r_0(X) = E[D|X]\).ml_g
(
LearnerRegr
,Learner
,character(1)
)
A learner of the classLearnerRegr
, which is available from mlr3 or its extension packages mlr3learners or mlr3extralearners. Alternatively, aLearner
object with public fieldtask_type = "regr"
can be passed, for example of classGraphLearner
. The learner can possibly be passed with specified parameters, for examplelrn("regr.cv_glmnet", s = "lambda.min")
.ml_g
refers to the nuisance function \(g_0(X) = E[Y - D\theta_0|X]\). Note: The learnerml_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 \(X\) should be partialled out. Default isTRUE
.partialZ
(
logical(1)
)
Indicates whether instruments \(Z\) should be partialled out. Default isFALSE
.n_folds
(
integer(1)
)
Number of folds. Default is5
.n_rep
(
integer(1)
)
Number of repetitions for the sample splitting. Default is1
.score
(
character(1)
,function()
)
Acharacter(1)
("partialling out"
or"IV-type"
) or afunction()
specifying the score function. If afunction()
is provided, it must be of the formfunction(y, z, d, l_hat, m_hat, r_hat, g_hat, smpls)
and the returned output must be a namedlist()
with elementspsi_a
andpsi_b
. Default is"partialling out"
.dml_procedure
(
character(1)
)
Acharacter(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 isTRUE
.apply_cross_fitting
(
logical(1)
)
Indicates whether cross-fitting should be applied. Default isTRUE
.
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 methodparams_names
).treat_var
(
character(1)
)
The treatment varaible (hyperparameters can be set treatment-variable specific).params
(named
list()
)
A namedlist()
with estimator parameters. Parameters are used for all folds by default. Alternatively, parameters can be passed in a fold-specific way if optionfold_specific
isTRUE
. In this case, the outer list needs to be of lengthn_rep
and the inner list of lengthn_folds
.set_fold_specific
(
logical(1)
)
Indicates if the parameters passed inparams
should be passed in fold-specific way. Default isFALSE
. IfTRUE
, the outer list needs to be of lengthn_rep
and the inner list of lengthn_folds
. Note that in the current implementation, either all parameters have to be set globally or all parameters have to be provided fold-specific.
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.
Arguments
param_set
(named
list()
)
A namedlist
with a parameter grid for each nuisance model/learner (see methodlearner_names()
). The parameter grid must be an object of class ParamSet.tune_settings
(named
list()
)
A namedlist()
with arguments passed to the hyperparameter-tuning with mlr3tuning to set up TuningInstance objects.tune_settings
has entriesterminator
(Terminator)
A Terminator object. Specification ofterminator
is required to perform tuning.algorithm
(Tuner orcharacter(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(). Ifalgorithm
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 orcharacter(1)
)
A Resampling object (recommended) or option passed to rsmp() to initialize a Resampling for parameter tuning inmlr3
. If not specified by the user, default is set to"cv"
(cross-validation).n_folds_tune
(integer(1)
, optional)
Ifrsmp_tune = "cv"
, number of folds used for cross-validation. If not specified by the user, default is set to5
.measure
(NULL
, namedlist()
, 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 methodlearner_names()
). If set toNULL
, 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 isFALSE
.
Examples
# \donttest{
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()
#> Estimates and significance testing of the effect of target variables
#> Estimate. Std. Error t value Pr(>|t|)
#> d 0.9722 0.1032 9.418 <2e-16 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#>
# }
if (FALSE) {
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::ParamSet$new(list(
paradox::ParamDbl$new("cp", lower = 0.01, upper = 0.02),
paradox::ParamInt$new("minsplit", lower = 1, upper = 2))),
"ml_m" = paradox::ParamSet$new(list(
paradox::ParamDbl$new("cp", lower = 0.01, upper = 0.02),
paradox::ParamInt$new("minsplit", lower = 1, upper = 2))),
"ml_r" = paradox::ParamSet$new(list(
paradox::ParamDbl$new("cp", lower = 0.01, upper = 0.02),
paradox::ParamInt$new("minsplit", 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()
}