Piecewise (segmented / broken-line) regression fits continuous straight-line segments joined at estimated breakpoints where the slope changes, with the Davies test for whether a change exists.
Many relationships are linear in pieces with an abrupt change in slope — a dose threshold, a growth breakpoint, a ventilatory threshold, a policy kink. A single straight line misses it and a polynomial smears it into a curve; segmented regression estimates both the breakpoint location and the slope on each side, keeping the fitted curve continuous (the segments meet at the break).
Muggeo's algorithm (the `segmented` package) starts from an ordinary linear fit and iteratively relocates the breakpoint until the fit stops improving, giving the breakpoint a standard error. Because the breakpoint is estimated, the usual t-test on the added term is invalid; the Davies test provides a proper p-value for the null of no slope change.
An X (predictor) and Y (response) numeric column + the number of breakpoints (1–3).
Breakpoint estimate(s) with SE and CI, per-segment slopes with SEs, the Davies test p-value, R² and AIC vs a straight line, and the fitted broken line on the scatter.
A small Davies p and a lower segmented AIC support a genuine slope change. A wide breakpoint CI means the location is poorly determined — don't over-interpret its exact value.
Non-convergence usually means too many breakpoints for the data — reduce the count.