File Exchange

image thumbnail

Two-phase linear regression model

version 2.0 (2.56 KB) by

calculates the parameters of unidimensional two-phase linear regression model

0 Downloads

Updated

View License

INPUTS:
x - vector row with 'x' values
y - vector row with 'y' values
r - expected 'x'-coordinate of break point
if r is empty it is calculated during
the optimisation
p - if p is equal to 1 the fit is plotted
OUTPUT:
th - estimated paremeters of the regression
lines
y_1 = th(1) + th(2) * x
y_2 = th(3) + th(4) * x
r - the estimated break point
SSR - Sum of Squares of the Residuals
SSM - Sum of Squares due to the Model
R^2 can be calculated as RRM/(SSM + SSR)
res - vector of residuals

Comments and Ratings (4)

Hi Dimitar Atanasov,
Thank you for your prompt reply.
I really appreciate it!
This function is very good!

Hi Dimitar Atanasov,

Thanks for your sharing the code, but I still have a couple of questions:

1)When I run function two_phase_lin I get an Error Message:

Undefined function or variable 'fmins'.
Error in two_phase_lin (line 61)
th = fmins(@aim,th0,[],[],x,y);
Could you solve this problem?

2)The second question is about using the function two_phase_lin when I want to find the intersection in a two-phase regression (the mathematical model of bisegmental linear regression using Hinkley’s algorithm). Specifically, I would like to find the point at which the trend of parameter y in terms of x changes. In another word, the trend of the parameter has a first linear phase and then a second linear phase, I want to find the point at which it passes from the first to the second phase. Is it possible to use this function for my problem?

Thanks for your great contribution.

Michele

guochao feng

Updates

2.0

Fixed to use fminsearch instead fmins

MATLAB Release
MATLAB 7 (R14)
Tags Add Tags

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video