Simulate x and y values for samples and calibrators across different plates

simulate_data(
  seed = NA,
  num_plate = 10,
  num_sam_per_plate = 40,
  num_rep_per_sam = 2,
  num_rep_per_cal = 2,
  x_cals = c(0, 0.37, 1.1, 3.3, 10, 30),
  y_obs_sd_cal_min = 0.003,
  y_obs_sd_cal_jump = 0.242,
  y_obs_sd_sam_min = 0.004,
  y_obs_sd_sam_jump = 0.718,
  mu_neg = -2.7,
  sd_neg = 1,
  mu_pos = 0.7,
  sd_pos = 1,
  p_pos = 0.5,
  p_blank = 0,
  f = c(0.95, 0.01, 3.33, 2.44),
  sigma_f_plate = c(0.073, 0.004, 0.704, 0.404),
  rho = matrix(c(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), 4, 4, byrow = TRUE),
  f_pred_vars = list(),
  sigma_f_pred_vars = list(),
  x_mix_pred_vars = list(p_pos = list(letter = letters[1:4]), mu_neg = list(letter =
    letters[1:4]), mu_pos = list(letter = letters[1:4]), sd_neg = list(letter =
    letters[1:4]), sd_pos = list(letter = letters[1:4])),
  x_mix_pred_vars_sds = list(p_pos = c(letter = 1), mu_neg = c(letter = 1), mu_pos =
    c(letter = 1), sd_neg = c(letter = 0.2), sd_pos = c(letter = 0.2)),
  x_mix_effects = NA,
  p_pos_binary_effects = c(boolA = -2, boolB = 0, boolC = 2),
  y_obs_sd_min_log_shift_sd = 0,
  y_obs_sd_jump_log_shift_sd = 0
)

Arguments

seed

seed used for random number generation (if no seed is provided, none is used)

num_plate

number of plates

num_sam_per_plate

number of samples per plate

num_rep_per_sam

number of replicates per sample

num_rep_per_cal

number of replicates per calibrator

x_cals

the x values of the set of calibrators on each plate

y_obs_sd_cal_min

the limit, as x tends to zero, of the scale of stochastic observational noise in y for calibrators

y_obs_sd_cal_jump

the difference between the lower and upper limits, as x tends to zero and infinity, of the scale of stochastic observational noise in y for calibrators

y_obs_sd_sam_min

the limit, as x tends to zero, of the scale of stochastic observational noise in y for samples

y_obs_sd_sam_jump

the difference between the lower and upper limits, as x tends to zero and infinity, of the scale of stochastic observational noise in y for samples

mu_neg

the population mean log_e(x) for seronegatives

sd_neg

the standard deviation of the population distribution of log_e(x) for seronegatives

mu_pos

the population mean log_e(x) for seropositives

sd_pos

the standard deviation of the population distribution of log_e(x) for seropositives

p_pos

the probability of a sample being seropositive (i.e. seroprevalence) before addition of subpopulation-specific deviations

p_blank

the probability that any given sample replicate is an accidental blank. Beware: in the main dvsb inference model this is assumed to be zero, so values greater than zero introduce model misspecification for inference. The dvsb_accidental_blanks inference model does not assume p_blank is zero.

f

a vector with the four parameters of the four-parameter logistic (4PL) function that link log_e(x) to the expected value of y through y = f_2 + (f_3 - f_2) / (1 + exp(-f_1 * (log_e(x) - f_4)))

sigma_f_plate

a vector with the four scales of normal variability between plates of the four elements of the f vector

rho

4x4 correlation matrix for the variability between plates of the four elements of the f vector

f_pred_vars

a list (whose names are the names of categorical variables) of character vectors (whose values are the different categories of a given categorical variable). Each plate has one category randomly allocated for each categorical variable. Categories differ systematically in their f vector (in addition to the random variability between plates).

sigma_f_pred_vars

a list (whose names are the names of categorical variables, matching those of f_pred_vars) of length-4 numeric vectors. Each of these vectors specifies the scales of normal variability in the f vector between different categories of the corresponding categorical variable.

x_mix_pred_vars

a list (whose names are the parameters p_pos, mu_neg, mu_pos, sd_neg, sd_pos) of lists (whose names are the names of categorical variables) of character vectors (whose values are the different categories of a given categorical variable). Each parameter has a regression model specified by additively combining its categorical variables. For each categorical variable, each sample has one of the categories randomly allocated.

x_mix_pred_vars_sds

a list (whose names are the parameters p_pos, mu_neg, mu_pos, sd_neg, sd_pos) of named numeric vectors (whose names must match the categorical variables named in the inner lists of x_mix_pred_vars). Each {name, numeric value} pair within one of these vectors specifies the scale of variability between the regression coefficients for the different categories of named categorical variable.

x_mix_effects

Normally you will want to leave this at its default value of NA, in which case we will randomly draw regression coefficients for the parameters of the regression model for the x distribution according to the values specified in x_mix_pred_vars_sds. Alternatively, this argument can be used to specify values for all these coefficients; this may be useful to keep them fixed over several different simulations of a dataset, e.g. with different stochastic seeds, to compare inference with these random effects fixed. If used, this argument should be a list (whose names are the x mixture parameters p_pos, mu_neg, mu_pos, sd_neg, sd_pos) of lists (whose names match those of the same parameter in x_mix_pred_vars) of named numeric vectors (one per categorical variable used in a regression model for this parameter; the names, one per category of this variable, must match those for the variable as specified in x_mix_pred_vars).

p_pos_binary_effects

a named numeric vector. Each {name, numeric value} pair within this vector specifies the name of a logical variable and the additive shift in seroprevalence (on a logit scale) between when this variable is true and when it is false. Each sample will be randomly allocated a value of true or false for each such variable.

y_obs_sd_min_log_shift_sd

the standard deviation (on a log scale) of the multiplicative variability in both y_obs_sd_cal_min and y_obs_sd_sam_min between plates. Beware: such variability is assumed to be zero in the inference model, so values greater than the default of zero will introduce model misspecification for inference (which may be of interest for testing purposes).

y_obs_sd_jump_log_shift_sd

the standard deviation (on a log scale) of the multiplicative variability in both y_obs_sd_cal_jump and y_obs_sd_sam_jump between plates. Beware: such variability is assumed to be zero in the inference model, so values greater than the default of zero will introduce model misspecification for inference (which may be of interest for testing purposes).

Value

a named list whose elements are:

  • df_sam, a dataframe with one row per simulated sample replicate;

  • df_plate, a dataframe with one row per simulated plate;

  • df_cal, a dataframe with one row per simulated calibrator replicate;

  • params, a list of the values of parameters used for simulation;

  • f_pred_vars_names, a character vector of the names of any variables used for a regression model for the four vector f;

  • x_mix_pred_vars_names, a named list whose names are the five parameters of the normal mixture model for x, each of the elements being a character vector naming the variables used in a regression model for that parameter;

  • p_pos_binary_pred_vars, a character vector of the names of any variables used for a regression model for p_pos, using only binary fixed effects.