match.patients: Match patients

View source: R/matching.R

match.patientsR Documentation

Match patients

Description

This function matches patient pairs using the MatchIt package. Observed treatment effect was defined as the difference between outcomes in pairs of patients matched on patient characteristics (or on individualized treatment effect predictions). Predicted treatment effect of a matched pair was defined as the difference between the predicted outcome probability of the untreated patient minus the predicted outcome probability of the treated patient. Please note, this function is only applicable for binary outcomes.

Usage

match.patients(
  Y,
  W,
  X,
  p.0,
  p.1,
  tau.hat,
  print = FALSE,
  measure = "nearest",
  distance = "mahalanobis",
  estimand = NULL,
  ...
)

Arguments

Y

a vector of binary outcomes; 1 if an unfavourable event; 0 if not

W

a vector of treatment assignment; 1 for active treatment; 0 for control

X

a matrix or data.frame of patient characteristics or individualized treatment effect predictions, categorical variables may be coded as.factor() to create dummy variables when matching, do not include Y or W in this matrix

p.0

a vector of outcome probabilities under control

p.1

a vector of outcome probabilities under active treatment

tau.hat

a vector of individualized treatment effect predictions

print

TRUE if the summary of matching needs to be printed

measure

measure option of matchit function from MatchIt package (default="nearest")

distance

distance option of matchit function from MatchIt package (default="mahalanobis)

estimand

default NULL meaning that all patients in the smallest treatment arm get matched with one patient in other treatment arm; estimand can also be "ATT", "ATC" or "ATE", see Details of matchit function of MatchIt for more information

...

additional arguments for matchit function from MatchIt package

Value

The output of the match.patients function is

df.matched.patients

a dataframe containing the matched patients, thus each individual is included in this dataframe

df.matched.pairs

a dataframe containing only the matched pairs, and not the individuals

discarded

a vector of ID's of the patients omitted that are not matched

Examples

library(HTEPredictionMetrics)
set.seed(1)
n <- 100
Y <- sample(0:1, n, replace=TRUE)
W <- sample(0:1, n, replace=TRUE)
X <- as.data.frame(matrix(rnorm(n*3), n, 3))
colnames(X) <- c("varA", "varB", "varC")
# categorical variable
X$varD <- as.factor(sample(1:3, nrow(X), replace=TRUE))
p.0 <- runif(n)
p.1 <- runif(n)
tau.hat <- runif(n)
matched.patients <- match.patients(Y=Y, W=W, X=X,
                                   p.0=p.0, p.1=p.1, tau.hat=tau.hat,
                                   print=TRUE, measure="nearest",
                                   distance="mahalanobis", estimand=NULL)
matched.patients

CHMMaas/HTEPredictionMetrics documentation built on June 2, 2025, 5:04 a.m.