The STATESPACE Procedure

Automatic State Space Model Selection

The STATESPACE procedure is designed to automatically select the best state space model for forecasting the series. You can specify your own model if you want, and you can use the output from PROC STATESPACE to help you identify a state space model. However, the easiest way to use PROC STATESPACE is to let it choose the model.

Stationarity and Differencing

Although PROC STATESPACE selects the state space model automatically, it does assume that the input series are stationary. If the series are nonstationary, then the process might fail. Therefore the first step is to examine your data and test to see if differencing is required. (For further discussion of this issue, see the section Stationarity and Differencing.)

The series shown in Figure 35.1 are nonstationary. In order to forecast X and Y with a state space model, you must difference them (or use some other detrending method). If you fail to difference when needed and try to use PROC STATESPACE with nonstationary data, an inappropriate state space model might be selected, and the model estimation might fail to converge.

The following statements identify and fit a state space model for the first differences of X and Y, and forecast X and Y 10 periods ahead:

proc statespace data=in out=out lead=10;
   var x(1) y(1);
   id t;
run;

The DATA= option specifies the input data set and the OUT= option specifies the output data set for the forecasts. The LEAD= option specifies forecasting 10 observations past the end of the input data. The VAR statement specifies the variables to forecast and specifies differencing. The notation X(1) Y(1) specifies that the state space model analyzes the first differences of X and Y.

Descriptive Statistics and Preliminary Autoregressions

The first page of the printed output produced by the preceding statements is shown in Figure 35.2.

Figure 35.2: Descriptive Statistics and VAR Order Selection

The STATESPACE Procedure

Number of Observations200

VariableMeanStandard
Error
 
x0.1443161.233457Has been differenced. With period(s) = 1.
y0.1648711.304358Has been differenced. With period(s) = 1.

The STATESPACE Procedure

Information Criterion for Autoregressive Models
Lag=0Lag=1Lag=2Lag=3Lag=4Lag=5Lag=6Lag=7Lag=8Lag=9Lag=10
149.6978.3877865.51709912.0598615.3695221.7953824.0063829.8887433.5570841.1760647.70222

Schematic Representation of Correlations
Name/Lag012345678910
x+++++++++++++...+.+...
y+++++++++++.+.+.+.....
+ is > 2*std error,  - is < -2*std error,  . is between


Descriptive statistics are printed first, giving the number of nonmissing observations after differencing and the sample means and standard deviations of the differenced series. The sample means are subtracted before the series are modeled (unless the NOCENTER option is specified), and the sample means are added back when the forecasts are produced.

Let and be the observed values of X and Y, and let and be the values of X and Y after differencing and subtracting the mean difference. The series modeled by the STATEPSPACE procedure is

where B represents the backshift operator.

After the descriptive statistics, PROC STATESPACE prints the Akaike’s information criterion (AIC) values for the autoregressive models fit to the series. The smallest AIC value, in this case 5.517 at lag 2, determines the number of autocovariance matrices analyzed in the canonical correlation phase.

A schematic representation of the autocorrelations is printed next. This indicates which elements of the autocorrelation matrices at different lags are significantly greater than or less than 0.

The second page of the STATESPACE printed output is shown in Figure 35.3.

Figure 35.3: Partial Autocorrelations and VAR Model

Schematic Representation of Partial
Autocorrelations
Name/Lag12345678910
x+++.................
y++..................
+ is > 2*std error,  - is < -2*std error,  . is between

Yule-Walker Estimates for Minimum AIC
 Lag=1Lag=2
 xyxy
x0.2574380.2022370.1708120.133554
y0.2921770.469297-0.00537-0.00048


Figure 35.3 shows a schematic representation of the partial autocorrelations, similar to the autocorrelations shown in Figure 35.2. The selection of a second order autoregressive model by the AIC statistic looks reasonable in this case because the partial autocorrelations for lags greater than 2 are not significant.

Next, the Yule-Walker estimates for the selected autoregressive model are printed. This output shows the coefficient matrices of the vector autoregressive model at each lag.

Selected State Space Model Form and Preliminary Estimates

After the autoregressive order selection process has determined the number of lags to consider, the canonical correlation analysis phase selects the state vector. By default, output for this process is not printed. You can use the CANCORR option to print details of the canonical correlation analysis. For an explanation of this process, see the section Canonical Correlation Analysis Options.

After the state vector is selected, the state space model is estimated by approximate maximum likelihood. Information from the canonical correlation analysis and from the preliminary autoregression is used to form preliminary estimates of the state space model parameters. These preliminary estimates are used as starting values for the iterative estimation process.

The form of the state vector and the preliminary estimates are printed next, as shown in Figure 35.4.

Figure 35.4: Preliminary Estimates of State Space Model

The STATESPACE Procedure
Selected Statespace Form and Preliminary Estimates

State Vector
x(T;T)y(T;T)x(T+1;T)

Estimate of Transition Matrix
001
0.2915360.468762-0.00411
0.248690.244840.204257

Input Matrix for Innovation
10
01
0.2574380.202237

Variance Matrix for Innovation
0.9451960.100786
0.1007861.014703


Figure 35.4 first prints the state vector as   X[T;T]   Y[T;T]   X[T+1;T]. This notation indicates that the state vector is

The notation indicates the conditional expectation or prediction of based on the information available at time t, and and are and , respectively.

