icd9 v1.3.1

by Jack O Wasey

Tools for Working with ICD-9 Codes, and Finding Comorbidities

Obsolete: 'icd9' is replaced by CRAN package 'icd'. Calculate comorbidities, Charlson scores, perform fast and accurate validation, conversion, manipulation, filtering and comparison of ICD-9-CM (clinical modification) codes. ICD-9 codes appear numeric but leading and trailing zeroes, and both decimal and non-decimal "short" format codes exist. The package enables a work flow from raw lists of ICD-9 codes from hospital billing databases to comorbidities. ICD-9 to comorbidity mappings from Quan (Deyo and Elixhauser versions), Elixhauser and AHRQ included. Any other mapping of codes, such as ICD-10, to comorbidities can be used.

Readme

icd9

Build Status Coverage Status CRAN version CRAN RStudio mirror downloads (RStudio mirror only)

ICD comorbidities, manipulation and validation

Obsolete

The icd9 package is obsolete and replaced by icd which is backward compatible, and adds ICD-10 support. icd should be available on CRAN soon. icd9 should be uninstalled and replaced by icd.

Until it is on CRAN, you can try it with:

devtools::install_github("jackwasey/icd")

Main Features

  • assignment of patients to high level comorbidities based on admission or discharge ICD-9 codes
    • several mappings of ICD-9 codes to comorbidities are included (Quan, Deyo, Elixhauser, AHRQ)
    • very fast assignment of ICD-9 codes to comorbidities (using C and C++ internally, with automatic parallel execution using OpenMP when available)
  • Charlson and Van Walvaren score calculations
  • validation of ICD-9 codes from different annual revisions of ICD-9-CM
  • summarizing ICD-9 codes into groups, and to human-readable descriptions
  • correct conversion between different representations of ICD-9 codes, with and without a decimal point
  • comprehensive test suite to increase confidence in accurate processing of ICD-9 codes.

New since last CRAN release:

  • further performance increases: 1 million ICD-9 codes assigned to comorbidities in less than a second
  • logical matrix or data.frame for comorbidity output and manipulation
  • see NEWS.md and github changelog for more details
  • minor update to fix an obscure memory leak found with address sanitizer.

Introduction

Calculate comorbidities, Charlson scores, perform fast and accurate validation, conversion, manipulation, filtering and comparison of ICD-9-CM (clinical modification) codes. ICD-9 codes appear numeric but leading and trailing zeroes, and both decimal and non-decimal "short" format codes exist. The package enables a work flow from raw lists of ICD-9 codes from hospital billing databases to comorbidities. ICD-9 to comorbidity mappings from Quan (Deyo and Elixhauser versions), Elixhauser and AHRQ included. Any other mapping of codes, such as ICD-10, to comorbidities can be used.

Relevance

ICD-9 codes are still in heavy use around the world, particularly in the USA where the ICD-9-CM (Clinical Modification) is in widespread use. ICD-10 and the corresponding ICD-10-CM are imminent, however a vast amount of patient data is recorded with ICD-9 codes of some kind: this package enables their use in R. A common requirement for medical research involving patients is determining new or existing comorbidities. This is often reported in Table 1 of research papers to demonstrate the similarity or differences of groups of patients. This package is focussed on fast and accurate generation of this comorbidity information from raw lists of ICD-9 codes.

ICD-9 code types

ICD-9 codes are not numbers, and great care is needed when matching individual codes and ranges of codes. It is easy to make mistakes, hence the need for this package. ICD-9 codes can be presented in short 5 character format, or decimal format, with a decimal place separating the code into two groups. There are also codes beginning with V and E which have different validation rules. Zeroes after a decimal place are meaningful, so numeric ICD-9 codes cannot be used in most cases. In addition, most clinical databases contain invalid codes, and even decimal and non-decimal format codes in different places. This package primarily deals with ICD-9-CM (Clinical Modification) codes, but should be applicable or easily extendible to the original WHO ICD-9 system.

Examples

See the vignette and code help for many more. Here's a taste:

