[R-sig-ME] Fwd: nlme package nonlinear mixed model errors - fixed effects only

Brenda Chang yc2800 at columbia.edu
Tue Jun 25 19:06:57 CEST 2013


Hi,

I am trying to use nlme and lme4 packages to perform a nonlinear mixed
effects model, but just with the fixed effects first. (The fixed with
random effects models do work). I created a custom model of the form alpha
+ beta*exp(-gamma*time) with the y variable as "conc".

I would very much appreciate any help or suggestions!

Thank you!

Brenda


library(nlme)
library(lme4)
metdata <- read.csv("metdatf.csv", header=TRUE)
Model <- function(times=times, a=a, b=b, g=g) {
   a + b*exp(-g*times)
}
ModelG <- deriv(
   body(Model)[[2]],
   namevec = c("a", "b", "g"),
   function.arg=Model
)
#use nlme package
fit.fixednlme <- nlme(conc~ModelG(times=times, a=a, b=b, g=g),
                  fixed=times~1,
                  data=metdata,
                  start=c(a=0,b=1,g=0))
#gives error: Error in eval(expr, envir, enclos) : object 'a' not found

#use lme4 package
fit.fixedlme4 <- nlmer(conc ~ ModelG(times, a, b, g), data=metdata,
start=c(a=0,
b=1,g=0), verbose=TRUE)
#gives error: Error: object of type 'symbol' is not subsettable

---------- Forwarded message ----------
From: Brenda Chang <ybc2 at cornell.edu>
Date: Mon, Jun 24, 2013 at 1:42 PM
Subject: nlme package nonlinear mixed model error when fitting only fixed
effects
To: r-sig-mixed-models at r-project.org


Dear all,

I am getting the error "Error in eval(expr, envir, enclos) : object 'a' not
found" when I want to model fixed effects in the *nlme package*:

library(nlme)
metdata <- read.csv("metdataf.csv", header=TRUE)
Model <- function(times=times, a=a, b=b, g=g) {
   a + b*exp(-g*times)
}
ModelG <- deriv(
   body(Model)[[2]],
   namevec = c("a", "b", "g"),
   function.arg=Model
)
fit.fixednlme <- nlme(conc~ModelG(times=times, a=a, b=b, g=g),
                  fixed=times~1,
                  data=metdata,
                  start=c(a=0,b=1,g=0))

I created a custom function of the form alpha+beta*exp(-gamma*time) that I
want nlme to use. I also tried the code below in the* lme4 package* but it
gave me a different error "Error: object of type 'symbol' is not subsettable
"

fit.fixedlme4 <- nlmer(conc ~ ModelG(times, a, b, g), data=metdata,
start=c(a=0,
b=1,g=0), verbose=TRUE)

Thank you so much in advance,

Best,

Brenda


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