Package 'codeditr'

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] , Sanjeev Pugazhendhi [ths, rev], Williams Udoh Ituen-Umanah [rev], Proochista Ariana [rev, 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

Help Index


Calculate age at death based on date of birth and date of death

Description

Calculate age at death based on date of birth and date of death

Usage

cod_calculate_age(dob, dod, date_format = "%Y-%m-%d", codedit = TRUE)

cod_calculate_ages(dob, dod, date_format = "%Y-%m-%d", codedit = TRUE)

Arguments

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 date_format.

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.

date_format

Format for date values provided. Date formatting is handled using strptime() hence this needs to be specified based on what strptime() requires for its format argument. By default, this is set to the standard ISO extended date format expressed as "%Y-%m-%d" which corresponds to "YYYY-MM-DD".

codedit

Logical. Should output be based on the CoDEdit version 2 coding rules. Default to TRUE.

Value

Values for age in days, months and years. IF codedit is TRUE, a tibble with age value and age type as required by CoDEdit.

Examples

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

Description

Check age values in cause-of-death data based on CoDEdit rules

Usage

cod_check_age(age_value, age_type, age_type_code = c("D", "M", "Y"))

Arguments

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 should be specified to correspond to the day, month, and year values of age_type.

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).

Value

A tibble with number of rows equal to length of age_value and two columns for age_check and age_check_note.

Examples

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

Description

Check cause-of-death code for code entry mistakes and/or code completeness

Usage

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)

Arguments

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 cod.

age

An integer value or vector of values for age (in years) of individual.

Value

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.

Examples

cod_check_code("U100", sex = 1, age = 10)
cod_check_code("2C6Z", version = "icd11", sex = 1, age = 65)

Summarise cause-of-death check results

Description

Summarise cause-of-death check results

Usage

cod_check_code_summary(cod_check, simplify = FALSE)

Arguments

cod_check

A data.frame output of the various ⁠cod_check_code_*⁠ functions

simplify

Logical. Should output be converted into a data.frame? Default is FALSE.

Value

If simplify is FALSE (default), a list of summary check outputs. Otherwise, a tabulated summary of check outputs.

Examples

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

Description

Check structure and values of input data to CoDEdit tool

Usage

cod_check_codedit_input(df)

Arguments

df

A data.frame with 6 columns with names "FreeId", "Sex", "Age Value", "Age Type", "Code", and "Death Date" and compatible with the input data required by the CoDEdit tool.

Value

A data.frame containing check codes and check notes for each row and variable identified with the FreeId of df.

Examples

cod_check_codedit_input(icd10_example)

Check date of death value in cause-of-death data based on CoDEdit rules

Description

Check date of death value in cause-of-death data based on CoDEdit rules

Usage

cod_check_dod(dod)

Arguments

dod

Date of death value expressed in terms of the year death occurred.

Value

A tibble with number of rows equal to length of dod and two columns for dod_check and dod_check_note.

Examples

cod_check_dod("2024")

Check sex values in cause-of-death data based on CoDEdit rules

Description

Check sex values in cause-of-death data based on CoDEdit rules

Usage

cod_check_sex(sex_value, sex_code = c(1, 2))

Arguments

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.

Value

A tibble with number of rows equal to length of sex_value and two columns for sex_check and sex_check_note.

Examples

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

Description

Example raw cause-of-death dataset

Usage

cod_data_raw_example

Format

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

Examples

cod_data_raw_example

Recode age type of cause-of-death data based on CoDEdit rules

Description

Recode age type of cause-of-death data based on CoDEdit rules

Usage

cod_recode_age_type(age_type, age_type_code = c("D", "M", "Y"))

Arguments

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 should be specified to correspond to the day, month, and year values of age_type.

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).

Value

A character value or vector of values containing either "D", "M", or "Y" for days, months, or years respectively.

Examples

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

Description

Recode sex value of cause-of-death data based on CoDEdit rules

Usage

cod_recode_sex(sex_value, sex_code = c(1L, 2L), codedit = TRUE)

Arguments

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.

Value

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_.

Examples

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

Description

Structure cause-of-death data into CoDEdit tool input data

Usage

cod_structure_input(df, sex, sex_code = c(1, 2), dob, dod, code, id = NULL)

Arguments

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 df containing the values for 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).

dob

A character value for the variable name in df containing the values for date of birth.

dod

A character value for the variable name in df containing the values for date of death.

