簡體   English   中英

按距離為 R 中的條件邏輯回歸創建案例對照匹配

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

阿羅哈,

我計划對在全國范圍內均勻分布的研究地點進行病例對照研究。 我需要 select 數據集中的每個案例,然后將其與 x 個控件進行匹配(我們將使用敏感性分析對 select 進行最佳匹配,因此我需要能夠運行 1、2、3、4、5 ,6,7,8 等控制數量)。 由於數據存在空間元素,因此我想通過選擇案例 25000 米內的控件在距離矩陣內運行此計算。

我找不到在 R 中運行此計算的最佳算法。 有人知道可以幫助我實現這一目標的最佳 R package 嗎?

謝謝

為了解決這個問題,我做了以下

獲得站點質心的坐標 (x,y)

將數據庫拆分為我的病例對照組

運行案例的空間緩沖區

跑了一個控件的交叉點

為所有交叉點分配了 label (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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM