early_warning_biomarker: Early Warning for Biomarkers

View source: R/early_warning.R

early_warning_biomarkerR Documentation

Early Warning for Biomarkers

Description

The early_warning_biomarker function is designed to detect unexpected changes in biomarker values for individual patients based on clinical chemistry data. It will flag cases where patients' biomarker results deviate from defined thresholds or exhibit significant changes within a specified time window.

Usage

early_warning_biomarker(
  df,
  testcode = NULL,
  ...,
  column_date = NULL,
  column_patientid = NULL,
  column_testcode = NULL,
  column_testresult = NULL,
  threshold_min = NULL,
  threshold_max = NULL,
  window_days = NULL,
  max_delta_absolute = NULL,
  max_delta_relative = NULL,
  direction = "any"
)

Arguments

df

A data frame containing clinical chemistry data with columns for patient ID, date, test code, and test result.

testcode

Value of the column containing test codes to filter on.

...

Filter arguments, e.g. testcode == "eGFR"

column_date

Name of the column to use for dates. If left blank, the first date column will be used.

column_patientid

Name of the column to use for patient IDs. If left blank, the first column resembling "patient|patid" will be used.

column_testcode

Name of the column containing test codes.

column_testresult

Name of the column containing test results.

threshold_min

Minimum threshold for biomarkers.

threshold_max

Maximum threshold for biomarkers.

window_days

Number of days for the time window to check for changes.

max_delta_absolute

Maximum allowable absolute change in biomarkers.

max_delta_relative

Maximum allowable relative change in biomarkers.

direction

Direction of change to check ("up", "down", or "any").

Details

This whole function, including the documentation, was written by ChatGPT 3.5 in October 2023. Only minor changes were applied manually.

This function is particularly useful in early detection of anomalous biomarker results, which can be indicative of health issues or treatment response. By providing detailed flags, it allows healthcare professionals and researchers to take timely action, conduct further investigations, or make informed clinical decisions.

The output of this function can be utilised for:

  • Generating patient-specific reports for healthcare providers.

  • Identifying trends and patterns in biomarker changes for research purposes.

  • Enhancing patient care by enabling proactive interventions when necessary.

  • Supporting data-driven clinical epidemiology studies and research.

The format() function allows you to format the results of the early_warning_biomarker() function for better readability and analysis. It organises the flag information into a structured data frame for easier inspection.

Value

A list with the following components:

  • flags: A list of flags per patient, containing data frames for each patient with details on dates, test codes, test results, and flagging criteria. The structure of each data frame includes the following columns:

    • patient: Patient identifier.

    • date: Date of the biomarker measurement.

    • testcode: Code of the biomarker test.

    • testresult: Biomarker test result.

    • delta_absolute: Absolute change in biomarker values.

    • delta_relative: Relative change in biomarker values.

    • threshold_min_flag: A logical flag indicating if the threshold minimum is exceeded.

    • threshold_max_flag: A logical flag indicating if the threshold maximum is exceeded.

    • delta_absolute_flag: A logical flag indicating if the absolute change exceeds the threshold.

    • delta_relative_flag: A logical flag indicating if the relative change exceeds the threshold.

  • details: A data frame containing all patient details and calculated flags, regardless of whether they meet the flagging criteria. The data frame includes the same columns as the individual patient data frames.

See Also

early_warning_cluster()

Examples

data <- data.frame(date = Sys.Date() + 1:10,
                   patient = "test",
                   value = c(10,12,14,15,13,21,22,19,14,12))

check <- data |> early_warning_biomarker(window_days = 6, max_delta_absolute = 10)

check

unlist(check)

certe-medical-epidemiology/certestats documentation built on Nov. 9, 2024, 8:15 p.m.