【问题标题】:Creating non-random matched pairs创建非随机匹配对
【发布时间】:2018-05-03 23:06:42
【问题描述】:

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

【问题讨论】:

  • 请用数据创建一个可重现的示例,以便我们提供更好的帮助
  • 使用 google 找到它并不难。试试看,(一条线索:包匹配)
  • 我使用 Google 找到的解决方案要么涉及随机匹配,要么涉及复杂算法(例如距离估计)。

标签: r statistics methodology


【解决方案1】:

我使用 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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    • 2023-03-08
    • 1970-01-01
    • 2018-12-17
    • 2014-05-05
    • 1970-01-01
    相关资源
    最近更新 更多