addMahal | R Documentation |
Adds a rank-based Mahalanobis distance to an exisiting distance matrix.
addMahal(costmatrix, z, X)
costmatrix |
An existing cost matrix with sum(z) rows and sum(1-z) columns. The function checks the compatability of costmatrix, z and p; so, it may stop with an error if these are not of appropriate dimensions. In particular, costmatrix may come from startcost(). |
z |
A vector with z[i]=1 if individual i is treated or z[i]=0 if individual i is control. The rows of costmatrix refer to treated individuals and the columns refer to controls. |
X |
A matrix with length(z) rows containing covariates. |
The rank-based Mahalanobis distance is defined in section 9.3 of Rosenbaum (2020).
A new distance matrix that is the sum of costmatrix and the rank-based Mahalanobis distances.
Paul R. Rosenbaum
Rosenbaum, P. R. (2020) <doi:10.1007/978-3-030-46405-9> Design of Observational Studies (2nd Edition). New York: Springer.
Rubin, D. B. (1980) <doi:10.2307/2529981> Bias reduction using Mahalanobis-metric matching. Biometrics, 36, 293-298.
data(binge)
# Select two treated and three controls from binge
d<-binge[is.element(binge$SEQN,c(109315,109365,109266,109273,109290)),]
z<-1*(d$AlcGroup=="B")
names(z)<-d$SEQN
attach(d)
x<-cbind(age,female)
detach(d)
rownames(x)<-d$SEQN
dist<-startcost(z)
z
x
dist
dist<-addMahal(dist,z,x)
dist
rm(z,x,dist,d)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.