I am using the code below to fit a gamma GAMM introducing a variance structure that informs the model that variance of the response variable is much larger in one of the levels of the factor coast than in the other. I am using the gamma distribution to ensure strictly positive fitted values, but I am getting the following error message:

model <- gamm(abundance ~ s(exposure)+s(depth), 
           random = list(coast =~ 1), 
           weights = varIdent(form =~ 1|coast),
           data=census, method="REML")

Error in gamm(abundance ~ s(exposure) + s(depth), random = list(coast = ~1),  : 
  weights must be like glm weights for generalized case

I am assuming the syntax to specify the variance structure needs to change, but I don't know how. Does anyone out there know how to improve this code to avoid the error message?

Very grateful!


Your error message "weights must be like glm weights for generalized case" is saying that if you choose to use Gamm() with a generalized case (which means: using a non-Gaussian probability distribution such as Gamma) then the weights argument should be specified as it would be for GlmmPQL().

The explanation is that GAMM is essentially a wrapper function and depending on how it is used it may utilize the functions nlme() or GlmmPQL(). If you specify a Gaussian distribution for your model then GAMM makes a call directly to nlme() by default. With this default method the weights argument specifies a gls variance structure, because that is what nlme() does (read ?nlme and the weights argument).

If you switch to a generalized distribution (eg, gamma, beta, poisson) GAMM calls to GlmmPQL(), which does have a weights argument but it entirely different (read ?GlmmPQL and the weights argument).

Thus, as far as I know you cannot access gls weights through gamm with a non-Gaussian distribution. If I am mistaken, please somebody correct this.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.