Contents

Using fixed parameters/constants in mcstate likelihoods

Contents

NB: mcstate is being replaced by monty which will make this easier

How do you use fixed parameter values during the pMCMC with mcstate and an odin model?

I was first asked this question in 2021 and I don’t think we’ve ever managed to more clearly document it, but the relevant part of the documentation is https://mrc-ide.github.io/mcstate/reference/pmcmc_parameters.html.

To get this to work you need to make your transform function a closure. The transform function always needs to take as input a list of the pmcmc_parameters() being inferred by mcstate, and output a list of pars as used by the odin.dust model, and can’t take any other options. But, one can use a closure to bind other arguments of a more general function to fixed values.

e.g. As in the paper if I wanted to sample R0R_0 directly in mcstate, but my SIR model in odin uses beta and gamma:

parameter_transform <- function(pars) {
    beta <- pars[["gamma"]] * pars[["R0"]]
    gamma <- pars[["gamma"]]
    list(beta = beta, gamma = gamma)
}

Now adding in a transmission matrix e.g.:

parameter_transform <- function(pars, transmission_matrix) {
    beta <- pars[["gamma"]] * pars[["R0"]]
    gamma <- pars[["gamma"]]
    m <- transmission_matrix * beta
    list(beta = beta, gamma = gamma, m = m)
}

But this won’t work directly, as the transform function must always take mcstate pars in as a list, and output odin.dust pars as a list. But, you can add fixed parameters to this by defining a closure:

transform <- function(pars) { parameter_transform(pars, transmission_matrix = polymod) }

Here I’ve bound the transmission_matrix argument of the more general function to polymod, which will work as long as polymod is defined at the point you define the transform function.

So you’d then supply the transform() closure to the pmcmc_parameters() builder.