code

A character value for the variable name in df containing the values for cause-of-death code.

id

A character value for the variable name in df containing unique record identifiers. Default to NULL. If NULL, unique record identifiers will be generated.

Value

A tibble with 6 columns and number of rows equal to df with names "FreeId", "Sex", "Age Value", "Age Type", "Code", and "Death Date".

Examples

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

Description

Enumerate ICD 10 codes given a code range

Usage

expand_icd10_code_range(code_range)

Arguments

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.

Value

A vector of ICD 10 codes that are within the range of codes specified by code_range.

Examples

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

Description

Get various age values for all three age types

Usage

get_age_values(age_value, age_type = c("D", "M", "Y"))

Arguments

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.

Value

A named list of age values in days, months, and years.

Examples

get_age_values(1, "Y")

Sex-specific causes of death for ICD 10

Description

Sex-specific causes of death for ICD 10

Usage

icd10_cod_by_sex

Format

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

Source

https://icd.who.int/browse10/Content/statichtml/ICD10Volume2_en_2019.pdf

Examples

icd10_cod_by_sex

Child-specific cause-of-death for ICD 10

Description

Child-specific cause-of-death for ICD 10

Usage

icd10_cod_child

Format

A data frame with 2 columns and 122 rows:

Variable Description
code ICD 10 Cause of Death code
title Cause of death title

Source

https://www.icd10data.com/ICD10CM/Codes/Rules/Pediatric_Codes

Examples

icd10_cod_child

Neonate-specific cause-of-death for ICD 10

Description

Neonate-specific cause-of-death for ICD 10

Usage

icd10_cod_neonate

Format

A data frame with 2 columns and 42 rows:

Variable Description
code ICD 10 Cause of Death code
title Cause of death title

Source

https://www.icd10data.com/ICD10CM/Codes/Rules/Newborn_Codes

Examples

icd10_cod_neonate

Example death records dataset with ICD10 cause-of-death coding

Description

Example death records dataset with ICD10 cause-of-death coding

Usage

icd10_example

Format

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

Source

https://www.who.int/standards/classifications/classification-of-diseases/services/codedit-tool

Examples

icd10_example

Unlikely causes of death for ICD 10

Description

Unlikely causes of death for ICD 10

Usage

icd10_unlikely_cod

Format

A data frame with 2 columns and 424 rows:

Variable Description
code ICD 10 Cause of Death code
title Cause of death title

Source

https://icd.who.int/browse10/Content/statichtml/ICD10Volume2_en_2019.pdf

Examples

icd10_unlikely_cod

Sex-specific causes of death for ICD 11

Description

Sex-specific causes of death for ICD 11

Usage

icd11_cod_by_sex

Format

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

Source

https://icdcdn.who.int/icd11referenceguide/en/html/index.html#list-of-categories-limited-to-or-more-likely-to-occur-in-female-persons

Examples

icd11_cod_by_sex

Child-specific cause-of-death for ICD 11

Description

Child-specific cause-of-death for ICD 11

Usage

icd11_cod_child

Format

A data frame with 2 columns and 149 rows:

Variable Description
code ICD 11 Cause of Death code
title Cause of death title

Examples

icd11_cod_child

Neonate-specific cause-of-death for ICD 11

Description

Neonate-specific cause-of-death for ICD 11

Usage

icd11_cod_neonate

Format

A data frame with 2 columns and 50 rows:

Variable Description
code ICD 11 Cause of Death code
title Cause of death title

Examples

icd11_cod_neonate

Example death records dataset with ICD11 cause-of-death coding

Description

Example death records dataset with ICD11 cause-of-death coding

Usage

icd11_example

Format

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

Source

https://www.who.int/standards/classifications/classification-of-diseases/services/codedit-tool

Examples

icd11_example

Unlikely causes of death for ICD 11

Description

Unlikely causes of death for ICD 11

Usage

icd11_unlikely_cod

Format

A data frame with 2 columns and 269 rows:

Variable Description
code ICD 11 Cause of Death code
title Cause of death title

Source

https://icd.who.int/valuesets/viewer/582/en

Examples

icd11_unlikely_cod

List ill-defined ICD 11 codes

Description

List ill-defined ICD 11 codes

Usage

list_ill_defined_icd11()

Value

An character vector of ICD 11 codes classified as ill-defined for cause-of-death

Examples

list_ill_defined_icd11()