-
Notifications
You must be signed in to change notification settings - Fork 14
Matching distances
Ben edited this page Aug 2, 2017
·
2 revisions
The following first prepares a distance of 0s and Infs, indicating which pairs are of the same sex and within 2 years of one another in age, before going on to pair them up optimally.
dist <- exactMatch(casestatus~sex, data=mydata)
dist <- match_on(casestatus~age, method="euclidean", within=dist)
dist <- caliper(dist, width=2)
pairs <- pairmatch(casestatus~date, within=dist)
The method="euclidean"
at the second line overrides the mahalanobis
default, which would have had the effect of constraining the match to be within +/- 2 pooled sds of age, not +/- 2 years.
If within the calipers you wanted to match on date
and age
, rather than just date
, you might instead end with the following. It'll combine date
and age
differences into a Mahalanobis distance.
pairs <- pairmatch(casestatus~ date + age, within=dist)
You might also take a look at Implementing non-standard matching distances