Recursive Deviance Information Criterion for the Hidden Markov Model

In Bayesian model selection, the deviance information criterion (DIC) has become a widely used criterion. It is however not defined for the hidden Markov models (HMMs). In particular, the main challenge of applying the DIC for HMMs is that the observed likelihood function of such models is not available in closed form. A closed form for the observed likelihood function can be obtained either by summing all possible hidden states of the complete likelihood using the so-called the forward recursion, or via integrating out the hidden states in the conditional likelihood. Hence, we propose two versions of the DIC to the model choice problem in HMMs context, namely, the recursive deviance-based DIC and the conditional likelihood-based DIC. In this paper, we compare several normal HMMs after they are estimated by Bayesian MCMC method. We conduct a simulation study based on synthetic data generated under two assumptions, namely diversity in the heterogeneity level and also the number of states. We show that the recursive deviance-based DIC performs well in selecting the correct model compared with the conditional likelihood-based DIC that prefers the more complicated models. A real application involving the waiting time of Old Faithful Geyser data was also used to check those criteria. All the simulations were conducted in Python v.2.7.10, available from first author on request.


Introduction
Hidden Markov Models (HMMs) have been used to model various types of data: discrete, continuous, univariate, multivariate, mixed and mixture data (MacDonald and Zucchini, 2009).Consequently, they have been widely applied in many fields, such as econometrics (Hamilton, 1989;Billio et al., 1999); finance (Bhar and Hamori, 2004); speech recognition (Rabiner, 1989;Derrode, 2006); and psychology (Visser et al., 2002).One important issue that is often discussed after fitting models is the model choice issue.In particular, we discuss this issue in the HMM context.When fitting several HMMs to a data set, we seek to determine the number of hidden states of a model that adequately fits those data or more formally the best model among those competitive models.Frequentest criteria such Akaike Information Criterion (AIC) (Akaike, 1973) and the Bayesian information criterion (BIC) (Schwarz, 1978) have been applied to the HMM model choice problem.In the HMM context, they have been used to determine the best HMM by MacDonald and Zucchini (2009).However, the AIC and BIC do not take into account uncertainty about the parameter values and model form.In addition, these criteria might suffer from irregular behavior of the likelihood function that may lead to under-fitting or over-fitting, where the number of hidden states that are analyzed is smaller or greater than the true number of states, respectively (MacDonald and Zucchini, 2009).Alternatively, the Bayesian theory that takes into account the uncertainty about the parameters of the model and also the model selection is used.The deviance information criterion (DIC) proposed by Spiegelhalter et al. (2002) can be viewed as an extended Bayesian version of the AIC the BIC.Similar to the AIC and BIC, the DIC trades off a measure of model adequacy against a measure of complexity.The popularity of the criterion is due to the ease of computing the posterior distribution of the log-likelihood or the deviance.Hence, it has been applied to a wide range of statistical models.Despite its popularity, a number of difficulties can be inherent in this criterion, especially in more complicated models, e.g.mixture and hidden Markov models, where latent (hidden) variables and model parameters are non-identifiable from data (Celeux et al., 2006).In this setting, Celeux et al. (2006) introduced eight formulae for DICs which have been classified according to the nature of the likelihood used; observed, complete and conditional.Celeux et al. (2006) pointed out also that the observed data likelihood of mixture models is sometimes available in closed form, but for the HMMs this is not always the case.Hence, the availability of a closed form for the likelihood function of the HMMs forms a main challenge.The Data Augmentation approach (Tanner and Wong, 1987) is often used with MCMC methods in the Bayesian inference of complicated models such as HMMs, hence, a closed form of the likelihood function of the HMMs can be available and the parameter estimation becomes more straightforward.Using the Data Augmentation principle, we can obtain a closed form to the likelihood function via two sources exclusively, either via the complete data likelihood or the conditional likelihood.The first source is obtained via summing all possible hidden states of the complete data likelihood.The computation of the observed likelihood function via the complete data likelihood is problematic because of the computational complexity caused by the high dimensions to this function.To overcome this problem, an efficient method called the forward-backward (F-B) (Rabiner, 1989) algorithm that is used for estimating the sequence of underlying hidden states of HMMs and evaluating the likelihood function (Scott, 2002) can be introduced.The observed likelihood function is recursively evaluated using only the forward part of the F-B algorithm to obtain the so-called recursive likelihood or log likelihood.Hence, we propose a DIC based on recursive deviance, which we denote as DIC rec .The advantage of recursive calculation is that the computational complexity will be reduced from O(K T T ) into O(K 2 T ), where T and K are the length of observations and number of hidden states respectively.The second way to obtain a closed form of the likelihood function is to integrate out the hidden states.Hence, another DIC based on a conditional deviance denoted by DIC con is proposed.
We contribute to this line of research by developing a new methodology aiming at finding closed forms for the observed likelihood of HMMs.A closed form of the observed likelihood can be obtained either via the complete-data likelihood or conditional.Hence, two of proposed criteria in this paper are introduced.The first criterion, called the recursive deviance-based DIC, is obtained via the evaluation of the observed likelihood by summing all hidden states of the complete likelihood using the forward recursion approach.The second, called the conditional deviance-based DIC, can be obtained via integrating the conditional likelihood.Since HMMs are appropriately described to accommodate the unobserved heterogeneity in data, we also contribute in this paper by taking into account the behaviour of the proposed criteria with different levels of heterogeneity in the data.We also examine these criteria on models with a different number of states to see whether each criterion has a fixed behaviour or not for different number of states.We show via simulation studies that the conditional likelihood-based DIC tends to favour more complicated models, and its estimates are generally unstable as documented from their large numerical standard errors.On the other hand, the DIC based on the recursive likelihoods is more accurately estimated as it has much smaller numerical standard errors compared to the conditional likelihood-based DIC.In addition, it performs well with respect to choosing the correct model.
The rest of this paper is organized as follows.In section 2, the HMMs are introduced.The Bayesian estimation with data augmentation are also reviewed.In section 3, we develop a recursive calculation for the likelihood function.In section 4, we review the general definition of the DIC, propose criteria for hidden Markov models, namely the recursive deviance-based DIC and the conditional likelihood-based DIC and discuss how to compute those criteria from the MCMC output.Section 5 is devoted for fitting the model and also describing the synthetic and real data used in the study.Section 6 shows the results of comparing of the proposed criteria using artificial and real data.The discussions of this paper and future research are introduced in Section 7.

