Tuesday, September 25, 2012

Robust nonlinear regression with nlinfit (Statistics toolbox required)

Our objective is to try different robust weighting function and see the result of robust estimation by nlinfit.

% 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)
view raw my_nlinfit.m hosted with ❤ by GitHub


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..........