File Exchange

Two-phase linear regression model

version 2.0.0.0 (2.56 KB) by Dimitar Atanasov

Dimitar Atanasov (view profile)

calculates the parameters of unidimensional two-phase linear regression model

Updated 25 Feb 2017

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

Karoline Qasem

Karoline Qasem (view profile)

This is exactly what I wanted. Can you please let me know how to cite it in my journal paper?

Michele Girardi

Michele Girardi (view profile)

Hi Dimitar Atanasov,
I really appreciate it!
This function is very good!

Michele Girardi

Michele Girardi (view profile)

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?

Michele

Michele Girardi

guochao feng

guochao feng (view profile)

 25 Feb 2017 2.0.0.0 Fixed to use fminsearch instead fmins
MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux