Data fitting and slop

46 views (last 30 days)
amberly hadden
amberly hadden on 14 Jun 2014
Edited: dpb on 15 Jun 2014
Hi Im interested to plot XY which is a curve also Im interested to fit a best fit curve through data which should follow the data trend as is and then the point from where curve is changing or having maximum curvature, (X-value at that point) and a best fit line from the trend where values are straight to get intercept, After getting intercept I would like to use intercept and slop to draw another model on same graph. please see the attached figure for detailed idea.
Guide me please Thank you

Accepted Answer

dpb
dpb on 14 Jun 2014
Edited: dpb on 15 Jun 2014
That's what is known as "piecewise" or "broken-stick" regression model. To incorporate the breakpoint into the model is often called a "change point" regression. It's relatively simple to do, but is a nonlinear problem.
The change point model starts with the broken-stick model, i.e.
Y=b0 + b1(X) + b2(X-C) + e
where
Y is the response variable,
X is the covariate, and
CP is the change point, i.e. where the break occurs.
e is the error term
To formulate a changepoint model into a functional form that can use to estimate the coefficients b and C, write something like
CP=b(4);
if (X < CP) then
Y = b(1) + b(2)*X;
else
Y = b(1) + b(2)*X + b(3)*(X-CP);
end
as the functional and use Matlab lsqnonlin
I left CP in as the changepoint to make the code read a little more easily while Matlab uses the array for all the coefficients.
ADDENDUM
That is, the "real" function would look more like--
if (X < b(4)) then % b4 is the estimated breakpoint value
Y = b(1) + b(2)*X;
else
Y = b(1) + b(2)*X + b(3)*(X-b(4));
end

More Answers (0)

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!