

The first part of the procedure is the calculus of $a_1$ and $a_2$ which determines the limits of the segments. This case is treated pp.29-30 in the paper referenced above. PIECEWISE REGRESSION for three not horizontal segments : The case of piecewise linear function, first and third segments horizontal, is treated pp.17-18. Lines(predictor_fit,predict(model,newdata=ame(predictor=pmin(817.4,pmax(441.8,predictor_fit)))))Ī very easy method (no guessed initial value, no iterative calculus) is given in the paper : Here is how it works: predictor <- pmin(817.4,pmax(441.8,x)) In R, we can calculate $x'$ using the pmin() and pmax() functions. However, this is nothing else than a straightforward linear regression of $y$ on a modified predictor I assume that you want a least squares solution. Note how this is constant outside the interval $$, linear within the interval, and continuous. In this case, you want to find parameters $a$ and $b$ such that the functionĪpproximates your observed $y$ well. If you know the $x$ values at which the breaks occur (or are happy with estimating them separately), then let's call them $x_1=441.8$ and $x_2=817.4$. Or slope3 = 0 # slope = 0 after the second breakpoint

parallel to x-axis and I also want the regression to be continuous. I have a large dataset with 3 segments where I want the first and third segment to be without slope, i.e. I want to make a piecewise linear regression in R.
