This is my first post on here, looking for some help. I am relatively new to analysis of temporal datasets. I have experience with R and developing linear models, so I am trying to figure out if the approach I am trying is appropriate with temporal data or if I need to do something different.

Data: Monthly measurements of metal concentrations that span one year, with a few missing months. With the missing months, I am pretty I can't set up a true time series analysis in R (right?). I have several predictor variables (rainfall, temp, etc) that I want to evaluate.

Approach: Construct a GLM with terms for each predictor and sampling month. I am considering using the gls function in nlme package in R so that I could examine autocorrelation.

Goal: Identify factors to explain pattern in temporal water data

Questions: - Can I use a glm approach with temporal data, even if there may be seasonality to the data? - How do i test for temporal autocorrelation in the error terms? I know there are some correlation structures that I could set up in gls but haven't figured out how to set this up and which one is best for testing temporal autocorrelation yet.

Example dataset and approach is below. I would appreciate advice on if what I propose seems appropriate. If not, suggestions of alternative approaches would be a great help.

rain = c(100,110,120,200,210,220,300,310,330), 
temp = c(10,11,12,14,12,13,10,12,8))

m0<-gls(wat~month+rain+temp,correlation = corAR1(),data=dat)


  • $\begingroup$ How many measurements do you have and how many missing months? I'm also wondering if you could group by month and thus sidestep autocorrelation issues. (Can anyone confirm if this makes sense or not?) $\endgroup$
    – Wayne
    Nov 9, 2013 at 2:03
  • $\begingroup$ I have 3-5 measurements per month and 4 missing months. $\endgroup$ Nov 9, 2013 at 2:36
  • $\begingroup$ Sorry, I forgot to ask: are your 3-5 measurements each month are from a single location or multiple locations? (That is, are the 3-5 measurements repeated measurements or not?) $\endgroup$
    – Wayne
    Nov 9, 2013 at 2:40
  • $\begingroup$ The data are replicates from the same location. $\endgroup$ Nov 9, 2013 at 5:05
  • 1
    $\begingroup$ Even if your various "replicates" are essentially simultaneous, you should use their daily dates as part of the information. Slight or even considerable irregularity in spacing of measurements is not fatal to a GLM approach, but for testing any model e.g. looking for structure in plots of residual versus exact date you should use all the information you have. Grouping separate measurements by month would be entirely arbitrary, as month has no intrinsic meaning or relevance to environmental data, except as an expression of time of year. $\endgroup$
    – Nick Cox
    Nov 9, 2013 at 15:29

1 Answer 1


I'm still learning a lot in this area, but since you don't have an answer yet, my thoughts are...

The correlation structure you specify in the various functions that allow it (gls, lme, etc) are for within-group correlation, so I don't believe AR1 is correct since the multiple measurements are within the same timeframe.

Perhaps you want (I created dat2, which centers your variables):

gls (wat ~ rain + temp, dat2, correlation=corCompSymm (form = ~1 | month))

which gives answers, in your example, similar to GEE:

library (geepack)
geeglm (wat ~ rain + temp, data = dat2, id = month, corstr = "exchangeable")

Unfortunately, I've read several papers on GEE v GLMM and still haven't figured out whether GEE would be applicable in such a case. There are several threads on this, one of which is:

What is the difference between generalized estimating equations and GLMM?

Hope that helps.


Your Answer

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

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