Help the Stat Consulting Group by giving a gift

How can I find where to split a piecewise regression?

We might look at this plot and believe that there is a downward trend inuse http://statistics.ats.ucla.edu/stat/stata/faq/nl.dta, clear twoway scatter y x

From the output above, we can see estimates of all four parameters. We can use the estimate for the cut pointnl (y = ({a1} + {b1}*x)*(x < {c}) + /// ({a1} + {b1}*{c} + {b2}*(x-{c}))*(x >= {c})), /// initial(a1 25 b1 -2 c 10 b2 2)Source | SS df MS -------------+------------------------------ Number of obs = 200 Model | 8770.59791 3 2923.53264 R-squared = 0.5169 Residual | 8197.31882 196 41.8230552 Adj R-squared = 0.5095 -------------+------------------------------ Root MSE = 6.467075 Total | 16967.9167 199 85.2659132 Res. dev. = 1310.224 ------------------------------------------------------------------------------ y | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- /a1 | 18.53111 1.382652 13.40 0.000 15.80433 21.2579 /b1 | -1.920463 .2668338 -7.20 0.000 -2.446697 -1.394229 /c | 8.987615 .4400011 20.43 0.000 8.11987 9.855359 /b2 | 2.267615 .1915718 11.84 0.000 1.889808 2.645422 ------------------------------------------------------------------------------ Parameter a1 taken as constant term in model & ANOVA table

In the regression output, we can see that we have the same sum of squares we saw in thegen x2 = x - 8.987615 replace x2 = 0 if x < 8.987615 regress y x x2Source | SS df MS Number of obs = 200 -------------+------------------------------ F( 2, 197) = 105.39 Model | 8770.59777 2 4385.29889 Prob > F = 0.0000 Residual | 8197.31896 197 41.6107562 R-squared = 0.5169 -------------+------------------------------ Adj R-squared = 0.5120 Total | 16967.9167 199 85.2659132 Root MSE = 6.4506 ------------------------------------------------------------------------------ y | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- x | -1.920463 .2023035 -9.49 0.000 -2.319422 -1.521505 x2 | 4.188078 .3214448 13.03 0.000 3.554163 4.821993 _cons | 18.53111 1.275748 14.53 0.000 16.01524 21.04699 ------------------------------------------------------------------------------

We have found the optimal point to split our piecewise function in this scenario. The same process could be used if we wished to fit quadratic or cubic terms, as long as we carefully described the function and its parameters in ourpredict p graph twoway (scatter y x) (scatter p x)

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.