I am looking for R code to be able to fit a linear-linear piecewise
model with person-specific changepoint. I have searched the web, but
have not been able to locate any code.
Below is my attempt at some code:
chgpt = function(a1,a2,a3,gam,wave){
yht=numeric(10)
y1=(wave <= gam)*(a1+(a2*wave))
y2=(wave > gam)*((a1+(a2-a3)*gam)+a3*wave)
yhat=y1+y2
return(yht)
}
nl.dat <- nlme(y ~ chgpt(a1,a2,a3,gam,wave)~wave|id,
data = ndat,
fixed = a1 + a2 + a3 + gam,
random = a1 + a2 + a3,
start = c(a1=10,a2=5,a3=1,gam=4.5))
summary(n1.dat)
I would appreciate any advice on this code or guidance as to where to
search for example code to fit this nonlinear mixed effects model.
Many thanks,
Jeff Harring
--
**********************************************************
Jeffrey R. Harring, Assistant Professor
Department of Measurement, Statistics & Evaluation (EDMS)
1230 Benjamin Building
University of Maryland
College Park, MD 20742-1115
Phone: 301.405.3630
Fax: 301.314.9245
Email: harring at umd.edu
Web: http://www.education.umd.edu/EDMS/fac/Harring/webpage.html
Jeff Harring wrote:> > I am looking for R code to be able to fit a linear-linear piecewise > model with person-specific changepoint. I have searched the web, but > have not been able to locate any code. > > .. > I would appreciate any advice on this code or guidance as to where to > search for example code to fit this nonlinear mixed effects model. > >I had good success in fitting piecewise functions with continuous derivatives, e.g. a logistic function with a linear continuation. Things did not work well with nlme when there was a discontinuity. There is an discussion from 2000 right from Douglas Bates' and Mary Lindstrom's mouth for nls and the hockey-stick, so it could be possible to get is to work with good data. http://www.biostat.wustl.edu/archives/html/s-news/2000-04/msg00209.html Also check http://markmail.org/message/6p63i4cxfk6enlp5 Dieter -- View this message in context: http://n4.nabble.com/question-about-nlme-tp1474561p1474765.html Sent from the R help mailing list archive at Nabble.com.