按距离为 R 中的条件逻辑回归创建病例对照匹配

Create case-control match by distance for conditional logistic regression in R

阿罗哈,

我计划 运行 对在全国空间上均匀分布的研究地点进行病例对照研究。我需要 select 数据集中的每个案例,然后将其与 x 个控件进行匹配(我们将使用敏感性分析来 select 最佳匹配,所以我需要能够 运行 它用于 1、2、3、4、5、6、7、8 等控件的数量)。由于数据有一个空间元素,我想 运行 通过 select 在距离案例 25000 米范围内控制控件来 运行 在距离矩阵内进行此计算。

我无法在 R 中找到 运行 此计算的最佳算法。有人知道可以帮助我实现此目的的最佳 R 包吗?

谢谢

为了解决这个问题,我做了以下工作

得到站点质心坐标(x,y)

将数据库拆分到我的病例对照组

运行个案的空间缓冲区

运行控件的交集

为所有路口分配了标签(match_no)

从 match_no 列中随机抽样

下面的代码。

db1 <- read.csv("db1_clf.csv")

library(sf)
dat <- st_as_sf(x=db1,
                   coords = c("x_coor_farm", "y_coor_farm"),
                   crs= "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")


##Filter the positive cases
library(dplyr)
case = dat %>% filter(TB2017 == "1")
control = dat %>% filter(TB2017 == "0")

case_buff = st_buffer(case, dist = 25000)

case_int = st_intersection(case_buff, control)

library(dplyr)

case_int$match_no <- as.integer(factor(case_int$idunique))

library(dplyr)

pos_db <- case_int %>%
  select("idunique", "match_no")

pos_db$geometry= NULL
pos_db <- unique(pos_db)

neg_db <- case_int %>%
  select("idunique.1", "match_no")

neg_db$geometry= NULL
neg_db <- unique(neg_db)


head(neg_db)


####Now the samples####
library(tidyverse)
control1 <- neg_db %>% group_by(match_no) %>% sample_n(1)
control2 <- neg_db %>% group_by(match_no) %>% sample_n(2)
control3 <- neg_db %>% group_by(match_no) %>% sample_n(3)
control4 <- neg_db %>% group_by(match_no) %>% sample_n(4)
control5 <- neg_db %>% group_by(match_no) %>% sample_n(5)
control6 <- neg_db %>% group_by(match_no) %>% sample_n(6)
control7 <- neg_db %>% group_by(match_no) %>% sample_n(7)
control8 <- neg_db %>% group_by(match_no) %>% sample_n(8)
control9 <- neg_db %>% group_by(match_no) %>% sample_n(9)
control10<- neg_db %>% group_by(match_no) %>% sample_n(10)