create_posterior_func: Posterior function pointer

View source: R/posteriors.R

create_posterior_funcR Documentation

Posterior function pointer


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 run_MCMC


  antigenic_map = NULL,
  strain_isolation_times = NULL,
  version = 1,
  solve_likelihood = TRUE,
  age_mask = NULL,
  measurement_indices_by_time = NULL,
  mu_indices = NULL,
  n_alive = NULL,
  function_type = 1,
  titre_before_infection = FALSE,
  data_type = 1,



the parameter table controlling information such as bounds, initial values etc. See example_par_tab


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); titre (integer of titre value against the given virus at that sampling time). See example_titre_dat


(optional) a data frame of antigenic x and y coordinates. Must have column names: x_coord; y_coord; inf_times. See example_antigenic_map


(optional) if no antigenic map is specified, this argument gives the vector of times at which individuals can be infected


which infection history assumption version to use? See describe_priors for options. Can be 1, 2, 3 or 4


usually set to TRUE. If FALSE, does not solve the likelihood and instead just samples/solves based on the model prior


see create_age_mask - a vector with one entry for each individual specifying the first epoch of circulation in which an individual could have been exposed


if not NULL, then use these indices to specify which measurement bias parameter index corresponds to which time


if not NULL, then use these indices to specify which boosting parameter index corresponds to which time


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


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, version!


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.


integer, currently accepting 1 or 2. Set to 1 for discretized, bounded data, or 2 for continuous, bounded data. Note that with 2, MIN_TITRE must be set.


other arguments to pass to the posterior solving function


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: 

## Simple model solving code. Output matches entries of example_titre_dat
model_func <- create_posterior_func(example_par_tab, example_titre_dat, 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_titre_dat, example_antigenic_map, function_type = 1, version = 2)
liks <- likelihood_func(par_tab$values, example_inf_hist)

## End(Not run)

seroanalytics/serosolver documentation built on April 24, 2023, 9:52 a.m.