Time Series Model Package
Example 32.3 Replaying a Previously Fitted Model
In some cases, it is useful to save the model specification and parameter estimates that are computed during an analysis for later use. For example, you can use the saved model specification and parameter estimates to produce model forecasts at a later stage (possibly with new measurements appended to the original data). This example shows how you can do the following:
Save the model specification and parameter estimates for later use by using the Collect method of the TSMSPEC and TSMPest objects, respectively.
Reuse the previously saved model specification and parameter estimates to configure a TSM object by using the Replay method.
Produce the model forecasts by using this TSM object.
The following statements fit the airline model to the airline series (see Example 32.1 for more information about the airline series and the airline model). The model specification and parameter estimates are stored in the tables mylib.airOSpec and mylib.airEst, respectively.
proc tsmodel data=mylib.air
outobj=(airEst=mylib.airEst airOSpec=mylib.airOSpec) ;
id date interval=month;
var air;
require tsm;
submit;
*** Analysis based on airline model ***;
declare object airModel(tsm);
declare object airSpec(arimaspec);
declare object airEst(tsmpest);
declare object airOSpec(tsmspec);
array diff[2]/nosymbols;
array ma[1]/nosymbols;
*** Set up the airline model spec: ***;
** Model: log(air) ~ (0,1,1)(0,1,1)12 noint ***;
rc = airSpec.Open();
*** Specify differencing orders ***;
diff[1] = 1;
diff[2] = 12;
rc = airSpec.SetDiff(diff,2);
*** Specify moving average orders: q = (1)(12) ***;
*** Use AddMAPoly twice for the two factors ***;
ma[1] = 1;
rc = airSpec.AddMAPoly(ma);
ma[1] = 12;
rc = airSpec.AddMAPoly(ma);
*** Specify NOINT ***;
rc = airSpec.SetOption('noint',1);
*** Specify the log transform ***;
rc = airSpec.SetTransform('log');
*** Done setting up the ARIMA model ***;
rc = airSpec.Close();
*** Set up and run the TSM object ***;
rc = airModel.Initialize(airSpec);
rc = airModel.SetY(Air);
rc = airModel.SetOption('lead',12);
rc = airModel.Run();
*** Output airline model spec and estimates ***;
rc = airEst.Collect(airModel);
rc = airOSpec.Collect(airModel);
endsubmit;
quit;
Output 32.3.1 shows the parameter estimates that are saved in mylib.airEst.
Output 32.3.1: Parameter Estimates for the Airline Model (Partial Output)
| Airline Model Parameter Estimates |
| _EST_ | _STDERR_ | _TVALUE_ | _PVALUE_ |
|---|---|---|---|
| 0.3773 | 0.0820 | 4.6033 | 9.828E-6 |
| 0.5724 | 0.0780 | 7.3361 | 2.17E-11 |
The following statements show how to forecast the airline series by using the previously saved model specification (mylib.airOSpec) and parameter estimates (mylib.airEst).
proc tsmodel data=mylib.air
outobj=(airFor=mylib.airFor)
inobj=(airEst=mylib.airEst airSpec=mylib.airOSpec) ;
id date interval=month;
var air;
require tsm;
submit;
*** Analysis based on the airline model ***;
declare object airModel(tsm);
declare object airSpec(tsminspec);
declare object airEst(tsminest);
declare object airFor(tsmfor);
*** Set up and run the TSM object ***;
rc = airModel.Initialize();
rc = airModel.SetY(Air);
rc = airModel.SetOption('lead',12);
rc = airModel.Replay(airSpec,airEst);
rc = airModel.Run();
*** Output the airline model forecasts ***;
rc = airFor.Collect(airModel);
endsubmit;
quit;
Output 32.3.2 shows the forecasts that are produced according to the fitted model.
Output 32.3.2: Replayed Forecasts (Partial Output)
| Airline Model Predictions |
| DATE | PREDICT | STD | UPPER | LOWER |
|---|---|---|---|---|
| JAN1961 | 450.4 | 16.9215 | 484.5 | 418.2 |
| FEB1961 | 426.1 | 18.8590 | 464.2 | 390.3 |
| MAR1961 | 480.1 | 24.0408 | 528.9 | 434.7 |
| APR1961 | 492.8 | 27.2405 | 548.3 | 441.6 |
| MAY1961 | 509.5 | 30.5863 | 572.0 | 452.1 |
| JUN1961 | 584.2 | 37.6514 | 661.4 | 513.9 |
| JUL1961 | 670.7 | 45.9957 | 765.3 | 585.1 |
| AUG1961 | 668.2 | 48.4237 | 768.0 | 578.3 |
| SEP1961 | 559.6 | 42.6271 | 647.7 | 480.7 |
| OCT1961 | 498.3 | 39.7181 | 580.6 | 425.0 |
| NOV1961 | 431.2 | 35.8240 | 505.5 | 365.2 |
| DEC1961 | 478.9 | 41.3484 | 565.0 | 403.0 |