The HMM Procedure

PROC HMM Statement

  • PROC HMM DATA=CAS-libref.data-table <options>;

The PROC HMM statement invokes the HMM procedure. You must specify the following option:

DATA=CAS-libref.data-table

names the input data table for PROC HMM to use. CAS-libref.data-table is a two-level name, where

CAS-libref

refers to a collection of information that is defined in the LIBNAME statement and includes the caslib, which includes a path to the data, and a session identifier, which defaults to the active session but which can be explicitly defined in the LIBNAME statement. For more information about CAS-libref, see the section Using CAS Sessions and CAS Engine Librefs.

data-table

specifies the name of the input data table.

You can also specify the following options:

LABELSWITCH=(options)

specifies the order in which to label the states (and components). The label switching problem is a common issue for HMMs because any two HMMs are mathematically equivalent if the only difference between two models is that the states are labeled in different ways. For example, consider the following two univariate bistate Gaussian HMMs, which are described by the parameters StartSet pi comma bold upper A comma bold upper B EndSet, where pi is the initial state probability vector, bold upper A is the transition probability matrix, bold upper B identical-to StartSet mu 1 comma normal upper Sigma 1 comma mu 2 comma normal upper Sigma 2 EndSet, mu 1 and normal upper Sigma 1 are mean and covariance parameters for state 1, and mu 2 and normal upper Sigma 2 are mean and covariance parameters for state 2:

StartLayout 1st Row 1st Column model 1 colon 2nd Column pi equals StartBinomialOrMatrix 0.75 Choose 0.25 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.3 2nd Column 0.7 EndMatrix comma mu 1 equals 1 comma normal upper Sigma 1 equals 1 comma mu 2 equals negative 1 comma normal upper Sigma 2 equals 4 2nd Row 1st Column model 2 colon 2nd Column pi equals StartBinomialOrMatrix 0.25 Choose 0.75 EndBinomialOrMatrix comma bold upper A equals Start 2 By 2 Matrix 1st Row 1st Column 0.7 2nd Column 0.3 2nd Row 1st Column 0.1 2nd Column 0.9 EndMatrix comma mu 1 equals negative 1 comma normal upper Sigma 1 equals 4 comma mu 2 equals 1 comma normal upper Sigma 2 equals 1 EndLayout

In theory, these two models are equivalent, and just the state labels “1” and “2” are switched. When the labels are switched, it is inconvenient to compare any state-related results, such as filtered or smoothed probabilities or decoded path. The LABELSWITCH= option helps you define the order of the state (and component) labels. You can specify the following options:

OUT=CAS-libref.data-table

writes the changes of state labels (and component labels in the case of GM HMMs) to the specified output data table. CAS-libref.data-table is a two-level name, where CAS-libref refers to the caslib and session identifier, and data-table specifies the name of the output data table. For more information about this two-level name, see the DATA= option and the section Using CAS Sessions and CAS Engine Librefs.

REORDER=(number-list)

specifies the new order of the state labels, where the number-list directly specifies the new order of the states. The number-list must be a permutation of numbers 1 to K, where K is the number of states; that is, the size of the number-list must be K, and each element in the number-list must be unique and between 1 and K. For example, REORDER=(3 1 2) implies that the original state 1 becomes state 3, state 2 becomes state 1, and state 3 becomes state 2. If you specify this option, the SORT= option is ignored.

REORDERCOMPONENT=(number-list)

specifies the new order of the component labels in the case of GM HMMs, where the number-list directly specifies the new order of the components for each state. For a K-state M-component GM HMM, the size of the number-list, StartSet n 11 comma ellipsis comma n Subscript 1 upper M Baseline comma ellipsis comma n Subscript upper K Baseline 1 Baseline comma ellipsis comma n Subscript upper K upper M Baseline EndSet, must be upper K upper M, and each sublist StartSet n Subscript i Baseline 1 Baseline comma ellipsis comma n Subscript i upper M Baseline EndSet comma i equals 1 comma ellipsis comma upper K comma must be a permutation of numbers 1 to M—that is, each element in the sublist StartSet n Subscript i Baseline 1 Baseline comma ellipsis comma n Subscript i upper M Baseline EndSet must be unique and between 1 and M. For example, REORDERCOMPONENT=(3 2 1 2 1 3) for a bistate tricomponent GM HMM implies that the original components 1, 2, and 3 for the original state 1 become components 3, 2, and 1, respectively, for the original state 1, and the original components 1, 2, and 3 for the original state 2 become components 2, 1, and 3, respectively, for the original state 2. If you specify this option, the labels for components in each state are not sorted.

SORT=type <(name-list)>

specifies whether to sort the labels of states (and components) and in which type of order. You can specify the following types:

ASC <(name-list)>

sorts the labels in ascending order. You can add a name-list in parentheses in order to sort the labels of states (and components). The possible names that can appear in the name-list are ISPV, TPM, MCP, CPM, LAMBDA, MU, SIGMA, CONST, SDUMMY, LTREND, QTREND, XL, AR, and COV; the meanings of those names are defined in Table 4. Any parameters that are not in the model are ignored.

DESC <(name-list)>

sorts the labels in descending order. You can add a name-list in parentheses in order to sort the labels of states (and components). The possible names that can appear in the name-list are ISPV, TPM, MCP, CPM, LAMBDA, MU, SIGMA, CONST, SDUMMY, LTREND, QTREND, XL, AR, and COV; the meanings of those names are defined in Table 4. Any parameters that are not in the model are ignored.

NONE

does not sort the labels.

By default, if the INMODEL= option is not specified in the SCORE statement, SORT=ASC(SIGMA); otherwise, SORT=NONE. For example, when the ESTISPV option is not specified, the ISPV is not in the stationary HMM; if you include ISPV in the name-list, it is ignored. For a GM HMM, the labels of components for each state are first sorted by the parameters state by state if the REORDERCOMPONENT= option is not specified; then the labels of states are sorted by the parameters that are stacked in the new order of components.

For more details and examples, see the section Label Switching Problem.

OUTSTAT=CAS-libref.data-table

writes the log likelihood and information criteria to the specified output data table. The information criteria include Akaike’s information criterion (AIC), the corrected Akaike’s information criterion (AICC), the Bayesian information criterion (BIC, also referred to as the Schwarz Bayesian criterion, SBC), and the Hannan-Quinn criterion (HQC). CAS-libref.data-table is a two-level name, where CAS-libref refers to the caslib and session identifier, and data-table specifies the name of the output data table. For more information about this two-level name, see the DATA= option and the section Using CAS Sessions and CAS Engine Librefs.

SEED=number

specifies a nonnegative integer to use as the seed for generating random number sequences. When the seed value is 0, random number sequences are generated by using the time of day from the computer’s clock. Seed values greater than 0 generate reproducible random number sequences. By default, SEED=1.

Last updated: May 01, 2023