xtdml: Abstract Class 'xtdml'

xtdmlR Documentation

Abstract Class xtdml

Description

Abstract base class that cannot be initialized.

xtdml estimates the structural parameter (treatment effect) in partially linear panel regression models with fixed effects using double machine learning (Clarke and Polselli, 2025). xtdml allows the estimation of the nuisance functions in the model by machine learning methods based on the panel data approach chosen by the user, and computation of the Neyman-orthogonal score functions.

xtdml follows the object-oriented architecture of DoubleML (Bach et al., 2024) and most of its notation, and uses the 'mlr3' ecosystem and the 'R6' package.

Format

R6::R6Class object.

Active bindings

all_coef_theta

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

all_dml1_coef_theta

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

all_se_theta

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

all_model_rmse

(matrix())
Model root-mean-squared-error.

apply_cross_fitting

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

coef_theta

(numeric())
Estimates for the causal parameter(s) "theta" 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_theta

(array())
Value of the score function \psi(W;\theta_0,\eta_0)=-\psi_a(W;\eta_0) \theta_0 + \psi_b(W;\eta_0) after calling fit().

psi_theta_a

(array())
Value of the score function component \psi_a(W;\eta_0) after calling fit().

psi_theta_b

(array())
Value of the score function component \psi_b(W;\eta_0) after calling fit().

res_y

(array())
Residual of output equation

res_d

(array())
Residual of treatment equation

predictions

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

targets

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

rmses

(array())
The root-mean-squared-errors of the nuisance parameters

all_model_mse

(array())
Collection of all mean-squared-errors of the model

model_rmse

(array())
The root-mean-squared-errors of the model

models

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

pval_theta

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

score

(character(1))
A character(1) specifying the score function among "orth-PO", "orth-IV". Default is "orth-PO".

se_theta

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

smpls

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

smpls_cluster

(list())
The partition used for cross-fitting. smpl is at cluster-var

t_stat_theta

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

tuning_res_theta

(named list())
Results from hyperparameter tuning.

Methods

Public methods


xtdml$new()

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

Usage
xtdml$new()

xtdml$print()

Prints xtdml objects.

Usage
xtdml$print()

xtdml$fit()

Estimates model.

Usage
xtdml$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


xtdml$split_samples()

Draws sample splitting for DML procedure.

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

Usage
xtdml$split_samples()
Returns

self


xtdml$tune()

Conducts hyperparameter tuning.

The hyperparameter tuning is performed using the tuning methods provided in the mlr3tuning package. For more information on tuning in mlr3, see the chapter on hyperparameter optimization in the mlr3 book.

Usage
xtdml$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), tuner =
    mlr3tuning::tnr("grid_search", resolution = 10)),
  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()). Each element must be a ParamSet object.

tune_settings

(named list())
A named list() of settings controlling the hyperparameter tuning process. Each entry is passed to the corresponding components from mlr3tuning:

  • terminator (⁠[bbotk::Terminator]⁠)
    A Terminator object specifying when the tuning process should stop (e.g., trm("evals", n_evals = 20)).

  • tuner a Tuner object created with tnr(), which defines the optimization algorithm. (e.g., tnr("grid_search") or tnr("random_search")). If set to "grid_search", then additional argument "resolution" is required.

  • rsmp_tune a Resampling object or a key passed to rsmp(). Defines the resampling strategy used during tuning (default: "cv").

  • n_folds_tune an integer scalar (optional). Number of folds used if rsmp_tune = "cv". Default is 5.

  • measure a named list() (optional). Contains the performance measures used for tuning. Each element must be either a Measure object or a key to msr(). Names must match the learner names (see learner_names()). If omitted, default measures are used ("regr.rmse" for regression and "classif.ce" for classification).

tune_on_folds

(logical(1))
Indicates whether the tuning should be performed separately for each cross-fitting fold (TRUE) or globally across all folds (FALSE, default).

Returns

self


xtdml$summary()

Summary for estimated model after calling fit().

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

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


xtdml$plot()

Plots nuisance-function diagnostics after calling fit(store_predictions = TRUE).

Produces a 2x2 panel with the following diagnostic plots for each nuisance parameter:

  • fitted vs residual(top-right)

  • fitted vs target (top-left)

  • fitted vs target (bottom-left)

  • Q-Q plot of residuals

For score "orth-PO", the nuisance parameters are l and m. For score "orth-IV", the nuisance parameters are g and m.

Usage
xtdml$plot(i_rep = 1L, i_treat = 1L, ask = interactive(), title = NULL, ...)
Arguments
i_rep

(integer(1)) repetition index. Default 1L.

i_treat

(integer(1)) treatment index. Default 1L.

ask

(logical(1))
Whether to ask before drawing the plot page. Default is interactive().

title

(character()) title of graph.

...

additional graphical arguments passed to plot().

Returns

Invisibly returns NULL.


xtdml$predict()

Computes predicted outcomes for specified values of the treatment variable.

Usage
xtdml$predict(d)
Arguments
d

(numeric())
Counterfactual treatment value. It can be can be a single value or a vector of multiple treatment levels.

Returns

An array() of predicted outcomes with dimensions ⁠(n_obs, n_d, n_rep, n_treat)⁠, where n_d is the number of treatment-value specifications.


xtdml$confint()

Confidence intervals for estimated model.

Usage
xtdml$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).


xtdml$learner_names()

Returns the names of the learners.

Usage
xtdml$learner_names()
Returns

character() with names of learners.


xtdml$params_names()

Returns the names of the nuisance models with hyperparameters.

Usage
xtdml$params_names()
Returns

character() with names of nuisance models with hyperparameters.


xtdml$set_ml_nuisance_params()

Sets hyperparameters for the nuisance models of estimated model.

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

Usage
xtdml$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 variAble (hyperparameters can be set treatment-variable specific).

params

(named list())
A named list() with estimator parameters for time-varying covariates. 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_per_cluster.

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_per_cluster. 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


xtdml$get_params()

Gets hyper-parameters for the nuisance model.

Usage
xtdml$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.


xtdml$get_panel_info()

Gets panel information for estimation models.

Usage
xtdml$get_panel_info()
Returns

named list()with panel information for the model.


xtdml$clone()

The objects of this class are cloneable with this method.

Usage
xtdml$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

Other xtdml: xtdml_plr


xtdml documentation built on Sept. 2, 2026, 1:07 a.m.