<?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 Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-AR-1-model-from-ARIMA-Procedure/m-p/415498#M21800</link>
    <description>&lt;P&gt;Hi Ksharp,&amp;nbsp;I posted there originally, however it was flagged as spam by SAS.&amp;nbsp; SAS has sense marked it as a legible question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Implementation-of-AR-1-Model-from-ARIMA-Procedure/m-p/415175#M2869" target="_self"&gt;https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Implementation-of-AR-1-Model-from-ARIMA-Procedure/m-p/415175#M2869&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate your feedback!&lt;/P&gt;</description>
    <pubDate>Wed, 22 Nov 2017 13:11:26 GMT</pubDate>
    <dc:creator>kybowma</dc:creator>
    <dc:date>2017-11-22T13:11:26Z</dc:date>
    <item>
      <title>Implementation of AR(1) model from ARIMA Procedure</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-AR-1-model-from-ARIMA-Procedure/m-p/415259#M21793</link>
      <description>&lt;P&gt;I posted earlier, however it seems that I accidently deleted or it was removed.&amp;nbsp; If this post/question is considered "taboo" or is posted in the wrong community, sorry and&amp;nbsp;please let me know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My objective is to implement a model which was scored with the PROC ARIMA procedure in SAS.&amp;nbsp; Working with SAS Tech support I was able to get a more simple explanation of the backend equation that the ARIMA procedure uses.&amp;nbsp; Here was the correspondence:&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;FONT color="#ff0000"&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;FONT face="Microsoft Sans Serif"&gt;*** Update 1 ***&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&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;Through trial and error I noticed that the above (if I implemented it right) produced a static difference for type='Actuals'.&amp;nbsp; I noticed the difference being -C*&lt;FONT color="#ff0000"&gt;&lt;FONT face="Microsoft Sans Serif" size="2"&gt;ϕ, thus the below code accommodates for this and is now replicating the ARIMA procedure model fit.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&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="#ff0000"&gt;&lt;FONT face="Microsoft Sans Serif" size="2"&gt;New equation:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&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="#ff0000"&gt;&lt;FONT face="Microsoft Sans Serif" size="2"&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; - C&lt;FONT color="#ff0000" face="Microsoft Sans Serif" size="2"&gt;ϕ&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&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="#000000"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;FONT face="Microsoft Sans Serif"&gt;&lt;FONT face="Microsoft Sans Serif" size="2"&gt;&lt;FONT face="Microsoft Sans Serif" size="2"&gt;Here is the parameter estimates which I believe the model to need:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&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="#ff0000"&gt;&lt;FONT face="Microsoft Sans Serif" size="2"&gt;&lt;FONT color="#ff0000" face="Microsoft Sans Serif" size="2"&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/16775i0008E05A42AE7EB5/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;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;FONT color="#000000"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;FONT face="Microsoft Sans Serif"&gt;&lt;FONT face="Microsoft Sans Serif" size="2"&gt;&lt;FONT face="Microsoft Sans Serif" size="2"&gt;Which I believe to imply from the equation above that C=MU=-15.59089, &lt;FONT color="#000000" face="Microsoft Sans Serif" size="2"&gt;ϕ=AR1,1=-0.57206, w1=NUM1=-0.0249 and w2=NUM2=0.05201.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&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="#000000"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;FONT face="Microsoft Sans Serif"&gt;&lt;FONT face="Microsoft Sans Serif" size="2"&gt;&lt;FONT face="Microsoft Sans Serif" size="2"&gt;&lt;FONT color="#000000" face="Microsoft Sans Serif" size="2"&gt;Can someone assist me with calculating the values in the type='Forecast' portion of the below data?&amp;nbsp; My assumption is that this is close, however it is still off.&amp;nbsp; For the type='Actuals' I match to within extreme rounding.&amp;nbsp; Any help would be greatly appreciated.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#000000"&gt;&lt;FONT face="Microsoft Sans Serif"&gt;&lt;FONT face="Microsoft Sans Serif" size="2"&gt;&lt;FONT face="Microsoft Sans Serif" size="2"&gt;&lt;FONT color="#000000" face="Microsoft Sans Serif" 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;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Nov 2017 17:17:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-AR-1-model-from-ARIMA-Procedure/m-p/415259#M21793</guid>
      <dc:creator>kybowma</dc:creator>
      <dc:date>2017-11-21T17:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: Implementation of AR(1) model from ARIMA Procedure</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-AR-1-model-from-ARIMA-Procedure/m-p/415495#M21799</link>
      <description>Post it at Forecast forum, since it is a time series analysis question.</description>
      <pubDate>Wed, 22 Nov 2017 12:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-AR-1-model-from-ARIMA-Procedure/m-p/415495#M21799</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-22T12:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Implementation of AR(1) model from ARIMA Procedure</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-AR-1-model-from-ARIMA-Procedure/m-p/415498#M21800</link>
      <description>&lt;P&gt;Hi Ksharp,&amp;nbsp;I posted there originally, however it was flagged as spam by SAS.&amp;nbsp; SAS has sense marked it as a legible question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Implementation-of-AR-1-Model-from-ARIMA-Procedure/m-p/415175#M2869" target="_self"&gt;https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Implementation-of-AR-1-Model-from-ARIMA-Procedure/m-p/415175#M2869&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate your feedback!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 13:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Implementation-of-AR-1-model-from-ARIMA-Procedure/m-p/415498#M21800</guid>
      <dc:creator>kybowma</dc:creator>
      <dc:date>2017-11-22T13:11:26Z</dc:date>
    </item>
  </channel>
</rss>

