[R-sig-ME] Error in nlmer gradient must be of size...

Luciano Selzer luciano.selzer at gmail.com
Tue Nov 29 15:53:00 CET 2011


Ben, Thank you very much.
Luciano



2011/11/12 Ben Bolker <bbolker at gmail.com>:
> Luciano Selzer <luciano.selzer at ...> writes:
>
>>
>> Hi list, i'm trying to fit a mixed effects model to photosynthesis
>> data and I'm getting an error. "Error en nlmer(CO2 ~ fModf(Amax, Aq,
>> LCP, luz) ~ (Amax + Aq + LCP | id), :
>>
>>   gradient matrix must be of size 48 by 3"
>>
>> I've seen a message posted a few days ago but nobody answered. I'm
>> putting a reproducible example below.
>> Thanks in advance for any help you might provide.
>> Luciano
>>
>
>  [snip]
>
>> library(lme4)
>>
>> model <- nls(CO2 ~ Amax*(1 - exp(-Aq * (PPF - LCP))),
>>               start = list(Amax = 3, Aq = 0.01, LCP = 40 ), data = fd)
>>
>> summary(model)
>>
>> fModel <- function(Amax, Aq, LCP, PPF)  Amax*(1 - exp(-Aq * (PPF - LCP)))
>> fModf <- deriv(body(fModel), namevec = c("Amax", "Aq", "LCP", "PPF"),
>>                func = fModel)
>>
>> model2 <- nlmer(CO2 ~ fModf(Amax, Aq, LCP, PPF) ~ (Amax + Aq + LCP|id),
>>                 start = list(fixef= c(Amax = 3, Aq = 0.01, LCP = 40)),
>>                 data = fd, verbose = TRUE)
>>
>> #Error en nlmer(CO2 ~ fModf(Amax, Aq, LCP, PPF) ~ (Amax + Aq + LCP | id),  :
>>
>> #  gradient matrix must be of size 48 by 3
>>
>
>  The error message is actually informative ... you have three
> variables, but your derivative function was based on four variables
> (you included "PPF").  I changed it to
>
> fModf <- deriv(body(fModel), namevec = c("Amax", "Aq", "LCP"),
>               func = fModel)
>
>
>  and proceeded from there; seemed to work fine.
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models




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