多重插补和倾向匹配后从爱情图中删除协变量

问题描述 投票:0回答:1

我使用小鼠创建了一系列多重插补数据集,然后应用 MatchThem 来匹配多个协变量。我正在尝试使用 cobalt 中的 love.plot 函数来创建爱情图,但我想省略图中的一个变量,因为我的数据集有很多匹配变量,而爱情图太忙了。

在下面的示例中,我想从爱情图中删除变量“已婚”。有办法做到这一点吗?

我的代码是:

data("lalonde_mis", package = "cobalt")
set.seed(100)

#Generate imputed data sets
m <- 10 #number of imputed data sets
imp.out <- mice::mice(lalonde_mis, m = m, print = FALSE) 


#Performing propensity score matching in each imputation
match.out <- MatchThem::matchthem(nodegree ~ age + race + 
                              re74 + re75, datasets = imp.out,
                           exact = "married",
                           method = "nearest",
                           caliper = 0.2,
                           distance = "glm")

# Removing the married variable from match.out
match.out$object$data$married <- NULL 

love.plot(match.out, threshold = .05, stats = "m",
      abs = FALSE,
      stars = "std", 
      which.imp = .none, agg.fun = "mean",
      drop.distance = TRUE) `
r propensity-score-matching
1个回答
0
投票

您可以做的一件事是使用

ggplot_build
提取数据并删除您不想绘制/重命名基础变量的变量。

library(dplyr)
library(ggplot2)


out = cobalt::love.plot(match.out, threshold = .05, stats = "m",
      abs = FALSE,
      stars = "std", 
      which.imp = .none, agg.fun = "mean",
      drop.distance = TRUE) 

plot_data = ggplot_build(out)

sans_marriage = plot_data$plot$data |>
  filter(var != 'married')

ggplot(sans_marriage, aes(x = stat, y = var, color = Sample)) +
  geom_point() +
  geom_vline(xintercept = .05, linetype = 'dashed') +
  geom_vline(xintercept = -0.05, linetype = 'dashed') +
  geom_vline(xintercept = 0) +
  theme_classic()

创建于 2024 年 10 月 25 日,使用 reprex v2.1.1

© www.soinside.com 2019 - 2024. All rights reserved.