<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Implementation of AR(1) Model from ARIMA Procedure in SAS Forecasting and Econometrics</title>
    <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Implementation-of-AR-1-Model-from-ARIMA-Procedure/m-p/547944#M3500</link>
    <description>&lt;P&gt;Thanks for the updates, this really helped me out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know the formula for a ARIMA p=1 q=1 model?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Apr 2019 16:10:28 GMT</pubDate>
    <dc:creator>SAS_Vpt</dc:creator>
    <dc:date>2019-04-02T16:10:28Z</dc:date>
    <item>
      <title>Implementation of AR(1) Model from ARIMA Procedure</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Implementation-of-AR-1-Model-from-ARIMA-Procedure/m-p/415175#M2869</link>
      <description>&lt;P&gt;My objective is to implement a model which was fit using the ARIMA procedure in SAS.&amp;nbsp; Via SAS technical support I was able to have them translate the models functional form (not the best at math)&amp;nbsp;as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;EM&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;FONT face="Microsoft Sans Serif"&gt;&lt;FONT color="#000000"&gt;y&lt;SUB&gt;t &lt;/SUB&gt;= y&lt;SUB&gt;t-1&lt;/SUB&gt; + C + &amp;nbsp;w1x1&lt;SUB&gt;t&lt;/SUB&gt; &amp;nbsp;+ w2x2&lt;SUB&gt;t &amp;nbsp;&lt;/SUB&gt;+ ϕ ((y&lt;SUB&gt;t-1&lt;/SUB&gt; - y&lt;SUB&gt;t-2&lt;/SUB&gt;) - w1x1&lt;SUB&gt;t-1 &lt;/SUB&gt;- w2x2&lt;SUB&gt;t-1&lt;/SUB&gt; ) + a&lt;SUB&gt;t&lt;/SUB&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;EM&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;FONT color="#000000" face="Microsoft Sans Serif"&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;EM&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;FONT color="#000000" face="Microsoft Sans Serif"&gt;The random error term at time t, a&lt;SUB&gt;t&lt;/SUB&gt;, takes on its expected value of 0 and effectively drops out of the equation. &amp;nbsp;In the forecast horizon, when actual values of the lags of y on the right-hand-side of the equation are no longer available, the corresponding predicted value is used in place of the lagged y values.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;FONT color="#000000" face="Microsoft Sans Serif"&gt;To test the above I create fake data and harvested the coefficients from the ARIMA procedures:&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;FONT color="#000000" face="Microsoft Sans Serif"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16772iD1472546771C45F6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;FONT color="#000000" face="Microsoft Sans Serif"&gt;Where C=-15.59089, &lt;FONT color="#000000" face="Microsoft Sans Serif" size="2"&gt;ϕ=-0.57206, w1=-0.02439 and w2=0.05201, the error term a(t) drops out and is essentially 0 as stated in the above.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;Programmatically speaking, if I implement the above equation (if I implemented correctly) I should get the exact output that the ARIMA procedure (with forecast statement) produces.&amp;nbsp; Unfortunately, I am off by more than rounding errors.&amp;nbsp; The example data and manual scoring is in the following code, can someone please correct my mistakes so that I can match the ARIMA forecast output (FORECAST variable to imp_forecast variable).&amp;nbsp; My assumption that the model fit (Actuals data denoted by the "type" variable) is close, as the "arima_forecast_diff" is static during this time at -8.91.&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;*** UPDATE 1 ***&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;FONT color="#ff0000"&gt;Given I was off by a constant for the fitted model (i.e. type='Actuals') I was able to determine the root cause of the difference and isolate to the following: If I add back -C*AR(1) (-1(-15.59089-1*-0.57206))=8.9189245334 which was the exact difference.&amp;nbsp; Still working on the forecasted difference.&amp;nbsp; So, the modeling equation becomes:&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;FONT color="#ff0000"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;FONT face="Microsoft Sans Serif"&gt;&lt;FONT color="#000000"&gt;&lt;EM&gt;y&lt;SUB&gt;t &lt;/SUB&gt;= y&lt;SUB&gt;t-1&lt;/SUB&gt; + C + &amp;nbsp;w1x1&lt;SUB&gt;t&lt;/SUB&gt; &amp;nbsp;+ w2x2&lt;SUB&gt;t &amp;nbsp;&lt;/SUB&gt;+ ϕ ((y&lt;SUB&gt;t-1&lt;/SUB&gt; - y&lt;SUB&gt;t-2&lt;/SUB&gt;) - w1x1&lt;SUB&gt;t-1 &lt;/SUB&gt;- w2x2&lt;SUB&gt;t-1&lt;/SUB&gt; ) + a&lt;SUB&gt;t&lt;/SUB&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp; - C*&lt;EM&gt;&lt;FONT face="Microsoft Sans Serif" size="2"&gt;ϕ&lt;/FONT&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;FONT color="#ff0000"&gt;Which yields (not regarding rounding errors) the exact output from the FORECAST statement in the ARIMA procedure.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT face="Courier New" size="2"&gt;data arima_data;
    format date date9.;
    length type $ 8;
    do date='01JAN2000'd to intnx('month',today(),-12,'B');
        date=intnx('month',date,0,'B');
        type='Actual';
        y=ranuni(28269)*1000;
        x1=ranuni(28123)*1000;
        x2=ranuni(28722)*1000;
        output;
        date=intnx('month',date,0,'E');
    end;
    /* Out of time. */
    do date=date to today();
        date=intnx('month',date,0,'B');
        type='Forecast';
        y=.;
        x1=ranuni(28123)*1000;
        x2=ranuni(28722)*1000;
        output;
        date=intnx('month',date,0,'E');
    end;
