# Finding the change point in data from a piecewise linear function

Greetings,

I'm performing research that will help determine the size of observed space and the time elapsed since the big bang. Hopefully you can help!

I have data conforming to a piecewise linear function on which I want to perform two linear regressions. There is a point at which the slope and intercept change, and I need to (write a program to) find this point.

Thoughts?

-
What is the policy on cross-posting? The exact same question was asked on math.stackexchange.com: math.stackexchange.com/questions/15214/… – mpiktas Dec 22 '10 at 17:58

R package strucchange might help you. Look at the vignette, it has a nice overview how to solve similar problems.

-

This is an (offline) changepoint detection problem. Our previous discussion provides references to journal articles and R code. Look first at the Barry and Hartigan "product partition model," because it handles changes in slope and has efficient implementations.

-

If the number of points is not too big, you may try all possibilities. Let's assume that the points are $X_i=(x_i,y_i)$ where $i=1,..,N$. Than, you may loop with $j$ from $2$ to $N-2$ and fit two lines to both $\{X_1,...,X_j\}$ and $\{X_{(j+1)},...,X_N\}$. Finally, you pick $j$ for which the sum of sum of squared residuals for both lines is minimal.

-

Also the segmented package has helped me with similar problems in the past.

-

What is wrong with doing simple non-linear least squares in this case? Am I missing something obvious?

-
I'd say that the derivative of the goal function with respect to the change point parameter is rather un-smooth – Andre Holzner Jul 27 '12 at 13:09