graph

Piecewise regression

Theory:

Segmented functions:

  •  y = a_{1} + b_{1}x, (x \le c)
  •  y = a_{2} + b_{2}x, (x > c)

Generalized function:

  •  y =(a_{1} + b_{1}x)[x \le c]+(a_{2} + b_{2}x)[x > c]

where [] is an indicator function: [I] = 1 if I=TRUE, 0 otherwise.

If y is continuous at the breakpoint, x = c:

  •  y =(a_{1} + b_{1}x)[x \le c]+((a_{1} + (b_{2}-b_{1})c) +b_{2}x)[x > c]

Example:

  •  y = - 0.1 + 0.5x, (x \le 1.5)
  •  y = - 2 - 5x, (1.5 < x \le 3)
  •  y = 2 + 0.65x, (x > 3)

Generalized function:

  • y = (- 0.1 + 0.5x)*[x\le1.5] + (- 2 - 5x)*[1.5<x\le3] + (2 + 0.65x)*[x>3]

Coding:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s