Simulate a cross-sectional serosurvey with noise

Description

Makes a cross-sectional data set (age, y(t) set) and adds noise, if desired.

Usage

sim_pop_data_2(
  lambda = 0.1,
  n_samples = 100,
  age_range = c(0, 20),
  age_fixed = NA,
  antigen_isos = intersect(get_biomarker_levels(curve_params), rownames(noise_limits)),
  n_mcmc_samples = 0,
  renew_params = FALSE,
  add_noise = FALSE,
  curve_params,
  noise_limits,
  format = "wide",
  verbose = FALSE,
  ...
)

Arguments

lambda a numeric() scalar indicating the incidence rate (in events per person-years)
n_samples number of samples to simulate
age_range age range of sampled individuals, in years
age_fixed specify the curve parameters to use by age (does nothing at present?)
antigen_isos Character vector with one or more antibody names. Values must match curve_params.
n_mcmc_samples not yet implemented for this function (MCMC iterations are always sampled at random, unlike sim_pop_data()); kept for API compatibility with sim_pop_data_multi()’s sim_function argument
renew_params not yet implemented for this function (curve parameters are always resampled independently for each simulated individual, unlike sim_pop_data()); kept for API compatibility with sim_pop_data_multi()’s sim_function argument
add_noise a logical() indicating whether to add biological and measurement noise
curve_params

a data.frame() containing MCMC samples of parameters from the Bayesian posterior distribution of a longitudinal decay curve model. The parameter columns must be named:

  • antigen_iso: a character() vector indicating antigen-isotype combinations

  • iter: an integer() vector indicating MCMC sampling iterations

  • y0: baseline antibody level at $t=0$ ($y(t=0)$)

  • y1: antibody peak level (ELISA units)

  • t1: duration of infection

  • alpha: antibody decay rate (1/days for the current longitudinal parameter sets)

  • r: shape factor of antibody decay

noise_limits biologic noise distribution parameters
format

a character() variable, containing either:

  • “long” (one measurement per row) or

  • “wide” (one serum sample per row)

verbose logical: if TRUE, print verbose log information to console
additional arguments passed to other functions (not currently used).

Value

a tibble::tbl_df containing simulated cross-sectional serosurvey data, with columns:

  • age: age (in years)

  • one column for each element in the antigen_iso input argument

Examples

Code
library("serocalculator")

# Load curve parameters
dmcmc <- typhoid_curves_nostrat_100

# Specify the antibody-isotype responses to include in analyses
antibodies <- c("HlyE_IgA", "HlyE_IgG")

# Set seed to reproduce results
set.seed(54321)

# Simulated incidence rate per person-year
lambda <- 0.2
# Range covered in simulations
lifespan <- c(0, 10)
# Cross-sectional sample size
nrep <- 100

# Biologic noise distribution
dlims <- rbind(
  "HlyE_IgA" = c(min = 0, max = 0.5),
  "HlyE_IgG" = c(min = 0, max = 0.5)
)

# Generate cross-sectional data
csdata <- sim_pop_data_2(
  curve_params = dmcmc,
  lambda = lambda,
  n_samples = nrep,
  age_range = lifespan,
  antigen_isos = antibodies,
  n_mcmc_samples = 0,
  renew_params = TRUE,
  add_noise = TRUE,
  noise_limits = dlims,
  format = "long"
)