3
$\begingroup$

I am trying to integrate spatial and temporal autocorrelation to my GAMM model using packages mgcv and nlme. The following code runs, but I do not know, how to interpret the “s(x, y)” command results. Can anyone explain it to me in a simple way?

I believe this should take account coordinates in my model. The model contains the following variables: I have 1 smoother, then coordinates, and 4 factor variables. I am using a quasi-poisson model, and I treat site ID (3 years data) as a random factor and have also an offset variable.

M1 <- gamm(sr~ s(smoother 1, fx=FALSE, k=-1, bs="cr")+ 
          s(x, y)+
         factor (variable 1)+
         factor (variable 2)+
         factor (variable 3)+
         factor (variable 4),
       family=quasipoisson,
       random=list(site id=~1),  
       data   = my dataset, offset=log(smoother 2))

This model is with a correlation structure, where I put the $x$ and $y$ coordinates inside, but it did not run unfortunately, although that can also be suitable for me. I also tried corAR1, but this correlation structure also did not work.

M2 <- gamm(sr~ s(smoother 1, fx=FALSE, k=-1, bs="cr")+ 
         factor (variable 1)+
         factor (variable 2)+
         factor (variable 3)+
         factor (variable 4),
       family=quasipoisson,
       correlation = corEXp(form = ~ x + y, nugget = T),
       random=list(site id =~1),  
       data   = my dataset, offset=log(smoother 2))

Can anyone comment on it in simple way? I am ecologist who does not have a very strong statistical background. But I am able to do this kind of R programming.


Thank you for your answer. Yes, there was a type in my code. I corrected it.

Answers for your questions. Here is my actual code:

M <- gamm(sr~ s(AREA, bs="cr")+
         factor (type)+
         factor (year)+
         factor (ditch)+
         factor (bush)+
         factor (stones),
       family=quasipoisson,
       correlation = corExp(form = ~ x + y, nugget = T),
       random=list(fieldid=~1),
       data   = mydataset, offset=log(transect))

And the error message is:

Error in getCovariate.corSpatial(object, data = data): cannot have zero distances in "corSpatial"

What about if I add following code: s(x, y) ? Does this help me out? How to interprete it, because there are now not 1 but 2 smoothers together?

$\endgroup$
4
  • $\begingroup$ There's a typo: it is corExp() note the lowercase x. This looks OK, but you are stressing the fitting functions a lot with the second model: this is going gamm() -> glmmPQL() -> lme() and iterating backwards and forwards, a lot. Note you can leave out the fx = false, k = -1 bits. If you can confirm the problem is not the typo in the correlation function, I'll look closer. Actual error messages and syntactically valid code would be nice: there is no way stuff like this is working as written: list(site id =~1). $\endgroup$ Dec 7, 2016 at 1:57
  • $\begingroup$ Also, I'd be surprised if you can fit this model with gam() directly now that it has a random effects spline basis (bs = "re") and you can include Gaussian process spline basis terms that would probably model the spatial exponential correlation part of your model in the main model component not the covariance structure. I suspect that fitting via gam() will be less problematic than the gamm() -> glmmPQL() -> lme() trick... $\endgroup$ Dec 7, 2016 at 1:59
  • $\begingroup$ Thank you for your answer. Yes, there was a type in my code. I corrected it. Answers for your questions. Here is my actual code:M <- gamm(sr~ s(AREA, bs="cr")+ factor (type)+ factor (year)+ factor (ditch)+ factor (bush)+ factor (stones), family=quasipoisson, correlation = corExp(form = ~ x + y, nugget = T), random=list(fieldid=~1), data = mydataset, offset=log(transect)) And the error message is: Error in getCovariate.corSpatial(object, data = data) : cannot have zero distances in "corSpatial" $\endgroup$
    – Riho Marja
    Jan 4, 2017 at 7:43
  • $\begingroup$ What about if I add following code:s(x, y)? Does this help me out? How to interprate it, because there are now not 1 but 2 smoothers together? $\endgroup$
    – Riho Marja
    Jan 4, 2017 at 7:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.