[R-sig-eco] autocorrelation structure

Gavin Simpson gavin.simpson at ucl.ac.uk
Thu Nov 24 17:34:18 CET 2011


On Thu, 2011-11-24 at 17:02 +0100, Marc Taylor wrote:
> Dear R-sig-ecology list,
> 
> 
> I am fitting a gamm model(package: mgcv)  in which I have a violation of
> independence with regard to temporal autocorrelation due to the fact that
> all of my variables have a cyclical seasonal pattern.

I would try to model this in the main effects rather than correct for it
in the covariance matrix.

If you have data measured throughout the year, over several years, then
add a cyclic spline term to your model. For example,

mod <- gamm(resp ~ s(year) + s(month, bs = "cc"), data = foo, ....)

will fit a cyclic cubic spline in month (say coded 1, 2, 3 numerically)
which means that the end points of the spline are match, up to 2nd
derivatives.

I have regularly used this for spot samples throughout years, where I
use the day of the year of the sample as my variable for the cyclic
term:

mod <- gamm(resp ~ s(year) + s(doy bs = "cc"), data = foo, ....)

You may want to specify the knots for the seasonal term to give coverage
over the real period of interest. For example, I had data on water
temperature over most days of the year but the people doing the sampling
didn't sample over Christmas and New Year, so I specifically set the
knot endpoints to be day of year 1 and 366 to be able to generate
predictions over the entire year (of course the fitted spline in the
period without data was subject to greater uncertainty but that was fine
for me).

HTH

G

>  I have largely
> corrected for this by including a AR-2 correlation structure in the
> following way:
> 
> >corstr <- corARMA(c(0.4, -0.1), p=2, q=0, form = ~ DATE)
> 
> I nevertheless continue to have some autocorrelation in the "significant"
> range at some of the larger time lags (i.e. year lags) as identified by:
> 
> >E <- resid(gamm.fit$lme, type="normalized")
> >acf(E)
> 
> 
> My guess is that an AR-2 structure can't produce a sin-like correlation
> structure, but when I try a higher AR structure(i.e. p=3), the fitting
> doesn't converge.
> 
> Is anyone familiar with such a problem? Does the fitting need to run for a
> longer period of time, or are there other options for me?
> 
> Many thanks for you help,
> Marc
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
> 

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-sig-ecology mailing list