[R-sig-ME] Fitting interaction term in GAMM with random effect

Samantha Cox samantha.cox at plymouth.ac.uk
Tue Apr 5 17:43:52 CEST 2016


Hi,

First sorry for cross posting with the R datatable help page -  I was not sure which list is more appropriate.

I am trying to fit a model with a random effect of DeploymentID with a nested AR1 autoregressive correlation structure.  For the fixed component I am fitting a smooth of tide.  I have two sets of models I am fitting with different data sets.  For the smooth of tide, I want a separate smooth to be fitted per SiteID.  In one set of models this is fine (each SiteID contains multiple DeploymentIDs).  In the other SiteID and DeploymentID are identical.  I am wondering how to code this.  I am not interested in the intercept of SiteID hence why it has previously been a random effect.  I am interested in how smooths vary between SiteIDs and hence why this is a fixed effect.

Example data structure first data set:

SiteID    DeploymentID
1                  1
1                  1
1                  1
1                  1
1                  1
1                  2
1                  2
1                  2
1                  3
2                  4
2                  4
2                  4
2                  4
2                  4
2                  5
2                  5
2                  5
3                  6
3                  7
3                  8
etc etc

Example data structure seconddata set:

SiteID    DeploymentID
1                  1
2                  2
3                  3
4                  4

My problem is that I understand to fit a interaction term, one must use
gamm(Y~s(tide,k=5,bs="cc",by=SiteID)+SiteID,knots=list(tide=c(0,1)),correlation=corAR1(form=~1|DeploymentID).....

- if I include +SiteID then I should NOT include DeploymentID as a random effect also (for the second model where SiteId and DeploymentID are identical - but this is ok for the first model)?
- the problem is when I want to compare nested models I run into issues if the smooth term is dropped as I do not have a random or smooth term in the model.

Can I code as
gamm(Y~s(tide,k=5,bs="cc",by=SiteID),knots=list(tide=c(0,1)),random=list(DeploymentID=~1),correlation=corAR1(form=~1|DeploymentID).....

Any help on this is appreciated....

Cheers
________________________________
[http://www.plymouth.ac.uk/images/email_footer.gif]<http://www.plymouth.ac.uk/worldclass>

This email and any files with it are confidential and intended solely for the use of the recipient to whom it is addressed. If you are not the intended recipient then copying, distribution or other use of the information contained is strictly prohibited and you should not rely on it. If you have received this email in error please let the sender know immediately and delete it from your system(s). Internet emails are not necessarily secure. While we take every care, Plymouth University accepts no responsibility for viruses and it is your responsibility to scan emails and their attachments. Plymouth University does not accept responsibility for any changes made after it was sent. Nothing in this email or its attachments constitutes an order for goods or services unless accompanied by an official order form.

	[[alternative HTML version deleted]]



More information about the R-sig-mixed-models mailing list