Description Usage Arguments Details Value References See Also Examples
Calling mixturemcmc()
performs MCMC sampling on the observations stored
in the fdata
object for the finite mixture model defined in the model
object. MCMC sampling is performed with a Gibbs sampler for all finite
mixture models using a prior that must be defined in the prior
object.
There are possibilities to control the MCMC sampling by hyperparameters
stored in the mcmc
object.
1 | mixturemcmc(fdata, model, prior, mcmc)
|
fdata |
An |
model |
A |
prior |
A |
mcmc |
An |
This function is the central part of the finmix
package. For MCMC sampling
it relies on high-performance C++ code using the Rcpp
and RcppArmadillo
packages. More specifically, these packages simplify the usage of external
C++ code on the objects in R
memory (enabled by R
's C
interface).
Execution of MCMC sampling with the default of 10,000 iterations and a
burn-in of 1,000 iterations should finish in a few seconds.
The algorithms used here are for the most part specified in the excellent
book Finite Mixture and Markov Switching Models by
Sylvia Fr\"uwirth-Schnatter. These algorithms rely on Gibbs sampling by
alternating between sampling the component and weight parameters of the
finite mixture model and the indicators of the data. Thereby, a so-called
random permutation is performed at each iteration of the algorithm, i.e. the
indicators S
and the component and weight parameters are permuted by their
index. As explained by Fr\"uwirth-Schnatter (2006, Section 3.5.5) label
switching in estimation of finite mixture distributions has to be addressed
explicitly when Bayesian estimation is used. While in maximum likelihood
estimation this is of no concern because only one of the equivalent modes of
likelihood function needs to be found, Bayesian estimation needs to explore
the full mixture posterior distribution and label switching occurs randomly,
but frequently during MCMC sampling. to overcome these issues the sampler is
forced to switch labels in a controlled form by randomly permuting the
labels of the components. This results in a balanced label switching and as
a result the sampler explores the full mixture posterior more thoroughly
leading to more robust estimations.
As laid out in the description of the input parameters sampling can start
either by sampling the indicators using starting parameters or by sampling
the parameters using starting indicators. The latter is for example applied,
if indicators are fixed (because they might be known). For starting by
sampling the parameters the slot @startpar
in the mcmc
input argument
must be set to TRUE
(default) and starting indicators must be present in
slot @S
of the fdata
object.
An object of class mcmcoutput storing the MCMC sampling results.
Fr\"uwirth-Schnatter, S. (2006), "Finite Mixture Models and Markov Switching Models", Springer
fdata for the fdata
class definition
model for the model
class definition
prior for the prior
class definition
prior()
for the prior
class constructor
priordefine()
for the advanced class constructor of the prior
class
mcmc for the mcmc
class definition
mcmc()
for the mcmc
class constructor
mcmcstart()
for defining starting parameters and/or indicators
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # Define a Poisson mixture model with two components.
f_model <- model("poisson", par = list(lambda = c(0.3, 1.2)), K = 2)
# Simulate data from the mixture model.
f_data <- simulate(f_model)
# Define the hyper-parameters for MCMC sampling.
f_mcmc <- mcmc()
# Complete object slots for consistency.
(f_data ~ f_model ~ f_mcmc) %=% mcmcstart(f_data, f_model, f_mcmc)
# Define the prior distribution by relying on the data.
f_prior <- priordefine(f_data, f_model)
# Start MCMC sampling.
f_output <- mixturemcmc(f_data, f_model, f_prior, f_mcmc)
# Get the sampled model parameters.
getPar(f_output)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.