Skip to contents

This simulation method assumes only that the model system can be written as a piecewise-linear ordinary differential equation system.

Usage

simulate_serosurvey_general_model(
  construct_A_fn,
  calculate_seropositivity_function,
  initial_conditions,
  survey_features,
  ...
)

Arguments

construct_A_fn

A function that constructs a matrix that defines the multiplier term in the linear ODE system.

calculate_seropositivity_function

A function which takes the state vector and returns the seropositive fraction.

initial_conditions

The initial state vector proportions for each birth cohort.

survey_features

A dataframe containing information about the binned age groups and sample sizes for each. It should contain columns: 'age_min', 'age_max', 'n_sample'.

...

Additional parameters for sum_of_A

Value

A dataframe with simulated serosurvey data, including age group information, overall sample sizes, the number of seropositive individuals, and other survey features.

Examples

foi_df_time <- data.frame(
  year = seq(1946, 2025, 1),
  foi = c(rep(0, 40), rep(1, 40))
)

foi_df_age <- data.frame(
  age = 1:80,
  foi = 2 * dlnorm(1:80, meanlog = 3.5, sdlog = 0.5)
)

# generate age and time dependent FOI from multipliers
foi_age_time <- expand.grid(
  year = foi_df_time$year,
  age = foi_df_age$age
) |>
  dplyr::left_join(foi_df_age, by = "age") |>
  dplyr::rename(foi_age = foi) |>
  dplyr::left_join(foi_df_time, by = "year") |>
  dplyr::rename(foi_time = foi) |>
  dplyr::mutate(foi = foi_age * foi_time) |>
  dplyr::select(-c("foi_age", "foi_time"))

# create survey features for simulating
max_age <- 80
n_sample <- 50
survey_features <- data.frame(
  age_min = seq(1, max_age, 5),
  age_max = seq(5, max_age, 5)) |>
  dplyr::mutate(n_sample = rep(n_sample, length(age_min))
  )

# simulate survey from age and time FOI
serosurvey <- simulate_serosurvey(
  model = "age-time",
  foi = foi_age_time,
  survey_features = survey_features
)