classify: Classify codified data

Description Usage Arguments Value See Also Examples

View source: R/classify.R

Description

This is the second step of codify() %>% classify() %>% index(). Hence, the function takes a codified data set and classify each case based on relevant codes as identified by the classification scheme provided by a classcodes object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
classify(codified, cc, ..., cc_args = list())

## Default S3 method:
classify(codified, cc, ..., cc_args = list())

## S3 method for class 'codified'
classify(codified, ...)

## S3 method for class 'data.frame'
classify(codified, ...)

## S3 method for class 'data.table'
classify(codified, cc, ..., id, code, cc_args = list())

Arguments

codified

output from codify()

cc

classcodes object (or name of a default object from all_classcodes()).

...

arguments passed between methods

cc_args

List with named arguments passed to set_classcodes()

code, id

name of code/id columns (in codified).

Value

Object of class "classified". Inheriting from a Boolean matrix with one row for each element/row of codified and columns for each class with corresponding class names (according to the classcodes object). Note, however, that print.classified() preview this output as a tibble.

See Also

as.data.frame.classified(), as.data.table.classified() and as.matrix.classified(), print.classified()

Other verbs: categorize(), codify(), index_fun

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# classify.default() ------------------------------------------------------

# Classify individual ICD10-codes by Elixhauser
classify(c("C80", "I20", "unvalid_code"), "elixhauser")



# classify.codified() -----------------------------------------------------

# Prepare some codified data with ICD-10 codes during 1 year (365 days)
# before surgery
x <-
  codify(
    ex_people,
    ex_icd10,
    id        = "name",
    code      = "icd10",
    date      = "surgery",
    days      = c(-365, 0),
    code_date = "admission"
  )

# Classify those patients by the Charlson and Elixhasuer comorbidity indices
classify(x, "charlson")        # classcodes object by name ...
classify(x, coder::elixhauser) # ... or by the object itself


# -- start/stop --
# Assume that a prefix "ICD-10 = " is used for all codes and that some
# additional numbers are added to the end
x$icd10 <- paste0("ICD-10 = ", x$icd10)

# Set start = FALSE to identify codes which are not necessarily found in the
# beginning of the string
classify(x, "charlson", cc_args = list(start = FALSE))


# -- regex --
# Use a different version of Charlson (as formulated by regular expressions
# according to the Royal College of Surgeons (RCS) by passing arguments to
# `set_classcodes()` using the `cc_args` argument
y <-
  classify(
    x,
    "charlson",
    cc_args = list(regex = "icd10_rcs")
  )


# -- tech_names --
# Assume that we want to compare the results using the default ICD-10
# formulations (from Quan et al. 2005) and the RCS version and that the result
# should be put into the same data frame. We can use `tech_names = TRUE`
# to distinguish variables with otherwise similar names
cc <- list(tech_names = TRUE) # Prepare sommon settings
compare <-
  merge(
  classify(x, "charlson", cc_args = cc),
  classify(x, "charlson", cc_args = c(cc, regex = "icd10_rcs"))
)
names(compare) # long but informative and distinguishable column names



# classify.data.frame() / classify.data.table() ------------------------

# Assume that `x` is a data.frame/data.table without additional attributes
# from `codify()` ...
xdf <- as.data.frame(x)
xdt <- data.table::as.data.table(x)

# ... then the `id` and `code` columns must be specified explicitly
classify(xdf, "charlson", id = "name", code = "icd10")
classify(xdt, "charlson", id = "name", code = "icd10")

coder documentation built on Jan. 18, 2021, 5:07 p.m.