The Model
The Hidden Markov Model (HMM) is a statistical model that involves two stochastic processes.The first process (Z t = z t ; t = 1, 2, ..., T ) is an unobserved or hidden process (state process), satisfying the Markov property.The second process (Y t = y t , t = 1, 2, ..., T ) is an observed process (state-dependent process).When Z t is known, the distribution of Y t can be determined based only on Z t (MacDonald and Zucchini, 2009).The dependency between Markovian hidden states and observed state can be illustrated in the directed graph in Figure 1.From Figure 1, we can mathematically summarize the relationship between those two processes under the following assumptions: We refer the reader to (Cappe et al., 2006) and(MacDonald andZucchini, 2009) for good overviews of HMMs.
In this paper, we focus on parametric discrete-time finite state-space HMMs, such that the observations in the assumption (2) can follow distributions from a parametric family, and each hidden state z at time t in assumption (1) takes a discrete value k and it is defined on a known finite state-space, Ω Z ∈ K, where K is a known number of the states.Formally, the HMMs can be expressed as a collection of the parameters Θ = (π, A, θ) and the number of hidden states K, that are defined in detail as follows: 1.The number of states K, where each hidden state z t take a discrete value k that belong to the state space {1, 2, ..., K}.
2. The initial state distribution π = {π k }, where π k denotes the probability that the model is in the state k at the time t = 1, i.e, π k = p {z 1 = k} , where 1 ≤ k ≤ K.

The probability transition matrix
, where a jk is the probability that the state at time t is k, given that the state at time t − 1 is j, i.e, a jk = p{z t = k|z t−1 = j} such that a jk satisfy the normal stochastic constraints, i.e.

