Given outputs from an MCMC run and the data used for fitting, generates an NxM matrix of plots where N is the number of individuals to be plotted and M is the range of sampling times. Where data are available, plots the observed antibody measurements and model predicted trajectories. In the longitudinal orientation, places biomarker_id on the x-axis and facets by sample time and individual.

plot_model_fits(
  chain,
  infection_histories,
  antibody_data = NULL,
  demographics = NULL,
  individuals,
  par_tab = NULL,
  antigenic_map = NULL,
  possible_exposure_times = NULL,
  nsamp = 1000,
  known_infection_history = NULL,
  measurement_bias = NULL,
  p_ncol = max(1, floor(length(individuals)/2)),
  data_type = 1,
  expand_to_all_times = FALSE,
  expand_to_all_biomarker_ids = FALSE,
  orientation = "cross-sectional",
  subset_biomarker_ids = NULL,
  subset_biomarker_groups = NULL,
  start_level = "none",
  settings = NULL,
  exponential_waning = NULL,
  verbose = FALSE
)

Arguments

chain

the full MCMC chain to generate antibody level trajectories from, usually `chains$theta_chain`

infection_histories

the MCMC chain for infection histories, usually `chains$inf_chain`

antibody_data

the antibody data frame, with one row per measurement

demographics

optional data frame identifying the demographic group for each individual. This is used when model parameters are stratified by demographics. See the [demographic stratification and covariate vignette](https://seroanalytics.github.io/serosolver/articles/demographics_covariates.html).

individuals

the subset of individual IDs to generate credible intervals for

par_tab

the model control table specifying the parameters in the MCMC chain

antigenic_map

(optional) a data frame of antigenic x and y coordinates. Must have column names: x_coord; y_coord; inf_times. The `inf_times` column identifies the circulation or exposure time represented by each map entry. See example_antigenic_map

possible_exposure_times

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

nsamp

number of draws to take from the posterior

known_infection_history

n-by-m matrix of known infection histories, with one row for each individual and one column for each possible exposure time. Use 1 for a known infection and 0 otherwise.

measurement_bias

default NULL, optional data frame mapping each `biomarker_id` and `biomarker_group` combination to the `rho_index` of the measurement-shift parameter that it uses. See the [advanced features vignette](https://seroanalytics.github.io/serosolver/articles/advanced_features.html).

p_ncol

integer giving the number of columns of subplots to create if using orientation = "longitudinal"

data_type

numeric or text value: `1` or `"discrete"` for discrete, bounded data; `2` or `"continuous"` for continuous, bounded data; or `3` or `"false_positive"` for continuous data with the false-positive observation model. Supply one value per biomarker group, or one value to use for all groups. For bounded data, the limits are given by `min_measurement` and `max_measurement` in par_tab.

expand_to_all_times

TRUE/FALSE value. If TRUE, uses all possible exposure times as sample times when expanding the prediction data. If FALSE, only the sample times represented in antibody_data are used.

expand_to_all_biomarker_ids

if TRUE, solves predictions for all biomarker IDs in the antigenic map while retaining the sample times in antibody_data

orientation

either "cross-sectional" or "longitudinal"

subset_biomarker_ids

if not NULL, then a vector giving the entries of biomarker_id to include in the longitudinal plot

subset_biomarker_groups

if not NULL, then a vector giving the biomarker groups to include in the plot

start_level

`"none"` or a starting-level summary or data frame. A starting level is the antibody level assigned before the modelled infection history begins. With `"none"`, starting levels are set to zero. See the [advanced features vignette](https://seroanalytics.github.io/serosolver/articles/advanced_features.html).

settings

if not NULL, list of serosolver settings as returned from the main serosolver function, such as `res$settings`

exponential_waning

Deprecated compatibility argument. Prefer a fixed `exponential_waning` row in `par_tab`, with `values = 1` and `par_type = 0`.

verbose

if TRUE, prints messages when settings are used or predictions are prepared

Value

a list of ggplot2 objects

Examples

if (FALSE) { # \dontrun{
data(example_theta_chain)
data(example_inf_chain)
data(example_antibody_data)
data(example_antigenic_map)
data(example_par_tab)

model_fit_plot <- plot_model_fits(example_theta_chain, example_inf_chain, example_antibody_data,
                                           1:10, example_antigenic_map, example_par_tab,orientation="longitudinal")
} # }