[R] GAM function with interaction

Paul Simonin paul.simonin at uvm.edu
Wed Jun 17 17:44:55 CEST 2009


Hello R Users,
  I have a question regarding fitting a model with GAM{mgcv}. I have 
data from several predictor (X) variables I wish to use to develop a 
model to predict one Y variable. I am working with ecological data, so 
have data collected many times (about 20) over the course of two years. 
Plotting data independently for each date there appears to be 
relationships between Y (fish density) and at least several X variables 
(temperature and light). However, the actual value of X variables (e.g., 
temperature) changes with date/season. In other words, fish distribution 
is likely related to temperature, but available temperatures change 
through the season. Thus, when data from all dates are combined to 
create a model from the entire dataset, I think I need to include some 
type of metric/variable/interaction term to account for this date 
relationship. I have written the following code using a "by" term:

Distribution.s.temp.logwm2.deltaT<-gam(yoyras~s(temp,by=datecode)+s(logwm2,by=datecode)+s(DeltaT,by=datecode),data=AllData)

  However, I am not convinced this is the correct way to account for 
this relationship. What do you think? Is there another way to include 
this in my model? Maybe I should simply include date ("datecode") as 
another term in the model?

  I also believe there may be an interaction between temperature and 
light (logwm2), and based on what I have read the "by" method may be the 
best way to include this. Correct?

  Thank you for any input, tips, or advice you may be able to offer. I 
am new to R, so especially grateful!

Thanks again,
Paul Simonin
(PhD student)




More information about the R-help mailing list