Bayesian Estimation
The Bayesian model can be written using Bayes Theorem as p(Θ|y) ∝ f (y|Θ)p(Θ), where p(Θ|y) denotes the posterior distribution of the model, f (y|Θ) and p(Θ) denote respectively the evidence or the observed data likelihood and prior.The difficulty of applying Bayesian inference for models such as HMMs is attributed to the complexity of evaluating the model evidence or the likelihood f (y|Θ).To overcome this problem, techniques such as Monte Carlo Markov Chain (MCMC) are used.The Data Augmentation (Tanner and Wong, 1987) approach is often used to facilitate the estimates process of the parameters of the model.This strategy is commonly used with MCMC methods in Bayesian analysis of HMMs in which the hidden states are introduced as missing data and augmented to the parameter space of the sampler (Robert et al., 1993;Albert and Chib, 1993;Chib, 1996).The posterior distribution can then be written as p(Θ, z|y) ∝ f (y, z|Θ)p(Θ) ∝ f (y|z, Θ)p(z|Θ)p(Θ). ( where the term, f (y, z|Θ), represents the complete data likelihood which can be written according to the Bayes' rules as f (y|z, Θ)p(z|Θ) and p(Θ) represents a prior distribution on Θ.In other words, the complete data likelihood function above can be obtained as follows: Given an initial probability distribution π and transition matrix A, the hidden state sequence z = (z 1 , z 2 , ..., z T ), with a known number of states K, can be modelled as p(z) = p(z t , z t−1 , ..., z 1 ; A, π).According to Bayes' rules based on the Markov property, we obtain By conditioning on z t , the observation y t can be sampled independently from a chosen parametric distribution, where f k (.|θ k ) denotes a parametric density function parametrized by θ at the state k.Hence, the complete data likelihood of HMM is then given by and the observed data likelihood can be obtained by summing the complete data likelihood above over all possible hidden states The calculation of the likelihood for a HMM using traditional methods can be computationally expensive, since it it involves a total of O(K T T ) calculations (Rabiner, 1989;Bishop, 2006).Therefore, it requires more sophisticated methods.
An efficient technique called the forward recursion can be a less expensive way to compute the likelihood function of HMMs (Rabiner, 1989;Chib, 1996;Scott, 2002).We devoted an independent section in this paper to discuss the computation of the likelihood function of the HMMs due to it forms the main part for constructing of the proposed model selection criteria, see Section 3. To complete the Bayesian HMM, we need to specify prior distributions on the parameters π, A, and θ.We assume independent Dirichlet priors (Fruhwirth-Schnatter, 2006) on the initial distribution π and each row of the transition matrix A, { a j.

}
, i.e., where δ is a hyperparameter of Dirichlet distribution.Regarding the state-dependent parameter θ, we choose priors on θ, expressed by p(θ|φ), where φ denotes a conjugate hyperparameter.Their priors have the same functional form as the likelihood, and hence the posterior.The complete data posterior of the HMM in equation ( 1) can then be written as follows Dir(a j. |δ). (4) Analytical computation of the posterior distribution in equation ( 4) is difficult due to its complex form.A way to address this complexity is to use MCMC algorithms.The MCMC algorithm involves sampling the parameters of the model, Θ, and the hidden state, z, from the desired distribution based on an ergodic Markov chain.We use the Gibbs algorithm (Geman and Geman, 1984), a special case of Metropolis-Hastings algorithm, to treat the high-dimensionality problem in the joint posterior distribution in the equation ( 4) by partitioning it into blocks (conditional distributions), to make sampling simpler.A two-stage Gibbs sampler is then implemented by alternating between drawing z from the conditional posterior distribution p(z|Θ, y) (data augmentation) and drawing Θ from the conditional posterior distribution p(Θ|z, y).
A significant advantage of using the Gibbs sampling is that the conditional distributions required are often available for simulation, and hence, the high-dimensionality problem is typically reduced (Casella and Robert, 2004).

A Recursive Evaluation of Likelihood Function
The likelihood function forms the main part of many Bayesian model choice criteria.However, with increasing model complexity, Bayesian inference and model selection become more challenging.The reason may be that the likelihood function is analytically unavailable or computationally costly to evaluate.Because of the complicated nature of hidden Markov models, the likelihood function of these models is often unavailable in closed form (Celeux et al., 2006).To overcome this problem, the data augmentation strategy (Tanner and Wong, 1987) is often used.The main idea behind this approach is augmenting the observations by adding hidden states z introduced as missing data, which leads to obtaining a closed form expression to likelihood function and hence simplifying the MCMC algorithms constructed for computing posterior distributions.As mentioned in Section 2, a closed form of the observed likelihood function in equation ( 2) is obtained by summing all possible (missing) states z over the complete data likelihood.However, evaluating of the observed likelihood function over the complete data likelihood is still not a simple task.For this, we rely on an efficient approach called the forward-backward algorithm (Baum et al., 1970;Rabiner, 1989) to achieve this task as shown in the next sub-section.

Forward-Backward Algorithm
The forward-backward recursion was developed by Baum et al. (1970) to implement an EM algorithm to obtain a maximum likelihood estimate.The observed likelihood function defined in equation ( 2) in Section 2 is evaluated by summing the complete data likelihood function over all possible hidden states.The evaluation of the observed likelihood function using direct ways requires O(T K T ) steps.Alternatively, we can compute the observed likelihood function recursively using only the forward part of the forward-backward algorithm to obtain the so-called recursive likelihood.This approach requires only O(T K 2 ) steps (Rabiner, 1989).The recursive computation of the likelihood function is based on defining the forward probabilities which provide the probability of ending up in any particular state, given a partial observation sequence, i.e p(y 1 , y 2 , ..., y t , z t |Θ).We define the forward variable α t (k), that represents the joint probability of the partial observation sequence until time t and the state k at time t, by According to Baum et al. (1970) and Rabiner (1989), the forward probabilities, αt(k), can be calculated recursively by first initializing a forward variable at time t = 1, and for t = 2, 3, ..., T , the updating of the next forward variables over induction steps is done using Hence, a recursion can be set up that will lead to obtaining α t ( j) for j = 1, 2, ..., K and t = 1, 2, ..., T .Note that computing α t (k) requires the sum of K quantities.Thus a single step in the recursion is O(K 2 ), and the evaluating of observed likelihood function in equation ( 2) is O(T K 2 ), which is far more efficient than the O(T K T ) complexity of the likelihood computed in the direct methods.Given the forward probabilities obtained above, the likelihood can be written as Practically, when dealing with a large observation sequence, the calculation of the likelihood function would cause the so-called underflow/overflow problem, that is, the likelihood may converge to zero or diverge to infinity as t increases.
To overcome this problem, we use the scaling factors (Rabiner, 1989) to re-scale the α t ( j) ′ s throughout the recursion by dividing them by ∑ K j=1 α t ( j).To do this, we define the first scaling coefficient as . Hence, at t=1, the forward variables are re-scaled by multiplying by c 1 , that is, α1 ( j) = c 1 α 1 ( j), for j = 1, 2, ..., K, where α is used to denote the re-scaled coefficients.Then, applying equation ( 5) directly to the re-scaled forward variables, we define at t = 2, , where the second scaling coefficient is defined as . Then, α2 ( j) = c 1 c 2 α 2 ( j), for j = 1, 2, ..., K.For t > 1, using the same procedure leads to and allows us to further define As this last expression is valid for t = T , it is possible to calculate the observed likelihood function from = 1.The log-likelihood function can be obtained as which depends only on the scaling constants.Since the log-likelihood is computed as a sum of the log scaling coefficients, this will avoid the underflow/overflow problems (Rabiner, 1989).In general, the recursive log-likelihood function computed here forms the main part of the deviance D(Θ), where D(Θ)=-2[log-likelihood], used in the constructing of most likelihood-based criteria.In the next section, we will show how to construct criteria based on the recursive likelihood function.

Deviance Information Criterion for HMMs
The deviance information criterion (DIC) was introduced by Spiegelhalter et al. ( 2002) from a Bayesian perspective.It is used to measure both the goodness of fit of the model and the model complexity.Spiegelhalter et al. (2002) developed this criterion by introducing the theoretical justification to the concept of effective number of parameters as a measure of the complexity of a model.This criterion is based on the concept of the deviance, which is defined as D(Θ) = −2 log f (y|Θ) + 2 log f (y), where f (y|Θ) is the likelihood function and f (y) is a function of the data alone which is often set to unity.Thus, the deviance is The DIC as defined by Spiegelhalter (2002) is then where, D(Θ), is used as a measure of the goodness of fit and is summarized by the posterior expectation of the deviance, and p DIC is the effective number of parameters, is used as a measure for model complexity, which is defined as the difference between the posterior mean of the deviance minus the deviance of posterior means, i.e.
where Θ is an estimate of Θ, which is often taken as the posterior mean or mode (Spiegelhalter, 2002;Celeux et al., 2006).Therefore, the DIC is then defined by and its the effective number of parameters is Given a set of competing models, smaller DIC values indicate a better-fitting model.The DIC criterion is based essentially on the likelihood function of the model since it forms the main part of the deviance used in constructing this criterion.
In the context of latent variable models, the likelihood function requires some care because they are often unavailable in closed form.The likelihood function of mixture models is sometimes available in closed form but for HMMs this is not always available (Celeux et al., 2006).In such situation, Celeux et al. (2006) introduced eight formulas to the DIC based on the type of likelihood function of the latent variable model.There are a number of methods by which the likelihood can be defined.Consider a model describing a data set y with latent variables z and parameters Θ.The likelihood can take one of the following forms: 1. f (y|Θ) is the observed or incomplete likelihood which is computed by marginalizing the complete likelihood shown in the point (2) below.
2. f (y, z|Θ) is the complete likelihood or the joint probability distribution of observations y and the latent or hidden variables z.
3. f (y|z, Θ) is the conditional likelihood of observation y, given the latent or hidden variable z and the parameters of the model Θ.
The observed data likelihood f (y|Θ) is sometimes called the incomplete data likelihood due the fact that the observed data likelihood cannot be evaluated without involving latent or missing variables.Hence, the analysis is based instead on the so-called complete-data likelihood f (y, z|Θ).In discrete time HMMs with a finite state space, that we adopt in this paper, the incomplete or observed data likelihood can be written as where, f (y|z, Θ), is the conditional likelihood multiplied by the probability of hidden states f (z|Θ), given the parameters of the model, and f (y, z|Θ), is the complete-data likelihood.From the expression above, one can conclude that in order to obtain the observed likelihood function in closed-form, which forms a hard task for HMMs, one can either use the conditional likelihood function f (y|z, Θ), weighted by the density of hidden states f (z|Θ), or the complete data function f (y, z|Θ).The approach applied in the expression above ( 9) is based on the so-called data augmentation strategy (Tanner and Wong, 1987).This strategy is commonly used with MCMC methods in Bayesian analysis of HMMs in which the hidden states are introduced as missing data and added to the parameter space in order to facilitate the estimation process of the parameters of the model and hence implicitly obtain a closed form for the likelihood function (Cappe et al., 2006;Fruhwirth-Schnatter, 2006).
Based on equation ( 9), we propose two different criteria of the DIC for the HMMs.The first criterion, denoted by DIC rec (Θ), is based on a recursive calculation of the log-likelihood or so-called the recursive deviance, see Section 3. To estimate DIC rec (Θ) over MCMC samples, we can obtain a value for the ℓ rec (Θ) at each iterative step in an MCMC run, of course after evaluate it recursively using the forward algorithm.Hence, a posterior distribution to the ℓ rec (Θ), this is, (ℓ (1) rec (Θ), ℓ (2) rec (Θ), ..., ℓ (M) rec (Θ)), where M is the number of iterations used in an MCMC run, can be obtained along with the posterior distributions of the other parameters of the model.Therefore, the posterior distribution of the ℓ (m)  rec (Θ), m = 1, 2, ..., M, can be summarized for obtaining Bayes point estimates, for example, a posterior mean and even a MAP estimate.Algorithm 1 illustrates the computation of the posterior distribution of the recursive log likelihood, adopted from Rabiner (1989), over an MCMC method.
3. Compute the recursive log-likelihood ℓ rec (Θ|y) at the m th iteration as: Given a posterior distribution of the recursive log-likelihood, ℓ (m) rec (Θ), m = 1, 2, ..., M, obtained using Algorithm 1, we can obtain Bayes point estimates from this posterior which will be used later in constructing the proposed DIC rec (Θ).Note that the criterion proposed in this work, DIC rec (Θ), which is based on a complete likelihood, is inspired from the criterion DIC 5 based on the complete-likelihood proposed by Celeux et al. (2006).From the DIC's formula in equation ( 8), we propose two versions to this criterion with different parameterization methods.Under the first parameterization method, we can define the first version as where Θ = Θ = (π, Ā, θ) in the second term of the equation above are the posterior means of the parameters of the HMM obtaining after ending up the MCMC run, i.e Note that an approximation for the ℓ rec ( Θ) is obtained using the Algorithm 1 via just one iteration step, given parameter estimates Θ = (π, Ā, θ) summarized from the MCMC output.The effective number of parameters, denoted by p DIC rec 1 , is then In the second parameterization method, we propose that the second term in the DIC rec 1 can take another form.We can set a maximum a posteriori (MAP) estimate which is derived from the posterior density of the ℓ rec (Θ) itself.In other words, we propose lrec(MAP) (Θ) = log fMAP (y, z|Θ) Therefore, another version of the DIC rec can be proposed as follows and Note that the hidden states z in both DIC rec 1 and DIC rec 2 are dealt with as missing data.Also note that the first terms of the DIC rec 2 and p DIC rec 2 in equations ( 12) and ( 13) respectively are similar to those used with the DIC rec 1 .
The second criterion proposed in this paper is the DIC based on the conditional recursive, denoted by DIC con , which is inspired from the DIC 7 based on conditional likelihood in Celeux (2006).From the relationship in equation ( 13), there is still another possibility for obtaining a closed form for the observed likelihood function for the HMM via the conditional likelihood function f (y|z, Θ).In this setting, obtaining a closed form of f (y|Θ) requires integrating out the hidden states z.
It means, the hidden states z will be treated here as added parameters which will be estimated along with the parameters of the model Θ.Thus, an approximation to the observed log-likelihood based on a conditional likelihood function, ℓ con (Θ), is defined as: Given a posterior sample of each parameter, Θ (m) = (π (m) , A (m) , θ (m) ) and hidden states z (m) induced by an MCMC run, the proposed DIC con is given by where the second term in equation ( 14) represents a MAP estimate of the conditional log-likelihood itself, and its effective number of parameters is

Methods
In this section, we describe the estimation process of parameters of the model and provide a simulation study involving synthetic and real data used in this study.We developed codes using Python (Python: v.2.7.10, see also Rossum (1995)) to generate the synthetic data, perform the estimation process and also model selection using the proposed criteria.

Fitting Algorithm
Before evaluating the proposed criteria, we have to estimate the parameters of the models adopted in this study which are the hidden states z and all parameters, Θ = (π, A, µ, σ 2 ).We use the Gibbs sampler in the estimation process.We need to specify priors to the parameters.The priors with respect to the initial state distributions π and each row } in the transition matrix A are independently given the Dirichlet distribution with hyperparameter δ k = 1, ∀ j, k ∈ K, where K = 2, 3, Fruhwirth-Schnatter ( 2006), { a j.
For the parameters of the state-depended distributions µ and σ 2 , we assumed a normal distribution as a conjugate prior on the mean parameter with hyperparameters λ = 0 and ζ = 0.01, i.e., µ k ∼ N(0, 100), ∀ k = 1, ..., K, and K = 2, 3, and InvGamma with hyper-parameters a = 0.1 and b = 0.1 as a conjugate prior on the variance parameter, i.e., σ 2 k ∼ InvGamma(0.1, 0.1), ∀ k = 1, ..., K, and K = 2, 3.The full conditional posterior distributions of the parameters of the models, see Cappe et al. (2005), are given by where where n j = ∑ T t=1 I(z t = j) denotes the number of observations generated from the state j.The full conditional distribution of the variance parameter σ 2 is given by We used the artificial identifiability constraints (Diebolt and Robert, 1994) on the mean parameter, such that, µ k < µ k+1 , to avoid the label switching problem .We also adopted Gelman and Rubin statistics R (Gelman and Rubin, 1992), which based on multiple chains and the use of the between-sequence and within sequence variances, to check the convergence.

Study Design
We designed a Monte Carlo simulation study to evaluate the performance of our proposed criteria using synthetic data generated from normal HMMs and also a real application involving the waiting time of Old faithful geyser data.

Synthetic Data
In this sub-section, we generate synthetic data from a normal HMM, in which we observe normal variables y t ∼ N(µ k , σ 2 k ), k = 1, 2, ..., K, whose parameters (µ k , σ 2 k ) depend on a hidden state z t such that z 1 , z 2 , ..., z T is a Markov chain.We consider two assumptions.The first assumption involves data from models with a different number of states to examine the influence of diversity in number of states on behaviour of proposed criteria.In this setting, we assume that data have been generated from two and three state normal HMM respectively.In the second assumption, we assume different levels of the heterogeneity in the data by assuming different values of the variance parameter σ 2 for the normal HMMs adopted in the first assumption, to examine the effect of the heterogeneity in the data on the behaviour of proposed criteria.Under the assumptions above, we generate three synthetic databases, each one of length T = 150, with a different level of heterogeneity, from the following two and three state normal HMM: ) , with three cases for the variance parameter σ 2 k , k = 1, 2, which are: σ 2 case 1 = (0.5, 0.2), σ 2 case 2 = (0.5, 1.2) and σ 2 case 3 = (0.5, 4), and, with also three cases of σ 2 k , k = 1, 2, 3, which are: σ 2 case 1 = (0.5, 1, 1.2), σ 2 case 2 = (0.5, 1, 4) and σ 2 case 3 = (0.5, 2, 4).The density plots of these data are shown in the Figures (2-7).

