HMM Procedure

Poisson Hidden Markov Model

Let y Subscript t, t equals 1 comma ellipsis comma upper T, denote a discrete time-series random variable whose sample space is a set of nonnegative integers.

The variable y Subscript t is said to follow a Poisson HMM distribution, with the parameter lamda Subscript s Sub Subscript t Baseline greater than 0, if it follows a Poisson distribution in each state upper S Subscript t. The conditional probability distribution is denoted as y Subscript t Baseline vertical bar bold upper S Subscript t Baseline equals i tilde normal upper P normal o normal i normal s left parenthesis lamda Subscript bold upper S Sub Subscript t Subscript Baseline right parenthesis, where i is a positive integer.

The variable bold upper S Subscript t is the so-called state and follows the first-order Markov chain; that is,

StartLayout 1st Row  p left-parenthesis bold upper S Subscript t Baseline vertical-bar bold upper S Subscript t minus 1 Baseline comma bold upper S Subscript t minus 2 Baseline comma ellipsis comma bold upper S 1 right-parenthesis equals p left-parenthesis bold upper S Subscript t Baseline vertical-bar bold upper S Subscript t minus 1 Baseline right-parenthesis EndLayout

where p left-parenthesis period vertical-bar period right-parenthesis denotes the conditional probability. The range of bold upper S Subscript t is a finite set, StartSet 1 comma ellipsis comma upper K EndSet. The transition probability from state i to state j is expressed as

StartLayout 1st Row  a Subscript i j Baseline equals p left-parenthesis bold upper S Subscript t Baseline equals j vertical-bar bold upper S Subscript t minus 1 Baseline equals i right-parenthesis EndLayout

The upper K times upper K matrix bold upper A equals StartSet a Subscript i j Baseline EndSet is called the transition probability matrix (TPM). The last element in the model is the initial state probability vector (ISPV), pi, of the first state, bold upper S 1:

StartLayout 1st Row  pi equals StartSet pi Subscript i Baseline equals p left-parenthesis bold upper S 1 equals i right-parenthesis comma i equals 1 comma ellipsis comma upper K EndSet EndLayout

Because the state variable bold upper S Subscript t is unobservable and follows a Markov chain, and because y Subscript t 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 y Subscript t Baseline tilde normal upper P normal o normal i normal s left parenthesis lamda Subscript s Sub Subscript t Subscript Baseline right parenthesis that has two regimes, lamda 1 equals 5 and lamda 2 equals 10.

The initial state probability vector and transition probability matrix are as follows:

StartLayout 1st Row  pi equals StartBinomialOrMatrix 0.7 Choose 0.3 EndBinomialOrMatrix comma bold upper A equals Start 2 By 2 Matrix 1st Row 1st Column 0.9 2nd Column 0.1 2nd Row 1st Column 0.2 2nd Column 0.8 EndMatrix EndLayout

%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

Observation Information
Number of Observations1000
Number of Missing Observations0

Model Information
Type of ModelPoisson HMM
StationaryYes
Number of States2
Number of Dependent Variables1


The estimates of the ISPV are shown in Figure 64.

Figure 64: Estimates of Initial State Probability Vector

Initial State Probabilities
StateEstimation
10.71828
20.28172


The estimates of the TPM are shown in Figure 65.

Figure 65: Estimates of Transition Probability Matrix

Estimated Transition Probability Matrix
State12
10.933280.06672
20.170100.82990


The estimates of the lambda are shown in Figure 66.

Figure 66: Estimates of Lambda of Poisson Distribution

Lambda
StateEstimation
15.15141
29.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
ParameterEstimateStandard
Error
t ValuePr > |t|
TPM1_10.9332810.01408466.26<.0001
TPM1_20.0667190.0140844.74<.0001
TPM2_10.1701040.0316785.37<.0001
TPM2_20.8298960.03167826.20<.0001
LAMBDA15.1514080.10818447.62<.0001
LAMBDA29.8478860.25487738.64<.0001


Last updated: July 09, 2026