I have count data of a species and would like to analyze the population trend over the years. The species was count twice a year (early summer and late summer --> column "season") for several years on different sites. The model I have set up is the following:

gam(count ~ s(site, bs = "re") + s(year) + season, data=mydata, family = nb)

If I want to include a correlation structure

gamm(count ~ s(site, bs = "re") + s(year) + season, data=mydata, family = nb, correlation = corAR1(form=~year|site))

I get an error since I have two observations for each year and site. The solutions I can think of are:

  1. Limit the analysis to one season -> only one count per year and site
  2. Sum the counts per year and site -> only one count per year and site

I don't like the first one since I use only half of my data but I also think that it might be the only way since I know that higher counts in early summer lead to higher counts in late summer - does this mean my data is not independent?

What is the best way to analyze this data?

Thank you very much for your help!


For this I think you could just specify a variable that contains the time ordering, rather than year and nest that within site.

So you want a variable time (say) that is the integers 1, 2, 3, ..., T in site 1, and again in site 2 and so on. This would be pretty straight forward to code in R if you have no missing time points in any of the sites. It needs to be coded (integers) in each site the same I think because you'll have the same correlation estimated for each site so we want time 1 in site A to match time 1 in site B.

Once you have that variable, the correlation argument would then be corAR1(form = ~ time | site)

  • $\begingroup$ Thank you, that's exactly what I was looking for! $\endgroup$
    – Schnipfi
    Nov 26 '20 at 6:30

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.