mixturemcmc: Performs MCMC sampling for finite mixture models

Description Usage Arguments Details Value References See Also Examples

Description

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.

Usage

1

Arguments

fdata

An fdata object storing the observations in slot @y and the (starting) indicators in slot @S. If sampling should start by sampling the parameters the starting indicators must be defined.

model

A model object specifying the finite mixture model. If it should be started by sampling the indicators starting parameters and weights must be defined in slots @par and @weight respectively.

prior

A prior object specifying the prior distribution for Bayesian estimation. This object must be fully specified regardless, if sampling should start with the indicators or parameters. See priordefine() for choosing automatically a data dependent prior distribution.

mcmc

An mcmc object storing the hyper-parameters for MCMC sampling. If slot @startpar is TRUE sampling starts by sampling the parameters. Henceforth, it needs starting indicators.

Details

Performance

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.

Algorithms

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.

Starting by sampling the parameters

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.

Value

An object of class mcmcoutput storing the MCMC sampling results.

References

Fr\"uwirth-Schnatter, S. (2006), "Finite Mixture Models and Markov Switching Models", Springer

See Also

Examples

 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)

simonsays1980/finmix documentation built on Dec. 23, 2021, 2:25 a.m.