% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/comorbid.R, R/comorbid_pccc.R
\name{comorbid}
\alias{comorbid}
\alias{icd10_comorbid}
\alias{icd9_comorbid}
\alias{icd9_comorbid_ahrq}
\alias{icd10_comorbid_ahrq}
\alias{icd9_comorbid_elix}
\alias{icd10_comorbid_elix}
\alias{icd9_comorbid_quan_elix}
\alias{icd10_comorbid_quan_elix}
\alias{icd9_comorbid_quan_deyo}
\alias{icd10_comorbid_quan_deyo}
\alias{icd9_comorbid_charlson}
\alias{icd10_comorbid_charlson}
\alias{comorbid_ccs}
\alias{icd9_comorbid_ccs}
\alias{icd10_comorbid_ccs}
\alias{comorbid_ahrq}
\alias{comorbid_elix}
\alias{comorbid_quan_elix}
\alias{comorbid_quan_deyo}
\alias{comorbid_charlson}
\alias{comorbid_pccc_dx}
\alias{comorbid_pccc_pcs}
\alias{icd9_comorbid_pccc_dx}
\alias{icd10_comorbid_pccc_dx}
\alias{icd9_comorbid_pccc_pcs}
\alias{icd10_comorbid_pccc_pcs}
\title{Find comorbidities from ICD-9 codes.}
\usage{
comorbid(
  x,
  map,
  visit_name = NULL,
  icd_name = NULL,
  short_code = guess_short(x, icd_name = icd_name),
  short_map = guess_short(map),
  return_df = FALSE,
  return_binary = FALSE,
  categorize_fun = categorize_simple,
  ...
)

icd10_comorbid(
  x,
  map,
  visit_name = NULL,
  icd_name = NULL,
  short_code = NULL,
  short_map = guess_short(map),
  return_df = FALSE,
  return_binary = FALSE,
  icd10_comorbid_fun = icd10_comorbid_reduce,
  ...
)

icd9_comorbid(
  x,
  map,
  visit_name = NULL,
  icd_name = NULL,
  short_code = guess_short(x, icd_name = icd_name),
  short_map = guess_short(map),
  return_df = FALSE,
  return_binary = FALSE,
  preclean = FALSE,
  categorize_fun = categorize_simple,
  comorbid_fun = comorbid_mat_mul_wide,
  ...
)

icd9_comorbid_ahrq(x, ..., abbrev_names = TRUE, hierarchy = TRUE)

icd10_comorbid_ahrq(x, ..., abbrev_names = TRUE, hierarchy = TRUE)

icd9_comorbid_elix(x, ..., abbrev_names = TRUE, hierarchy = TRUE)

icd10_comorbid_elix(x, ..., abbrev_names = TRUE, hierarchy = TRUE)

icd9_comorbid_quan_elix(x, ..., abbrev_names = TRUE, hierarchy = TRUE)

icd10_comorbid_quan_elix(x, ..., abbrev_names = TRUE, hierarchy = TRUE)

icd9_comorbid_quan_deyo(x, ..., abbrev_names = TRUE, hierarchy = TRUE)

icd10_comorbid_quan_deyo(x, ..., abbrev_names = TRUE, hierarchy = TRUE)

icd9_comorbid_charlson(...)

icd10_comorbid_charlson(...)

comorbid_ccs(x, icd_name = get_icd_name(x), ...)

icd9_comorbid_ccs(
  x,
  ...,
  single = TRUE,
  lvl = NULL,
  map = icd::icd9_map_single_ccs,
  short_map = TRUE
)

icd10_comorbid_ccs(x, ..., single = TRUE, lvl = NULL)

comorbid_ahrq(x, ...)

comorbid_elix(x, ...)

comorbid_quan_elix(x, ...)

comorbid_quan_deyo(x, ...)

comorbid_charlson(...)

comorbid_pccc_dx(
  x,
  visit_name = get_visit_name(x),
  icd_name = get_icd_name(x),
  short_code = guess_short(x, icd_name = icd_name),
  return_df = FALSE,
  return_binary = FALSE,
  ...
)

comorbid_pccc_pcs(
  x,
  visit_name = get_visit_name(x),
  icd_name,
  return_df = FALSE,
  return_binary = FALSE,
  ...
)

icd9_comorbid_pccc_dx(
  x,
  visit_name = NULL,
  icd_name = NULL,
  short_code = guess_short(x, icd_name = icd_name),
  return_df = FALSE,
  return_binary = FALSE,
  ...,
  abbrev_names = TRUE
)

icd10_comorbid_pccc_dx(
  x,
  visit_name = NULL,
  icd_name = NULL,
  short_code = guess_short(x, icd_name = icd_name),
  return_df = FALSE,
  return_binary = FALSE,
  ...,
  abbrev_names = TRUE
)

icd9_comorbid_pccc_pcs(
  x,
  visit_name = get_visit_name(x),
  icd_name = get_icd_pc_name(x),
  return_df = FALSE,
  return_binary = FALSE,
  ...,
  abbrev_names = TRUE
)

icd10_comorbid_pccc_pcs(
  x,
  visit_name = get_visit_name(x),
  icd_name,
  return_df = FALSE,
  return_binary = FALSE,
  ...,
  abbrev_names = TRUE
)
}
\arguments{
\item{x}{\code{data.frame} containing a column of patient-visit identifiers
and a column of ICD codes. The \code{data.frame} may be in \sQuote{long} or
\sQuote{wide} format, like the example \code{\link{vermont_dx}}
and \code{\link{uranium_pathology}} data.}

\item{map}{A named list of the comorbidities with each list item containing a
vector of decimal ICD-9 codes. \pkg{icd} includes a number of these, e.g.,
\code{\link{icd9_map_elix}}. Alternatively, this can be omitted if the
convenience functions, such as \code{icd10_comorbid_charlson} are used
directly. \code{map} should be in the form of a list, with the names of the
items corresponding to the comorbidities (e.g. \sQuote{HTN}, or
\sQuote{diabetes}) and the contents of each list item being a character
vector of short-form (no decimal place, zero left-padded) ICD codes. There
is no default: the user should use the family of functions, e.g.
\code{comorbid_ahrq}, since these also name the fields correctly, and these
functions also apply any hierarchical rules (see \code{hierarchy} below)}

\item{visit_name}{The name of the column in the data frame which contains the
patient or visit identifier. Typically this is the visit identifier, since
patients come leave and enter hospital with different ICD-9 codes. It is a
character vector of length one. If left empty, or \code{NULL}, then an
attempt is made to guess which field has the ID for the patient encounter
(not a patient ID, although this can of course be specified directly). The
guesses proceed until a single match is made. Data frames may be wide with
many matching fields, so to avoid false positives, anything but a single
match is rejected. If there are no successful guesses, and \code{visit_id}
was not specified, then the first column of the data frame is used.}

\item{icd_name}{The name of the column in the \code{data.frame} which
contains the ICD codes. This is a character vector of length one. If it is
\code{NULL}, \code{icd9} will attempt to guess the column name, looking for
progressively less likely possibilities until it matches a single column.
Failing this, it will take the first column in the data frame. Specifying
the column using this argument avoids the guesswork.}

\item{short_code}{single logical value which determines whether the ICD-9
code provided is in short (\code{TRUE}) or decimal (\code{FALSE}) form.
Where reasonable, this is guessed from the input data.}

\item{short_map}{Same as short, but applied to \code{map} instead of the data
frame of ICD codes, \code{x}. All the codes in a mapping should be of the
same type, i.e. short or decimal.}

\item{return_df}{single logical value, if \code{TRUE}, return 'tidy' data,
i.e., the result is a data frame with the first column being the
\code{visit_id}, and the second being the count. If \code{visit_id} was a
factor or named differently in the input, this is preserved.}

\item{return_binary}{Single logical value, if \code{TRUE}, the returned
\code{matrix} or \code{data.frame} will be composed of \code{1} and
\code{0}, instead of \code{TRUE} and \code{FALSE}, respectively. This
conversion can also be done by the internal functions
\code{icd:::logical_to_binary} and \code{icd:::binary_to_logical}, or using
other tools, e.g. \code{apply(x, 2, as.integer)}}

\item{categorize_fun}{Internal. Function used for the categorization problem.}

\item{...}{Arguments passed through to \code{comorbid}, and ultimately \code{\link{categorize_simple}}, e.g. \code{restore_id_order}.}

\item{icd10_comorbid_fun}{Internal function Default will be fast and
accurate. A function which calculates comorbidities for ICD-10 codes, in
which the comorbidity map only specifies parent codes, not every possible
child.}

\item{preclean}{single logical value, which, if \code{TRUE} causes ICD-9
'short' code input to be padded to correct three (or four for E code)
length before applying the comorbidity map. For very large data sets, e.g.
ten million rows, this is much slower than the comorbidity calculation. If
you know that the source ICD-9 codes are already well formed (or have
already run \code{icd9_add_leading_zeroes}), then \code{preclean} can be
set to \code{FALSE} to save time.}

\item{comorbid_fun}{Internal. Function used inside categorization.}

\item{abbrev_names}{single logical value that defaults to \code{TRUE}, in
which case the shorter human-readable names stored in e.g.
\code{ahrqComorbidNamesAbbrev} are applied to the data frame column names.}

\item{hierarchy}{single logical value that defaults to \code{TRUE}, in which
case the hierarchy defined for the mapping is applied. E.g. in Elixhauser,
you can't have uncomplicated and complicated diabetes both flagged.}

\item{single}{a logical value, if \code{TRUE} then use single level CCS,
otherwise use multi level}

\item{lvl}{If multiple level CCS, then level must be selected as a number
between one and four.}
}
\description{
This is the main function which extracts comorbidities from a set of ICD-9
codes. Some comorbidity schemes have rules, for example, what to do when both
'hypertension' and 'hypertension with complications' are present. These rules
are applied by default; if the exact fields from the original mappings are
needed, use \code{hierarchy = FALSE}. For comorbidity counting, Charlson or
Van Walraven scores the default should be used to apply the rules. For more
about computing Hierarchical Condition Codes (HCC), see
\code{\link{comorbid_hcc}} For more about comorbidities following the
Clinical Classification Software (CCS) rules from AHRQ, see
\code{\link{comorbid_ccs}}.
}
\details{
The order of visits may change depending on the original sequence,
  and the underlying algorithm used. Usually this would be the order of the
  first occurrence of each visit/patient identifier, but this is not
  guaranteed unless \code{restore_id_order} is set to \code{TRUE}.

\code{data.frame}s of patient data may have columns within them
  which are of class \code{icd9}, \code{icd10} etc., but do not themselves
  have a class: therefore, the S3 mechanism for dispatch is not suitable. I
  may add a wrapper function which looks inside a \code{data.frame} of
  comorbidities, and dispatches to the appropriate function, but right now
  the user must call the \code{icd9_} or \code{icd10_} prefixed function
  directly.
}
\section{Functions}{
\itemize{
\item \code{icd10_comorbid}: ICD-10 comorbidities

\item \code{icd9_comorbid}: Get comorbidities from \code{data.frame} of ICD-9
codes

\item \code{icd9_comorbid_ahrq}: AHRQ comorbidities for ICD-9 codes

\item \code{icd10_comorbid_ahrq}: AHRQ comorbidities for ICD-10 codes

\item \code{icd9_comorbid_elix}: Elixhauser comorbidities for ICD-9 codes

\item \code{icd10_comorbid_elix}: Elixhauser comorbidities for ICD-10 codes

\item \code{icd9_comorbid_quan_elix}: Quan's Elixhauser comorbidities for ICD-9 codes

\item \code{icd10_comorbid_quan_elix}: Quan's Elixhauser comorbidities for ICD-10 codes

\item \code{icd9_comorbid_quan_deyo}: Quan's Deyo (Charlson) comorbidities for ICD-9 codes

\item \code{icd10_comorbid_quan_deyo}: Quan's Deyo (Charlson) comorbidities for ICD-10 codes

\item \code{icd9_comorbid_charlson}: Currently synonym for \code{icd9_comorbid_quan_deyo}

\item \code{icd10_comorbid_charlson}: Currently synonym for \code{icd10_comorbid_quan_deyo}

\item \code{comorbid_ccs}: Use AHRQ CCS for comorbidity classification

\item \code{icd9_comorbid_ccs}: Compute AHRQ Clinical Classifications Software (CCS)
scores from ICD-9 codes

\item \code{icd10_comorbid_ccs}: Compute AHRQ Clinical Classifications Software (CCS)
scores from ICD-10 codes

\item \code{comorbid_ahrq}: AHRQ comorbidities, infers whether to use ICD-9 or
ICD-10 codes

\item \code{comorbid_elix}: Elixhauser comorbidities, infers whether to use ICD-9 or
ICD-10 codes

\item \code{comorbid_quan_elix}: Quan's Elixhauser comorbidities, infers whether to use
ICD-9 or ICD-10 codes

\item \code{comorbid_quan_deyo}: Quan's Deyo (Charlson) comorbidities, infers whether to
use ICD-9 or ICD-10 codes

\item \code{comorbid_charlson}: Calculate comorbidities using Charlson categories
according to Quan/Deyo ICD categories. Synonymous with
\code{link{comorbid_quan_deyo}} in this release.

\item \code{comorbid_pccc_dx}: Calculate pediatric complex chronic conditions (PCCC) comorbidities

Unlike with ICD-9 and ICD-10 diagnostic codes, 'icd' doesn't
currently have a method for guessing which fields are procedure
codes, so \code{icd_name} must be specified for the \code{_pcs}
functions.

\item \code{comorbid_pccc_pcs}: Calculate the PCCC comorbidities based
on procedure codes,

\item \code{icd9_comorbid_pccc_dx}: Calculate PCCC comorbidities from ICD-9
diagnosis codes

\item \code{icd10_comorbid_pccc_dx}: Calculate PCCC comorbidities from ICD-10
diagnosis codes

\item \code{icd9_comorbid_pccc_pcs}: Calculate PCCC comorbidities from ICD-9
procedure codes

\item \code{icd10_comorbid_pccc_pcs}: Calculate PCCC comorbidities from ICD-10
procedure codes
}}

\examples{
library(icd)
vermont_dx[1:5, 1:10]
# get first few rows and columns of Charlson comorbidities using Quan/Deyo
# mapping of ICD-9 or ICD-10 codes Charlson categories
comorbid_quan_deyo(vermont_dx)[1:5, 1:14]

# Note that the comorbidity calculations automatically finds the ICD code
# columns, and uses 'wide' or 'long' format data.

stopifnot(
  identical(
    comorbid_quan_deyo(vermont_dx),
    comorbid_quan_deyo(wide_to_long(vermont_dx))
  )
)

# get summary AHRQ (based on Elixhauser) comorbidities for the Uranium data:
summary(comorbid_ahrq(uranium_pathology))

pts <- icd_long_data(
  visit_name = c("2", "1", "2", "3", "3"),
  icd9 = c("39891", "40110", "09322", "41514", "39891")
)
comorbid(pts, icd9_map_ahrq, short_code = TRUE) # visit_name is now sorted
pts <- icd_long_data(
  visit_name = c("1", "2", "3", "4", "4"),
  icd_name = c("20084", "1742", "30410", "41514", "95893"),
  date = as.Date(c(
    "2011-01-01", "2011-01-02", "2011-01-03",
    "2011-01-04", "2011-01-04"
  ))
)

pt_hccs <- comorbid_hcc(pts, date_name = "date")
head(pt_hccs)

pts10 <- icd_long_data(
  visit_name = c("a", "b", "c", "d", "e"),
  icd_name = c("I058", NA, "T82817A", "", "I69369"),
  date = as.Date(
    c("2011-01-01", "2011-01-02", "2011-01-03", "2011-01-03", "2011-01-03")
  )
)

icd10_comorbid(pts10, map = icd10_map_ahrq)
# or if library(icd) hasn't been called first:
icd::icd10_comorbid(pts10, map = icd::icd10_map_ahrq)
# or most simply:
icd::icd10_comorbid_ahrq(pts10)

# specify a simple custom comorbidity map:
my_map <- list(
  "malady" = c("100", "2000"),
  "ailment" = c("003", "040")
)
two_pts <- data.frame(
  visit_id = c("v01", "v01", "v02", "v02"),
  icd9 = as.icd9(c("040", "000", "100", "000")),
  stringsAsFactors = FALSE
)
comorbid(two_pts, map = my_map)
# not pediatric data, but let's look for this example
head(icd9_comorbid_pccc_dx(vermont_dx))
# Six random codes from each PCCC procedure code map. 'icd' will use
# an heuristic to guess whether ICD-9 or ICD-10:
pts <- data.frame(
  encounters = c(10, 11, 12),
  icd9_pcs = c("0152", "304", "0050"),
  icd10_pcs = c("0B110Z4", "02YA0Z2", "031209D")
)
comorbid_pccc_pcs(pts, icd_name = "icd9_pcs", return_binary = TRUE)
comorbid_pccc_pcs(pts, icd_name = "icd10_pcs", return_binary = TRUE)

# All ICD-9 procedure codes are numeric, some ICD-10 procedure codes
# are numeric, so best to call functions directly:
pts <- data.frame(encounters = c(100), icd10_pcs = c("0016070"))
icd10_comorbid_pccc_pcs(pts, icd_name = "icd10_pcs")
}
\seealso{
\link{icd9_map_single_ccs}

Consider using \code{\link{comorbid_ahrq}} instead of
  \code{\link{comorbid_elix}} for more recently updated mappings based on the
  Elixhauser scheme.

Other comorbidity computations: 
\code{\link{comorbid_hcc}()}

Other comorbidities: 
\code{\link{comorbid_hcc}()},
\code{\link{icd10_map_ahrq_pcs}},
\code{\link{icd9_map_ahrq}},
\code{\link{icd9_map_elix}},
\code{\link{icd9_map_hcc}},
\code{\link{icd9_map_pccc}},
\code{\link{icd9_map_quan_deyo}},
\code{\link{icd9_map_quan_elix}},
\code{\link{icd9_map_single_ccs}}

Other comorbidity computations: 
\code{\link{comorbid_hcc}()}

Other comorbidities: 
\code{\link{comorbid_hcc}()},
\code{\link{icd10_map_ahrq_pcs}},
\code{\link{icd9_map_ahrq}},
\code{\link{icd9_map_elix}},
\code{\link{icd9_map_hcc}},
\code{\link{icd9_map_pccc}},
\code{\link{icd9_map_quan_deyo}},
\code{\link{icd9_map_quan_elix}},
\code{\link{icd9_map_single_ccs}}
}
\concept{comorbidities}
\concept{comorbidity computations}
