Skip to contents

Introduction

PERiskProfileR is an R package designed to calculate preeclampsia risk scores based on first-trimester parameters using the Fetal Medicine Foundation (FMF) algorithm. The package provides both local implementation of the risk calculations and an interface to the online FMF calculator.

Installation

You can install PERiskProfileR from GitHub using devtools:

if (!requireNamespace("devtools", quietly = TRUE))
    install.packages("devtools")
devtools::install_github("andjar/PERiskProfileR", ref = "main")

Demo data

Your data set must adhere to the following standards to be processed. Please see: Data Specifications

For simplicity, the package includes a demo data set that can be loaded as follows:

demo_data <- get_demo_data()

This data set can act as a template to see ow your data should be structured.

Local Risk Calculation

Your data set must adhere to the following standards to be processed. Please see: Data specification

Getting MoMs (Multiples of Median)

The package calculates MoM values for key biomarkers:

# Convert a data row to parameter list
params <- row_to_list(demo_data[1,])

# Calculate MoMs for individual markers
mom_map <- get_mom_map(params)
mom_utpi <- get_mom_utpi(params)
mom_plgf <- get_mom_plgf(params)

print(c(MAP_MoM = mom_map, UtPI_MoM = mom_utpi, PlGF_MoM = mom_plgf))

Getting Risk Scores

Calculate preeclampsia risk using the formula-based method:

# Calculate risk for a single patient
risk_results <- calculate_formula_risk(params, G = 37)
print(risk_results)

# Calculate risk for multiple patients
results_df <- calculate_pe_risk(
  demo_data,
  method = "formula",
  report_as_text = FALSE,
  G = 37
)
head(results_df[, c("risk_prior", "risk")])

The risk scores are returned as:

  • risk_prior: Background risk based on maternal characteristics

  • risk: Final risk incorporating biomarker measurements

Online Risk Calculation

Your data set must adhere to the following standards to be processed. Please see: Data specification

The package can also submit data to the FMF online calculator:

# Calculate risk using online calculator
online_results <- calculate_pe_risk(
  demo_data,
  method = "online",
  save_responses = TRUE,
  response_dir = "calculator_responses"
)

Saving and Reading HTML Files

For documentation and retrieval, the package can save the FMF calculator response pages:

# Extract risk scores from saved HTML files
saved_results <- extract_risk_scores_from_files(
  response_dir = "calculator_responses",
  report_as_text = FALSE
)

The saved HTML files contain:

  • Original input data

  • Calculated MoM values

  • Prior and final risk scores

  • Additional details about the calculations

Comparing Online and Local Results

You can compare results from both methods:

# Calculate risks using both methods
formula_results <- calculate_pe_risk(demo_data, method = "formula")
online_results <- calculate_pe_risk(demo_data, method = "online")

# Compare risk scores
comparison <- data.frame(
  Formula_Risk = formula_results$risk,
  Online_Risk = online_results$risk
)
print(comparison)

Important Notes

  1. This package is NOT intended for clinical use. All risk calculations should be verified using official clinical tools.

  2. The online calculator requires internet connectivity and may be subject to rate limiting or access restrictions. Note that data will be sent to an external server.

  3. Always validate the results and ensure the input data meets the expected format and ranges.

References

The package implements the algorithm described in:

  • Tan MY, et al. Screening for pre-eclampsia by maternal factors and biomarkers at 11-13 weeks’ gestation. Ultrasound Obstet Gynecol. 2018;52:186-195.