patientData
#>   visitId  icd9  poa
#> 1    1000 40201    Y
#> 2    1000  2258 <NA>
#> 3    1000  7208    N
#> 4    1000 25001    Y
#> 5    1001 34400    X
#> 6    1001  4011    Y
#> 7    1002  4011    E

# reformat input data as needed
patientData %>% icd9LongToWide # everything works well with magrittr %>%
#>      [,1]    [,2]   [,3]   [,4]   
#> 1000 "40201" "2258" "7208" "25001"
#> 1001 "34400" "4011" NA     NA     
#> 1002 "4011"  NA     NA     NA

# get comorbidities:
icd9ComorbidQuanDeyo(patientData)
#>         MI   CHF   PVD Stroke Dementia Pulmonary Rheumatic   PUD LiverMild
#> 1000 FALSE  TRUE FALSE  FALSE    FALSE     FALSE     FALSE FALSE     FALSE
#> 1001 FALSE FALSE FALSE  FALSE    FALSE     FALSE     FALSE FALSE     FALSE
#> 1002 FALSE FALSE FALSE  FALSE    FALSE     FALSE     FALSE FALSE     FALSE
#>         DM  DMcx Paralysis Renal Cancer LiverSevere  Mets   HIV
#> 1000  TRUE FALSE     FALSE FALSE  FALSE       FALSE FALSE FALSE
#> 1001 FALSE FALSE      TRUE FALSE  FALSE       FALSE FALSE FALSE
#> 1002 FALSE FALSE     FALSE FALSE  FALSE       FALSE FALSE FALSE

# find diagnoses present on admission:
icd9FilterPoa(patientData)
#>   visitId  icd9
#> 1    1000 40201
#> 4    1000 25001
#> 6    1001  4011

Note that reformatting from wide to long and back is not as straightforward as using the various Hadley Wickham tools for doing this: knowing the more detailed structure of the data let's us do this better for the case of dealing with ICD codes.

Install

The latest version is available in github and can be installed with:

install.packages("devtools") # if needed
devtools::install_github("jackwasey/icd9")

install.packages("magrittr") # recommended, but not required

The master branch at github should always build and pass all tests and R CMD check, and will be similar or identical to the most recent CRAN release. The CRAN releases are stable milestones. Contributions and bug reports are encouraged.

Functions in icd9

