Title: | Implementing Cause-of-Death Data Checks Based on the WHO CoDEdit Tool |
---|---|
Description: | The World Health Organization's CoDEdit electronic tool is intended to help producers of cause-of-death statistics in strengthening their capacity to perform routine checks on their data. This package ports the original tool built using Microsoft Access into R so as to leverage the utility and function of the original tool into a usable application program interface that can be used for building more universal tools or for creating programmatic scientific workflows aimed at routine, automated, and large-scale monitoring of cause-of-death data. |
Authors: | Anita Makori [aut, cph],
Ernest Guevarra [aut, cre, cph]
|
Maintainer: | Ernest Guevarra <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.0.0.9000 |
Built: | 2025-03-02 04:04:19 UTC |
Source: | https://github.com/OxfordIHTM/codeditr |
Calculate age at death based on date of birth and date of death
cod_calculate_age(dob, dod, date_format = "%Y-%m-%d", codedit = TRUE) cod_calculate_ages(dob, dod, date_format = "%Y-%m-%d", codedit = TRUE)
cod_calculate_age(dob, dod, date_format = "%Y-%m-%d", codedit = TRUE) cod_calculate_ages(dob, dod, date_format = "%Y-%m-%d", codedit = TRUE)
dob |
Date of birth. This should ideally be in standard ISO extended
date format of "YYYY-MM-DD" as specified in the default value for
|
dod |
Date of death. This should ideally be in standard ISO extended
date format of YYYY-MM_DD" as specified in the default value for
|
date_format |
Format for date values provided. Date formatting is
handled using |
codedit |
Logical. Should output be based on the CoDEdit version 2 coding rules. Default to TRUE. |
Values for age in days, months and years. IF codedit
is TRUE,
a tibble with age value and age type as required by CoDEdit.
cod_calculate_age("1977-11-05", Sys.Date()) cod_calculate_age("1965-05-20", "2023-10-03")
cod_calculate_age("1977-11-05", Sys.Date()) cod_calculate_age("1965-05-20", "2023-10-03")
Check age values in cause-of-death data based on CoDEdit rules
cod_check_age(age_value, age_type, age_type_code = c("D", "M", "Y"))
cod_check_age(age_value, age_type, age_type_code = c("D", "M", "Y"))
age_value |
An integer value or vector of values for age based on the CoDEdit rules. |
age_type |
A vector of values for age type based on the CoDEdit rules.
This should either be "D" for age in days, "M" for age
in months, or "Y" for age in years. If values are different from these,
then |
age_type_code |
A character or integer vector of 3 values that indicate which values are to be considered pertaining to days (first value in the vector), to months (second value in the vector), or years (third value in the vector). |
A tibble with number of rows equal to length of age_value
and
two columns for age_check and age_check_note.
cod_check_age(120, "Y") cod_check_age(28, "D") cod_check_age(32, "D")
cod_check_age(120, "Y") cod_check_age(28, "D") cod_check_age(32, "D")
Check cause-of-death code for code entry mistakes and/or code completeness
cod_check_code(cod, version = c("icd10", "icd11"), sex, age) cod_check_code_structure_icd10(cod) cod_check_code_structure_icd11(cod) cod_check_code_ill_defined_icd10(cod) cod_check_code_ill_defined_icd11(cod) cod_check_code_unlikely_icd10(cod) cod_check_code_unlikely_icd11(cod) cod_check_code_sex_icd10_(cod, sex) cod_check_code_sex_icd10(cod, sex) cod_check_code_sex_icd11_(cod, sex) cod_check_code_sex_icd11(cod, sex) cod_check_code_age_icd10_(cod, age) cod_check_code_age_icd10(cod, age) cod_check_code_age_icd11_(cod, age) cod_check_code_age_icd11(cod, age)
cod_check_code(cod, version = c("icd10", "icd11"), sex, age) cod_check_code_structure_icd10(cod) cod_check_code_structure_icd11(cod) cod_check_code_ill_defined_icd10(cod) cod_check_code_ill_defined_icd11(cod) cod_check_code_unlikely_icd10(cod) cod_check_code_unlikely_icd11(cod) cod_check_code_sex_icd10_(cod, sex) cod_check_code_sex_icd10(cod, sex) cod_check_code_sex_icd11_(cod, sex) cod_check_code_sex_icd11(cod, sex) cod_check_code_age_icd10_(cod, age) cod_check_code_age_icd10(cod, age) cod_check_code_age_icd11_(cod, age) cod_check_code_age_icd11(cod, age)
cod |
A character value or vector of values for cause-of-death code/s. |
version |
A character value for ICD version used. This should be either "icd10" or "icd11". Default is "icd10". |
sex |
A character value or vector of values for sex of individual
associated with the specified |
age |
An integer value or vector of values for age (in years) of individual. |
A tibble with 2 columns/fields. First is an integer value indicating whether there is an issue with the cause-of-death code provided in relation to a potential code entry mistake and/or and issue of code completeness.
cod_check_code("U100", sex = 1, age = 10) cod_check_code("2C6Z", version = "icd11", sex = 1, age = 65)
cod_check_code("U100", sex = 1, age = 10) cod_check_code("2C6Z", version = "icd11", sex = 1, age = 65)
Summarise cause-of-death check results
cod_check_code_summary(cod_check, simplify = FALSE)
cod_check_code_summary(cod_check, simplify = FALSE)
cod_check |
A data.frame output of the various |
simplify |
Logical. Should output be converted into a data.frame? Default is FALSE. |
If simplify
is FALSE (default), a list of summary check outputs.
Otherwise, a tabulated summary of check outputs.
cod_check_code( cod_data_raw_example$code, version = "icd11", sex = cod_data_raw_example$sex, age = cod_data_raw_example$age ) |> cod_check_code_summary()
cod_check_code( cod_data_raw_example$code, version = "icd11", sex = cod_data_raw_example$sex, age = cod_data_raw_example$age ) |> cod_check_code_summary()
Check structure and values of input data to CoDEdit tool
cod_check_codedit_input(df)
cod_check_codedit_input(df)
df |
A data.frame with 6 columns with names |
A data.frame containing check codes and check notes for each row
and variable identified with the FreeId
of df
.
cod_check_codedit_input(icd10_example)
cod_check_codedit_input(icd10_example)
Check date of death value in cause-of-death data based on CoDEdit rules
cod_check_dod(dod)
cod_check_dod(dod)
dod |
Date of death value expressed in terms of the year death occurred. |
A tibble with number of rows equal to length of dod
and
two columns for dod_check and dod_check_note.
cod_check_dod("2024")
cod_check_dod("2024")
Check sex values in cause-of-death data based on CoDEdit rules
cod_check_sex(sex_value, sex_code = c(1, 2))
cod_check_sex(sex_value, sex_code = c(1, 2))
sex_value |
An integer value or vector of values for age based on the CoDEdit rules. |
sex_code |
A character or integer vector of 2 values that indicate which values are to be considered pertaining to males (first value in the vector) or to females (second value in the vector). Default is 1 for male and 2 for female. |
A tibble with number of rows equal to length of sex_value
and
two columns for sex_check and sex_check_note.
cod_check_sex("m", c("m", "f")) cod_check_sex("male", c("male", "female")) cod_check_sex(1, 1:2)
cod_check_sex("m", c("m", "f")) cod_check_sex("male", c("male", "female")) cod_check_sex(1, 1:2)
Example raw cause-of-death dataset
cod_data_raw_example
cod_data_raw_example
A data frame with 6 columns and 20 rows:
Variable | Description |
id | Unique identifier |
sex | Sex of deceased |
age | Age of diseased in years |
code | ICD 11 cause-of-death code |
dod | Date of death |
dob | Date of birth |
cod_data_raw_example
cod_data_raw_example
Recode age type of cause-of-death data based on CoDEdit rules
cod_recode_age_type(age_type, age_type_code = c("D", "M", "Y"))
cod_recode_age_type(age_type, age_type_code = c("D", "M", "Y"))
age_type |
A vector of values for age type based on the CoDEdit rules.
This should either be "D" for age in days, "M" for age
in months, or "Y" for age in years. If values are different from these,
then |
age_type_code |
A character or integer vector of 3 values that indicate which values are to be considered pertaining to days (first value in the vector), to months (second value in the vector), or years (third value in the vector). |
A character value or vector of values containing either "D", "M", or "Y" for days, months, or years respectively.
cod_recode_age_type( age_type = c(rep("d", 3), rep("m", 2), rep("y", 3)), age_type_code = c("d", "m", "y") )
cod_recode_age_type( age_type = c(rep("d", 3), rep("m", 2), rep("y", 3)), age_type_code = c("d", "m", "y") )
Recode sex value of cause-of-death data based on CoDEdit rules
cod_recode_sex(sex_value, sex_code = c(1L, 2L), codedit = TRUE)
cod_recode_sex(sex_value, sex_code = c(1L, 2L), codedit = TRUE)
sex_value |
A character or integer value or vector of values signifying the sex. |
sex_code |
A character or integer vector of 2 values that indicate which values are to be considered pertaining to males (first value in the vector) or to females (second value in the vector). |
codedit |
Logical. Should output be based on the CoDEdit version 2 coding rules. Default to TRUE. |
An integer value or vector of values containing either 1 for males
or 2 for females. If codedit = TRUE
, values not equal to the sex_code
values are coded as 9 (integer). Otherwise, it is coded as NA_integer_.
cod_recode_sex( sex_value = c(rep("m", 2), rep("f", 3)), sex_code = c("m", "f") )
cod_recode_sex( sex_value = c(rep("m", 2), rep("f", 3)), sex_code = c("m", "f") )
Structure cause-of-death data into CoDEdit tool input data
cod_structure_input(df, sex, sex_code = c(1, 2), dob, dod, code, id = NULL)
cod_structure_input(df, sex, sex_code = c(1, 2), dob, dod, code, id = NULL)
df |
A data.frame of raw cause-of-death data with the following required variables that contains values for sex, date of birth, date of death, and cause-of-death code. |
sex |
A character value for the variable name in |
sex_code |
A character or integer vector of 2 values that indicate which values are to be considered pertaining to males (first value in the vector) or to females (second value in the vector). |
dob |
A character value for the variable name in |
dod |
A character value for the variable name in |
code |
A character value for the variable name in |
id |
A character value for the variable name in |
A tibble with 6 columns and number of rows equal to df
with
names "FreeId"
, "Sex"
, "Age Value"
, "Age Type"
, "Code"
, and
"Death Date"
.
df <- data.frame( id = 1:3, sex = c(1, 1, 2), dob = c("1977-11-05", "1971-04-04", "2012-08-13"), dod = c("2024-06-28", "2023-10-11", "2023-09-25"), code = c("P219", "O230", "Q913") ) cod_structure_input(df, sex = "sex", dob = "dob", dod = "dod", code = "code")
df <- data.frame( id = 1:3, sex = c(1, 1, 2), dob = c("1977-11-05", "1971-04-04", "2012-08-13"), dod = c("2024-06-28", "2023-10-11", "2023-09-25"), code = c("P219", "O230", "Q913") ) cod_structure_input(df, sex = "sex", dob = "dob", dod = "dod", code = "code")
Enumerate ICD 10 codes given a code range
expand_icd10_code_range(code_range)
expand_icd10_code_range(code_range)
code_range |
A character value or a vector of character values indicating a range of ICD 10 codes. See Details for syntax of code range/s. |
A vector of ICD 10 codes that are within the range of codes
specified by code_range
.
expand_icd10_code_range("A71.0-A71.9") expand_icd10_code_range("F50.1,F50.3-F50.9")
expand_icd10_code_range("A71.0-A71.9") expand_icd10_code_range("F50.1,F50.3-F50.9")
Get various age values for all three age types
get_age_values(age_value, age_type = c("D", "M", "Y"))
get_age_values(age_value, age_type = c("D", "M", "Y"))
age_value |
An integer value for the age |
age_type |
The age type of the specified age value. Can be either "D" for day, "M" for month, or "Y" for year. |
A named list of age values in days, months, and years.
get_age_values(1, "Y")
get_age_values(1, "Y")
Sex-specific causes of death for ICD 10
icd10_cod_by_sex
icd10_cod_by_sex
A data frame with 3 columns and 880 rows:
Variable | Description |
code | ICD 10 Cause of Death code |
title | Cause of death title |
sex | Sex - 1 for male; 2 for female |
https://icd.who.int/browse10/Content/statichtml/ICD10Volume2_en_2019.pdf
icd10_cod_by_sex
icd10_cod_by_sex
Child-specific cause-of-death for ICD 10
icd10_cod_child
icd10_cod_child
A data frame with 2 columns and 122 rows:
Variable | Description |
code | ICD 10 Cause of Death code |
title | Cause of death title |
https://www.icd10data.com/ICD10CM/Codes/Rules/Pediatric_Codes
icd10_cod_child
icd10_cod_child
Neonate-specific cause-of-death for ICD 10
icd10_cod_neonate
icd10_cod_neonate
A data frame with 2 columns and 42 rows:
Variable | Description |
code | ICD 10 Cause of Death code |
title | Cause of death title |
https://www.icd10data.com/ICD10CM/Codes/Rules/Newborn_Codes
icd10_cod_neonate
icd10_cod_neonate
Example death records dataset with ICD10 cause-of-death coding
icd10_example
icd10_example
A data frame with 6 columns and 3613 rows:
Variable | Description |
FreeId | Record identifier |
Sex | Sex: 1 = Male; 2 = Female; 9 = unknown |
Age Value | Integer value for age |
Age Type | Is the age value in days (D), months (M), or years (Y) |
Code | ICD10 code for cause-of-death |
Death Date | Date of death in year format |
https://www.who.int/standards/classifications/classification-of-diseases/services/codedit-tool
icd10_example
icd10_example
Unlikely causes of death for ICD 10
icd10_unlikely_cod
icd10_unlikely_cod
A data frame with 2 columns and 424 rows:
Variable | Description |
code | ICD 10 Cause of Death code |
title | Cause of death title |
https://icd.who.int/browse10/Content/statichtml/ICD10Volume2_en_2019.pdf
icd10_unlikely_cod
icd10_unlikely_cod
Sex-specific causes of death for ICD 11
icd11_cod_by_sex
icd11_cod_by_sex
A data frame with 3 columns and 547 rows:
Variable | Description |
code | ICD 11 Cause of Death code |
title | Cause of death title |
sex | Sex - 1 for male; 2 for female |
https://icdcdn.who.int/icd11referenceguide/en/html/index.html#list-of-categories-limited-to-or-more-likely-to-occur-in-female-persons
icd11_cod_by_sex
icd11_cod_by_sex
Child-specific cause-of-death for ICD 11
icd11_cod_child
icd11_cod_child
A data frame with 2 columns and 149 rows:
Variable | Description |
code | ICD 11 Cause of Death code |
title | Cause of death title |
icd11_cod_child
icd11_cod_child
Neonate-specific cause-of-death for ICD 11
icd11_cod_neonate
icd11_cod_neonate
A data frame with 2 columns and 50 rows:
Variable | Description |
code | ICD 11 Cause of Death code |
title | Cause of death title |
icd11_cod_neonate
icd11_cod_neonate
Example death records dataset with ICD11 cause-of-death coding
icd11_example
icd11_example
A data frame with 6 columns and 244 rows:
Variable | Description |
FreeId | Record identifier |
Sex | Sex: 1 = Male; 2 = Female; 9 = unknown |
Age Value | Integer value for age |
Age Type | Is the age value in days (D), months (M), or years (Y) |
Code | ICD11 code for cause-of-death |
Death Date | Date of death in year format |
https://www.who.int/standards/classifications/classification-of-diseases/services/codedit-tool
icd11_example
icd11_example
Unlikely causes of death for ICD 11
icd11_unlikely_cod
icd11_unlikely_cod
A data frame with 2 columns and 269 rows:
Variable | Description |
code | ICD 11 Cause of Death code |
title | Cause of death title |
https://icd.who.int/valuesets/viewer/582/en
icd11_unlikely_cod
icd11_unlikely_cod
List ill-defined ICD 11 codes
list_ill_defined_icd11()
list_ill_defined_icd11()
An character vector of ICD 11 codes classified as ill-defined for cause-of-death
list_ill_defined_icd11()
list_ill_defined_icd11()