Calculate Pre-eclampsia Risk Scores
calculate_pe_risk.RdCalculates pre-eclampsia risk scores for patient data using either a formula-based method or by querying an online calculator. The function can process both individual and batch data, with support for parallel processing for large datasets.
Usage
calculate_pe_risk(
data,
id_column = "id",
method = c("formula", "online"),
report_as_text = FALSE,
G = 37,
save_responses = FALSE,
response_dir = "requests",
url = "https://fetalmedicine.org/research/assess/preeclampsia/First",
verbose = TRUE,
parallel = NA
)Arguments
- data
A data frame containing patient information and measurements
- id_column
Character string specifying the column name containing unique identifiers. If not present, sequential IDs will be generated. Default: "id"
- method
Character string specifying the calculation method to use. Must be either "formula" or "online". Default: "formula"
- report_as_text
Logical indicating whether to return risk scores as text rather than numeric values. Default: FALSE
- G
Numeric value specifying gestational age in weeks. Only used when method = "formula". Default: 37
- save_responses
Logical indicating whether to save responses from the online calculator. Only applicable when method = "online". Default: FALSE
- response_dir
Character string specifying the directory where responses should be saved if save_responses is TRUE. Default: "requests"
- url
Character string specifying the URL of the online calculator. Default: "https://fetalmedicine.org/research/assess/preeclampsia/First"
- verbose
Logical indicating whether to display progress messages. Default: TRUE
- parallel
Logical indicating whether to use parallel processing. If NA, parallel processing will be automatically enabled for datasets with more than 100 rows. Default: NA
Value
A data frame containing the original data with additional columns:
mom_MAP: Multiple of median for mean arterial pressure
mom_PI: Multiple of median for pulsatility index
mom_PlGF: Multiple of median for PlGF
risk_prior: Prior risk score
risk: Final calculated risk score
Details
The function supports two methods for calculating pre-eclampsia risk:
Formula-based calculation using local implementation
Online calculation using the Fetal Medicine Foundation calculator
For large datasets (>100 rows), parallel processing is automatically enabled unless explicitly disabled. The function will use all available cores minus one for parallel processing.
Examples
if (FALSE) { # \dontrun{
# Calculate risk using formula method
results <- calculate_pe_risk(patient_data, method = "formula")
# Calculate risk using online calculator and save responses
results <- calculate_pe_risk(
patient_data,
method = "online",
save_responses = TRUE,
response_dir = "pe_responses"
)
} # }