pretestcad

An R package for Pretest Probability
for Coronary Artery Disease


Jeremy Selva

@JauntyJJS
https://jeremy-selva.netlify.app

For R/Medicine 2025

13 June 2025

Hex Sticker of pretestcad. R/Medicine 2025 Logo.

whoami

Research Officer from National Heart Centre Singapore who collects, cleans and harmonises clinical data.

Picture by Allison Horst about a data analyst facing a dataset in the form of a monster.

Taming the Data Beast from “Cleaning Medical Data with R” workshop by Shannon Pileggi, Crystal Lewis and Peter Higgins presented at R/Medicine 2023. Illustrated by Allison Horst.

What is Coronary Artery Disease (CAD) ?

Coronary Artery Disease (CAD) happens when the coronary arteries from the heart become narrow or blocked by fatty deposits called plaque. This can lead to chest pain, shortness of breath or even heart attack.

Picture showing coronary arteries from the heart become narrow or blocked by fatty deposits called plaque.

Coronary Artery Disease for health education Infographic designed by brgfx from Freepik.

What is Coronary Artery Disease (CAD) ?

Diagnosis of CAD includes invasive coronary angiography (right), or computerized tomography coronary angiogram (left).

Early detection and treatment of CAD can help improve the patient’s outcome.

Picture showing diagnosis of Coronary Artery Disease via computerized tomography coronary angiogram on the left and invasive coronary angiography on the right.

Images from Latina et al. Radiology: Cardiothoracic Imaging 2021; 3(4):e210053 doi: 10.1148/ryct.2021210053.

What is Pretest Probability ?

Pretest probability is the estimated probability, given a set of risk factors, that a patient has a specific disease or condition before any diagnostic tests are performed.

It helps clinicians and doctors makes informed decision on which patients go for diagnostic tests, especially if the diagnostic test is expensive, invasive or time consuming to the patient.

European Society of Cardiology (ESC) 2024 guidelines of first-line testing in symptomatic individuals with suspected chronic coronary syndrome.

European Society of Cardiology (ESC) 2024 guidelines of first-line testing in symptomatic individuals with suspected chronic coronary syndrome.

Pretest Probability Calculation

Pretest probability of CAD may be presented in the form of a table or an online calculator where we calculate the probability for each patients.

European Society of Cardiology (ESC) 2019 pretest probability for CAD table.

Table from Knuuti et al. Herz 2020; 45:409-420 doi: 10.1007/s00059-020-04935-x.

Online calculator to calculate pretest probability for CAD using the CAD Consortium cohort.

Online calculator from CAD Consortium.

Motivation

Tables are getting more complicated as more risk factors are used to calculate.

ESC 2019 Guidelines

European Society of Cardiology (ESC) 2019 pretest probability for CAD table.

Table from Knuuti et al. Herz 2020; 45:409-420 doi: 10.1007/s00059-020-04935-x.

ESC 2024 Guidelines

European Society of Cardiology (ESC) 2024 pretest probability for CAD table.

Workflow from Vrints et al. European Heart journal 2024; 45(36):3415-3537 doi: 10.1093/eurheartj/ehae177.

Motivation

As pretest models changes with time, it becomes tedious to calculate and update pretest probability one patient at a time.

Motivation

There are many R packages for calculating risk for cardiovascular disease (CVD).

Why not create one for CAD ?

R packages preventr, RiskScorecvd and globorisk to calculate risk of cardiovascular disease.

R packages preventr, RiskScorecvd and globorisk to calculate risk of CVD.

pretestcad

https://jauntyjjs.github.io/pretestcad/

Features of pretestcad

# 30 female with symptom score of 3 and 0 risk factors
calculate_esc_2024_fig_4_ptp(
  age = 30,
  sex = "female",
  chest_pain_type = "typical",
  have_dyspnoea = "no",
  have_family_history = "no",
  have_smoking_history = "no",
  have_dyslipidemia = "no",
  have_hypertension = "no",
  have_diabetes = "no",
  output = "percentage"
)
[1] "2%"
ESC 2024 pretest probability of CAD table.

ESC 2024 guidelines from Vrints et al. European Heart journal 2024; 45(36):3415-3537 doi: 10.1093/eurheartj/ehae177.

