使用 R 中的合并症包对每位患者的合并症进行评分

Scoring Comorbidities per patient using the Comorbidity Package in R

我正在尝试根据他们的 ICD10 代码对我的数据中的每个患者进行评分。

library(dplyr)
library(comorbidity)

set.seed(1)
x <- data.frame(
  pat_id = sample(100:999, size = 300, replace = TRUE),
  code = sample_diag(n = 300)
)

我可以成功创建 Charlson 分数,并且输出包含一个包含原始患者 ID 的列 pat_id

charlson <- comorbidity(x = x, id = "pat_id", code = "code", map = "charlson_icd10_quan", assign0 = TRUE, tidy.codes = TRUE)

我创建了一个行号 ID,以便我可以加入分数输出

charlson_ids <- charlson %>% 
  mutate(id = row_number()) %>% 
  select(id,pat_id)

当我将 charlson 索引转换为分数时,没有患者 ID,因此我假设上面 charlson 的输出中的第 1 行与下面分数中的第 1 行相关联??

scores <- score(charlson, weights = NULL, assign0 = FALSE)

scores_df <- data.frame(scores) %>% 
  mutate(id = row_number())

combined <- charlson_ids %>% 
  inner_join(scores_df, by = c("id"="id")) %>% 
  select(-id)

如果有人能提出一种更简洁的方法来从每个患者的个人 ICD-10 代码到每个患者的合并症评分,我将不胜感激任何反馈。

score() 函数 returns charlson 的每行一个值(comorbidity() 函数的输出)。 因此,您可以将上面的内容简化为:

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(comorbidity)

set.seed(1)
x <- data.frame(
  pat_id = sample(seq(5), size = 100, replace = TRUE),
  code = sample_diag(n = 100)
)
charlson <- comorbidity(x = x, id = "pat_id", code = "code", map = "charlson_icd10_quan", assign0 = TRUE, tidy.codes = TRUE)
charlson_with_score <- mutate(charlson, score = score(charlson, weights = NULL, assign0 = FALSE))
charlson_with_score
#>   pat_id ami chf pvd cevd dementia copd rheumd pud mld diab diabwc hp rend canc
#> 1      1   0   0   0    0        0    0      0   0   1    1      0  0    0    0
#> 2      2   0   0   0    0        0    0      0   0   0    0      0  0    0    1
#> 3      3   0   0   0    0        0    0      0   0   0    0      0  0    0    1
#> 4      4   0   1   0    0        0    0      0   0   0    0      0  0    0    1
#> 5      5   0   0   0    1        0    0      0   0   0    0      0  0    0    0
#>   msld metacanc aids score
#> 1    0        0    0     2
#> 2    0        0    0     1
#> 3    1        0    0     2
#> 4    0        0    0     2
#> 5    0        0    1     2

reprex package (v2.0.1)

创建于 2022-03-15

或者,您可以一直通过管道:

x %>%
  comorbidity(id = "pat_id", code = "code", map = "charlson_icd10_quan", assign0 = TRUE, tidy.codes = TRUE) %>%
  mutate(score = score(x = ., weights = NULL, assign0 = FALSE))
#>   pat_id ami chf pvd cevd dementia copd rheumd pud mld diab diabwc hp rend canc
#> 1      1   0   0   0    0        0    0      0   0   1    1      0  0    0    0
#> 2      2   0   0   0    0        0    0      0   0   0    0      0  0    0    1
#> 3      3   0   0   0    0        0    0      0   0   0    0      0  0    0    1
#> 4      4   0   1   0    0        0    0      0   0   0    0      0  0    0    1
#> 5      5   0   0   0    1        0    0      0   0   0    0      0  0    0    0
#>   msld metacanc aids score
#> 1    0        0    0     2
#> 2    0        0    0     1
#> 3    1        0    0     2
#> 4    0        0    0     2
#> 5    0        0    1     2

...但这只是风格问题,如您所见,结果是一样的。

亚历山德罗