[R] question about nlme...

Jeff Harring harring at umd.edu
Tue Feb 9 15:30:19 CET 2010


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



More information about the R-help mailing list