The remainder of Figure 35.4 shows the preliminary estimates of the transition matrix , the input matrix , and the covariance matrix .

Estimated State Space Model

The next page of the STATESPACE output prints the final estimates of the fitted model, as shown in Figure 35.5. This output has the same form as in Figure 35.4, but it shows the maximum likelihood estimates instead of the preliminary estimates.

Figure 35.5: Fitted State Space Model

The STATESPACE Procedure
Selected Statespace Form and Fitted Model

State Vector
x(T;T)y(T;T)x(T+1;T)

Estimate of Transition Matrix
001
0.2972730.47376-0.01998
0.23010.2284250.256031

Input Matrix for Innovation
10
01
0.2572840.202273

Variance Matrix for Innovation
0.9451880.100752
0.1007521.014712


The estimated state space model shown in Figure 35.5 is

The next page of the STATESPACE output lists the estimates of the free parameters in the and matrices with standard errors and t statistics, as shown in Figure 35.6.

Figure 35.6: Final Parameter Estimates

Parameter Estimates
ParameterEstimateStandard
Error
t Value
F(2,1)0.2972730.1299952.29
F(2,2)0.4737600.1156884.10
F(2,3)-0.019980.313025-0.06
F(3,1)0.2301000.1262261.82
F(3,2)0.2284250.1129782.02
F(3,3)0.2560310.3052560.84
G(3,1)0.2572840.0710603.62
G(3,2)0.2022730.0685932.95


Convergence Failures

The maximum likelihood estimates are computed by an iterative nonlinear maximization algorithm, which might not converge. If the estimates fail to converge, warning messages are printed in the output.

If you encounter convergence problems, you should recheck the stationarity of the data and ensure that the specified differencing orders are correct. Attempting to fit state space models to nonstationary data is a common cause of convergence failure. You can also use the MAXIT= option to increase the number of iterations allowed, or experiment with the convergence tolerance options DETTOL= and PARMTOL=.

Forecast Data Set

The following statements print the output data set. The WHERE statement excludes the first 190 observations from the output, so that only the forecasts and the last 10 actual observations are printed.

proc print data=out;
   id t;
   where t > 190;
run;

The PROC PRINT output is shown in Figure 35.7.

Figure 35.7: OUT= Data Set Produced by PROC STATESPACE

txFOR1RES1STD1yFOR2RES2STD2
19134.815933.62991.186000.9722158.718957.99160.727281.00733
19235.065635.6598-0.594190.9722158.544059.7718-1.227801.00733
19334.703435.5530-0.849620.9722159.047658.57230.475221.00733
19434.662634.7597-0.097070.9722159.777459.22410.553301.00733
19534.405534.8322-0.426640.9722160.511860.15440.357381.00733
19633.821034.6053-0.784340.9722159.875060.8260-0.951021.00733
19734.016433.62300.393330.9722158.469859.4502-0.980461.00733
19835.381933.62511.756840.9722160.678257.91672.761501.00733
19936.295436.05280.242560.9722160.969262.1637-1.194501.00733
20037.894537.14310.751420.9722160.858661.4085-0.549841.00733
201.38.5068.0.97221.61.3161.1.00733
202.39.0428.1.59125.61.7509.1.83678
203.39.4619.2.28028.62.1546.2.62366
204.39.8284.2.97824.62.5099.3.38839
205.40.1474.3.67689.62.8275.4.12805
206.40.4310.4.36299.63.1139.4.84149
207.40.6861.5.03040.63.3755.5.52744
208.40.9185.5.67548.63.6174.6.18564
209.41.1330.6.29673.63.8435.6.81655
210.41.3332.6.89383.64.0572.7.42114


The OUT= data set produced by PROC STATESPACE contains the VAR and ID statement variables. In addition, for each VAR statement variable, the OUT= data set contains the variables FORi, RESi, and STDi. These variables contain the predicted values, residuals, and forecast standard errors for the ith variable in the VAR statement list. In this case, X is listed first in the VAR statement, so FOR1 contains the forecasts of X, while FOR2 contains the forecasts of Y.

The following statements plot the forecasts and actuals for the series:

proc sgplot data=out noautolegend;
   where t > 150;
   series x=t y=for1 / markers
    markerattrs=(symbol=circle color=blue)
    lineattrs=(pattern=solid color=blue);
  series x=t y=for2 / markers
   markerattrs=(symbol=circle color=blue)
   lineattrs=(pattern=solid color=blue);
  series x=t y=x / markers
   markerattrs=(symbol=circle color=red)
   lineattrs=(pattern=solid color=red);
  series x=t y=y / markers
   markerattrs=(symbol=circle color=red)
   lineattrs=(pattern=solid color=red);
  refline 200.5 / axis=x;
run;

The forecast plot is shown in Figure 35.8. The last 50 observations are also plotted to provide context, and a reference line is drawn between the historical and forecast periods.

Figure 35.8: Plot of Forecasts

Plot of Forecasts


Controlling Printed Output

By default, the STATESPACE procedure produces a large amount of printed output. The NOPRINT option suppresses all printed output. You can suppress the printed output for the autoregressive model selection process with the PRINTOUT=NONE option. The descriptive statistics and state space model estimation output are still printed when PRINTOUT=NONE is specified. You can produce more detailed output with the PRINTOUT=LONG option and by specifying the printing control options CANCORR, COVB, and PRINT.

Last updated: August 25, 2017