Real Data
This study also includes a real application involving the waiting time of Old Faithful geyser data.The Old Faithful geyser data consist of 299 observations which represent the waiting time, in minutes, between two successive eruptions.Old Faithful is a geyser in the Yellowstone National Park in Wyoming, USA (Hardle, 1991).These data have been used by Robert and Titterington (1998); MacDonald and Zucchini (2009) for modelling normal HMMs with a different number of states.A histogram of these 299 observations is shown in Figure 8 which also shows plots of six fitted densities to be discussed later.

Results
We ran the DG sampler for 12000 iterations and adopted the last 10000 iterations, after discarding 2000 iterations as a burn-in period, to summarize the posterior chain of each conditional.Tables 1 and 2 show the results of the parameter estimates for the two and three state normal HMMs respectively.Regarding the presence of the label switching problem, we saw no evidence of label switching in the MCMC run for both adopted models.Perhaps the reason is that the K! modes are well separated in the high-dimensional parameter space, see Figures (2-7).For checking convergence, the convergence statistic √ R of most parameters was below 1.2.Convergence is also suggested by the parameter estimates in the Table 1 and 2 compared with true parameters.Given MCMC samples to the hidden states z and all parameters Θ = (π, A, θ), we can obtain the posterior distribution of the recursive log-likelihood using Algorithm 1 illustrated in Section 4. In the next step, we will evaluate the performance of the proposed criteria.We need to know whether the proposed criteria are able to select the correct model among competitive models.For this purpose, we assume six test models, as competing models, with a different number of states K test = 2, 3, ..., 7 of each normal HMM.We fit these test models to the data that have been generated from a normal HMM with 2 states, and also to those generated from normal HMM with 3 states (assuming that 2 and 3 normal HMM are the true models), respectively.

