R/mcmc_kernel.R

Defines functions mcmc_kernel

Documented in mcmc_kernel

#'Specify an MCMC transition kernel
#'
#'@param parameter_blocks list of parameter blocks with an MCMC kernel for each
#'  block. Each list element should be generated by a call to the
#'  \code{parblock} function
#'@param lna_ess_control list of control settings for updating LNA paths via
#'  elliptical slice sampling, generated by a call to \code{lna_control}.
#'@param initdist_ess_control list of control settings for updating initial
#'  distributions, generated by a call to \code{initdist_control}.
#'@param tparam_ess_control list of control settings for updating standard
#'  normal variates for time-varying parameters via elliptical slice sampling.
#'
#'@details Specifies the MCMC transition kernel for updating parameters, the
#'  latent epidemic process, time-varying parameters, and adaptive MCMC control.
#'  Parameter blocks group (time-homogeneous) parameters that are to be updated
#'  jointly. Each parameter block is updated via a multivariate
#'  Metropolis-Hastings update or a multivariate normal slice sampling update.
#'  Empirical covariances for these algorithms can be adapted using a global
#'  adaptive scaling algorithm (Andrieu and Thoms, 2008).
#'
#'  References
#'
#'  Andrieu, Christophe, and Johannes Thoms. "A tutorial on adaptive MCMC."
#'  Statistics and Computing 18.4 (2008): 343-373.
#'
#'@return list containing the MCMC kernel.
#'@export
mcmc_kernel <-
        function(parameter_blocks,
                 lna_ess_control = NULL,
                 initdist_ess_control = NULL,
                 tparam_ess_control = NULL) {
            
    if(!all(sapply(parameter_blocks, is.list))) {
        stop("The parameter_blocks argument must be a list of lists.")
    }
    
    if(is.null(lna_ess_control)) {
        lna_ess_control = lna_control()
    }
    
    if(is.null(initdist_ess_control)) {
        initdist_ess_control = initdist_control()
    }
    
    if(is.null(tparam_ess_control)) {
        tparam_ess_control = tpar_control()
    }

    kernel_settings = 
        list(parameter_blocks     = parameter_blocks,
             lna_ess_control      = lna_ess_control,
             initdist_ess_control = initdist_ess_control,
             tparam_ess_control   = tparam_ess_control)
        
    return(kernel_settings)
}
fintzij/stemr documentation built on March 25, 2022, 12:25 p.m.