Theil-Sen estimator inorder to fit line

3 次查看(过去 30 天)
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 个)

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by