overall_simulation: Serosurvey simulation function

Description Usage Arguments Value See Also Examples

View source: R/model.R

Description

Simulates readings from a generic serosurvey. The function can take pointers to any data generating function and noise adding function to generate values generated from a custom process. A number of bools and parameters can be passed to customise the protocol.

Usage

1
2
3
4
5
overall_simulation(individuals = 100, strains = c("H3N2", "H5N1", "H1N1"),
  strainIncidences, samplingTimes, processParams, y0s, startTime = 0,
  endTime = 200, addNoise = TRUE, noiseParams = c(0.79, 0.2, 8),
  discreteData = TRUE, PROCESS_FUNCTION = multiple_strains,
  NOISE_FUNCTION = add_noise_func, MIXED_EFFECTS = TRUE)

Arguments

individuals

number of individuals to simulate. Defaults to 100

strains

a vector of virus strain names to label the simulation data

strainIncidences

a list of incidence vectors. Should match length of the strains vector (ie. each circulating strain has an incidence vector. Note that the range of these vectors should cover the entire study period. ie. go from 0 (the day of the first sample) to x (the day of the last sample).

processParams

a generic vector of parameters to be passed to the data generating function. If using mixed effects, should also provide the distributions/parameters of the population parameters

y0s

baseline readings for each individual. May simply be a matrix of zeroes.

startTime

the start time of the survey. Defaults to 0

endTime

the end time of the survey. Defaults to 200 (ie. 200 days)

addNoise

if true, adds noise to the simulated data

noiseParams

generic vector of parameters to pass to the noise generating function. Defaults to match add_noise

discreteData

if TRUE, takes the floor of all generated data. Defaults to TRUE.

PROCESS_FUNCTION

a pointer to the data generating process, taking the processParams as an argument. The function should take the following arguments: "infection_times" - a vector of times of infection with each strain; "y0" - a vector of initial values for each strain; processParams - as above; t - vector of times. This function should return a matrix of serological values matching the simulation data type. The first column should be time in days, and each subsequent column should be the measurement for each strain of interest on that day. See multiple_strains for an example.

NOISE_FUNCTION

pointer to a noise adding function. Should take the value to be manipulated and a vector of function specific parameters (noiseParams). See add_noise for an example.

MIXED_EFFECTS

bool to indicate whether or not mixed effects should be used

logTitre

if TRUE, returns log transformed titre values. (5*2^y). This might be specific to HAI titre data, so might be best left to default as FALSE.

Value

a dataframe of the simulated serosurvey.

See Also

individual_simulation

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
n <- 1000

inc_vectors <- NULL
inc_vectors[[1]] <- generate_toy_inc(0.4,900,200,600)
inc_vectors[[2]] <- generate_toy_inc(0.1,900,500,750)

samplingTimes <- matrix(ncol=2, nrow=n)
samplingTimes[,1] <- 0
samplingTimes[,2] <- 150

y0s <- matrix(ncol=2,nrow=n)
y0s[,1] <- 0
y0s[,2] <- 0

processParams <- list(mu_pars, tp_pars, m_pars)

y <- overall_simulation(n, c("A","B"), inc_vectors, samplingTimes, processParams, y0s, 0, 200, TRUE, c(0.8,0.1),TRUE,TRUE,multiple_strains, add_noise)
ERROR CHECKS
Create the matrix to store the data
Row for each individual
One column for each time point for each strain; one column for each time point.
Generate a cumulative risk of infection vector for each strain    
For each strain, generate a cumulative incidence vector
For each individual, generate an infection time for each strain and simulate
Generate an infection time for each strain. Make sure that no two infections can occur within 21 days of each other
If data is discrete, take floor of matrix
Add noise and log transform if required
First column in times

jameshay218/serosim2 documentation built on May 18, 2019, 11:21 a.m.