You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: R/manual_for_datasets.R
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,10 @@
97
97
#' All liver diseases (including mild) are included in
98
98
#' "moderate or severe liver disease".
99
99
#' All diabetes is included in "diabetes complication"
100
+
#' - `icd10_swe:` Swedish version using ICD-10 by Ludvigsson et al. (2021).
101
+
#' Note that chronic pulmonary disease is combined (separated as chronic and other in the article).
102
+
#' Note that mild kidney disease combined with `R18`should also count as moderate or severe kidney disease
103
+
#' (not implemented so must be handled manually).
100
104
#' - `icd8_brusselaers:` Back translated version from ICD-10 to
101
105
#' ICD-8 by Brusselaers et al. (2017).
102
106
#' "Moderate and severe liver disease" contains all liver disease and
@@ -131,6 +135,10 @@
131
135
#' administrative databases.
132
136
#' Journal of Clinical Epidemiology, 45(6), 613–619.
133
137
#'
138
+
#' Ludvigsson, J. F., Appelros, P., Askling, J., Byberg, L., Carrero, J.-J., Ekström, A. M., Ekström, M., Smedby, K. E., Hagström, H., James, S., Järvholm, B., Michaelsson, K., Pedersen, N. L., Sundelin, H., Sundquist, K., Sundström, J.
139
+
#' Adaptation of the Charlson Comorbidity Index for Register-Based Research in Sweden.
Assume we have some patients with surgery at specified dates:
58
58
59
59
60
-
```r
60
+
```r
61
61
library(coder)
62
62
ex_people
63
63
#> # A tibble: 100 × 2
64
64
#> name surgery
65
65
#> <chr> <date>
66
-
#> 1 Chen, Trevor 2023-02-28
67
-
#> 2 Graves, Acineth 2022-11-20
68
-
#> 3 Trujillo, Yanelly 2022-11-07
69
-
#> 4 Simpson, Kenneth 2023-02-09
70
-
#> 5 Chin, Nelson 2023-01-23
71
-
#> 6 Le, Christina 2022-08-27
72
-
#> 7 Kang, Xuan 2022-11-29
73
-
#> 8 Shuemaker, Lauren 2022-08-28
74
-
#> 9 Boucher, Teresa 2023-02-03
75
-
#> 10 Le, Soraiya 2023-01-08
76
-
#> # … with 90 more rows
66
+
#> 1 Chen, Trevor 2025-04-21
67
+
#> 2 Graves, Acineth 2025-01-11
68
+
#> 3 Trujillo, Yanelly 2024-12-29
69
+
#> 4 Simpson, Kenneth 2025-04-02
70
+
#> 5 Chin, Nelson 2025-03-16
71
+
#> 6 Le, Christina 2024-10-18
72
+
#> 7 Kang, Xuan 2025-01-20
73
+
#> 8 Shuemaker, Lauren 2024-10-19
74
+
#> 9 Boucher, Teresa 2025-03-27
75
+
#> 10 Le, Soraiya 2025-03-01
76
+
#> # ℹ 90 more rows
77
77
```
78
78
79
79
Those patients (among others) were also recorded in a national patient register with date of hospital admissions and diagnoses codes coded by the International Classification of Diseases (ICD) version 10:
80
80
81
81
82
-
```r
82
+
```r
83
83
ex_icd10
84
84
#> # A tibble: 2,376 × 4
85
85
#> name admission icd10 hdia
86
86
#> <chr> <date> <chr> <lgl>
87
-
#> 1 Tran, Kenneth 2022-09-11 S134A FALSE
88
-
#> 2 Tran, Kenneth 2023-02-25 W3319 FALSE
89
-
#> 3 Tran, Kenneth 2023-02-04 Y0262 TRUE
90
-
#> 4 Tran, Kenneth 2022-12-28 X0488 FALSE
91
-
#> 5 Sommerville, Dominic 2023-02-16 V8104 FALSE
92
-
#> 6 Sommerville, Dominic 2022-09-27 B853 FALSE
93
-
#> 7 Sommerville, Dominic 2023-02-11 Q174 FALSE
94
-
#> 8 Sommerville, Dominic 2022-10-02 A227 FALSE
95
-
#> 9 Sommerville, Dominic 2023-02-06 H702 FALSE
96
-
#> 10 Sommerville, Dominic 2022-05-31 X6051 TRUE
97
-
#> # … with 2,366 more rows
87
+
#> 1 Tran, Kenneth 2024-11-02 S134A FALSE
88
+
#> 2 Tran, Kenneth 2025-04-18 W3319 FALSE
89
+
#> 3 Tran, Kenneth 2025-03-28 Y0262 TRUE
90
+
#> 4 Tran, Kenneth 2025-02-18 X0488 FALSE
91
+
#> 5 Sommerville, Dominic 2025-04-09 V8104 FALSE
92
+
#> 6 Sommerville, Dominic 2024-11-18 B853 FALSE
93
+
#> 7 Sommerville, Dominic 2025-04-04 Q174 FALSE
94
+
#> 8 Sommerville, Dominic 2024-11-23 A227 FALSE
95
+
#> 9 Sommerville, Dominic 2025-03-30 H702 FALSE
96
+
#> 10 Sommerville, Dominic 2024-07-22 X6051 TRUE
97
+
#> # ℹ 2,366 more rows
98
98
```
99
99
100
100
Using those two data sets, as well as a classification scheme (`classcodes` object; see below), we can easily identify all Charlson comorbidities for each patient:
101
101
102
102
103
-
```r
103
+
```r
104
104
ch<-
105
105
categorize(
106
106
ex_people, # patients of interest
107
107
codedata=ex_icd10, # Medical codes from national patient register
108
108
cc="charlson", # Calculate Charlson comorbidity
109
109
id="name", code="icd10"# Specify column names
110
110
)
111
-
#> Error in UseMethod("categorize"): no applicable method for 'categorize' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"
111
+
#> Classification based on: icd10
112
112
113
113
ch
114
-
#> Error in eval(expr, envir, enclos): object 'ch' not found
114
+
#> # A tibble: 100 × 25
115
+
#> name surgery myocardial.infarction congestive.heart.fai…¹ peripheral.vascular.…² cerebrovascular.dise…³ dementia
#> Error in eval(expr, envir, enclos): object 'ch' not found
140
+
#> [1] 5
123
141
```
124
142
125
143
What is the distribution of the combined comorbidity index for each patient?
126
144
127
145
128
-
```r
146
+
```r
129
147
barplot(table(ch$charlson))
130
-
#> Error in table(ch$charlson): object 'ch' not found
131
148
```
132
149
150
+
<divclass="figure">
151
+
<imgsrc="man/figures/READMEunnamed-chunk-5-1.png"alt="plot of chunk unnamed-chunk-5"width="100%" />
152
+
<pclass="caption">plot of chunk unnamed-chunk-5</p>
153
+
</div>
154
+
133
155
There are many versions of the Charlson comorbidity index, which might be controlled by the `index` argument. We might also be interested only in diagnoses from 90 days before surgery as specified with an argument list `codify_args`as passed to `codify()`:
#> Error in UseMethod("categorize"): no applicable method for 'categorize' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"
171
+
#> Classification based on: icd10
150
172
```
151
173
152
174
Number of malignancies during this period?
153
175
154
176
155
-
```r
177
+
```r
156
178
sum(ch$malignancy, na.rm=TRUE)
157
-
#> Error in eval(expr, envir, enclos): object 'ch' not found
179
+
#> [1] 3
158
180
```
159
181
160
182
Distribution of the index as proposed by Quan et al 2011 during the 90 day period:
161
183
162
184
163
-
```r
185
+
```r
164
186
barplot(table(ch$quan_updated))
165
-
#> Error in table(ch$quan_updated): object 'ch' not found
166
187
```
167
188
189
+
<divclass="figure">
190
+
<imgsrc="man/figures/READMEunnamed-chunk-8-1.png"alt="plot of chunk unnamed-chunk-8"width="100%" />
191
+
<pclass="caption">plot of chunk unnamed-chunk-8</p>
192
+
</div>
193
+
168
194
## Classification schemes
169
195
170
196
Classification schemes (`classcodes` objects, see `vignette("classcodes")`) are based on regular expressions for computational speed (see `vignette("Interpret_regular_expressions")`), but their content can be summarized and visualized for clarity. Arbitrary `classcodes` objects can also be specified by the user.
@@ -174,9 +200,18 @@ The package includes default `classcodes` for medical patient data based on the
174
200
Default `classcades` are listed in the table. Each classification (classcodes column) can be based on several code systems (regex column) and have several alternative weighted indices (indices column). Those might be combined freely.
175
201
176
202
177
-
```r
203
+
```r
178
204
coder::all_classcodes()
179
-
#> Error: 'all_classcodes' is not an exported object from 'namespace:coder'
0 commit comments