run_stage | R Documentation |
Run one of burnin, adaptation or sampling phase from the PMwG sampler. Each stage involves slightly different processes, so for the full PMwG sampling we need to run this three times.
run_stage(
pmwgs,
stage,
iter = 1000,
particles = 100,
display_progress = TRUE,
n_cores = 1,
n_unique = ifelse(stage == "adapt", 100, NA),
epsilon = NULL,
p_accept = 0.8,
mix = NULL,
pdist_update_n = ifelse(stage == "sample", 50, NA)
)
pmwgs |
A Particle Metropolis within Gibbs sampler which has been set up and initialised |
stage |
The sampling stage to run. Must be one of |
iter |
The number of iterations to run for the sampler. For
|
particles |
The default here is 1000 particles to be generated for each iteration, however during the sample phase this should be reduced. |
display_progress |
Display a progress bar during sampling. |
n_cores |
Set to more than 1 to use |
n_unique |
A number representing the number of unique samples to check
for on each iteration of the sampler (An initial test for the generation
of the proposal distribution). Only used during the |
epsilon |
A value between 0 and 1 that controls the extent to which the covariance matrix is scaled when generating particles from the previous random effect. The default will be chosen based on the number of random effects in the model. |
p_accept |
A value between 0 and 1 that will flexibly tune epsilon to achieve an acceptance ratio close to what you set p_accept to. The default is set at 0.8. |
mix |
A vector of floats that controls the mixture of different sources
for particles. The function |
pdist_update_n |
The number of iterations in the sample stage after which the proposal distribution will be recomputed. |
The burnin stage by default selects 50 parameter sample (selected through a Gibbs step) and 50 the previous random effect of each subject. It assesses each particle with the log-likelihood function and samples from all particles weighted by their log-likelihood.
The adaptation stage selects and assesses particle in the same was as burnin, however on each iteration it also checks whether each subject has enough unique random effect samples to attempt to create a conditional distribution for efficient sampling in the next stage. If the attempt at creating a conditional distribution fails, then the number of unique samples is increased and sampling continues. If the attempt succeeds then the stage is finished early.
The final stage (sampling) by default samples predominantly from the conditional distribution created at the end of adaptation. This is more efficient and allows the number of particles to be reduced whilst still getting a high enough acceptance rate of new samples.
Once complete each stage will return a sampler object with the new samples stored within it.
The progress bar (which is displayed by default) shows the number of
iterations out of those requested which have been completed. It also contains
additional information at the end about the number of newly generated
particles that have been accepted. This is show as New(XXX
average across subjects of newly sampled random effects accept rate. See
accept_rate
for more detail on getting individual accept rate
values per subject.
A pmwgs object with the newly generated samples in place.
library(rtdists)
sampled_forstmann$data <- forstmann
run_stage(sampled_forstmann, "sample", iter = 1, particles = 10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.