创建非随机匹配对

Creating non-random matched pairs

我正在寻找一个 R 程序包,它可以让我将治疗组中的每个受试者与具有相似特征(年龄、性别等)的一般人群中的受试者相匹配。

我使用 MatchIt 包来做这类事情。您可能会收到使用倾向得分匹配的建议,但这种广泛使用的方法存在局限性(参见:PS Not

library(MatchIt)   # use for matching
library(tidyverse) # The overall package.  It will load lots of dependencies

set.seed(950)
n.size <- 1000

# This creates a tibble (an easier to use version of a data frame)
myData <- tibble(
a = lubridate::now() + runif(n.size) * 86400,
b = lubridate::today() + runif(n.size) * 30,
ID = 1:n.size,
#   d = runif(1000),
ivFactor = sample(c("Level 1", "Level 2", "Level 3", "Level 4" ), n.size, replace = TRUE),
age = round(rnorm(n = n.size, mean = 52, sd = 10),2),
outContinuous = rnorm(n = n.size, mean = 100, sd = 10),
tmt = sample(c(1,0), size = n.size, prob = c(.3, .7), replace = TRUE)
)

# Using matching methods suggestions found in Ho, Imai, King and Stuart 
myData.balance <- matchit(tmt~age + ivFactor, data = myData, method = "nearest", distance = "logit")

# Check to see if the matching improved balance between treatment and control group
summary(myData.balance)

 # Extract the matched data.  Now we can use this in subsequent analyses
 myData.matched <- match.data(myData.balance)