# GLM with Temporal Data

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.

dat<-data.frame(month=c("Jan","Jan","Jan","Feb","Feb","Feb","Jun","Jun","Jun"),
wat=c(0.4,0.5,0.6,1,1.5,1.8,0.4,0.3,0.8),
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)


Thanks!

• 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?) – Wayne Nov 9 '13 at 2:03
• I have 3-5 measurements per month and 4 missing months. – user1868064 Nov 9 '13 at 2:36
• 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?) – Wayne Nov 9 '13 at 2:40
• The data are replicates from the same location. – user1868064 Nov 9 '13 at 5:05
• 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. – Nick Cox Nov 9 '13 at 15:29

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))


library (geepack)