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

4 visualizzazioni (ultimi 30 giorni)
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 Commenti
jgg
jgg il 3 Mag 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 il 29 Dic 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?

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by