我设计了一个病例对照研究,根据出生年份,性别和实践,将病例与对照组相匹配,比例为1:4。
dt <- data.table(ID = seq(1,500,1), practice = sample(seq(1,10,1), size = 500, replace = TRUE),
sex = sample(seq(from = 0, to = 1, by = 1), size = 500, replace = TRUE),
dob.year = sample(seq(from = 1910, to = 1960, by = 1), size = 500, replace = TRUE),
event = sample(seq(from = 0, to = 1, by = 1), size = 500, replace = TRUE),
start.date = sample(seq(as.Date("2000/1/1"), by = "month", length.out = 24), size = 500, replace = TRUE),
stop.date = sample(seq(as.Date("2009/1/1"), by = "month", length.out = 36), size = 500, replace = TRUE))
dt$dob.yearcat <- cut(dt$dob.year, breaks = seq(1910,1960,by=5),
labels = c("1910-1915", "1916-1920", "1921-1925", "1926-1930", "1931-1935",
"1936-1940", "1941-1945", "1946-1950", "1951-1955", "1956-1960"), include.lowest = TRUE,
right = TRUE)
# categorised age into 5 year blocks
为了将案例与控件匹配,我在ccwc
包中使用了Epi
命令:
require(Epi)
cc <- ccwc(entry = start.date, exit = stop.date, fail = event, origin = dob.year, controls=4,
match = list(sex, practice, dob.yearcat), include = list(ID, dob.year),
data=dt)
# matching 1:4 cases to controls
setnames(cc, old = c( "Fail", "ID", "dob.year", "NA.", "NA..1", "NA..2"),
new = c("event", "sex", "practice", "dob.yearcat", "ID", "dob.year"))
我知道ccwc
从风险集中随机抽取样本,但我遇到的问题是我不想要重复的控件:
cc <- as.data.table(cc)
cc[(duplicated(ID)), .N]
#in my current sample I have 159 duplicated IDs
在没有替换控件的情况下,有没有办法将案例与R中的控件匹配?