pub struct AutoDml { /* private fields */ }Expand description
Auto-DML estimator of θ = E[m(W; γ)].
ml_g learns γ(D, X) = E[Y | D, X] on W = (D, X) (the treatment in the
first column), the Riesz learner (default RieszLasso) learns α from
the functional, and the score is
ψ = m(W; γ̂) + α̂(W)·(Y − γ̂(W)) − θ,cross-fitted like every other model. Each treatment in the data gets the
same functional applied to it (other treatments act as covariates).
Sensitivity analysis uses σ² = E[(Y − γ)²] and ν² = E[2m(W; α) − α²].
use dml_core::{AutoDml, AverageDerivative, DmlData, Ols, ShiftEffect};
use ndarray::{Array1, Array2};
let n = 400;
let x = Array2::from_shape_fn((n, 1), |(i, _)| ((i * 7) % 11) as f64 / 5.0);
let d: Array1<f64> = (0..n).map(|i| x[[i, 0]] + ((i * 13) % 7) as f64 / 3.0).collect();
let y: Array1<f64> = (0..n).map(|i| 0.5 * d[i] + x[[i, 0]].sin() + ((i * 17) % 5) as f64 / 4.0).collect();
let data = DmlData::new(y, d, x)?;
// Average derivative E[∂γ/∂D]; here γ is linear in D with slope 0.5.
let fit = AutoDml::new(Ols::new(), AverageDerivative::new()).fit(&data)?;
assert!((fit.coef()[0] - 0.5).abs() < 0.1);
// Effect of raising every treatment by one unit.
let shift = AutoDml::new(Ols::new(), ShiftEffect::new(1.0)).fit(&data)?;
assert!((shift.coef()[0] - fit.coef()[0]).abs() < 1e-6);Implementations§
Source§impl AutoDml
impl AutoDml
pub fn new( ml_g: impl Regressor + 'static, functional: impl LinearFunctional + 'static, ) -> Self
Sourcepub fn from_boxed(
ml_g: Box<dyn Regressor>,
functional: Box<dyn LinearFunctional>,
) -> Self
pub fn from_boxed( ml_g: Box<dyn Regressor>, functional: Box<dyn LinearFunctional>, ) -> Self
Like AutoDml::new for boxed trait objects.
Sourcepub fn riesz(self, riesz: impl RieszLearner + 'static) -> Self
pub fn riesz(self, riesz: impl RieszLearner + 'static) -> Self
Learner for the Riesz representer (default RieszLasso::default).
pub fn riesz_boxed(self, riesz: Box<dyn RieszLearner>) -> Self
Sourcepub fn n_rep(self, n_rep: usize) -> Self
pub fn n_rep(self, n_rep: usize) -> Self
Number of independent sample splits (default 1). Estimates are aggregated across repetitions by the median, as in DoubleML.
Sourcepub fn fit(&self, data: &DmlData) -> Result<DmlFit>
pub fn fit(&self, data: &DmlData) -> Result<DmlFit>
Draw seeded sample splits and fit. With clustered data
(DmlData::with_clusters) whole clusters are assigned to folds
and standard errors are cluster-robust.
Sourcepub fn fit_with_cluster_folds(
&self,
data: &DmlData,
splits: &[Vec<ClusterFold>],
) -> Result<DmlFit>
pub fn fit_with_cluster_folds( &self, data: &DmlData, splits: &[Vec<ClusterFold>], ) -> Result<DmlFit>
Fit clustered data with explicit cluster folds, one
Vec<ClusterFold> per repetition.
Sourcepub fn sensitivity_benchmark(
&self,
data: &DmlData,
long: &DmlFit,
benchmarking_set: &[usize],
) -> Result<SensitivityBenchmark>
pub fn sensitivity_benchmark( &self, data: &DmlData, long: &DmlFit, benchmarking_set: &[usize], ) -> Result<SensitivityBenchmark>
Sensitivity benchmark for the covariate columns benchmarking_set:
refits this model without them (with the same sample splitting, so
long must come from fit with the current settings)
and compares it with long.
Trait Implementations§
Source§impl LinearScoreModel for AutoDml
impl LinearScoreModel for AutoDml
Source§fn estimate_score(
&self,
input: &ScoreInput<'_>,
folds: &[Fold],
) -> Result<ScoreEstimate>
fn estimate_score( &self, input: &ScoreInput<'_>, folds: &[Fold], ) -> Result<ScoreEstimate>
folds and return the score elements.Auto Trait Implementations§
impl !RefUnwindSafe for AutoDml
impl !UnwindSafe for AutoDml
impl Freeze for AutoDml
impl Send for AutoDml
impl Sync for AutoDml
impl Unpin for AutoDml
impl UnsafeUnpin for AutoDml
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more