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,psi=.5)
plot(z,y)
points(z,broken.line(o.seg,link=FALSE)$fit,col=2) #just to illustrate, use plot.segmented
Run the code above in your browser using DataLab