[R] GAM function with interaction

Simon Wood s.wood at bath.ac.uk
Wed Jun 17 17:43:52 CEST 2009


Paul,

I think I would try something like 

yoyoras~te(temp,date) ...

to incorportate a continuous interaction of temp and date. Otherwise with the 
models you are using, if `datecode' is a factor you'll get a smooth for every 
date, which may be over-flexible, and if datecode is numeric you'll get a 
linear dependance on date where the slope parameter changes with temp, which 
may be a bit too restrictive.

Simon

On Wednesday 17 June 2009 16:44, Paul Simonin wrote:
> 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)
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented, minimal,
> self-contained, reproducible code.

-- 
> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK
> +44 1225 386603  www.maths.bath.ac.uk/~sw283




More information about the R-help mailing list