Abstract
Hidden Markov models are useful in simultaneously analyzing a longitudinal observation process and its dynamic transition. Existing hidden Markov models focus on mean regression for the longitudinal response. However, the tails of the response distribution are as important as the center in many substantive studies. We propose a quantile hidden Markov model to provide a systematic method to examine the entire conditional distribution of the response given the hidden state and potential covariates. Instead of considering homogeneous hidden Markov models, which assume that the probabilities of between-state transitions are independent of subject- and time-specific characteristics, we allow the transition probabilities to depend on exogenous covariates, thereby yielding nonhomogeneous Markov chains and making the proposed model more flexible than its homogeneous counterpart. We develop a Bayesian approach coupled with efficient Markov chain Monte Carlo methods for statistical inference. Simulations are conducted to assess the empirical performance of the proposed method. The proposed methodology is applied to a cocaine use study to provide new insights into the prevention of cocaine use.
Keywords
1 Introduction
Heterogeneous longitudinal data are frequently encountered in medical, behavioral, socioeconomic, environmental, and psychological sciences. Hidden Markov models (HMMs), which consist of a transition model to describe the dynamic transition of hidden states and a conditional regression model to examine state-specific covariate effects on the response of interest, provide a useful model framework to accommodate heterogeneous and longitudinal features.1–3 HMMs and their variants have elicited extensive attention in various disciplines due to their ability to simultaneously reveal the longitudinal association structure and dynamic heterogeneity of the observed process.4–12 An R package for HMMs was also developed by Visser and Speekenbrink. 13
Despite the rapid development and wide application of HMMs, existing literature has focused on mean regression-based HMMs,1–15 in which the conditional model is a mean regression for examining the effects of potential covariates on the average of the response variable. One problem of mean regression-based models is that they are sensitive to the violation of distributional assumptions, such as nonnormality of the response variable and presence of outliers. Moreover, mean regression-based models only assess covariate effects on the central tendency of the response distribution. However, in many circumstances, covariate effects on the tails of the response distribution are of even more interest than those on the center. A highly comprehensive analysis should perform quantile regression (QR) in the context of HMMs so that the dynamic heterogeneity in the effects of potential covariates on the entire distribution of the response variable can be investigated.
QR16,17 is a valuable alternative to its mean counterpart. It reveals the effects of covariates on the entire conditional distributions of the response variable instead of the effects on its average only. Moreover, QR makes minimal assumptions on the error distribution and thus enables the accommodation of nonnormal data that are frequently encountered in substantive research. QR has received considerable attention in statistical applications and has recently been introduced into HMMs due to its appealing features. For example, Farcomeni 18 used QR to analyze longitudinal data with latent Markov subject-specific parameters and adopted the expectation–maximization algorithm to perform estimation. Marino and coworkers19–21 considered informative missingness and latent dropout-based transitions in the context of quantile HMMs and proposed maximum likelihood approaches for statistical inference. However, the preceding analyses were conducted within a frequentist framework and based on a restrictive assumption that the between-state transitions are homogeneous, which implies that the probability of transitioning from one state to another is independent of subject-specific characteristics and observation times. This homogeneous assumption is unrealistic because the dynamic transition between hidden states is actually influenced by certain covariates in many circumstances. To our knowledge, no existing study has investigated quantile HMMs with nonhomogeneous between-state transitions.
We aim to fill this gap and consider a novel quantile HMM that allows nonhomogeneous transitions of hidden states. A continuation-logit model is proposed to examine how subject- and/or time-specific covariates influence the transition probabilities. We develop a Bayesian approach coupled with Markov chain Monte Carlo (MCMC) sampling techniques to conduct statistical inference because of this approach’s potential in managing highly complex data/model structures and capability to incorporate additional model inputs that stem from the prior distributions of model parameters. The majority of extant studies on Bayesian QR concentrated on cross-sectional data analyses. Yu and Moyeed 22 proposed the asymmetric Laplace distribution (ALD) approach to facilitate the Bayesian inference of QR. Kottas and Gelfand 23 conducted Bayesian QR based on Dirichlet process priors. Dunson et al. 24 developed a substitution likelihood-based approach for QR with latent variables. Readers can also refer to other studies in relevant fields25–32 and the R package bayesQR. 33 The only exception is the study of Koutsourelis, 34 who considered homogeneous quantile HMMs in the Bayesian framework. However, these available methods cannot jointly accommodate all of the abovementioned features. This study is the first to provide a Bayesian method to analyze nonhomogeneous quantile HMMs. We utilize the ALD approach proposed by Yu and Moyeed 22 to facilitate Bayesian inference for the proposed quantile HMMs not only because the approach provides a natural and effective means to model Bayesian QR but also because it enables highly efficient MCMC algorithms for posterior sampling. 35 Moreover, Sriram et al. 36 provided theoretical guarantees for this approach by establishing the posterior consistency of Bayesian QR on the basis of the misspecified asymmetric Laplace density in the case of QR on independent responses.
The proposed model is motivated by the longitudinal analysis of cocaine use as described in the Longitudinal Analysis of Cocaine Use section, in which the response of our primary interest,

