# Own distance measure in R MatchIt

I would like to use propensity scores that I developed from a multilevel logistic model as the distance measure for matching using the MatchIt package in R. The documentation for MatchIt says that I can use my own distance measure with the distance option, but how do I specify it? I have tried:

set.seed(1234)
m.out.M1 <- matchit(data=retention, method="nearest", m.order="random",
distance= M1_PS, caliper=.2)


M1_PS is the variable name of my distance measure that is in the dataset, but I get error message, "M1_PS not found". I did not include a formula statement in my code because I'm assuming that I do not need one if I am using my own distance measure.

• You need a formula to tell MatchIt what the treatment variable is. It doesn't matter what is on the right side of the formula. – Noah Apr 10 '18 at 0:59

## 1 Answer

I found an answer to a similar question on the R MatchIt listserv. It says:

"It will look something like

m.out <- matchit(treat ~ x1 + x2, data=dataset,
distance=dataset\$myownmeasure)


The treat ~ x1 + x2 formula is then used just to tell matchit what the treatment variable is and what the covariates to check balance on are."