Two-State Normal HMM
For 2-state normal HMM, we fit six test models with a different number of states K test = 2, 3, ..., 7 using the Gibbs sampler.Figures 2-4 show the density plots of the six test models and the density of the original model (2-state normal HMM).Table 3 shows the results of all criteria and their the effective numbers of the parameters p DIC , applied to the normal HMMs with 2 state.The values of the criteria are random quantities as they are based on the posterior distributions.Hence, their values might be unstable.For this purpose, we ran 10 independent MCMC runs, and calculated the averages and standard deviations.From Table 3, both recursive versions of the DIC, DIC rec 1 and DIC rec 2 , behave well for selecting the correct model in all heterogeneity cases.On the other hand, the conditional-based DIC, DIC con , began first in selecting the correct model at the first and second levels of heterogeneity and then tended to select a more complicated model with 7 states in the third level of heterogeneity.We can conclude that the DIC con is not stable for non homogeneous data.From Figure 2 with the first heterogeneity level, σ 2 case 1 = (0.5, 0.2) and Figure 3 with the second heterogeneity level, σ 2 case 2 = (0.5, 1.2), it appears there is no a substantial improvement in the fit after the 2-state model.In contrast, in Figure 4 with the third heterogeneity level, σ 2 case 3 = (0.5, 4), there appears to be a fixed improvement after K test = 3 which continues until the model with K test = 7 which was selected by the DIC con .

