Skip to content
Prev 172907 / 398502 Next

piecewise linear regression

It actually looked reasonably economical but the output certainly is  
ugly. I see a variety of approaches in the r-help archives. This  
thread discusses two other approaches, degree-one splines from Berry  
and hard coded-coefficients from Lumley:

http://finzi.psych.upenn.edu/R/Rhelp08/archive/118046.html

The Lumley solution has the advantage which he articulates that the  
slopes are more directly interpretabel and in this case you can see  
that yourversion's year slope agrees with Lumley's suggested  
parametrization:

 > m=lm(percent~ year + pmax(year,1996) + pmin(year, 1996), weights=1/ 
se,
+ subset=year>=1988, da=d);
 > m

Call:
lm(formula = percent ~ year + pmax(year, 1996) + pmin(year, 1996),      
data = d, subset = year >= 1988, weights = 1/se)

Coefficients:
      (Intercept)              year  pmax(year, 1996)  pmin(year, 1996)
        1161.3126           -0.2177           -0.3494                NA

More compact output to boot.