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:
where doy is 'day of year' and accounts for seasonality
Thanks
What you seem to be wanting to do doesn't make any sense unless you want the linear effect of temp
to vary within the levels of a grouping factor.
Typically, you specify this random slope using random
as
list(group = ~ x)
where group
is a factor grouping variable and x
is your temp
.
What you are asking for with temp = ~ 1
is a random intercept for the unique values of temp
, which is probably asking too much of the data.
The equivalent of s(time, bs = "re")
requires you to remove the intercept from the random
formula:
list(group = ~ x - 1)
but you still need a group
variable.
If you just want to control for temp
, add it as a linear parametric effect ( + temp
) or a smooth effect ( + s(temp)
) in the gamm()
model formula.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.