[R-sig-ME] nlmer/nlme with custom selfStart

Lyman, Mark Mark.Lyman at atk.com
Wed Oct 21 18:34:41 CEST 2009


I am trying to fit a nonlinear mixed effects model with a my own
selfStart model. The selfStart model works fine with nls. I have tried
fitting the model in nlme and nlmer, but I have been unable to
understand the error message either produces. The following example
demonstrates my problem. Can anybody tell me what I am doing wrong? I
have had this problem on R 2.9.1, lme4 0.999375-31, and nlme 3.1-92 on
Windows and R 2.9.0, lme4 0.999375-28, and nlme 3.1-90 on Linux.

> library(nlme)
> 
> SSslgr <-
selfStart(~log(epsilon0)+(alpha0)*x-log(1+epsilon0/(alpha0)*9.6770731089
10072*(exp((alpha0)*x)-1)),
+ function(mCall, data, LHS)
+ {
+ xy <- sortedXyData(mCall[["x"]], LHS, data)
+ tmp <- coef(lm(y~x, data=xy))
+ value <- c(exp(tmp[1]), tmp[2])
+ names(value) <- mCall[c("epsilon0", "alpha0")]
+ value
+ }, c("epsilon0", "alpha0"))
> 
> 
> my.data <- expand.grid(x=seq(10, 120, length=12), group=1:50)
> epsilon0 <- 0.0004
> alpha0 <- 0.02
> my.data$y <- exp((rnorm(600)%*%chol(diag(50)%x%(diag(0.01,
12)+0.001)))[1,]+log(epsilon0)+(alpha0)*my.data$x-log(1+epsilon0/(alpha0
)*9.677073108910072*(exp((alpha0)*my.data$x)-1)))
> 
> nls(log(y)~SSslgr(x, epsilon0, alpha0), data=my.data)
Nonlinear regression model
  model:  log(y) ~ SSslgr(x, epsilon0, alpha0) 
   data:  my.data 
 epsilon0    alpha0 
0.0004001 0.0200358 
 residual sum-of-squares: 6.346

Number of iterations to convergence: 3 
Achieved convergence tolerance: 1.508e-07 
> 
> nlme(log(y)~SSslgr(x, epsilon0, alpha0), fixed=epsilon0+alpha0~1,
random=alpha0~1|group, data=my.data)
Error in nlmeCall[[i]] <- NULL : subscript out of bounds
> 
> unloadNamespace("nlme")
> 
> library(lme4)
Warning message:
package 'lme4' was built under R version 2.9.2 
> 
> nlmer(log(y)~SSslgr(x, epsilon0, alpha0) ~ alpha0|group, data=my.data,
start=list(fixef=c(epsilon0=0.0004, alpha0=0.02)))
Error: object 'y' not found
Error in model.frame(data = my.data, formula = log(y),
drop.unused.levels = TRUE) : 
  error in evaluating the argument 'formula' in selecting a method for
function 'model.frame'

Mark Lyman, Statistician
Engineering Systems & Integration, ATK




More information about the R-sig-mixed-models mailing list