Histograms of the days of cocaine use per month (yit) at different time points.
The rest of this article is organized as follows. The next section defines the proposed nonhomogeneous quantile HMM. This is followed by the Bayesian estimation section that describes the Bayesian approach and the implementation of the MCMC algorithm. The model identifiability issue and the associated solution are also discussed. Then, simulation studies to evaluate the empirical performance of the proposed methodology are presented in the Simulation study section. The penultimate section provides an application of the proposed method to a cocaine use study, and the final section concludes the paper.
2 Model settings
Let
We describe the conditional model given the hidden state. For a given quantile level
If S = 1, then models (1) and (2) are the same as the model of Yu and Moyeed,
22
which assumes an ALD for noise. In the following, we omit τ from
Next, we present the model setting for the hidden state process. Following existing literature,
7
,14,15 we assume that
To model the transition probabilities, we assume that the hidden states
Notably, although we assume an ordering of the underlying states, we do not restrict transitions between states. The transition process is allowed to be reversible with transition probability
3 Bayesian estimation
3.1 Identification
Labeling the component membership is an important issue when studying mixture-type models, including HMMs. If label switching occurs, the posterior samples may jump between labeling subspaces in a balanced manner when MCMC iterations are performed, leading to meaningless estimation results. Several methods have been proposed to address the label switching problem.38–40 Among them, imposing an ordering restriction on component means that
3.2 Full likelihood with scale mixture normal representation
Let
On the basis of the model defined by (1) and (2), we have
To simplify MCMC sampling, we represent the ALD of
Accordingly, the conditional likelihood of
Let
3.3 Prior specification and posterior sampling
To conduct a Bayesian analysis, we must initially specify prior distributions for the unknown parameters. Following existing literature,14,15,35 we consider commonly used prior distributions for the unknown parameters as follows:
The main task of posterior inference is to sample from
Step 1: Update hidden states
Similarly, we initialize
Step 2: Update
Step 3: Update initial probability
Step 4: Update transition parameters
Step 5: Update transition parameter
Step 6: Update QR coefficient
By incorporating the prior distribution
That is,
Step 7: Update scale parameter
By incorporating the prior distribution
4. Simulation study
4.1 Simulation 1
In this section, we assess the finite sample performance of the proposed method through numerical studies. We consider an HMM with S = 2 as follows:
The hyperparameters of the prior distributions in (8) are assigned as follows (Prior 1): a = 1;
We use estimated potential scale reduction (EPSR)
45
to check the convergence of the MCMC algorithm. The MCMC algorithm converges within 2000 iterations. Thus, we discard 2000 burn-ins and collect the subsequent 10,000 posterior samples for posterior inference. Tables 1 to 3 present the biases (Bias) and root mean squared errors (RMSE) between the Bayesian estimates and true population values of the unknown parameters at τ = 0.5, 0.25, and 0.75, respectively. Bias and RMSE are close to zero in all the considered scenarios, thus revealing the good performance of the proposed method regardless of the distribution of
Bayesian estimates of the parameters under
RMSE: root mean squared error.
Bayesian estimates of the parameters under
RMSE: root mean squared error.
Bayesian estimates of the parameters under
RMSE: root mean squared error.

Boxplots of the summations of the absolute biases of all unknown parameters under various combinations of (N, T) in the simulation study.
Moreover, we conduct a sensitivity analysis to determine if the Bayesian results are sensitive to the prior specification. We disturb the hyperparameters in Prior 1 as follows (Prior 2): a = 2;
As suggested by an anonymous referee, we compare the results obtained by the proposed method with those obtained by a standard HMM assuming the conditional distribution of
To demonstrate the capability of the quantile HMM in revealing quantile-specific covariate effects, we consider another scenario where the effect of covariates varies with τ as follows: at
4.2 Simulation 2
In this section, we expand the proposed model by relaxing the assumption of ordered hidden states. The conditional model is defined by (1) and (2), and the transition model is a multinomial logit model as follows:
With this transition model, the posterior sampling of the parameters in (11) is slightly modified. For example, the full conditional distribution of
We consider S = 3 and other settings as follows:
A total of 1000 replicated datasets are generated from the abovementioned model under
In practice, we can determine whether the underlying states have a natural order on the basis of subject knowledge, experts’ experience, and/or common sense. For HMMs with ordered hidden states, the continuation-ratio logit model (4) is recommended to consider the ranking information of the hidden states, thereby facilitating a parsimonious transition model and simple interpretation. Otherwise, the multinomial logit model (10) is suggested to model the unordered hidden states.
5 Longitudinal analysis of cocaine use
We applied the proposed quantile HMM to analyze a longitudinal study concerning the prevention of cocaine use and its influential factors. The dataset was collected from the University of California, Los Angeles, Center for Advancing Longitudinal Drug Abuse Research. A total of 321 participants admitted in the West Los Angeles Veterans Affairs Medical Center between 1988 to 1989 were assessed at the baseline, 1 year after treatment, 2 years after treatment, and 12 years after treatment in 2002–2003; thus, T = 4. After deleting individuals with missing entries, N = 298 samples remained. The response of our primary interest,
We considered the following covariates in the conditional QR and continuation-logit transition models.
Among these covariates,
In accordance with a previous study,
12
we fixed S = 3 and regarded the three hidden states as severe, moderate, and minor cocaine addiction states. Then, the proposed model can be written as

