HMM Procedure
Poisson Hidden Markov Model
Let ,
, denote a discrete time-series random variable whose sample space is a set of nonnegative integers.
The variable is said to follow a Poisson HMM distribution, with the parameter
, if it follows a Poisson distribution in each state
. The conditional probability distribution is denoted as
, where
is a positive integer.
The variable is the so-called state and follows the first-order Markov chain; that is,
where denotes the conditional probability. The range of
is a finite set,
. The transition probability from state i to state j is expressed as
The matrix
is called the transition probability matrix (TPM). The last element in the model is the initial state probability vector (ISPV),
, of the first state,
:
Because the state variable is unobservable and follows a Markov chain, and because
is from a Poisson distribution that depends on a different state, the model is called the Poisson hidden Markov model (Poisson HMM).
Consider a univariate Poisson HMM model that has two regimes,
and
.
The initial state probability vector and transition probability matrix are as follows:
%let pi1 = 0.7;
%let a11 = 0.9;
%let a22 = 0.8;
%let lambda1 = 5;
%let lambda2 = 10;
%macro dgpPsHMM(table,T,nSections,seed);
data &table;
call streaminit(&seed.);
secLen = ceil(&T./&nSections.);
do t = 1 to &T.;
sec = floor((t-1)/secLen)+1;
if(t=1) then do;
/* initial probability distribution */
p = &pi1.;
end;
else do;
/* transition probability matrix */
if(lags=1) then p = &a11.;
else p = 1-&a22.;
end;
u = rand("Uniform");
if(u<=p) then s=1;
else s = 2;
if(s=1) then do;
/* at state 1 */
y = rand("Poisson",&lambda1.);
end;
else do;
/* at state 2 */
y = rand("Poisson",&lambda2.);
end;
output;
lags = s;
end;
run;
proc sort data=&table.; by sec t; run;
%mend;
%let T = 1000 ;
%let nSections = 2;
%let seed = 1234;
%dgpPsHMM(hmmpsdt,&T.,&nSections.,&seed.);
data mylib.hmmpsdt;
set hmmpsdt;
run;
The following code estimates a bistate Poisson HMM:
proc hmm data=mylib.hmmpsdt;
id time=t;
model y / type=Poisson nstate=2;
run;
The number of observations and model information are shown in Figure 63.
Figure 63: Number of Observations and Model Information
The estimates of the ISPV are shown in Figure 64.
Figure 64: Estimates of Initial State Probability Vector
| Initial State Probabilities | |
|---|---|
| State | Estimation |
| 1 | 0.71828 |
| 2 | 0.28172 |
The estimates of the TPM are shown in Figure 65.
Figure 65: Estimates of Transition Probability Matrix
| Estimated Transition Probability Matrix | ||
|---|---|---|
| State | 1 | 2 |
| 1 | 0.93328 | 0.06672 |
| 2 | 0.17010 | 0.82990 |
The estimates of the lambda are shown in Figure 66.
Figure 66: Estimates of Lambda of Poisson Distribution
| Lambda | |
|---|---|
| State | Estimation |
| 1 | 5.15141 |
| 2 | 9.84789 |
The estimates of all parameters are shown in Figure 67, which displays columns for parameter name, estimated value, standard error, t value, and p-value.
Figure 67: Parameter Estimates
| Parameter Estimates | ||||
|---|---|---|---|---|
| Parameter | Estimate | Standard Error | t Value | Pr > |t| |
| TPM1_1 | 0.933281 | 0.014084 | 66.26 | <.0001 |
| TPM1_2 | 0.066719 | 0.014084 | 4.74 | <.0001 |
| TPM2_1 | 0.170104 | 0.031678 | 5.37 | <.0001 |
| TPM2_2 | 0.829896 | 0.031678 | 26.20 | <.0001 |
| LAMBDA1 | 5.151408 | 0.108184 | 47.62 | <.0001 |
| LAMBDA2 | 9.847886 | 0.254877 | 38.64 | <.0001 |