Theil-Sen estimator inorder to fit line
13 views (last 30 days)
Show older comments
Hi,
I have attached a data file,consisting of two columns,with x and y data
and also the graph,I obtained with the data.
Red color->indicates the raw data
Green color-> indicates the Theil Sen Regression line
I would be really glad,if someone can check the below code and let me know the changes to be done,so that Theil sen regression line is fitted properly to the data.
I am exactly not sure,if the line equation would be in the form y = b*x, where b is the slope obtained from Theil Sen regression estimator.
I have written the following code:
data = load(textFile);
b = Thenil_Sen_Regress(data(:,1),data(:,2));
scatter(data(:,1),data(:,2),'r');
hold on;
plot(data(:,1),b*data(:,1),'g','LineWidth',3);
The function Theil_Sen_Regress() is as follows:
function b = Theil_Sen_Regress(x,y)
[N c]=size(x);
Comb = combnk(1:N,2);
deltay=diff(y(Comb),1,2);
deltax=diff(x(Comb),1,2);
theil=diff(y(Comb),1,2)./diff(x(Comb),1,2);
b=median(theil);
0 Comments
Answers (0)
See Also
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!