Three State Normal HMM
Regarding the model with 3 states, we also fit six test models with a different number of states K test = 2, 3, ..., 7 to the normal HMM with three states using the Gibbs sampler.We also used 10 MCMC runs to compute the estimates and the standard deviations of the proposed criteria .We can see from Table 4 that both versions of the DICs rec are also selecting the correct model, i.e.K test = K true = 3, for all the cases of heterogeneity.This suggests, both proposed criteria, DIC rec 1 and DIC rec 2 , were not affected by any level of the assumed heterogeneity and followed a fixed behavior although of the diversity in the number of the states.Conversely, the DIC con behaves in the same way as for the normal HMM with 2 states.It also selects the correct model in the first and second cases of the heterogeneity and then tends to select the more complicated model, K test = 5, in the third heterogeneity level.
Figures 5-7 illustrate the densities of six test models fitting to the synthetic data generated from a 3-state normal HMM.We can clearly see from the Figures 5 and 6 with the heterogeneity levels, σ 2 case 1 = (0.5, 1, 1.2) and σ 2 case 2 = (0.5, 1, 4), respectively that there is no improvement in the fitting after the model with K test = 3.In contrast, a slight improvement is observed in the fitting in Figure 7, K test = 7, with the third heterogeneity level, σ 2 case 3 = (0.5, 2, 4).Nevertheless, the K test = 5 was more favourable state as it corresponds to the smallest value for the criterion DIC con .

