Fitting data with broekn stick regression
Show older comments
Hi.
I have some grape ripening data (sugar versus heat degrees) and want to try and fit a broken stick regression to it, and am wondering if this can be done in Matlab.
The data is quite simple e.g.
x=[1644 1669 1697 1720 1792 1909];
y=[11.9 11.6 12.6 13.4 13.9 14.6],
Basically grape ripening seems to follow a linear increase until some point and then flattens off on another trajectory. I'm wondering how I might use segmented or broken stick regression in matlab.
Answers (3)
Image Analyst
on 6 Jun 2018
Yes your data is quite simple. In fact TOO simple.
x=[1644 1669 1697 1720 1792 1909];
y=[11.9 11.6 12.6 13.4 13.9 14.6]
plot(x, y, 'bs-', 'LineWidth', 2);
grid on;
title('Sugar versus heat degrees', 'fontSize', fontSize);
ylabel('Sugar', 'fontSize', fontSize);
xlabel('heat degrees', 'fontSize', fontSize);

I don't see how you can expect to get any kind of meaningful regression out of this very tiny simple set of data.
Anyway, why would you want to lines instead of a formula for a more continuous function? What does two linear formulas get you over one single model formula, except for a more complicated model where you have to check your x value first before plugging it into one of two models? Not sure why two formulas are desired/advantageous over one formula. Please explain why.
11 Comments
Wendy Cameron
on 6 Jun 2018
Image Analyst
on 6 Jun 2018
I do not see two linear portions in the data you posted. I see 3. Also, did you mean sugar (y) vs. heat (x) (like you said) or heat (y) vs. sugar (x)?
Wendy Cameron
on 7 Jun 2018
Image Analyst
on 7 Jun 2018
Do you think the "kink" or crossing in the linear portions changes with each data set? If so, why would that be? If not, just combine all data sets into one before the fitting. I also do not see how a piecewise linear fit can be said to be better or worse than a Gompert function when you only have a dozen or so data points to try to make that determination with.
John D'Errico
on 7 Jun 2018
Edited: John D'Errico
on 7 Jun 2018
You have insufficient data to justify a broken stick regression. Just wanting something is not sufficient. Were you to try to wrap confidence limits around the result, they would be large enough that the results would be of no value.
If you absolutely insist on a broken stick regression, here it is:
plot(x,y,'-')

Simple. Fast. It reproduces the data exactly. What more could you ask for? ;-)
Seriously, this data merits nothing more then a simple linear regression, or at best a simple interpolation (as given by plot).

Your preference.
Wendy Cameron
on 7 Jun 2018
Edited: Image Analyst
on 7 Jun 2018
Image Analyst
on 7 Jun 2018
I don't see how this is better.

I don't see two distinct linear segments. If you were to split this data into two separate parts/halves with a different slope on each side, which x value would you place the dividing line?
Wendy Cameron
on 8 Jun 2018
Image Analyst
on 8 Jun 2018
Wendy, you evidently did not see my separate answer here: https://www.mathworks.com/matlabcentral/answers/404048-fitting-data-with-broekn-stick-regression#answer_323745
I think it makes intuitive sense and I don't choose (preselect) where the break is - it is computed to be at the point where the left slope is most different from the right slope. If you think about it, this is intuitively where you'd expect the break point to be. Please look at that answer.
Wendy Cameron
on 8 Jun 2018
John D'Errico
on 8 Jun 2018
To reiterate my comment, you simply do not have sufficient information to estimate a broken stick regression, and certainly not to estimate where the breaks occur.
Image Analyst
on 8 Jun 2018
Edited: Image Analyst
on 8 Jun 2018
1 vote
Here's one way to do it. See attached script for demo with noisy data.

Basically I fit lines to the left side and right side and kept track of the slope differences as I varied the point (x value, index) at which the sides were separated. The point where the slope different is greatest is where the lines are most dissimilar and where the crossing occurs.
2 Comments
Wendy Cameron
on 8 Jun 2018
Image Analyst
on 8 Jun 2018
Then, is it time to "Accept this answer"? Or is it still not working?
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!