pmcmc_parameters_nested | R Documentation |
Construct nested parameters for use with
pmcmc()
. This creates a utility object that is used
internally to work with parameters that may be fixed and the same for all
given populations, or varied and possibly-different between populations.
Most users only need to construct this object, but see the examples for
how it can be used.
new()
Create the pmcmc_parameters object
pmcmc_parameters_nested$new( parameters, proposal_varied = NULL, proposal_fixed = NULL, populations = NULL, transform = NULL )
parameters
A list
of
pmcmc_parameter or pmcmc_varied_parameter objects, each of which
describe a single (possibly-varying) parameter in your model.
If parameters
is named, then these names must match the $name
element of each parameter that is used (this is verified).
proposal_varied, proposal_fixed
Square proposal matrices
corresponding to the variance-covariance matrix of a multivariate
gaussian distribution used to generate new varied and fixed parameters
respectively.'. They must have the same number of
rows and columns as there are varied and fixed parameters respectively.
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.
populations
Specifies the names of the different populations
that the varying parameters change according to. Only required if no
pmcmc_varied_parameter objects are included in parameters
.
Otherwise population names are taken from those objects.
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 you need to generate derived parameters from those being actively sampled you can do arbitrary transformations here.
names()
Return the names of the parameters
pmcmc_parameters_nested$names(type = "both")
type
One of "both" (the default, all parameters), "fixed" (parameters that are shared across populations) or "varied" (parameters that vary over populations).
populations()
Return the names of the populations
pmcmc_parameters_nested$populations()
validate()
Validate a parameter matrix. This method checks that your matrix has the expected size (rows according to parameters, columns to populations) and if named that the names are exactly what is expected. It also verifies that the fixed parameters are same across all populations.
pmcmc_parameters_nested$validate(theta)
theta
a parameter matrix
summary()
Return a data.frame
with information about
parameters (name, min, max, integer, type (fixed or varied)
and population)
pmcmc_parameters_nested$summary()
initial()
Return the initial parameter values as a named matrix with rows corresponding to parameters and columns to populations.
pmcmc_parameters_nested$initial()
mean()
Return the estimate of the mean of the parameters, as set when created (this is not updated by any fitting!)
pmcmc_parameters_nested$mean(type)
vcv()
Return the variance-covariance matrix used for the proposal.
pmcmc_parameters_nested$vcv(type)
prior()
Compute the prior(s) for a parameter matrix. Returns a named vector with names corresponding to populations.
pmcmc_parameters_nested$prior(theta)
theta
a parameter matrix with columns in the same order as
$names()
and rows in the same order as $populations()
.
propose()
This proposes a new parameter matrix given your current
matrix and the variance-covariance matrices of the proposal
kernels, rounds any integer values, and reflects bounded
parameters until they lie within min
:max
. Returns matrix with rows
corresponding to parameters and columns to populations (i.e.,
the same orientation as theta
).
pmcmc_parameters_nested$propose(theta, type, scale = 1, vcv = NULL)
theta
a parameter matrix with rows in the same order as
$names()
and columns in the same order as $populations()
.
type
specifies which type of parameters should be proposed, either fixed parameters only ("fixed"), varied only ("varied"), or both ("both") types. For 'fixed' and 'varied', parameters of the other type are left unchanged.
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.
model()
Apply the model transformation function to a parameter matrix.
pmcmc_parameters_nested$model(theta)
theta
a parameter matrix with rows in the same order as
$names()
and columns in the same order as $populations()
.
fix()
Set some parameters to fixed values. Use this to reduce the dimensionality of your system. Note that this function has an unfortunate name collision - we use "fixed" and "varied" parameters generally to refer to ones that are fixed across populations or which vary among populations. However, in the context of this method "fixed" refers to parameters which will be set to a single value and no longer used in inference.
pmcmc_parameters_nested$fix(fixed)
fixed
a named vector of parameters to fix
# Construct an object with two varied parameters ('a' and 'b'),
# two fixed parameters ('c' and 'd') and two populations ('p1' and 'p2')
parameters <- list(mcstate::pmcmc_varied_parameter("a", c("p1", "p2"), 2),
mcstate::pmcmc_varied_parameter("b", c("p1", "p2"), 2),
mcstate::pmcmc_parameter("c", 3),
mcstate::pmcmc_parameter("d", 4))
proposal_fixed <- diag(2)
proposal_varied <- diag(2) + 1
pars <- mcstate::pmcmc_parameters_nested$new(parameters, proposal_varied,
proposal_fixed)
# Initial parameters
p <- pars$initial()
p
# Propose a new parameter point
pars$propose(p, type = "both")
pars$propose(p, type = "fixed")
pars$propose(p, type = "varied")
# Information about parameters:
pars$names()
pars$names("fixed")
pars$names("varied")
pars$summary()
# Compute log prior probability, per population
pars$prior(p)
# Transform data for your model
pars$model(p)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.