Real Application
In this sub-subsection, we look at the performance of the proposed criteria, DICs rec and DIC con , on models fitted to the waiting time of Old Faithful geyser data that have been described in the Section 5. We follow the same scenario used to examine the proposed criteria with synthetic data.We also fit six normal HMMs as test models with K test = 2, 3, ..., 7, to the waiting time of Old Faithful geyser data.We used the Gibbs sampler to estimate these test models.Figure 8 shows the plots of the densities of the six test models fitted to the waiting time of Old Faithful geyser data.
Using the proposed criteria, we try to decide which model adequately fits the data.Each one of the six test models has been estimated using the DG sampler with the same information used to estimate models generated from the simulation data (sub-section 5.1), which are the priors, the burn-in period, the number of adopted iterations for analysis and the number of MCMC runs (10 runs) used for checking the randomness of the criteria values.Table 5 shows the averages of the proposed criteria DIC rec 1 , DIC rec 2 and DIC con , their effective numbers of parameters and the standard deviations appearing in parentheses.We can see from Table 5 that estimates of both DICs rec remain stable over all test states K test compared with estimates of the DIC con which have high standard deviations starting after state K test = 5.We can also see from Table 5 that both versions of the DIC rec select the normal HMM with K test = 5, while the DIC con prefers a more complicated model, K test = 6.Note that the model with K test = 6, as shown in the Figure 8, can provide a more adequate fitting to the data.However, it is not often favoured in applications since a large number of parameters can lead to high variance in parameter estimates and overfitting.
Figure 8. Histograms of the densities fitted of six tested models to a normal HMM fitted to the waiting time of faithful geyser data.The number of adopted iterations is 10000 (main) and discarded is 2000 iterations (burn-in).

