フィルターのクリア

Theil-Sen estimator inorder to fit line

3 ビュー (過去 30 日間)
Math Enthusiast
Math Enthusiast 2018 年 11 月 27 日
編集済み: Math Enthusiast 2018 年 11 月 27 日
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 Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by