run;

proc arima data=arima_data;
    /* Difference model with 2 x terms */;
    identify var=y(1) crosscorr=(x1 x2) noprint;
    /* Including 1 lag. */
    estimate input=(x1 x2) p=1 noest noprint
        ar=-0.57206
        mu=-15.59089
        initval=(-0.02439 x1 0.05201 x2)
    ;
    forecast interval=month id=date out=arima_forecast lead=12 noprint;
run;quit;

data merge_arima_forecast;
    merge arima_data (in=mas)
          arima_forecast (in=fcst keep=date forecast residual)
    ;
    by date;
run;

data implementation;
    set merge_arima_forecast;
    by date;

    /* From SAS Tech Support:
    y(t)=y(t-1) + C + beta1*x1(t) + beta2*x2(t) + AR(1)((y(t-1) - y(t-2)) - beta1*x1(t-1) - beta2*x2(t-1)) + a(t)
    Assumed, C=Mu (-15.59089), AR(1)=Auto Regressive Parameter (-0.57206), beta1 (-0.02439) and beta2 (0.5201)
    a(t) is the error term which is essentially zero and drops out of the model.
    */

    y_lag=lag(y);
    y_lag2=lag2(y);
    x1_lag=lag(x1);
    x2_lag=lag(x2);

    c=-15.59089;
    ar=-0.57206;
    beta1=-0.02439;
    beta2=0.05201;

    /* Actuals */
    *if type='Actual' then imp_forecast=sum(y_lag,c,beta1*x1,beta2*x2,ar*((y_lag-y_lag2)-beta1*x1_lag-beta2*x2_lag));
    /* Updated with -c*ar, matches the ARIMA fit. */
    if type='Actual' then imp_forecast=sum(y_lag,c,beta1*x1,beta2*x2,ar*((y_lag-y_lag2)-beta1*x1_lag-beta2*x2_lag),-c*ar);
    /* Forecast */
    lag_imp_forecast=lag(imp_forecast);
    lag2_imp_forecast=lag2(imp_forecast);
    if type='Forecast' then imp_forecast=sum(lag_imp_forecast,c,beta1*x1,beta2*x2,ar*((lag_imp_forecast-coalesce(y_lag2,lag2_imp_forecast))-beta1*x1_lag-beta2*x2_lag),-c*ar);

    arima_forecast_diff=forecast-imp_forecast;

run;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2017 16:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Implementation-of-AR-1-Model-from-ARIMA-Procedure/m-p/415175#M2869</guid>
      <dc:creator>kybowma</dc:creator>
      <dc:date>2017-11-21T16:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Implementation of AR(1) Model from ARIMA Procedure</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Implementation-of-AR-1-Model-from-ARIMA-Procedure/m-p/547944#M3500</link>
      <description>&lt;P&gt;Thanks for the updates, this really helped me out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know the formula for a ARIMA p=1 q=1 model?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 16:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Implementation-of-AR-1-Model-from-ARIMA-Procedure/m-p/547944#M3500</guid>
      <dc:creator>SAS_Vpt</dc:creator>
      <dc:date>2019-04-02T16:10:28Z</dc:date>
    </item>
  </channel>
</rss>

