R/icd-package.R
icd-package.Rd
Calculate comorbidities, medical risk scores, and work very quickly and precisely with ICD-9 and ICD-10 codes. This package enables a work flow from raw tables of ICD codes in hospital databases to comorbidities. ICD-9 and ICD-10 comorbidity mappings from Quan (Deyo and Elixhauser versions), Elixhauser and AHRQ included. Common ambiguities and code formats are handled. Comorbidity computation includes Hierarchical Condition Codes, and an implementation of AHRQ Clinical Classifications. Risk scores include those of Charlson and van Walraven. US Clinical Modification, Word Health Organization, Belgian and French ICD-10 codes are supported, most of which are downloaded on demand.
comorbid
determines
comorbidities for a set of patients with one or more ICD codes each. All
the comorbidity functions guess which columns are the identifiers and which
are ICD code fields. You may also specify these. Most 'long' or 'wide' data
can simply be passed directly, e.g.: comorbid(patient_data_frame)
.
The AHRQ comorbidity mappings from ICD-9 and ICD-10 are provided as
icd9_map_ahrq
and icd10_map_ahrq
. The easiest
way to use them is by calling the function comorbid_ahrq
directly with your icd_long_data
format patient data.
Quan revised both Deyo/Charlson and Elixhauser ICD-9 and ICD-10 to
comorbidity mappings. These are presented as:
icd9_map_quan_deyo
, icd10_map_quan_deyo
,
icd9_map_quan_elix
, and icd10_map_quan_elix
.
Like the AHRQ mappings, these are all carefully extracted from the original
publications or source code. These mappings can be used on patient data by
calling comorbid_quan_deyo
and
comorbid_quan_elix
There is no canonical Charlson ICD-9 or ICD-10 mapping, so
comorbid_charlson
uses the thoroughly researched and widely
cited comorbid_quan_deyo
method by default.
The original Elixhauser mappings are provided by the lists
icd9_map_elix
and icd10_map_elix
, and
Elixhauser comorbidities can be calculated directly from patient data using
comorbid_elix
.
The US Center for Medicare and Medicare services (CMS) publishes
Hierarchical Condition Codes (HCC) which are essentially comorbidity maps
with very many comorbidities, complicated by a single- or multi-level
system. These categories can be computed using comorbid_hcc
.
AHRQ also publishes Clinical Classification Software (CCS) which
provides another set of disease groups, and this SAS code is implemented in
'icd' by comorbid_ccs
charlson
calculates Charlson scores (Charlson Comorbidity
Indices) directly from your patient data. If you already calculated the
Charlson comorbidities, it is more efficient to use
charlson_from_comorbid
. Similarly, van_walraven
calculates Van Walraven scores (based on the Elixhauser comorbidities,
instead of Charlson), and van_walraven_from_comorbid
if you
already calculated Elixhauser comorbidities
is_valid
checks whether ICD codes are syntactically valid
(although not necessarily genuine ICD diagnoses). In contrast,
is_defined
checks whether ICD-9 codes correspond to defined
diagnoses or diagnostic groups in the hierarchy of ICD codes.
is_leaf
(and for the US, is_billable
) determine
whether given codes are leaves in the hierarchy, or not. icd may need
to download data due to package size or copyright restrictions on
redistributing data, and needs a cache directory and your permission to do
this. Use set_icd_data_dir
to do this, e.g.,
set_icd_data_dir()
for a default location in a suitable place for
your OS, e.g. ~/.local/icd/icd-ver-num
on Linux. Use
download_all_icd_data
to download everything at once, which
will take a few minutes on a broadband connection. Validation depends on the class of code, and is different if the code is
from France, Belgium, the USA, or the World Health Organization (WHO). Use
the functions as.icd10who
, as.icd10fr
,
as.icd10be
, and as.icd10cm
to set the class of
a set of ICD codes. This doesn't affect comorbidity calculations, but will
change the result of the above validation functions, and
There are many functions to convert ICD-9 codes or their components between
different formats and structures. The most commonly used are:
decimal_to_short
, short_to_decimal
to convert,
e.g., 002.3 to 0023 and back again. See convert for other options.
Conversion between ICD-9, ICD-10, and ICD-11 codes is not yet supported,
but is the subject of an upcoming US National Institutes of Health (NIH)
hackathon.
You can find children of a higher-level ICD-9 code with
children
and find a common parent to a set of children (or
arbitrary list of ICD-9 codes) with condense
.
sort
(sort.icd9
, sort.icd10cm
,
etc.) sorts in hierarchical, then numerical order, so '100.0' comes before
'100.00', for example. The comorbidity functions in icd accept 'wide' or 'long' format data,
but you may wish to use wide_to_long
and
long_to_wide
, which convert between these two most common
data structures containing patient disease data. This is more sophisticated
and tailored to the problem than base reshaping or packages like
dplyr, although these could no doubt be used.
Use explain_code
to convert a set of ICD codes into
human-readable descriptions. See above for discussion on WHO, French,
Belgian and US ICD code classes. This function can can also reduce the
codes to their top-level groups if all the child members of a group are
present. diff_comorbid
allows summary of the differences
between comorbidity mappings, e.g. between revisions by different authors.
Useful links: