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!