Skip to content
Prev 315041 / 398506 Next

piece-wise linear regression nls function

Instead of reinventing the wheel, why not use the "segmented" package?
Having  stored your data in a data frame "X" I did:

require(segmented)
m1 <- lm(FM ~ BMIJS,data=X)
m2 <- segmented(m1,seg.Z=~BMIJS,psi=list(BMIJS=35))

which worked instantaneously.  The break point is estimated as 41.580, with
a standard error of 2.094  I then did:

with(X, plot(BMIJS,FM))
plot(m2,add=TRUE)

which seems to look as good as one can expect.

I must say however that the plot of your data does not look to me
as though a broken-stick model is appropriate.  Why not just a straight 
line?

     cheers,

         Rolf Turner
On 01/10/2013 02:33 PM, John Sorkin wrote: