Segmented regression or broken stick regression

7 ビュー (過去 30 日間)
Wendy Cameron
Wendy Cameron 2018 年 6 月 8 日
コメント済み: Wendy Cameron 2018 年 6 月 8 日
An example of my data is as follows: xdata=[1150 1200 1263.3 1333.3 1429 1497.3 1567.8 1608.3 1643.5 1668.8]; ydata=[6.2 7.2 8.6 10.4 11.2 12.9 13.3 13.3 13.5 13.55];
A scatter plot shows there are arguably 2 linear sections to the graph, the first steeper than the second. I would like to find out the slope of the first linear section (always positive) and the break point (can vary). the slope the second section may be zero, positive or negative (depending on the weather).
I tried the on line suggested solution but get an error message as shown. xdata=[1150 1200 1263.3 1333.3 1429 1497.3 1567.8 1608.3 1643.5 1668.8]; ydata=[6.2 7.2 8.6 10.4 11.2 12.9 13.3 13.3 13.5 13.55]; >> coefs = @(xbreak) [ones(numel(xdata),1),min(xdata,xbreak)-xbreak]\ydata; >> errfun = @(xbreak) norm([ones(numel(xdata),1),min(xdata,xbreak)-xbreak]*coefs(xbreak) - ydata); >> xbreak = fminbnd(errfun,0,1) Error using horzcat Dimensions of matrices being concatenated are not consistent.
Error in @(xbreak)norm([ones(numel(xdata),1),min(xdata,xbreak)-xbreak]*coefs(xbreak)-ydata)
Error in fminbnd (line 228) x= xf; fx = funfcn(x,varargin{:});
Hoping someone can help me?
Kind regards, Wendy

採用された回答

Image Analyst
Image Analyst 2018 年 6 月 8 日
I've already given you an answer here in this answer.
I'm attaching it again where I'm using your data in the m-file above.
  1 件のコメント
Wendy Cameron
Wendy Cameron 2018 年 6 月 8 日
Thank you. This seems to work well and thank you particularly for the many explanations of what each step was doing which really meant I learnt a lot from this as well as solving my problem.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDiscrete Data Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by