Name Description
ahrqComorbid AHRQ comorbidities
icd9PoaChoices present-on-admission flags
icd9ComorbidMatToDf convert matrix of comorbidities into data frame, preserving visitId information
elixComorbidNames Comorbidity names
icd9AddLeadingZeroesShort Add leading zeroes to incomplete ICD codes
icd9ChaptersToMap convert the chapter headings to lists of codes
icd9ComorbidDfToMat convert matrix of comorbidities into data frame, preserving visitId information
icd9Charlson Calculate Charlson Comorbidity Index (Charlson Score)
icd9Count count ICD codes or comorbidities for each patient
icd9ExpandMinor expand decimal part of ICD-9 code to cover all possible sub-codes
icd9DropLeadingZeroes drop zero padding from decimal ICD-9 code.
icd9Condense Condense ICD-9 code by replacing complete families with parent codes
expandRangeWorker expand range worker function
icd9Hierarchy ICD9-CM diagnosis code lookup
icd9GetValid invalid subset of decimal or short ICD-9 codes
parseIcd9Chapters Read higher-level ICD-9 structure from a reliable web site
icd9IsValid check whether ICD-9 codes are syntactically valid
sasFormatExtract extract assignments from a SAS FORMAT definition.
parseElix Generate Elixhauser comorbidities
icd9ComorbidShortCpp find comorbidities from ICD-9 codes.
icd9Children Expand ICD-9 codes to all possible sub-codes
icd9GetChapters get ICD-9 Chapters from vector of ICD-9 codes
icd9LongToWide convert ICD data from long to wide format
quanDeyoComorbid Quan adaptation of Deyo/Charlson comorbidities
icd9IsA test whether elements of vector begin with V, E (or any other character)
parseLeafDescriptionsVersion read the ICD-9-CM description data as provided by the Center for Medicaid Services.
icd9IsValidMapping validate an icd9 mapping to comorbidities
elixComorbid Elixhauser comorbidities
icd9Chapters ICD-9-CM chapters
icd9PartsToShort Convert ICD9 codes between formats and structures.
icd9IsReal Check whether ICD-9 codes exist
icd9GuessIsShort guess whether short or long
icd9ExpandRange take two ICD-9 codes and expand range to include all child codes
generateSysData Generate sysdata.rda
icd9-package Tools for Working with ICD-9 Codes, and Finding Comorbidities
fastIntToStringStd fast convert integer vector to character vector
icd9DiffComorbid show the difference between two comorbidity mappings
zip_single unzip a single file
ahrqComorbidAll AHRQ comorbidities, with HTN, CHF and renal failure subgroups
icd9IsN do codes belong to numeric, V or E classes?
icd9FilterInvalid Filter ICD-9 codes by invalidity.
sasExtractLetStrings extract quoted or unquoted SAS string definitions
strMultiMatch return the actual matches from a bracketed regex
icd9GetMajor Get major (three-digit) part of ICD-9 codes
icd9RandomShort generate random short-form icd9 E codes
parseQuanDeyoSas parse original SAS code defining Quan's update of Deyo comorbidities.
logicalToBinary encode TRUE as 1, and FALSE as 0 (integers)
icd9ShortToDecimal Convert ICD-9 codes between short and decimal forms
randomShortIcd9 genereate random short icd9 codes
parseRtfLines parse a character vector containing RTF strings
vermont_dx de-identified data from public Vermont source for 2013
parseLeafDescriptionsAll get billable codes from all available years
quanElixComorbid Quan adaptation of Elixhauser comorbidities
icd9Sort sort short-form icd9 codes
icd9ExtractAlphaNumeric extract alphabetic, and numeric part of icd9 code prefix
icd9Explain explain ICD9 codes
sasParseAssignments get assignments from a character string strings.
parseRtfYear parse RTF description of entire ICD-9-CM for a specific year
parseAhrqSas parse AHRQ data
parseRtfFifthDigitRanges parse a row of RTF source data for ranges to apply fifth digit sub-classifications
sasDropOtherAssignment drop superfluous assignment name when the name is already defined.
stripRtf Strip RTF
icd9FilterValid Filter ICD-9 codes by validity.
factor_ Fast Factor Generation
icd9VanWalraven Calculate van Walraven Elixhauser Score
icd9Billable list of annual versions of billable leaf nodes of ICD-9-CM
icd9FilterPoa Filters data frame based on present-on-arrival flag
icd9IsBillable Determine whether codes are billable leaf-nodes
icd9InReferenceCode match ICD9 codes
icd9WideToLong convert ICD data from wide to long format
icd9RandomShortV generate random short-form icd9 V codes
swapNamesWithVals swap names and values of a vector
listTrimFlat trim null or empty values from a list
icd9Benchmark benchmark and profile major functions with larger data sets
icd9RandomShortE generate random short-form icd9 E codes
cr get sequence of column indices of comorbidities
parseAndSaveQuick parse almost everything
icd9RandomShortN generate random short-form numeric icd9 codes
parseQuanElix Generate Quan's revised Elixhauser comorbidities
No Results!

Details

Date 2016-04-12
URL https://github.com/jackwasey/icd9
LazyData true
LazyDataCompression xz
BugReports https://github.com/jackwasey/icd9/issues
License GPL-3
Copyright See file (inst/)COPYRIGHTS
VignetteBuilder knitr
LinkingTo Rcpp
RoxygenNote 5.0.1
NeedsCompilation yes
Packaged 2016-04-14 18:01:17 UTC; jack
Repository CRAN
Date/Publication 2016-04-15 08:33:09

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/icd9)](http://www.rdocumentation.org/packages/icd9)