create_posterior_func | R Documentation |
Takes all of the input data/parameters and returns a function pointer. This function finds the posterior for a given set of input parameters (theta) and infection histories without needing to pass the data set back and forth. No example is provided for function_type=2, as this should only be called within serosolver
create_posterior_func(
par_tab,
antibody_data,
antigenic_map = NULL,
possible_exposure_times = NULL,
prior_version = 2,
solve_likelihood = TRUE,
age_mask = NULL,
measurement_bias = NULL,
n_alive = NULL,
function_type = 1,
antibody_level_before_infection = FALSE,
data_type = 1,
biomarker_groups_weights = 1,
start_level = "other",
start_level_randomize = FALSE,
demographics = NULL,
demographic_groups = NULL,
fixed_inf_hists = NULL,
verbose = FALSE,
...
)
par_tab |
the parameter table controlling information such as bounds, initial values etc. See |
antibody_data |
the data frame of data to be fitted. Must have columns: group (index of group); individual (integer ID of individual); samples (numeric time of sample taken); virus (numeric time of when the virus was circulating); biomarker_group (integer of the observation group type, using a unique value for each distinctive type of observation underpinned by the same generative model); titre (integer of titre value against the given virus at that sampling time). See |
antigenic_map |
(optional) a data frame of antigenic x and y coordinates. Must have column names: x_coord; y_coord; inf_times. See |
possible_exposure_times |
(optional) if no antigenic map is specified, this argument gives the vector of times at which individuals can be infected |
prior_version |
which infection history assumption version to use? See |
solve_likelihood |
usually set to TRUE. If FALSE, does not solve the likelihood and instead just samples/solves based on the model prior |
age_mask |
see |
measurement_bias |
if not NULL, then use these indices to specify which measurement bias parameter index corresponds to which time |
n_alive |
if not NULL, uses this as the number alive in a given year rather than calculating from the ages. This is needed if the number of alive individuals is known, but individual birth dates are not |
function_type |
integer specifying which version of this function to use. Specify 1 to give a posterior solving function; 2 to give the gibbs sampler for infection history proposals; otherwise just solves the titre model and returns predicted titres. NOTE that this is not the same as the attack rate prior argument, |
data_type |
integer or vector, with an entry for each unique data type in 'antibody_data'. Set to 1 for discrete data (e.g., fold dilution) or 2 for continuous (e.g., ELISA optical density). |
biomarker_groups_weights |
integer or vector, giving a factor to multiply the log-likelihood contribution of this data type towards the overall likelihood. |
start_level |
character, to tell the model how to treat initial antibody levels. This uses the observed data to either select starting values for each unique 'individual', 'biomarker_id' and 'biomarker_group' combination. See |
start_level_randomize |
if TRUE, and data is discretized, then sets the starting antibody level to a random value between floor(x) and floor(x) + 1. Does nothing if using continuous data. |
demographics |
if not NULL, then a tibble for each individual (1:n_indiv) giving demographic variable entries. Most importantly must include "birth" as the birth time. This is used if, for example, you have a stratification grouping in 'par_tab' |
verbose |
if TRUE, prints warning messages |
... |
other arguments to pass to the posterior solving function |
titre_before_infection |
TRUE/FALSE value. If TRUE, solves titre predictions, but gives the predicted titre at a given time point BEFORE any infection during that time occurs. |
a single function pointer that takes only pars and infection_histories as unnamed arguments. This function goes on to return a vector of posterior values for each individual
## Not run:
data(example_par_tab)
data(example_antibody_data)
data(example_antigenic_map)
data(example_inf_hist)
## Simple model solving code. Output matches entries of example_antibody_data
model_func <- create_posterior_func(example_par_tab, example_antibody_data, example_antigenic_map, function_type = 3)
y <- model_func(example_par_tab$values, example_inf_hist)
## Solve likelihood
par_tab <- example_par_tab[example_par_tab$names != "phi",]
likelihood_func <- create_posterior_func(par_tab, example_antibody_data, example_antigenic_map, function_type = 1, prior_version = 2)
liks <- likelihood_func(par_tab$values, example_inf_hist)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.