set.seed(1234)
z<-runif(100)
y<-rpois(100,exp(2+1.8*pmax(z-.6,0)))
o<-glm(y~z,family=poisson)
o.seg<-segmented(o,seg.Z=~z)
if (FALSE) plot(z,y)
if (FALSE) points(z,broken.line(o.seg,link=FALSE)$fit,col=2) #ok, but use plot.segmented()!
Run the code above in your browser using DataLab