KNOWLEDGEBASE - ARTICLE #1101

Segmental linear regression

Segmental linear regression fits one linear regression line to the first part of your data (when X is less than some value X0), and a second linear regression line to the rest (when X is greater than X0). Segmental linear regression ensures that the two lines intersect at X=X0.

Download this Prism file

When segmental linear regression is (and is not) useful

Segmental linear regression is useful when X is time, and you did something X= X0 to change the slope. For example, segmental linear regression makes sense when at time X0 you injected a drug, changed a voltage,  or turned the lights on (or off). In these cases, it makes sense to think that the data follow a different model after the intervention at time X0, and it can make sense to think that the model is linear before and after the intervention. 

If you didn't perform an intervention at time X0, segmental linear regression is unlikely to be useful. Don't use segmental linear regression to analyze a biphasic Scatchard  or Lineweaver-Burk plot. A biphasic Scatchard plot follows a curve, not two intersecting lines. There is no abrupt break point. If you plot the two components separately on a Scatchard plot, neither line comes near the points. You should fit the original data to a two-site binding curve instead.

Fitting segmental linear regression with Prism 5

Create an XY data table. Enter time into X, and your measurements into Y. If you have several experimental conditions, place the first into column A, the second into column B, etc.

After entering data, click Analyze, choose nonlinear regression, choose the panel equations for lines, and choose Segmental linear regression.

Go to the Constraints tab, and enter a value for X0 (the time of the intervention). If you want to ask Prism to fit X0 (rarely useful), go to the constraints tab and set X0 to have no constraint. 

Fitting segmental linear regression with Prism 4

The equation for segmental linear regression is not built-in to Prism 4, but it is easy to add as a user defined equation.  Enter this equation must as a user-defined nonlinear regression model (that's right, nonlinear). 

   Y1=intercept1 + slope1*X
   YatX0=slope1*X0 + intercept1
   Y2=YatX0 + slope2*(X-X0)
   Y= IF(X<X0, Y1, Y2)

 

The first line of the equation defines the first line segment.

The second line computes Y at X=X0. This will be the right end of the first segment. X0 is the X coordinate where the two segments meet.

The third line computes the second line segment. The left end of this segment, must equal the right end of the first segment, so when X=X0, Y1 and Y2 will both equal YatX0.

The fourth line defines Y for any value of X. If X is less than X0, then Y is set equal to Y1 (the first line segment). At larger values of X, Y is set equal to Y2 (the second segment).

To fit this model to your data, you need to provide the nonlinear regression with some initial values. I can't think of any rules that would always work, so you'll need to estimate the slope and intercepts by eye and enter those values.  It is especially important to give a sensible initial value for X0. The other parameters don't matter so much.

Fitting a model with three line segments

Here is an adaptation of the equation to deal with three line segments:

 

Y1 = intercept1 + slope1*X  
YatX0 = slope1*X0 + intercept1
 
Y2 = YatX0 + slope2*(X-X0)
YatX1 =  YatX0 + (X1-X0)*slope2 
 
Y3=YatX1 + slope3*(X-X1)
Y = IF(X<X0, Y1,  IF(X<X1,Y2, Y3))
 
And here is an example file that fits three segments. It takes a lot of fussing with initial values to get it to fit, especially if you are asking Prism to fit the X0 and X1 points (where the slope changes). It is easier to fit the model if you can constrain X1 and X2 to constants based on experimental design.


Keywords: piecewise, bilinear

Explore the Knowledgebase

Analyze, graph and present your scientific work easily with GraphPad Prism. No coding required.