Skip to content

Parsing EpiFusion Outputs

Ciara Judge edited this page Dec 20, 2023 · 12 revisions

What is in the output?

For each MCMC chain, EpiFusion will give you the following output files:

  • betas: csv file where each row is a trajectory of rate beta sampled from the MCMC
  • trajectories: csv file where each row is a daily infection trajectory sampled from the MCMC
  • rt: csv file where each row is a daily Rt trajectory sampled from the MCMC
  • params: txt file where each column is an MCMC parameter, and each row is an MCMC sample
  • likelihoods: txt file of the posterior likelihoods from each MCMC step
  • acceptance: txt file where each line logs if the MCMC step was accepted (1) or rejected (0)

How do I interpret the output?

We have a number of useful R functions for parsing through the output which are in the 'EpiFusion_utilities.R' script, to load these just run

source('EpiFusion_utilities.R')

in an R session where your working directory has this script. Someday we hope to package these functions in an R package, but for now the script has everything you should need.

EpiFusion_utilities.R Functions

Here's a guide to all the functions in EpiFusion_utilities.R.

Loading Functions

loadlikelihoods()

*Description: Loads the log likelihood values for each MCMC sample on each chain. *Input: A filepath to an EpiFusion outputs folder *Output: A list of length (number of chains), of vectors of length (number of MCMC samples per chain). The values of these vectors are the log likelihood of that chain at that MCMC sample.

likelihoods <- loadlikelihoods('epifusionoutputs/')

loadtrajectoriesfromfile()

*Description: Loads the trajectories contained in a trajectories csv file *Input: The name of the trajectory file and filepath to an EpiFusion outputs folder *Output: A table of infection trajectories for one chain.

trajectories <- loadtrajectoriesfromfile('trajectories_chain0.csv','epifusionoutputs/')

loadtrajectoriesminusburnin()

*Description: Loads the trajectories of all chains minus the burn-in *Input: A filepath to an EpiFusion outputs folder and a proportion of each chain to discard as burn-in *Output: A table of infection trajectories across all chains and minus burn-in.

trajectories <- loadtrajectoriesminusburnin('epifusionoutputs/', 0.1)

loadtrajectoriesminusburninseparate()

*Description: Loads the trajectories of all chains minus the burn-in, but keeps them separate in a list *Input: A filepath to an EpiFusion outputs folder and a proportion of each chain to discard as burn-in *Output: A list of tables of infection trajectories minus burn-in, with one table per chain.

trajectories <- loadtrajectoriesminusburninseparate('epifusionoutputs/', 0.1)

loadrtsfromfile()

*Description: Loads the Rts contained in a rts csv file - note, these are the rts from the renewal equation method. *Input: The name of the rt file and filepath to an EpiFusion outputs folder *Output: A table of rt trajectories for one chain.

rts <- loadrtsfromfile('rts_chain0.csv','epifusionoutputs/')

loadrtsminusburnin()

*Description: Loads the rts of all chains minus the burn-in - note, these are the rts from the renewal equation method *Input: A filepath to an EpiFusion outputs folder and a proportion of each chain to discard as burn-in *Output: A table of rt trajectories across all chains and minus burn-in.

rts <- loadrtsminusburnin('epifusionoutputs/', 0.1)

loadbetasfromfile()

*Description: Loads the betas contained in a betas csv file. *Input: The name of the beta file and filepath to an EpiFusion outputs folder *Output: A table of beta trajectories for one chain.

betas <- loadbetasfromfile('betas_chain0.csv','epifusionoutputs/')

loadbetasminusburnin()

*Description: Loads the betas of all chains minus the burn-in. *Input: A filepath to an EpiFusion outputs folder and a proportion of each chain to discard as burn-in *Output: A table of beta trajectories across all chains and minus burn-in.

betas <- loadbetasminusburnin('epifusionoutputs/', 0.1)

loadgammasfromfile()

*Description: Loads the gammas contained in a params txt file. *Input: The name of the params file and filepath to an EpiFusion outputs folder *Output: A vector of gamma values for one chain.

gammas <- loadgammasfromfile('params_chain0.csv','epifusionoutputs/')

loadgammasminusburnin()

*Description: Loads the gammas of all chains minus the burn-in. *Input: A filepath to an EpiFusion outputs folder and a proportion of each chain to discard as burn-in *Output: A vector of gamma values across all chains and minus burn-in.

gammas <- loadgammasminusburnin('epifusionoutputs/', 0.1)

loadbetagammartminusburnin()

*Description: Loads the rts of all chains minus the burn-in using the beta/gamma method *Input: A filepath to an EpiFusion outputs folder and a proportion of each chain to discard as burn-in *Output: A table of rt trajectories across all chains and minus burn-in.

rts <- loadbetagammartminusburnin('epifusionoutputs/', 0.1)

loadparamsfromfile()

*Description: Loads the parameters contained in a params txt file. *Input: The name of the params file and filepath to an EpiFusion outputs folder *Output: A table of parameter values for one chain.

params <- loadparamsfromfile('params_chain0.csv','epifusionoutputs/')

loadparamsminusburnin()

*Description: Loads the parameter posteriors of all chains minus the burn-in. *Input: A filepath to an EpiFusion outputs folder and a proportion of each chain to discard as burn-in *Output: A table of parameter values across all chains and minus burn-in.

params <- loadparamsminusburnin('epifusionoutputs/', 0.1)

loadparamsminusburninseparate()

*Description: Loads the parameter posteriors of all chains minus the burn-in, but keeps them separate in a list. *Input: A filepath to an EpiFusion outputs folder and a proportion of each chain to discard as burn-in. *Output: A list of table of parameter values and minus burn-in, with one table per chain.

params <- loadparamsminusburninseparate('epifusionoutputs/', 0.1)

loadparamsseparate()

*Description: Same as loadparamsminusburninseparate(), but does not discard any samples as burn-in. *Input: A filepath to an EpiFusion outputs folder. *Output: A list of table of parameter values, with one table per chain.

params <- loadparamsseparate('epifusionoutputs/', 0.1)

loadparamfromfilebyname()

*Description: Loads the values for a specific parameter contained in a params txt file. *Input: The name of the params file, a filepath to an EpiFusion outputs folder, and the name of the parameter you are interested in. *Output: A vector of the parameter values for one chain.

params <- loadparamfromfilebyname('params_chain0.csv','epifusionoutputs/', 'psi')

loadparambyname()

*Description: Loads the values for a specific parameter across all chains minus the burn-in. *Input: A filepath to an EpiFusion outputs folder, and the name of the parameter you are interested in. *Output: A vector of the parameter values across all chains.

params <- loadparambyname('epifusionoutputs/', 'psi')

Plotting Functions

plottrajectoriesfromtable()

plottrajectoryposteriors()

addtrajectoriesfromtable()

addtrajectoryposteriors()

plotrtposteriors_renewal()

addrtposteriors_renewal()

plotrtfromtable_renewal()

addrtfromtable_renewal()

plotrtposteriors_betagamma()

addrtposteriors_betagamma()

plotrtfromtable_betagamma()

addrtfromtable_betagamma()

Clone this wiki locally