I am having difficulty with programming a nonlinear mixed effects model in R using the nlme package. I am not concerned with fitting to data at this point, rather I just want to make sure I have the model coded correctly. The model I am trying to code looks like this in equation form:
y = (a + X)(1 - exp(-bZ))^(c+dX) + e
where X is the random effect varying across a single grouping level we can call g1, Z is a variable in the data, and e is described by N(0, LZ) where L is a parameter estimated from the data.
I am struggling to understand the correct coding syntax, specifically surrounding the (c+dX) and the error structure.
From my best understanding, I can get the code of a simpler equation if we remove the d parameter leaving the equation as:
y = (a + X)(1 - exp(-bZ))^(c+X) + e
m1<-nlme(y~a*(1-exp(-b*Z))^c, fixed=a+b+c~1, random=a+c~1|g1, start=c(a=1,b=1, c=1))
However, I'm not sure how to actually program the equation I want with c+dX. Another concern I have is that the X random effect should be the same random effect just used in two locations of the equation. Is this what will give me that? And lastly, for the error structure, I am completely lost on how to include that in the code and become more confused when reading the R documentation. Any and all help would be greatly appreciated, as I'm certain this is just a lack of understanding on my part. Thank you!