- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Good day, I have basic ARIMA forecasting knowledge as like forecasting from a model built of datasets. BUT, the following I do not know how to do:
I am in need of building my ARMA(1,2) model in SAS, specified as:
Xt*(1-8B) = Wt*(1+0.7B+0.6B^2) therefore
Xt = 8*Xt-1 + Wt + 0.7*Wt-1 + 0.6*Wt-2
I have been given observations:
X1=1.5 X2=0.9 X3=0.5 X4=0.12
I want to calculate the 1 to 3 step ahead forecasts and mean square prediction errors.
Is there a way I can do this in SAS?
ANY help would be appreciated. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
One way can be through PROC MODEL. PROC MODEL supports ARMA models through the %AR and %MA macros, a convenient set of code-generating macros designed to add ARMA terms to an equation in PROC MODEL. Additionally, you can give this proc input estimates. Let's go through the process of how you can do this.
First, add your data as a SAS dataset.
data have;
obs = _N_;
input x;
datalines;
1.5
0.9
0.5
0.12
;
run;
Next, let's create an input estimate dataset for PROC MODEL that holds all of your given parameter estimates. It needs to follow a certain format. We'll go over how we can identify what format it needs in a moment. For now, here's what it needs to look like:
data inest;
mu = 1; /* Intercept */
x_l1 = 8; /* p = 1 */
x_m1 = 0.7; /* q = 1 */
x_m2 = 0.6; /* q = 2 */
run;
Note: It's not entirely clear to me, but your equation seems like it has differencing, but you are looking for an ARMA(1,2) model. The estimates above may not be totally right. Either way, the actual model parameters are less important here than the process; you can modify them as needed and the rest will run through just fine.
Finally, we need to create our ARMA model within PROC MODEL and have it generate forecasts for us. The %AR and %MA macros make it very convenient.
proc model data=have;
dependent x; /* Variable to forecast */
parms mu; /* Intercept */
x = mu; /* Set this to x = 0 if you do not want an intercept */
/* Add ARMA terms on x */
%ar(x, 1);
%ma(x, 2);
/* Forecast x */
solve x / estdata = inest /* Input estimate data */
out = outfor /* Output forecast data */
outpredict /* Include predictions */
outactual /* Include actuals */
outresid /* Include residuals */
time = obs /* Include our time variable */
nahead = 1 /* 1-period ahead dynamic forecasting */
;
run;
Our output data can be transposed so it's easier to read.
proc transpose data = outfor out = outfor_tpose
name = var
; by obs; id _TYPE_; var x; run;
Output of one-step ahead forecasts:
obs var ACTUAL PREDICT RESIDUAL 1 x 1.5 1 0.5 2 x 0.9 1 -0.1 3 x 0.5 1 -0.5 4 x 0.12 1 -0.88
But how do I know what the input estimate dataset should look like?
Easiest way: use some test data! Let's grab any dataset and tell PROC MODEL to create a solution for us. It doesn't need to be valid, it just needs to converge and output something we can use as a template. Let's use it on sashelp.air, but rename the variable air to x.
proc model data=sashelp.air(rename=(air = x));
dependent x;
parms mu;
x = mu;
%ar(x, 1);
%ma(x, 2);
fit x / outest=outest;
run;
If we open up outest, we can see what variables are output. All we need to do is create a dataset that looks like this so that PROC MODEL can use it:
_NAME_ _TYPE_ _STATUS_ _NUSED_ mu x_l1 x_m1 x_m2 OLS 0 Converged 144 113.44982117 0.9954123973 -0.390908688 0.2704188551
Note that PROC MODEL does not need _NAME_, _TYPE_, _STATUS_, or _NUSED_ in order to make use of the parameter estimates. Because we used the %AR and %MA macros, we can see that they automatically create variables in PROC MODEL in the following format:
AR: <variable>_l<lag number>
MA: <variable>_m<lag number>