Solved – GLM with Temporal Data

autocorrelationgeneralized linear modelrtime series

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!

Best Answer

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.

Related Question