[R] piecewise linear regression

Jonathan Baron baron at cattell.psych.upenn.edu
Sat Nov 10 21:23:15 CET 2001

We sent questionnaires to lots of folks.  The questionnaires
differed in word count (wc).  For each questionnaire, I know wc
and whether the questionnaire was returned or not (status).  It
looks like there is a fixed rate of return when wc is below a
break point, and the rate of return falls off linearly after

I want to do a piecewise linear regression with two pieces
meeting at a common breakpoint.  I think it is important that I
don't specify the breakpoint in advance (although, if I get
desperate, I'll do that).

I've tried to fit a model in nls, several different ways
(including using the "hockey stick" method described in
and I keep getting a "singular gradient matrix" error (sometimes
the "initial" matrix, sometimes not).  I also got the same thing
with very simple artificial data (using a continuous dependent
measure).  For example:


(I know I should use a logistic version, but if this version
doesn't work, I can't imagine that would work.)


Jon Baron
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list