Construct parameters for use with pmcmc(). This creates a utility object that is used internally to work with parameters. Most users only need to construct this object, but see the examples for how it can be used.

Methods


Method new()

Create the pmcmc_parameters object

Usage

pmcmc_parameters$new(parameters, proposal, transform = NULL)

Arguments

parameters

A list of pmcmc_parameter objects, each of which describe a single parameter in your model. If parameters is named, then these names must match the $name element of each parameter is used (this is verified).

proposal

A square proposal distribution corresponding to the variance-covariance matrix of a multivariate gaussian distribution used to generate new parameters. It must have the same number of rows and columns as there are elements in parameters, and if named the names must correspond exactly to the names in parameters. Because it corresponds to a variance-covariance matrix it must be symmetric and positive definite.

transform

An optional transformation function to apply to your parameter vector immediately before passing it to the model function. If not given, then as.list is used, as dust models require this. However, if t you need to generate derived parameters from those being actively sampled you can do arbitrary transformations here.


Method initial()

Return the initial parameter values as a named numeric vector

Usage

pmcmc_parameters$initial()


Method names()

Return the names of the parameters

Usage

pmcmc_parameters$names()


Method summary()

Return a data.frame with information about parameters (name, min, max, and discrete).

Usage

pmcmc_parameters$summary()


Method prior()

Compute the prior for a parameter vector

Usage

pmcmc_parameters$prior(theta)

Arguments

theta

a parameter vector in the same order as your parameters were defined in (see $names() for that order.


Method propose()

Propose a new parameter vector given a current parameter vector. This proposes a new parameter vector given your current vector and the variance-covariance matrix of your proposal kernel, discretises any discrete values, and reflects bounded parameters until they lie within min:max.

Usage

pmcmc_parameters$propose(theta, scale = 1)

Arguments

theta

a parameter vector in the same order as your parameters were defined in (see $names() for that order.

scale

an optional scaling factor to apply to the proposal distribution. This may be useful in sampling starting points. The parameter is equivalent to a multiplicative factor applied to the variance covariance matrix.


Method model()

Apply the model transformation function to a parameter vector.

Usage

pmcmc_parameters$model(theta)

Arguments

theta

a parameter vector in the same order as your parameters were defined in (see $names() for that order.


Method fix()

Set some parameters to fixed values. Use this to reduce the dimensionality of your system.

Usage

pmcmc_parameters$fix(fixed)

Arguments

fixed

a named vector of parameters to fix

Examples

# Construct an object with two parameters:
pars <- mcstate::pmcmc_parameters$new(
  list(mcstate::pmcmc_parameter("a", 0.1, min = 0, max = 1,
                                prior = function(a) log(a)),
       mcstate::pmcmc_parameter("b", 0, prior = dnorm)),
  matrix(c(1, 0.5, 0.5, 2), 2, 2))

# Initial parameters
p <- pars$initial()
p
#>   a   b 
#> 0.1 0.0 

# Propose a new parameter point
pars$propose(p)
#>           a           b 
#>  0.02891308 -0.96602612 

# Information about parameters:
pars$names()
#> [1] "a" "b"
pars$summary()
#>   name  min max discrete
#> 1    a    0   1    FALSE
#> 2    b -Inf Inf    FALSE

# Compute prior
pars$prior(p)
#> [1] -1.903643

# Transform data for your model
pars$model(p)
#> $a
#> [1] 0.1
#> 
#> $b
#> [1] 0
#>