我看到可以为 OLS 使用 regress/regstats,并且我找到了 L1-Regression (Laplace) 的在线实现,但我似乎不太明白如何实现 t 分布式错误术语。我已经尝试最大化残差的对数似然,但似乎没有提出正确的答案。
classdef student < handle
methods (Static)
% Find the sigma that maximizes the Log Liklihood function given a B
function s = findLonS(r,df)
n = length(r);
% if x ~ t location, scale distribution with df
% degrees of freedom, then (x-u)/sigma ~ t(df)
f = @(s) -sum(log(tpdf(r ./ s, df)));
s = fminunc(f, (r'*r)/n);
end
function B = regress(X,Y,df)
[n,m] = size(X);
bInit = ones(m, 1);
r = (Y - X*bInit);
s = student.findLonS(r, df);
% if x ~ t location, scale distribution with df
% degrees of freedom, then (x-u)/sigma ~ t(df)
f = @(b) -sum(log(tpdf((Y - X*b) ./ s, df)));
options = optimset('MaxFunEvals', 10000, 'TolX', 1e-16, 'TolFun', 1e-16);
[B, fval] = fminunc(f, bInit, options);
end
end
end
与 R 实现(我知道它已经过测试并且是准确的)相比,我得到的解决方案是错误的。
任何关于修复的建议或想法,我可以在哪里找到已经可用的解决方案?