필터 지우기
필터 지우기

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

조회 수: 5 (최근 30일)
zahid
zahid 2016년 5월 3일
댓글: Agnieszka Dybalska 2020년 12월 29일
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
jgg
jgg 2016년 5월 3일
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 2020년 12월 29일
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?

댓글을 달려면 로그인하십시오.

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by