I am using gamm models in mgcv package to analyse how specific diversity measures eg. Shannon vary over time and with environmental variables eg. temperature.
I have the initial model so far to analyse time series:
modf<-gamm(y~ as.factor(year) + s(doy,bs='cc',k=kdy),method=mth,correlation=tcor,data=d,
control=ctrl,random=NULL,gamma=1)
I want to include temperature as random effect and thought of doing something like:
modf<-gamm(y~ as.factor(year) + s(doy,bs='cc',k=kdy), + s(temp,bs="re"),method=mth,
correlation=tcor,data=d,control=ctrl,gamma=1)
However, so far I have only seen this for gam not gamm. Does it still work this way?
An example of type of data structure:
- $ total_abundance: num 6364161 1929775 7057036 1266342 3981198 ...
- $ shannon : num 1.87 2.08 1.95 1.84 2.06 ...
- $ turnover : num 0.613 0.475 0.525 0.556 0.429 ...
- $ year : int 1985 1986 1987 1987 1987 1988 1989 1989 1991
- $ month : int 8 12 3 7 8 5 1 8 1 9 ...
- $ day : int 20 8 15 6 17 9 16 29 14 4 ...
- $ temp : num 25.5 9.87 4.8 19.72 26.03 ...
- $ doy : num 232 342 74 187 229 130 16 241 14 247 ...
where doy is 'day of year' and accounts for seasonality
Thanks
temp
a continuous variable or something else? What is the grouping structure you have in mind? Might I suggest including some sample data in your question -- you are more likely to get a helpful answer that way. – Weihuang Wong