new_sample: Generate particles and select one to be the new sample

View source: R/sampling.R

new_sampleR Documentation

Generate particles and select one to be the new sample

Description

Generate a new sample for a particular subject given their data and the new model parameter estimates. This should not be called directly, rather it is used internally to run_stage.

Usage

new_sample(
  s,
  data,
  num_particles,
  parameters,
  efficient_mu = NULL,
  efficient_sig2 = NULL,
  mix_proportion = c(0.5, 0.5, 0),
  likelihood_func = NULL,
  epsilon = 1,
  subjects = NULL
)

Arguments

s

A number - the index of the subject. For s == 1 The first subject ID from the data subject column will be selected. For s == 2 the second unique value for subject id will be used.

data

A data.frame (or similar object) which contains the data against which the particles are assessed. The only strict requirement is that it contains a subject column named as such to allow for the splitting of the data by unique subject id. The provided log likelihood function is the only other contact with the data.

num_particles

The total number of particles to generate using a combination of the three methods.

parameters

A list containing:

tmu

The vector of means for the multivariate normal

tsig

A covariate matrix for the multivariate normal

alpha

An array of individual subject random effects

efficient_mu

The mu value for the efficient proposals

efficient_sig2

The sigma value for the efficient proposals

mix_proportion

A vector of floats between 0 and 1 and summing to 1 which give the proportion of particles to generate from the population level parameters, the individual random effects and the conditional parameters respectively

likelihood_func

A likelihood function for calculating log likelihood of samples. Usually provided internally in run_stage from the pmwgs object.

epsilon

A scaling factor to reduce the variance on the distribution based on subject random effects when generating particles.

subjects

A list of unique subject ids in the order they appear in the data.frame

Details

The function that controls the generation of new samples for the Particle Metropolis within Gibbs sampler. It generates samples from either the initial proposal or from the last iteration of the sampler. This function should not usually need to be called, as the run_stage function uses this internally.

The way it selects a new sample is by generating proposal particles from up to three different distributions (according to a mixing proportion).

The first distribution is based on the current model parameter sample values. The second distribution is based on the last random effects for the subject. The third distribution is only used in the final sampling phase and is based on the conditional distribution built from accepted particles in the adapt phase of the sampler.

Value

A single sample from the new proposals


pmwg documentation built on May 29, 2024, 12:09 p.m.