How can i perform robust regression by setting my own weight function
조회 수: 6 (최근 30일)
이전 댓글 표시
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
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
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!