Features of pretestcad

# 55 male with symptom score of 3 and 3 risk factors and 2 NA
calculate_esc_2024_fig_4_ptp(
  age = 55,
  sex = "male",
  chest_pain_type = "typical",
  have_dyspnoea = "no",
  have_family_history = NA,
  have_smoking_history = NA,
  have_dyslipidemia = "yes",
  have_hypertension = "yes",
  have_diabetes = "yes",
  max_na_num_of_rf = 2,
  output = "percentage"
)
[1] "27%"
ESC 2024 pretest probability of CAD table.

ESC 2024 guidelines from Vrints et al. European Heart journal 2024; 45(36):3415-3537 doi: 10.1093/eurheartj/ehae177.

Features of pretestcad

patient_data <- tibble::tribble(
    ~unique_id,
    ~age,     ~sex, 
    ~chest_pain_type, ~have_dyspnoea, 
    ~have_family_history, ~have_smoking_history, ~have_dyslipidemia, ~have_hypertension, ~have_diabetes,
    "45 year old male with typical chest pain, no dyspnoea, hypertension and diabetes",
    45, "male", 
    "typical", "no",  
    "no", "no", "no", "yes", "yes",
    "70 year old female with no chest pain, dyspnoea, have smoking history (past or current smoker) and dyslipidemia",
    70, "female", 
    "no chest pain", "yes",  
    "no", "yes", "yes", "no", "no"
)

risk_data <- patient_data |>
    dplyr::mutate(
      esc_2024_ptp_percent = purrr::pmap_chr(
        .l = list(
          age = .data[["age"]],
          sex = .data[["sex"]],
          chest_pain_type = .data[["chest_pain_type"]],
          have_dyspnoea = .data[["have_dyspnoea"]],
          have_family_history = .data[["have_family_history"]],
          have_smoking_history = .data[["have_smoking_history"]],
          have_dyslipidemia = .data[["have_dyslipidemia"]],
          have_hypertension = .data[["have_hypertension"]],
          have_diabetes = .data[["have_diabetes"]],
          output = "percentage"
        ),
        .f = pretestcad::calculate_esc_2024_fig_4_ptp
      )
    ) |> 
   dplyr::select(
      c("unique_id", "esc_2024_ptp_percent")
   )

print(risk_data)
# A tibble: 2 × 2
  unique_id                                                 esc_2024_ptp_percent
  <chr>                                                     <chr>               
1 45 year old male with typical chest pain, no dyspnoea, h… 20%                 
2 70 year old female with no chest pain, dyspnoea, have sm… 10%                 

Features of pretestcad

Applied this talk from useR! 2024 to write better error messages.

calculate_esc_2024_fig_4_ptp(
  age = 0,
  sex = "male",
  chest_pain_type = "typical",
  have_dyspnoea = "no",
  have_family_history = "no",
  have_smoking_history = "no",
  have_dyslipidemia = "yes",
  have_hypertension = "yes",
  have_diabetes = "yes",
  output = "percentage"
)
Error in `calculate_esc_2024_fig_4_ptp_simplfied()`:
! `age` must be positive, not 0
calculate_esc_2024_fig_4_ptp(
  age = 50,
  sex = "ale",
  chest_pain_type = "typical",
  have_dyspnoea = "no",
  have_family_history = "no",
  have_smoking_history = "no",
  have_dyslipidemia = "yes",
  have_hypertension = "yes",
  have_diabetes = "yes",
  output = "percentage"
)
Error in `calculate_esc_2024_fig_4_ptp_simplfied()`:
! `sex` must be one of "female" or "male", not "ale".
ℹ Did you mean "male"?

Conclusion

Pretest probability for CAD is useful in patient management to ensure high-risk patients are diagnosed and treated early.

While there are many R packages developed to calculate risk of cardiovascular disease, there is currently no R package dedicated for calculating pretest probability for CAD.

R package pretestcad helps to ensure that these values can be calculated efficiently as number of patient increase and pretest probability models evolved over time.

Hex Sticker of pretestcad.

Thank you

Available on CRAN, RUniverse and Github.

Comic howing too many bugs to fix during first day of release.

Great Expectations from MonkeyUser.com