[R] problem of Mahalanobis distance matching using MatchIT

Giorgio Garziano giorgio.garziano at ericsson.com
Fri Oct 2 14:41:32 CEST 2015


About the "distance = NA" issue, please see if this comment helps:

https://lists.gking.harvard.edu/pipermail/matchit/2011-January/000174.html


Furthermore, the Mahalanobis NA distance values are hard-wired in the code, file matchit.R:

  ## no distance for full mahalanobis matching
  if(fn1=="distance2mahalanobis"){
    distance[1:length(distance)] <- NA
    class(out2) <- c("matchit.mahalanobis","matchit")
  }


About the resulting MDM matrix, I was able to create some "unmatching" by changing T1
so that its values do not always exactly map 1:1 to a pair of values each one taken
from the distribution values set control and treated (x1_.., x2_..).

n<-100
set.seed(1023)
x1_contr<-runif(n,0,5)
x2_contr<-runif(n,0,5)
x_contr<-cbind(x1=x1_contr,x2=x2_contr)
x1_treat<-runif(n,1,6)
x2_treat<-runif(n,1,6)

x_treat<-cbind(x1=x1_treat,x2=x2_treat)

T1<-c(rep(0,n/2),rep(1,3*n/2))

X.all<-rbind(x_contr,x_treat)

my.data<-data.frame(T1,X.all)
rownames(my.data)<-paste("ID",1:dim(my.data)[1])

library(MatchIt)
mdm.out<-matchit(T1~x1+x2,data=my.data, method="nearest", distance="mahalanobis",
                 mahvars=c("x1","x2"), caliper=0.15, replace=FALSE)

Sample sizes:
          Control Treated
All            50     150
Matched        50      50
Unmatched       0     100
Discarded       0       0


Hope this helps.

--

GG

	[[alternative HTML version deleted]]



More information about the R-help mailing list