How can i perform robust regression by setting my own weight function

2 views (last 30 days)
Dear ALL, Anyone can help to understand to about robustfit command in matlab.In the description of this function it is given that we can define our own weight function but i do not know how can i define my own weight function to run this robust regression.Suppose i have to define my weight function w=weights = @(r) 1./((a + b*abs(r)).^2);where a and b are tuning constants with values a=1,and b=1.With these weights how can i run the robust regression line? Data on x and y variables can be let x = (1:10)'; and y = 10 - 2*x + randn(10,1);
Thanks
  2 Comments
jgg
jgg on 3 May 2016
As it says: you can write your own weight function. The function must take a vector of scaled residuals as input and produce a vector of weights as output. In this case, wfun is specified using a function handle @ (as in @myfun), and the input tune is required.
So, something like
a = 1; b = 1;
w = @(r)(1./((a + b*abs(r)).^2))
should work. Then, call it like:
b = robustfit(x,y,w,1)
You'll need to figure out what the appropriate tuning constant is, though.
Agnieszka Dybalska
Agnieszka Dybalska on 29 Dec 2020
I followed that,
but I have a vector with weight values instead. The code :
b = robustfit(x,y,w1,1)
w1=w % w is a vector
w is a column size as x,y...
doesn't work,
Error using statrobustfit (line 12)
Weight function is not valid.
Error in robustfit (line 114)
[varargout{:}] = statrobustfit(X,y,wfun,tune,wasnan,doconst,priorw,dowarn);
I received that error.
Any ideas what is wrong?

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!