<?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: Moving window for AR(1) in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245224#M2555</link>
    <description>I'm getting tired I guess :')</description>
    <pubDate>Thu, 21 Jan 2016 16:40:48 GMT</pubDate>
    <dc:creator>Lumanitoc</dc:creator>
    <dc:date>2016-01-21T16:40:48Z</dc:date>
    <item>
      <title>Moving window for AR(1)</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245165#M2548</link>
      <description>&lt;P&gt;Hello !&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to create a &lt;STRONG&gt;moving window for an AR(1)&lt;/STRONG&gt; in SAS/IML&amp;nbsp;. I don't know how to create my loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote an AR(1) (And it is ok) :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Ya=lag(Xa);
Y=Ya[2:nrow(Ya)];
X=Xa[2:nrow(Xa)];
B=inv(t(X)*X)*t(X)*Y;
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Xa is my vector&amp;nbsp;data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So how to do a moving window &lt;STRONG&gt;in half of the data?&lt;/STRONG&gt;&amp;nbsp;I'm a beginer in SAS IML and I have not achieved the loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried like that :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Ya=lag(Xa);
Roll=(nrow(Ya)-1)/2;
do i=1 to Roll;
Y[i]=Ya[i+1:i+Roll];
X[i]=Xa[i+1:i+Roll];
B[i]=inv(t(X[i])*X[i])*t(X[i])*Y[i];
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But it doesnt work and I feel like it's completely wrong and stupid ^^.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Could you help me please ? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you very much !&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 17:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245165#M2548</guid>
      <dc:creator>Lumanitoc</dc:creator>
      <dc:date>2016-01-21T17:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Moving window for AR(1)</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245195#M2550</link>
      <description>&lt;P&gt;I'm sorry but I do not understand your question well enough to respond.&amp;nbsp; Let's use some example data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
X = { 0, 1, 2, 3, 4, 5};
Y = {11,12,13,12,11,10};&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For this example N=6, so you want a rolling window of length 3.&amp;nbsp; Is this a backward window? Centered? Forward?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to interpret your question is to use backward windows and say that B will have 4 elements and that&lt;/P&gt;
&lt;P&gt;B[1] is the coefficient of the linear regression that uses data points 1:3&lt;/P&gt;
&lt;P&gt;B[2] is the coefficient of the linear regression that uses data points 2:4&lt;/P&gt;
&lt;P&gt;B[3] is the coefficient of the linear regression that uses data points 3:5&lt;/P&gt;
&lt;P&gt;B[4] is the coefficient of the linear regression that uses data points 4:6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A loop that implements that condition would look like the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;k = 3;
do i = k to nrow(X);
   idx = (i-k+1):i;
   Xa = X[idx];
   Ya = Y[idx];
   /* compute and store B here */
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jan 2016 14:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245195#M2550</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-01-21T14:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: Moving window for AR(1)</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245212#M2551</link>
      <description>&lt;P&gt;Thank you very much for your answer ! My english isn't really good and I'm a bit lost so I'm happy you understood my pb :).&lt;/P&gt;&lt;P&gt;It was exactly what I expected :&amp;nbsp;I need a backward windows.&lt;/P&gt;&lt;P&gt;Unfortunately I didn't solve my problem yet :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;M&amp;nbsp;data is like :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc iml;
X = {1, 2, 3, 4, 5, 6];
Y = {2, 3, 4 ,5, 6, 7};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm using&amp;nbsp;you're SAS code :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;k = 3;
do i = k to nrow(X);
   idx = (i-k+1):i;
   Xa = X[idx];
   Ya = Y[idx];&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;That souds perfect.&lt;/P&gt;&lt;P&gt;But when I try to calculate my 4 differents Beta I have a new pb :&lt;/P&gt;&lt;P&gt;The B without any loop is like that :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;B=inv(t(X)*X)*t(X)*Y;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But in my case I need to use Xa and Ya and I need to have a vector of 4 different beta.&lt;/P&gt;&lt;P&gt;Do you know how to do that ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your help&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 16:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245212#M2551</guid>
      <dc:creator>Lumanitoc</dc:creator>
      <dc:date>2016-01-21T16:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Moving window for AR(1)</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245215#M2552</link>
      <description>&lt;P&gt;I now see that your ORIGINAL variables are called Xa and Ya, and that you are using X and Y for the local (moving) regression.&amp;nbsp;I'm sorry for the confusion. Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc iml;
Xa = {1, 2, 3, 4, 5, 6};
Ya = {2, 3, 4 ,5, 6, 7};

k = 3;
B = j(nrow(Xa)-k, 1);   /* allocate vector for results */
do i = k to nrow(Xa);
   j = i-k+1;    /* first element */
   idx = j:i;
   X = Xa[idx];
   Y = Ya[idx];
   B[j]=inv(t(X)*X)*t(X)*Y;
end;
print B;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you are new to SAS/IML programming, here are &lt;A href="http://blogs.sas.com/content/iml/2014/08/11/ten-tips-for-learning-sasiml.html" target="_self"&gt;ten tips for learning the SAS/IML language&lt;/A&gt;. You might also want to read the paper &lt;A href="http://support.sas.com/resources/papers/proceedings13/144-2013.pdf" target="_self"&gt;"Getting started with the SAS/IML language."&lt;/A&gt;&amp;nbsp; Good luck!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 16:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245215#M2552</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-01-21T16:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: Moving window for AR(1)</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245217#M2553</link>
      <description>&lt;P&gt;It's working now ! Thank you !&lt;/P&gt;&lt;P&gt;I'll read your paper&amp;nbsp;&lt;/P&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 16:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245217#M2553</guid>
      <dc:creator>Lumanitoc</dc:creator>
      <dc:date>2016-01-21T16:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Moving window for AR(1)</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245220#M2554</link>
      <description>&lt;P&gt;Great.&amp;nbsp; But I think you meant to select my answer as the sollution, rather than your reply. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 16:27:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245220#M2554</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-01-21T16:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: Moving window for AR(1)</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245224#M2555</link>
      <description>I'm getting tired I guess :')</description>
      <pubDate>Thu, 21 Jan 2016 16:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Moving-window-for-AR-1/m-p/245224#M2555</guid>
      <dc:creator>Lumanitoc</dc:creator>
      <dc:date>2016-01-21T16:40:48Z</dc:date>
    </item>
  </channel>
</rss>

