R/SeroCOPMulti.R
SeroCOPMulti.RdAn R6 class for analyzing multiple biomarkers simultaneously. Fits separate models for each biomarker using brms and provides comparison tools. Supports hierarchical modeling with group-level effects.
titreMatrix of antibody titres (columns = biomarkers)
infectedBinary vector of infection status (0/1)
biomarker_namesNames of biomarkers
modelsList of fitted SeroCOP objects
groupOptional factor vector for hierarchical modeling
weightsOptional numeric matrix of observation weights (rows = observations, cols = biomarkers)
new()Create a new SeroCOPMulti object
SeroCOPMulti$new(
titre,
infected,
biomarker_names = NULL,
group = NULL,
weights = NULL
)titreMatrix of antibody titres (rows = samples, cols = biomarkers)
infectedBinary vector (0/1) of infection outcomes
biomarker_namesOptional vector of biomarker names
groupOptional grouping variable for hierarchical modeling
weightsOptional numeric matrix of non-negative observation weights with
the same dimensions as titre. Column i is passed as per-observation
weights for biomarker i, multiplying each observation's log-likelihood
contribution in the Stan model. A plain vector of length nrow(titre) is
also accepted and broadcast across all biomarkers.
If NULL (the default) all observations receive equal weight.
fit_all()Fit models for all biomarkers
SeroCOPMulti$fit_all(
chains = 4,
iter = 2000,
warmup = floor(iter/2),
cores = 1,
...
)extract_group_parameters()Extract group-specific parameters for all biomarkers (hierarchical models only)
extract_cop_multi()Extract the correlate of protection conditional on exposure for all biomarkers.
if (FALSE) { # \dontrun{
# Create multi-biomarker data
titres <- matrix(rnorm(600), ncol = 3)
colnames(titres) <- c("IgG", "IgA", "Neutralization")
infected <- rbinom(200, 1, 0.3)
# Initialize and fit
multi_model <- SeroCOPMulti$new(titre = titres, infected = infected)
multi_model$fit_all(chains = 4, iter = 2000)
# Compare biomarkers
multi_model$compare_biomarkers()
multi_model$plot_comparison()
# With hierarchical effects
age_group <- sample(c("Young", "Middle", "Old"), 200, replace = TRUE)
hier_model <- SeroCOPMulti$new(titre = titres, infected = infected, group = age_group)
hier_model$fit_all(chains = 4, iter = 2000)
hier_model$plot_group_curves()
hier_model$extract_group_parameters()
} # }