Skip to main content

DmlData

Struct DmlData 

Source
pub struct DmlData { /* private fields */ }
Expand description

Data for a DML model.

  • y: outcome, length n
  • d: one or more treatments, shape (n, k) (continuous or 0/1)
  • x: covariates / confounders, shape (n, p)
  • z: optional instrument(s), length n (for Pliv, 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 (for Ssm)

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

Source

pub fn new(y: Array1<f64>, d: Array1<f64>, x: Array2<f64>) -> Result<Self>

Single treatment.

Source

pub fn with_treatments( y: Array1<f64>, d: Array2<f64>, x: Array2<f64>, ) -> Result<Self>

Several treatments, one per column of d.

Source

pub fn with_instrument(self, z: Array1<f64>) -> Result<Self>

Attach an instrument z (required by Pliv).

Source

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

Source

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.

Source

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

Source

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.

Source

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

Source

pub fn clusters(&self) -> Option<&[Array1<i64>]>

The cluster variables (one or two), if any.

Source

pub fn without_covariates(&self, drop: &[usize]) -> Result<Self>

The same data without the covariate columns drop (for sensitivity benchmarks).

Source

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, …).

Source

pub fn n_obs(&self) -> usize

Source

pub fn n_features(&self) -> usize

Source

pub fn n_treat(&self) -> usize

Source

pub fn y(&self) -> ArrayView1<'_, f64>

Source

pub fn d(&self) -> ArrayView2<'_, f64>

All treatments, shape (n, k).

Source

pub fn treatment(&self, j: usize) -> ArrayView1<'_, f64>

Treatment j.

Source

pub fn x(&self) -> ArrayView2<'_, f64>

Source

pub fn z(&self) -> Option<ArrayView1<'_, f64>>

The instrument, if exactly one is attached.

Source

pub fn instruments(&self) -> Option<ArrayView2<'_, f64>>

All instruments, one per column.

Source

pub fn n_instruments(&self) -> usize

Source

pub fn time(&self) -> Option<ArrayView1<'_, f64>>

The 0/1 time-period indicator, if attached.

Source

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

Source

pub fn external_predictions(&self) -> Option<&ExternalPredictions>

Source

pub fn selection(&self) -> Option<ArrayView1<'_, f64>>

The 0/1 selection indicator, if attached.

Source

pub fn treatment_names(&self) -> &[String]

Source

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

Source

pub fn is_binary_treatment(&self, j: usize) -> bool

True when every value of treatment j is exactly 0 or 1.

Trait Implementations§

Source§

impl Clone for DmlData

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DmlData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V