getMD: Get Mahalanobis Distance

View source: R/getMD.R

getMDR Documentation

Get Mahalanobis Distance

Description

getMD returns the Mahalanobis distance between two groups.

Usage

getMD(X, indicator, covX.inv = NULL)

Arguments

X

Covariate matrix (with units as rows and covariates as columns).

indicator

Binary indicator vector (must contain 1 or 0 for each unit). For example, could be a binary treatment or instrument.

covX.inv

Inverse of the covariate covariance matrix. Usually this is left as NULL, because getMD() will compute covX.inv for you. However, if getMD() is used many times (e.g., as in a permutation test), it can be computationally efficient to specify covX.inv beforehand.

Value

Mahalanobis distance between two groups.

Author(s)

Zach Branson and Luke Keele

References

Branson, Z. and Keele, L. (2020). Evaluating a Key Instrumental Variable Assumption Using Randomization Tests. American Journal of Epidemiology. To appear.

Examples

	#load the data
	data(icu.data)
	#the covariate matrix is
	X = as.matrix(subset(icu.data, select = -c(open_bin, icu_bed)))
	#mahalanobis distance across the treatment
	getMD(X = X, indicator = icu.data$icu_bed)
	#mahalanobis distance across the instrument
	getMD(X = X, indicator = icu.data$open_bin)

ivmodel documentation built on April 9, 2023, 5:08 p.m.