Flexible Least Squares (FLS) regression 1 是否有MATLAB实现?
我正在寻找一种适当的(好的,最不痛苦的)处理具有时变系数的回归的方法。欢迎所有的想法,但最好的是指向FLS回归实现的指针,因为我在广泛的谷歌搜索后找不到。
答案 0 :(得分:1)
我找到了R code on GitHub FLS回归。我已将其转换为MATLAB,但由于R和MATLAB的功能不同,可能会出现一些错误。现在,我们只需要对其进行测试即可进行最终调整。
function X = fls(A, b, mu, ncap, smoothed)
if isempty(mu)
mu = 1;
end
if isempty(ncap)
ncap = length(b);
end
if isempty(smoothed)
smoothed = true;
end
[m n] = size(A);
M = zeros(n, n, ncap);
E = zeros(n, ncap);
X = zeros(n, ncap);
R = eye(n) * mu;
for j = 1:ncap
Z = linsolve( qr( R + tcrossprod(A(j,:)) ), eye(n) );
M(:,:,j) = mu * Z; % (5.7b)
v = b(j) * A(j,:);
if (j == 1)
p = zeros(n,1);
else
p = mu * E(:,j-1);
end
w = p + v;
E(:,j) = Z * w; % (5.7c)
R = -mu * mu * Z;
diag = R(1:n+1:end);
R(diag) = R(diag) + 2*mu;
end
% Calculate eqn (5.15) FLS estimate at ncap
Q = -mu * M(:,:,ncap-1);
diag = Q(1: (size(Q,1)+1) : end);
Q(diag) = Q(diag) + mu;
Ancap = A(ncap,:);
C = Q + Ancap' * Ancap;
d = mu * E(:,ncap-1) + b(ncap)*Ancap';
X(:,ncap) = C * d;
X(:,ncap) = linsolve(qr(C),d);
if smoothed
% Use eqn (5.16) to obtain smoothed FLS estimates for
% X[,1], X[,2], ..., X[,ncap-1]
for j = 1:ncap-1
l = ncap - j;
X(:,l) = E(:,l) + M(:,:,l) * X(:,l+1);
end
else
X = X(:,ncap);
end
end
function resp = tcrossprod(A)
resp = A * A';
end