SMC Procedure
SUBMITMODEL Statement
SUBMITMODEL dependent-variables <=independent-variables> < / options >;
The SUBMITMODEL statement indicates the start of your user-defined program statements between the SUBMITMODEL and ENDSUBMIT statements or specifies a file that contains your user-defined program statements in the FILE= option. When you specify the SUBMITMODEL statement, the AUXMODEL, INITSTATE, MODEL, PARAMETERS, PRIOR, STATE, STATEVAR, and VAR statements are ignored.
PROC SMC loads the predefined functions or subroutines from the current CMPLIB session and combines them with the functions or subroutines defined in the SUBMITMODEL statement. For more information about the combination of the CMPLIB session and SUBMITMODEL statement, see the section Method 2.
The SUBMITMODEL defines the user-defined functions or subroutines by using either the FILE= option or the user-defined program statements that appear between the SUBMITMODEL and ENDSUBMIT statements. If you specify the FILE= option, you cannot add lines of code for the user-defined program in the SUBMITMODEL statement. If you omit the FILE= option in the SUBMITMODEL statement, then PROC SMC executes all lines of code that are specified between the SUBMITMODEL and ENDSUBMIT statements. For more information, see the section ENDSUBMIT Statement.
To define a state space model, you define FCMP functions and subroutines in the user-defined program. For more information, see the "FCMP Procedure" chapter in the Base SAS Procedures Guide. Each function or subroutine must be named using the format model-name
_
keyword
, where model-name must be identical to the name specified in the NAME= option and keyword identifies the function or subroutine. The total length of the name should not exceed 32 characters. Each function or subroutine must have a specific signature, which consists of the number of arguments, sequence and types of arguments, and return value type. The summary of all the recognized function and subroutine names and their expected behavior is presented in Table 7. Moreover, the type, definition, and size of each argument in the functions and subroutines are summarized in Table 8. Consider the following points when you define a distribution model:
When you define a function or subroutine, the name, type, and order of those arguments must follow the corresponding signature syntax and semantics. For more information about the signature syntax and semantics, see the section Signature Syntax and Semantics of User-Defined Functions and Subroutines.
When the SMC procedure invokes any function or subroutine, it provides the necessary input values according to the specified signature, and it expects the function or subroutine to prepare the output and return it according to the specification of the return values in the signature.
You can use most of the SAS programming statements and SAS functions that you can use in a DATA step to define the FCMP functions and subroutines. However, there are a few differences in the capabilities of the DATA step and the FCMP procedure. To learn more, see the documentation of the FCMP procedure in the Base SAS Procedures Guide.
The dimensions of the state variable and parameter array must match the values specified in the NSTATE= and NPARM= options in the SUBMITMODEL statement. The dimensions of the dependent and independent variable array must match the number of variables specified in the dependent-variables and independent-variables in the SUBMITMODEL statement. The dimensions of the lagged variables must match the XLAG=, YLAG=, and ZLAG= option values. For more information, see Table 8.
Not all the functions and subroutines are required. Whether you need to define a particular function or subroutine depends on the SMC algorithms and other statements (see the section Signature Syntax and Semantics of User-Defined Functions and Subroutines).
The results of the subroutine should be returned in the parameter arguments of the subroutine.
You can specify the following options in the SUBMITMODEL statement after a forward slash (/):
Table 7 shows functions and subroutines that define a state space model, and the subsections after the table provide more details.
Table 7: Functions and Subroutines That Define a State Space Model
| Name | Type | Expected to Return |
|---|---|---|
| name_EVALINIT | Function | LOGPDF of the initialization distribution |
| name_EVALINITP | Function | LOGPDF of the proposal initialization distribution |
| name_EVALMEAS | Function | LOGPDF of the measurement distribution |
| name_EVALNEXTMEAS | Function | LOGPDF of the auxiliary distribution |
| name_EVALPRIO | Function | LOGPDF of the prior distribution |
| name_EVALTRAN | Function | LOGPDF of the transition distribution |
| name_EVALTRANP | Function | LOGPDF of the proposal transition distribution |
| name_LOWERBOUNDS | Subroutine | Lower bounds of the parameters |
| name_SAMPINIT | Subroutine | A sample from the initialization distribution |
| name_SAMPINITP | Subroutine | A sample from the proposal initialization distribution |
| name_SAMPMEAS | Subroutine | A sample from the measurement distribution |
| name_SAMPPRIO | Subroutine | Initial values for the parameters |
| name_SAMPTRAN | Subroutine | A sample from the transition distribution |
| name_SAMPTRANP | Subroutine | A sample from the proposal transition distribution |
| name_UPPERBOUNDS | Subroutine | Upper bounds of the parameters |
Signature Syntax and Semantics of User-Defined Functions and Subroutines
Each function or subroutine has a fixed sequence and type of arguments. The name of each argument is also fixed. All the arguments of the functions and subroutines are listed in Table 8, where n is specified by the NPARM= option, is defined by the NSTATE= option,
is the number of dependent variables,
is defined by the number of independent variables, r is specified by the maximum value in the XLAG=(xlag-options) option, p is specified by the maximum value in the YLAG=(ylag-options) option, and s is specified by the maximum value in the ZLAG=(zlag-options) option. Moreover,
_time refers to the actual time index of the observations (see the section Time Index).
For an array argument array-argument[*] that is one of theta[*], x[*], y[*], and z[*], the ith () element,
array-argument[i], refers to the ith element of the corresponding variable or parameter vector. For a lagged variable array argument lag-array-argument[*] that is one of xlag[*], ylag[*], and zlag[*], lag-array-argument (
) refers to the jth order of lag for the ith element of the corresponding variable whose dimension is denoted by d. For more information about the array or lagged array arguments for the parameter, state variables, dependent variables, and independent variables, see the sections Method 2: Parameters, Method 2: State Variables, Method 2: Dependent Variables, Method 2: Independent Variables, and Method 2: Lagged Variables.
Table 8: List of Arguments in Functions and Subroutines
The details of the argument, signature syntax, and semantics of each function or subroutine are listed as follows:
name_EVALINIT
defines a function that returns the log of the probability density function (LOGPDF) of the initialization distribution, .
Type: FUNCTION
Requirement: Required only when the APF or SIR algorithm is specified and the name_SAMPINITP function is specified
Number of arguments: 7
-
Sequence and type of arguments:
- x[*]
Input numeric array of the current state variables at the initial time step
- xlag[*]
Input numeric array of the lagged state variables before the initial time step
- ylag[*]
Input numeric array of the lagged dependent variables before the initial time step
- z[*]
Input numeric array of the current independent variables at the initial time step
- zlag[*]
Input numeric array of the lagged independent variables before the initial time step
- theta[*]
Input numeric array of the parameters
- _time
Input numeric value of the current actual time index
Here is a sample structure of this function for a model named 'TOY':
function TOY_EVALINIT(x[*],xlag[*],ylag[*],z[*],zlag[*],theta[*],_time);
/*Code to compute LOGPDF based on initialization distribution*/
LOGPDF = <computed logpdf>;
return (LOGPDF);
endsub;
name_EVALINITP
defines a function that returns the LOGPDF of the proposal initialization distribution, .
Type: FUNCTION
Requirement: Required only when the APF or SIR algorithm is specified and the name_SAMPINITP function is specified
Number of arguments: 8
-
Sequence and type of arguments:
- x[*]
Input numeric array of the current state variables at the initial time step
- xlag[*]
Input numeric array of the lagged state variables before the initial time step
- y[*]
Input numeric array of the current dependent variables at the initial time step
- ylag[*]
Input numeric array of the lagged dependent variables before the initial time step
- z[*]
Input numeric array of the current independent variables at the initial time step
- zlag[*]
Input numeric array of the lagged independent variables before the initial time step
- theta[*]
Input numeric array of the parameters
- _time
Input numeric value of the current actual time index
Here is a sample structure of this function for a model named 'TOY':
function TOY_EVALINITP(x[*],xlag[*],y[*],ylag[*],z[*],zlag[*],theta[*],_time);
/*Code to compute LOGPDF based on proposal initialization distribution*/
LOGPDF = <computed logpdf>;
return (LOGPDF);
endsub;
name_EVALMEAS
defines a function that returns the LOGPDF of the measurement distribution, .
Type: FUNCTION
Requirement: Always required
Number of arguments: 8
-
Sequence and type of arguments:
- x[*]
Input numeric array of the current state variables
- xlag[*]
Input numeric array of the lagged state variables
- y[*]
Input numeric array of the current dependent variables
- ylag[*]
Input numeric array of the lagged dependent variables
- z[*]
Input numeric array of the current independent variables
- zlag[*]
Input numeric array of the lagged independent variables
- theta[*]
Input numeric array of the parameters
- _time
Input numeric value of the current actual time index
Here is a sample structure of this function for a model named 'TOY':
function TOY_EVALMEAS(x[*],xlag[*],y[*],ylag[*],z[*],zlag[*],theta[*],_time);
/*Code to compute LOGPDF based on measurement distribution*/
LOGPDF = <computed logpdf>;
return (LOGPDF);
endsub;
name_EVALNEXTMEAS
defines a function that returns the LOGPDF of the auxiliary distribution, .
Type: FUNCTION
Required: Required only when the APF algorithm is specified in one or more of the EVALUATE, FILTER, FORECAST, LEARN, and SMOOTH statements.
Number of arguments: 7
-
Sequence and type of arguments:
- xlag[*]
Input numeric array of the lagged state variables
- y[*]
Input numeric array of the current dependent variables
- ylag[*]
Input numeric array of the lagged dependent variables
- z[*]
Input numeric array of the current independent variables
- zlag[*]
Input numeric array of the lagged independent variables
- theta[*]
Input numeric array of the parameters
- _time
Input numeric value of the current actual time index
Here is a sample structure of this function for a model named 'TOY':
function TOY_EVALNEXTMEAS(xlag[*],y[*],ylag[*],z[*],zlag[*],theta[*],_time);
/*Code to compute LOGPDF based on the approximated density function*/
LOGPDF = <computed logpdf>;
return (LOGPDF);
endsub;
name_EVALPRIO
defines a function that defines the LOGPDF of the prior distribution, .
Type: FUNCTION
Required: Required only when the PMCMC method is specified in the LEARN statement
Number of arguments: 1
-
Sequence and type of arguments:
- theta[*]
Input numeric array of the parameters
Here is a sample structure of this function for a model named 'TOY':
function TOY_EVALPRIO(theta[*]);
/*Code to compute LOGPDF based on the prior distribution*/
LOGPDF = <computed logpdf>;
return (LOGPDF);
endsub;
name_EVALTRAN
defines a function that returns LOGPDF of the transition distribution, .
Type: FUNCTION
Requirement: Required only when the APF or SIR algorithm is specified and the name_SAMPTRANP subroutine is specified
Number of arguments: 7
-
Sequence and type of arguments:
- x[*]
Input numeric array of the current state variables
- xlag[*]
Input numeric array of the lagged state variables
- ylag[*]
Input numeric array of the lagged dependent variables
- z[*]
Input numeric array of the current independent variables
- zlag[*]
Input numeric array of the lagged independent variables
- theta[*]
Input numeric array of the parameters
- _time
Input numeric value of the current actual time index
Here is a sample structure of this function for a model named 'TOY':
function TOY_EVALTRAN(x[*],xlag[*],ylag[*],z[*],zlag[*],theta[*],_time);
/*Code to compute LOGPDF based on the transition distribution*/
LOGPDF = <computed logpdf>;
return (LOGPDF);
endsub;
name_EVALTRANP
defines a function that returns the LOGPDF of the proposal transition distribution, .
Type: FUNCTION
Requirement: Required only when the APF or SIR algorithm is specified and the name_SAMPTRANP subroutine is specified
Number of arguments: 8
-
Sequence and type of arguments:
- x[*]
Input numeric array of the current state variables
- xlag[*]
Input numeric array of the lagged state variables
- y[*]
Input numeric array of the current dependent variables
- ylag[*]
Input numeric array of the lagged dependent variables
- z[*]
Input numeric array of the current independent variables
- zlag[*]
Input numeric array of the lagged independent variables
- theta[*]
Input numeric array of the parameters
- _time
Input numeric value of the current actual time index
Here is a sample structure of this function for a model named 'TOY':
function TOY_EVALTRANP(x[*],xlag[*],y[*],ylag[*],z[*],zlag[*],theta[*],_time);
/* Code to compute LOGCDF based on the proposal transition distribution*/
LOGPDF = <computed logpdf>;
return (LOGPDF);
endsub;
name_LOWERBOUNDS
defines a subroutine that returns lower bounds for the parameters. To indicate the output numeric array, the line "outargs theta;" must appear after the line "subroutine name_LOWERBOUNDS(theta[*]);".
Type: SUBROUTINE
Requirement: Not always required
Number of arguments: 1
-
Sequence and type of arguments:
- theta[*]
Output numeric array of the parameters.
theta[i]assigns the lower bound for the ith parameter.
If this subroutine is not defined, then the SMC procedure assumes a lower bound of for each parameter. If a lower bound of
is returned for a parameter
, then PROC SMC assumes that
(strict inequality). If a missing value or no value is returned for one parameter, then PROC SMC assumes that there is no lower bound for that parameter (this is equivalent to a lower bound of
).
Here is a sample structure of this subroutine for a model named 'TOY' that has three parameters:
subroutine TOY_LOWERBOUNDS(theta[*]);
outargs theta;
theta[1] = <lower bound for the first parameter>;
/*the second parameter is missing */
theta[3] = <lower bound for the third parameter>;
endsub;
name_SAMPINIT
defines a subroutine that returns the initial state variables drawn from the initialization distribution, . To indicate the output numeric arrays, the line "outargs x, xlag;" must appear after the line "subroutine name_SAMPINIT(x[*],xlag[*],ylag[*],z[*],zlag[*],theta[*],_time);".
Type: SUBROUTINE
-
Requirement: Required only when either of the following conditions is satisfied:
The BF algorithm is specified.
The APF or SIR algorithm is specified and the name_SAMPINITP subroutine is not specified.
Number of arguments: 7
-
Sequence and type of arguments:
- x[*]
Output numeric array of the current state variables at the initial time step.
x[i]assigns the initial value of the ith state variable.- xlag[*]
Output numeric array of the lagged state variables before the initial time step
xlag(
) assigns the initial value of the jth order of lag for the ith state variable.
- ylag[*]
Input numeric array of the lagged dependent variables before the initial time step
- z[*]
Input numeric array of the current independent variables at the initial time step
- zlag[*]
Input numeric array of the lagged independent variables before the initial time step
- theta[*]
Input numeric array of the parameters
- _time
Input numeric value of the current actual time index
Here is a sample structure of this subroutine for a model named 'TOY' that has three state variables:
subroutine TOY_SAMPINIT(x[*],xlag[*],ylag[*],z[*],zlag[*],theta[*],_time);
outargs x, xlag;
/*Code to generate x and xlag based on the sampling initial distribution*/
x[1] = <generated first state variable>;
x[2] = <generated second state variable>;
x[3] = <generated third state variable>;
endsub;
name_SAMPINITP
defines a subroutine that returns the initial state variables drawn from the proposal initialization distribution, . To indicate the output numeric arrays, the line "outargs x, xlag;" must appear after the line "subroutine name_SAMPINITP(x[*],xlag[*],y[*],ylag[*],z[*],zlag[*],theta[*],_time);".
Type: SUBROUTINE
Required: Required only when the APF or SIR algorithm is specified and the proposal initialization distribution,
, is different from the initialization distribution,
Number of arguments: 8
-
Sequence and type of arguments:
- x[*]
Output numeric array of the current state variables at the initial time step.
x[i]assigns the initial value of the ith state variable.- xlag[*]
Output numeric array of the lagged state variables before the initial time step.
xlag(
) assigns the initial value of the jth order of lag for the ith state variable.
- y[*]
Input numeric array of the lagged dependent variables at the initial time step
- ylag[*]
Input numeric array of the lagged dependent variables before the initial time step
- z[*]
Input numeric array of the current independent variables at the initial time step
- zlag[*]
Input numeric array of the lagged independent variables before the initial time step
- theta[*]
Input numeric array of the parameters
- _time
Input numeric value of the current actual time index
Here is a sample structure of this subroutine for a model named 'TOY' that has three state variables:
subroutine TOY_SAMPINITP(x[*],xlag[*],y[*],ylag[*],z[*],zlag[*],theta[*],_time);
outargs x, xlag;
/*Code to generate x and xlag based on the sampling initial distribution*/
x[1] = <generated first state variable>;
x[2] = <generated second state variable>;
x[3] = <generated third state variable>;
endsub;
name_SAMPMEAS
defines a subroutine that returns the current dependent variables drawn from the measurement distribution, . To indicate the output numeric array, the line "outargs y;" must appear after the line "subroutine name_SAMPMEAS(x[*],xlag[*],y[*],ylag[*],z[*],zlag[*],theta[*],_time);".
Type: SUBROUTINE
Requirement: Required when the FORECAST statement is specified
Number of arguments: 8
-
Sequence and type of arguments:
- x[*]
Input numeric array of the current state variables
- xlag[*]
Input numeric array of the lagged state variables
- y[*]
Output numeric array of the current dependent variables.
y[i]assigns the value of the ith current dependent variable.- ylag[*]
Input numeric array of the lagged dependent variables
- z[*]
Input numeric array of the current independent variables
- zlag[*]
Input numeric array of the lagged independent variables
- theta[*]
Input numeric array of the parameters
- _time
Input numeric value of the current actual time index
Here is a sample structure of this subroutine for a model named 'TOY' that has one dependent variable:
subroutine TOY_SAMPMEAS(x[*],xlag[*],y[*],ylag[*],z[*],zlag[*],theta[*],_time);
outargs y;
/*Code to generate x based on the sampling observation distribution*/
y[1] = <the first generated dependent variable>;
endsub;
name_SAMPPRIO
defines a subroutine that returns the initial values of the parameters. To indicate the output numeric array, the line "outargs theta;" must appear after the line "subroutine name_SAMPPRIO(theta[*]);".
Type: Subroutine
Requirement: Always required
Number of arguments: 1
-
Sequence and type of arguments:
- theta[*]
Output numeric array of the parameters.
theta[i]assigns the initial value of the ith parameter.
Here is a sample structure of this subroutine for a model named 'TOY' that has three parameters:
subroutine TOY_SAMPPRIO(theta[*]);
outargs theta;
/*Code to initialize parameters*/
theta[1] = <initial value of the first parameter>;
theta[2] = <initial value of the second parameter>;
theta[3] = <initial value of the third parameter>;
endsub;
name_SAMPTRAN
defines a subroutine that returns the current state variables drawn from the transition distribution, . To indicate the output numeric array, the line "outargs x;" must appear after the line "subroutine name_SAMPTRAN(x[*],xlag[*],ylag[*],z[*],zlag[*],theta[*],_time);".
Type: SUBROUTINE
-
Requirement: Required only when one of the following conditions is satisfied:
The BF algorithm is specified.
The APF or SIR algorithm is specified and the name_SAMPTRANP subroutine is not specified.
The FORECAST statement is specified.
Number of arguments: 7
-
Sequence and type of arguments:
- x[*]
Output numeric array of the current state variables.
x[i]assigns the value of the ith current state variable.- xlag[*]
Input numeric array of the lagged state variables
- ylag[*]
Input numeric array of the lagged dependent variables
- z[*]
Input numeric array of the current independent variables
- zlag[*]
Input numeric array of the lagged independent variables
- theta[*]
Input numeric array of the parameters
- _time
Input numeric value of the current actual time index
Here is a sample structure of this subroutine for a model named 'TOY' that has three state variables:
subroutine TOY_SAMPTRAN(x[*],xlag[*],ylag[*],z[*],zlag[*],theta[*],_time);
outargs x;
/*Code to generate x based on the sampling transition distribution*/
x[1] = <the first generated state variable>;
x[2] = <the second generated state variable>;
x[3] = <the third generated state variable>;
endsub;
name_SAMPTRANP
defines a subroutine that returns the current state variables drawn from the proposal transition distribution, . To indicate the output numeric array, the line "outargs x;" must appear after the line "subroutine name_SAMPTRANP(x[*],xlag[*],y[*],ylag[*],z[*],zlag[*],theta[*],_time);".
Type: SUBROUTINE
Requirement: Required only when the APF or SIR algorithm is specified and the proposal transition distribution,
, is different from the transition distribution,
.
Number of arguments: 9
-
Sequence and type of arguments:
- x[*]
Output numeric array of the current state variables.
x[i]assigns the value of the ith current state variable.- xlag[*]
Input numeric array of the lagged state variables
- y[*]
Input numeric array of the current dependent variables
- ylag[*]
Input numeric array of the lagged dependent variables
- z[*]
Input numeric array of the current independent variables
- zlag[*]
Input numeric array of the lagged independent variables
- theta[*]
Input numeric array of the parameters
- _time
Input numeric value of the current actual time index
Here is a sample structure of this subroutine for a model named 'TOY' that has three state variables:
subroutine TOY_SAMPTRANP(x[*],xlag[*],y[*],ylag[*],z[*],zlag[*],theta[*],_time);
outargs x;
/*Code to generate x based on the sampling transition distribution*/
x[1] = <the first generated state variable>;
x[2] = <the second generated state variable>;
x[3] = <the third generated state variable>;
endsub;
name_UPPERBOUNDS
defines a subroutine that returns upper bounds for the parameters. To indicate the output numeric array, the line "outargs theta;" must appear after the line "subroutine name_UPPERBOUNDS(theta[*]);".
Type: Subroutine
Requirement: Not always required
Number of arguments: 1
-
Sequence and type of arguments:
- theta[*]
Output numeric array of the parameters.
theta[i]assigns the upper bound for the ith parameter.
Here is a sample structure of this subroutine for a model named 'TOY' that has three parameters:
subroutine TOY_UPPERBOUNDS(theta[*]);
outargs theta;
theta[1] = <upper bound for the first parameter>;
theta[2] = <upper bound for the second parameter>;
theta[3] = <upper bound for the third parameter>;
endsub;
If this subroutine is not defined, then the SMC procedure assumes that there is no upper bound for any of the parameters. If an upper bound of is returned for a parameter
, then PROC SMC assumes that
(strict inequality). If a missing value or no value is returned for one parameter, then PROC SMC assumes that there is no upper bound for that parameter (this is equivalent to an upper bound of
).