Data fitting and slop
조회 수: 35 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
dpb
2014년 6월 14일
편집: dpb
2014년 6월 15일
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
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!