seroCOP is an R package for analysing correlates of protection using Bayesian methods. It fits generalized four-parameter logistic functions to antibody titre and infection outcome data using Stan, providing comprehensive model diagnostics and performance metrics.
You can install the development version of seroCOP from GitHub:
# Install devtools if needed
install.packages("devtools")
# Install seroCOP
devtools::install_github("seroanalytics/seroCOP")Note: This package requires a working installation of brms and Stan. The brms package will handle Stan installation automatically when you first use it.
library(seroCOP)
# Simulate data
sim_data <- simulate_serocop_data(
n = 200,
floor = 0.05,
ceiling = 0.90,
ec50 = 1.5,
slope = 2.0,
seed = 123
)
# Create SeroCOP object
model <- SeroCOP$new(
titre = sim_data$titre,
infected = sim_data$infected
)
# Fit the model (uses brms with sensible defaults)
model$fit_model(chains = 4, iter = 2000)
# Get performance metrics
metrics <- model$get_metrics()
# Visualize results
model$plot_curve()
model$plot_roc()
# Extract parameter estimates
model$summary()Model group-level heterogeneity (e.g., age groups with different correlates):
# Simulate age-stratified data
age_group <- sample(c("Young", "Middle", "Old"), 200, replace = TRUE)
# Fit hierarchical model
hier_model <- SeroCOP$new(
titre = sim_data$titre,
infected = sim_data$infected,
group = age_group # Adds random effects on slope and ec50
)
hier_model$fit_model(chains = 4, iter = 2000)
# Extract group-specific parameters
group_params <- hier_model$extract_group_parameters()
# Plot group-specific curves
hier_model$plot_group_curves()Compare multiple biomarkers simultaneously with optional hierarchical effects:
# Prepare multi-biomarker data (matrix with columns = biomarkers)
titre_matrix <- cbind(
IgG = rnorm(200, 2, 1),
IgA = rnorm(200, 1.5, 1),
Neutralization = rnorm(200, 3, 1.2)
)
# Initialize and fit (without groups)
multi_model <- SeroCOPMulti$new(
titre = titre_matrix,
infected = infected
)
multi_model$fit_all(chains = 4, iter = 2000)
# Compare biomarkers
multi_model$compare_biomarkers()
multi_model$plot_comparison() # AUC vs LOO-ELPD plot
multi_model$plot_all_curves()
# With hierarchical effects across biomarkers
hier_multi <- SeroCOPMulti$new(
titre = titre_matrix,
infected = infected,
group = age_group
)
hier_multi$fit_all(chains = 4, iter = 2000)
hier_multi$plot_group_curves() # Shows all biomarkers × groups
hier_multi$extract_group_parameters()The package fits a four-parameter logistic model using brms (Bayesian Regression Models using Stan):
Where: - floor: Lower asymptote (baseline infection probability at high titres) - ceiling: Upper asymptote (maximum infection probability at low titres)
- ec50: Titre at 50% between floor and ceiling (inflection point) - slope: Steepness of the dose-response curve
The package automatically sets weakly informative priors based on your data:
See the package vignettes for detailed examples:
# View available vignettes
browseVignettes("seroCOP")The package calculates several performance metrics: