Our objective is to try different robust weighting function and see the result of robust estimation by nlinfit.
Please try different options of "opts.RobustWgtFun" and observe how beta is close or far from ground truth (b). You may add different types or different amount of noise as well.
Do not hesitate to ask!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Robust nonlinear regression using nlinfit | |
% requirements: Statistics toolbox | |
% this code is based on the example of the help page of nlinfit | |
% Author: Hasan | |
modelfun = @(b,x)(b(1)+b(2)*exp(-b(3)*x)); | |
rng('default') % for reproducibility | |
b = [1;3;2]; % ground truth parameters | |
x = exprnd(2,100,1); | |
y = modelfun(b,x) + normrnd(0,0.1,100,1); % noise addition to check the robustness of the estimation procedure. | |
opts = statset('nlinfit'); % | |
% Now try different options and observe the estimation of parameters (beta) and | |
% compare with ground truth (b) | |
opts.RobustWgtFun = 'fair'; % default is 'bisquare' | |
%opts.RobustWgtFun = 'cauchy'; % | |
%opts.RobustWgtFun = 'huber'; % | |
%opts.RobustWgtFun = 'logistic'; % | |
beta0 = [2;2;2]; | |
beta = nlinfit(x,y,modelfun,beta0,opts) |
Please try different options of "opts.RobustWgtFun" and observe how beta is close or far from ground truth (b). You may add different types or different amount of noise as well.
Do not hesitate to ask!
No comments:
Post a Comment
Please ask if anything is not clear enough..........