How to access robust fit weights when using fit with Robust: 'Bisquare' , instead of robustfit?
9 次查看(过去 30 天)
显示 更早的评论
While robustfit gives as an output robust weights, it does not have an option of using a custom fit function as an input.
Since I needed to fit specific models to my data, I used instead fit, which is more flexible int hat sense, with robust option activated. However, fit does not print out robust fit related statistics, nor weights. I would like to have access to weights, in order to compare several models via weighted least square error. I tried to calculate weights myself, but the outcome does not seem right.
ft = fittype(......);
opts = fitoptions(......);
opts.Robust = 'Bisquare';
[fitresult, gof, output] = fit(x,y,ft,opts);
res = output.residuals;
[Q,~] = qr(output.Jacobian,0);
h = min(.9999, sum(Q.*Q,2)); %leverage
res_adj = res./sqrt(1-h); %adjusted residuals
K = 4.685; %tuning constant
res_adj_sorted = sort(abs(res_adj));
s = median(res_adj_sorted(max(1,p):end)) / 0.6745;
u=res_adj./(K*s); % standardized residuals
w = zeros(size(res));
for i = 1:length(res)
if abs(u(i,:)) < 1
w(i,:) = (1-u(i,:)^2)^2;
else
w(i,:) = 0;
end
end
0 个评论
回答(1 个)
Gábor Holló
2024-6-4
编辑:Gábor Holló
2024-6-4
Based on this description: https://uk.mathworks.com/help/stats/robustfit.html#mw_84ae84c6-63ed-4c22-93bb-4d0064b07c51
% get the residuals
residuals = output.residuals;
% the vector of leverage values
h = leverage(x);
% median absolute deviation
MAD_calc = mad(residuals, 1);
% an estimate of the standard deviation of the error term
ss = MAD_calc/0.6745;
% tuning constant
tune = 4.685;
r = residuals ./ (tune * ss * sqrt(1 - h));
% the calculated bisquared weights
weights = (abs(r) < 1) .* (1 - r.^2).^2;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!