Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom list of codes #35

Open
ellessenne opened this issue Jan 14, 2021 · 4 comments
Open

Allow custom list of codes #35

ellessenne opened this issue Jan 14, 2021 · 4 comments
Assignees

Comments

@ellessenne
Copy link
Owner

The idea is to allow the user passing a list of codes, e.g. a different comorbidity map.
Could use something like this to turn a list of codes into a regex:

list_of_codes <- c("I10", "I11", "I12")
make_regex <- function(x) {
  x <- paste(x, collapse = "|^")
  x <- paste0("^", x)
  return(x)
}
list_of_codes
#> [1] "I10" "I11" "I12"
make_regex(list_of_codes)
#> [1] "^I10|^I11|^I12"

Created on 2021-01-14 by the reprex package (v0.3.0)

@ellessenne ellessenne self-assigned this Jan 14, 2021
@salmasian
Copy link
Contributor

Some of the code that @fiksdala has written in his fork already does something like this. He uses it to automatically parse the SAS code from AHRQ's latest Elixhauser algorithm and turn it into regex patterns that can be used when updating the R code of his fork.

@ellessenne
Copy link
Owner Author

Yep - I already have an idea on how to implement it, with the main goal to provide a "custom" score option to the end user.

@csylve7
Copy link

csylve7 commented Apr 15, 2021

I came across this package when I was researching ways to calculate comorbidity indices. Am I correct in understanding that this is the issue for allowing comorbidity() to work on multiple columns? The HCUP databases have ~40 columns of ICD10 codes, and I can't find a way to pass them through.

If so, how is this part of the project coming along? Do you need some help with it? I am developing my own R package for working with HCUP databases, and I'd love to be able to use your package for calculating Elxihauser scores.

@ellessenne
Copy link
Owner Author

Hi!
This issue is unrelated to that, actually (it has to do with the internal implementation of scoring algorithms).
Anyway, you can solve the multiple columns issue by reshaping long your data (see e.g. pivot_longer() from the {tidyr} package). After that you have a single column with all the codes that you can easily feed to comorbidity().
See the example below:

library(comorbidity)
library(tidyr)

set.seed(1)
N <- 15
x <- data.frame(
  id = seq(N),
  code1 = sample_diag(N),
  code2 = sample_diag(N),
  code3 = sample_diag(N),
  code4 = sample_diag(N),
  code5 = sample_diag(N),
  code6 = sample_diag(N),
  code7 = sample_diag(N),
  code8 = sample_diag(N),
  code9 = sample_diag(N),
  code10 = sample_diag(N)
)
head(x)
#>   id code1 code2 code3 code4 code5 code6 code7 code8 code9 code10
#> 1  1  C260  T408  F458  N013  J100   V46  P509  Y606  A422   C694
#> 2  2   S10  C005  D181  S398  T940  B901  B217   K10  S564    K02
#> 3  3  L572  T132  Q691  N823  S497  P788  Q113  N130  B210   S770
#> 4  4   X46  R853  L200  N850  D838  T788  Q978  N481  H118   A921
#> 5  5  V470  N926  P121  O747  H051  A665  Q984  S907  T622    P23
#> 6  6  Y449  P130   K45  M964  Y402  B582  I749  N951  P298   B942

xlong <- pivot_longer(x, cols = starts_with("code"))
head(xlong)
#> # A tibble: 6 x 3
#>      id name  value
#>   <int> <chr> <chr>
#> 1     1 code1 C260 
#> 2     1 code2 T408 
#> 3     1 code3 F458 
#> 4     1 code4 N013 
#> 5     1 code5 J100 
#> 6     1 code6 V46

comorbidity(x = xlong, id = "id", code = "value", score = "charlson", assign0 = FALSE)
#>    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   0    0      0  0    0    1
#> 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    0
#> 4   4   0   0   0    0        0    0      0   0   0    0      0  0    0    0
#> 5   5   0   0   0    0        0    0      0   0   0    0      0  0    0    0
#> 6   6   0   0   0    0        0    0      0   0   0    0      0  0    0    0
#> 7   7   0   0   0    0        0    1      0   0   1    0      0  0    0    1
#> 8   8   0   0   0    0        0    0      0   0   0    0      0  0    0    0
#> 9   9   0   0   0    0        0    0      0   0   0    0      0  0    0    0
#> 10 10   0   0   0    0        1    0      0   0   0    0      0  0    0    1
#> 11 11   0   0   0    0        0    0      0   0   0    0      0  0    0    1
#> 12 12   0   0   0    0        0    0      0   0   0    0      0  0    0    0
#> 13 13   0   0   0    0        0    1      0   0   0    0      0  0    0    1
#> 14 14   0   0   0    0        0    0      0   0   0    1      0  0    0    1
#> 15 15   0   0   0    0        0    0      0   0   0    0      0  0    0    1
#>    msld metacanc aids score index wscore windex
#> 1     0        0    0     1   1-2      2    1-2
#> 2     0        0    1     2   1-2      8    >=5
#> 3     0        0    1     1   1-2      6    >=5
#> 4     0        0    0     0     0      0      0
#> 5     0        0    0     0     0      0      0
#> 6     0        0    0     0     0      0      0
#> 7     0        0    0     3   3-4      4    3-4
#> 8     0        0    0     0     0      0      0
#> 9     0        0    0     0     0      0      0
#> 10    0        0    0     2   1-2      3    3-4
#> 11    1        0    0     2   1-2      5    >=5
#> 12    0        0    0     0     0      0      0
#> 13    0        0    0     2   1-2      3    3-4
#> 14    0        0    1     3   3-4      9    >=5
#> 15    0        0    0     1   1-2      2    1-2

Created on 2021-04-16 by the reprex package (v2.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants