Paquete comorbidity
1. Paquete comorbidity .
comorbidity
is an R package for computing comorbidity scores based on ICD codes data. As of version 0.1.0
, comorbidity
can calculate the Charlson comorbidity score and the Elixhauser comorbidity score, using either the ICD-9 or ICD-10 coding system. Details on each score supported by this package are presented in this vignette, along with examples on how to compute the different scores with this software.
The Charlson comorbidity index was first developed by Charlson et al. in 1987 to predict one-year mortality for patients who may have a range of comorbid conditions. Each condition is assigned a score depending on the risk of dying associated with each one, and consequently scores are summed to provide a total score to predict mortality.
The Charlson comorbidity index includes the following comorbid conditions: acute myocardial infarction, congestive heart failure, peripheral vascular disease, cerebrovascular disease, dementia, chronic obstructive pulmonary disease [COPD], rheumatoid disease, peptic ulcer disease, mild and moderate/severe liver disease, diabetes mellitus with and without complications, hemiplegia/paraplegia, renal disease, cancer (any malignancy) and metastatic solid tumour, AIDS/HIV.
Many variations of the Charlson comorbidity index have been presented, as outlined by Sharabiani et al. in their systematic review. comorbidity
computes the Quan et al. version of the Charlson score for both ICD-9-CM and ICD-10 coding systems, as outlined in their paper from 2005; in the next subsections, we present the different ICD codes utilised by comorbidity
. Categorisation of scores and weighted scores are based on work by Menendez et al.
The ICD-9-CM codes used by comorbidity
to compute the Charlson comorbidity index are:
Myocardial infarction: 410.x, 412.x
Congestive heart failure: 398.91, 402.01, 402.11, 402.91, 404.01, 404.03, 404.11, 404.13, 404.91, 404.93, 425.4 - 425.9, 428.x
Peripheral vascular disease: 093.0, 437.3, 440.x, 441.x, 443.1 - 443.9, 447.1, 557.1, 557.9, V43.4
Cerebrovascular disease: 362.34, 430.x - 438.x
Dementia: 290.x, 294.1, 331.2
Chronic pulmonary disease: 416.8, 416.9, 490.x - 505.x, 506.4, 508.1, 508.8
Rheumatic disease: 446.5, 710.0 - 710.4, 714.0 - 714.2, 714.8, 725.x
Peptic ulcer disease: 531.x - 534.x
Mild liver disease: 070.22, 070.23, 070.32, 070.33, 070.44, 070.54, 070.6, 070.9, 570.x, 571.x, 573.3, 573.4, 573.8, 573.9, V42.7
Diabetes without chronic complication: 250.0 - 250.3, 250.8, 250.9
Diabetes with chronic complication: 250.4 - 250.7
Hemiplegia or paraplegia: 334.1, 342.x, 343.x, 344.0 - 344.6, 344.9
Renal disease: 403.01, 403.11, 403.91, 404.02, 404.03, 404.12, 404.13, 404.92, 404.93, 582.x, 583.0 - 583.7, 585.x, 586.x, 588.0, V42.0, V45.1, V56.x
Any malignancy, including lymphoma and leukaemia, except malignant neoplasm of skin: 140.x - 172.x, 174.x - 195.8, 200.x - 208.x, 238.6
Moderate or severe liver disease: 456.0 - 456.2, 572.2- 572.8
Metastatic solid tumour: 196.x - 199.x
AIDS/HIV: 042.x - 044.x
There is a difference between codes reported above for peripheral vascular disease and the paper by Quan et al.; the code 47.1 reported in the paper is replaced by 447.1, as it is likely a typo. See here and here for more details.
The ICD-10 codes used by comorbidity
to compute the Charlson comorbidity index are:
Myocardial infarction: I21.x, I22.x, I25.2
Congestive heart failure: I09.9, I11.0, I13.0, I13.2, I25.5, I42.0, I42.5 - I42.9, I43.x, I50.x, P29.0
Peripheral vascular disease: I70.x, I71.x, I73.1, I73.8, I73.9, I77.1, I79.0, I79.2, K55.1, K55.8, K55.9, Z95.8, Z95.9
Cerebrovascular disease: G45.x, G46.x, H34.0, I60.x - I69.x
Dementia: F00.x - F03.x, F05.1, G30.x, G31.1
Chronic pulmonary disease: I27.8, I27.9, J40.x - J47.x, J60.x - J67.x, J68.4, J70.1, J70.3
Rheumatic disease: M05.x, M06.x, M31.5, M32.x - M34.x, M35.1, M35.3, M36.0
Peptic ulcer disease: K25.x - K28.x
Mild liver disease: B18.x, K70.0 - K70.3, K70.9, K71.3 - K71.5, K71.7, K73.x, K74.x, K76.0, K76.2 - K76.4, K76.8, K76.9, Z94.4
Diabetes without chronic complication: E10.0, E10.1, E10.6, E10.8, E10.9, E11.0, E11.1, E11.6, E11.8, E11.9, E12.0, E12.1, E12.6, E12.8, E12.9, E13.0, E13.1, E13.6, E13.8, E13.9, E14.0, E14.1, E14.6, E14.8, E14.9
Diabetes with chronic complication: E10.2 - E10.5, E10.7, E11.2 - E11.5, E11.7, E12.2 - E12.5, E12.7, E13.2 - E13.5, E13.7, E14.2 - E14.5, E14.7
Hemiplegia or paraplegia: G04.1, G11.4, G80.1, G80.2, G81.x, G82.x, G83.0 - G83.4, G83.9
Renal disease: I12.0, I13.1, N03.2 - N03.7, N05.2 - N05.7, N18.x, N19.x, N25.0, Z49.0 - Z49.2, Z94.0, Z99.2
Any malignancy, including lymphoma and leukaemia, except malignant neoplasm of skin: C00.x - C26.x, C30.x - C34.x, C37.x - C41.x, C43.x, C45.x - C58.x, C60.x - C76.x, C81.x - C85.x, C88.x, C90.x - C97.x
Moderate or severe liver disease: I85.0, I85.9, I86.4, I98.2, K70.4, K71.1, K72.1, K72.9, K76.5, K76.6, K76.7
Metastatic solid tumour: C77.x - C80.x
AIDS/HIV: B20.x - B22.x, B24.x
Each condition from the Charlson score is assigned a score when computing the weighted Charlson index, irrespectively of the coding system utilised. In particular, diabetes with complications, hemiplegia/paraplegia, renal disease, and malignancies are assigned a score of 2; moderate/severe liver disease is assigned a score of 3; metastatic solid tumour and AIDS/HIV are assigned a score of 6; the remaining comorbidities are assigned a score of 1. comorbidity
allows the option of applying a hierarchy of comorbidities should a more severe version be present: by choosing to do so (and that is the default behaviour of comorbidity
) a type of comorbidity is never computed more than once for a given patient.
The Elixhauser comorbidity index, analogously as the Charlson comorbidity index, is a method for measuring patient comorbidity based on ICD-9-CM and ICD-10 diagnosis codes found in administrative data developed by Elixhauser et al. in 1998. Over time, there have been changes to the Index based on different research. For instance:
comorbidity
is using the coding definition of Quan et al. (2005) for both ICD-9-CM and ICD-10 coding systems; the actual codes and weights utilised by comorbidity
are introduced in the next subsections. However, there is no consensus regarding the weighting algorithm, with several competing definitions. comorbidity
implements (and returns) both the AHRQ version of the Elixhauser index (Moore et al., 2017) and the van Walraven et al. (2009) version. The AHRQ Elixhauser comorbidity score only includes 29 comorbidities; the missing comorbidities are therefore assigned a weight of zero. Finally, the categorisation of scores and weighted scores is based on work by Menendez et al.
The ICD-9-CM codes used by comorbidity
to compute the Elixhauser comorbidity index are:
Congestive heart failure: 398.91, 402.01, 402.11, 402.91, 404.01, 404.03, 404.11, 404.13, 404.91, 404.93, 425.4 - 425.9, 428.x
Cardiac arrhythmias: 426.0, 426.13, 426.7, 426.9, 426.10, 426.12, 427.0 - 427.4, 427.6 - 427.9, 785.0, 996.01, 996.04, V45.0, V53.3
Valvular disease: 093.2, 394.x - 397.x, 424.x, 746.3 - 746.6, V42.2, V43.3
Pulmonary circulation disorders: 415.0, 415.1, 416.x, 417.0, 417.8, 417.9
Peripheral vascular disorders: 093.0, 437.3, 440.x, 441.x, 443.1 - 443.9, 447.1, 557.1, 557.9, V43.4
Hypertension, uncomplicated: 401.x
Hypertension, complicated: 402.x - 405.x
Paralysis: 334.1, 342.x, 343.x, 344.0 - 344.6, 344.9
Other neurological disorders: 331.9, 332.0, 332.1, 333.4, 333.5, 333.92, 334.x - 335.x, 336.2, 340.x, 341.x, 345.x, 348.1, 348.3, 780.3, 784.3
Chronic pulmonary disease: 416.8, 416.9, 490.x - 505.x, 506.4, 508.1, 508.8
Diabetes, uncomplicated: 250.0 - 250.3
Diabetes, complicated: 250.4 - 250.9
Hypothyroidism: 240.9, 243.x, 244.x, 246.1, 246.8
Renal failure: 403.01, 403.11, 403.91, 404.02, 404.03, 404.12, 404.13, 404.92, 404.93, 585.x, 586.x, 588.0, V42.0, V45.1, V56.x
Liver disease: 070.22, 070.23, 070.32, 070.33, 070.44, 070.54, 070.6, 070.9, 456.0 - 456.2, 570.x, 571.x, 572.2 - 572.8, 573.3, 573.4, 573.8, 573.9, V42.7
Peptic ulcer disease, excluding bleeding: 531.7, 531.9, 532.7, 532.9, 533.7, 533.9, 534.7, 534.9
AIDS/HIV: 042.x - 044.x
Lymphoma: 200.x - 202.x, 203.0, 238.6
Metastatic cancer: 196.x - 199.x
Solid tumour without metastasis: 140.x - 172.x, 174.x - 195.x
Rheumatoid arthritis/collagen vascular diseases: 446.x, 701.0, 710.0 - 710.4, 710.8, 710.9, 711.2, 714.x, 719.3, 720.x, 725.x, 728.5, 728.89, 729.30
Coagulopathy: 286.x, 287.1, 287.3 - 287.5
Obesity: 278.0
Weight loss: 260.x - 263.x, 783.2, 799.4
Fluid and electrolyte disorders: 253.6, 276.x
Blood loss anaemia: 280.0
Deficiency anaemia: 280.1 - 280.9, 281.x
Alcohol abuse: 265.2, 291.1 - 291.3, 291.5 - 291.9, 303.0, 303.9, 305.0, 357.5, 425.5, 535.3, 571.0 - 571.3, 980.x, V11.3
Drug abuse: 292.x, 304.x, 305.2 - 305.9, V65.42
Psychoses: 293.8, 295.x, 296.04, 296.14, 296.44, 296.54, 297.x, 298.x
Depression: 296.2, 296.3, 296.5, 300.4, 309.x, 311
The ICD-10 codes used by comorbidity
to compute the Elixhauser comorbidity index are:
Congestive heart failure: I09.9, I11.0, I13.0, I13.2, I25.5, I42.0, I42.5 - I42.9, I43.x, I50.x, P29.0
Cardiac arrhythmias: I44.1 - I44.3, I45.6, I45.9, I47.x - I49.x, R00.0, R00.1, R00.8, T82.1, Z45.0, Z95.0
Valvular disease: A52.0, I05.x - I08.x, I09.1, I09.8, I34.x - I39.x, Q23.0 - Q23.3, Z95.2 - Z95.4
Pulmonary circulation disorders: I26.x, I27.x, I28.0, I28.8, I28.9
Peripheral vascular disorders: I70.x, I71.x, I73.1, I73.8, I73.9, I77.1, I79.0, I79.2, K55.1, K55.8, K55.9, Z95.8, Z95.9
Hypertension, uncomplicated: I10.x
Hypertension, complicated: I11.x - I13.x, I15.x
Paralysis: G04.1, G11.4, G80.1, G80.2, G81.x, G82.x, G83.0 - G83.4, G83.9
Other neurological disorders: G10.x - G13.x, G20.x - G22.x, G25.4, G25.5, G31.2, G31.8, G31.9, G32.x, G35.x - G37.x, G40.x, G41.x, G93.1, G93.4, R47.0, R56.x
Chronic pulmonary disease: I27.8, I27.9, J40.x - J47.x, J60.x - J67.x, J68.4, J70.1, J70.3
Diabetes, uncomplicated: E10.0, E10.1, E10.9, E11.0, E11.1, E11.9, E12.0, E12.1, E12.9, E13.0, E13.1, E13.9, E14.0, E14.1, E14.9
Diabetes, complicated: E10.2 - E10.8, E11.2 - E11.8, E12.2 - E12.8, E13.2 - E13.8, E14.2 - E14.8
Hypothyroidism: E00.x - E03.x, E89.0
Renal failure: I12.0, I13.1, N18.x, N19.x, N25.0, Z49.0 - Z49.2, Z94.0, Z99.2
Liver disease: B18.x, I85.x, I86.4, I98.2, K70.x, K71.1, K71.3 - K71.5, K71.7, K72.x - K74.x, K76.0, K76.2 - K76.9, Z94.4
Peptic ulcer disease, excluding bleeding: K25.7, K25.9, K26.7, K26.9, K27.7, K27.9, K28.7, K28.9
AIDS/HIV: B20.x - B22.x, B24.x
Lymphoma: C81.x - C85.x, C88.x, C96.x, C90.0, C90.2
Metastatic cancer: C77.x - C80.x
Solid tumour without metastasis: C00.x - C26.x, C30.x - C34.x, C37.x - C41.x, C43.x, C45.x - C58.x, C60.x - C76.x, C97.x
Rheumatoid arthritis/collagen vascular diseases: L94.0, L94.1, L94.3, M05.x, M06.x, M08.x, M12.0, M12.3, M30.x, M31.0 - M31.3, M32.x - M35.x, M45.x, M46.1, M46.8, M46.9
Coagulopathy: D65 - D68.x, D69.1, D69.3 - D69.6
Obesity: E66.x
Weight loss: E40.x - E46.x, R63.4, R64
Fluid and electrolyte disorders: E22.2, E86.x, E87.x
Blood loss anaemia: D50.0
Deficiency anaemia: D50.8, D50.9, D51.x - D53.x
Alcohol abuse: F10, E52, G62.1, I42.6, K29.2, K70.0, K70.3, K70.9, T51.x, Z50.2, Z71.4, Z72.1
Drug abuse: F11.x - F16.x, F18.x, F19.x, Z71.5, Z72.2
Psychoses: F20.x, F22.x - F25.x, F28.x, F29.x, F30.2, F31.2, F31.5
Depression: F20.4, F31.3 - F31.5, F32.x, F33.x, F34.1, F41.2, F43.2
The weights for the Elixhauser comorbidity index are included in the following table, depending on the algorithm used for the weighting process:
Comorbidity Domain | AHRQ Algorithm | van Walraven Algorithm |
---|---|---|
Congestive heart failure | 9 | 7 |
Cardiac arrhythmias | (0) | 5 |
Valvular disease | 0 | -1 |
Pulmonary circulation disorders | 6 | 4 |
Peripheral vascular disorders | 3 | 2 |
Hypertension (combined uncomplicated and complicated) | -1 | 0 |
Paralysis | 5 | 7 |
Other neurological disorders | 5 | 6 |
Chronic pulmonary disease | 3 | 3 |
Diabetes, uncomplicated | 0 | 0 |
Diabetes, complicated | -3 | 0 |
Hypothyroidism | 0 | 0 |
Renal failure | 6 | 5 |
Liver disease | 4 | 11 |
Peptic ulcer disease, excluding bleeding | 0 | 0 |
AIDS/HIV | 0 | 0 |
Lymphoma | 6 | 9 |
Metastatic cancer | 14 | 12 |
Solid tumour without metastasis | 7 | 4 |
Rheumatoid arthritis/collagen vascular diseases | 0 | 0 |
Coagulopathy | 11 | 3 |
Obesity | -5 | -4 |
Weight loss | 9 | 6 |
Fluid and electrolyte disorders | 11 | 5 |
Blood loss anaemia | -3 | -2 |
Deficiency anaemia | -2 | -2 |
Alcohol abuse | -1 | 0 |
Drug abuse | -7 | -7 |
Psychoses | -5 | 0 |
Depression | -5 | -3 |
The AHRQ algorithm does not include cardiac arrhythmias, hence a weight of 0 is assigned.
Partimos de dos años 2012 y 2021, para abarcar dos tipos de CIE (clasificacion Intenacional de Enfermedades), la version 9 y 10
## # A tibble: 6 × 4
## Pac_Unif_Cod Diag_Cod Diag_Tipo ResDiag_Inicio_Fecha
## <dbl> <chr> <chr> <dttm>
## 1 36350 285.9 9 2011-01-01 00:00:00
## 2 36350 72.4 9 2011-01-01 00:00:00
## 3 36350 V27.0 9 2011-01-01 00:00:00
## 4 42434 157.3 9 2011-01-01 00:00:00
## 5 42434 401.9 9 2011-01-01 00:00:00
## 6 42434 52.7 9 2011-01-01 00:00:00
funcion01<-function(tabla,id="Pac_Unif_Cod",code="Diag_Cod", fecha="ResDiag_Inicio_Fecha", dicod=dicod) {
### 0. normaliza codigo (no es necesario el diag_tipo), pero aqui lo damos por dado###
tabla <- tabla %>% dplyr::select(id,code,fecha)
names(tabla) <- c("id","code","fecha")
tabla <- tabla %>% dplyr::mutate(code=gsub("\\.","",code)) # lo normalizo code
### 1. construye in identificador compuesto de id.fecha.codecie ####
tabla <- tabla %>% dplyr::mutate(idfechacod=paste(as.character(id),as.character(fecha),code, sep=",")) %>% relocate(idfechacod, .before=id) %>% select(-c(id,fecha)) %>% setDT()
}
## Note: Using an external vector in selections is ambiguous.
## ℹ Use `all_of(id)` instead of `id` to silence this message.
## ℹ See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
## This message is displayed once per session.
## Note: Using an external vector in selections is ambiguous.
## ℹ Use `all_of(code)` instead of `code` to silence this message.
## ℹ See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
## This message is displayed once per session.
## Note: Using an external vector in selections is ambiguous.
## ℹ Use `all_of(fecha)` instead of `fecha` to silence this message.
## ℹ See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
## This message is displayed once per session.
## idfechacod code
## 1: 36350,2011-01-01,2859 2859
## 2: 36350,2011-01-01,724 724
## 3: 36350,2011-01-01,V270 V270
## 4: 42434,2011-01-01,1573 1573
## 5: 42434,2011-01-01,4019 4019
## 6: 42434,2011-01-01,527 527
funcion02= function(df) {
dicod <- list(
ami ="^410|^412|^I21|^I22|^I252",
chf ="^39891|^40201|^40211|^40291|^40401|^40403|^40411|^40413|^40491|^40493|^4254|^4255|^4256|^4257|^4258|^4259|^428|^I099|^I110|^I130|^I132|^I255|^I420|^I425|^I426|^I427|^I428|^I429|^I43|^I50|^P290",
pvd ="^0930|^4373|^440|^441|^4431|^4432|^4433|^4434|^4435|^4436|^4437|^4438|^4439|^4471|^5571|^5579|^V434|^I70|^I71|^I731|^I738|^I739|^I771|^I790|^I792|^K551|^K558|^K559|^Z958|^Z959",
cevd = "^362.34|^430|^431|^432|^433|^434|^435|^436|^437|^438|^G45|^G46|^H340|^I60|^I61|^I62|^I63|^I64|^I65|^I66|^I67|^I68|^I69",
dementia ="^290|^2941|^3312|^F00|^F01|^F02|^F03|^F051|^G30|^G311",
copd ="^4168|^4169|^490|^491|^492|^493|^494|^495|^496|^497|^498|^499|^500|^501|^502|^503|^504|^505|^5064|^5081|^5088|^I278|^I279|^J40|^J41|^J42|^J43|^J44|^J45|^J46|^J47|^J60|^J61|^J62|^J63|^J64|^J65|^J66|^J67|^J684|^J701|^J703",
rheumd_ch ="^4465|^7010|^7100|^7101|^7102|^7103|^7104|^7140|^7141|^7142|^7148|^725|^M05|^M06|^M315|^M32|^M33|^M34|^M351|^M353|^M360",
pud ="^531|^532|^533|^534|^K25|^K26|^K27|^K28",
mld ="^07022|^07023|^07032|^07033|^07044|^07054|^0706|^0709|^4560|^4561|^4562|^570|^571|^5722|^5723|^5724|^5725|^5726|^5727|^5728|^5733|^5734|^5738|^5739|^V427|^B18|^K700|^K701|^K702|^K703|^K709|^K713|^K714|^K715|^K717|^K73|^K74|^K760|^K762|^K763|^K764|^K768|^K769|^Z944",
diabwoc ="^2500|^2501|^2502|^2503|^2508|^2509|^E100|^E101|^E106|^E108|^E109|^E110|^E111|^E116|^E118|^E119|^E120|^E121|^E126|^E128|^E129|^E130|^E131|^E136|^E138|^E139|^E140|^E141|^E146|^E148|^E149",
diabwic ="^2504|^2505|^2506|^2507|^2508|^E102|^E103|^E104|^E105|^E107|^E112|^E113|^E114|^E115|^E117|^E122|^E123|^E124|^E125|^E127|^E132|^E133|^E134|^E135|^E137|^E142|^E143|^E144|^E145|^E147",
hp ="^3341|^342|^343|^344|^3441|^3442|^3443|^3444|^3445|^3446|^3449|^G041|^G114|^G801|^G802|^G81|^G82|^G830|^G831|^G832|^G834|^G839",
rend ="^40301|^40311|^40391|^40402|^40403|^40412|^40413|^40492|^40493|^582|^5830|^5831|^5832|^5833|^5834|^5835|^5836|^5837|^585|^586|^5880|^V420|^V451|^V56|^I120|^I131|^N032|^N033|^N034|^N035|^N036|^N037|^N052|^N053|^N054|^N055|^N056|^N057|^N18|^N19|^N250|^Z490|^Z491|^Z492|^Z940|^Z992",
canc ="^140|^141|^142|^143|^144|^145|^146|^147|^148|^149|^150|^151|^152|^153|^154|^155|^156|^157|^158|^159|^160|^161|^162|^163|^164|^165|^166|^167|^168|^169|^170|^171|^172|^174|^175|^176|^177|^178|^179|^180|^181|^182|^183|^184|^185|^186|^187|^188|^189|^190|^191|^192|^193|^194|^195|^200|^201|^202|^203|^204|^205|^207|^208|^2386|^C00|^C01|^C02|^C03|^C04|^C05|^C06|^C07|^C08|^C09|^C10|^C11|^C12|^C13|^C14|^C15|^C16|^C17|^C18|^C19|^C20|^C21|^C22|^C23|^C24|^C25|^C26|^C30|^C31|^C32|^C33|^C34|^C37|^C38|^C39|^C40|^C41|^C43|^C45|^C46|^C47|^C48|^C49|^C50|^C51|^C52|^C53|^C54|^C55|^C56|^C57|^C58|^C60|^C61|^C62|^C63|^C64|^C65|^C66|^C67|^C68|^C69|^C70|^C71|^C72|^C73|^C74|^C75|^C76|^C81|^C82|^C83|^C84|^C85|^C88|^C90|^C91|^C92|^C93|^C94|^C95|^C96|^C97",
msld ="^4560|^4561|^4562|^5722|^5723|^5724|^5725|^5726|^5727|^5728|^I850|^I859|^I864|^I982|^K704|^K711|^K721|^K729|^K765|^K766|^K767",
metacanc ="^196|^197|^198|^199|^C77|^C78|^C79|^C80",
aids ="^042|^043|^044|^B20|^B21|^B22|^B24",
carit ="^4260|^42613|^4267|^4269|^42610|^42612|^4270|^4271|^4272|^4273|^4274|^4276|^4277|^4278|^4279|^7850|^99601|^99604|^V450|^V533|^I441|^I442|^I443|^I456|^I459|^I47|^I48|^I49|^R000|^R001|^R008|^T821|^Z450|^Z950",
valv ="^0932|^394|^395|^396|^397|^424|^7463|^7464|^7465|^7466|^V422|^V433|^A520|^I05|^I06|^I07|^I08|^I091|^I098|^I34|^I35|^I36|^I37|^I38|^I39|^Q230|^Q231|^Q232|^Q233|^Z952|^Z953|^Z954",
pcd ="^4150|^4151|^416|^4170|^4178|^4179|^I26|^I27|^I280|^I288|^I289",
pvd ="^0930|^4373|^440|^441|^4431|^4432|^4433|^4434|^4435|^4436|^4437|^4438|^4439|^4471|^5571|^5579|^V434|^I70|^I71|^I731|^I738|^I739|^I771|^I790|^I792|^K551|^K558|^K559|^Z958|^Z959",
hypunc ="^401|^I10",
hypc ="^402|^403|^404|^405|^I11|^I12|^I13",
para ="^3341|^342|^343|^3440|^3441|^3442|^3443|^3444|^3445|^3446|^3449|^G041|^G114|^G801|^G802|^G81|^G82|^G830|^G831|^G832|^G833|^G834|^G839",
ond ="^3319|^3320|^3321|^3334|^3335|^33392|^334|^335|^3362|^340|^341|^345|^3481|^3483|^7803|^7843|^G10|^G11|^G12|^G13|^G20|^G21|^G22|^G254|^G255|^G312|^G318|^G319|^G32|^G35|^G36|^G37|^G40|^G41|^G931|^G934|^R470|^R56",
diabunc ="^2500|^2501|^2502|^2503|^E100|^E101|^E109|^E110|^E111|^E119|^E120|^E121|^E129|^E130|^E131|^E139|^E140|^E141|^E149",
diabc ="^2504|^2505|^2506|^2507|^2508|^2509|^E102|^E103|^E104|^E105|^E106|^E107|^E108|^E112|^E113|^E114|^E115|^E116|^E117|^E118|^E122|^E123|^E124|^E125|^E126|^E127|^E128|^E132|^E133|^E134|^E135|^E136|^E137|^E138|^E142|^E143|^E144|^E145|^E146|^E147|^E148",
hypothy ="^2409|^243|^244|^2461|^2468|^E00|^E01|^E02|^E03|^E890",
rf ="^40301|^40311|^40391|^40402|^40403|^40412|^40413|^40492|^40493|^585|^586|^5880|^V420|^V451|^V56|^I120|^I131|^N18|^N19|^N250|^Z490|^Z491|^Z492|^Z940|^Z992",
ld ="^07022|^07023|^07032|^07033|^07044|^07054|^0706|^0709|^4560|^4561|^4562|^570|^571|^5722|^5723|^5724|^5725|^5726|^5727|^5728|^5733|^5734|^5738|^5739|^V427|^B18|^I85|^I864|^I982|^K70|^K711|^K713|^K714|^K715|^K717|^K72|^K73|^K74|^K760|^K762|^K763|^K764|^K765|^K766|^K767|^K768|^K769|^Z944" ,
pud ="^5317|^5319|^5327|^5329|^5337|^5339|^5347|^5349|^K257|^K259|^K267|^K269|^K277|^K279|^K287|^K289",
lymph ="^200|^201|^202|^2030|^2386|^C81|^C82|^C83|^C84|^C85|^C88|^C900|^C902^C96",
solidtum ="^140|^141|^142|^143|^144|^145|^146|^147|^148|^149|^150|^151|^152|^153|^154|^155|^156|^157|^158|^159|^160|^161|^162|^163|^164|^165|^166|^167|^168|^169|^170|^171|^172|^174|^175|^176|^177|^178|^179|^180|^181|^182|^183|^184|^185|^186|^187|^188|^189|^190|^191|^192|^193|^194|^195",
rheumd_hx ="^446|^7100|^7101|^7102|^7103|^7104|^7108|^7109|^7112|^714|^7193|^720|^725|^7285|^72889|^72930|^L940|^L941|^L943|^M05|^M06|^M08|^M120|^M123|^M30|^M310|^M311|^M312|^M313|^M315|^M32|^M33|^M34|^M35|^M45|^M360|^M461|^M468|^M469",
coag ="^286|^2871|^2873|^2874|^2875|^D65|^D66|^D67|^D68|^D691|^D693|^D694|^D695|^D696",
obes ="^2780|^E66",
wloss ="^260|^261|^262|^263|^7832|^7994|^E40|^E41|^E42|^E43|^E44|^E45|^E46|^R634|^R64",
fed ="^2536|^276|^E222|^E86|^E87",
blane ="^2800|^D500",
dane ="^2801|^2802|^2803|^2804|^2805|^2806|^2807|^2808|^2809|^281|^D508|^D509|^D51|^D52|^D513",
alcohol ="^2652|^2911|^2912|^2913|^2915|^2916|^2917|^2918|^2919|^3030|^3039|^3050|^3575|^4255|^5353|^5710|^5711|^5712|^5713|^980|^V113|^F10|^E52|^G621|^I426|^K292|^K700|^K703|^K709|^T51|^Z502|^Z714|^Z721",
drug ="^292|^304|^3052|^3053|^3054|^3055|^3056|^3057|^3058|^3059|^V6542|^F11|^F12|^F13|^F14|^F15|^F16|^F18|^F19|^Z715|^Z722",
psycho ="^2938|^295|^29604|^29614|^29644|^29654|^297|^298|^F20|^F22|^F23|^F24|^F25|^F28|^F29|^F302|^F312|^F315",
depre ="^2962|^2963|^2965|^3004|^309|^311|^F204|^F313|^F314|^F315|^F32|^F33|^F341|^F412|^F432"
)
## 2. se generan las diversas comorbilidades empleando los codigos del objeto dicod ####
for(i in 1:44) {
dc=dicod[[i]]
varname=names(dicod)[i]
df <- df %>% mutate(!!varname:=as.numeric(str_detect(code,dc)))
}
return(df)
}
## idfechacod code ami chf pvd cevd dementia copd rheumd_ch pud mld
## 1: 36350,2011-01-01,2859 2859 0 0 0 0 0 0 0 0 0
## 2: 36350,2011-01-01,724 724 0 0 0 0 0 0 0 0 0
## 3: 36350,2011-01-01,V270 V270 0 0 0 0 0 0 0 0 0
## 4: 42434,2011-01-01,1573 1573 0 0 0 0 0 0 0 0 0
## 5: 42434,2011-01-01,4019 4019 0 0 0 0 0 0 0 0 0
## 6: 42434,2011-01-01,527 527 0 0 0 0 0 0 0 0 0
## diabwoc diabwic hp rend canc msld metacanc aids carit valv pcd hypunc hypc
## 1: 0 0 0 0 0 0 0 0 0 0 0 0 0
## 2: 0 0 0 0 0 0 0 0 0 0 0 0 0
## 3: 0 0 0 0 0 0 0 0 0 0 0 0 0
## 4: 0 0 0 0 1 0 0 0 0 0 0 0 0
## 5: 0 0 0 0 0 0 0 0 0 0 0 1 0
## 6: 0 0 0 0 0 0 0 0 0 0 0 0 0
## para ond diabunc diabc hypothy rf ld lymph solidtum rheumd_hx coag obes
## 1: 0 0 0 0 0 0 0 0 0 0 0 0
## 2: 0 0 0 0 0 0 0 0 0 0 0 0
## 3: 0 0 0 0 0 0 0 0 0 0 0 0
## 4: 0 0 0 0 0 0 0 0 1 0 0 0
## 5: 0 0 0 0 0 0 0 0 0 0 0 0
## 6: 0 0 0 0 0 0 0 0 0 0 0 0
## wloss fed blane dane alcohol drug psycho depre
## 1: 0 0 0 0 0 0 0 0
## 2: 0 0 0 0 0 0 0 0
## 3: 0 0 0 0 0 0 0 0
## 4: 0 0 0 0 0 0 0 0
## 5: 0 0 0 0 0 0 0 0
## 6: 0 0 0 0 0 0 0 0
modo= “pesos” [por defecto] (42g+score): de charlson (17 primeros grupos) y elixhauser, con un operador numerico 1/0 segun se hayan dado o no en el periodo estudiado, más la puntuacion de los índices charlson t¡y elixhauser
modo=“fechas” (42g+fecha): 42 grupos, con vacios (NA) para todas aquellas comorbilidades que no se dieron y en el resto la fecha de primera aparicion.
modo=“codigos”S (42g+cie): 42 grupos, igualmente vacios si no tuvieron y con un codigo diagnostico (el primero) en caso afirmativo.
#
funcion03 <- function(df, modo="pesos",assign0 = TRUE) {
mpp=data.table::melt(df, id.vars = "idfechacod",measure.vars = names(df)[3:44])
mpp=mpp[value!=0] ## eliminar registros con codigos no incluidos
mpp[, c("id","fecha","code"):=tstrsplit(idfechacod, "," , fixed=TRUE)]
mpp=mpp[, -"idfechacod"]
## S1 17g+score generar el fichero previo (a falta del cálculo de pesos) de la S1
if (modo == "pesos") {
pps=dcast.data.table(
mpp, id ~ variable,
value.var = 'value',
fill=0)
pps= pps %>% mutate_at(vars(ami:depre),function(x){x=ifelse(x>0,1,0)})
# co_cols=names(pps)[-1]
# ch_cols=c( "ami" ,"chf", "pvd", "cevd","dementia" ,"codp","rheumd_ch", "pud", "mld", "diabwoc" , "diabwic" ,"hp", "rend","canc","msld","metacanc" , "aids")
# hx_cols=c("chf","carit","valv", "pcd", "pvd", "hypunc" , "hypc", "para","ond", "codp", "diabunc" , "diabc", "hypothy" , "rf", "ld", "lymph","solidtum", "rheumd_hx", "coag", "obes", "wloss" , "fed", "blane","dane", "alcohol", "drug", "psycho", "depre","aids" )
data.table::setDF(pps)
pps$score_ch <- with(pps, ami + chf + pvd + cevd + dementia +
copd + rheumd_ch + pud + mld * ifelse(msld == 1 & assign0,
0, 1) + diabwoc * ifelse(diabwic == 1 & assign0, 0, 1) +
diabwic + hp + rend + canc * ifelse(metacanc == 1 &
assign0, 0, 1) + msld + metacanc + aids)
pps$index_ch <- with(pps, cut(score_ch, breaks = c(0, 1, 2.5, 4.5,
Inf), labels = c("0", "1-2", "3-4",
">=5"), right = FALSE))
pps$wscore_ch <- with(pps, ami + chf + pvd + cevd + dementia +
copd + rheumd_ch + pud + mld * ifelse(msld == 1 & assign0,
0, 1) + diabwoc * ifelse(diabwic == 1 & assign0, 0, 1) +
diabwic * 2 + hp * 2 + rend * 2 + canc * ifelse(metacanc ==
1 & assign0, 0, 2) + msld * 3 + metacanc * 6 + aids *
6)
pps$windex_ch <- with(pps, cut(wscore_ch, breaks = c(0, 1, 2.5,
4.5, Inf), labels = c("0", "1-2", "3-4",
">=5"), right = FALSE))
pps$score_hx <- with(pps, chf + carit + valv + pcd + pvd + hypunc *
ifelse(hypc == 1 & assign0, 0, 1) + hypc + para +
ond + copd + diabunc * ifelse(diabc == 1 & assign0,
0, 1) + diabc + hypothy + rf + ld + pud + aids +
lymph + metacanc + solidtum * ifelse(metacanc ==
1 & assign0, 0, 1) + rheumd_hx + coag + obes + wloss +
fed + blane + dane + alcohol + drug + psycho + depre)
pps$index_hx <- with(pps, cut(score_hx, breaks = c(-Inf, 0, 1,
4.5, Inf), labels = c("<0", "0", "1-4",
">=5"), right = FALSE))
pps$wscore_ahrq <- with(pps, chf * 9 + carit * 0 + valv *
0 + pcd * 6 + pvd * 3 + ifelse(hypunc == 1 | hypc ==
1, 1, 0) * (-1) + para * 5 + ond * 5 + copd * 3 +
diabunc * ifelse(diabc == 1 & assign0, 0, 0) + diabc *
(-3) + hypothy * 0 + rf * 6 + ld * 4 + pud * 0 +
aids * 0 + lymph * 6 + metacanc * 14 + solidtum *
ifelse(metacanc == 1 & assign0, 0, 7) + rheumd_hx *
0 + coag * 11 + obes * (-5) + wloss * 9 + fed * 11 +
blane * (-3) + dane * (-2) + alcohol * (-1) + drug *
(-7) + psycho * (-5) + depre * (-5))
pps$wscore_hxvw <- with(pps, chf * 7 + carit * 5 + valv * (-1) +
pcd * 4 + pvd * 2 + ifelse(hypunc == 1 | hypc ==
1, 1, 0) * 0 + para * 7 + ond * 6 + copd * 3 + diabunc *
ifelse(diabc == 1 & assign0, 0, 0) + diabc * 0 +
hypothy * 0 + rf * 5 + ld * 11 + pud * 0 + aids *
0 + lymph * 9 + metacanc * 12 + solidtum * ifelse(metacanc ==
1 & assign0, 0, 4) + rheumd_hx * 0 + coag * 3 + obes *
(-4) + wloss * 6 + fed * 5 + blane * (-2) + dane *
(-2) + alcohol * 0 + drug * (-7) + psycho * 0 + depre *
(-3))
pps$windex_ahrq <- with(pps, cut(wscore_ahrq, breaks = c(-Inf,
0, 1, 4.5, Inf), labels = c("<0", "0",
"1-4", ">=5"), right = FALSE))
pps$windex_vw <- with(pps, cut(wscore_hxvw, breaks = c(-Inf,
0, 1, 4.5, Inf), labels = c("<0", "0",
"1-4", ">=5"), right = FALSE))
return(pps)
}
if (modo == "fechas") {
## S2 17g+fecha ( formato fecha?)
ppf=dcast.data.table(
mpp, id ~ variable,
value.var = 'fecha',
fun = list(min))
return(ppf)
}
if (modo == "codigos") {
ppd=dcast.data.table(
mpp, id ~ variable,
value.var = 'code',
fun = list(min)) ## no se como aplica y que consecuencias tiene, este minimo, podria hacer un descriptivo previo de distribucion de diagnosticos por grupo CIE
return(ppd)
}
}
## Aggregate function missing, defaulting to 'length'
## id ami chf pvd cevd dementia copd rheumd_ch pud mld diabwoc diabwic hp
## 1 100004 0 0 0 0 0 0 0 0 0 0 0 0
## 2 1000045 0 0 0 0 0 0 0 0 0 1 0 0
## 3 1000063 0 0 0 0 0 0 0 0 0 0 0 0
## 4 100015 0 0 0 1 0 0 0 0 0 0 0 1
## 5 1000210 0 0 0 0 0 1 0 0 0 0 0 0
## 6 1000218 0 0 0 0 0 0 0 0 0 0 0 0
## rend canc msld metacanc aids carit valv pcd hypunc hypc para ond diabunc
## 1 0 0 0 0 0 0 0 0 1 0 0 0 0
## 2 0 0 0 0 0 0 0 0 1 0 0 0 1
## 3 0 1 0 1 0 0 0 0 0 0 0 0 0
## 4 0 0 0 0 0 0 0 0 0 0 1 0 0
## 5 0 0 0 0 0 0 0 0 0 0 0 1 0
## 6 0 0 0 0 0 0 0 0 0 0 0 0 0
## diabc hypothy rf ld lymph solidtum rheumd_hx coag obes wloss fed blane dane
## 1 0 0 0 0 0 0 0 0 0 0 0 0 0
## 2 0 0 0 0 0 0 0 0 0 0 0 0 0
## 3 0 0 0 0 0 1 0 0 0 0 0 0 0
## 4 0 0 0 0 0 0 0 0 0 0 0 0 0
## 5 0 0 0 0 0 0 0 0 0 0 0 0 0
## 6 0 0 0 0 0 0 0 0 0 0 0 0 0
## alcohol drug psycho depre score_ch index_ch wscore_ch windex_ch score_hx
## 1 0 0 0 0 0 0 0 0 1
## 2 0 0 0 0 1 1-2 1 1-2 2
## 3 0 0 0 0 1 1-2 6 >=5 1
## 4 0 0 0 0 2 1-2 3 3-4 1
## 5 0 0 0 0 1 1-2 1 1-2 2
## 6 0 0 0 1 0 0 0 0 1
## index_hx wscore_ahrq wscore_hxvw windex_ahrq windex_vw
## 1 1-4 -1 0 <0 0
## 2 1-4 -1 0 <0 0
## 3 1-4 14 12 >=5 >=5
## 4 1-4 5 7 >=5 >=5
## 5 1-4 8 9 >=5 >=5
## 6 1-4 -5 -3 <0 <0
## id ami chf pvd cevd dementia copd rheumd_ch pud mld
## 1: 100004 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 2: 1000045 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 3: 1000063 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 4: 100015 <NA> <NA> <NA> 2012-06-11 <NA> <NA> <NA> <NA> <NA>
## 5: 1000210 <NA> <NA> <NA> <NA> <NA> 2011-03-31 <NA> <NA> <NA>
## 6: 1000218 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## diabwoc diabwic hp rend canc msld metacanc aids carit
## 1: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 2: 2012-07-20 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 3: <NA> <NA> <NA> <NA> 2011-04-29 <NA> 2011-04-29 <NA> <NA>
## 4: <NA> <NA> 2012-06-11 <NA> <NA> <NA> <NA> <NA> <NA>
## 5: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 6: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## valv pcd hypunc hypc para ond diabunc diabc hypothy
## 1: <NA> <NA> 2012-08-10 <NA> <NA> <NA> <NA> <NA> <NA>
## 2: <NA> <NA> 2012-07-20 <NA> <NA> <NA> 2012-07-20 <NA> <NA>
## 3: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 4: <NA> <NA> <NA> <NA> 2012-06-11 <NA> <NA> <NA> <NA>
## 5: <NA> <NA> <NA> <NA> <NA> 2011-03-31 <NA> <NA> <NA>
## 6: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## rf ld lymph solidtum rheumd_hx coag obes wloss fed blane dane alcohol
## 1: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 2: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 3: <NA> <NA> <NA> 2011-04-29 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 4: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 5: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 6: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## drug psycho depre
## 1: <NA> <NA> <NA>
## 2: <NA> <NA> <NA>
## 3: <NA> <NA> <NA>
## 4: <NA> <NA> <NA>
## 5: <NA> <NA> <NA>
## 6: <NA> <NA> 2021-02-04
## id ami chf pvd cevd dementia copd rheumd_ch pud mld diabwoc
## 1: 100004 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 2: 1000045 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> 25000
## 3: 1000063 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 4: 100015 <NA> <NA> <NA> 431 <NA> <NA> <NA> <NA> <NA> <NA>
## 5: 1000210 <NA> <NA> <NA> <NA> <NA> 4928 <NA> <NA> <NA> <NA>
## 6: 1000218 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## diabwic hp rend canc msld metacanc aids carit valv pcd hypunc hypc para
## 1: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> 4019 <NA> <NA>
## 2: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> 4019 <NA> <NA>
## 3: <NA> <NA> <NA> 1539 <NA> 1962 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 4: <NA> 34290 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> 34290
## 5: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 6: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## ond diabunc diabc hypothy rf ld lymph solidtum rheumd_hx coag obes
## 1: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 2: <NA> 25000 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 3: <NA> <NA> <NA> <NA> <NA> <NA> <NA> 1539 <NA> <NA> <NA>
## 4: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 5: 3404 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 6: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## wloss fed blane dane alcohol drug psycho depre
## 1: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 2: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 3: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 4: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 5: <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 6: <NA> <NA> <NA> <NA> <NA> <NA> <NA> F32