pub struct DmlData { /* private fields */ }Expand description
Data for a DML model.
y: outcome, lengthnd: one or more treatments, shape(n, k)(continuous or 0/1)x: covariates / confounders, shape(n, p)z: optional instrument(s), lengthn(forPliv, which also takes several, and, binary,Iivm)t: optional 0/1 time-period indicator (for repeated cross-sections,DidCs)s: optional 0/1 selection indicator, 1 where the outcome is observed (forSsm)
With several treatments each one is estimated in turn, and the other treatments are added to the covariates (as in DoubleML).
Implementations§
Source§impl DmlData
impl DmlData
Sourcepub fn with_treatments(
y: Array1<f64>,
d: Array2<f64>,
x: Array2<f64>,
) -> Result<Self>
pub fn with_treatments( y: Array1<f64>, d: Array2<f64>, x: Array2<f64>, ) -> Result<Self>
Several treatments, one per column of d.
Sourcepub fn with_instrument(self, z: Array1<f64>) -> Result<Self>
pub fn with_instrument(self, z: Array1<f64>) -> Result<Self>
Attach an instrument z (required by Pliv).
Sourcepub fn with_instruments(self, z: Array2<f64>) -> Result<Self>
pub fn with_instruments(self, z: Array2<f64>) -> Result<Self>
Attach several instruments, one per column (Pliv
combines them; the other instrumental models need exactly one).
Sourcepub fn with_time_indicator(self, t: Array1<f64>) -> Result<Self>
pub fn with_time_indicator(self, t: Array1<f64>) -> Result<Self>
Attach a 0/1 time-period indicator (post-period = 1), required by
DidCs for repeated cross-sections.
Sourcepub fn with_selection_indicator(self, s: Array1<f64>) -> Result<Self>
pub fn with_selection_indicator(self, s: Array1<f64>) -> Result<Self>
Attach a 0/1 selection indicator (1 where the outcome is observed),
required by the sample selection model Ssm. The
outcome of unselected observations is not used but must be finite
(e.g. 0).
Sourcepub fn with_clusters(self, cluster: Array1<i64>) -> Result<Self>
pub fn with_clusters(self, cluster: Array1<i64>) -> Result<Self>
Cluster the observations (e.g. by firm or school): sample splitting then keeps clusters together and standard errors are cluster-robust.
Sourcepub fn with_two_way_clusters(
self,
first: Array1<i64>,
second: Array1<i64>,
) -> Result<Self>
pub fn with_two_way_clusters( self, first: Array1<i64>, second: Array1<i64>, ) -> Result<Self>
Two-way clustering (e.g. by firm and by year).
Sourcepub fn without_covariates(&self, drop: &[usize]) -> Result<Self>
pub fn without_covariates(&self, drop: &[usize]) -> Result<Self>
The same data without the covariate columns drop (for sensitivity
benchmarks).
Sourcepub fn with_treatment_names<S: Into<String>>(
self,
names: impl IntoIterator<Item = S>,
) -> Result<Self>
pub fn with_treatment_names<S: Into<String>>( self, names: impl IntoIterator<Item = S>, ) -> Result<Self>
Names shown in summaries (default d, or d0, d1, …).
pub fn n_obs(&self) -> usize
pub fn n_features(&self) -> usize
pub fn n_treat(&self) -> usize
pub fn y(&self) -> ArrayView1<'_, f64>
Sourcepub fn d(&self) -> ArrayView2<'_, f64>
pub fn d(&self) -> ArrayView2<'_, f64>
All treatments, shape (n, k).
Sourcepub fn treatment(&self, j: usize) -> ArrayView1<'_, f64>
pub fn treatment(&self, j: usize) -> ArrayView1<'_, f64>
Treatment j.
pub fn x(&self) -> ArrayView2<'_, f64>
Sourcepub fn z(&self) -> Option<ArrayView1<'_, f64>>
pub fn z(&self) -> Option<ArrayView1<'_, f64>>
The instrument, if exactly one is attached.
Sourcepub fn instruments(&self) -> Option<ArrayView2<'_, f64>>
pub fn instruments(&self) -> Option<ArrayView2<'_, f64>>
All instruments, one per column.
pub fn n_instruments(&self) -> usize
Sourcepub fn time(&self) -> Option<ArrayView1<'_, f64>>
pub fn time(&self) -> Option<ArrayView1<'_, f64>>
The 0/1 time-period indicator, if attached.
Sourcepub fn with_external_predictions(self, external: ExternalPredictions) -> Self
pub fn with_external_predictions(self, external: ExternalPredictions) -> Self
Use user-supplied out-of-fold predictions for some nuisance learners
instead of fitting them (DoubleML’s external_predictions).
pub fn external_predictions(&self) -> Option<&ExternalPredictions>
Sourcepub fn selection(&self) -> Option<ArrayView1<'_, f64>>
pub fn selection(&self) -> Option<ArrayView1<'_, f64>>
The 0/1 selection indicator, if attached.
pub fn treatment_names(&self) -> &[String]
Sourcepub fn covariates_for(&self, j: usize) -> Cow<'_, Array2<f64>>
pub fn covariates_for(&self, j: usize) -> Cow<'_, Array2<f64>>
Covariates used when estimating the effect of treatment j: x plus
the other treatment columns. Borrowed when there is only one treatment.
(Cow = “clone on write”: either a borrowed view or an owned matrix.)
Sourcepub fn is_binary_treatment(&self, j: usize) -> bool
pub fn is_binary_treatment(&self, j: usize) -> bool
True when every value of treatment j is exactly 0 or 1.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DmlData
impl RefUnwindSafe for DmlData
impl Send for DmlData
impl Sync for DmlData
impl Unpin for DmlData
impl UnsafeUnpin for DmlData
impl UnwindSafe for DmlData
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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