classcodes: Classcodes methods

classcodesR Documentation

Classcodes methods

Description

classcodes are classification schemes based on regular expression stored in data frames. These are essential to the package and constitute the third part of the triad of case data, code data and a classification scheme.

Usage

as.classcodes(x, ...)

## S3 method for class 'classcodes'
as.classcodes(
  x,
  ...,
  regex = attr(x, "regexpr"),
  indices = attr(x, "indices"),
  hierarchy = attr(x, "hierarchy")
)

## S3 method for class 'data.frame'
as.classcodes(
  x,
  ...,
  regex = NULL,
  indices = NULL,
  hierarchy = attr(x, "hierarchy"),
  .name = NULL
)

is.classcodes(x)

Arguments

x

data frame with columns described in the details section. Alternatively a classcodes object to be modified.

...

arguments passed between methods#'

regex, indices

character vector with names of columns in x containing regular expressions/indices.

hierarchy

named list of pairwise group names to appear as superior and subordinate for indices. To be used for indexing when the subordinate class is redundant (see the details section of elixhauser for an example).

.name

used internally for name dispatch

Details

A classcodes object is a data frame with mandatory columns:

  • group: unique and non missing class names

  • At least one column with regular expressions (regex without Perl-like versions) defining class membership. Those columns can have arbitrary names (as specified by the regex argument). Occurrences of non unique regular expressions will lead to the same class having multiple names. This is accepted but will raise a warning. Classes do not have to be disjunct.

The object can have additional optional columns:

  • description: description of each category

  • condition: a class might have conditions additional to what is expressed by the regular expressions. If so, these should be specified as quoted expressions that can be evaluated within the data frame used by classify()

  • weights for each class used by index(). Could be more than one and could have arbitrary names (as specified by the indicesargument).

Value

Object of class classcodes (inheriting from data frame) with additional attributes:

  • code: the coding used (for example "icd10", or "ATC"). NULL for unknown/arbitrary coding.

  • regexprs: name of columns with regular expressions (as specified by the regexargument)

  • indices: name of columns with (optional) index weights (as specified by the indicesargument)

  • hierarchy: list as specified by the hierarchy argument.

  • name: name as specified by the .name argument.

See Also

vignette("classcodes") vignette("Interpret_regular_expressions") The package have several default classcodes included, see all_classcodes().

Other classcodes: all_classcodes(), as.data.frame.classified(), codebook(), print.classcodes(), print.classified(), set_classcodes(), summary.classcodes(), visualize.classcodes()

Other classcodes: all_classcodes(), as.data.frame.classified(), codebook(), print.classcodes(), print.classified(), set_classcodes(), summary.classcodes(), visualize.classcodes()

Examples

# The Elixhauser comorbidity classification is already a classcodes object
is.classcodes(coder::elixhauser)

# Strip its class attributes to use in examples
df <- as.data.frame(coder::elixhauser)

# Specify which columns store regular expressions and indices
# (assume no hierarchy)
elix <-
  as.classcodes(
    df,
    regex     = c("icd10", "icd10_short", "icd9cm", "icd9cm_ahrqweb", "icd9cm_enhanced"),
    indices   = c("sum_all", "sum_all_ahrq", "walraven",
                "sid29", "sid30", "ahrq_mort", "ahrq_readm"),
    hierarchy = NULL
  )
elix

# Specify hierarchy for patients with different types of cancer and diabetes
# See `?elixhauser` for details
as.classcodes(
  elix,
  hierarchy = list(
    cancer   = c("metastatic cancer", "solid tumor"),
    diabetes = c("diabetes complicated", "diabetes uncomplicated")
  )
)

# Several checks are performed to not allow any erroneous classcodes object
## Not run: 
  as.classcodes(iris)
  as.classcodes(iris, regex = "Species")

## End(Not run)

eribul/coder documentation built on March 16, 2023, 12:50 a.m.