```From: "Michael Robbins" <michael.robbins@us.cibc.com>
Path: news.mathworks.com!newsfeed!WebX
Newsgroups: comp.soft-sys.matlab
Subject: vectorized rolling regression?
Message-ID: <eebdf1d.-1@WebX.raydaftYaTP>
Date: Fri, 16 May 2003 08:06:38 -0400
Lines: 28
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Xref: news.mathworks.com comp.soft-sys.matlab:161138

Has anyone come up with a vectorized rolling linear regression or
robust linear regression?

WINDOW=20;
[L,W]=size(y);
for i=L:-1:20
X=[ones(size(x(i-20:i))) X(i-20:i)];
Y=y(i-20:i);
[b{i},bint{i},r{i},rint{i},stats{i}] = ...
regress(Y,X);
[br{i},statsr{i}] = robustfit(X,Y);
end;

Or even better one that will vectorize this

WINDOW=20;
[L,W]=size(y);
for i=1:L
for j=1:W
X=[ones(size(x(i-20:i,j))) X(i-20:i,j)];
Y=y(i-20:i,j);
[b{i,j},bint{i,j},r{i,j},rint{i,j},stats{i,j}] = ...
regress(Y,X);
[br{i,j},statsr{i,j}] = robustfit(X,Y);
end;

What about just for either regress or robustfit if you don't know how
to do both?

```