comorbidity score calculator

Hi all

I am trying to calculate comorbidity scores for a large dataset. I am using the following code: comorbidity(x=new1,id=NULL,map = "charlson_icd10_quan", code = I10_DX1:I10_DX40, assign0 = TRUE).
I don't have id in my dataset so I have put null.
Diagnostic codes are in the columns I10_DX1 to I10_DX40.
I am getting errors while calculating the score. Can someone help me writing the correct code?

Thank you

Zafar

It would be easier to help you with a reprex, and to include the full error messages.

In particular, which package does the comorbidity() function come from, this one?

The id is probably important, you might want to add one. Based on the vignette, your data.frame new1 should have, for each row, a diagnostic code associated with the patient. The same patient can appear in multiple rows. So, without an ID, you can't know which diagnostic code is associated with each patient, you don't have any data, just a collection of diagnostic codes that may or may not come from the same patients.

Since you seem to have 40 diagnostic columns in new1, perhaps the current structure of new1 is one row per patient, one column per code? In that case you can get to the correct format using pivot_longer(). Something like:

# add an id column
new1$id <- 1:nrow(new1)

# pivot to long format
new1_long <- pivot_longer(-id, names_to = "diag_number", values_to = "diag_code")

comorbidity(new1_long, id = "id", code = "diag_code")

(you probably need to modify this code depending on what your data really looks like)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.