I have data which I suspect follows a power function over time. It is collected from several units which have different intercepts. Therefore I'd like to do a mixed model with the parameters of the power function as fixed effects and intercept as random effect. Can I do this with lme4::nlmer
? If not, can I do it in another way?
To illustrate with a reproducible example, say I have this data, D
:
x = 1:100
y1 = 7 + 2 * x^0.4 + rnorm(100); plot(y1, main='y1') # unit 1
y2 = 4 + 2 * x^0.4 + rnorm(100); plot(y2, main='y2') # unit 2
y3 = 1 + 2 * x^0.4 + rnorm(100); plot(y3, main='y3') # unit 3
D = data.frame(y=c(y1, y2, y3), id=rep(c(1,2,3), each=100), time=rep(x, 3))
plot(y ~ time, D, main='all') # combined data
I can model this as a power function with the nls
function with a common intercept:
nls(y ~ k + a * time ^ b, D, start=c(a=1, b=1, k=5))
This gives me estimates like a=1.3 (it was 2), b=0.47 (it was 0.4) and k=5.4 (it was 1, 4 and 7). I'd like to do something like this:
nlmer(y ~ k + a * time ^ b + (1|id), D) # doesn't work of course
I'm going to add more random effects later. This is just a minimal reproducible example.
nlmer
is for. I believe the problem is that you are trying to usenlmer()
incorrectly. See?nlmer
regarding the use ofderiv()
to properly develop your formula. If you want someone to do this for you, try asking on stack overflow. $\endgroup$