R/SeroCOPCompare.R
SeroCOPCompare.RdAn R6 class that fits independent univariate models for each biomarker and compares their performance. It does not fit a joint multidimensional model. Supports hierarchical modeling with group-level effects for each biomarker.
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). Column i is passed to the ith biomarker model.
new()Create a new SeroCOPCompare object
SeroCOPCompare$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 (rows = observations, cols = biomarkers).
Column i is used as the per-observation weights for biomarker i,
multiplying each observation's log-likelihood contribution in the Stan model.
A single vector of length nrow(titre) is also accepted and is broadcast
across all biomarkers. If NULL (the default) all observations receive
equal weight.
fit_all()Fit models for all biomarkers
SeroCOPCompare$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
comparison_model <- SeroCOPCompare$new(titre = titres, infected = infected)
comparison_model$fit_all(chains = 4, iter = 2000)
# Compare biomarkers
comparison_model$compare_biomarkers()
comparison_model$plot_comparison()
# With hierarchical effects
age_group <- sample(c("Young", "Middle", "Old"), 200, replace = TRUE)
hier_model <- SeroCOPCompare$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()
} # }