Plot of EPSR values in the analysis of cocaine usage study under Prior 1.
Tables 4 and 5 present the estimation results under Priors 1 and 2, respectively. The results obtained with different priors are similar. For the conditional model, we derived the following observations. (i) Formal treatment (
Parameter estimates in the cocaine usage study under Prior 1.
Parameter estimates in the cocaine usage study under Prior 2.
Furthermore, for any given subject i and time t, a transition matrix
Specifically, if the first patient’s baseline state is severe (u = 1), then after one-year treatment, the patient will stay in a severe state (s = 1) with a probability of 0.408, will transition to a moderate state (s = 2) with a probability of 0.238, and will jump to a minor state (s = 3) with a probability of 0.354. Likewise, if the patient’s baseline state is moderate (u = 2) or minor (u = 3), then after one-year treatment, the patient will transition to a severe (s = 1), moderate (s = 2), and minor (s = 3) state with probabilities 0.217 or 0.070, 0.296 or 0.165, and 0.487 or 0.765, respectively.
6 Discussion
We proposed a new quantile HMM to reveal the association structure of a longitudinal process and its dynamic heterogeneity simultaneously. The proposed model accommodates nonhomogeneous transitions between hidden states by allowing the transition probabilities to depend on exogenous covariates. Unlike mean regression that focuses on modeling the central tendency of the response variable, the proposed model provides a systematic and flexible method to analyze the entire conditional distribution of the response given the covariates and hidden states. We developed a Bayesian approach coupled with efficient MCMC methods to conduct statistical inference. Simulation studies demonstrated that the proposed method performs satisfactorily regardless of the error distributions and quantile levels.
The proposed method can be extended in several directions. First, we may consider nonparametric or semiparametric models, such as varying coefficient and additive models, to formulate the conditional QR and/or nonhomogeneous transition parts. Bayesian nonparametric techniques, such as Bayesian P-splines,47,48 can be used to model the nonparametric functions. Second, model/variable selection is an important inference beyond estimation. Bayesian penalized likelihood methods, including but not limited to Bayesian Lasso 49 and spike-and-slab regression,50,51 can be developed to determine the number of hidden states and select important variables in quantile HMMs. Third, Sriram et al. 36 developed the consistency of Bayesian QR by using the misspecified ALD in the case of QR on independent responses. However, whether this result would necessarily carry across to HMMs with longitudinal responses remains unclear. While our simulation studies provided empirical evidence on consistent estimates, we failed to provide theoretical guarantees of posterior consistency in the context of the proposed quantile HMM. This theoretical problem is worthy of investigation in the future. Lastly, the proposed method does not give valid posterior standard deviations. Yang et al. 30 pointed out that the posterior from the working likelihood based on ALD is not the conditional distribution of the parameter given the data; thus, the credible intervals obtained from the posterior do not generally have the right Bayesian confidence level. Our simulation confirmed this result and showed that the credible intervals (not reported) over-cover with almost 100% empirical coverage probabilities at the nominal level of 95%. Yang et al. 30 also proposed a correction method for standard deviations under the cross-sectional (single-state) QR setting. However, their correction method is not directly applicable to the present study due to the dynamic transition feature of the proposed model. How to overcome this limitation is an interesting direction for future research. Substantial efforts are required for the aforementioned extensions.
Footnotes
Acknowledgements
The authors would like to thank two anonymous reviewers, an associate editor, and the editor for constructive comments and helpful suggestions.
Declaration of conflicting interests
The author(s) declared no potential conflicts of interest with respect to the research, authorship, and/or publication of this article.
Funding
The author(s) disclosed receipt of the following financial support for the research, authorship, and/or publication of this article: The work was supported by National Natural Science Foundation of China grants (11671268, 11871376), General Research Fund grants (14303017, 14302519) from the Research Grant Council of Hong Kong Special Administration Region, Yunnan Provincial Science and Technology Department Program 2018FH001-109, and Shanghai Pujiang Program 18PJ1409800.
