diff --git a/R/sim.cs.R b/R/sim.cs.R index 9582a82c..96e77d12 100644 --- a/R/sim.cs.R +++ b/R/sim.cs.R @@ -26,8 +26,7 @@ #' - `r`: shape factor of antibody decay #' @param predpar an [array()] containing MCMC samples from the Bayesian distribution of longitudinal decay curve model parameters. NOTE: most users should leave `predpar` at its default value and provide `curve_params` instead. -#' @param noise_limits noise distribution parameters -#' @param baseline_limits baseline noise distribution parameters +#' @param noise_limits biologic noise distribution parameters #' @param npar number of longitudinal curve parameters in model #' @param ... additional arguments passed to `simcs.tinf()` #' @return a [dplyr::tibble()] containing simulated cross-sectional serosurvey data, with columns: @@ -52,15 +51,18 @@ sim.cs <- function( prep_curve_params_for_array() %>% df_to_array(dim_var_names = c("antigen_iso", "parameter")), noise_limits, - baseline_limits, npar, ...) { stopifnot(length(lambda) == 1) + day2yr = 365.25 + ablist = 1:length(antigen_isos) + baseline_limits <- noise_limits + ysim <- simcs.tinf( lambda = lambda, n.smpl = n.smpl, @@ -86,6 +88,6 @@ sim.cs <- function( } colnames(ysim) <- c("age", antigen_isos) - return(ysim |> as_tibble()) + return(ysim |> as_tibble() %>% mutate(age = round(age/day2yr, 2))) } diff --git a/vignettes/articles/simulate_xsectionalData.Rmd b/vignettes/articles/simulate_xsectionalData.Rmd index 3334ecbb..602ce774 100644 --- a/vignettes/articles/simulate_xsectionalData.Rmd +++ b/vignettes/articles/simulate_xsectionalData.Rmd @@ -66,16 +66,13 @@ ab.nm <- rbind(c("HlyE","IgA"),c("HlyE","IgG")); # antibodies <- dmcmc$antigen_iso |> droplevels() |> levels() antibodies = c("HlyE_IgA", "HlyE_IgG") abs <- c(1,2); -age.fx <- NA; # age used for longitudinal model (fixed for now) -day2yr <- 365.25; lambda <- 0.2; # incidence (1/yr) npar <- 5; # y0, y1, t1, alpha, shape lifespan <- c(0,20); # range covered in simulations nrep <- 100; # cross-sectional sample size -dlims <- rbind(c(1e-2,5e-1),c(1e-2,5e-1)); # noise distribution -blims <- dlims; # baseline distribution +dlims <- rbind(c(1e-2,5e-1),c(1e-2,5e-1)); # biologic noise distribution csdata0 <- sim.cs( curve_params = dmcmc, @@ -88,12 +85,10 @@ csdata0 <- sim.cs( renew.params = TRUE, add.noise = TRUE, noise_limits = dlims, - baseline_limits = blims, npar = npar ) -csdata0[, 1] <- csdata0[, 1] / day2yr ``` @@ -126,7 +121,6 @@ sim.cl <- npar = npar ) - csdata[, 1] <- csdata[, 1] / day2yr csdata1 <- csdata %>% as.data.frame() %>% @@ -157,7 +151,7 @@ csdataL <- as.data.frame(csdata0) %>% est.incidence(csdataL %>% rename(y = value, a = age), - dmcmc, cond, antigen_isos = c("HlyE_IgA")) + dmcmc, cond, antigen_isos = c("HlyE_IgG", "HlyE_IgA")) ```