match_snap: Nearest Snapshot Matching

match_snapR Documentation

Nearest Snapshot Matching

Description

Longitudinal snapshot matching.

Usage

match_snap(
  x,
  data,
  id,
  tol=1e-6)

Arguments

x

Any valid input to match_on. match_snap will use x and any optional arguments to generate a distance before performing the matching.

Alternatively, a precomputed distance may be entered. A matrix of non-negative discrepancies, each indicating the permissibility and desirability of matching the unit corresponding to its row (a 'treatment') to the unit corresponding to its column (a 'control'); or, better, a distance specification as produced by match_on.

controls

The number of controls to be matched to each treatment.

data

data.frame to use to get order of the final matching factor. If a data.frame, the rownames are used. Useful to pass if you want to combine a match (using, e.g., cbind) with the data that were used to generate it (for example, in a propensity score matching).

id

A string to indicate which column of the data is the subject ID.

tol

The minimum difference in distance that match_snap will differentiate.

Details

The usage of this function is very similar to the fullmatch in the optmatch package.

Value

A vector indicating matched groups.

Author(s)

Tianchen Xu, Yiyue Lou

Examples

dat <- SnapMatch:::demo()

### Match With Covariate Distance
  # calculate the distance matrix
dis <- match_on(trt~X1+X2, data = dat, method="mahalanobis")
  # conduct nearest matching. 'Id' is the id column for each subject
pm <- match_snap(dis, data = dat, id = 'id')
  # plot result
# plot(xBalance(trt ~ X1+X2+strata(pm), data=dat), xlim=c(-2,1), ylim=c(0,3))

### Match With Propensity Score
  # calculate propensity score
prop <- glm(trt ~ X1+X2, data = dat, family = binomial())
  # conduct nearest matching by propensity score. 'Id' is the id column for each subject
pm <- match_snap(prop, data = dat, id = 'id')
  # plot result
# plot(xBalance(trt ~ X1+X2+strata(pm), data=dat), xlim=c(-2,1), ylim=c(0,3))

### Complex Match With 'match_on' Function
  # calculate distance by propensity score
dis <- match_on(glm(trt ~ X1+X2, data = dat, family = binomial()))
  # add caliper
dis <- caliper(dis,2) + dis
  # conduct nearest snapshot matching
dis <- as.matrix(dis)
dis[which(is.infinite(dis))] <- 100
pm <- match_snap(dis, data = dat, id = 'id')
  # plot result
# plot(xBalance(trt ~ X1+X2+strata(pm), data=dat), xlim=c(-2,1), ylim=c(0,3))


zjph602xtc/SnapMatch documentation built on July 8, 2022, 10 a.m.