ellessenne / comorbidity

An R package for computing comorbidity scores.
https://ellessenne.github.io/comorbidity/
GNU General Public License v3.0
80 stars 21 forks source link

Missing codes cause max. score #50

Closed Chris-M-P closed 2 years ago

Chris-M-P commented 2 years ago

Missing ICD10 (and probably ICD9) codes cause people to be marked as having every comorbidity.

Compare ID 1 using this code:

set.seed(1)
x <- data.frame(
  id = sample(1:15, size = 200, replace = TRUE),
  code = sample_diag(200),
  stringsAsFactors = FALSE
)

# Charlson score based on ICD-10 diagnostic codes:
comorbidity(x = x, id = "id", code = "code", map = "charlson_icd10_quan", assign0 = FALSE)
id ami chf pvd cevd dementia copd rheumd pud mld diab diabwc hp rend canc msld metacanc aids
1   1   0   0   0    0        0    0      0   0   0    0      0  0    0    1    0        0    0

With the same person after setting 1 code to missing:

set.seed(1)
x <- data.frame(
  id = sample(1:15, size = 200, replace = TRUE),
  code = sample_diag(200),
  stringsAsFactors = FALSE
)

x$code[36] <- NA_character_

# Charlson score based on ICD-10 diagnostic codes:
comorbidity(x = x, id = "id", code = "code", map = "charlson_icd10_quan", assign0 = FALSE)
   id ami chf pvd cevd dementia copd rheumd pud mld diab diabwc hp rend canc msld metacanc aids
1   1   1   1   1    1        1    1      1   1   1    1      1  1    1    1    1        1    1
ellessenne commented 2 years ago

Hi, Thanks for reporting this, it should be an easy fix (just dropping the missing data before doing any calculation)!

ellessenne commented 2 years ago

Update: I pushed a fix to a new branch, could you give it a try by installing the new version with

library(remotes)
remotes::install_github("ellessenne/comorbidity", ref = "#50")
Chris-M-P commented 2 years ago

Looks good to me - thanks for the super quick fix!

ellessenne commented 2 years ago

Super, thanks for checking. I'll merge this branch, and the fix will be on CRAN with the next release of {comorbidity}!