Discussion and Future Research
We have illustrated two main ways to obtain a closed form for the observed likelihood of HMMs.Hence, two criteria are proposed.The first proposed criterion, the recursive deviance-based DIC, is based on the observed likelihood obtained by summing all possible states of the complete data likelihood using forward recursion.We also have developed two different parameterization strategies to that criterion.The second proposed criterion, the conditional deviance-based DIC, is based on the observed likelihood obtained by integrating out the hidden states of the conditional likelihood.In order to examine the proposed criteria, we have performed a simulation study involving the assumptions of diversity in the number of states and the heterogeneity in the data, with the goal of understanding the effect of these assumptions on the behavior of the proposed criteria.The simulation study has demonstrated that both versions of the recursive deviance-based DIC are able to select the correct model and they are robust to sensitivity tests conducted in this study.On the other hand, the conditional deviance-based DIC agrees first with the recursive deviance-based DICs in selecting the correct model for the 2 and 3 state models, especially at moderate levels of heterogeneity.It then tends to select a more complex model when the data have a high level of heterogeneity.We can conclude that the high heterogeneity in the data leads to producing new modes and this may explain why more complicated models are selected by some criteria such as the DIC con .In the real application involving the waiting time of the Old Faithful geyser data, we have found that the conditional deviancebased DIC tends to select more complicated models, with 6 states, while, the DICs based on recursive deviances select

Figure 1 .
Figure 1.Dependence structure of a HMM

Figure 4 .
Figure 4. Fitting six test models to the data generated from two state normal HMM with variance σ 2 case 3 = (0.5, 4).

Table 1 .
Parameter estimates of 2-state normal HMMs fitted to three synthetic data sets each one with a different level in the parameter of variance σ 2 .

Table 2 .
Parameter estimates of 3-state normal HMMs fitted to three synthetic data sets each one with a different level in the parameter of variance σ 2 .

Table 3 .
Estimates of the proposed criteria to the 2-state model with three levels of variance.The numbers in brackets indicate standard deviations.

Table 4 .
Estimates of the proposed criteria to the 3-state model with three levels of variance.The numbers in brackets indicates standard deviations.

Table 5 .
Results the estimates of the proposed criteria obtained from fitting a normal HMM with a different number of states, to the waiting time of Old Faithful geyser data.