Pure-MoonBit port of doubleml-for-py: Double / Debiased Machine Learning for partial linear, IRM, IV, DID, SSM, APO(S), PQ, QTE, LPQ, CVaR, RDD, BLP, and policy-tree models
Status: MIT, pure MoonBit, on native, wasm, wasm-gc and js, with 22 estimators. Development status below states what is verified against upstream and what is not claimed.
moon add riantr/moonbit_doubleML///|
import {
"riantr/moonbit_doubleML@0.164.58",
}$ moon test --target native --deny-warn
Total tests: 1117, passed: 1117, failed: 0.
$ moon run examples/main
=== MoonBit DML PLR (partialling out) ===
true theta_0 = 1
estimated theta = 1.092018247331361
standard error = 0.08875683254582736
...
$ python validate_irm_with_python.py
======================================================================
PASS |mb - handrolled_nrep5| (theta) = 8.868664e-02 < max(MODEL_TOL=0.1, 2.0*handrolled_n5_se) = 1.912555e-01// inside a function body -- MoonBit rejects a module-scope `let` bound to a call
let data = @moonbit_doubleML.DoubleMLData::new(x, y, d) // x : Matrix, y / d : Array[Double]
let fitted = @moonbit_doubleML.DoubleMLPLR::new(data, n_folds=2, n_rep=1, seed=3141).fit()
let coef = fitted.coef() // Double
let se = fitted.se() // Double
let (lo, hi) = fitted.confint()| Model | Score | Description |
|---|---|---|
| DoubleMLPLR | partialling-out | partially linear regression (upstream) |
| DoubleMLIRM | ATE | interactive regression model (upstream) |
| DoubleMLPLIV | partialling-out | partially linear IV regression (upstream) |
| DoubleMLIIVM | LATE | interactive IV model (upstream) |
| DoubleMLDID | observational | difference-in-differences (upstream) |
| DoubleMLDIDBinary | observational | DID with binary outcome (upstream) |
| DoubleMLDIDCS | observational | DID with staggered adoption (Callaway-Sant'Anna) (upstream design, no 1:1 class) -- the port's variant of upstream DoubleMLDIDMulti, without its gt_combinations selector |
| DoubleMLDIDCSBinary | observational | CS-DID with binary outcome (upstream) |
| DoubleMLDIDMulti | observational | multi-period DID with group-time ATT aggregation (upstream) |
| DoubleMLDIDCrossSection | observational | Sant'Anna-Zhao 2020 cross-section DID (upstream, renamed) -- upstream DoubleMLDIDCS |
| DoubleMLSSM | MAR | sample selection (missing-at-random) (upstream) |
| DoubleMLAPO | policy score | average potential outcomes for one treatment level (upstream) |
| DoubleMLAPOS | policy score | average potential outcomes across several treatment levels (upstream) |
| DoubleMLPQ | quantile | potential quantile (upstream) |
| DoubleMLQTE | quantile | quantile treatment effect (upstream) |
| DoubleMLLPQ | local polynomial | local potential quantile (upstream) |
| DoubleMLLPLR | partialling-out | partially logistic regression, Liu-Zhang-Zhou 2021 (upstream) |
| DoubleMLCVAR | CVaR | conditional value-at-risk (upstream) |
| DoubleMLRDD | local polynomial | regression discontinuity (upstream, renamed) -- upstream RDFlex |
| DoubleMLBLP | IV | best linear predictor of treatment effect (upstream) |
| DoubleMLPLPR | partialling-out | partially linear panel regression, Clarke-Polselli 2025 (upstream) |
| DoubleMLPolicyTree | policy | policy tree (upstream), + v0.98.0 honest split (honest = true) with leaf_se / policy_value_se |
How the names map. The estimator table's last column is the map; the derivation is in _verify/UPSTREAM_PROVENANCE.md and in ENGINEERING.md.
| estimator | instead of | because |
|---|---|---|
| DoubleMLAPOS | coef / se -> coefs / ses | one estimate per treatment level |
| DoubleMLQTE | coef / se -> coefs / ses | one estimate per quantile |
| DoubleMLDIDCS | coef / se -> coef_at / se_at | one ATT per (group, period) |
| DoubleMLDIDMulti | coef / se -> coef_at_idx / se_at_idx | the same cells, by row-major index |
| DoubleMLBLP | confint -> confint_joint | the interval is for a contrast of the IV coefficient vector |
| DoubleMLPolicyTree | no scalar coefficient at all | leaf_influence, leaf_se, policy_value, policy_value_se |
| estimators | n_folds | n_rep | seed |
|---|---|---|---|
| the other 16 | yes | yes | yes |
| DoubleMLPQ, DoubleMLQTE, DoubleMLLPQ | yes | no | yes |
| DoubleMLBLP, DoubleMLRDD, DoubleMLPolicyTree | no | no | no |
| learner arguments | estimators |
|---|---|
| ml_g / ml_m | DoubleMLAPO, DoubleMLAPOS, DoubleMLCVAR, DoubleMLDID, DoubleMLDIDBinary, DoubleMLDIDCS, DoubleMLDIDCSBinary, DoubleMLDIDCrossSection, DoubleMLDIDMulti, DoubleMLIRM, DoubleMLLPLR |
| ml_l / ml_m | DoubleMLPQ, DoubleMLQTE |
| ml_g / ml_m / ml_r | DoubleMLIIVM |
| ml_g / ml_m / ml_pi | DoubleMLSSM |
| ml_g | DoubleMLBLP, DoubleMLRDD |
| learner_l / learner_m | DoubleMLPLR |
| learner | DoubleMLPLIV, DoubleMLPLPR |
| none | DoubleMLLPQ, DoubleMLPolicyTree |
| learner | kind | sample_weight | note |
|---|---|---|---|
| LinearRegression | regression | WLS | OLS, the default |
| Ridge | regression | weighted | v0.120.0+, L2 penalty, unpenalised intercept |
| Lasso | regression | weighted | v0.120.0+, L1 penalty, coordinate descent |
| ElasticNet | regression | weighted | v0.120.0+, the convex L1/L2 blend |
| LogisticRegression | classification | weighted IRLS | binary, IRLS Newton-Raphson |
| RFClassifier | classification | weighted | v0.117.0+, Breiman 2001, Gini splits |
| GBClassifier | classification | weighted Newton leaf | v0.117.0+, Friedman 2001, binary log loss |
| RFLearner | regression | weighted splits/leaf | Breiman 2001, MSE splits |
| GBLearner | regression | weighted leaf | Friedman 2001, squared-error loss |
| ConstantLearner, NoopLearner | either | ignored | constant / zero predictors |
| ml_m | coef | rv |
|---|---|---|
| linear_regression | -225.86 | 0.043 |
| logistic_regression | 1.44 | 0.842 |
// inside a function body -- MoonBit rejects a module-scope `let` bound to a call
let fitted_cvar = @moonbit_doubleML.DoubleMLCVAR::new(
data,
ml_m=@moonbit_doubleML.LearnerDispatch::logistic_regression(
@moonbit_doubleML.LogisticRegression::new(),
),
).fit()| Estimator | OLS default | Evidence |
|---|---|---|
| DoubleMLIRM | hazardous | coef -225.86 vs 1.44 |
| DoubleMLAPO | hazardous | bias 5.246 vs 0.531; SE 86.28 vs 0.270 |
| DoubleMLAPOS | hazardous | per-level bias to 436.11 |
| DoubleMLDIDBinary | not demonstrated | 4 designs, ~14 configs, ~1e-4 |
| DoubleMLDID, DoubleMLDIDCS, DoubleMLDIDCSBinary, DoubleMLDIDCrossSection, DoubleMLDIDMulti | not demonstrated | doubly robust -- m cancels for treated rows |
| DoubleMLSSM | hazardous -- fixed in v0.138.0 | coef 242.116 vs 1.177 |
| DoubleMLCVAR | not demonstrated | 2.300 vs 2.373 |
| DoubleMLQTE | hazardous -- fixed in v0.139.0 | OLS arm frozen at -1.583 at the three measured taus 0.50 / 0.75 / 0.90 |
| DoubleMLIIVM | not demonstrated | 0.987 vs 1.031; SE 0.0047 vs 0.0747 (16x smaller) |
| DoubleMLPLR | not demonstrated | 1.015 vs 1.103 -- OLS better |
| DoubleMLLPLR | not demonstrated -- root-caused in v0.140.0-v0.142.0 | not an ml_m hazard; two failure modes; see below |
| DoubleMLPQ | hazardous -- fixed in v0.139.0 | ignored its quantile entirely |
| Driver | Model | DGP | True theta |
|---|---|---|---|
| examples/main | DoubleMLPLR + 11 others (IRM / PLIV / IIVM / DID / SSM / BLP / RDD / PQ / QTE / LPQ / PolicyTree) | Simple partially linear, n=500, p=5 | 1.0 |
| examples/datasets | DoubleMLPLR + DoubleMLIRM | Synthetic 401(k)-style, n=4000, 9 controls | 1.5 |
| examples/did_binary | DoubleMLDIDBinary | 2-period panel DID, 400 units | 1.0 |
| examples/did_cs | DoubleMLDIDCS | Staggered CS-DID, 4 cohorts x 4 periods -- 3 treatment groups (cohort 0 is never treated) | 1.0 |
| examples/did_cs_binary | DoubleMLDIDCSBinary | Staggered CS-DID with binary outcome | 1.0 |
| examples/did_multi | DoubleMLDIDMulti | Top-level multi-period DID + aggregation | 1.0 |
| examples/did_cross_section | DoubleMLDIDCrossSection | Sant'Anna-Zhao 2020 cross-section DID, 500 units | 1.0 |
| examples/plpr | DoubleMLPLPR | Static-panel PLR (60 units x 4 periods) | 1.0 |
| examples/lplr | DoubleMLLPLR | Partially logistic regression, LZZ2020 | 0.5 (logit-scale alpha) |
| examples/apo | DoubleMLAPO | 3-level discrete treatment (D in 0/1/2): the LEVEL E[Y(t)] | 1.0 (E[Y(1)]) / 2.5 (E[Y(2)]) |
| examples/apos | DoubleMLAPOS | 2-level discrete treatment: per-level E[Y(t)] PLUS pairwise CONTRASTS | 1.0 per level; contrast 0.0 |
| examples/cvar | DoubleMLCVAR | CVaR at q=0.5 | 1.74 |
| examples/ssm | DoubleMLSSM | Sharp synthetic treatment | 1.0 |
| examples/cluster | DoubleMLPLIV / DoubleMLPLR + cluster_* | Clustered data, cluster-robust SEs | 1.0 |
| examples/splitting | DoubleMLPLR + set_sample_splitting | External sample splitting (n=200, p=2) | 1.5 |
| examples/pava | pava core | Isotonic regression, exact (no MC error) | n/a -- fixed input cases, not a theta demo |
| examples/fuzz | wrappers | Random-property fuzz harness across 11 surfaces (native-only) | n/a |
| examples/bitexact | fixture | The bit-exact values and RNG keys validate_bitexact_with_python.py drives | n/a |
| examples/parity | fixture | The LPLR nuisance-space / instrument values the parity gate drives | n/a |
| examples/consumer_demo | library-user pattern | Minimal end-to-end PLR (no estimator-specific extras) | 1.0 |
| examples/api_server | DoubleMLPLR + DoubleMLIRM | HTTP service -- see below | n/a |
$ moon run examples/main
$ moon run examples/datasets
$ moon run examples/did_binary
$ moon run examples/did_cs
$ moon run examples/did_multi
$ moon run examples/did_cross_section$ moon build --target native examples/api_server
$ _build/native/debug/build/example/api_server/api_server.exe # listens on 127.0.0.1:4000
$ curl -s http://127.0.0.1:4000/healthz
{"status":"ok"}
$ curl -s -X POST http://127.0.0.1:4000/fit/plr \
-H 'Content-Type: application/json' \
-d '{"x":[[1.0,0.5],[2.0,1.5],[3.0,2.5],[4.0,3.5],[5.0,4.5],[6.0,5.5]],"y":[2.0,4.0,6.0,8.0,10.0,12.0],"d":[1.0,2.0,3.0,4.0,5.0,6.0],"n_folds":2,"seed":3141}'
{"estimator":"plr","coef":2,"se":0,"ci_lo":2,"ci_hi":2,"n_obs":6,"n_features":2}// inside a function body -- MoonBit rejects a module-scope `let` bound to a call
let data = @moonbit_doubleML.DoubleMLBinaryData::new(x, y, d)
let model = @moonbit_doubleML.DoubleMLLPLR::new(data).fit()
for w in model.warnings() { println(w) }| Item | Value |
|---|---|
| Repository | https://github.com/riantr/moonbit_doubleML |
| Author | riantr |
| License | MIT (port of upstream doubleml-for-py, BSD-3-Clause) |
| moon.mod version | 0.164.58 |
| Toolchain | moon 0.1.20261028 -- the version this release's tests, cross-checks and bit-exactness gate were run on, and the version every number in this table was re-verified on; a bare moon from cli.moonbitlang.com may be newer |
| Source layout | flat, moonbit_doubleML/ (the library) |
| .mbt file count | 220 .mbt files (65 production + 129 blackbox test + 26 whitebox test) |
| Estimators | 22 DoubleML* estimator structs (PLR / IRM / PLIV / IIVM / DID family / SSM / APO(S) / PQ / QTE / LPQ / LPLR / CVAR / RDD / BLP / PLPR / PolicyTree) |
| Backends | native, wasm, wasm-gc, js -- all pass moon test --target <backend> --deny-warn |
| Tests (native / wasm / js) | 1117 / 1117 / 1117 |
| Tests (wasm-gc) | 1123 / 1123 (lib + 6 doc tutorials) |
| Sandwich-variance coverage | 15 / 22 expose the scalar sandwich_se / cluster_sandwich_se / bias_corrected_coef; 4 more (DoubleMLAPOS, DoubleMLDIDCS, DoubleMLDIDMulti, DoubleMLQTE) expose per-cell variants sandwich_se_at / ..._at_idx; 3 expose none of that API (DoubleMLBLP, DoubleMLPolicyTree, DoubleMLRDD) -- but DoubleMLRDD (v0.96.0) and DoubleMLBLP (v0.97.0) do expose a heteroskedasticity-robust hac_se under their own name; DoubleMLPolicyTree exposes no robust SE at all. Introduced v0.79.0 (on DoubleMLIRM and DoubleMLPLR), extended to 19 / 22 by v0.100.0 |
| Python cross-checks | 24 / 24 PASS (validate_*_with_python.py); 25 of the 25 bit-exact items are IEEE-754 identical to CPython, and the 6 / 6 RNG keys are byte-identical |
| HTTP service | examples/api_server/ -- hand-rolled on moonbitlang/async, no third-party framework |
| script | upstream class | how the two sides get their rows |
|---|---|---|
| pyexample_did.py | DoubleMLDID on make_did_SZ2020 | upstream's own DGP |
| pyexample_did_cs2021.py | DoubleMLDIDMulti on make_did_CS2021 | upstream's own DGP |
| pyexample_did_binary.py | DoubleMLDIDBinary | shared rows |
| pyexample_did_cs_binary.py | DoubleMLDIDCSBinary | shared rows |
| pyexample_lplr.py | DoubleMLLPLR | shared rows + pinned outer partition |
| pyexample_pq.py | DoubleMLPQ / DoubleMLQTE / DoubleMLLPQ | integer-only DGP, rebuilt independently on both sides |
| pyexample_policytree.py | DoubleMLPolicyTree | integer-only DGP; the label vector over every row is compared, because the port's builder and upstream's DecisionTreeClassifier differ in threshold convention, criterion and leaf rule |
| pyexample_rdd.py | DoubleMLRDD vs rdrobust | integer-only DGP with genuine non-collinear noise; the bias-corrected arm is gated |
| pyexample_suite.py | the core estimator family | mixed |
| operation | bit-exact | why |
|---|---|---|
| + - * / | yes | IEEE-754 requires correct rounding, so same operands in the same order MUST agree |
| sqrt | yes | same guarantee -- 6 / 6 measured |
| cos, sin | observed 6 / 6 | agreement today, not guaranteed: neither is correctly rounded |
| ln | 5 / 6 | ln(3.0) differs by exactly 1 ULP: MoonBit 1.0986122886681096, CPython 1.0986122886681098 |
moonbit_doubleML/ <- the library (moon.mod v0.164.58, 220 .mbt files)
moon.pkg <- the package's imports and supported targets
... <- one file per estimator + DGPs + score / nuisance kernels
vectorized.mbt <- v0.81.0+ vectorised cross-fit helpers
doc/ <- wasm-gc-targeted numbered tutorials
001_introduction/
...
006_python_check/
examples/ <- 21 driver binaries (all listed in moon.work)
main/ <- 12 estimators in 18 printed runs, 20 model fits:
5 also run with n_rep=5, and RDD runs twice
(sharp, fuzzy)
datasets/ <- 401(k)-style ATE / ATT recovery
did_binary/ <- 2-period panel DID
did_cs/ <- staggered CS-DID
did_cs_binary/ <- staggered CS-DID (binary outcome)
did_multi/ <- multi-period DID aggregation
did_cross_section/ <- Sant'Anna-Zhao 2020
plpr/, lplr/, apos/, <- single-estimator focused demos
cvar/, fuzz/
consumer_demo/ <- library-user pattern (`examples/consumer_demo`)
api_server/ <- HTTP service built on `moonbitlang/async`
moon.work <- 23-member workspace aggregator (the library, doc/, 21 examples)
AGENTS.md <- agent guide for coding agents (MoonBit convention)
skills/moonbit_doubleML.md <- agent skill: API surface + anti-patterns| declared | imported by the library? | note |
|---|---|---|
| moonbitlang/async@0.22.7 | no | referenced by nothing in the library: examples/api_server/ imports the same package at the same pin (moonbitlang/async@0.22.7), but no .mbt under moonbit_doubleML/ imports it |
| moonbit-community/sqlite3@0.2.3 | no | not moonbitlang/* -- added in v0.85.0 for DoubleMLPolicyTree memoisation, which now uses an in-memory FitCache |
$ moon test --target native --deny-warn
Total tests: 1117, passed: 1117, failed: 0.pub suberror BootstrapMethodError {
UnknownMethod(String)
}pub suberror BracketSignError {
UpperSignFailed
}pub suberror CalibrationFittingError {
IncompleteCVPartition
}pub suberror ClusterDataError {
MissingUnit(Int)
}pub suberror DIDDataError {
NonBinaryTreatment(Int)
}pub suberror EmptyArrayErrorpub suberror InvalidCalibrationError {
UnknownMethod(String)
}pub suberror PSConfigError {
InconsistentCVCalibration
}pub suberror VarEstClusterError {
JTooSmall(Double, Double, Int)
}type DidCsDatatype DidMultiDatapub struct DoubleMLAPO {
data : DoubleMLData
treatment_level : Double
n_folds : Int
n_rep : Int
seed : Int
smpls : Array[Array[Fold]]
propensity_clip : Double
ps_processor_config : PSProcessorConfig
normalize_ipw : Bool
ml_g : LearnerDispatch
ml_m : LearnerDispatch
g_hat : Array[Double]
m_hat : Array[Double]
coef : Double
se : Double
fitted : Bool
psi_a : Array[Double]
psi_b : Array[Double]
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
fit_cache : FitCache
} derive(Debug)fn DoubleMLAPO::bootstrap(self : DoubleMLAPO, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLAPOfn DoubleMLAPO::fit(self : DoubleMLAPO, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLAPOfn DoubleMLAPO::new(data : DoubleMLData, treatment_level? : Double, n_folds? : Int, n_rep? : Int, seed? : Int, propensity_clip? : Double, normalize_ipw? : Bool, ps_processor_config? : PSProcessorConfig?, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLAPOfn DoubleMLAPO::sensitivity_analysis(self : DoubleMLAPO, cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLAPO::sensitivity_analysis_cluster(self : DoubleMLAPO, cluster_ids? : Array[Int], cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLAPO::sensitivity_nu2_elements(self : DoubleMLAPO) -> (Array[Double], Array[Double]) raise m_alpha = 1 / m_hat_adj
rr = treated / m_hat_adj
nu2 = mean( 2*m_alpha - rr^2 )fn DoubleMLAPO::tune(self : DoubleMLAPO, param_set~ : Array[TuneParam], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLAPOpub struct DoubleMLAPOS {
data : DoubleMLData
treatment_levels : Array[Double]
n_folds : Int
n_rep : Int
seed : Int
smpls : Array[Array[Fold]]
propensity_clip : Double
ps_processor_config : PSProcessorConfig
normalize_ipw : Bool
ml_g : LearnerDispatch
ml_m : LearnerDispatch
coefs : Array[Double]
ses : Array[Double]
fitted : Bool
boot_t_stat : Array[Array[Double]]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
fit_cache : FitCache
psi_b_flat : Array[Double]
} derive(Debug)fn DoubleMLAPOS::bootstrap(self : DoubleMLAPOS, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLAPOSfn DoubleMLAPOS::causal_contrast(self : DoubleMLAPOS, reference_levels : Array[Double]) -> Array[Array[Double]]fn DoubleMLAPOS::cluster_sandwich_se_at(self : DoubleMLAPOS, treatment_index : Int, cluster_ids : Array[Int]) -> Doublefn DoubleMLAPOS::confint(self : DoubleMLAPOS, level? : Double, joint? : Bool) -> Array[(Double, Double)]fn DoubleMLAPOS::fit(self : DoubleMLAPOS, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLAPOSfn DoubleMLAPOS::new(data : DoubleMLData, treatment_levels : Array[Double], n_folds? : Int, n_rep? : Int, seed? : Int, propensity_clip? : Double, normalize_ipw? : Bool, ps_processor_config? : PSProcessorConfig?, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLAPOSfn DoubleMLAPOS::sandwich_se_at(self : DoubleMLAPOS, treatment_index : Int, kind : SandwichKind) -> Doublefn DoubleMLAPOS::sensitivity_analysis(self : DoubleMLAPOS, cf_y? : Double, cf_d? : Double) -> Array[SensitivityResult] raisefn DoubleMLAPOS::sensitivity_analysis_cluster(self : DoubleMLAPOS, cluster_ids? : Array[Int], cf_y? : Double, cf_d? : Double) -> Array[SensitivityResult] raisefn DoubleMLAPOS::set_sample_splitting(self : DoubleMLAPOS, smpls : Array[Array[Fold]]) -> DoubleMLAPOSfn DoubleMLAPOS::tune(self : DoubleMLAPOS, param_set~ : Array[TuneParam], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLAPOSpub struct DoubleMLBLP {
basis : Matrix
orth_signal : Array[Double]
cov_type : String
ml_g : LearnerDispatch
coef : Array[Double]
se : Array[Double]
fitted : Bool
n_obs : Int
rss : Double
var_y : Double
residuals : Array[Double]
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
fit_cache : FitCache
} derive(Debug)fn DoubleMLBLP::bootstrap(self : DoubleMLBLP, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLBLP S_cj = sum_{i in c} s_ij
var_j = sum_c S_cj^2 * n_c / (n_c - 1)fn DoubleMLBLP::confint_joint(self : DoubleMLBLP, contrast : Matrix, level? : Double) -> Array[(Double, Double)]fn DoubleMLBLP::new(basis : Matrix, orth_signal : Array[Double], cov_type? : String, ml_g? : LearnerDispatch) -> DoubleMLBLPfn DoubleMLBLP::sensitivity_analysis(self : DoubleMLBLP, cf_y? : Double, cf_d? : Double) -> Array[SensitivityResult] raisefn DoubleMLBLP::sensitivity_analysis_cluster(self : DoubleMLBLP, cluster_ids : Array[Int], cf_y? : Double, cf_d? : Double) -> Array[SensitivityResult] raise Y = expit(D * theta_0 + r_0(X)), Y in {0, 1}pub struct DoubleMLCVAR {
data : DoubleMLData
treatment : Double
quantile : Double
n_folds : Int
n_rep : Int
seed : Int
smpls : Array[Array[Fold]]
propensity_clip : Double
ps_processor_config : PSProcessorConfig
normalize_ipw : Bool
ml_g : LearnerDispatch
ml_m : LearnerDispatch
g_hat : Array[Double]
m_hat : Array[Double]
coef : Double
se : Double
fitted : Bool
psi_a : Array[Double]
psi_b : Array[Double]
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
fit_cache : FitCache
} derive(Debug)fn DoubleMLCVAR::bootstrap(self : DoubleMLCVAR, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLCVARfn DoubleMLCVAR::fit(self : DoubleMLCVAR, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLCVARfn DoubleMLCVAR::new(data : DoubleMLData, treatment? : Double, quantile? : Double, n_folds? : Int, n_rep? : Int, seed? : Int, propensity_clip? : Double, ps_processor_config? : PSProcessorConfig?, normalize_ipw? : Bool, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLCVARfn DoubleMLCVAR::sensitivity_analysis(self : DoubleMLCVAR, cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLCVAR::sensitivity_analysis_cluster(self : DoubleMLCVAR, cluster_ids? : Array[Int], cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLCVAR::set_sample_splitting(self : DoubleMLCVAR, smpls : Array[Array[Fold]]) -> DoubleMLCVARfn DoubleMLCVAR::tune(self : DoubleMLCVAR, param_set~ : Array[TuneParam], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLCVARpub struct DoubleMLDID {
data : DoubleMLDIDData
n_folds : Int
n_rep : Int
seed : Int
smpls : Array[Array[Fold]]
propensity_clip : Double
ps_processor_config : PSProcessorConfig
score : String
in_sample_normalization : Bool
ml_g : LearnerDispatch
ml_m : LearnerDispatch
strata : Array[Int]
g0_hat : Array[Double]
g1_hat : Array[Double]
m_hat : Array[Double]
coef : Double
se : Double
psi_a : Array[Double]
psi_b : Array[Double]
fitted : Bool
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
fit_cache : FitCache
} derive(Debug) Y_post = g_0(0, X) + D * theta + U_post, E[U | D, X] = 0
Y_pre = g_0(0, X) + U_pre, E[U_pre | X] = 0 dY = Y_post - Y_pre = g_1(1, X) - g_0(0, X) + D * theta + (U_post - U_pre) g0(X) = E[Y | D = 0, X] (trained on D = 0)
g1(X) = E[Y | D = 1, X] (trained on D = 1)
m(X) = P(D = 1 | X) (trained on all obs; observational
only, clipped to [eps, 1 - eps]) resid_d0 = Y - g0
p_hat = mean(D)
weight_psi_a = D / p_hat
weight_resid = (D - m) / (p_hat * (1 - m))
psi_b = (D - m)/(p_hat (1 - m)) * (Y - g0) [the g1 term cancels in ATT]
psi_a = -D / p_hat
psi(theta) = theta * psi_a + psi_b theta_hat = -mean(psi_b) / mean(psi_a)
J = mean(psi_a)
gamma = mean(psi(theta_hat)^2)
sigma2 = gamma / (J^2 * n)
se = sqrt(sigma2).fn DoubleMLDID::bootstrap(self : DoubleMLDID, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLDIDfn DoubleMLDID::fit(self : DoubleMLDID, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLDIDfn DoubleMLDID::new(data : DoubleMLDIDData, n_folds? : Int, n_rep? : Int, seed? : Int, propensity_clip? : Double, ps_processor? : PSProcessor, ps_processor_config? : PSProcessorConfig?, score? : String, in_sample_normalization? : Bool, strata? : Array[Int], ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLDIDfn DoubleMLDID::sensitivity_analysis(self : DoubleMLDID, cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLDID::sensitivity_analysis_cluster(self : DoubleMLDID, cluster_ids : Array[Int], cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLDID::sensitivity_nu2_elements(self : DoubleMLDID) -> (Array[Double], Array[Double]) raisep_hat = mean(d)
propensity_weight_d0 = m_hat / (1 - m_hat)
score == "observational", in_sample_normalization:
weight_d0 = (1 - d) * propensity_weight_d0
m_alpha = (d / p_hat) * (1/p_hat + propensity_weight_d0 / mean(weight_d0))
rr = d / p_hat - weight_d0 / mean(weight_d0)
score == "observational", not in_sample_normalization:
m_alpha = (d / p_hat^2) * (1 + propensity_weight_d0)
rr = d / p_hat - ((1 - d) / p_hat) * propensity_weight_d0
score == "experimental": (identical with and without the flag)
m_alpha = 1/p_hat + 1/(1 - p_hat) -- a CONSTANT array
rr = d / p_hat - (1 - d)/(1 - p_hat)
nu2_score_element = 2 * m_alpha - rr^2
nu2 = mean(nu2_score_element)fn DoubleMLDID::tune(self : DoubleMLDID, param_set~ : Array[TuneParam], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLDIDpub struct DoubleMLDIDBinary {
data : DoubleMLDIDBinaryData
g_value : Int
t_value_pre : Int
t_value_eval : Int
control_group : String
anticipation_periods : Int
n_folds : Int
n_rep : Int
seed : Int
propensity_clip : Double
ps_processor_config : PSProcessorConfig
score : String
in_sample_normalization : Bool
ml_g : LearnerDispatch
ml_m : LearnerDispatch
eval_idx : Array[Int]
inner : DoubleMLDID
fitted : Bool
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
} derive(Debug)fn DoubleMLDIDBinary::bootstrap(self : DoubleMLDIDBinary, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLDIDBinaryfn DoubleMLDIDBinary::cluster_sandwich_se(self : DoubleMLDIDBinary, cluster_ids : Array[Int]) -> Doublefn DoubleMLDIDBinary::confint(self : DoubleMLDIDBinary, joint? : Bool, level? : Double) -> (Double, Double)fn DoubleMLDIDBinary::fit(self : DoubleMLDIDBinary, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLDIDBinaryfn DoubleMLDIDBinary::new(data : DoubleMLDIDBinaryData, g_value : Int, t_value_pre : Int, t_value_eval : Int, control_group? : String, anticipation_periods? : Int, n_folds? : Int, n_rep? : Int, seed? : Int, propensity_clip? : Double, ps_processor? : PSProcessor, ps_processor_config? : PSProcessorConfig?, score? : String, in_sample_normalization? : Bool, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLDIDBinaryfn DoubleMLDIDBinary::sensitivity_analysis(self : DoubleMLDIDBinary, cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLDIDBinary::sensitivity_analysis_cluster(self : DoubleMLDIDBinary, cluster_ids : Array[Int], cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLDIDBinary::tune(self : DoubleMLDIDBinary, param_set~ : Array[TuneParam], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLDIDBinaryfn DoubleMLDIDBinaryData::new(x : Matrix, y : Array[Double], d : Array[Double], t : Array[Int], g : Array[Int], id : Array[Int]) -> DoubleMLDIDBinaryDatapub struct DoubleMLDIDCS {
data : DoubleMLDIDCSData
control_group : String
anticipation_periods : Int
n_folds : Int
n_rep : Int
seed : Int
propensity_clip : Double
ps_processor_config : PSProcessorConfig
in_sample_normalization : Bool
coef_matrix : Array[Double]
se_matrix : Array[Double]
psi_matrix : Array[Double]
psi_a_matrix : Array[Double]
residuals_matrix : Array[Double]
cell_psi_a : Array[Array[Double]]
cell_psi_b : Array[Array[Double]]
m_hat_long : Array[Double]
panel_folds : Array[Fold]
g_hat_d0t0_long : Array[Double]
g_hat_d0t1_long : Array[Double]
g_hat_d1t0_long : Array[Double]
g_hat_d1t1_long : Array[Double]
sigma2_panel : Double
nu2_panel : Double
psi_sigma2_long : Array[Double]
psi_nu2_long : Array[Double]
riesz_rep_long : Array[Double]
n_groups : Int
n_periods : Int
fitted : Bool
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
ml_g : LearnerDispatch
ml_m : LearnerDispatch
} derive(Debug)fn DoubleMLDIDCS::bias_corrected_coef_at(self : DoubleMLDIDCS, group_idx : Int, period_idx : Int) -> Doublefn DoubleMLDIDCS::bootstrap(self : DoubleMLDIDCS, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLDIDCSfn DoubleMLDIDCS::cluster_sandwich_se_at(self : DoubleMLDIDCS, group_idx : Int, period_idx : Int, cluster_ids : Array[Int]) -> Doublefn DoubleMLDIDCS::confint(self : DoubleMLDIDCS, joint? : Bool, level? : Double) -> Array[(Double, Double)]fn DoubleMLDIDCS::fit(self : DoubleMLDIDCS, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLDIDCSfn DoubleMLDIDCS::new(data : DoubleMLDIDCSData, control_group? : String, anticipation_periods? : Int, n_folds? : Int, n_rep? : Int, seed? : Int, propensity_clip? : Double, ps_processor? : PSProcessor, ps_processor_config? : PSProcessorConfig?, in_sample_normalization? : Bool, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLDIDCSfn DoubleMLDIDCS::sandwich_se_at(self : DoubleMLDIDCS, group_idx : Int, period_idx : Int, kind : SandwichKind) -> Double sandwich_se_at(g, t, HC0) == se_at(g, t)fn DoubleMLDIDCS::sensitivity_analysis(self : DoubleMLDIDCS, cf_y? : Double, cf_d? : Double) -> Array[SensitivityResult] raisefn DoubleMLDIDCS::sensitivity_analysis_cluster(self : DoubleMLDIDCS, cluster_ids : Array[Int], cf_y? : Double, cf_d? : Double) -> Array[SensitivityResult] raise nu2 = mean(2*m_alpha - rr^2) sigma2 = mean((y - g_hat)^2)fn DoubleMLDIDCS::tune(self : DoubleMLDIDCS, param_set~ : Array[TuneParam], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLDIDCSpub struct DoubleMLDIDCSBinary {
data : DoubleMLDIDCSData
g_value : Int
t_value_pre : Int
t_value_eval : Int
control_group : String
anticipation_periods : Int
n_folds : Int
n_rep : Int
seed : Int
propensity_clip : Double
ps_processor_config : PSProcessorConfig
score : String
in_sample_normalization : Bool
coef : Double
se : Double
psi_a : Array[Double]
psi_b : Array[Double]
g_d0_t0 : Array[Double]
g_d0_t1 : Array[Double]
g_d1_t0 : Array[Double]
g_d1_t1 : Array[Double]
m_hat : Array[Double]
subset_y : Array[Double]
subset_g : Array[Double]
subset_t : Array[Double]
n_obs_subset : Int
n_g_subset : Int
n_c_subset : Int
fitted : Bool
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
ml_g : LearnerDispatch
ml_m : LearnerDispatch
} derive(Debug)fn DoubleMLDIDCSBinary::bootstrap(self : DoubleMLDIDCSBinary, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLDIDCSBinaryfn DoubleMLDIDCSBinary::cluster_sandwich_se(self : DoubleMLDIDCSBinary, cluster_ids : Array[Int]) -> Doublefn DoubleMLDIDCSBinary::confint(self : DoubleMLDIDCSBinary, joint? : Bool, level? : Double) -> (Double, Double)fn DoubleMLDIDCSBinary::fit(self : DoubleMLDIDCSBinary, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLDIDCSBinaryfn DoubleMLDIDCSBinary::new(data : DoubleMLDIDCSData, g_value : Int, t_value_pre : Int, t_value_eval : Int, control_group? : String, anticipation_periods? : Int, n_folds? : Int, n_rep? : Int, seed? : Int, propensity_clip? : Double, ps_processor? : PSProcessor, ps_processor_config? : PSProcessorConfig?, score? : String, in_sample_normalization? : Bool, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLDIDCSBinaryfn DoubleMLDIDCSBinary::sensitivity_analysis(self : DoubleMLDIDCSBinary, cf_y? : Double, cf_d? : Double) -> SensitivityResult raise let d = self.data.d
residuals[i] = self.data.y[i] - g00[i] - (g10[i] - g00[i]) * d[i]fn DoubleMLDIDCSBinary::sensitivity_analysis_cluster(self : DoubleMLDIDCSBinary, cluster_ids : Array[Int], cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLDIDCSBinary::tune(self : DoubleMLDIDCSBinary, param_set~ : Array[TuneParam], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLDIDCSBinaryfn DoubleMLDIDCSData::new(x : Matrix, y : Array[Double], d : Array[Double], t : Array[Int], id : Array[Int], g : Array[Int]) -> DoubleMLDIDCSDatapub struct DoubleMLDIDCrossSection {
data : DoubleMLDIDCrossSectionData
n_folds : Int
n_rep : Int
seed : Int
score : String
in_sample_normalization : Bool
propensity_clip : Double
ps_processor_config : PSProcessorConfig
ml_g : LearnerDispatch
ml_m : LearnerDispatch
coef : Double
se : Double
psi_a : Array[Double]
psi_b : Array[Double]
g_d0_t0 : Array[Double]
g_d0_t1 : Array[Double]
g_d1_t0 : Array[Double]
g_d1_t1 : Array[Double]
m_hat : Array[Double]
fitted : Bool
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
} derive(Debug)fn DoubleMLDIDCrossSection::bootstrap(self : DoubleMLDIDCrossSection, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLDIDCrossSectionfn DoubleMLDIDCrossSection::cluster_sandwich_se(self : DoubleMLDIDCrossSection, cluster_ids : Array[Int]) -> Doublefn DoubleMLDIDCrossSection::confint(self : DoubleMLDIDCrossSection, joint? : Bool, level? : Double) -> (Double, Double)fn DoubleMLDIDCrossSection::disable_memoize(self : DoubleMLDIDCrossSection) -> DoubleMLDIDCrossSectionfn DoubleMLDIDCrossSection::enable_memoize(self : DoubleMLDIDCrossSection) -> DoubleMLDIDCrossSectionfn DoubleMLDIDCrossSection::fit(self : DoubleMLDIDCrossSection, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLDIDCrossSectionfn DoubleMLDIDCrossSection::new(data : DoubleMLDIDCrossSectionData, n_folds? : Int, n_rep? : Int, seed? : Int, score? : String, in_sample_normalization? : Bool, propensity_clip? : Double, ps_processor? : PSProcessor, ps_processor_config? : PSProcessorConfig?, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLDIDCrossSectionfn DoubleMLDIDCrossSection::sandwich_se(self : DoubleMLDIDCrossSection, kind : SandwichKind) -> Doublefn DoubleMLDIDCrossSection::sensitivity_analysis(self : DoubleMLDIDCrossSection, cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLDIDCrossSection::sensitivity_analysis_cluster(self : DoubleMLDIDCrossSection, cluster_ids : Array[Int], cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLDIDCrossSection::tune(self : DoubleMLDIDCrossSection, param_set~ : Array[TuneParam], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLDIDCrossSectionfn DoubleMLDIDCrossSectionData::new(x : Matrix, y : Array[Double], d : Array[Double], t : Array[Int], name? : String) -> DoubleMLDIDCrossSectionDatafn DoubleMLDIDData::new(x : Matrix, y : Array[Double], d : Array[Double]) -> DoubleMLDIDData raise DIDDataErrorpub struct DoubleMLDIDMulti {
data : DoubleMLDIDCSData
gt_combinations : Array[(Int, Int, Int)]
control_group : String
anticipation_periods : Int
n_folds : Int
n_rep : Int
seed : Int
ps_processor : PSProcessor
in_sample_normalization : Bool
ml_g : LearnerDispatch
ml_m : LearnerDispatch
group_sizes : Array[Int]
inner : DoubleMLDIDCS
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
fitted : Bool
memoize_enabled : Bool
} derive(Debug)fn DoubleMLDIDMulti::bootstrap(self : DoubleMLDIDMulti, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLDIDMultifn DoubleMLDIDMulti::cluster_sandwich_se_at_idx(self : DoubleMLDIDMulti, idx : Int, cluster_ids : Array[Int]) -> Doublefn DoubleMLDIDMulti::confint(self : DoubleMLDIDMulti, joint? : Bool, level? : Double) -> Array[(Double, Double)]fn DoubleMLDIDMulti::fit(self : DoubleMLDIDMulti, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLDIDMultifn DoubleMLDIDMulti::new(data : DoubleMLDIDCSData, gt_combinations? : Array[(Int, Int, Int)], gt_combinations_keyword? : String, control_group? : String, anticipation_periods? : Int, n_folds? : Int, n_rep? : Int, seed? : Int, ps_processor? : PSProcessor, in_sample_normalization? : Bool, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLDIDMultifn DoubleMLDIDMulti::sandwich_se_at_idx(self : DoubleMLDIDMulti, idx : Int, kind : SandwichKind) -> Double sandwich_se_at_idx(idx, kind) ==
inner.sandwich_se_at(gi, pi, kind) sandwich_se_at_idx(idx, HC0) == se_at_idx(idx)fn DoubleMLDIDMulti::sensitivity_analysis(self : DoubleMLDIDMulti, cf_y? : Double, cf_d? : Double) -> Array[SensitivityResult] raisefn DoubleMLDIDMulti::sensitivity_analysis_cluster(self : DoubleMLDIDMulti, cluster_ids : Array[Int], cf_y? : Double, cf_d? : Double) -> Array[SensitivityResult] raisefn DoubleMLDIDMulti::tune(self : DoubleMLDIDMulti, param_set~ : Array[TuneParam], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLDIDMultifn DoubleMLData::new(x : Matrix, y : Array[Double], d : Array[Double], cluster_vars? : Array[Int], z? : Array[Double]) -> DoubleMLDatapub struct DoubleMLIIVM {
data : DoubleMLIIVMData
n_folds : Int
n_rep : Int
seed : Int
smpls : Array[Array[Fold]]
propensity_clip : Double
ps_processor_config : PSProcessorConfig
ml_g : LearnerDispatch
ml_m : LearnerDispatch
ml_r : LearnerDispatch
g0_hat : Array[Double]
g1_hat : Array[Double]
m_hat : Array[Double]
r0_hat : Array[Double]
r1_hat : Array[Double]
coef : Double
se : Double
fitted : Bool
psi_a : Array[Double]
psi_b : Array[Double]
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
fit_cache : FitCache
} derive(Debug) Y = theta * D + g_0(D, X) + U, E[U | D, X] = 0
D = m_0(X, Z) + V, E[V | X, Z] = 0 g0(X) = E[Y | Z = 0, X] (trained only on Z = 0)
g1(X) = E[Y | Z = 1, X] (trained only on Z = 1)
m(X) = E[Z | X] (trained on all obs, then
clipped to [eps, 1 - eps])
r0(X) = E[D | Z = 0, X] (trained only on Z = 0)
r1(X) = E[D | Z = 1, X] (trained only on Z = 1) u_hat0 = Y - g0, u_hat1 = Y - g1
w_hat0 = D - r0, w_hat1 = D - r1 psi_b = (g1 - g0) + Z u_hat1 / m - (1 - Z) u_hat0 / (1 - m)
psi_a = -(r1 - r0) - Z w_hat1 / m + (1 - Z) w_hat0 / (1 - m)
psi(theta) = theta * psi_a + psi_b theta_hat = -mean(psi_b) / mean(psi_a)
J = mean(psi_a)
gamma = mean(psi(theta_hat)^2)
sigma2 = gamma / (J^2 * n)
se = sqrt(sigma2).fn DoubleMLIIVM::bootstrap(self : DoubleMLIIVM, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLIIVMfn DoubleMLIIVM::fit(self : DoubleMLIIVM, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch, ml_r? : LearnerDispatch, max_attempts? : Int) -> DoubleMLIIVMfn DoubleMLIIVM::new(data : DoubleMLIIVMData, n_folds? : Int, n_rep? : Int, seed? : Int, propensity_clip? : Double, ps_processor_config? : PSProcessorConfig?, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch, ml_r? : LearnerDispatch) -> DoubleMLIIVMfn DoubleMLIIVM::sensitivity_analysis(self : DoubleMLIIVM, cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLIIVM::sensitivity_analysis_cluster(self : DoubleMLIIVM, cluster_ids? : Array[Int], cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLIIVM::set_sample_splitting(self : DoubleMLIIVM, smpls : Array[Array[Fold]]) -> DoubleMLIIVMfn DoubleMLIIVM::tune(self : DoubleMLIIVM, param_set~ : Array[TuneParam], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLIIVMfn DoubleMLIIVMData::new(x : Matrix, y : Array[Double], d : Array[Double], z : Array[Double], cluster_vars? : Array[Int]) -> DoubleMLIIVMDatapub struct DoubleMLIRM {
data : DoubleMLData
n_folds : Int
n_rep : Int
seed : Int
smpls : Array[Array[Fold]]
propensity_clip : Double
ps_processor_config : PSProcessorConfig
ml_g : LearnerDispatch
ml_m : LearnerDispatch
g0_hat : Array[Double]
g1_hat : Array[Double]
m_hat : Array[Double]
m_raw : Array[Double]
coef : Double
se : Double
fitted : Bool
psi_a : Array[Double]
psi_b : Array[Double]
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
fit_cache : FitCache
} derive(Debug) Y = g_0(D, X) + U, E[U | D, X] = 0
D = m_0(X) + V, E[V | X] = 0 g0(X) = E[Y | D=0, X]
g1(X) = E[Y | D=1, X]
m(X) = P(D=1 | X) (the propensity score)
u0 = Y - g0(X)
u1 = Y - g1(X)
psi_b = (g1 - g0) + (D u1 / m - (1 - D) u0 / (1 - m))
psi_a = -1
psi(theta) = theta * psi_a + psi_b theta_hat = -mean(psi_b) / mean(psi_a) = mean(psi_b) J = mean(psi_a) = -1
gamma = mean(psi(theta_hat)^2)
sigma2 = gamma / (J^2 * n)
se = sqrt(sigma2)fn DoubleMLIRM::bootstrap(self : DoubleMLIRM, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLIRMfn DoubleMLIRM::fit(self : DoubleMLIRM, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch, max_attempts? : Int) -> DoubleMLIRMfn DoubleMLIRM::new(data : DoubleMLData, n_folds? : Int, n_rep? : Int, seed? : Int, propensity_clip? : Double, ps_processor_config? : PSProcessorConfig?, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLIRMfn DoubleMLIRM::sensitivity_analysis(self : DoubleMLIRM, cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLIRM::sensitivity_analysis_cluster(self : DoubleMLIRM, cluster_ids? : Array[Int], cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLIRM::sensitivity_nu2_elements(self : DoubleMLIRM) -> (Array[Double], Array[Double]) raise m_alpha = 1/m_hat + 1/(1 - m_hat)
rr = d/m_hat - (1 - d)/(1 - m_hat)
nu2 = mean( 2*m_alpha - rr^2 )fn DoubleMLIRM::tune(self : DoubleMLIRM, param_set~ : Array[TuneParam], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLIRMpub struct DoubleMLLPLR {
data : DoubleMLBinaryData
score : String
n_folds : Int
n_folds_inner : Int
n_rep : Int
seed : Int
smpls : Array[Array[Fold]]
ml_g : LearnerDispatch
ml_m : LearnerDispatch
coef_ : Double
se_ : Double
r_hat : Array[Double]
m_hat : Array[Double]
a_hat : Array[Double]
fitted : Bool
fit_warnings : Array[String]
psi_a : Array[Double]
psi_b : Array[Double]
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
fit_cache : FitCache
} derive(Debug)fn DoubleMLLPLR::bootstrap(self : DoubleMLLPLR, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLLPLRfn DoubleMLLPLR::fit(self : DoubleMLLPLR, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLLPLRfn DoubleMLLPLR::new(data : DoubleMLBinaryData, score? : String, n_folds? : Int, n_folds_inner? : Int, n_rep? : Int, seed? : Int, ml_g? : LearnerDispatch, ml_m? : LearnerDispatch) -> DoubleMLLPLR self.psi_a = sc.psi - theta_hat * sc.psi_deriv (OFFSET)
self.psi_b = sc.psi_deriv (DERIVATIVE) sandwich_se(HC0) == se()fn DoubleMLLPLR::sensitivity_analysis(self : DoubleMLLPLR, cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLLPLR::sensitivity_analysis_cluster(self : DoubleMLLPLR, cluster_ids : Array[Int], cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLLPLR::set_sample_splitting(self : DoubleMLLPLR, smpls : Array[Array[Fold]]) -> DoubleMLLPLRfn DoubleMLLPLR::tune(self : DoubleMLLPLR, param_set~ : Array[TuneParam], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLLPLRlet model = DoubleMLLPLR::new(data).fit()
for w in model.warnings() {
println(w) // the CALLER decides whether to print
}| stop_reason | meaning |
|---|---|
| degenerate_derivative | |d psi / d theta| < 1e-300 -- the Jacobian vanished, so the Newton direction is undefined |
| diverged | the iterate passed 1e6 and was abandoned |
| exhausted_step_budget | all 50 damped-Newton steps were used without meeting the 1e-9 step tolerance |
pub struct DoubleMLLPQ {
data : DoubleMLLPQData
treatment : Double
quantile : Double
n_folds : Int
seed : Int
propensity_clip : Double
ps_processor_config : PSProcessorConfig
coef : Double
se : Double
fitted : Bool
predictions_g0 : Array[Double]
predictions_g1 : Array[Double]
predictions_m : Array[Double]
psi : Array[Double]
psi_a : Array[Double]
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
fit_cache : FitCache
} derive(Debug)fn DoubleMLLPQ::bootstrap(self : DoubleMLLPQ, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLLPQfn DoubleMLLPQ::new(data : DoubleMLLPQData, treatment? : Double, quantile? : Double, n_folds? : Int, seed? : Int, propensity_clip? : Double, ps_processor_config? : PSProcessorConfig?) -> DoubleMLLPQfn DoubleMLLPQ::sensitivity_analysis(self : DoubleMLLPQ, cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLLPQ::sensitivity_analysis_cluster(self : DoubleMLLPQ, cluster_ids : Array[Int], cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLLPQData::new(x : Matrix, y : Array[Double], d : Array[Double], z : Array[Double]) -> DoubleMLLPQDatapub struct DoubleMLPLIV {
data : DoubleMLPLIVData
n_folds : Int
n_rep : Int
seed : Int
smpls : Array[Array[Fold]]
learner : LearnerDispatch
l_hat : Array[Double]
r_hat : Array[Double]
m_hat : Array[Double]
coef : Double
se : Double
fitted : Bool
psi_a : Array[Double]
psi_b : Array[Double]
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
fit_cache : FitCache
} derive(Debug) Y = D * theta_0 + g_0(X) + zeta, E[zeta | D, X] = 0
D = m_0(X) + V, E[V | X] = 0
Z = ell_0(X) + xi, E[xi | X] = 0,
Cov(Z, V) != 0 (relevance) l_hat = E_hat[Y | X]
r_hat = E_hat[D | X]
m_hat = E_hat[Z | X]
u_hat = Y - l_hat
w_hat = D - r_hat
v_hat = Z - m_hat
psi_a = -w_hat * v_hat
psi_b = v_hat * u_hat
psi(theta) = theta * psi_a + psi_b theta_hat = -mean(psi_b) / mean(psi_a)
= mean(v_hat * u_hat) / mean(w_hat * v_hat)
J = mean(psi_a)
gamma = mean(psi(theta_hat)^2)
sigma2 = gamma / (J^2 * n)
se = sqrt(sigma2).fn DoubleMLPLIV::bootstrap(self : DoubleMLPLIV, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLPLIVfn DoubleMLPLIV::fit(self : DoubleMLPLIV, learner? : LearnerDispatch, max_attempts? : Int) -> DoubleMLPLIVfn DoubleMLPLIV::new(data : DoubleMLPLIVData, n_folds? : Int, n_rep? : Int, seed? : Int, learner? : LearnerDispatch) -> DoubleMLPLIVfn DoubleMLPLIV::sensitivity_analysis(self : DoubleMLPLIV, cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLPLIV::sensitivity_analysis_cluster(self : DoubleMLPLIV, cluster_ids? : Array[Int], cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLPLIV::set_sample_splitting(self : DoubleMLPLIV, smpls : Array[Array[Fold]]) -> DoubleMLPLIVfn DoubleMLPLIV::tune(self : DoubleMLPLIV, param_set~ : Array[LearnerDispatch], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLPLIVfn DoubleMLPLIVData::new(x : Matrix, y : Array[Double], d : Array[Double], z : Array[Double], cluster_vars? : Array[Int]) -> DoubleMLPLIVDatapub struct DoubleMLPLPR {
panel : DoubleMLPanelData
approach : String
score : String
n_folds : Int
n_rep : Int
seed : Int
learner : LearnerDispatch
coef_ : Double
se_ : Double
l_hat : Array[Double]
m_hat : Array[Double]
fitted : Bool
psi_a : Array[Double]
psi_b : Array[Double]
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
fit_cache : FitCache
} derive(Debug)fn DoubleMLPLPR::bootstrap(self : DoubleMLPLPR, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLPLPRfn DoubleMLPLPR::fit(self : DoubleMLPLPR, learner? : LearnerDispatch, max_attempts? : Int) -> DoubleMLPLPRfn DoubleMLPLPR::new(panel : DoubleMLPanelData, approach? : String, score? : String, n_folds? : Int, n_rep? : Int, seed? : Int, learner? : LearnerDispatch) -> DoubleMLPLPRfn DoubleMLPLPR::sensitivity_analysis(self : DoubleMLPLPR, cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLPLPR::sensitivity_analysis_cluster(self : DoubleMLPLPR, cluster_ids : Array[Int], cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLPLPR::tune(self : DoubleMLPLPR, param_set~ : Array[LearnerDispatch], scoring_method? : String, n_folds_tune? : Int, seed? : Int) -> DoubleMLPLPRpub struct DoubleMLPLR {
data : DoubleMLData
learner_l : LearnerDispatch
learner_m : LearnerDispatch
n_folds : Int
n_rep : Int
seed : Int
smpls : Array[Array[Fold]]
l_hat : Array[Double]
m_hat : Array[Double]
coef : Double
se : Double
fitted : Bool
psi_a : Array[Double]
psi_b : Array[Double]
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
tune_result : TuneResult?
memoize_enabled : Bool
fit_cache : FitCache
} derive(Debug) Y = D * theta_0 + g_0(X) + zeta, E[zeta | D, X] = 0
D = m_0(X) + V, E[V | X] = 0 psi_a(theta) = -(D - m_hat)^2,
psi_b(theta) = (D - m_hat) * (Y - l_hat),
psi(theta) = theta * psi_a + psi_b theta_hat = -mean(psi_b) / mean(psi_a)
= mean((D - m_hat)(Y - l_hat)) / mean((D - m_hat)^2). J = mean(psi_a) # expected derivative of psi w.r.t. theta
gamma = mean(psi(theta_hat)^2)
sigma2 = gamma / (J^2 * n)
se = sqrt(sigma2).fn DoubleMLPLR::bootstrap(self : DoubleMLPLR, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLPLRfn DoubleMLPLR::fit(self : DoubleMLPLR, learner_l? : LearnerDispatch, learner_m? : LearnerDispatch, max_attempts? : Int, score? : String, tune_result? : TuneResult?) -> DoubleMLPLRfn DoubleMLPLR::new(data : DoubleMLData, learner_l? : LearnerDispatch, learner_m? : LearnerDispatch, n_folds? : Int, n_rep? : Int, seed? : Int) -> DoubleMLPLRfn DoubleMLPLR::sensitivity_analysis(self : DoubleMLPLR, cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLPLR::sensitivity_analysis_cluster(self : DoubleMLPLR, cluster_ids? : Array[Int], cf_y? : Double, cf_d? : Double) -> SensitivityResult raisefn DoubleMLPLR::tune(self : DoubleMLPLR, param_set~ : Array[TuneParam], scoring_method? : String, n_folds_tune? : Int, seed? : Int, score? : String) -> DoubleMLPLRpub struct DoubleMLPQ {
data : DoubleMLData
treatment : Double
quantile : Double
n_folds : Int
seed : Int
smpls : Array[Array[Fold]]
propensity_clip : Double
ps_processor_config : PSProcessorConfig
ml_l : LearnerDispatch
ml_m : LearnerDispatch
coef : Double
se : Double
fitted : Bool
psi : Array[Double]
psi_a : Array[Double]
boot_t_stat : Array[Double]
boot_method : String
n_rep_boot : Int
boot_seed : Int
memoize_enabled : Bool
fit_cache : FitCache
} derive(Debug)fn DoubleMLPQ::bootstrap(self : DoubleMLPQ, method_name? : String, n_rep_boot? : Int, seed? : Int) -> DoubleMLPQ